/* ==========================================================================
   MsgCX — Zoho-CRM–style layout, modern palette, Manrope (slim weights)
   ========================================================================== */
:root {
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef1f6;
  --border: #e3e7ee;
  --border-strong: #d3d9e3;
  --text: #1a2030;
  --text-2: #586174;
  --text-3: #8b94a5;

  --top: #151a30;
  --top-2: #1e2440;
  --top-text: #aab2cf;
  --top-text-active: #ffffff;

  --primary: #4f5bd5;
  --primary-hover: #4350c4;
  --primary-soft: #eef0fd;
  --primary-text: #3b46b8;

  --green: #12a875;
  --green-soft: #e6f7f0;
  --amber: #d98a00;
  --amber-soft: #fdf3e1;
  --red: #e0454b;
  --red-soft: #fdecec;
  --blue: #2f80ed;
  --blue-soft: #e8f1fd;
  --violet: #8a5cf6;
  --violet-soft: #f1ecfe;
  --slate-soft: #eef0f4;

  --chat-bg: #f1f3f8;
  --bubble-out: #e7ebfd;
  --bubble-in: #ffffff;

  /* Data-viz tokens — validated (scripts/validate_palette.js) for both modes.
     Categorical slots 1–2 for sent/received; one-hue blue ordinal ramp for message status. */
  --viz-1: #2a78d6;
  --viz-2: #eb6834;
  --viz-sent: #86b6ef;
  --viz-delivered: #3987e5;
  --viz-read: #1c5cab;
  --viz-pending: #b9bec8;
  --viz-critical: #d03b3b;
  --viz-grid: #edf0f4;
  --viz-axis: #8b94a5;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(20, 26, 48, .05);
  --shadow: 0 4px 16px rgba(20, 26, 48, .08);
  --shadow-lg: 0 18px 48px rgba(20, 26, 48, .18);
  color-scheme: light;
}

/* data-theme is always set by /js/theme.js (saved choice, else the OS preference). */
:root[data-theme='dark'] {
  --bg: #0d1017;
  --surface: #151922;
  --surface-2: #1a1f2a;
  --surface-3: #212734;
  --border: #252b38;
  --border-strong: #303848;
  --text: #e5e8ef;
  --text-2: #a2aabb;
  --text-3: #6f788a;
  --top: #0a0c14;
  --top-2: #161a2b;
  --top-text: #8d95b3;
  --primary: #7f89f2;
  --primary-hover: #939cf5;
  --primary-soft: #1f2445;
  --primary-text: #a7aef8;
  --green-soft: #12291f;
  --amber-soft: #2c2210;
  --red-soft: #2d1517;
  --blue-soft: #132238;
  --violet-soft: #221a3a;
  --slate-soft: #222836;
  --chat-bg: #11141c;
  --bubble-out: #262c52;
  --bubble-in: #1c212c;
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-sent: #256abf;
  --viz-delivered: #5598e7;
  --viz-read: #9ec5f4;
  --viz-pending: #4a5163;
  --viz-grid: #212734;
  --viz-axis: #6f788a;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-weight: 400;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; letter-spacing: -0.015em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, .mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: 52px;
  display: flex; align-items: stretch; gap: 8px;
  padding: 0 16px;
  background: var(--top);
  color: var(--top-text);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-weight: 600; font-size: 15px; letter-spacing: -0.02em;
  padding-right: 18px; margin-right: 4px;
  border-right: 1px solid rgba(255,255,255,.08);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6c78ff, #20c997);
  color: #fff; font-size: 15px;
}
.tabs {
  display: flex; align-items: stretch; gap: 2px;
  overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: flex; align-items: center; gap: 7px;
  padding: 0 14px;
  color: var(--top-text);
  font-weight: 400; font-size: 13.5px; white-space: nowrap;
  transition: color .15s, background .15s;
}
.tab i { font-size: 14px; opacity: .8; }
.tab:hover { color: #fff; background: rgba(255,255,255,.04); text-decoration: none; }
.tab.active { color: var(--top-text-active); font-weight: 500; }
.tab.active::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: 0;
  height: 2px; border-radius: 2px 2px 0 0; background: #8d97ff;
}
.top-actions { display: flex; align-items: center; gap: 6px; }
.top-select {
  height: 32px; max-width: 200px;
  background: var(--top-2); color: #e3e6f3;
  border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius-sm);
  font: inherit; font-size: 12.5px; padding: 0 28px 0 10px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23aab2cf' viewBox='0 0 16 16'%3E%3Cpath d='M1.6 5.1a.7.7 0 0 1 1-.1L8 9.7l5.4-4.7a.7.7 0 1 1 .9 1.1l-5.8 5a.7.7 0 0 1-.9 0l-5.8-5a.7.7 0 0 1-.2-1z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: transparent; border: 0; color: var(--top-text); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.avatar-btn { border: 0; background: transparent; padding: 0 0 0 4px; cursor: pointer; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  font-size: 12px; font-weight: 500; color: #fff;
  background: var(--primary);
}
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }

