:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --ink: #15181b;
  --ink-2: #3c4247;
  --muted: #6c737a;
  --line: #e3e6e1;
  --line-strong: #cfd4cd;
  --accent: #169b52;
  --accent-ink: #0d6b37;
  --accent-soft: #e5f4eb;
  --bubble-client: #dff3e6;
  --bubble-bank: #ffffff;
  --warn: #b86e00;
  --warn-soft: #fff3df;
  --bad: #c83c35;
  --bad-soft: #fde9e7;
  --info: #2f66c8;
  --info-soft: #e7eefb;
  --violet: #7a4fc9;
  --violet-soft: #f0eafb;
  --teal: #0f8a8a;
  --teal-soft: #e1f4f4;
  --grey-soft: #eef0ec;
  --shadow: 0 1px 2px rgba(20, 24, 27, .04), 0 6px 20px rgba(20, 24, 27, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #191d1b;
    --surface-2: #1e2320;
    --ink: #eef1ee;
    --ink-2: #c9cfca;
    --muted: #8f978f;
    --line: #2a302c;
    --line-strong: #3a423d;
    --accent: #2fbf6d;
    --accent-ink: #6fdc9b;
    --accent-soft: #173524;
    --bubble-client: #1d3a28;
    --bubble-bank: #232926;
    --warn: #f0a93b;
    --warn-soft: #3a2c14;
    --bad: #f07268;
    --bad-soft: #3d1d1b;
    --info: #7aa7f5;
    --info-soft: #1c2940;
    --violet: #b394ee;
    --violet-soft: #2a2140;
    --teal: #4fc9c9;
    --teal-soft: #163333;
    --grey-soft: #252b27;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), #0c7a3d);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
  position: relative;
}
.brand-mark::before, .brand-mark::after {
  content: ""; position: absolute; left: 8px; height: 3px; border-radius: 2px; background: #fff;
}
.brand-mark::before { top: 11px; width: 16px; }
.brand-mark::after { top: 18px; width: 10px; opacity: .8; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: 14px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav a { padding: 7px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--grey-soft); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); }
.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 720px; }

/* ---------- базовые элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.pre { white-space: pre-wrap; word-break: break-word; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--grey-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--grey-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 32px; padding: 0; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input[type=text], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 14px/1.4 var(--font);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13.5px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--grey-soft); }
.segmented button {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 550;
  padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--grey-soft); color: var(--ink-2); white-space: nowrap;
}
.chip.help, .chip.engaged, .chip.good { background: var(--accent-soft); color: var(--accent-ink); }
.chip.inform { background: var(--teal-soft); color: var(--teal); }
.chip.care { background: var(--violet-soft); color: var(--violet); }
.chip.offer, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.annoyed, .chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }

table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }

.score { display: grid; grid-template-columns: 1fr 110px 28px; align-items: center; gap: 10px; font-size: 13px; }
.score-bar { height: 6px; border-radius: 3px; background: var(--grey-soft); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.score-bar i.mid { background: var(--warn); }
.score-bar i.low { background: var(--bad); }
.score b { text-align: right; font-variant-numeric: tabular-nums; }

.bar-line { height: 8px; border-radius: 4px; background: var(--grey-soft); overflow: hidden; min-width: 60px; }
.bar-line i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-line i.cache { background: var(--info); }

/* ---------- чат ---------- */
.phone {
  display: flex; flex-direction: column; border-radius: 28px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface-2); box-shadow: var(--shadow);
  min-height: 520px;
}
.phone-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.phone-head .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none;
}
.phone-head small { display: block; color: var(--muted); font-size: 12px; }
.chat { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 10px; max-height: 620px; }
.chat .day { align-self: center; font-size: 12px; color: var(--muted); background: var(--grey-soft); padding: 2px 10px; border-radius: 999px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 4px; }
.msg.bank { align-self: flex-start; }
.msg.client { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.bank .bubble { background: var(--bubble-bank); border: 1px solid var(--line); border-top-left-radius: 5px; }
.msg.client .bubble { background: var(--bubble-client); border-top-right-radius: 5px; }
.bubble.ghost { background: transparent !important; border: 1px dashed var(--line-strong) !important; color: var(--muted); font-style: italic; }
.msg-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.msg-meta button { border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; padding: 0; text-decoration: underline dotted; }
.msg.selected .bubble { box-shadow: 0 0 0 2px var(--accent); }
.typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; border-radius: 16px; background: var(--bubble-bank); border: 1px solid var(--line); }
.typing.client { align-self: flex-end; background: var(--bubble-client); border: 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--surface); }
.composer input { flex: 1; }

