:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #16191f;
  --muted: #5d6573;
  --accent: #2446c7;
  --accent-soft: #e8edff;
  --high: #b42318;
  --high-soft: #fdecea;
  --medium: #a15c07;
  --medium-soft: #fff4e0;
  --ok: #1b7a43;
  --ok-soft: #e6f5ec;
  --synthetic: #6b3fa0;
  --synthetic-soft: #f2eafb;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1d212a;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --accent: #8ea4ff;
    --accent-soft: #1f2748;
    --high: #ff8a80;
    --high-soft: #3a1c1c;
    --medium: #f5b85a;
    --medium-soft: #36291a;
    --ok: #6fd39b;
    --ok-soft: #173125;
    --synthetic: #c9a7f5;
    --synthetic-soft: #2b2140;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--high); min-height: 1em; margin: 8px 0 0; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700;
}
.brand-name { font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--muted); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.session { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em; border: 1px solid transparent; white-space: nowrap;
}
.badge.dev { background: var(--medium-soft); color: var(--medium); }
.badge.synthetic { background: var(--synthetic-soft); color: var(--synthetic); }
.badge.demo { background: var(--high-soft); color: var(--high); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

.data-banner {
  padding: 8px 20px; background: var(--synthetic-soft); color: var(--synthetic);
  font-size: 13px; border-bottom: 1px solid var(--border);
}

.layout {
  display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px;
  padding: 16px 20px 40px; max-width: 1480px; margin: 0 auto;
}
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; padding: 12px 16px 32px; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.head-meta { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; flex-wrap: wrap; }
#conversation-select { min-width: 0; max-width: min(260px, 100%); text-overflow: ellipsis; }

.btn {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.approve { color: var(--ok); }
.btn.reject { color: var(--high); }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px;
}
textarea { resize: vertical; width: 100%; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); min-height: 84px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-value.na { font-size: 14px; font-weight: 600; color: var(--muted); padding-top: 8px; }
.kpi-note { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kpi.attention .kpi-value { color: var(--high); }

.unavailable, .limits { margin-top: 12px; font-size: 13px; }
.unavailable summary, .limits summary { cursor: pointer; color: var(--muted); }
.unavailable ul, .limits ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 5px; height: fit-content; }
.sev.high { background: var(--high-soft); color: var(--high); }
.sev.medium { background: var(--medium-soft); color: var(--medium); }
.sev.low { background: var(--surface); color: var(--muted); }
.alert-title { font-weight: 550; overflow-wrap: anywhere; }
.alert-evidence { font-size: 12px; color: var(--muted); margin-top: 2px; }

.rec { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.rec-head { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.rec-title { font-weight: 600; overflow-wrap: anywhere; }
.rec dl { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; margin: 10px 0; font-size: 13px; }
.rec dt { color: var(--muted); }
.rec dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) { .rec dl { grid-template-columns: 1fr; } .rec dt { margin-top: 6px; } }
.rec-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rec-actions input { flex: 1; min-width: 160px; }
.status-pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.status-pill.approved { background: var(--ok-soft); color: var(--ok); }
.status-pill.rejected { background: var(--high-soft); color: var(--high); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }

.chat { display: flex; flex-direction: column; }
.mode-note { font-size: 12px; padding: 6px 10px; border-radius: 7px; margin-bottom: 8px; }
.mode-note.demo { background: var(--high-soft); color: var(--high); }
.mode-note.live { background: var(--ok-soft); color: var(--ok); }
.messages { display: flex; flex-direction: column; gap: 10px; max-height: 520px; min-height: 180px; overflow-y: auto; padding: 4px 2px; }
.msg { padding: 10px 12px; border-radius: 10px; max-width: 94%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: normal; display: flex; gap: 6px; flex-wrap: wrap; }
.msg details { margin-top: 6px; font-size: 12px; white-space: normal; }
.msg details summary { cursor: pointer; color: var(--muted); }
.msg details ul { padding-left: 16px; margin: 4px 0; }
.msg.pending { color: var(--muted); font-style: italic; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.chip { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }

.memories { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.memory { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.memory-meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.memory-actions { display: flex; gap: 6px; margin-top: 6px; }
.memory-actions .btn { padding: 2px 8px; font-size: 12px; }

.status { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 0; font-size: 13px; }
.status dt { color: var(--muted); }
.status dd { margin: 0; overflow-wrap: anywhere; }

.login { display: grid; place-items: center; padding: 48px 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.login-fields { display: flex; flex-direction: column; gap: 12px; }
.answer-label { font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; margin-bottom: 6px; white-space: normal; }
.answer-label.ai { color: var(--accent); }
.answer-label.verified { color: var(--ok); }
.verified { white-space: pre-wrap; margin-top: 4px; }
.fact-meta { color: var(--muted); }
.msg-meta.warn { color: var(--medium); }