/* dropdown */
.dropdown { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 220px; padding: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.menu-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; background: none; border-radius: var(--radius-sm);
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-3); text-decoration: none; }
.menu i { color: var(--text-2); }

/* ---------------------------------------------------------------- page chrome */
.page { padding: 0 0 40px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.page-head h1 { font-size: 18px; }
.page-head .crumb { font-size: 12px; color: var(--text-3); margin-bottom: 2px; }
.page-body { padding: 20px 24px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* list view: filter panel + content (Zoho style) */
.split { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100vh - 52px - 63px); }
.filter-panel {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px; display: flex; flex-direction: column; gap: 18px;
}
.filter-panel h4 { font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 8px; }
.filter-list { display: flex; flex-direction: column; gap: 2px; }
.filter-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); cursor: pointer; border: 0; background: none; font: inherit; text-align: left;
}
.filter-item:hover { background: var(--surface-3); color: var(--text); }
.filter-item.active { background: var(--primary-soft); color: var(--primary-text); font-weight: 500; }
.filter-item .count { font-size: 11.5px; color: var(--text-3); }
.split-main { padding: 16px 20px; min-width: 0; }

/* toolbar above tables */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.search {
  position: relative; display: flex; align-items: center;
}
.search i { position: absolute; left: 10px; color: var(--text-3); font-size: 13px; pointer-events: none; }
.search input { padding-left: 32px; width: 260px; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 30px; padding: 0; height: 30px; }
.btn i { font-size: 14px; }

