/* Colours follow the workbook: navy #1F2A44 headers, soft-blue #F3F6FB cards,
   grey #6B7280 labels, #9CA3AF footnotes. */
:root {
  --bg: #FFFFFF;
  --bg-2: #F7F8FA;
  --card: #F3F6FB;
  --card-line: #E3E8F1;
  --ink: #1F2A44;
  --ink-2: #374151;
  --label: #6B7280;
  --muted: #9CA3AF;
  --navy: #1F2A44;
  --on-navy: #FFFFFF;
  --accent: #2563EB;
  --good: #15803D;
  --bad: #B91C1C;
  --bar: #BFD3F2;
  --sheet: #FFFFFF;
  --tab-bg: rgba(255,255,255,.92);
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1020; --bg-2: #0F1528; --card: #151C2F; --card-line: #232B42; --ink: #E7EBF3; --ink-2: #C9D0DD;
    --label: #8C96A8; --muted: #687387; --navy: #151C2F; --on-navy: #E7EBF3; --accent: #60A5FA;
    --good: #4ADE80; --bad: #F87171; --bar: #2B4A7A; --sheet: #121a2c; --tab-bg: rgba(11,16,32,.92);
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1020; --bg-2: #0F1528; --card: #151C2F; --card-line: #232B42; --ink: #E7EBF3; --ink-2: #C9D0DD;
  --label: #8C96A8; --muted: #687387; --navy: #151C2F; --on-navy: #E7EBF3; --accent: #60A5FA;
  --good: #4ADE80; --bad: #F87171; --bar: #2B4A7A; --sheet: #121a2c; --tab-bg: rgba(11,16,32,.92);
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
#app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  background: var(--navy); color: var(--on-navy);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
}
.topbar-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 13px; letter-spacing: .12em; font-weight: 700; }
.topbar .total { font-size: 28px; font-weight: 700; letter-spacing: -.01em; margin-top: 6px; }
.topbar .topbar-row { align-items: center; }
.topbar .topbar-row:first-child { align-items: baseline; }
.perf-row { margin-top: 6px; }
.perf { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.75); white-space: nowrap; }
.perf.up { color: #4ADE80; } .perf.down { color: #F87171; }
.perf .arrow { font-size: 10px; }
.perf .perf-label { font-weight: 400; color: rgba(255,255,255,.6); }
.pill { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px; }
.pill button { border: 0; background: none; color: rgba(255,255,255,.75); font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; cursor: pointer; }
.pill button.on { background: #fff; color: #1F2A44; }
.pill.period button { padding: 4px 8px; font-size: 11.5px; }
.topbar .status { font-size: 11px; opacity: .7; text-align: right; }
.topbar .status.err { color: #FCA5A5; opacity: 1; }

#scroller { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }
#view { padding: 12px 16px calc(env(safe-area-inset-bottom) + 84px); max-width: 720px; margin: 0 auto; }

.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; color: var(--label); font-size: 12px; transition: height .2s; }
.ptr.pulling { transition: none; }
.ptr span { padding-bottom: 8px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--tab-bg); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--card-line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; color: var(--muted); cursor: pointer;
}
.tabbar button .tab-ic { height: 26px; width: auto; transition: filter .2s, opacity .2s, transform .2s; }
.tabbar button .tab-ic.line { width: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tabbar button .tab-ic.color { filter: grayscale(.55); opacity: .85; }
.tabbar button .tab-ic .ln { stroke: var(--ink-2); }
.tabbar button.active .tab-ic .ln { stroke: var(--accent); }
.tabbar button.active { color: var(--accent); }
.tabbar button.active .tab-ic.color { filter: none; opacity: 1; transform: scale(1.06); }

/* ---------- common ---------- */
.section-title { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--label); text-transform: uppercase; margin: 18px 4px 8px; }
.card { background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--card-line); background: var(--bg); color: var(--ink-2);
  border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--navy); color: var(--on-navy); border-color: var(--navy); }
