/* ---------- Theme tokens ---------- */
:root {
  --accent: #22c55e;
  --accent-ink: #04130a;
  --accent-soft: color-mix(in oklab, var(--accent) 16%, transparent);
  --accent-line: color-mix(in oklab, var(--accent) 40%, transparent);
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0a0e13;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, color-mix(in oklab, var(--accent) 7%, transparent), transparent 60%);
  --surface: #121821;
  --surface-2: #171e29;
  --surface-3: #1e2733;
  --border: #232d3a;
  --border-strong: #2e3a4a;
  --text: #e8edf3;
  --text-2: #b4bfcc;
  --muted: #7d8a9b;
  --bubble-in: #1b2430;
  --bubble-out: color-mix(in oklab, var(--accent) 22%, #121821);
  --chat-bg: #0d1218;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.35);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #22c55e;
  --warn: #f5a524;
  --bad: #f2555a;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f3f5f8;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, color-mix(in oklab, var(--accent) 8%, transparent), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef1f5;
  --border: #e4e8ee;
  --border-strong: #d5dbe3;
  --text: #0f1722;
  --text-2: #3b4757;
  --muted: #6b7686;
  --bubble-in: #ffffff;
  --bubble-out: color-mix(in oklab, var(--accent) 18%, #ffffff);
  --chat-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(15,23,34,.04), 0 6px 20px rgba(15,23,34,.06);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--font);
  background: var(--bg-grad), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
.sub { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
i[data-icon] { display: inline-flex; font-style: normal; }
::selection { background: var(--accent-soft); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; border: 3px solid transparent; }

/* ---------- Shell ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 232px; flex: none; display: flex; flex-direction: column; gap: 8px;
  padding: 18px 14px; border-right: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 70%, transparent);
  backdrop-filter: blur(12px);
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), color-mix(in oklab, var(--accent) 55%, #0ea5e9));
  color: var(--accent-ink); box-shadow: 0 6px 18px color-mix(in oklab, var(--accent) 35%, transparent);
}
.logo-mark svg.logo-g, .logo-mark svg { width: 22px; height: 22px; }
.logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; border: 0; background: none; cursor: pointer; width: 100%;
  transition: background .15s, color .15s;
}
.nav a:hover, .nav-btn:hover { background: var(--surface-3); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--text); }
.nav a.on svg { color: var(--accent); }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.conn-summary {
  padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.conn-summary strong { color: var(--text); font-size: 13px; display: block; margin-bottom: 6px; }
.conn-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.conn-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn-dots span.ok { background: var(--good); box-shadow: 0 0 0 3px color-mix(in oklab, var(--good) 20%, transparent); }
.conn-dots span.wait { background: var(--warn); }
.conn-dots span.bad { background: var(--bad); }

.main { flex: 1; min-width: 0; min-height: 0; width: 100%; display: flex; overflow: hidden; }
.view { display: none; flex: 1; min-width: 0; overflow-y: auto; padding: 28px 32px 40px; flex-direction: column; gap: 20px; }
.view.on { display: flex; animation: fade .25s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 13.5px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: transform .1s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 6px 18px color-mix(in oklab, var(--accent) 28%, transparent);
}
.btn.primary:hover { background: color-mix(in oklab, var(--accent) 88%, white); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); background: transparent; border-color: color-mix(in oklab, var(--bad) 35%, transparent); }
.btn.danger:hover { background: color-mix(in oklab, var(--bad) 12%, transparent); }
.btn.lg { padding: 13px 18px; font-size: 15px; border-radius: 12px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center;
  background: none; border: 0; color: var(--text-2); cursor: pointer; flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.link { color: var(--accent); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 2px; background: none; border: 0; cursor: pointer; padding: 0; }
.link svg { width: 16px; height: 16px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); }
.seg button {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 13px; display: inline-flex; gap: 6px; align-items: center;
}
.seg button svg { width: 16px; height: 16px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

input[type=text], input[type=search], input[type=password], input[type=email], input:not([type]), textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span, .field .row > span { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.toggle { position: relative; width: 40px; height: 24px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; inset: 0; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--border-strong);
  cursor: pointer; transition: background .2s;
}
.toggle span::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-2); transition: transform .2s var(--ease), background .2s;
}
.toggle input:checked + span { background: var(--accent); border-color: transparent; }
.toggle input:checked + span::after { transform: translateX(16px); background: var(--accent-ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; }
.grid-2 + .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
  position: relative; overflow: hidden;
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.kpi-foot { font-size: 12px; color: var(--muted); }
.kpi.hero { background: linear-gradient(140deg, color-mix(in oklab, var(--accent) 22%, var(--surface)), var(--surface) 70%); border-color: var(--accent-line); }
.kpi.hero .kpi-icon { background: var(--accent); color: var(--accent-ink); }

/* Chart */
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.chart { height: 230px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar-1 { fill: var(--series-1); }
.chart .bar-2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: color-mix(in oklab, var(--text) 5%, transparent); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  font-size: 12px; min-width: 140px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 6px; color: var(--text); }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-2); }
.tooltip .tt-row b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--border); min-width: 0; }
.list li:first-child { border-top: 0; }
.list li.clickable { cursor: pointer; border-radius: 10px; padding: 10px 8px; }
.list li.clickable:hover { background: var(--surface-2); }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .right { text-align: right; font-size: 12px; color: var(--muted); flex: none; }
.list-empty { color: var(--muted); padding: 16px 4px; font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.connected { color: var(--good); background: color-mix(in oklab, var(--good) 14%, transparent); }
.pill.qr, .pill.connecting, .pill.reconnecting { color: var(--warn); background: color-mix(in oklab, var(--warn) 14%, transparent); }
.pill.logged_out, .pill.stopped { color: var(--bad); background: color-mix(in oklab, var(--bad) 14%, transparent); }
.acct-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--text-2);
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.acct-chip::before { content: ''; width: 8px; height: 8px; border-radius: 3px; background: var(--c, var(--muted)); flex: none; }