/* ---------- таймлайн «почему так» ---------- */
.timeline { display: flex; flex-direction: column; }
.tl-item { padding: 14px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tl-item:last-child { border-bottom: 0; }
.tl-item:hover, .tl-item.selected { background: var(--surface-2); }
.tl-item .who { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.tl-item .body { color: var(--ink-2); white-space: pre-wrap; }
.tl-item .body.thoughts { font-style: italic; }
.tl-item .foot { display: flex; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* ---------- раскладки страниц ---------- */
.dialog-layout { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(320px, 440px); gap: 20px; align-items: start; }
.settings-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.ab-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
.list { display: flex; flex-direction: column; }
.list-item { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item.active { background: var(--accent-soft); }
.list-item .title { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.list-item .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.scroll { max-height: 70vh; overflow-y: auto; }

.day-context { display: flex; flex-direction: column; gap: 10px; }
.day-context details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface-2); }
.day-context summary { cursor: pointer; font-weight: 600; }
.day-context li { margin: 6px 0; color: var(--ink-2); }

.verdict { display: flex; flex-direction: column; gap: 12px; }
.verdict-top { display: flex; align-items: center; gap: 14px; }
.big-score { font-size: 34px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.big-score small { font-size: 15px; color: var(--muted); font-weight: 500; }
.issues { margin: 0; padding-left: 18px; color: var(--ink-2); }
.issues li { margin: 3px 0; }

/* трейсы */
.waterfall { display: flex; flex-direction: column; }
.span { display: grid; grid-template-columns: 180px 1fr 90px; gap: 12px; align-items: center; padding: 9px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.span:hover, .span.active { background: var(--surface-2); }
.span .name { font-weight: 600; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.span .name small { color: var(--muted); font-weight: 500; }
.span .track { position: relative; height: 16px; background: var(--grey-soft); border-radius: 4px; }
.span .track i { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); min-width: 3px; opacity: .85; }
.span .track i.client { background: var(--info); }
.span .track i.judge { background: var(--violet); }
.span .track i.persona { background: var(--teal); }
.span .track i.error { background: var(--bad); }
.span .ms { text-align: right; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.prompt-msg { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.prompt-msg header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 12.5px; }
.prompt-msg header .role { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.prompt-msg pre { margin: 0; padding: 12px; max-height: 360px; overflow: auto; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.prompt-msg.response header { background: var(--accent-soft); }
.log-view { font: 12px/1.55 var(--mono); white-space: pre-wrap; max-height: 460px; overflow: auto; padding: 14px 18px; margin: 0; }

/* калибровка */
.rate-card { max-width: 640px; margin: 0 auto; }
.progress { height: 6px; background: var(--grey-soft); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  padding: 12px; border-radius: 12px; border: 1.5px solid var(--line-strong); background: var(--surface);
  font: inherit; font-weight: 550; text-align: left; cursor: pointer; color: var(--ink);
}
.choice:hover { border-color: var(--accent); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.stars { display: flex; gap: 6px; }
.stars button {
  width: 44px; height: 40px; border-radius: 10px; border: 1.5px solid var(--line-strong);
  background: var(--surface); font: inherit; font-weight: 650; cursor: pointer; color: var(--ink);
}
.stars button.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.matrix td.cell { text-align: center; font-variant-numeric: tabular-nums; }
.matrix td.diag { font-weight: 700; }

/* выезжающая панель и тосты */
.drawer { position: fixed; inset: 0; z-index: 30; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 11, .35); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(860px, 94vw);
  background: var(--surface); box-shadow: -10px 0 40px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); max-width: 420px; }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 1100px) {
  .dialog-layout, .ab-layout, .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group, .sidebar-foot { display: none; }
  .main { padding: 18px 16px 40px; }
  .choice-grid { grid-template-columns: 1fr; }
  .span { grid-template-columns: 120px 1fr 60px; }
}

/* ---------- демо (главная) ---------- */
body.demo { background: radial-gradient(1200px 600px at 70% -10%, var(--accent-soft), transparent 60%), var(--bg); min-height: 100vh; }
.demo-top { display: flex; align-items: center; justify-content: space-between; max-width: 1120px; margin: 0 auto; padding: 22px 24px 8px; }
.demo-links { display: flex; gap: 16px; }
.demo-admin { color: var(--muted); font-size: 13px; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.login-card input[type=password] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: 15px var(--font); }
.login-card .btn { height: 42px; }
.login-error { color: var(--bad); font-size: 13px; }
.demo-main { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 28px; max-width: 1120px; margin: 0 auto; padding: 16px 24px 48px; align-items: start; }
.demo-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 20px; }
.demo-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.demo-label { font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.demo-name { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.demo-about { color: var(--ink-2); font-size: 13.5px; }
.demo-note { color: var(--muted); font-size: 12.5px; }
.demo-date { width: auto; padding: 2px 6px; font-size: 12px; border-radius: 7px; text-transform: none; letter-spacing: 0; }
.demo-occasions { display: flex; flex-wrap: wrap; gap: 6px; }
.demo-occasions span { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }
.demo-occasions span.more { background: var(--grey-soft); color: var(--muted); }
.demo-start { height: 46px; font-size: 15px; border-radius: 12px; }
.demo-toggle { justify-content: center; font-size: 13px; color: var(--muted); }
.demo-phone { max-width: 560px; margin: 0 auto; width: 100%; min-height: 680px; border-radius: 36px; }
.demo-phone .phone-head { padding: 16px 22px; }
.demo-scroll { min-height: 460px; max-height: 64vh; padding: 20px 18px; }
.demo-empty { margin: auto; text-align: center; color: var(--muted); max-width: 320px; display: flex; flex-direction: column; gap: 6px; }
.demo-empty strong { color: var(--ink); font-size: 15px; }
.demo-system { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--grey-soft); padding: 4px 12px; border-radius: 999px; text-align: center; }
.demo-thought { font-size: 12.5px; font-style: italic; color: var(--muted); max-width: 100%; padding: 6px 10px; border-left: 2px solid var(--line-strong); margin-bottom: 2px; }
.demo-actions { display: flex; gap: 8px; justify-content: center; padding: 10px 12px 0; background: var(--surface); border-top: 1px solid var(--line); }
@media (max-width: 900px) {
  .demo-main { grid-template-columns: 1fr; padding: 12px 16px 40px; }
  .demo-side { position: static; }
  .demo-phone { min-height: 560px; border-radius: 28px; }
}
