/* Раскладка: три колонки как в окне CRM — сделки | переписка | подготовленный ответ.
   Цвета: спокойный хвойно-зелёный акцент (продукты для здоровья), подсказка менеджеру —
   тёплый «стикер», чтобы её нельзя было спутать с текстом для клиента. */
:root {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --fg: #18211c;
  --muted: #5d6b63;
  --line: #d8e0db;
  --accent: #1f6b4f;
  --accent-fg: #ffffff;
  --accent-soft: #dcefe5;
  --client: #ffffff;
  --manager: #e3f0e9;
  --hint-bg: #fff4d6;
  --hint-line: #e6c56a;
  --hint-fg: #4a3a0b;
  --warn: #9a5b00;
  --danger: #b3261e;
  --font-display: "Unbounded", "Onest", system-ui, sans-serif;
  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111713; --surface: #18201b; --surface-2: #1f2923; --fg: #e4ebe6; --muted: #98a79e;
    --line: #2c3831; --accent: #5cc496; --accent-fg: #0d1a13; --accent-soft: #1f3b2e;
    --client: #1f2923; --manager: #1d3428; --hint-bg: #3a3014; --hint-line: #8a7127; --hint-fg: #f3e2b0;
    --warn: #e8b04d; --danger: #f08a82; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111713; --surface: #18201b; --surface-2: #1f2923; --fg: #e4ebe6; --muted: #98a79e;
  --line: #2c3831; --accent: #5cc496; --accent-fg: #0d1a13; --accent-soft: #1f3b2e;
  --client: #1f2923; --manager: #1d3428; --hint-bg: #3a3014; --hint-line: #8a7127; --hint-fg: #f3e2b0;
  --warn: #e8b04d; --danger: #f08a82; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font-body); }
h1, h2, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.small-text { font-size: 13px; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 6px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--fg); font-weight: 600; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--accent); }
.status.bad .dot { background: var(--danger); }
.status.bad { color: var(--danger); }

main { padding: 16px 20px 32px; }
.panel { display: grid; grid-template-columns: 230px minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.panel.single { display: block; max-width: 1100px; }
.panel[hidden] { display: none; }

.leads .label { margin-bottom: 8px; }
.lead-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lead-list button {
  width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.lead-list button[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.lead-list .lead-name { font-weight: 600; font-size: 14px; }
.lead-list .lead-scn { font-size: 12px; color: var(--muted); }

.chat, .result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.chat { display: flex; flex-direction: column; gap: 12px; }
.chat-head, .row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.row-gap { display: inline-flex; gap: 8px; }
.chat-title { font-family: var(--font-display); font-weight: 500; font-size: 18px; text-wrap: balance; }
.raw { margin: 0; max-height: 260px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 10px; font: 12px/1.45 var(--font-mono); }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--client); }
.msg.manager { align-self: flex-end; background: var(--manager); border-color: transparent; }
.msg.added { border-style: dashed; border-color: var(--accent); }
.msg .who { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }

.composer { display: flex; flex-direction: column; gap: 6px; }
textarea, input, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
textarea { resize: vertical; }
.composer-actions { display: flex; flex-wrap: wrap; gap: 6px; }

button.primary { border: 0; border-radius: 8px; padding: 11px 16px; background: var(--accent); color: var(--accent-fg); font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: .55; cursor: wait; }
button.ghost { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button.ghost:hover { border-color: var(--accent); }
button.danger { border: 1px solid var(--danger); color: var(--danger); background: none; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button.small { font-size: 13px; padding: 5px 10px; }

.result { display: flex; flex-direction: column; gap: 14px; }
.empty { display: flex; flex-direction: column; gap: 8px; color: var(--muted); max-width: 60ch; }
.loading { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.error { color: var(--danger); border: 1px solid var(--danger); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }
#result { display: flex; flex-direction: column; gap: 14px; }
#result[hidden] { display: none; }

.saved-note { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.card { border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card.reply { border: 1px solid var(--accent); }
.reply-text { font-size: 16px; white-space: pre-wrap; }
.card.hint { background: var(--hint-bg); border: 1px dashed var(--hint-line); color: var(--hint-fg); }
.card.hint .label { color: var(--hint-fg); }
.internal { font-weight: 500; text-transform: none; letter-spacing: 0; opacity: .8; margin-left: 6px; }
.hint-text { white-space: pre-wrap; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.attention { background: var(--hint-bg); color: var(--warn); font-weight: 600; }

.facts { margin: 0; display: grid; gap: 10px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); }
.warnings { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.warnings li { font-size: 13px; color: var(--warn); }
.warnings li::before { content: "⚠ "; }

.kb-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 16px; align-items: start; }
.kb-list-wrap { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.kb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kb-table th, .kb-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.kb-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.kb-table tbody tr { cursor: pointer; }
.kb-table tbody tr:hover { background: var(--surface-2); }
.kb-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kb-table td.clip { max-width: 320px; }
.kb-form { background: var(--surface); border: 1px solid var(--line); gap: 6px; position: sticky; top: 16px; }
.kb-form label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kb-form[hidden] { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two > div { display: flex; flex-direction: column; min-width: 0; }

@media (max-width: 1100px) {
  .panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .leads { grid-column: 1 / -1; }
  .lead-list { flex-direction: row; flex-wrap: wrap; }
  .lead-list li { flex: 1 1 200px; }
}
@media (max-width: 760px) {
  main { padding: 12px 16px 24px; }
  .top { padding: 10px 16px; }
  .panel, .kb-layout { grid-template-columns: minmax(0, 1fr); }
  .status { margin-left: 0; }
  .two { grid-template-columns: 1fr; }
}