/* Avatars */
.avatar {
  --size: 42px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; position: relative;
  display: grid; place-items: center; font-weight: 600; color: #fff; font-size: calc(var(--size) * .38);
  background: var(--g, #475569);
}
.avatar.sm { --size: 34px; }
.avatar.lg { --size: 44px; }
.avatar .dot {
  position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--c); border: 2.5px solid var(--surface);
}
.avatar.square { border-radius: 12px; }

/* ---------- Inbox ---------- */
.view.inbox { padding: 0; gap: 0; flex-direction: row; overflow: hidden; }
.chatlist {
  width: 380px; flex: none; display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--border); background: var(--surface);
}
.chatlist-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 12px; }
.search {
  margin: 0 14px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; background: none; padding: 10px 0; box-shadow: none !important; }
.chips { display: flex; gap: 6px; padding: 12px 14px; overflow-x: auto; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 20px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.chip .d { width: 8px; height: 8px; border-radius: 3px; background: var(--c); }
.chip.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text); }
.chip .n { color: var(--muted); font-weight: 500; }

#chats { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
#chats li.chat {
  display: flex; gap: 12px; padding: 11px 10px; border-radius: 12px; cursor: pointer; align-items: center;
  transition: background .12s;
}
#chats li.chat:hover { background: var(--surface-2); }
#chats li.chat.on { background: var(--accent-soft); }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-top, .chat-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: 11.5px; flex: none; }
.chat-time.unread { color: var(--accent); font-weight: 600; }
.chat-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; flex: none;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.compact #chats li.chat { padding: 7px 10px; }
.compact .avatar { --size: 34px; }
.compact .chat-main .acct-chip { display: none; }