.input, .select, textarea.input {
  width: 100%; height: 34px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13.5px; font-weight: 400;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
.input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input::placeholder { color: var(--text-3); }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%238b94a5' viewBox='0 0 16 16'%3E%3Cpath d='M1.6 5.1a.7.7 0 0 1 1-.1L8 9.7l5.4-4.7a.7.7 0 1 1 .9 1.1l-5.8 5a.7.7 0 0 1-.9 0l-5.8-5a.7.7 0 0 1-.2-1z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 20px; background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(14px); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14px; font-weight: 500; }
.card-body { padding: 16px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* KPI tiles */
.kpi { padding: 16px 18px; display: flex; align-items: flex-start; gap: 14px; }
.kpi-icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; font-size: 17px; flex: none; }
.kpi-label { font-size: 12.5px; color: var(--text-2); }
.kpi-value { font-size: 24px; font-weight: 500; letter-spacing: -0.03em; line-height: 1.2; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.tone-indigo { background: var(--primary-soft); color: var(--primary-text); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }

/* quick actions */
.quick { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: var(--text); }
.quick:hover { text-decoration: none; border-color: var(--primary); }
.quick .kpi-icon { width: 34px; height: 34px; font-size: 15px; }
.quick-title { font-weight: 500; }
.quick-sub { font-size: 12px; color: var(--text-3); }

/* ---------------------------------------------------------------- table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.cell-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-title { font-weight: 500; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); font-size: 12.5px; color: var(--text-2); }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  background: var(--slate-soft); color: var(--text-2);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.indigo { background: var(--primary-soft); color: var(--primary-text); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }

/* empty states */
.empty { text-align: center; padding: 48px 24px; color: var(--text-2); }
.empty i { font-size: 30px; color: var(--text-3); display: block; margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty .btn i { font-size: 14px; color: inherit; display: inline-block; margin: 0; }

/* ---------------------------------------------------------------- modal & toast */
dialog.modal {
  border: 0; padding: 0; border-radius: 12px; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(12, 15, 28, .45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; font-weight: 500; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 380px;
  padding: 11px 14px; border-radius: var(--radius); background: var(--top); color: #eef0f8;
  box-shadow: var(--shadow-lg); font-size: 13px; animation: toast-in .2s ease-out;
}
.toast.error i { color: #ff8a8f; }
.toast.success i { color: #4ade9b; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- devices */
.qr-box { display: grid; place-items: center; padding: 16px; background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--border); min-height: 300px; }
.qr-box img { width: 264px; height: 264px; max-width: 100%; height: auto; aspect-ratio: 1; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 6px; }
@media (max-width: 600px) { .qr-grid { grid-template-columns: 1fr !important; } }
.steps { margin: 0; padding-left: 18px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.device-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.device-card .card-body { display: flex; flex-direction: column; gap: 12px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.copy { cursor: pointer; color: var(--text-3); margin-left: 4px; }
.copy:hover { color: var(--primary-text); }

/* ---------------------------------------------------------------- messages */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 52px); background: var(--surface); }
.inbox-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox-list-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.chat-items { overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; gap: 11px; padding: 11px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border); border-left: 2px solid transparent;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--primary-soft); border-left-color: var(--primary); }
.chat-item .name { font-weight: 500; }
.chat-item .time { font-size: 11.5px; color: var(--text-3); flex: none; }
.chat-item .preview { font-size: 12.5px; color: var(--text-2); }
.unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 10.5px; font-weight: 500; display: inline-grid; place-items: center; }
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.thread-body { flex: 1; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; margin: 12px 0 8px; font-size: 11.5px; color: var(--text-3); background: var(--surface); padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border); }
.bubble {
  max-width: min(560px, 75%); padding: 8px 11px 6px; border-radius: 10px;
  background: var(--bubble-in); box-shadow: var(--shadow-sm); align-self: flex-start;
  word-wrap: break-word; border: 1px solid var(--border);
}
.bubble .text { white-space: pre-wrap; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; }
.bubble .sender { font-size: 12px; font-weight: 500; color: var(--primary-text); margin-bottom: 2px; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 10.5px; color: var(--text-3); margin-top: 3px; }
.bubble .meta .read { color: var(--blue); }
.bubble img, .bubble video { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-bottom: 4px; }
.bubble audio { max-width: 260px; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-3); border-radius: 6px; margin-bottom: 4px; color: var(--text); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { min-height: 38px; max-height: 140px; height: 38px; resize: none; padding: 9px 12px; }
.attach-chip { display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin: 0 16px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-text); font-size: 12.5px; }

/* ---------------------------------------------------------------- detail drawer */
.drawer { position: fixed; top: 52px; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 50; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transform: translateX(100%); transition: transform .2s ease; }
.drawer.open { transform: none; }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 14px; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 18px; }
.section-title { font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 8px; }
.participant { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }

