/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:      #25d366;
  --primary-dark: #128c4e;
  --primary-fg:   #fff;

  --bg:           #f0f2f5;
  --surface:      #ffffff;
  --surface-2:    #f7f8fa;
  --border:       #e5e7eb;
  --border-2:     #d1d5db;

  --text:         #111827;
  --text-2:       #374151;
  --muted:        #6b7280;
  --muted-2:      #9ca3af;

  --success:      #10b981;
  --warn:         #f59e0b;
  --danger:       #ef4444;
  --info:         #3b82f6;

  --sidebar-w:    220px;
  --header-h:     56px;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,.10);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a    { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ── Shell ───────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #111827;
  color: #f9fafb;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo-text { font-weight: 700; font-size: 1rem; color: #fff; }

.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #9ca3af;
  font-size: .9rem;
  font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  position: relative;
  text-decoration: none;
}
.nav-item:hover       { background: rgba(255,255,255,.06); color: #f9fafb; text-decoration: none; }
.nav-item.active      { background: rgba(37,211,102,.12); color: var(--primary); }
.nav-item.active svg  { color: var(--primary); }
.nav-item svg         { flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 8px 0;
}
.admin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: .85rem;
  color: var(--muted-2);
}

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

.page-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: 1rem; font-weight: 600; }
.page-body  { padding: 20px 24px; flex: 1; }

/* ── Stat Grid ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.stat-icon--blue   { background: #dbeafe; color: #1d4ed8; }
.stat-icon--green  { background: #dcfce7; color: #15803d; }
.stat-icon--purple { background: #ede9fe; color: #6d28d9; }
.stat-icon--orange { background: #ffedd5; color: #c2410c; }
.stat-value  { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-total  { font-size: 1rem; color: var(--muted); font-weight: 400; }
.stat-label  { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ── Grid ────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card.p-0 { padding: 0; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-weight: 600; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  background: var(--surface-2);
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover  { background: var(--surface-2); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-connected    { background: #dcfce7; color: #15803d; }
.badge-qr           { background: #fef3c7; color: #92400e; }
.badge-pending      { background: #e0e7ff; color: #3730a3; }
.badge-disconnected { background: #fee2e2; color: #991b1b; }
.badge-logged_out   { background: #f3f4f6; color: #4b5563; }
.badge-error        { background: #fee2e2; color: #991b1b; }
.badge-connecting   { background: #e0f2fe; color: #075985; }
.badge-otp          { background: #fef3c7; color: #92400e; }
.badge-banned       { background: #fee2e2; color: #7f1d1d; font-weight:700; }
.badge-draft        { background: #f3f4f6; color: #4b5563; }
.badge-running      { background: #dcfce7; color: #15803d; }
.badge-paused       { background: #fef3c7; color: #92400e; }
.badge-completed    { background: #dbeafe; color: #1e40af; }
.badge-stopped      { background: #f3f4f6; color: #6b7280; }
.badge-failed       { background: #fee2e2; color: #991b1b; }
.badge-sent         { background: #dcfce7; color: #15803d; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, box-shadow .15s, opacity .15s;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none !important;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary);    color: var(--primary-fg); border-color: var(--primary-dark); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface);    color: var(--text-2);      border-color: var(--border-2); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger    { background: #fee2e2;           color: #991b1b;            border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-warn      { background: #fef3c7;           color: #92400e;            border-color: #fcd34d; }
.btn-warn:hover { background: #fde68a; }
.btn-info      { background: #dbeafe;           color: #1e40af;            border-color: #93c5fd; }
.btn-info:hover { background: #bfdbfe; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 5px; font-size: .875rem; }
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
/* Checkboxes & radios: natural size, inline with their label text */
.form-group input[type="checkbox"],
.form-group input[type="radio"] {
  width: auto;
  margin-right: 7px;
  vertical-align: middle;
  cursor: pointer;
}
/* Inline checkbox labels (not the block field labels) */
.form-group label.inline-check,
label.inline-check {
  display: inline-flex;
  align-items: center;
  font-weight: 400;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,211,102,.15);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warn  { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info  { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .2s, transform .2s;
  max-width: 320px;
}
.toast.show         { opacity: 1; transform: translateX(0); }
.toast--success svg { color: var(--success); }
.toast--error   svg { color: var(--danger); }
.toast--info    svg { color: var(--info); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}
.modal--narrow { max-width: 380px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 400px; padding: 16px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.2rem; font-weight: 700; margin-top: 10px; }
.login-logo p  { color: var(--muted); font-size: .875rem; }
.logo-mark { display: inline-flex; }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* ── Device list ─────────────────────────────────────────────────────────── */
.device-list { display: flex; flex-direction: column; gap: 2px; }
.device-row  {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
}
.device-row:hover { background: var(--surface-2); }
.device-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); flex-shrink: 0; }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-phone{ font-size: .8rem; color: var(--muted); }

