:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0f7b3e;
  --bad: #c0322f;
  --warn: #9a6400;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --actual: #52514e;
  --grid: #e8e7e3;
  --input-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #918f86;
    --accent: #3987e5;
    --good: #4cc27c;
    --bad: #ef7372;
    --warn: #e0a437;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --actual: #c3c2b7;
    --grid: #2a2a28;
    --input-bg: #141413;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #918f86;
  --accent: #3987e5;
  --good: #4cc27c;
  --bad: #ef7372;
  --warn: #e0a437;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --actual: #c3c2b7;
  --grid: #2a2a28;
  --input-bg: #141413;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-size: 14px; }
.otp-input { letter-spacing: 10px; font-size: 22px; text-align: center; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px;
}
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2);
  white-space: nowrap; font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.tabs { align-items: center; }
.tab-group { display: flex; align-items: center; gap: 2px; }
.tab-group + .tab-group { border-left: 1px solid var(--border); margin-left: 8px; padding-left: 8px; }
.tab-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-right: 4px; }
.tab-group:not(.tools) .tab { font-size: 13px; padding: 6px 9px; }
.tab.primary { font-weight: 600; color: var(--text); padding: 8px 16px; }
.tab.primary.active { background: var(--accent); color: var(--accent-ink); }
.tab.primary:not(.active):hover { background: var(--surface-2); }
.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
main { padding: 20px; max-width: 1440px; margin: 0 auto; display: grid; gap: 16px; }
.page { display: grid; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--text-2); }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---------- forms ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer;
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=number], select, textarea {
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 10px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.error { color: var(--bad); font-size: 13px; }
.note { font-size: 12px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }

/* ---------- plan layout ---------- */
.plan-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.assump { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.assump-group { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; display: grid; gap: 10px; }
.assump-group:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.arow { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 8px; align-items: center; }
.arow .lab { font-size: 12.5px; }
.arow .lab .why { display: block; color: var(--text-3); font-size: 11.5px; }
.arow .changed { color: var(--accent); }
.arow input, .arow select { padding: 5px 8px; text-align: right; }
.arow select { text-align: left; }
.scen-list { display: flex; gap: 6px; flex-wrap: wrap; }
.scen-chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 5px 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
.scen-chip.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.hire-row { display: grid; grid-template-columns: minmax(0, 1fr) 78px 52px 66px 66px 28px; gap: 6px; align-items: center; }
.hire-row input { padding: 5px 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; font-size: 12.5px; }
th { font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
th:first-child { background: var(--surface-2); z-index: 2; }
tr.total td { font-weight: 650; }
tr.section td { font-weight: 650; color: var(--text-2); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.l, th.l { text-align: left; }
.scroll-y { max-height: 520px; overflow: auto; }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .line { width: 16px; height: 0; border-top: 2px solid; }
.legend .line.dash { border-top-style: dashed; }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100vh - 170px); min-height: 420px; }
.chat-log { overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 4px 12px; }
.msg { max-width: 820px; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); }
.msg.assistant table { margin: 6px 0; width: auto; }
.msg.assistant th, .msg.assistant td { position: static; background: transparent; }
.chat-form { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.chat-form textarea { resize: none; height: 64px; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50; box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  .plan-layout { grid-template-columns: minmax(0, 1fr); }
  .assump { position: static; max-height: none; }
}
@media (max-width: 760px) {
  main { padding: 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .userbox .email, .userbox .pill, .brand-name, .tab-group-label { display: none; }
  .tab.primary { padding: 7px 12px; }
  .kpi .value { font-size: 20px; }
}
