:root {
  --surface-0: #0f1115; --surface-1: #17191e; --surface-2: #1e2128; --surface-3: #262a33;
  --border: #2c313b; --grid: #262a33;
  --text-1: #eceef2; --text-2: #a3a9b6; --text-3: #737a88;
  --accent: #00a888; --accent-ink: #04120f; --accent-soft: #00a88822;
  --pos: #2fbf5b; --neg: #ef6b6c; --warn: #fbb315;
  --radius: 14px; --radius-s: 9px;
  --shadow: 0 1px 2px #0006, 0 8px 24px #0003;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --surface-0: #f4f5f7; --surface-1: #ffffff; --surface-2: #f7f8fa; --surface-3: #ffffff;
  --border: #e3e6eb; --grid: #eef0f3;
  --text-1: #191b20; --text-2: #5b6170; --text-3: #8a90a0;
  --accent: #00866d; --accent-ink: #ffffff; --accent-soft: #00866d18;
  --pos: #0b8a2a; --neg: #c93435; --warn: #a86b00;
  --shadow: 0 1px 2px #0000000d, 0 6px 20px #0000000a;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--surface-0); color: var(--text-1); display: flex; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--accent); color: var(--accent-ink); padding: 6px 10px; border-radius: 6px; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 650; } h2 { font-size: 17px; font-weight: 620; } h3 { font-size: 15px; font-weight: 600; }
small, .muted { color: var(--text-2); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* layout */
.sidebar { width: 236px; flex: none; background: var(--surface-1); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; }
.logo svg { width: 28px; height: 28px; display: block; } .logo rect { fill: var(--accent); } .logo path { fill: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-2); padding: 8px 10px; border-radius: 9px; font-weight: 500; }
.nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.nav a:hover { background: var(--surface-2); color: var(--text-1); }
.nav a.active { background: var(--accent-soft); color: var(--text-1); }
.nav a.active i { color: var(--accent); opacity: 1; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 14px 10px 4px; }
.badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.sidebar-foot small { font-size: 11px; color: var(--text-3); }
.sync { font-size: 12px; } .sync::before { content: "●"; margin-right: 6px; } .sync.ok::before { color: var(--pos); } .sync.warn::before { color: var(--warn); } .sync.muted::before { color: var(--text-3); }
.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface-0); position: sticky; top: 0; z-index: 20; }
main { padding: 24px; max-width: 1440px; width: 100%; outline: none; }
.only-mobile { display: none; }