/* ── Message list (dashboard) ────────────────────────────────────────────── */
.msg-list { display: flex; flex-direction: column; gap: 2px; }
.msg-row  { display: flex; align-items: flex-start; gap: 10px; padding: 6px 4px; border-radius: var(--radius-sm); }
.msg-row:hover { background: var(--surface-2); }
.msg-dir  { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px; }
.msg-dir--in  { background: #dcfce7; color: #15803d; }
.msg-dir--out { background: #dbeafe; color: #1e40af; }
.msg-body { flex: 1; min-width: 0; }
.msg-phone{ font-size: .8rem; font-weight: 500; }
.msg-text { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-time { font-size: .75rem; color: var(--muted-2); white-space: nowrap; }

/* ── Row actions ─────────────────────────────────────────────────────────── */
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ── Inbox layout ────────────────────────────────────────────────────────── */
.inbox-layout {
  display: flex;
  height: calc(100vh - var(--header-h) - 40px);
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.contact-panel {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.contact-search-wrap {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-input-box {
  position: relative;
  flex: 1;
}
.search-input-box input {
  width: 100%;
  padding: 7px 10px 7px 34px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  background: var(--surface-2);
  color: var(--text);
}
.search-input-box input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  pointer-events: none;
}
.contact-sort-select {
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: .78rem;
  color: var(--muted);
  cursor: pointer;
  padding: 7px 8px;
  flex-shrink: 0;
}

/* ── Device filter dropdown ──────────────────────────────────────────── */
.device-dd { position: relative; width: 100%; }
.device-dd-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
}
.device-dd-toggle:hover { border-color: var(--primary); }
.device-dd-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 280px;
  overflow-y: auto;
  display: none;
  padding: 4px;
}
.device-dd.open .device-dd-menu { display: block; }
.device-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .82rem;
}
.device-dd-item:hover { background: var(--surface-2); }
.device-dd-item input { cursor: pointer; }
.device-dd-divider { height: 1px; background: var(--border); margin: 4px 0; }
.dev-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

#contact-list { flex: 1; overflow-y: auto; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.contact-item:hover  { background: var(--surface-2); }
.contact-item.active { background: rgba(37,211,102,.08); }

.c-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
}
.c-info    { flex: 1; min-width: 0; }
.c-name    { font-weight: 500; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-preview { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-out   { color: var(--muted-2); }
.c-meta    { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.c-time    { font-size: .72rem; color: var(--muted-2); white-space: nowrap; }
.c-unread  {
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 0 6px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-no-select {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted-2);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-name { font-weight: 600; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: .875rem;
  line-height: 1.45;
  word-break: break-word;
}
.bubble-in  {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-out {
  align-self: flex-end;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  border-bottom-right-radius: 4px;
  color: #111827; /* always dark text on the light-green bubble */
}
.bubble-time {
  font-size: .7rem;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.bubble-out .bubble-time { justify-content: flex-end; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: .875rem;
  font-family: inherit;
  line-height: 1.45;
  max-height: 120px;
  overflow-y: auto;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,211,102,.15); }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar  { height: 4px; background: var(--border); border-radius: 2px; margin-top: 4px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width .4s; }

/* ── QR status ───────────────────────────────────────────────────────────── */
.qr-status {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 10px;
  font-size: .875rem;
  color: var(--muted);
}
.qr-pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.7); }
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-muted   { color: var(--muted); }
.text-sm      { font-size: .8rem; }
.text-danger  { color: var(--danger); }
.empty-state  { padding: 32px 16px; text-align: center; color: var(--muted-2); font-size: .875rem; }
/* ── V3 additions — append to style.css ──────────────────────────────────── */

/* Nav section label */
.nav-section {
  padding: 12px 16px 4px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #4b5563;
}

/* Small user avatar in sidebar footer */
.user-avatar-sm {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .75rem; color: #fff;
  flex-shrink: 0;
}

/* Role badges */
.badge-role-admin  { background: #dcfce7; color: #15803d; }
.badge-role-agent  { background: #dbeafe; color: #1e40af; }
.badge-role-viewer { background: #f3f4f6; color: #4b5563; }

/* Larger user avatar for users page */
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; color: #fff;
  flex-shrink: 0;
}

/* Alert info */
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Dark theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #0f1419;
  --surface:      #1a2027;
  --surface-2:    #232b34;
  --border:       #2d3742;
  --border-2:     #3a4654;

  --text:         #e6edf3;
  --text-2:       #c9d1d9;
  --muted:        #8b949e;
  --muted-2:      #6e7681;

  --shadow:       0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md:    0 4px 16px rgba(0,0,0,.5);
}
[data-theme="dark"] .sidebar { background: #0a0e13; border-right: 1px solid var(--border); }
[data-theme="dark"] .nav-item.active { background: rgba(37,211,102,.16); }
[data-theme="dark"] img { opacity: .95; }
[data-theme="dark"] .badge-role-admin  { background:#14321f;color:#4ade80; }
[data-theme="dark"] .badge-role-agent  { background:#16243f;color:#60a5fa; }
[data-theme="dark"] .badge-role-viewer { background:#262b31;color:#9ca3af; }

/* Theme toggle button */
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2); transition: background .15s;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ── Bell / notifications ────────────────────────────────────────────────── */
.bell-wrap { position: relative; }
.bell-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2); transition: background .15s; position: relative;
}
.bell-btn:hover { background: var(--surface-2); }
.bell-badge {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff; border-radius: 9px; font-size: .68rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface);
}
.bell-panel {
  position: absolute; top: 44px; right: 0; width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); z-index: 100; display: none;
}
.bell-panel.open { display: block; }
.bell-head { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); }
.bell-head-title { font-weight: 600; font-size: .9rem; }
.bell-clear { font-size: .75rem; color: var(--primary-dark); cursor: pointer; background: none; border: none; }
.notif-item { padding: 11px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: rgba(37,211,102,.06); }
.notif-icon { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.notif-icon.danger  { background: #fee2e2; color: #b91c1c; }
.notif-icon.success { background: #dcfce7; color: #15803d; }
.notif-icon.warn    { background: #fef3c7; color: #b45309; }
.notif-icon.info    { background: #dbeafe; color: #1e40af; }
[data-theme="dark"] .notif-icon.danger  { background:#3a1a1a; color:#fca5a5; }
[data-theme="dark"] .notif-icon.success { background:#13301d; color:#86efac; }
[data-theme="dark"] .notif-icon.warn    { background:#3a2e12; color:#fcd34d; }
[data-theme="dark"] .notif-icon.info    { background:#16243f; color:#93c5fd; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: .82rem; font-weight: 600; }
.notif-text  { font-size: .78rem; color: var(--muted); margin-top: 1px; }
.notif-time  { font-size: .7rem; color: var(--muted-2); margin-top: 3px; }
.notif-empty { padding: 30px 14px; text-align: center; color: var(--muted); font-size: .85rem; }


/* ── Dark mode chat bubbles ──────────────────────────────────────────────── */
[data-theme="dark"] .bubble-in  { background: var(--surface-2); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .bubble-out { background: #1f6b3a; border-color: #2a7d47; color: #f0fff5; }
[data-theme="dark"] .bubble-out .bubble-time { color: #b7e6c8; }
[data-theme="dark"] .bubble-in  .bubble-time { color: var(--muted); }

/* ── Tooltip (? icon) ─────────────────────────────────────────────────────── */
.tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border-2);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
  cursor: default;
  flex-shrink: 0;
  user-select: none;
}
.tooltip-icon:hover { background: var(--primary-dark); color: #fff; }
.tooltip-body {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .78rem;
  line-height: 1.5;
  color: var(--text-2);
  box-shadow: var(--shadow-md);
  z-index: 200;
  font-weight: 400;
}
.tooltip-wrap:hover .tooltip-body { display: block; }
