/* Tokens ------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --canvas: #e9eeeb;
  --surface: #fbfcfb;
  --surface-raised: #ffffff;
  --sunken: #e0e7e3;
  --ink: #16221e;
  --ink-soft: #33433d;
  --muted: #5c6b65;
  --line: #d2dbd6;
  --line-strong: #b9c6bf;
  --accent: #256b5f;
  --accent-hover: #1d574d;
  --accent-soft: #d6e9e3;
  --accent-ink: #ffffff;
  --bubble-out: #d9ece5;
  --ok: #2b7a4a;
  --ok-soft: #dbefe2;
  --warn: #a8600b;
  --warn-soft: #f8e9cf;
  --danger: #b3362f;
  --danger-soft: #f6dcd9;
  --info: #35589a;
  --info-soft: #dfe6f5;
  --avatar-lightness: 82%;
  --avatar-ink: #1e2d28;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  --shadow-float: 0 12px 32px -12px rgb(16 32 26 / 0.35), 0 2px 6px rgb(16 32 26 / 0.08);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --radius-small: 6px;
  --radius: 10px;
  --sidebar-width: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #0f1513;
    --surface: #151d1a;
    --surface-raised: #1b2521;
    --sunken: #0b100e;
    --ink: #dce6e1;
    --ink-soft: #b9c7c0;
    --muted: #8b9b94;
    --line: #25332d;
    --line-strong: #34463e;
    --accent: #5cb6a3;
    --accent-hover: #74c6b4;
    --accent-soft: #1d3a33;
    --accent-ink: #0b1a16;
    --bubble-out: #1c3a32;
    --ok: #63bf86;
    --ok-soft: #173325;
    --warn: #e2a54b;
    --warn-soft: #3a2a12;
    --danger: #e86b62;
    --danger-soft: #3c1b19;
    --info: #86a6e3;
    --info-soft: #1c2740;
    --avatar-lightness: 30%;
    --avatar-ink: #e6efea;
    --shadow-float: 0 16px 40px -12px rgb(0 0 0 / 0.7), 0 2px 6px rgb(0 0 0 / 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f1513;
  --surface: #151d1a;
  --surface-raised: #1b2521;
  --sunken: #0b100e;
  --ink: #dce6e1;
  --ink-soft: #b9c7c0;
  --muted: #8b9b94;
  --line: #25332d;
  --line-strong: #34463e;
  --accent: #5cb6a3;
  --accent-hover: #74c6b4;
  --accent-soft: #1d3a33;
  --accent-ink: #0b1a16;
  --bubble-out: #1c3a32;
  --ok: #63bf86;
  --ok-soft: #173325;
  --warn: #e2a54b;
  --warn-soft: #3a2a12;
  --danger: #e86b62;
  --danger-soft: #3c1b19;
  --info: #86a6e3;
  --info-soft: #1c2740;
  --avatar-lightness: 30%;
  --avatar-ink: #e6efea;
  --shadow-float: 0 16px 40px -12px rgb(0 0 0 / 0.7), 0 2px 6px rgb(0 0 0 / 0.4);
}

/* Base -------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-small); }
code, .mono { font-family: var(--font-mono); font-size: 0.95em; }
.numeric { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.align-end { text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; }

/* Shell ------------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100dvh;
}
.view {
  overflow-y: auto;
  padding: 28px clamp(16px, 3vw, 40px) 48px;
  outline: none;
}
.view > * { max-width: 1240px; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}
.sidebar-top { display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); padding: 2px 6px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 8px; background: var(--accent); color: var(--accent-ink);
}
.brand-mark .icon { width: 18px; height: 18px; stroke-width: 2.4; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }

.connection-badge {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--ink);
}
.connection-badge:hover { text-decoration: none; border-color: var(--line-strong); }
.badge-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.badge-state { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-account { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--ink-soft); font-weight: 500;
}
.nav-link:hover { background: var(--sunken); text-decoration: none; color: var(--ink); }
.nav-link.is-active { background: var(--accent-soft); color: var(--ink); }
.nav-link.is-active .icon { color: var(--accent); }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.sidebar-tool {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); text-align: left;
}
.sidebar-tool:hover { background: var(--sunken); color: var(--ink); }
.stream-state { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; font-size: 12px; color: var(--muted); }
.stream-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); margin: 0 5px; }
.stream-state[data-state="live"] .stream-dot { background: var(--ok); }
.stream-state[data-state="reconnecting"] .stream-dot { background: var(--warn); animation: blink 1.2s steps(2) infinite; }

/* The signal lamp: the one expressive element, reused at two sizes. */
.signal {
  position: relative; flex: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line-strong);
}
.signal-open { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent); }
.signal-qr, .signal-connecting { background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 22%, transparent); }
.signal-close, .signal-logged_out { background: var(--danger); box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 20%, transparent); }
.signal-open::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--ok); opacity: 0; animation: ripple 2.8s ease-out infinite;
}
.signal-qr, .signal-connecting { animation: blink 1.6s ease-in-out infinite; }
.signal-large { width: 22px; height: 22px; }
.signal-large.signal-open { box-shadow: 0 0 0 7px color-mix(in srgb, var(--ok) 20%, transparent); }
@keyframes ripple { 0% { transform: scale(0.8); opacity: 0.7; } 100% { transform: scale(2.4); opacity: 0; } }
@keyframes blink { 50% { opacity: 0.35; } }

