/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 250px;
  --sidebar-bg: #1a1b2e;
  --sidebar-hover: #252640;
  --sidebar-active-bg: rgba(124,58,237,0.15);
  --sidebar-active-border: #7c3aed;
  --primary: #7c3aed;
  --body-bg: #f0f2f5;
  --card-radius: 12px;
  --transition: 0.25s ease;
}

/* ── Reset / Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--body-bg);
  overflow-x: hidden;
  font-size: 0.925rem;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 1050;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-icon {
  font-size: 1.6rem;
  color: var(--primary);
}

.sidebar-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  margin: 0;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

.sidebar-nav li a i { font-size: 1.05rem; width: 18px; }

.sidebar-nav li a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav li.active a {
  background: var(--sidebar-active-bg);
  color: #fff;
  border-left-color: var(--sidebar-active-border);
  font-weight: 600;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
}

.status-dot.running {
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.4);
  animation: pulse-dot 2s infinite;
}

.status-dot.stopped { background: #ef4444; }
.status-dot.connected { background: #3b82f6; }

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* ── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ── Top bar ────────────────────────────────────────────────────────────────── */
.top-bar {
  background: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar h5 { color: #1a1b2e; }

.sidebar-toggle-btn {
  background: none;
  border: 1px solid #e2e8f0;
  color: #64748b;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.sidebar-toggle-btn:hover { background: #f1f5f9; }

/* ── Content area ───────────────────────────────────────────────────────────── */
.content-area { padding: 22px 24px; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  border: none !important;
  border-radius: var(--card-radius) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.card-header {
  background: #fff !important;
  border-bottom: 1px solid #f1f5f9 !important;
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 0.9rem;
}

/* ── Stat cards ─────────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 18px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  transition: transform 0.15s;
}

.stat-card:hover { transform: translateY(-2px); }

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #94a3b8;
  font-weight: 600;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2;
  margin: 2px 0;
}

.stat-sub { font-size: 0.78rem; }

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
  font-weight: 600;
  border-bottom: 1px solid #f1f5f9;
  padding: 10px 14px;
}

.table td { padding: 10px 14px; vertical-align: middle; }

.group-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.group-avatar-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ede9fe;
  color: #6d28d9;
}

.pipeline-target-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pipeline-avatar-wrapper {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  max-width: 38px;
  max-height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pipeline-target-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.pipeline-target-avatar.pipeline-target-avatar-placeholder {
  background: #ede9fe;
  color: #6d28d9;
  font-size: 0.95rem;
}

.pipeline-target-avatar-placeholder {
  font-size: 0.95rem;
}

.pipeline-target-meta {
  min-width: 0;
}

.group-preview-card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  background: #f8fafc;
  overflow: hidden;
}

.group-preview-layout {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.group-preview-avatar-shell {
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  max-width: 56px;
  max-height: 56px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
}

.group-preview-meta {
  min-width: 0;
}

.group-preview-avatar,
#group-preview-avatar,
#group-preview-fallback {
  width: 56px !important;
  height: 56px !important;
  min-width: 56px !important;
  min-height: 56px !important;
  max-width: 56px !important;
  max-height: 56px !important;
  border-radius: 50% !important;
  flex: 0 0 56px;
  overflow: hidden;
}

.group-preview-layout img,
#group-preview-avatar {
  display: block;
  width: 56px !important;
  height: 56px !important;
  max-width: 56px !important;
  max-height: 56px !important;
  object-fit: cover;
}

#group-preview-title,
#group-lookup-status {
  overflow-wrap: anywhere;
}

#addGroupModal .modal-body {
  overflow-x: hidden;
}

@media (max-width: 576px) {
  .group-preview-layout {
    grid-template-columns: 1fr;
  }

  #group-preview-avatar,
  #group-preview-fallback {
    margin: 0 auto;
  }
}

/* ── Small buttons ──────────────────────────────────────────────────────────── */
.btn-xs {
  padding: 3px 8px;
  font-size: 0.78rem;
  border-radius: 6px;
  line-height: 1.4;
}

/* ── Message preview ────────────────────────────────────────────────────────── */
.msg-preview {
  max-width: 400px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  color: #374151;
}

/* ── Log entry animation ────────────────────────────────────────────────────── */
.log-entry {
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Blink for live indicator ───────────────────────────────────────────────── */
.blink { animation: blink 1.4s infinite; }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Sidebar collapsed ──────────────────────────────────────────────────────── */
.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.sidebar-collapsed .main-content { margin-left: 0; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .sidebar.open { transform: translateX(0); }
  .content-area { padding: 14px; }
}