/* ---------------------------------------------------------------- auth pages */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-art {
  background: radial-gradient(1200px 600px at 0% 0%, #2d3570 0%, transparent 60%), radial-gradient(900px 500px at 100% 100%, #0f6b5a 0%, transparent 55%), var(--top);
  color: #dfe3f5; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-art h2 { font-size: 30px; font-weight: 300; letter-spacing: -0.03em; line-height: 1.25; color: #fff; max-width: 440px; }
.auth-art h2 b { font-weight: 600; }
.auth-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: flex; flex-direction: column; gap: 12px; font-weight: 300; }
.auth-art li i { color: #7ee2c0; margin-right: 10px; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 24px; font-weight: 400; letter-spacing: -0.03em; }
.auth-card .btn { height: 40px; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.alert.error { background: var(--red-soft); color: var(--red); }
.alert.success { background: var(--green-soft); color: var(--green); }
.alert.info { background: var(--blue-soft); color: var(--blue); }

/* ---------------------------------------------------------------- docs */
.docs { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
.docs-nav { position: sticky; top: 72px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.endpoint { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.endpoint:last-child { border-bottom: 0; }
.method { font-family: var(--mono); font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 4px; min-width: 54px; text-align: center; }
.method.get { background: var(--blue-soft); color: var(--blue); }
.method.post { background: var(--green-soft); color: var(--green); }
.method.put { background: var(--amber-soft); color: var(--amber); }
.method.delete { background: var(--red-soft); color: var(--red); }
pre.code { margin: 0; padding: 14px 16px; background: #10142a; color: #dbe0f5; border-radius: var(--radius); overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.6; }

/* ---------------------------------------------------------------- charts */
.chart-legend { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend .key b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.swatch.line { width: 14px; height: 2px; border-radius: 2px; }
.chart-box { position: relative; height: 260px; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 9px 11px; font-size: 12.5px; transition: opacity .1s;
}
.chart-tip .tip-title { color: var(--text-3); margin-bottom: 5px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .tip-row span:nth-child(2) { flex: 1; color: var(--text-2); }
.chart-tip .tip-row b { font-weight: 500; font-variant-numeric: tabular-nums; }
.seg-bar { display: flex; gap: 2px; height: 28px; margin: 4px 0 18px; }
.seg { border-radius: 4px; min-width: 3px; display: flex; align-items: center; padding: 0 8px; font-size: 12px; font-weight: 500; overflow: hidden; white-space: nowrap; cursor: default; }
.seg:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.seg-legend { display: flex; flex-direction: column; }
.seg-row { display: grid; grid-template-columns: 14px 1fr auto 52px; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.seg-row:last-child { border-bottom: 0; }
.seg-row .n { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.seg-row .pct { font-variant-numeric: tabular-nums; color: var(--text-3); text-align: right; }
.hero-figure { display: flex; align-items: baseline; gap: 8px; }
.hero-figure .v { font-size: 30px; font-weight: 500; letter-spacing: -0.03em; line-height: 1.1; }
.hero-figure .l { color: var(--text-2); font-size: 13px; }
.hbar-row { display: grid; grid-template-columns: 110px 1fr minmax(56px, auto); align-items: center; gap: 12px; padding: 7px 0; font-size: 13px; }
.hbar-track { height: 14px; display: flex; align-items: center; }
.hbar { height: 14px; border-radius: 0 4px 4px 0; background: var(--viz-1); min-width: 2px; }
.hbar-row .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.seg-toggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg-toggle button { border: 0; background: var(--surface); color: var(--text-2); font: inherit; font-size: 12px; padding: 4px 10px; cursor: pointer; }
.seg-toggle button.on { background: var(--surface-3); color: var(--text); font-weight: 500; }
.chart-table { max-height: 260px; overflow: auto; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .filter-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-chat .inbox-list { display: none; }
  .inbox:not(.has-chat) .thread { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .docs { grid-template-columns: 1fr; }
  .docs-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .top-select { max-width: 120px; }
}
@media (max-width: 600px) {
  .page-head, .page-body, .split-main { padding-left: 16px; padding-right: 16px; }
  .grid-4, .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
  .search input { width: 100%; }
  .search { flex: 1; }
  .thread-body { padding: 14px 12px; }
  .hide-sm { display: none; }
}

/* ---------------------------------------------------------------- plan / trial */
.plan-banner { display: flex; align-items: center; gap: 10px; padding: 8px 24px; font-size: 13px; border-bottom: 1px solid var(--border); }
.plan-banner.info { background: var(--blue-soft); color: var(--blue); }
.plan-banner.warn { background: var(--amber-soft); color: var(--amber); }
.plan-banner span { flex: 1; min-width: 0; }
.plan-banner b { font-weight: 600; }
.plan-banner a { color: inherit; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.expired-card { max-width: 520px; margin: 48px auto; padding: 36px 32px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.expired-card h2 { margin: 6px 0 0; font-size: 20px; font-weight: 500; }
.expired-card p { margin: 0; line-height: 1.6; }
.support-box { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.plan-chip { display: inline-flex; flex-direction: column; gap: 1px; line-height: 1.3; }
.meter { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 6px; background: var(--primary); }
@media (max-width: 720px) { .plan-banner { padding: 8px 16px; flex-wrap: wrap; } }
/* Narrow, centred pages (Settings): a 900px column in the middle, with the title lined up above it. */
.page-narrow { --narrow: 900px; }
.page-narrow .page-body { max-width: var(--narrow); margin-inline: auto; }
.page-narrow .page-head { padding-inline: max(24px, calc(50% - var(--narrow) / 2 + 24px)); }
@media (max-width: 600px) { .page-narrow .page-head { padding-inline: 16px; } }

/* ---------------------------------------------------------------- small-screen menu */
.nav-toggle { display: none; align-self: center; font-size: 22px; margin-left: -6px; }
.nav-layer { position: fixed; inset: 0; z-index: 90; }
.nav-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 30, .45); opacity: 0; transition: opacity .2s; }
.nav-drawer {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
  display: flex; flex-direction: column; gap: 12px; padding: 0 12px 20px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  transform: translateX(-100%); transition: transform .22s ease;
}
.nav-layer.open .nav-backdrop { opacity: 1; }
.nav-layer.open .nav-drawer { transform: none; }
.nav-drawer-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  height: 52px; margin: 0 -12px; padding: 0 8px 0 16px; background: var(--top); }
.nav-drawer-head .brand { border: 0; padding: 0; }
.nav-drawer-head .icon-btn { font-size: 16px; }
.nav-user { display: flex; align-items: center; gap: 10px; padding: 4px 4px 0; min-width: 0; }
.nav-plan-slot:empty { display: none; }
.nav-plan-slot .menu-plan { margin: 0; color: var(--text); }
.nav-plan-slot .menu-plan:hover { text-decoration: none; background: var(--surface-3); }
.nav-device { display: flex; flex-direction: column; gap: 6px; padding: 0 4px; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-list a, .nav-list button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px;
  border: 0; border-radius: var(--radius-sm); background: none; font: inherit; font-size: 14px; color: var(--text); text-align: left; cursor: pointer;
}
.nav-list i { font-size: 16px; width: 18px; color: var(--text-2); }
.nav-list a:hover, .nav-list button:hover { background: var(--surface-3); text-decoration: none; }
.nav-list a.active { background: var(--primary-soft, var(--surface-3)); color: var(--primary); font-weight: 500; }
.nav-list a.active i { color: var(--primary); }
.nav-secondary { padding-top: 10px; border-top: 1px solid var(--border); }
html.nav-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .nav-drawer, .nav-backdrop { transition: none; } }

/* .compact is set from app.js whenever the tabs don't all fit in the top bar. */
.topbar.compact .nav-toggle { display: grid; }
.topbar.compact .tabs { display: none; }
.topbar.compact .brand { border-right: 0; padding-right: 0; }
.topbar.compact .top-actions { margin-left: auto; }
@media (max-width: 600px) {
  .topbar { padding: 0 10px; gap: 4px; }
  .topbar #deviceSwitch { display: none; }
  .topbar .brand-mark { width: 26px; height: 26px; font-size: 13px; }
  .plan-pill { padding: 0 8px; font-size: 12px; }
}
@media (max-width: 360px) { .topbar .brand > span:last-child { display: none; } }

.plan-pill { align-self: center; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; border: 1px solid rgba(255,255,255,.14); color: var(--top-text); background: rgba(255,255,255,.06); }
.plan-pill:hover { text-decoration: none; background: rgba(255,255,255,.12); }
.plan-pill.ok i { color: #4ade80; }
.plan-pill.trial i { color: #93c5fd; }
.plan-pill.warn { color: #fcd34d; border-color: rgba(252,211,77,.4); background: rgba(252,211,77,.1); }
.menu-plan { margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; }
.menu-plan b { font-weight: 600; }
.plan-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; text-align: left; }
.plan-tile { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.plan-tile .plan-name { font-weight: 500; }
.plan-tile .plan-price { font-size: 20px; font-weight: 500; letter-spacing: -.01em; }
.plan-tile .plan-price span { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 2px; }
.plan-tile ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.plan-tile li i { width: 18px; display: inline-block; color: var(--text-3); }
.expired-card:has(.plan-grid) { max-width: 760px; }

/* ---------------------------------------------------------------- campaigns */
.drawer.wide { width: min(640px, 100vw); }
.progress { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; display: flex; gap: 0; min-width: 90px; }
.progress > i { display: block; height: 100%; }
.cmp-builder { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; }
.cmp-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; align-self: start; position: sticky; top: 0; }
.cmp-preview .bubble { max-width: 100%; align-self: flex-end; background: var(--bubble-out, var(--primary-soft)); white-space: pre-wrap; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 20px; padding: 2px 9px; font: inherit; font-size: 12px; color: var(--text-2); cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary-text); }
.dropzone { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 16px; text-align: center; color: var(--text-3); font-size: 13px; cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--primary-text); background: var(--primary-soft); }
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-tiles > div { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat-tiles .v { font-size: 20px; font-weight: 500; }
.stat-tiles .l { font-size: 12px; color: var(--text-3); }
.tabs-inline { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs-inline button { border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--text-2); padding: 4px 10px; border-radius: 20px; cursor: pointer; }
.tabs-inline button.on { background: var(--primary-soft); color: var(--primary-text); font-weight: 500; }
@media (max-width: 760px) { .cmp-builder { grid-template-columns: 1fr; } .cmp-preview { position: static; } }
