:root {
  --bg: #f4f6f5; --panel: #ffffff; --ink: #14201f; --muted: #5d6b69; --line: #dfe5e3; --soft: #eef2f1;
  --brand: #0f3d3e; --brand-2: #17595a; --accent: #f2c14e; --hot: #d1495b; --ok: #2a9d6f; --warn: #d98e04;
  --info: #3d6fb6; --radius: 10px; --shadow: 0 1px 2px rgba(20,32,31,.06), 0 4px 16px rgba(20,32,31,.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1515; --panel: #152021; --ink: #e6eeec; --muted: #93a3a0; --line: #263536; --soft: #1b2829;
    --brand: #9fd6cf; --brand-2: #7cc3ba; --accent: #f2c14e; --hot: #ef6f80; --ok: #4cc493; --warn: #f0b13c;
    --info: #78a6e8; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
p { margin: 0 0 10px; }
.boot { display: grid; place-items: center; height: 100vh; font-weight: 700; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #e8f1ef; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; }
@media (prefers-color-scheme: dark) { .side { background: #0a1112; border-right: 1px solid var(--line); } }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 4px 8px 16px;
  color: #fff; }
.logo img { width: 30px; height: 30px; }
.logo small { display: block; font-weight: 500; font-size: 11px; opacity: .7; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #d5e4e1;
  font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.14); color: #fff; }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.side .foot { margin-top: auto; font-size: 12px; opacity: .75; padding: 8px 10px; }
.side .foot button { color: #e8f1ef; border-color: rgba(255,255,255,.25); background: transparent; margin-top: 6px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px;
  flex-wrap: wrap; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .main { padding: 14px 16px 60px; }
  .menu-btn { display: inline-flex; }
}

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card + .kpis, .kpis + .card, .card + .card, .tablewrap + .card { margin-top: 14px; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.kpi .s { color: var(--muted); font-size: 12px; }
.kpi.hot .v { color: var(--hot); }
@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .g2, .g3 { grid-template-columns: 1fr; } }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--brand-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary, .btn.primary { color: #0e1515; } }
button.danger { color: var(--hot); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { border: 0; background: none; padding: 0; color: var(--brand-2); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand-2);
  outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field input, label.field select { font-weight: 400; color: var(--ink); font-size: 14px; }
.check { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; background: var(--panel); }
.check:hover { border-color: var(--brand-2); }
.check input { margin-top: 3px; flex: none; }
.check b { display: block; font-weight: 600; }
.check span { color: var(--muted); font-size: 12px; }
.check.off { opacity: .55; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { width: 240px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--brand); color: #fff; }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650;
  background: var(--soft); position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: var(--soft); }
tbody tr.click { cursor: pointer; }
td .sub { color: var(--muted); font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--soft); color: var(--muted); border: 1px solid var(--line); margin: 1px 3px 1px 0;
  white-space: nowrap; }
.chip.hot { background: color-mix(in srgb, var(--hot) 14%, transparent); color: var(--hot); border-color: transparent; }
.chip.fit { background: color-mix(in srgb, var(--info) 12%, transparent); color: var(--info); border-color: transparent; }
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: transparent; }
.chip.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: transparent; }
.chip.bad { background: color-mix(in srgb, var(--hot) 12%, transparent); color: var(--hot); border-color: transparent; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--hot); }

/* charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--brand-2); }
.chart .bar.hot { fill: var(--hot); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); }
.hbars .hb { display: grid; grid-template-columns: minmax(80px, 34%) 1fr 56px; gap: 8px; align-items: center;
  font-size: 13px; padding: 3px 0; }
.hbars .hb .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .hb .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.hbars svg { width: 100%; height: 10px; display: block; }
.hbars rect.track { fill: var(--soft); }
.hbars rect.fill { fill: var(--brand-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px;
  vertical-align: -1px; background: var(--brand-2); }
.legend i.hot { background: var(--hot); }
.progress { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.progress svg { display: block; width: 100%; height: 8px; }
.progress rect { fill: var(--ok); }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(10,20,20,.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel);
  z-index: 41; overflow-y: auto; padding: 20px 22px 40px; box-shadow: -10px 0 40px rgba(0,0,0,.15);
  border-left: 1px solid var(--line); }
.drawer .close { position: absolute; top: 14px; right: 14px; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 2px; }
dl.kv dd { margin: 0; word-break: break-word; }
.quote { background: var(--soft); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px;
  max-height: 260px; overflow: auto; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% 0%, color-mix(in srgb, var(--brand) 18%, transparent), transparent),
              var(--bg); }
.auth .card { width: min(400px, 100%); padding: 26px; }
.auth .logo { color: var(--ink); padding: 0 0 18px; }
.auth form { display: grid; gap: 12px; }
.err { color: var(--hot); font-size: 13px; min-height: 18px; }
.note { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.note.info { border-left-color: var(--info); background: color-mix(in srgb, var(--info) 8%, transparent); }

/* population */
.steps { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.steps span { padding: 4px 10px; border-radius: 99px; background: var(--soft); color: var(--muted); font-size: 12px;
  font-weight: 600; }
.steps span.on { background: var(--brand); color: #fff; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px; text-align: center;
  background: var(--panel); cursor: pointer; }
.drop.over { border-color: var(--brand-2); background: var(--soft); }
.maptable td, .maptable th { padding: 6px 8px; }
.opts { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
  padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 13px; box-shadow: var(--shadow); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.grid > .card, .stack > .card + .card { margin-top: 0; } .stack > .card + .card { margin-top: 12px; }
.menu-btn svg { width: 20px; height: 20px; }

/* assistant */
.assist { display: grid; grid-template-columns: 240px 1fr; gap: 14px; min-height: 70vh; }
.threads { display: flex; flex-direction: column; gap: 6px; }
.thread { display: block; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.thread:hover { border-color: var(--brand-2); text-decoration: none; }
.thread.on { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.thread .sub { color: var(--muted); font-size: 12px; }
.assist-main { display: flex; flex-direction: column; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.chat { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 64vh; min-height: 320px; }
.msg { max-width: 82%; padding: 10px 13px; border-radius: 12px; line-height: 1.5; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; } .msg ul { margin: 4px 0 4px 18px; padding: 0; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
@media (prefers-color-scheme: dark) { .msg.user { color: #0e1515; } }
.msg.bot { align-self: flex-start; background: var(--soft); border-bottom-left-radius: 4px; }
.msg.act { align-self: flex-start; color: var(--muted); font-size: 12.5px; padding: 0 4px; }
.approval { align-self: stretch; border-left: 3px solid var(--accent); }
.approval .row + .row, .approval .muted { margin-top: 6px; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; min-height: 64px; }
.examples { display: grid; gap: 8px; max-width: 560px; margin: 12px auto 0; text-align: left; }
.examples .check { font: inherit; color: var(--ink); }
@media (max-width: 860px) { .assist { grid-template-columns: 1fr; } .threads { flex-direction: row; overflow-x: auto; } .thread { min-width: 180px; } .msg { max-width: 95%; } }
.helpers { align-self: stretch; } .helper { padding: 6px 0; border-top: 1px solid var(--line); } .helper:first-of-type { border-top: 0; }
