:root {
  --bg: #f6f5f1; --panel: #ffffff; --panel-2: #fbfaf7; --ink: #1d1b22; --muted: #6f6b78; --line: #e7e4dc;
  --accent: #6d5efc; --accent-2: #8f84ff; --accent-soft: #6d5efc14; --good: #16a34a; --bad: #dc2626; --warn: #d97706;
  --shadow: 0 1px 2px #0000000a, 0 8px 24px #1d1b220d; --radius: 14px;
  --serif: 'Fraunces', Georgia, serif; --sans: 'Inter', system-ui, sans-serif; --mono: 'JetBrains Mono', ui-monospace, monospace;
}
:root[data-theme="dark"] {
  --bg: #121117; --panel: #1b1a22; --panel-2: #17161d; --ink: #ecebf2; --muted: #9c98aa; --line: #2b2935;
  --accent: #8f84ff; --accent-2: #b2aaff; --accent-soft: #8f84ff1f; --shadow: 0 1px 2px #0006, 0 8px 24px #0005;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 7px 13px; cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 9px 11px; outline: none; transition: .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* auth */
.auth { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: radial-gradient(circle at 30% 20%, #8f84ff55, transparent 50%), radial-gradient(circle at 80% 80%, #14b8a644, transparent 50%), #17151f;
  color: #f2f0fa; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-hero h1 { font-size: 46px; line-height: 1.05; max-width: 480px; }
.auth-hero p { color: #c9c5d8; max-width: 440px; font-size: 16px; }
.auth-hero .quote { font-family: var(--serif); font-style: italic; color: #a9a4bd; }
.auth-hero svg.bg { position: absolute; right: -60px; bottom: 80px; opacity: .35; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 28px; margin-bottom: 6px; }
.tabs-inline { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin: 22px 0; }
.tabs-inline button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.tabs-inline button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 600; font-size: 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #14b8a6); display: grid; place-items: center; color: #fff; }

/* shell */
.shell { display: grid; grid-template-columns: 250px 1fr; height: 100%; }
.side { border-right: 1px solid var(--line); background: var(--panel-2); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; overflow: auto; }
.side h4 { margin: 0 6px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.ws-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; color: var(--ink); }
.ws-item:hover { background: var(--accent-soft); }
.ws-item.on { background: var(--panel); box-shadow: var(--shadow); }
.ws-item .em { width: 28px; height: 28px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; }
.ws-item small { display: block; color: var(--muted); font-size: 11.5px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.main { overflow: auto; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 14px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 22px; }
.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav button { border: 0; background: none; padding: 7px 12px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.nav button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.content { padding: 24px 28px 60px; max-width: 1500px; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; position: relative; }
.card h3 { font-size: 15px; font-family: var(--sans); font-weight: 600; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head .tools { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: .15s; }
.card:hover .card-head .tools { opacity: 1; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-6 { grid-column: span 6; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { cursor: pointer; transition: transform .15s; }
.kpi:hover { transform: translateY(-2px); }
.kpi .label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.kpi .value { font-family: var(--serif); font-size: 28px; font-weight: 600; margin: 4px 0 2px; letter-spacing: -0.02em; }
.delta { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 20px; }
.delta.up { color: var(--good); background: #16a34a17; } .delta.down { color: var(--bad); background: #dc262617; } .delta.flat { color: var(--muted); background: var(--panel-2); }
.goalbar { height: 5px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); margin-top: 8px; overflow: hidden; }
.goalbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #14b8a6); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }

/* deductions */
.deductions { background: linear-gradient(135deg, var(--accent-soft), transparent 60%), var(--panel); }
.deductions h3 { font-family: var(--serif); font-size: 18px; }
.deduction { display: flex; gap: 12px; padding: 10px 0; border-top: 1px dashed var(--line); align-items: flex-start; }
.deduction:first-of-type { border-top: 0; }
.deduction .ic { font-size: 18px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--panel-2); flex: none; }
.deduction.warn .ic { background: #d9770617; } .deduction.up .ic { background: #16a34a17; } .deduction.down .ic { background: #dc262617; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.chart .grid-line { stroke: var(--line); stroke-dasharray: 2 4; }
.chart .axis { stroke: var(--line); }
.tip { position: fixed; pointer-events: none; z-index: 100; background: var(--ink); color: var(--bg); padding: 8px 10px; border-radius: 9px; font-size: 12px; box-shadow: var(--shadow); min-width: 120px; }
.tip b { font-weight: 600; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.legend span.off { opacity: .35; }

/* tables */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.t tr:last-child td { border-bottom: 0; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }
.stat small { color: var(--muted); font-size: 11.5px; display: block; }
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* modal */
.overlay { position: fixed; inset: 0; background: #0b0a1066; backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; animation: fade .15s; }
.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 60px); overflow: auto; background: var(--panel); border-radius: 18px; padding: 22px 24px; box-shadow: 0 30px 80px #0005; animation: pop .18s; }
.modal h2 { font-size: 22px; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.choice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice { border: 1px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; text-align: left; background: var(--panel-2); }
.choice:hover { border-color: var(--accent-2); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.choice .ci { font-size: 20px; } .choice b { display: block; font-size: 13px; } .choice small { color: var(--muted); font-size: 11.5px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; cursor: pointer; font-size: 13px; }
.checks input { accent-color: var(--accent); }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: var(--ink); }

/* palette */
.palette { width: min(600px, calc(100vw - 32px)); background: var(--panel); border-radius: 16px; box-shadow: 0 30px 80px #0006; overflow: hidden; align-self: start; margin-top: 12vh; }
.palette input { border: 0; border-bottom: 1px solid var(--line); width: 100%; padding: 16px 18px; font-size: 16px; background: none; outline: none; }
.palette .items { max-height: 360px; overflow: auto; padding: 6px; }
.palette .it { padding: 9px 12px; border-radius: 9px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.palette .it.on { background: var(--accent-soft); color: var(--accent); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow); animation: pop .2s; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 44px; }
pre.code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.drop.over, .drop:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.heat td { width: 36px; height: 30px; text-align: center; font-size: 11px; border-radius: 6px; }
.menu-btn { display: none; }

@media (max-width: 1000px) {
  .span-3, .span-4, .span-6, .span-8 { grid-column: span 12; }
  .auth { grid-template-columns: 1fr; } .auth-hero { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 30; transform: translateX(-105%); transition: .2s; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; } .content { padding: 16px; }
  .nav { margin-left: 0; overflow-x: auto; width: 100%; }
  .choice-grid { grid-template-columns: repeat(2, 1fr); }
}
.grid { align-items: start; }
.deductions .body { max-height: 330px; overflow: auto; padding-right: 4px; }

/* experiments */
.grid-t { font-size: 13px; }
.grid-t th { position: sticky; top: 0; background: var(--panel); z-index: 1; white-space: nowrap; }
.grid-t th.oh { color: var(--accent); }
.grid-t td { padding: 3px 4px; }
.grid-t td.oc { background: var(--accent-soft); }
.cell { width: 100%; min-width: 92px; border: 1px solid transparent; background: transparent; border-radius: 7px; padding: 6px 7px; outline: none; transition: .15s; }
.cell:hover { border-color: var(--line); }
.cell:focus { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-soft); }
.cell.saved { border-color: var(--good); background: #16a34a14; }
.grid-t tbody tr:hover { background: var(--panel-2); }
.pchip { cursor: pointer; padding: 3px 4px 3px 10px; font-size: 12.5px; }
.pchip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.pchip .icon-btn { padding: 0 5px; font-size: 11px; }
.chip.sig2 { color: var(--good); background: #16a34a17; border-color: #16a34a40; font-weight: 600; }
.chip.sig1 { color: #0d9488; background: #14b8a617; border-color: #14b8a640; }
.drivers { display: flex; flex-direction: column; gap: 4px; }
.drv { display: grid; grid-template-columns: 160px 1fr 56px 130px 150px; gap: 12px; align-items: center; padding: 7px 8px; border-radius: 10px; cursor: pointer; }
.drv:hover { background: var(--panel-2); }
.drv-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drv-bar { height: 12px; background: var(--panel-2); border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.drv-bar i { display: block; height: 100%; border-radius: 8px; animation: grow .7s ease-out; transform-origin: left; }
@keyframes grow { from { transform: scaleX(0); } }
.drv-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.drv-dir { font-size: 12px; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.colrow { margin-bottom: 8px; }
.span-5 { grid-column: span 5; } .span-7 { grid-column: span 7; }
@media (max-width: 1000px) { .span-5, .span-7 { grid-column: span 12; } .cols2 { grid-template-columns: 1fr; } .drv { grid-template-columns: 110px 1fr 50px; } .drv > div:nth-child(n+4) { display: none; } }