.conversation { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }
.conversation::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(color-mix(in oklab, var(--text) 6%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
.empty-state { margin: auto; text-align: center; max-width: 360px; padding: 24px; position: relative; color: var(--muted); }
.empty-state h3 { color: var(--text); margin: 14px 0 6px; font-size: 18px; }
.empty-state p { margin: 0; }
.empty-icon {
  width: 72px; height: 72px; border-radius: 22px; margin: 0 auto; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.empty-icon svg { width: 32px; height: 32px; }
#convo { display: flex; flex-direction: column; height: 100%; position: relative; }
.convo-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: color-mix(in oklab, var(--surface) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.convo-meta { min-width: 0; }
.convo-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 20px 8%; display: flex; flex-direction: column; gap: 3px; }
.day-sep { align-self: center; margin: 14px 0 8px; font-size: 11.5px; font-weight: 600; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); padding: 4px 12px; border-radius: 20px; }
.msg {
  max-width: min(68%, 560px); padding: 7px 10px 5px; border-radius: 14px; background: var(--bubble-in);
  align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; border: 1px solid var(--border);
  border-top-left-radius: 4px; animation: pop .18s var(--ease);
}
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-left-radius: 14px; border-top-right-radius: 4px; border-color: transparent; }
.msg.cont { border-radius: 14px; margin-top: -1px; }
@keyframes pop { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.msg .who { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg img, .msg video { max-width: 100%; max-height: 340px; border-radius: 10px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 280px; display: block; }
.msg .doc { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: var(--surface-3); margin-bottom: 4px; }
.msg .tag { color: var(--muted); font-style: italic; }

.composer { padding: 12px 18px 16px; background: color-mix(in oklab, var(--surface) 85%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 11px 14px; border-radius: 22px; line-height: 1.4;
  background: var(--surface-2);
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; transition: transform .1s, opacity .15s;
  box-shadow: 0 6px 16px color-mix(in oklab, var(--accent) 30%, transparent);
}
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { opacity: .5; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 10px 46px; padding: 6px 6px 6px 12px;
  border-radius: 20px; background: var(--surface-3); font-size: 12.5px; max-width: calc(100% - 46px);
}
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-only { display: none; }

/* ---------- Status ---------- */
.status-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.status-compose { gap: 18px; }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 22px; cursor: pointer;
  display: flex; align-items: center; gap: 14px; color: var(--text-2); transition: border-color .15s, background .15s;
}
.dropzone svg { width: 28px; height: 28px; color: var(--accent); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-file { border-style: solid; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
  background: var(--c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); transition: transform .12s;
}
.swatches button:hover { transform: scale(1.08); }
.swatches button.on { border-color: var(--text); box-shadow: 0 0 0 3px var(--surface), inset 0 0 0 1px rgba(255,255,255,.1); }
.swatches label.custom {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); color: var(--muted);
}
.swatches label.custom svg { width: 16px; height: 16px; }
.swatches input[type=color] { position: absolute; opacity: 0; width: 0; height: 0; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 10px; }
.pick {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); transition: all .15s; position: relative;
}
.pick input { position: absolute; opacity: 0; }
.pick .check {
  margin-left: auto; width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--border-strong);
  display: grid; place-items: center; color: transparent; flex: none;
}
.pick .check svg { width: 14px; height: 14px; stroke-width: 3; }
.pick:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
.pick:has(input:checked) .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pick.off { opacity: .5; cursor: not-allowed; }
.pick .grow { min-width: 0; }
.pick .title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .meta { color: var(--muted); font-size: 12px; }
.results { display: flex; flex-direction: column; gap: 6px; }
.result { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.result svg { width: 16px; height: 16px; }
.result.ok svg { color: var(--good); }
.result.err { color: var(--bad); }
.status-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.status-side { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; }

/* Status history */
.count-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center;
}
#status-history-card { scroll-margin-top: 16px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.h-item {
  display: flex; gap: 14px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
}
.h-thumb {
  width: 64px; height: 88px; border-radius: 10px; flex: none; display: grid; place-items: center; overflow: hidden;
  color: #fff; font-size: 9px; font-weight: 600; line-height: 1.2; text-align: center; padding: 6px; word-break: break-word;
}
.h-thumb.media { background: linear-gradient(135deg, #3b82f6, #8b5cf6); }
.h-thumb.media svg { width: 24px; height: 24px; }
.h-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.h-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.h-type { font-weight: 600; text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }
.h-text { font-weight: 500; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.h-stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.h-stats span { display: inline-flex; align-items: center; gap: 5px; }
.h-stats svg { width: 14px; height: 14px; }
.h-outcome.ok { color: var(--good); }
.h-outcome.partial { color: var(--warn); }
.h-outcome.err { color: var(--bad); }
.h-accounts { display: flex; gap: 6px; flex-wrap: wrap; }
.h-acc {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 20px;
  background: var(--surface-3); color: var(--text-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.h-acc i { width: 7px; height: 7px; border-radius: 2px; background: var(--c); flex: none; }
.h-acc.err { color: var(--bad); background: color-mix(in oklab, var(--bad) 12%, transparent); }
.h-when { display: inline-flex; align-items: center; gap: 4px; }
.h-delete { width: 28px; height: 28px; margin: -6px -6px -6px 0; color: var(--muted); }
.h-delete svg { width: 15px; height: 15px; }
.h-delete:hover { color: var(--bad); background: color-mix(in oklab, var(--bad) 12%, transparent); }
.h-live {
  margin-left: 8px; padding: 1px 7px; border-radius: 10px; font-size: 10px; letter-spacing: .04em;
  color: var(--good); background: color-mix(in oklab, var(--good) 14%, transparent);
}
.h-views {
  display: inline-flex; align-items: center; gap: 5px; border: 0; cursor: pointer; font-size: 12.5px;
  padding: 3px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--text);
}
.h-views svg { width: 14px; height: 14px; color: var(--accent); }
.h-views:hover { background: color-mix(in oklab, var(--accent) 26%, transparent); }
.h-untracked { color: var(--muted); font-style: italic; }
.list.viewers li { padding: 9px 2px; }
.history-empty { display: flex; gap: 14px; align-items: center; padding: 18px 8px; color: var(--text-2); }
.history-empty svg { width: 28px; height: 28px; color: var(--muted); }

.phone {
  width: 260px; margin: 0 auto; aspect-ratio: 9 / 17.5; border-radius: 38px; padding: 10px; position: relative;
  background: linear-gradient(160deg, #2a3240, #10151c); box-shadow: 0 20px 50px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.08);
}
.phone-notch { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); width: 80px; height: 22px; border-radius: 12px; background: #000; z-index: 2; }
.phone-screen {
  width: 100%; height: 100%; border-radius: 30px; overflow: hidden; position: relative;
  display: grid; place-items: center; padding: 28px 22px; text-align: center;
  color: #fff; font-size: 22px; font-weight: 600; line-height: 1.3; transition: background .25s;
}
.phone-bars { position: absolute; top: 46px; left: 14px; right: 14px; display: flex; gap: 4px; z-index: 2; }
.phone-bars i { flex: 1; height: 2.5px; border-radius: 2px; background: rgba(255,255,255,.4); }
.phone-bars i:first-child { background: #fff; }
.phone-screen img, .phone-screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#status-preview-text { position: relative; white-space: pre-wrap; word-break: break-word; max-height: 100%; overflow: hidden; }
.phone-screen.media #status-preview-text {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 13px; font-weight: 500; padding: 40px 16px 22px;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
}

/* ---------- Accounts ---------- */
.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 18px; }
.acct-card { gap: 16px; }
.acct-card .top { display: flex; gap: 12px; align-items: center; }
.acct-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.acct-card .stat { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.acct-card .stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.acct-card .stat span { font-size: 11.5px; color: var(--muted); }
.acct-card .actions { display: flex; gap: 8px; align-items: center; }
.acct-card .actions .icon-btn.danger { margin-left: auto; color: var(--bad); }
.acct-card .actions .icon-btn.danger:hover { background: color-mix(in oklab, var(--bad) 12%, transparent); }
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; border-radius: 12px; background: var(--surface-2); }
.qr-wrap img { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; }
.qr-wrap ol { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.acct-empty { grid-column: 1 / -1; text-align: center; padding: 48px 20px; }

/* ---------- Modal / toasts ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(4, 8, 12, .55); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px; animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.45);
  padding: 22px; display: flex; flex-direction: column; gap: 16px;
}
.modal.wide { max-width: 560px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.settings-group { display: flex; flex-direction: column; gap: 10px; }
.settings-group h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.theme-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-opt {
  border: 1.5px solid var(--border); border-radius: 12px; padding: 8px; cursor: pointer; background: var(--surface-2);
  display: flex; flex-direction: column; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; color: var(--text-2);
}
.theme-opt.on { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-prev { width: 100%; height: 56px; border-radius: 8px; display: flex; gap: 4px; padding: 6px; overflow: hidden; }
.theme-prev i { border-radius: 4px; }
.theme-prev.dark { background: #0a0e13; }
.theme-prev.dark i:first-child { width: 22%; background: #171e29; }
.theme-prev.dark i:last-child { flex: 1; background: #121821; }
.theme-prev.light { background: #f3f5f8; }
.theme-prev.light i:first-child { width: 22%; background: #e4e8ee; }
.theme-prev.light i:last-child { flex: 1; background: #fff; }
.theme-prev.system { background: linear-gradient(90deg, #0a0e13 50%, #f3f5f8 50%); }
.theme-prev.system i { flex: 1; background: transparent; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--border); }
.setting-row:first-of-type { border-top: 0; }
.setting-row .t { font-weight: 600; }
.setting-row .d { font-size: 12.5px; color: var(--muted); }
.accent-opts { display: flex; gap: 10px; flex-wrap: wrap; }
.accent-opts button {
  width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer; background: var(--c);
  display: grid; place-items: center; color: #fff;
}
.accent-opts button.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.accent-opts svg { width: 14px; height: 14px; stroke-width: 3; }

.pw-field { position: relative; }
.pw-field input { padding-right: 44px; }
.pw-field .icon-btn { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); }
.strength { display: flex; align-items: center; gap: 10px; }
.strength-bar { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.strength-bar i { display: block; height: 100%; width: 0; border-radius: 3px; transition: width .25s var(--ease), background .25s; }
.strength .sub { margin: 0; font-size: 12px; min-width: 120px; text-align: right; }
.form-error {
  padding: 10px 12px; border-radius: 10px; font-size: 13px; color: var(--bad);
  background: color-mix(in oklab, var(--bad) 12%, transparent); border: 1px solid color-mix(in oklab, var(--bad) 30%, transparent);
}
#sign-out:hover { color: var(--bad); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px; max-width: 360px;
  background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 13px;
  animation: slide .25s var(--ease);
}
.toast svg { width: 16px; height: 16px; }
.toast.ok svg { color: var(--good); }
.toast.err svg { color: var(--bad); }
.toast.leave { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes slide { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Mobile tab bar ---------- */
.tabbar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .sidebar { width: 76px; padding: 18px 10px; align-items: center; }
  .logo { padding: 4px 0 18px; }
  .logo-text, .nav span, .nav-btn span, .conn-summary { display: none; }
  .nav a, .nav-btn { justify-content: center; padding: 11px; position: relative; }
  .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; font-size: 10px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2 + .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .status-layout { grid-template-columns: minmax(0, 1fr); }
  .status-side { position: static; }
  .chatlist { width: 330px; }
}
@media (max-width: 760px) {
  /* 16px stops iOS Safari from zooming in when a field is focused */
  input, textarea, select { font-size: 16px !important; }
  .app { flex-direction: column; }
  body.in-convo .tabbar { display: none; }
  body.in-convo .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .convo-head { padding: 10px 12px; }
  .chatlist-head { padding: 16px 16px 10px; }
  /* Modals become bottom sheets */
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal {
    max-width: none; border-radius: 20px 20px 0 0; border-bottom: 0; max-height: 92dvh;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: sheet .25s var(--ease);
  }
  .modal::before { content: ''; width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); align-self: center; margin: -6px 0 2px; }
  .modal-actions .btn { flex: 1; padding: 12px; }
  .theme-opts { gap: 8px; }
  .setting-row { align-items: center; }
  .page-head .sub { font-size: 12.5px; }
  .pick-grid { grid-template-columns: minmax(0, 1fr); }
  .qr-wrap img { width: min(240px, 70vw); height: auto; aspect-ratio: 1; }
  .tooltip { max-width: calc(100vw - 32px); }
  .sidebar { display: none; }
  .main { min-height: 0; }
  .view { padding: 20px 16px 28px; }
  h1 { font-size: 21px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 24px; }
  .kpi-top .kpi-icon { display: none; }
  .phone { width: 220px; }
  .chatlist { width: 100%; border-right: 0; }
  .conversation { display: none; }
  .inbox.show-convo .chatlist { display: none; }
  .inbox.show-convo .conversation { display: flex; }
  .mobile-only { display: inline-grid; }
  .messages { padding: 14px 12px; }
  .msg { max-width: 86%; }
  .composer { padding: 10px 12px; }
  .tabbar {
    display: flex; flex: none; border-top: 1px solid var(--border); background: var(--surface);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
    font-size: 10.5px; font-weight: 600; color: var(--muted); background: none; border: 0; position: relative; cursor: pointer;
  }
  .tabbar a.on { color: var(--accent); }
  .tabbar .nav-badge { position: absolute; top: 0; left: calc(50% + 4px); right: auto; width: max-content; margin: 0; min-width: 16px; height: 16px; padding: 0 4px; font-size: 9.5px; }
  .toasts { left: 16px; right: 16px; bottom: 80px; align-items: stretch; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
}
@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