/* search */
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface-3); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; z-index: 30; }
.search-results a { display: flex; gap: 10px; align-items: baseline; padding: 9px 12px; text-decoration: none; }
.search-results a:hover, .search-results a:focus { background: var(--surface-2); }
.search-results b { min-width: 58px; font-family: var(--mono); font-size: 12px; } .search-results span { color: var(--text-2); flex: 1; } .search-results em { font-style: normal; font-size: 11px; color: var(--text-3); }
.search-results a.raw span { font-size: 12px; }
.progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.progress .bar { width: 120px; height: 4px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
#progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* controls */
input, select, textarea { font: inherit; color: var(--text-1); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=range] { accent-color: var(--accent); padding: 0; background: none; border: 0; }
.btn { font: inherit; font-weight: 600; border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: var(--radius-s); cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text-1); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--neg); border-color: var(--border); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text-1); border-radius: 9px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: var(--surface-2); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button, .seg label { border: 0; background: transparent; color: var(--text-2); padding: 6px 12px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 550; font-size: 13px; }
.seg button.on, .seg label:has(input:checked) { background: var(--surface-3); color: var(--text-1); box-shadow: 0 1px 2px #0003; }
.seg input { display: none; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-1); cursor: pointer; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px; }
.filters label.field { min-width: 140px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px; font-size: 12px; color: var(--text-2); cursor: pointer; background: var(--surface-2); user-select: none; }
.chip:has(input:checked) { border-color: var(--accent); color: var(--text-1); background: var(--accent-soft); }
.chip input { display: none; }
.chip.ex:has(input:checked) { border-color: var(--neg); background: #ef6b6c1c; }

/* cards & grid */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 720px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card > header p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.card > header a.more { font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 600; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.g-form { grid-template-columns: 360px minmax(0, 1fr); align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); 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); font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.chart-box { position: relative; height: 300px; } .chart-box.tall { height: 360px; } .chart-box.short { height: 220px; } .chart-box.xs { height: 160px; }
.legend-note { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-top: 10px; flex-wrap: wrap; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; background: var(--text-2); }
.sw.hatch { background: repeating-linear-gradient(135deg, var(--text-2) 0 2px, transparent 2px 5px); border: 1px solid var(--text-2); }
.stack > * + * { margin-top: 16px; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 550; color: var(--text-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface-1); }
th[data-sort] { cursor: pointer; } th[data-sort]:hover { color: var(--text-1); } th.sorted::after { content: " ↓"; } th.sorted.asc::after { content: " ↑"; }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.month-head td { background: var(--surface-2); font-weight: 600; } tr.month-total td { font-weight: 600; color: var(--text-2); }
.co { display: flex; flex-direction: column; text-decoration: none; min-width: 160px; } .co b { font-weight: 600; } .co small { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
a.co:hover b { color: var(--accent); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.isa { color: #00a888; border-color: #00a88855; } .tag.sipp { color: #9887ef; border-color: #9887ef55; } .tag.gia { color: #e76624; border-color: #e7662455; }
.tag.est { font-style: italic; } .tag.declared { color: var(--pos); border-color: currentColor; } .tag.special { color: var(--warn); border-color: currentColor; }
.risk { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }
.risk i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.risk.low i { background: var(--pos); } .risk.med i { background: var(--warn); } .risk.high i { background: var(--neg); }

/* portfolio cards */
.pcard { display: block; text-decoration: none; transition: transform .1s, border-color .1s; }
.pcard:hover { border-color: var(--accent); transform: translateY(-1px); }
.pcard .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pcard .big { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pcard dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.pcard dt { font-size: 11px; color: var(--text-2); } .pcard dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--text-1); border-color: var(--accent); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }
.kv .total { border-top: 1px solid var(--border); padding-top: 8px; font-weight: 700; }
.hbar { display: grid; grid-template-columns: minmax(110px, 1fr) 2fr auto; gap: 8px 10px; align-items: center; font-size: 12px; }
.hbar .track { height: 10px; background: var(--surface-3); border-radius: 0 5px 5px 0; overflow: hidden; }
.hbar .track > div { height: 100%; border-radius: 0 4px 4px 0; }

/* optimizer cards */
.ocards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ocard { display: flex; flex-direction: column; gap: 12px; }
.ocard .top { display: flex; justify-content: space-between; gap: 10px; }
.ocard .yield { text-align: right; } .ocard .yield b { font-size: 24px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; display: block; line-height: 1.1; } .ocard .yield small { font-size: 11px; }
.ocard .facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 12px; }
.ocard .facts span { color: var(--text-2); display: block; font-size: 11px; } .ocard .facts b { font-variant-numeric: tabular-nums; font-weight: 600; }
.ocard table { font-size: 12px; } .ocard td, .ocard th { padding: 5px 6px; }

.week-nav { display: flex; align-items: center; gap: 10px; }
.week-nav b { min-width: 210px; text-align: center; }
.empty { text-align: center; padding: 60px 20px; color: var(--text-2); }
.empty h2 { color: var(--text-1); margin-bottom: 8px; } .empty p { max-width: 520px; margin: 0 auto 16px; }
.note { font-size: 12px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.note.warn { border-color: #fbb31555; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* builder */
.form-card { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; }
.form-card fieldset { border: 0; border-top: 1px solid var(--border); margin: 14px 0 0; padding: 14px 0 0; display: flex; flex-direction: column; gap: 10px; }
.form-card legend { font-weight: 650; font-size: 13px; padding: 0 0 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range-row { display: flex; align-items: center; gap: 10px; } .range-row input[type=range] { flex: 1; } .range-row output { min-width: 50px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; color: var(--text-2); font-size: 12px; }

/* modal & toast */
.modal-wrap { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; z-index: 50; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow); }
.modal.wide { width: min(820px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-body .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--surface-3); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; transition: opacity .4s; }
.toast.warn { border-left-color: var(--warn); } .toast.err { border-left-color: var(--neg); } .toast.out { opacity: 0; }

@media (max-width: 1100px) { .g-side, .g-form { grid-template-columns: 1fr; } .form-card { position: static; max-height: none; } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .only-mobile { display: inline-block; }
  .g2, .g3 { grid-template-columns: 1fr; }
  main { padding: 16px; } .topbar { padding: 10px 12px; } #refresh { display: none; } .progress .bar { display: none; }
}
@media print { .sidebar, .topbar { display: none; } .card { box-shadow: none; } }