:root[data-theme="dark"] .chip.on { background: var(--accent); color: #0B1020; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { background: var(--accent); color: #0B1020; border-color: var(--accent); } }

.wallet-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--card); color: var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 6px 8px; cursor: pointer; color: var(--label); }
.row-actions { display: flex; gap: 8px; margin-top: 14px; }
.row-actions .btn { flex: 1; }
.empty { text-align: center; color: var(--label); padding: 40px 16px; }

/* ---------- holdings ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.toolbar .chips { flex: 1; }
.add-btn { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.hold-list { display: flex; flex-direction: column; }
.hold {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 1px 12px; align-items: center;
  padding: 12px 2px; border-bottom: 1px solid var(--card-line); cursor: pointer;
}
.hold .ic { grid-row: span 2; width: 36px; height: 36px; }
.logo-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--card); display: block; }
.hold .c { text-align: right; font-size: 12.5px; font-weight: 600; color: var(--label); }
.hold .c.up { color: var(--good); } .hold .c.down { color: var(--bad); }
.hold .meta .w { min-width: 40px; }
.hold .meta .q { color: var(--label); white-space: nowrap; }
.hold .meta .wl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.hold:last-child { border-bottom: 0; }
.badge { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 11px; letter-spacing: -.02em; }
.hold .t { font-weight: 700; }
.hold .n { color: var(--label); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hold .v { text-align: right; font-weight: 600; }
.hold .q { text-align: right; color: var(--label); font-size: 12px; }
.hold .meta { grid-column: 2 / 4; display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--label); }
.wbar { flex: 1; min-width: 40px; height: 4px; background: var(--card-line); border-radius: 3px; overflow: hidden; }
.wbar i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.pnl.up { color: var(--good); } .pnl.down { color: var(--bad); }
.synced { font-size: 10px; color: var(--accent); font-weight: 600; }
.total-row { display: flex; justify-content: space-between; padding: 12px 4px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 4px; }
.warn { background: #FEF3C7; color: #92400E; border-radius: 10px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }
:root[data-theme="dark"] .warn { background: #3a2a0a; color: #FCD34D; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .warn { background: #3a2a0a; color: #FCD34D; } }

/* ---------- allocations ---------- */
.pie-wrap { display: grid; place-items: center; margin: 6px 0 0; }
.pie-wrap svg { width: min(92vw, 380px); height: auto; overflow: visible; }
.pie-wrap .slice { cursor: pointer; transition: opacity .2s, transform .25s cubic-bezier(.2,.8,.2,1); }
.pie-wrap .slice.dim { opacity: .45; }