/* Page scaffolding -------------------------------------------------------- */
.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px;
  margin-bottom: 22px;
}
.page-header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.page-subtitle { color: var(--muted); margin-top: 4px; max-width: 62ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.panel + .panel { margin-top: 16px; }
.panel-title { font-size: 15px; font-weight: 650; margin-bottom: 10px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head .panel-title { margin: 0; }
.panel-text { color: var(--muted); margin-bottom: 12px; max-width: 64ch; }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 12px; }
.list-count { font-size: 12px; margin-bottom: 8px; min-height: 18px; }

/* Controls ---------------------------------------------------------------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface-raised); color: var(--ink);
  font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background-color 120ms, border-color 120ms;
}
.button:hover { border-color: var(--muted); text-decoration: none; }
.button:disabled { opacity: 0.55; cursor: progress; }
.button .icon { width: 16px; height: 16px; }
.button-small { height: 28px; padding: 0 10px; font-size: 13px; }
.button-block { width: 100%; }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button-danger:hover { filter: brightness(1.08); border-color: var(--danger); }
.button-danger-quiet { color: var(--danger); }
.button-danger-quiet:hover { border-color: var(--danger); background: var(--danger-soft); }
.button.is-busy { position: relative; color: transparent; }
.button.is-busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); border-right-color: transparent; animation: spin 0.7s linear infinite;
}
.button-row { display: flex; flex-wrap: wrap; gap: 6px; }
.link-button { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; margin-left: 10px; font-size: 13px; font-weight: 500; }
.link-button:hover { text-decoration: underline; }
.link-quiet { color: var(--muted); font-size: 13px; }
.icon-button {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 8px; color: var(--ink-soft);
}
.icon-button:hover { background: var(--sunken); }

input[type="text"], input[type="search"], input[type="tel"], input[type="url"], input[type="password"], input:not([type]), textarea, select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-raised);
  min-height: 34px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
.input-compact { max-width: 240px; min-height: 30px; padding: 4px 10px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-weight: 550; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.field-hint { font-size: 12px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

.search-field { position: relative; flex: 1 1 260px; max-width: 380px; }
.search-field .icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--muted); }
.search-field input { padding-left: 34px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunken); border-radius: 9px; }
.segment {
  border: 0; background: none; padding: 5px 12px; border-radius: 7px;
  color: var(--muted); font-weight: 550; cursor: pointer;
}
.segment:hover { color: var(--ink); }
.segment[aria-selected="true"] { background: var(--surface-raised); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track {
  width: 36px; height: 20px; border-radius: 10px; background: var(--line-strong);
  position: relative; transition: background-color 150ms;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); transition: transform 150ms;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch-with-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 550; font-size: 13px; }

.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.checkbox input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.checkbox-description { display: block; color: var(--muted); font-size: 13px; }
.checkbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.pill {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
  border-radius: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; vertical-align: 1px;
  background: var(--sunken); color: var(--ink-soft);
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-strong { background: var(--ink); color: var(--surface); }
.pill-row { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.type-badge {
  display: inline-block; margin-bottom: 3px; padding: 0 6px; border-radius: 4px;
  font-size: 11.5px; font-weight: 600; color: var(--info); background: var(--info-soft);
}

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: hsl(var(--avatar-hue) 32% var(--avatar-lightness));
  color: var(--avatar-ink); font-weight: 650; font-size: 13px;
}
.avatar-small { width: 26px; height: 26px; font-size: 11px; }
.avatar-large { width: 48px; height: 48px; font-size: 17px; }
.avatar-photo { object-fit: cover; background: var(--sunken); }

/* Feedback ---------------------------------------------------------------- */
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state { display: flex; align-items: center; gap: 10px; padding: 28px 4px; color: var(--muted); list-style: none; }
.boot-screen { display: flex; height: 100dvh; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }

.empty-state {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 32px 4px; max-width: 52ch; list-style: none;
}
.empty-title { font-weight: 650; font-size: 15px; }
.empty-body { color: var(--muted); margin-bottom: 8px; }
.empty-state-error .empty-title { color: var(--danger); }

.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 10px 14px; border-radius: 9px; background: var(--ink); color: var(--surface);
  box-shadow: var(--shadow-float); font-weight: 500; border-left: 4px solid var(--muted);
  animation: toast-in 180ms ease-out;
}
.toast-success { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--danger); }
.toast-leaving { opacity: 0; transform: translateY(6px); transition: opacity 300ms, transform 300ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 22px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-float);
}
.confirm-dialog::backdrop { background: rgb(10 18 15 / 0.45); }
.confirm-dialog h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.confirm-target { font-weight: 600; color: var(--accent); margin-bottom: 10px; overflow-wrap: anywhere; }
.confirm-body {
  color: var(--ink-soft); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 200px; overflow: auto; padding: 10px 12px; background: var(--sunken); border-radius: 8px;
}
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Login ------------------------------------------------------------------- */
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.login-card h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
.login-hint { color: var(--muted); margin-bottom: 20px; }

