/* Lead catcher panel. Colors are tokens; dark theme follows the system setting. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --border: #e1e4ea;
  --border-strong: #cfd4dc;
  --text: #1a1d23;
  --muted: #667085;
  --accent: #2f6fed;
  --accent-hover: #245ad0;
  --accent-soft: #e8efff;
  --accent-text: #ffffff;
  --ok: #067647;      --ok-soft: #e3f5ea;
  --warn: #9a5b00;    --warn-soft: #fdf1dc;
  --danger: #c4320a;  --danger-soft: #fdeae4;
  --info: #175cd3;    --info-soft: #e6eefc;
  --bubble-in: #ffffff;
  --bubble-out: #e3ecff;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / .18);
  --radius: 10px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-w: 216px;
  /* chart series 1–3, validated for CVD separation on both surfaces */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1d2129;
    --surface-3: #262b35;
    --border: #2a2f39;
    --border-strong: #3a404c;
    --text: #e7e9ee;
    --muted: #98a2b3;
    --accent: #6b9bff;
    --accent-hover: #86adff;
    --accent-soft: #1b2847;
    --accent-text: #0b1020;
    --ok: #4fd18b;      --ok-soft: #12301f;
    --warn: #f5b546;    --warn-soft: #33260d;
    --danger: #ff7a5c;  --danger-soft: #3a1a12;
    --info: #7fa8ff;    --info-soft: #172442;
    --bubble-in: #1f232c;
    --bubble-out: #1c2c4f;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / .55);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .9em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.link { color: var(--accent); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { padding: 0; width: 38px; }
.btn-block { width: 100%; }
.btn.is-busy { position: relative; color: transparent; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent-text); border-right-color: transparent; animation: spin .7s linear infinite;
}

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  min-height: 38px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea:read-only { background: var(--surface-2); }
input:disabled, textarea:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); margin: 0; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; cursor: pointer; }

.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--muted);
}
.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px;
  font-size: 12px; background: var(--surface-3); color: var(--text); white-space: nowrap;
}
.score {
  display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px;
  font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; background: var(--surface-3);
}
.tone-ok { background: var(--ok-soft); color: var(--ok); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-danger { background: var(--danger-soft); color: var(--danger); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }
.tone-muted { background: var(--surface-3); color: var(--muted); }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.45; }
.alert .btn { margin-top: 6px; }
.alert a { color: inherit; font-weight: 600; }

/* --- states --- */
.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 40px 16px; text-align: center; color: var(--muted);
}
.state strong { color: var(--text); font-size: 15px; }
.state-loading { flex-direction: row; gap: 10px; }
.state-error strong { color: var(--danger); }
.state .btn { margin-top: 8px; }
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- shell --- */
.shell {
  display: grid; height: 100dvh;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "nav main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 12px 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-lg { font-size: 20px; justify-content: center; margin-bottom: 8px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  /* a file, not a data: URI: the panel runs under CSP default-src 'self' */
  -webkit-mask: url("brand-mark.svg") center / contain no-repeat;
          mask: url("brand-mark.svg") center / contain no-repeat;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.stream-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin: 0 8px; }
.stream-dot.is-live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.stream-dot.is-connecting, .stream-dot.is-retrying { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.nav {
  grid-area: nav; display: flex; flex-direction: column; gap: 2px; padding: 12px 10px;
  background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto;
}
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 520;
}
.nav-link .icon { color: var(--muted); }
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current=page] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-link[aria-current=page] .icon { color: var(--accent); }

.main { grid-area: main; min-width: 0; min-height: 0; overflow-y: auto; position: relative; display: flex; flex-direction: column; }
.outlet { flex: 1 0 auto; min-width: 0; }
.main.view-dialogs .outlet { flex: 1 1 0; min-height: 0; overflow: hidden; }
.banners { display: flex; flex-direction: column; }
.banners:empty { display: none; }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 14px; border-bottom: 1px solid var(--border);
}
.boot { min-height: 100dvh; display: grid; place-items: center; }
.not-ready { min-height: 50dvh; }
.not-ready .spin { width: 28px; height: 28px; margin-bottom: 6px; }
.page { max-width: 1320px; margin: 0 auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: baseline; gap: 10px; }