/* 3D allocation pie */
.pie3d { width: min(94vw, 390px); height: auto; overflow: visible; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.pie3d .pslice, .pie3d .pslice + *, .pie3d g > g { transition: transform .26s cubic-bezier(.3,1.5,.5,1), opacity .2s, filter .2s; }
.pie3d .pslice .cuts { display: none; }
.pie3d .pslice.on .cuts { display: inline; }
.pie3d .pslice.dim { opacity: .68; }
.pie3d .pslice.on { filter: brightness(1.08) saturate(1.1); }
.pie3d .pin { animation: pie-in .55s cubic-bezier(.2,.9,.3,1.2) backwards; }
@keyframes pie-in { from { opacity: 0; transform: translateY(-22px); } }
@media (prefers-reduced-motion: reduce) { .pie3d .pin { animation: none; } .pie3d .pslice, .pie3d g > g { transition: none; } }
.glass-card { animation: card-in .2s ease-out; }
@keyframes card-in { from { opacity: .4; transform: translateY(4px) scale(.985); } }
.slice-label { paint-order: stroke; stroke: rgba(0,0,0,.18); stroke-width: 2px; font-variant-numeric: tabular-nums; }
.glass-card, .glass-hint {
  display: flex; align-items: center; gap: 12px; margin: 4px auto 10px; max-width: 360px; padding: 10px 14px; border-radius: 18px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid color-mix(in srgb, #fff 55%, transparent);
  box-shadow: 0 8px 24px rgba(15,23,42,.10), inset 0 1px 0 rgba(255,255,255,.6);
}
:root[data-theme="dark"] .glass-card, :root[data-theme="dark"] .glass-hint { border-color: rgba(255,255,255,.12); box-shadow: 0 8px 24px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .glass-card, :root:not([data-theme="light"]) .glass-hint { border-color: rgba(255,255,255,.12); box-shadow: 0 8px 24px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08); } }
.glass-hint { justify-content: center; color: var(--label); font-size: 13px; padding: 8px 14px; }
.glass-card .lg-ic { width: 30px; height: 30px; }
.gc-name { flex: 1; display: flex; flex-direction: column; }
.gc-name small, .gc-val small { color: var(--label); font-size: 12px; }
.gc-val { display: flex; flex-direction: column; align-items: flex-end; }
.gc-val b { font-size: 18px; }
.legend { display: flex; flex-direction: column; margin-top: 6px; }
.legend-row { display: grid; grid-template-columns: 26px 1fr auto auto; gap: 12px; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--card-line); cursor: pointer; }
.legend-row.sel { background: var(--card); border-radius: 10px; }
.lg-ic { width: 26px; height: 26px; display: block; }
.lg-name { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lg-bar { display: block; height: 4px; background: var(--card-line); border-radius: 2px; overflow: hidden; max-width: 140px; }
.lg-bar i { display: block; height: 100%; border-radius: 2px; }
.legend-row .p { font-weight: 700; min-width: 54px; text-align: right; }
.legend-row .val { color: var(--label); font-size: 13px; min-width: 76px; text-align: right; }

/* ---------- overview (Holdings K-P) ---------- */
.ov-head { background: var(--navy); color: var(--on-navy); text-align: center; font-weight: 700; font-size: 15px; letter-spacing: .04em; padding: 10px; border-radius: 12px 12px 0 0; }
.ov-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 8px; }
.ov-card { background: var(--card); border-radius: 10px; padding: 10px 8px; text-align: center; box-shadow: var(--shadow); }
.ov-card .lbl { font-size: 10px; font-weight: 700; color: var(--label); letter-spacing: .05em; text-transform: uppercase; }
.ov-card .big { font-size: 20px; font-weight: 700; margin-top: 4px; }
.ov-card .mid { font-size: 16px; font-weight: 700; margin-top: 4px; }
.span-3 { grid-column: span 3; } .span-2 { grid-column: span 2; } .span-6 { grid-column: span 6; }
.ov-card .sm { font-size: 12.5px; font-weight: 600; margin-top: 2px; color: var(--label); }
.ov-card .tiny { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.ov-card .up { color: var(--good); } .ov-card .down { color: var(--bad); }
.ov-card.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.perf-grid { margin-top: 0; }
.hist { width: 100%; height: 120px; display: block; }
.hist-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.hist-empty { color: var(--label); font-size: 13px; text-align: center; padding: 18px 14px; }
.stamp { text-align: center; color: var(--muted); font-size: 11px; margin: 10px 0 4px; }
.wallet-rows .w { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--card-line); align-items: center; }
.wallet-rows .w:last-child { border-bottom: 0; }

/* ---------- settings ---------- */
.group { background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--card-line); min-height: 46px; }
.item:last-child { border-bottom: 0; }
.item.tap { cursor: pointer; }
.item .k { flex: 1; }
.item .k small { display: block; color: var(--label); font-size: 12px; margin-top: 2px; }
.item .val { color: var(--label); font-size: 14px; text-align: right; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--card-line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--accent); color: #fff; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card-line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }
.chev { color: var(--muted); }
.foot { color: var(--muted); font-size: 12px; margin: 6px 6px 0; }