/* Connection -------------------------------------------------------------- */
.hero-panel {
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px 40px; align-items: center;
  padding: 26px 28px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  border-left: 5px solid var(--line-strong);
}
.hero-panel[data-connection="open"] { border-left-color: var(--ok); }
.hero-panel[data-connection="qr"], .hero-panel[data-connection="connecting"] { border-left-color: var(--warn); }
.hero-panel[data-connection="close"], .hero-panel[data-connection="logged_out"] { border-left-color: var(--danger); }
.hero-state { display: flex; align-items: center; gap: 22px; }
.hero-word { font-size: clamp(30px, 4vw, 44px); font-weight: 750; letter-spacing: -0.035em; line-height: 1.05; }
.hero-explanation { color: var(--muted); margin-top: 6px; max-width: 48ch; }
.hero-facts { margin: 0; display: grid; gap: 10px; }
.hero-facts div, .fact-list div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; align-items: baseline; }
.hero-facts dt, .fact-list dt { color: var(--muted); font-size: 13px; }
.hero-facts dd, .fact-list dd { margin: 0; overflow-wrap: anywhere; }

.metrics {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
.metric { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; color: var(--ink); border-right: 1px solid var(--line); }
.metric:nth-child(6) { border-right: 0; }
a.metric:hover { background: var(--sunken); text-decoration: none; }
.metric-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.metric-label { font-size: 12.5px; color: var(--muted); }
.metric-warn .metric-value { color: var(--warn); }
.metric-danger .metric-value { color: var(--danger); }
.metrics-note { grid-column: 1 / -1; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--warn-soft); color: var(--ink-soft); font-size: 13px; }