/* --- login --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
  padding: 28px 24px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.form-error { color: var(--danger); font-size: 14px; }

/* --- leads --- */
.filters {
  display: grid; gap: 10px 12px; align-items: end;
  grid-template-columns: minmax(170px, 2fr) 130px minmax(140px, 1.4fr) 84px 140px 140px auto;
  padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.filters-toggle { display: none; }
.list-box { container-type: inline-size; min-width: 0; }
.list-surface { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.row-link.is-active td { background: var(--accent-soft); }
.cell-chat { max-width: 220px; }
.cell-summary { min-width: 240px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgb(0 0 0 / .28); opacity: 0; transition: opacity .18s; z-index: 20;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 21;
  display: flex; flex-direction: column; background: var(--surface); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .2s ease;
}
.drawer:focus { outline: none; }
.drawer-backdrop.open { opacity: 1; }
.drawer.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--border);
}
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 0; display: flex; flex-direction: column; gap: 14px; }
.drawer-body > :last-child { margin-bottom: 20px; }
.lead-title { display: flex; flex-direction: column; gap: 8px; }
.lead-summary { font-size: 18px; font-weight: 650; line-height: 1.35; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.quote {
  padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm);
  border-left: 3px solid var(--border-strong); font-size: 14px;
}
.draft { min-height: 180px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; }
.sticky-actions {
  position: sticky; bottom: 0; margin: 0 -20px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.drawer-body > .sticky-actions:last-child { margin-bottom: 0; }

/* --- modal --- */
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgb(0 0 0 / .4); }
.modal-head { padding: 18px 20px 8px; }
.modal-body { padding: 4px 20px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-body > div { display: flex; flex-direction: column; gap: 10px; }
.modal-body .quote { max-height: 40dvh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px 18px; }

/* --- toasts --- */
.toasts {
  position: fixed; z-index: 50; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 550;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); transition: opacity .3s, transform .3s;
}
.toast.tone-ok { background: var(--ok); color: #fff; }
.toast.tone-danger { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* --- dialogs --- */
.main.view-dialogs { overflow: hidden; }
.split { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); height: 100%; min-height: 0; }
.dlg-list-pane { min-width: 0; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--surface); }
.pane-head { padding: 16px 14px 12px; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid var(--border); }
.dlg-filters { display: flex; flex-direction: column; gap: 8px; }
.dlg-filters-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dlg-filters-row select { flex: 1 1 120px; width: auto; }
.dlg-list-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.dlg-list { list-style: none; margin: 0; padding: 0; }
.dlg-list-foot { padding: 10px; }
.dlg-item {
  display: flex; flex-direction: column; gap: 3px; padding: 11px 14px; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--border); border-left: 3px solid transparent;
}
.dlg-item:hover { background: var(--surface-2); }
.dlg-item.is-active { background: var(--accent-soft); border-left-color: var(--accent); }
.dlg-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dlg-item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.is-unread .dlg-item-name { font-weight: 750; }
.dlg-item-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dlg-item-sub { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.dlg-item-lead { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-item-last { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); }
.is-unread .dlg-item-last { color: var(--text); }
.unread {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-grid; place-items: center; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700;
}

.dlg-chat-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.chat-back-only { padding: 10px 12px; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.chat-back { display: none; }
.chat-peer { flex: 1; min-width: 0; }
.chat-peer-name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-peer-sub { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.chat-peer-sub .badge { margin-left: 4px; }
.status-select { width: auto; flex: none; min-height: 34px; font-size: 14px; }
.chat-source {
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; font-size: 14px;
}
.source-line { display: flex; gap: 8px; align-items: center; min-width: 0; flex-wrap: wrap; }
.source-line strong { flex: 0 1 auto; }
.source-links { display: flex; gap: 14px; flex-wrap: wrap; }
.source-text summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.source-text .pre { margin-top: 6px; max-height: 140px; overflow-y: auto; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); }

.chat-feed-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.chat-feed { flex: 1; overflow-y: auto; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.feed-more { display: flex; justify-content: center; padding: 4px 0 8px; }
.day-sep { display: flex; justify-content: center; margin: 10px 0 4px; }
.day-sep span { font-size: 12px; color: var(--muted); background: var(--surface-3); padding: 2px 10px; border-radius: 999px; }
.msg {
  max-width: min(78%, 620px); padding: 8px 12px 6px; border-radius: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.msg-in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg-out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: 11.5px; color: var(--muted); }
.msg-src { padding: 0 6px; border-radius: 5px; background: rgb(127 127 127 / .14); }
.msg-src.src-first { color: var(--info); }
.msg-src.src-phone { color: var(--warn); }
.msg-photo { display: block; border-radius: 10px; overflow: hidden; max-width: 320px; }
.msg-photo img { display: block; width: 100%; height: auto; }
.attach { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 6px 0; }
.attach-icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.attach-info { flex: 1; min-width: 0; }
.attach-name { font-weight: 600; font-size: 14px; }
.attach-note { font-size: 12px; color: var(--warn); }
.attach-info { display: flex; flex-direction: column; }
.new-pill {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  border: 0; border-radius: 999px; padding: 6px 14px; background: var(--accent); color: var(--accent-text);
  font: inherit; font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); cursor: pointer;
}

.composer {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.composer-error:empty { display: none; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-input { resize: none; min-height: 42px; max-height: 200px; }
.composer-send { width: 42px; min-height: 42px; }
.composer-note {
  font-size: 13px; color: var(--warn); background: var(--warn-soft); padding: 8px 10px; border-radius: var(--radius-sm);
}



/* --- shared page bits (C2) --- */
.page-head { flex-wrap: wrap; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.summary-line { display: flex; flex-wrap: wrap; gap: 6px 24px; font-size: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.disabled-wrap { display: inline-flex; align-items: center; gap: 6px; }
.status-cell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; min-width: 160px; max-width: 280px; }
.acc-name { display: flex; align-items: center; gap: 8px; font-weight: 650; }
tr.is-removed td { opacity: .6; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; width: 100%; min-width: 120px; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.join { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.join-failed { margin: 0; padding-left: 16px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.table-accounts td { vertical-align: top; }
.modal.wizard { width: min(480px, calc(100vw - 32px)); }
.steps { list-style: none; display: flex; gap: 6px; padding: 0; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.steps li { flex: 1; padding-top: 6px; border-top: 3px solid var(--surface-3); }
.steps li.is-done { border-color: var(--ok); }
.steps li.is-current { border-color: var(--accent); color: var(--text); font-weight: 600; }
.code-input { font-size: 22px; letter-spacing: .3em; font-family: var(--mono); max-width: 220px; }
.wizard-error:empty { display: none; }
.qr-box { align-self: center; width: min(240px, 70vw); aspect-ratio: 1; padding: 12px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); display: grid; place-items: center; }
.qr-box .qr { width: 100%; height: 100%; }
.qr-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.code-via { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.wizard-error .btn { margin-top: 8px; }
.alert.tone-info { background: var(--info-soft); color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.card > h3 { margin: 0; }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plain-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.src-title { font-weight: 650; }
.src-sub { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin-top: 4px; }
.table-sources td { vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.matrix { display: flex; flex-wrap: wrap; gap: 4px; max-width: 180px; }
.table-sources th, .table-sources td { padding-left: 8px; padding-right: 8px; }
.table-sources .row-actions { flex-direction: column; align-items: flex-start; }
.table-sources td:first-child { min-width: 170px; }
.chip-m { display: inline-flex; align-items: center; height: 22px; padding: 0 7px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.radio { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.radio input { width: 16px; height: 16px; min-height: 0; margin-top: 3px; accent-color: var(--accent); flex: none; }
.radio > span { display: flex; flex-direction: column; }
.topic-list { display: flex; flex-direction: column; gap: 2px; max-height: 45dvh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; }
.topic { padding: 5px 0; }
.topic.is-new { font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; font: inherit; font-weight: 550; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.add-panel-body { display: flex; flex-direction: column; gap: 10px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.cand-list { list-style: none; margin: 0; padding: 0; }
.cand-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.cand-list li:last-child { border-bottom: 0; }
.cand-main { display: flex; flex-direction: column; min-width: 0; }

.filters-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: none; font: inherit; font-weight: 550; padding: 8px 14px; cursor: pointer; color: var(--text); }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-checked=true] { background: var(--accent); color: var(--accent-text); }
.period-custom { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.period-custom .field { width: 150px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.list-surface.flat { border: 0; border-radius: 0; }
.sort-btn { border: 0; background: none; font: inherit; color: inherit; font-weight: inherit; cursor: pointer; padding: 0; }
.table-stats th.num .sort-btn { width: 100%; text-align: right; }
.table-stats tr.is-total td { font-weight: 700; background: var(--surface-2); }
.table-stats tr.is-sub td { background: var(--surface-2); font-size: 13px; }
.sub-label { padding-left: 28px !important; }
.expand-btn { border: 0; background: none; font: inherit; color: inherit; cursor: pointer; padding: 0; text-align: left; display: inline-flex; gap: 6px; align-items: baseline; }
.chev { width: 12px; display: inline-block; color: var(--muted); }
.chart-wrap { display: flex; flex-direction: column; gap: 8px; }
.chart-area { position: relative; }
.chart { display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .end-label { fill: var(--text); font-size: 12px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .s1 { stroke: var(--series-1); } .chart .dot.s1 { fill: var(--series-1); }
.chart .s2 { stroke: var(--series-2); } .chart .dot.s2 { fill: var(--series-2); }
.chart .s3 { stroke: var(--series-3); } .chart .dot.s3 { fill: var(--series-3); }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.s1 { background: var(--series-1); } .swatch.s2 { background: var(--series-2); } .swatch.s3 { background: var(--series-3); }
.chart-tip {
  position: absolute; top: 4px; transform: translateX(-50%); pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 8px 10px; font-size: 13px; min-width: 150px;
}
.tip-row { display: flex; align-items: center; gap: 6px; }

.radios { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: start; }
.pair { display: flex; align-items: center; gap: 6px; }
.pair input { width: 0; flex: 1; }
.field-error { font-size: 12px; color: var(--danger); }
.field-error:empty { display: none; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--danger); }
.preview { display: flex; flex-direction: column; gap: 4px; }
.settings-page { padding-bottom: 0; }
.save-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 10px; justify-content: flex-end;
  margin: 0 -24px; padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.save-bar .save-state { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-bar.is-dirty .save-state { color: var(--warn); }
.conflict { border-color: var(--warn); }
.diff-table td { font-size: 13px; overflow-wrap: anywhere; }
.diff-table tr.is-conflict td { background: var(--warn-soft); }
.prices-table { max-width: 620px; }
.prices-table td { padding: 4px 6px; border: 0; }
.prices-table th { padding: 4px 6px; background: none; border: 0; }
.prices-table td:first-child { min-width: 140px; }
.prices-table td:nth-child(2), .prices-table td:nth-child(3) { width: 130px; }
.prices-table td:last-child { width: 40px; }
.prices > .btn { align-self: flex-start; }
@media (max-width: 700px) {
  /* phone: model on its own line, prices and the remove button under it */
  .prices-table thead { display: none; }
  .prices-table, .prices-table tbody { display: block; }
  .prices-table tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .prices-table td { display: block; padding: 0; width: auto !important; min-width: 0 !important; }
  .prices-table td:first-child { grid-column: 1 / -1; }
}
.err-list { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 700px) { .save-bar { margin: 0 -16px; padding-left: 16px; padding-right: 16px; flex-wrap: wrap; } .save-bar .save-state { flex-basis: 100%; } }

.type-picker { position: relative; }
.type-picker > summary { list-style: none; min-width: 140px; justify-content: space-between; }
.type-picker > summary::-webkit-details-marker { display: none; }
.type-picker > summary::after { content: "▾"; color: var(--muted); }
.type-menu {
  position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; width: min(360px, calc(100vw - 32px));
  max-height: 60dvh; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.type-menu fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.type-menu legend { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.table-events td { vertical-align: top; }
.cell-details { font-size: 14px; overflow-wrap: anywhere; }
.only-cards { display: none; }

/* --- tables turn into cards by the width of their own box, not the viewport:
   the side menu eats 216 px, so a 1024 px screen has less room than it seems. --- */
@container (max-width: 880px) {
  .list-surface:has(> .table-leads) { background: transparent; border: 0; overflow: visible; }
  .table-leads thead { display: none; }
  .table-leads, .table-leads tbody { display: block; }
  .table-leads tr {
    display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
    padding: 12px 14px; margin-bottom: 10px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
  }
  .table-leads td { display: block; padding: 0; border: 0; min-width: 0; }
  .table-leads .row-link:hover td, .table-leads .row-link.is-active td { background: transparent; }
  .table-leads .row-link:hover { background: var(--surface-2); }
  .table-leads .row-link.is-active { border-color: var(--accent); }
  /* card: time · chat · score / summary / author · status / account */
  .table-leads td:nth-child(1) { grid-column: 1; font-size: 13px; color: var(--muted); }
  .table-leads td:nth-child(2) { grid-column: 2; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: none; }
  .table-leads td:nth-child(3) { grid-column: 3; }
  .table-leads td:nth-child(4) { grid-column: 1 / -1; min-width: 0; font-weight: 600; }
  .table-leads td:nth-child(5) { grid-column: 1 / 3; font-size: 13px; }
  .table-leads td:nth-child(6) { grid-column: 3; grid-row: 3; justify-self: end; }
  .table-leads td:nth-child(7) { grid-column: 1 / -1; font-size: 12px; }
  .table-leads .cell-account::before { content: "Аккаунт: "; }
  .table-leads .cell-account.is-empty { display: none; }
}

/* Generic card mode: a table becomes cards when it does not fit its box
   (ui.js autoCards measures it). Every cell turns into "label: value". */
.list-surface.is-cards { background: transparent; border: 0; overflow: visible; }
.is-cards .table-cards thead { display: none; }
.is-cards .table-cards, .is-cards .table-cards tbody { display: block; }
.is-cards .table-cards tr {
  display: block; padding: 10px 14px; margin-bottom: 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.is-cards .table-cards tr.is-sub { margin-left: 16px; }
.is-cards .table-cards tr.is-total { background: var(--surface-2); }
.is-cards .table-cards td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: right; background: none; }
.is-cards .table-cards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
.is-cards .table-cards td.cell-main { display: block; text-align: left; font-weight: 600; padding-bottom: 6px; }
.is-cards .table-cards td.cell-main::before { content: none; }
.is-cards .table-cards td.cell-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 8px; }
.is-cards .table-cards td.cell-actions::before { content: none; }
.is-cards .table-cards td:empty { display: none; }
.is-cards .table-cards .only-cards { display: inline-flex; margin-left: 6px; }
.is-cards .table-cards td.hide-in-cards { display: none; }
.is-cards .table-cards td.cell-details { display: block; text-align: left; }
.is-cards .table-cards td.cell-details::before { display: block; margin-bottom: 2px; }
.is-cards .table-cards .status-cell { align-items: flex-end; max-width: none; }
.is-cards .table-cards .matrix { justify-content: flex-end; max-width: none; }
.is-cards .table-sources .row-actions { flex-direction: row; }
.is-cards .table-stats tr.is-sub td, .is-cards .table-stats tr.is-total td { background: none; }

/* --- responsive --- */
@media (max-width: 1199px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters .field-grow { grid-column: 1 / -1; }
}

@media (max-width: 899px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr;
    grid-template-areas: "top" "nav" "main";
  }
  .topbar { padding: 0 8px 0 16px; }
  .nav {
    flex-direction: row; padding: 6px 8px; gap: 4px; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--border); scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { flex: none; padding: 7px 11px; font-size: 14px; }
  .nav-link .icon { display: none; }

  .split { grid-template-columns: minmax(0, 1fr); }
  .split .dlg-chat-pane { display: none; }
  .split.has-open .dlg-list-pane { display: none; }
  .split.has-open .dlg-chat-pane { display: flex; }
  .dlg-list-pane { border-right: 0; }
  .chat-back { display: inline-flex; margin-left: -6px; }
  .chat-head { padding: 8px 10px; gap: 6px; }
  .status-select { max-width: 132px; }
  .msg { max-width: 88%; }
  .chat-feed { padding: 10px 10px 14px; }
}

@media (max-width: 700px) {
  .page { padding: 14px 16px 32px; gap: 12px; }
  .filters { grid-template-columns: 1fr 1fr; padding: 12px; }
  .filters-reset { grid-column: 1 / -1; }
  .filters-toggle { display: inline-flex; grid-column: 1 / -1; }
  .filters:not(.is-open) > .field:not(.field-grow),
  .filters:not(.is-open) > .filters-reset { display: none; }

  .drawer-head { padding-left: 16px; }
  .drawer-body { padding: 14px 16px 0; }
  .sticky-actions { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .sticky-actions .btn { flex: 1; }
  .meta { grid-template-columns: 1fr; gap: 0; }
  .meta dt { font-size: 12px; margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
