:root {
  --brand: #9b3b6a;
  --brand-dark: #7c2d54;
  --brand-soft: #f7e9ef;
  --ink: #1f1b24;
  --ink-2: #625b68;
  --line: #e8e2e6;
  --bg: #faf7f9;
  --surface: #ffffff;
  --good: #006c10;
  --warn: #8a5a00;
  --crit: #b3261e;
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--bg);
  display: grid; grid-template-columns: 232px minmax(0, 1fr);
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---- sidebar ---- */
.sidebar { background: var(--ink); color: #fff; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand-name { font-weight: 700; letter-spacing: .04em; font-size: 13px; }
.brand-sub { color: #cdb9c5; font-size: 12px; margin-top: 2px; }
nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; }
nav a { color: #d9d2dc; text-decoration: none; padding: 9px 10px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
nav a.active { background: var(--brand); color: #fff; }
nav .count { background: #fff; color: var(--crit); border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 7px; }
.side-foot { margin-top: auto; }
.ai-pill { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 12px; background: rgba(255,255,255,.1); }
.ai-pill.on { background: #1d5c2b; }
.demo-note { margin-top: 10px; font-size: 11px; color: #a79cab; }

.link { background: none; border: 0; padding: 0; color: #e7c3d6; text-decoration: underline; cursor: pointer; font-size: inherit; }

/* ---- layout ---- */
main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 18px 28px 6px; }
.topbar h1 { font-size: 22px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.view { padding: 12px 28px 48px; display: flex; flex-direction: column; gap: 18px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card > h2 { font-size: 15px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sub { color: var(--ink-2); font-size: 12.5px; }
.muted { color: var(--ink-2); }
.empty { color: var(--ink-2); padding: 12px 0; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--ink-2); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.kpi .note { font-size: 12px; color: var(--ink-2); background: none; padding: 0; border-radius: 0; }

/* ---- buttons / forms ---- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); color: #fff; }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
input, select, textarea { border: 1px solid #d6cdd3; border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--ink); min-width: 0; }
textarea { resize: vertical; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.form .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid #f1ecef; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td input, td select { width: 100%; padding: 4px 6px; }

/* ---- badges ---- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: #eee9ec; color: var(--ink-2); white-space: nowrap; }
.badge.good { background: #e3f3e5; color: var(--good); }
.badge.warn { background: #fdf0d3; color: var(--warn); }
.badge.crit { background: #fbe3e1; color: var(--crit); }
.badge.brand { background: var(--brand-soft); color: var(--brand-dark); }

/* ---- lists ---- */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid #f1ecef; }
.item:last-child { border-bottom: 0; }
.item .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .title { font-weight: 500; }

/* ---- charts ---- */
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-size: 11px; fill: var(--ink-2); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.hbars { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 7px 10px; align-items: center; }
.hbars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .track { height: 12px; }
.hbars .fill { height: 12px; background: var(--brand); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip { position: fixed; z-index: 50; background: var(--ink); color: #fff; font-size: 12.5px; padding: 6px 9px; border-radius: 6px; pointer-events: none; max-width: 260px; }

/* ---- modal / toast ---- */
.modal-wrap { position: fixed; inset: 0; background: rgba(31,27,36,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; z-index: 20; }
.modal-wrap[hidden] { display: none; }
.modal { background: #fff; border-radius: 14px; width: min(920px, 100%); padding: 20px 22px; }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.note { background: var(--brand-soft); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.note.warn { background: #fdf0d3; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: min(560px, 90vw); }
.toast.err { background: var(--crit); }

/* ---- chat / prose ---- */
.chat { display: flex; flex-direction: column; gap: 10px; min-height: 240px; }
.msg { max-width: 78ch; padding: 10px 14px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; }
.msg.assistant { align-self: flex-start; background: #f4eff2; }
.prose { max-width: 78ch; }
.prose h2, .prose h3, .prose h4 { margin: 14px 0 4px; font-size: 15px; }
.prose p { margin: 6px 0; }
.prose ul { margin: 6px 0; padding-left: 20px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--brand); }
pre.email { white-space: pre-wrap; background: #f4eff2; border-radius: 8px; padding: 12px; font-family: inherit; margin: 8px 0 0; }

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; flex-direction: row; color: var(--ink); }

@media (max-width: 860px) {
  body { display: block; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin-top: 12px; }
  .topbar, .view { padding-left: 14px; padding-right: 14px; }
}
@media print {
  .sidebar, .actions, .no-print { display: none !important; }
  body { display: block; background: #fff; }
  .card, .kpi { break-inside: avoid; }
}