.link-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 28px; align-items: start; }
.qr-frame {
  width: 296px; min-height: 296px; padding: 16px; display: grid; place-items: center;
  background: #fff; border-radius: 12px; border: 1px solid var(--line);
}
.qr-frame .loading-state, .qr-placeholder { color: #5c6b65; text-align: center; padding: 16px; }
.qr-image { width: 264px; height: 264px; image-rendering: pixelated; display: block; }
.pair-form { max-width: 420px; }
.pair-form .field { margin-top: 4px; }
.pairing-code { margin-top: 20px; padding: 16px; border-radius: var(--radius); background: var(--accent-soft); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.pairing-code-label { font-size: 13px; color: var(--ink-soft); }
.pairing-code-value { font-family: var(--font-mono); font-size: 36px; font-weight: 700; letter-spacing: 0.12em; line-height: 1.1; }

/* Lists ------------------------------------------------------------------- */
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.list-flush { border: 0; background: none; max-height: 480px; overflow-y: auto; margin: 0 -8px; }
.list-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px;
  padding: 8px 16px 8px 12px; border-bottom: 1px solid var(--line);
}
.list-flush .list-row { grid-template-columns: minmax(0, 1fr); padding: 6px 8px; border-bottom: 0; border-radius: 8px; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
.list-row.is-watched { box-shadow: inset 3px 0 0 var(--accent); }
.list-row-main { display: flex; align-items: center; gap: 12px; min-width: 0; color: var(--ink); }
.list-row-main:hover { text-decoration: none; }
.list-row-main:hover .list-row-title { color: var(--accent); }
.list-row-text { display: flex; flex-direction: column; min-width: 0; }
.list-row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-time { font-size: 12px; color: var(--muted); min-width: 48px; text-align: right; }
.list-row.has-activity .list-row-time { color: var(--accent); font-weight: 650; }
.list .empty-state, .list .loading-state { padding-left: 18px; }

.compact-list { list-style: none; margin: 0; padding: 0; }
.compact-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.compact-list li:last-child { border-bottom: 0; }

/* Tables ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.panel .data-table { border-radius: 8px; }
.data-table th {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--canvas);
}
.data-table th:first-child { border-top-left-radius: var(--radius); }
.data-table th:last-child { border-top-right-radius: var(--radius); }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: color-mix(in srgb, var(--sunken) 45%, transparent); }
.data-table .th-numeric, .data-table th.align-end { text-align: right; }
.data-table-compact { margin-top: 8px; }
.table-primary { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; }
a.table-primary:hover { color: var(--accent); text-decoration: none; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .button + .button { margin-left: 6px; }
.table-empty { padding: 20px 12px; }

.delivery-row.is-expanded td { background: var(--sunken); border-bottom-color: transparent; }
.delivery-detail td { background: var(--sunken); padding: 4px 16px 16px; }
.expand-button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer; padding: 2px 0; color: var(--ink); }
.expand-icon { width: 14px; height: 14px; color: var(--muted); transform: rotate(-90deg); transition: transform 150ms; }
.expand-button[aria-expanded="true"] .expand-icon { transform: none; }
.json-block {
  margin: 8px 0 0; padding: 14px 16px; max-height: 420px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  font: 12.5px/1.55 var(--font-mono); white-space: pre; color: var(--ink-soft);
}
.detail-facts { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 6px 0; font-size: 13px; }
.detail-facts div { display: flex; gap: 8px; }
.detail-facts dt { color: var(--muted); }
.detail-facts dd { margin: 0; }
.data-table-deliveries td[data-label="Next"], .data-table-deliveries td[data-label="Created"] { white-space: nowrap; }
.data-table-deliveries td[data-label="Last response"] { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attempt-unit { display: none; }
.load-more { display: flex; justify-content: center; padding: 16px; }

/* Chat -------------------------------------------------------------------- */
.view.view-chat { padding: 0; overflow: hidden; display: flex; }
.view.view-chat > * { max-width: none; }
.chat-view { display: flex; flex-direction: column; flex: 1; min-width: 0; height: 100%; position: relative; }
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 12px clamp(12px, 2.5vw, 28px);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.chat-heading { min-width: 0; flex: 1; }
.chat-heading h1 { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-heading p { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header-actions { display: flex; align-items: center; gap: 14px; }
.chat-notice { padding: 8px clamp(12px, 2.5vw, 28px); background: var(--warn-soft); color: var(--ink-soft); font-size: 13px; border-bottom: 1px solid var(--line); }
.message-scroll { flex: 1; overflow-y: auto; padding: 16px clamp(12px, 2.5vw, 28px) 20px; overscroll-behavior: contain; }
.message-list { display: flex; flex-direction: column; gap: 4px; max-width: 920px; margin: 0 auto; }
.older-zone { display: flex; justify-content: center; padding-bottom: 12px; }
.message {
  max-width: min(72%, 620px); padding: 7px 11px 5px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); align-self: flex-start;
  overflow-wrap: anywhere;
}
.message-out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; }
.message-sender { font-size: 12.5px; font-weight: 650; color: var(--accent); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.message-sender-phone { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.message-text { white-space: pre-wrap; }
.message-quote {
  margin: 2px 0 5px; padding: 4px 8px; border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--sunken) 70%, transparent); border-radius: 4px;
  color: var(--muted); font-size: 13px; white-space: pre-wrap; max-height: 4.5em; overflow: hidden;
}
.message-time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 1px; }
.day-separator { display: flex; justify-content: center; margin: 14px 0 8px; }
.day-separator span { font-size: 12px; color: var(--muted); padding: 2px 10px; background: var(--sunken); border-radius: 10px; }
.new-messages-pill {
  position: absolute; left: 50%; bottom: 84px; translate: -50% 0;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 16px;
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; box-shadow: var(--shadow-float);
}
.composer {
  display: flex; gap: 10px; align-items: flex-end; padding: 12px clamp(12px, 2.5vw, 28px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea { resize: none; min-height: 38px; max-height: 200px; }
.composer-send { height: 38px; }

/* Groups ------------------------------------------------------------------ */
.group-header { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.group-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.group-subject { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: anywhere; }
.group-description { color: var(--ink-soft); white-space: pre-wrap; max-width: 75ch; overflow-wrap: anywhere; }
.inline-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 640px; }
.inline-edit input { flex: 1 1 260px; font-size: 18px; font-weight: 600; }
.inline-edit-stacked { flex-direction: column; align-items: stretch; }
.inline-edit-actions { display: flex; gap: 8px; }
.group-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.group-rail .panel + .panel, .group-main .panel + .panel { margin-top: 16px; }
.fact-list { margin: 0 0 14px; display: grid; gap: 8px; }
.fact-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.settings-list { list-style: none; margin: 0; padding: 0; }
.settings-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.settings-list li:last-child { border-bottom: 0; }
.invite-link { padding: 10px 12px; margin-bottom: 10px; background: var(--sunken); border-radius: 8px; overflow-wrap: anywhere; font-size: 13px; }
.request-list { list-style: none; margin: 0 0 10px; padding: 0; }
.request-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.request-who { display: flex; flex-direction: column; font-size: 13px; }
.add-participants { display: flex; gap: 10px; align-items: flex-end; margin-top: 16px; }
.add-participants .field { flex: 1; margin: 0; }

/* Contacts ---------------------------------------------------------------- */
.contacts-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.contacts-layout .panel + .panel { margin-top: 0; }
.inline-form { display: flex; gap: 8px; }
.lookup-result { display: flex; gap: 14px; align-items: flex-start; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.lookup-missing { color: var(--ink-soft); }
.lookup-details { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lookup-name { font-weight: 650; font-size: 15px; }
.lookup-status { color: var(--ink-soft); font-style: italic; }
.lookup-details .button-row { margin-top: 8px; }

/* Settings ---------------------------------------------------------------- */
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.settings-form { max-width: 720px; }
.form-footer { display: flex; justify-content: flex-end; margin-top: 16px; }

/* Responsive -------------------------------------------------------------- */
@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .group-layout, .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .contacts-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .hero-panel { grid-template-columns: minmax(0, 1fr); }
  .link-grid { grid-template-columns: minmax(0, 1fr); }
  .qr-frame { justify-self: center; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sidebar {
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 10px;
    padding: 10px 16px 0; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar-top { flex-direction: row; align-items: center; flex: 1; min-width: 0; gap: 10px; }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .connection-badge { padding: 5px 10px; flex: 1; min-width: 0; }
  .sidebar-footer { order: 2; margin: 0; flex-direction: row; }
  .stream-state { display: none; }
  .sidebar-tool { padding: 8px; }
  .sidebar-tool-label { display: none; }
  .nav {
    order: 3; flex-basis: 100%; flex-direction: row; overflow-x: auto; gap: 0;
    margin: 0 -16px; padding: 0 10px; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 10px 10px 11px; border-radius: 0; flex: none; border-bottom: 2px solid transparent; gap: 6px; }
  .nav-link .icon { display: none; }
  .nav-link.is-active { background: none; border-bottom-color: var(--accent); }
  .view { padding: 20px 16px 40px; }
  .page-header h1 { font-size: 22px; }

  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--line); }
  .metric:nth-child(odd) { border-right: 1px solid var(--line); }
  .metric:nth-child(even) { border-right: 0; }
  .hero-panel { padding: 20px; }
  .hero-facts div, .fact-list div { grid-template-columns: 110px minmax(0, 1fr); }
  .qr-frame { width: 100%; max-width: 296px; min-height: 0; }
  .qr-image { width: 100%; height: auto; }
  .pairing-code-value { font-size: 30px; }

  .search-field { max-width: none; }
  .segmented { width: 100%; }
  .segment { flex: 1; padding: 6px 4px; }
  .list-row { gap: 10px; padding-right: 12px; }

  /* Wide tables collapse into stacked records on phones. */
  .data-table-groups thead, .data-table-participants thead, .data-table-deliveries thead { display: none; }
  .data-table-groups tr, .data-table-participants tr, .data-table-deliveries tr.delivery-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 12px; border-bottom: 1px solid var(--line);
  }
  .data-table-groups tbody tr:last-child, .data-table-participants tbody tr:last-child { border-bottom: 0; }
  .data-table-groups td, .data-table-participants td, .data-table-deliveries tr.delivery-row td { padding: 0; border: 0; background: none !important; }
  .data-table-groups td[data-label="Group"], .data-table-participants td[data-label="Name"] { grid-column: 1; }
  .data-table-groups td[data-label="Watch"] { grid-column: 2; grid-row: 1; align-self: center; }
  .data-table-groups td[data-label="Members"]::after { content: " members"; color: var(--muted); }
  .data-table-groups td[data-label="Members"] { text-align: left; font-size: 13px; }
  .data-table-groups td[data-label="Created"], .data-table-groups td[data-label="Messages"] { display: none; }
  .data-table-participants td[data-label="Role"] { grid-column: 2; grid-row: 1; }
  .data-table-participants td[data-label="Phone"] { font-size: 12px; color: var(--muted); }
  .data-table-participants td.row-actions { grid-column: 1 / -1; text-align: left; padding-top: 4px; }
  .data-table-deliveries td[data-label="Status"] { grid-column: 2; grid-row: 1; }
  .data-table-deliveries td[data-label="Event"] { grid-column: 1; grid-row: 1; }
  .data-table-deliveries tr.delivery-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .data-table-deliveries td[data-label="Status"], .data-table-deliveries td[data-label="Next"] { justify-self: end; text-align: right; }
  .data-table-deliveries td[data-label="Next"], .data-table-deliveries td[data-label="Last response"] { white-space: normal; max-width: none; }
  .attempt-unit { display: inline; color: var(--muted); }
  .data-table-deliveries td[data-label="Attempts"] { text-align: left; }
  .data-table-deliveries td { font-size: 13px; }
  .data-table-deliveries td.row-actions { grid-column: 1 / -1; text-align: left; }
  .data-table-deliveries td.row-actions:empty { display: none; }
  .delivery-detail td { display: block; }
  .input-compact { max-width: none; }
  .panel-head { flex-direction: column; align-items: stretch; }

  .chat-header { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
  .chat-header .avatar-large { width: 36px; height: 36px; font-size: 13px; }
  .chat-heading { flex: 1 1 0; }
  .chat-header-actions { gap: 14px; flex-basis: 100%; justify-content: flex-end; }
  .chat-header-actions .button span, .chat-header-actions a.button { font-size: 12px; }
  .message { max-width: 86%; }
  .composer-send span { display: none; }
  .composer-send { width: 42px; padding: 0; }
  .new-messages-pill { bottom: 74px; }

  .group-header { flex-wrap: wrap; }
  .group-subject { font-size: 20px; }
  .add-participants { flex-direction: column; align-items: stretch; }
  .inline-form { flex-direction: column; }
  .toasts { left: 16px; right: 16px; bottom: 16px; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
[data-link-panel] { margin-bottom: 16px; }

/* Message actions (operator tools on incoming messages) */
.message-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
.message-action {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid transparent; border-radius: 999px;
  padding: 3px 10px; cursor: pointer;
}
.message-action:hover { border-color: var(--accent); }
.message-action:focus-visible { outline: none; box-shadow: var(--focus); }
.action-panel { width: min(520px, calc(100vw - 32px)); }
.action-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.action-panel-head .icon-button { font-size: 20px; line-height: 1; }
.action-panel-body { display: flex; flex-direction: column; gap: 12px; }
.action-panel-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; }
.action-facts dd a { overflow-wrap: anywhere; }
.action-choices { display: flex; flex-direction: column; gap: 8px; }
.action-choices .button { justify-content: flex-start; text-align: left; height: auto; min-height: 36px; padding: 8px 12px; }
.action-search { display: flex; gap: 8px; }
.action-search input { flex: 1; min-width: 0; }
.settings-actions .action-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.settings-actions .action-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.settings-actions .group-picks { max-height: 180px; overflow: auto; padding: 8px 10px; background: var(--sunken); border-radius: 8px; }
@media (max-width: 720px) { .settings-actions .action-row-grid { grid-template-columns: 1fr; } }
select { color: inherit; font: inherit; appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.settings-layout .settings-actions { grid-column: 1; max-width: 720px; }
