:root {
  --bg: #f4f6f9; --card: #fff; --ink: #18212b; --muted: #66727f; --line: #e4e9ef; --brand: #1f4e78; --brand-ink: #fff;
  --gain: #0a7a3d; --gain-bg: #dff5e7; --loss: #b3261e; --loss-bg: #fde4e2; --warn: #b26a00; --warn-bg: #fff3dc;
  --c-gold: #d4a017; --c-silver: #8c99a8; --c-crypto: #7a5af8; --c-stock: #1e88e5;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f141a; --card: #18202a; --ink: #e8edf2; --muted: #93a0ae; --line: #28323d; --brand: #1b3a57; --brand-ink: #fff;
          --gain: #4cd388; --gain-bg: #12341f; --loss: #ff8a80; --loss-bg: #3a1815; --warn: #f0b252; --warn-bg: #3a2c10;
          --c-gold: #e6b422; --c-silver: #a7b2c0; --c-crypto: #9b82ff; --c-stock: #4aa3f0; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink);
       padding-bottom: calc(72px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
a { color: var(--brand); }

/* header + navigation */
header { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink);
         padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 16px; }
header h1 { font-size: 18px; margin: 0; flex: 0 0 auto; }
header .sp { flex: 1; }
header .upd { font-size: 12px; opacity: .8; white-space: nowrap; }
header .tabs { display: none; gap: 4px; }
header .tabs button { background: none; border: 0; color: #fff; opacity: .75; padding: 8px 14px; border-radius: 8px; font-size: 14px; }
header .tabs button.on { opacity: 1; background: rgba(255,255,255,.18); font-weight: 600; }
#refresh { background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px; padding: 8px 12px; font-size: 14px; white-space: nowrap; }
#refresh:disabled { opacity: .6; }
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: flex;
             padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
nav.bottom button { flex: 1; background: none; border: 0; padding: 9px 4px 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.bottom button svg { width: 22px; height: 22px; }
nav.bottom button.on { color: var(--brand); font-weight: 700; }
@media (prefers-color-scheme: dark) { nav.bottom button.on { color: #7fb2e5; } }
@media (min-width: 860px) {
  header .tabs { display: flex; } nav.bottom { display: none; } body { padding-bottom: 32px; } header { padding-left: 28px; padding-right: 28px; }
}
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
@media (min-width: 860px) { main { padding: 24px 28px; } }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.gain { color: var(--gain); } .loss { color: var(--loss); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.pill.gain { background: var(--gain-bg); } .pill.loss { background: var(--loss-bg); }
.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.ok { background: var(--gain-bg); color: var(--gain); }
.banner.err { background: var(--loss-bg); color: var(--loss); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.num { font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.cls-gold { --c: var(--c-gold); } .cls-silver { --c: var(--c-silver); } .cls-crypto { --c: var(--c-crypto); } .cls-stock { --c: var(--c-stock); }
.dot { background: var(--c); }

/* dashboard */
.kpis { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
.kpis .card { margin: 0; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .big { font-size: 30px; font-weight: 700; letter-spacing: -.5px; line-height: 1.2; }
.kpi .sub { margin-top: 4px; }
@media (min-width: 700px) { .kpis { grid-template-columns: 1.4fr 1fr 1fr; } .kpi .big { font-size: 34px; } }
.cols { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.cols > *, .kpis > *, .formwrap > *, .classes > * { min-width: 0; }
.cols > .card { margin: 0; }
@media (min-width: 860px) { .cols.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); } }
.insights { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.insights li { padding-left: 22px; position: relative; }
.insights li::before { content: ''; position: absolute; left: 4px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.insights li.g::before { background: var(--gain); } .insights li.l::before { background: var(--loss); } .insights li.w::before { background: var(--warn); }
.alloc { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.alloc svg { width: 160px; height: 160px; flex: 0 0 auto; }
.alloc .legend { flex: 1; min-width: 160px; display: grid; gap: 8px; }
.alloc .legend .row { align-items: center; }
.donut-c { fill: var(--ink); font-size: 4.6px; font-weight: 700; text-anchor: middle; }
.donut-s { fill: var(--muted); font-size: 2.8px; text-anchor: middle; }
.classes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
@media (min-width: 700px) { .classes { grid-template-columns: repeat(4, 1fr); } }
.classes .card { margin: 0; border-top: 3px solid var(--c); padding: 12px 14px; }
.classes .v { font-size: 20px; font-weight: 700; }

/* P/L bars (diverging around zero) */
.bars { display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: 56px minmax(0, 1fr) 70px; align-items: center; gap: 10px; font-size: 14px; }
.bar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { position: relative; height: 18px; background: var(--bg); border-radius: 6px; }
.bar .track::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line); }
.bar .fill { position: absolute; top: 2px; bottom: 2px; border-radius: 4px; }
.bar .fill.gain { background: var(--gain); left: 50%; } .bar .fill.loss { background: var(--loss); right: 50%; }
.bar .val { text-align: right; }

/* tables */
.tablewrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { text-align: right; padding: 11px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
td .sym { font-weight: 700; } td .nm { color: var(--muted); font-size: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .dot { margin-right: 6px; }
.chip.on .dot { background: #fff; }

/* holdings cards (mobile first) */
.asset { padding: 0; overflow: hidden; border-left: 4px solid var(--c); }
.asset > .head { padding: 14px 16px; cursor: pointer; display: grid; gap: 4px; }
.asset .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px 14px; }
.asset .stats div { font-size: 13px; } .asset .stats b { display: block; font-size: 14px; }
.asset .lots { border-top: 1px solid var(--line); background: var(--bg); }
.lot { display: flex; justify-content: space-between; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.lot:first-child { border-top: 0; }
.lot .r { text-align: right; white-space: nowrap; }
.stale { color: var(--warn); font-size: 12px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
input, select, textarea { width: 100%; padding: 11px 12px; font-size: 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.btn { width: 100%; margin-top: 18px; padding: 13px; font-size: 16px; font-weight: 600; border: 0; border-radius: 10px; background: var(--brand); color: #fff; }
.btn:disabled { opacity: .6; }
.btn.alt { background: none; color: var(--brand); border: 1px solid var(--line); margin-top: 8px; }
.btn.del { background: none; color: var(--loss); border: 1px solid var(--line); margin-top: 8px; }
@media (prefers-color-scheme: dark) { .btn.alt { color: #7fb2e5; } }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formwrap { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .formwrap { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; } }
.classpick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.classpick button { border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 12px 4px; font-weight: 600; font-size: 14px; }
.classpick button.on { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.results { border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; overflow: hidden; }
.results button { display: flex; justify-content: space-between; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 12px; }
.results button:first-child { border-top: 0; } .results button:hover { background: var(--bg); }
.picked { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--bg); margin-top: 8px; }
.preview .big { font-size: 26px; font-weight: 700; }
.preview dl { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.preview dt { color: var(--muted); } .preview dd { margin: 0; text-align: right; }

.login { max-width: 360px; margin: 16vh auto 0; padding: 0 16px; }
.empty { text-align: center; padding: 36px 16px; }
.empty .btn { width: auto; padding: 12px 22px; }
.err { color: var(--loss); margin-top: 12px; } .ok { color: var(--gain); }

@media (max-width: 600px) { .hm { display: none; } .alloc { justify-content: center; } .kpi .big { font-size: 28px; } }
@media (max-width: 600px) { header .upd { display: none; } header { gap: 8px; } .tablewrap { margin: 0; } th, td { padding-left: 4px; padding-right: 4px; } }