/* ---------- forms + sheets ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--label); }
.field-hint { font-size: 11.5px; color: var(--muted); }
.field input, .field select, .field textarea, input.inp, select.inp {
  width: 100%; border: 1px solid var(--card-line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0); transition: background .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop.open { background: rgba(0,0,0,.4); }
.sheet {
  background: var(--sheet); width: 100%; max-width: 720px; max-height: 92vh; display: flex; flex-direction: column;
  border-radius: 16px 16px 0 0; transform: translateY(100%); transition: transform .22s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.sheet-title { font-weight: 700; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 6px 16px 18px; }
.preview-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--card-line); font-size: 14px; }
.preview-row small { display: block; color: var(--label); font-size: 12px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--card); color: var(--label); text-transform: uppercase; }
.tag.replace { background: #DBEAFE; color: #1E40AF; } .tag.new { background: #DCFCE7; color: #166534; } .tag.gone { background: #FEE2E2; color: #991B1B; } .tag.unknown { background: #FEF3C7; color: #92400E; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 76px); transform: translate(-50%, 20px); opacity: 0; z-index: 60;
  background: #111827; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 13px; transition: .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #991B1B; }

/* ---------- lock / onboarding ---------- */
.lock { position: fixed; inset: 0; z-index: 40; background: var(--navy); color: var(--on-navy); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.lock .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 16px; }
.lock h2 { margin: 0 0 6px; font-size: 22px; }
.lock p { margin: 0 0 18px; opacity: .8; max-width: 340px; }
.lock .inp { max-width: 300px; text-align: center; background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); margin-bottom: 10px; }
.lock .inp::placeholder { color: rgba(255,255,255,.55); }
.lock .btn { width: 100%; max-width: 300px; margin-top: 6px; }
.lock .btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.3); }
.lock .err { color: #FCA5A5; min-height: 20px; font-size: 13px; margin-top: 8px; }
.steps { text-align: left; max-width: 340px; font-size: 14px; opacity: .9; }

.haptic-sw { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }

/* Optional light header (light mode only) */
:root[data-header="light"] .topbar { background: var(--bg); color: var(--ink); border-bottom: 1px solid var(--card-line); }
:root[data-header="light"] .perf { color: var(--label); }
:root[data-header="light"] .perf.up { color: var(--good); }
:root[data-header="light"] .perf.down { color: var(--bad); }
:root[data-header="light"] .perf .perf-label { color: var(--label); }
:root[data-header="light"] .pill { background: var(--card); box-shadow: inset 0 0 0 1px var(--card-line); }
:root[data-header="light"] .pill button { color: var(--ink-2); }
:root[data-header="light"] .pill button.on { background: var(--navy); color: #fff; }
:root[data-header="light"] .topbar .status { color: var(--label); opacity: 1; }
:root[data-header="light"] .topbar .status.err { color: var(--bad); }

/* Holdings: combine wallets */
.combine-row { display: flex; justify-content: flex-end; margin: -2px 0 8px; }
.combine { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.combine .switch { transform: scale(.82); transform-origin: right center; margin-left: -4px; }
.wallet-tag.multi { background: var(--card); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--card-line); }
.hold .chev { color: var(--label); font-size: 12px; margin-left: auto; }
.hold.open { border-bottom-color: transparent; }
.sub-hold { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 8px 2px 8px 48px; font-size: 13px; border-bottom: 1px dashed var(--card-line); cursor: pointer; animation: card-in .18s ease-out; }
.sub-hold .q { color: var(--label); }
.sub-hold .wallet-tag { justify-self: start; }
.sub-hold:last-of-type { border-bottom: 1px solid var(--card-line); }

/* Allocations: coins inside Others */
.others-list:empty { display: none; }
.others-list { margin: 0 0 4px 38px; border-left: 2px solid var(--card-line); padding-left: 10px; animation: card-in .2s ease-out; }
.others-row { display: grid; grid-template-columns: 22px 1fr auto 52px; gap: 10px; align-items: center; padding: 6px 4px; font-size: 13px; border-bottom: 1px dashed var(--card-line); }
.others-row:last-child { border-bottom: 0; }
.others-row .lg-ic { width: 22px; height: 22px; }
.others-row .val { color: var(--label); }
.others-row .p { text-align: right; font-weight: 600; }
.hist-note { font-size: 11px; color: var(--label); margin-top: 6px; line-height: 1.35; }
