/* ==========================================================================
   Wealth Insight — glass UI, mobile first.
   Built on the CutoffGenie UI guide: the same tokens, type, backdrop, shell
   and components, plus the portfolio-specific pieces (holdings cards, value
   pills, allocation charts, longevity sliders, the investment form).

   Theme: light by default, dark from the system setting, and either one
   when the viewer picks it (data-theme on <html>, saved by js/theme.js
   under wealthInsight.theme.v1). Every colour is a token; add new tokens to
   all three token blocks.
   ========================================================================== */

/* ---------- font: Plus Jakarta Sans 400–800 (variable), self-hosted ---------- */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../fonts/plus-jakarta-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../fonts/plus-jakarta-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- tokens: light ---------- */
:root {
  color-scheme: light;
  --bg: #eceefb;
  --bg-2: #f7f5ff;
  --blob-1: rgba(167, 139, 250, 0.55);
  --blob-2: rgba(103, 232, 249, 0.45);
  --blob-3: rgba(249, 168, 212, 0.45);
  --blob-4: rgba(147, 197, 253, 0.55);
  --glass: linear-gradient(150deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.58));
  --glass-solid: rgba(250, 250, 255, 0.94);
  --card-bg: linear-gradient(150deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.62));
  --bar-bg: rgba(250, 250, 255, 0.84);
  --sheet-bg: rgba(248, 248, 255, 0.92);
  --table-solid: #f6f6fd;
  --glass-border: rgba(255, 255, 255, 0.85);
  --glass-hi: rgba(255, 255, 255, 0.9);
  --shadow: 0 24px 48px -28px rgba(49, 46, 129, 0.35), 0 2px 6px rgba(49, 46, 129, 0.05);
  --shadow-sm: 0 14px 30px -22px rgba(49, 46, 129, 0.5), 0 1px 3px rgba(49, 46, 129, 0.05);
  --surface: #f3f3fb;
  --ink: #15142b;
  --ink-2: #45435f;
  --ink-3: #5b5977;
  --hairline: rgba(21, 20, 43, 0.09);
  --grid: rgba(21, 20, 43, 0.08);
  --axis: rgba(21, 20, 43, 0.22);
  --field-bg: rgba(255, 255, 255, 0.6);
  --chip-bg: rgba(255, 255, 255, 0.7);
  --track: rgba(21, 20, 43, 0.1);
  --seg-active: #ffffff;
  --focus: rgba(124, 58, 237, 0.28);
  --notice-bg: rgba(250, 178, 25, 0.14);
  --notice-border: rgba(250, 178, 25, 0.35);
  --info-bg: rgba(124, 58, 237, 0.08);
  --accent-1: #6d28d9;
  --accent-2: #0891b2;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 55%, #06b6d4 100%);
  --btn-grad: linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
  --hero-ink: linear-gradient(180deg, #15142b 35%, #5b3fd6 100%);
  --good: #0ca30c;
  --ok-ink: #03694c;
  --ok-bg: rgba(5, 150, 105, 0.12);
  --warn-ink: #8a5a00;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --danger: #b91c1c;
  --loss-ink: #b42318;
  --loss-bg: rgba(220, 38, 38, 0.1);

  /* Data colours: the guide's validated categorical palette. Marks use
     them directly; text beside a mark uses an *-ink step instead. */
  --rank1: #2a78d6;
  --rank2: #008300;
  --rank3: #e87ba4;
  --rank4: #eda100;
  --rank5: #1baf7a;

  /* Portfolio identity: real estate vs. liquid (investable) assets.
     Aliases, so they follow whichever theme block is active. */
  --re-mark: var(--rank4);
  --re-ink: var(--warn-ink);
  --liquid-mark: var(--rank5);
  --liquid-ink: var(--ok-ink);

  --topbar-h: 65px;
  --sidebar-w: 254px;
  --sidebar-w-collapsed: 76px;
  --sticky-top: calc(var(--topbar-h) + env(safe-area-inset-top));
}

/* ---------- tokens: dark (system preference, unless the viewer picked light) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0a1a;
    --bg-2: #171433;
    --blob-1: rgba(124, 58, 237, 0.3);
    --blob-2: rgba(6, 182, 212, 0.18);
    --blob-3: rgba(236, 72, 153, 0.18);
    --blob-4: rgba(79, 70, 229, 0.28);
    --glass: linear-gradient(150deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
    --glass-solid: rgba(28, 27, 51, 0.94);
    --card-bg: linear-gradient(150deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.03));
    --bar-bg: rgba(22, 20, 44, 0.84);
    --sheet-bg: rgba(24, 22, 46, 0.92);
    --table-solid: #221f3f;
    --glass-border: rgba(255, 255, 255, 0.13);
    --glass-hi: rgba(255, 255, 255, 0.14);
    --shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 16px 32px -22px rgba(0, 0, 0, 0.8), 0 1px 4px rgba(0, 0, 0, 0.2);
    --surface: #1c1b33;
    --ink: #f4f3ff;
    --ink-2: #c6c4e2;
    --ink-3: #b8b6d6;
    --hairline: rgba(255, 255, 255, 0.1);
    --grid: rgba(255, 255, 255, 0.08);
    --axis: rgba(255, 255, 255, 0.24);
    --field-bg: rgba(255, 255, 255, 0.05);
    --chip-bg: rgba(255, 255, 255, 0.06);
    --track: rgba(255, 255, 255, 0.12);
    --seg-active: rgba(255, 255, 255, 0.14);
    --focus: rgba(167, 139, 250, 0.35);
    --notice-bg: rgba(250, 178, 25, 0.12);
    --notice-border: rgba(250, 178, 25, 0.3);
    --info-bg: rgba(167, 139, 250, 0.1);
    --accent-1: #b4a0fb;
    --accent-2: #22d3ee;
    --hero-ink: linear-gradient(180deg, #ffffff 30%, #c4b5fd 100%);
    --ok-ink: #6ee7b7;
    --ok-bg: rgba(52, 211, 153, 0.13);
    --warn-ink: #fcd34d;
    --warn-bg: rgba(251, 191, 36, 0.14);
    --danger: #f87171;
    --loss-ink: #f59494;
    --loss-bg: rgba(248, 113, 113, 0.14);
    --rank1: #3987e5;
    --rank2: #008300;
    --rank3: #d55181;
    --rank4: #c98500;
    --rank5: #199e70;
  }
}

/* ---------- tokens: dark (explicit toggle) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0a1a;
  --bg-2: #171433;
  --blob-1: rgba(124, 58, 237, 0.3);
  --blob-2: rgba(6, 182, 212, 0.18);
  --blob-3: rgba(236, 72, 153, 0.18);
  --blob-4: rgba(79, 70, 229, 0.28);
  --glass: linear-gradient(150deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  --glass-solid: rgba(28, 27, 51, 0.94);
  --card-bg: linear-gradient(150deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.03));
  --bar-bg: rgba(22, 20, 44, 0.84);
  --sheet-bg: rgba(24, 22, 46, 0.92);
  --table-solid: #221f3f;
  --glass-border: rgba(255, 255, 255, 0.13);
  --glass-hi: rgba(255, 255, 255, 0.14);
  --shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 16px 32px -22px rgba(0, 0, 0, 0.8), 0 1px 4px rgba(0, 0, 0, 0.2);
  --surface: #1c1b33;
  --ink: #f4f3ff;
  --ink-2: #c6c4e2;
  --ink-3: #b8b6d6;
  --hairline: rgba(255, 255, 255, 0.1);
  --grid: rgba(255, 255, 255, 0.08);
  --axis: rgba(255, 255, 255, 0.24);
  --field-bg: rgba(255, 255, 255, 0.05);
  --chip-bg: rgba(255, 255, 255, 0.06);
  --track: rgba(255, 255, 255, 0.12);
  --seg-active: rgba(255, 255, 255, 0.14);
  --focus: rgba(167, 139, 250, 0.35);
  --notice-bg: rgba(250, 178, 25, 0.12);
  --notice-border: rgba(250, 178, 25, 0.3);
  --info-bg: rgba(167, 139, 250, 0.1);
  --accent-1: #b4a0fb;
  --accent-2: #22d3ee;
  --hero-ink: linear-gradient(180deg, #ffffff 30%, #c4b5fd 100%);
  --ok-ink: #6ee7b7;
  --ok-bg: rgba(52, 211, 153, 0.13);
  --warn-ink: #fcd34d;
  --warn-bg: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --loss-ink: #f59494;
  --loss-bg: rgba(248, 113, 113, 0.14);
  --rank1: #3987e5;
  --rank2: #008300;
  --rank3: #d55181;
  --rank4: #c98500;
  --rank5: #199e70;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--sticky-top) + 12px);
}
html.modal-open { overflow: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent-1); outline-offset: 2px; }
/* `hidden` must win over class-level display: flex/grid */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--ink-3); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.up { color: var(--ok-ink); }
.down { color: var(--loss-ink); }

/* inline SVG sprite (js/icons.js): <svg class="i"><use href="#i-name"/></svg> */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i {
  width: 1em;
  height: 1em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.125em;
}

/* ---------- moving backdrop ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(120% 70% at 50% -10%, var(--bg-2), var(--bg) 65%);
}
.blob {
  position: absolute;
  width: 75vmax;
  height: 75vmax;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--c), transparent 72%);
  will-change: transform;
  animation: drift 28s ease-in-out infinite alternate;
}
.b1 { --c: var(--blob-1); top: -30vmax; left: -25vmax; }
.b2 { --c: var(--blob-2); top: 5vh; right: -35vmax; animation-duration: 34s; animation-delay: -9s; }
.b3 { --c: var(--blob-3); bottom: -35vmax; left: -15vmax; animation-duration: 38s; animation-delay: -15s; }
.b4 { --c: var(--blob-4); bottom: -25vmax; right: -25vmax; animation-duration: 31s; animation-delay: -4s; }
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(7vmax, 5vmax, 0) scale(1.08); }
  100% { transform: translate3d(-5vmax, 9vmax, 0) scale(0.94); }
}
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- glass ----------
   Cards are translucent gradients WITHOUT backdrop blur (blur on tall or
   repeated surfaces stalls phones). Real blur is kept for the small fixed
   surfaces only: top bar, tab bar, desktop sidebar and the sheet. */
.glass {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-hi);
}
.card { border-radius: 24px; padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head > div { min-width: 0; }
.card-head h2, .card-title { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.3; }
.card-sub { margin-top: 4px; font-size: 13px; color: var(--ink-3); line-height: 1.5; overflow-wrap: anywhere; }
.card-sub strong, .card-sub b { color: var(--ink-2); }
.card-icon { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 11px; background: var(--chip-bg); border: 1px solid var(--hairline); color: var(--accent-1); }
.card-icon .i { width: 17px; height: 17px; }

/* ==========================================================================
   Top bar (phones & tablets)
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid transparent;
  transition: background 0.3s, border-color 0.3s;
}
.topbar.scrolled {
  background: var(--bar-bg);
  border-bottom-color: var(--glass-border);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.brand-mark { width: 36px; height: 36px; flex: none; border-radius: 11px; box-shadow: 0 6px 18px -6px rgba(99, 102, 241, 0.6); }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; white-space: nowrap; }
.brand-text strong { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.brand-text span { font-size: 12px; color: var(--ink-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.2s, border-color 0.2s;
}
.icon-btn:hover { border-color: var(--accent-1); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .i { width: 20px; height: 20px; }
.i-moon { display: none; }
:root[data-effective="light"] .i-sun { display: none; }
:root[data-effective="light"] .i-moon { display: block; }

/* sync status: a pill in the top bar, a row in the sidebar */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  max-width: 46vw;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s, transform 0.15s;
}
.sync-pill:hover { border-color: var(--accent-1); color: var(--ink); }
.sync-pill:active { transform: scale(0.96); }
.sync-label { overflow: hidden; text-overflow: ellipsis; }
.sync-dot { position: relative; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--good); }
.sync-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; opacity: 0.5; animation: pulse 2.4s infinite; }
.sync-pill.is-offline .sync-dot { background: var(--rank4); }
.sync-pill.is-offline .sync-dot::after { animation: none; }
.sync-pill.is-syncing .sync-dot { background: var(--accent-1); }
.sync-pill.is-syncing .sync-dot::after { animation-duration: 1s; }
.sync-count { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--btn-grad); color: #fff; font-size: 11px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
@keyframes pulse { 70%, 100% { transform: scale(3); opacity: 0; } }

/* ==========================================================================
   App shell: sidebar (desktop) + content
   ========================================================================== */
.app-shell { display: block; }
.app-content { min-width: 0; }
.sidebar { display: none; }

/* ==========================================================================
   Bottom tab bar (phones & tablets) — floating, 5 tabs with Add in the middle
   ========================================================================== */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  width: min(480px, calc(100% - 24px));
  padding: 6px;
  border-radius: 24px;
  border: 1px solid var(--glass-border);
  background: var(--bar-bg);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-hi);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  transform: translateX(-50%);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 52px;
  padding: 8px 4px 7px;
  border: 0;
  border-radius: 18px;
  background: none;
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .i { width: 22px; height: 22px; }
.tab:hover { color: var(--ink); }
.tab:active { transform: scale(0.96); }
.tab[aria-current="page"] { background: var(--seg-active); color: var(--ink); box-shadow: 0 2px 10px -3px rgba(15, 12, 40, 0.3); }
.tab[aria-current="page"] .i { color: var(--accent-1); }
.tab-add { color: var(--ink-2); }
.tab-add-icon { display: grid; place-items: center; width: 40px; height: 26px; border-radius: 10px; background: var(--btn-grad); color: #fff; box-shadow: 0 8px 18px -8px rgba(79, 70, 229, 0.8); }
.tab-add-icon .i { width: 18px; height: 18px; stroke-width: 2.6; }
@media (max-width: 359px) { .tab { padding-inline: 2px; font-size: 10.5px; letter-spacing: -0.01em; } }

/* ==========================================================================
   Layout + page intro
   ========================================================================== */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px max(16px, env(safe-area-inset-right)) calc(112px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  outline: none;
}
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.stack > * { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }

.intro { padding: 10px 2px 20px; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--glass-border);
  color: var(--ink-2);
}
.eyebrow > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse { position: relative; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--good); }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--good); opacity: 0.5; animation: pulse 2.4s infinite; }
h1 {
  margin-top: 14px;
  font-size: clamp(28px, 7.6vw, 44px);
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.035em;
  background: var(--hero-ink);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding-bottom: 0.06em;
  overflow-wrap: anywhere;
}
.lede { margin-top: 10px; font-size: 15px; color: var(--ink-2); max-width: 44em; }
.intro-controls { display: grid; gap: 12px; margin-top: 18px; min-width: 0; }
.intro-controls:empty { display: none; }
.intro-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* a heading between sections, outside cards */
.group { display: grid; gap: 10px; min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 4px 0; }
.section-head h2 { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 17px; font-weight: 800; letter-spacing: -0.015em; }
.section-head .meta { flex: none; font-size: 13px; font-weight: 700; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Segmented control (buttons) — owner filter, view toggles, form choices
   ========================================================================== */
.seg {
  display: inline-flex;
  max-width: 100%;
  padding: 3px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
}
.seg > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 11px;
  background: none;
  color: var(--ink-3);
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, color 0.2s;
}
.seg > button:hover { color: var(--ink); }
.seg > button[aria-pressed="true"] { background: var(--seg-active); color: var(--ink); box-shadow: 0 2px 8px -2px rgba(15, 12, 40, 0.25); }
.seg .i { width: 18px; height: 18px; }
/* in-card segmented control (field surface, no blur) */
.seg.seg-field { background: var(--field-bg); border-color: var(--hairline); }
/* full-width segments that share the space */
.seg.seg-block { display: flex; width: 100%; }
.seg.seg-block > button { flex: 1 1 0; min-width: 0; padding: 0 8px; }
.seg.seg-block > button > span { overflow: hidden; text-overflow: ellipsis; }
/* a long list of segments scrolls sideways */
.seg.seg-scroll { overflow-x: auto; scrollbar-width: none; }
.seg.seg-scroll::-webkit-scrollbar { display: none; }

/* ==========================================================================
   Buttons & chips
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 14.5px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn .i { width: 18px; height: 18px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { color: #fff; background: var(--btn-grad); box-shadow: 0 10px 24px -10px rgba(79, 70, 229, 0.8); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s, color 0.2s, transform 0.15s;
}
.btn-ghost:hover { border-color: var(--accent-1); color: var(--ink); }
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost .i { width: 18px; height: 18px; }
/* destructive: tinted, never white-on-red (fails contrast in dark mode) */
.btn-danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > * { flex: 1 1 auto; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px 0 14px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.chip .i { width: 17px; height: 17px; }
.chip:hover:not([disabled]) { border-color: var(--accent-1); color: var(--ink); }
.chip:active:not([disabled]) { transform: scale(0.96); }
.chip[disabled] { opacity: 0.45; cursor: not-allowed; }
.chip.sm { min-height: 40px; padding: 0 14px 0 12px; font-size: 13.5px; }
.toggle-chip[aria-pressed="true"] { color: #fff; background: var(--btn-grad); border-color: transparent; box-shadow: 0 8px 20px -10px rgba(79, 70, 229, 0.8); }
/* touch screens keep :hover after a tap — don't let it grey out a pressed chip */
.chip.toggle-chip[aria-pressed="true"]:hover { color: #fff; border-color: transparent; }
.chip-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--btn-grad); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.toggle-chip[aria-pressed="true"] .chip-count { background: rgba(255, 255, 255, 0.25); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-scroll { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
.chip-scroll::-webkit-scrollbar { display: none; }
.chip-scroll > * { flex: none; }

.link-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 4px 0; font-size: 13px; font-weight: 700; color: var(--accent-1); cursor: pointer; }
.link-btn .i { width: 15px; height: 15px; }

/* ==========================================================================
   Form controls — every field ≥ 16px so iOS never zooms on focus
   ========================================================================== */
.form { display: grid; gap: 16px; min-width: 0; }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label, .field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.req { color: var(--danger); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-hint { font-size: 12.5px; color: var(--ink-3); }

.input, select, .select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background-color: var(--field-bg);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); opacity: 0.7; font-weight: 500; }
.input:hover, select:hover { border-color: color-mix(in srgb, var(--accent-1) 45%, var(--hairline)); }
.input:focus, select:focus, .textarea:focus { border-color: var(--accent-1); box-shadow: 0 0 0 4px var(--focus); }
.input[readonly] { background-color: transparent; color: var(--ink-2); border-style: dashed; }
input[type="date"].input { -webkit-appearance: none; appearance: none; line-height: 46px; }
select, .select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 20px center, right 15px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
select option { background: var(--surface); color: var(--ink); }
.textarea { height: auto; min-height: 88px; padding: 12px 14px; line-height: 1.45; resize: vertical; font-weight: 500; }

/* prefix / suffix inputs: ₹ amounts and % rates */
.affix {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: var(--field-bg);
  cursor: text;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.affix:focus-within { border-color: var(--accent-1); box-shadow: 0 0 0 4px var(--focus); }
.affix-text { flex: none; font-weight: 800; color: var(--ink-3); }
.affix input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.affix input::placeholder { color: var(--ink-3); opacity: 0.6; }
/* the big number field (values you update most) */
.affix.big { height: 60px; padding: 0 16px; border-radius: 18px; }
.affix.big .affix-text { font-size: 22px; }
.affix.big input { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.affix.is-computed { background: transparent; border-style: dashed; }
.affix.is-computed input { color: var(--ink-2); }
.money-stack { display: grid; gap: 4px; min-width: 0; }
.amount-hint:empty { display: none; }
.amount-hint { font-size: 12.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.field.invalid .input, .field.invalid .affix { border-color: var(--danger); }
.field-error { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--danger); }
.field-error .i { width: 15px; height: 15px; }

/* grouped form sections (the investment form) */
.fgroup {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--glass-hi);
}
.fgroup-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fgroup-head h3 { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.fgroup-head .card-icon { width: 30px; height: 30px; border-radius: 10px; }
.fgroup-head .card-icon .i { width: 16px; height: 16px; }
.fgroup.accent { border-color: color-mix(in srgb, var(--accent-1) 35%, var(--glass-border)); }

/* asset-class picker (add) / current class row (edit) */
.class-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.class-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 16px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}
.class-opt:hover { border-color: var(--accent-1); color: var(--ink); }
.class-opt:active { transform: scale(0.97); }
.class-opt[aria-pressed="true"] { background: var(--seg-active); color: var(--ink); border-color: var(--accent-1); box-shadow: 0 0 0 3px var(--focus); }
.class-opt .emoji { font-size: 20px; line-height: 1; flex: none; }
.class-opt .nm { min-width: 0; line-height: 1.25; }
.class-current { display: flex; align-items: center; gap: 12px; min-width: 0; }
.class-current .emoji { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 12px; font-size: 20px; background: color-mix(in srgb, var(--tint, var(--accent-1)) 16%, transparent); border: 1px solid var(--hairline); }
.class-current .nm { flex: 1; min-width: 0; font-weight: 800; }
.class-current .nm span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }

/* live gain / loss under the value fields */
.gain-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--chip-bg);
  border: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 600;
}
.gain-preview strong { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }
.gain-preview strong.up { color: var(--ok-ink); }
.gain-preview strong.down { color: var(--loss-ink); }

/* emoji + colour pickers (owners, asset classes) */
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-opt { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--hairline); background: var(--chip-bg); font-size: 21px; cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; }
.emoji-opt[aria-pressed="true"] { border-color: var(--accent-1); box-shadow: 0 0 0 3px var(--focus); background: var(--seg-active); }
.swatch-dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.color-input { width: 100%; height: 48px; padding: 4px; border-radius: 14px; border: 1px solid var(--hairline); background: var(--field-bg); cursor: pointer; }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 10px; }
.color-input::-moz-color-swatch { border: 0; border-radius: 10px; }

/* search field: icon + input */
.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 48px;
  padding: 0 12px 0 14px;
  border-radius: 16px;
  border: 1px solid var(--hairline);
  background: var(--field-bg);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within { border-color: var(--accent-1); box-shadow: 0 0 0 4px var(--focus); }
.search-box > .i { width: 19px; height: 19px; color: var(--ink-3); }
.search-box input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; background: none; color: var(--ink); font-size: 16px; font-weight: 500; }
.search-box input::placeholder { color: var(--ink-3); opacity: 0.85; }

/* ==========================================================================
   Filters (dashboard + holdings)
   ========================================================================== */
.filters { display: grid; gap: 10px; min-width: 0; }

/* ==========================================================================
   Stat tiles
   ========================================================================== */
.stats-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat-tile {
  min-width: 0;
  padding: 14px 16px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--glass-hi);
}
.stat-value { font-size: clamp(20px, 6.2vw, 24px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-label { margin-top: 2px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.stat-label .i { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.stat-sub { margin-top: 4px; font-size: 12.5px; font-weight: 700; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.stat-sub.up { color: var(--ok-ink); }
.stat-sub.down { color: var(--loss-ink); }
.stat-tile.accent .stat-value { background: var(--hero-ink); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-tile.wide { grid-column: 1 / -1; }
.stat-tile.wide .stat-value { font-size: clamp(26px, 8vw, 34px); }
@media (max-width: 359px) { .stat-tile { padding: 12px 13px; } }

/* share of the whole: thin bar under a tile */
.share-bar { height: 6px; margin-top: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.share-bar > i { display: block; height: 100%; border-radius: inherit; }

/* ==========================================================================
   Cards in lists (holdings, owners, asset classes) — never blurred
   ========================================================================== */
.card-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
@media (min-width: 860px) { .card-list.cols { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.rcard {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 12px 12px 12px 14px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--glass-hi);
  color: var(--ink);
  text-align: left;
  transition: transform 0.18s, border-color 0.2s, opacity 0.2s;
}
button.rcard { font: inherit; }
.rcard.clickable { cursor: pointer; touch-action: manipulation; }
.card-list > .rcard { content-visibility: auto; contain-intrinsic-size: auto 72px; }
.rcard.clickable:hover { border-color: var(--accent-1); }
.rcard.clickable:active { transform: scale(0.985); }
.rcard.muted-card { opacity: 0.6; }
.rcard-left { flex: 1; min-width: 0; display: grid; gap: 3px; }
.rcard-left > * { display: block; min-width: 0; }
.rcard-title { font-size: 14.5px; font-weight: 700; line-height: 1.3; letter-spacing: -0.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcard-sub { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcard-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }

/* emoji avatar tinted with the category / owner colour (data, not a token) */
.ava {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 13px;
  font-size: 20px;
  line-height: 1;
  background: color-mix(in srgb, var(--tint, var(--accent-1)) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint, var(--accent-1)) 30%, transparent);
}
.owner-chip, .tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag.warn { color: var(--warn-ink); background: var(--warn-bg); border-color: transparent; }
.tag.ok { color: var(--ok-ink); background: var(--ok-bg); border-color: transparent; }
.tag.info { color: var(--accent-1); background: var(--info-bg); border-color: transparent; }

/* the big figure on the right of a card */
.value-pill {
  flex: none;
  display: grid;
  justify-items: end;
  gap: 1px;
  min-width: 78px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--chip-bg);
  border: 1px solid var(--hairline);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.vp-value { font-size: 16.5px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; white-space: nowrap; }
.vp-delta { font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.rcard-chev { flex: none; width: 16px; height: 16px; margin-left: -4px; color: var(--ink-3); transition: transform 0.2s, color 0.2s; }
.rcard.clickable:hover .rcard-chev { color: var(--accent-1); transform: translateX(2px); }

/* ==========================================================================
   Data display: legends, donuts, stacked bar, key-value rows, events
   ========================================================================== */
.chart-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-wrap { flex: none; margin-inline: auto; }
.donut-track { stroke: var(--track); }
.donut-label { fill: var(--ink); font-weight: 800; font-family: inherit; letter-spacing: -0.02em; }
.donut-sub { fill: var(--ink-3); font-weight: 600; font-family: inherit; }
.legend { display: grid; gap: 9px; flex: 1; min-width: 180px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: 13.5px; min-width: 0; }
.legend-item .sw { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.legend-item .lg-name { flex: 1; min-width: 0; color: var(--ink-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item .lg-val { font-weight: 800; font-variant-numeric: tabular-nums; }
.legend-item .lg-pct { width: 40px; text-align: right; color: var(--ink-3); font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* categorical stacked bar (liquid split) */
.split-bar { display: flex; height: 18px; margin: 4px 0 14px; border-radius: 6px; background: var(--track); overflow: hidden; }
.split-seg { height: 100%; border-right: 2px solid transparent; background-clip: padding-box; }
.split-seg:last-child { border-right: 0; }
.split-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 12px; }
.split-col { min-width: 0; }
.sc-label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--ink-3); line-height: 1.25; }
.sc-label .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sc-val { margin-top: 4px; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sc-pct { font-size: 12px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.kv-list { display: grid; }
.kv { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 11px 0; border-top: 1px solid var(--hairline); font-size: 14px; }
.kv:first-child { border-top: 0; }
.kv .k { flex: none; max-width: 48%; color: var(--ink-3); font-weight: 600; }
.kv .v { min-width: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv-owner { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 700; color: var(--ink); }
.kv-owner .ava { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; }

.event-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--hairline); }
.event-row:first-child { border-top: 0; }
.ev-date { display: grid; place-items: center; width: 48px; flex: none; padding: 5px 0; border-radius: 12px; background: var(--info-bg); color: var(--accent-1); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ev-date small { font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }
.ev-main { flex: 1; min-width: 0; }
.ev-name { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-sub { font-size: 12.5px; color: var(--ink-3); }
.ev-amt { flex: none; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Portfolio longevity (dashboard)
   ========================================================================== */
.long-controls { display: grid; gap: 18px; }
.lr-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.lr-val { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; color: var(--accent-1); font-variant-numeric: tabular-nums; }
.lr-slider { display: flex; align-items: center; gap: 10px; }
.lr-slider .icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--chip-bg); border-color: var(--hairline); }
.lr-slider .icon-btn .i { width: 18px; height: 18px; }
/* tall transparent input = large touch target (reliable dragging on iOS) */
.lr-range { -webkit-appearance: none; appearance: none; flex: 1; min-width: 0; height: 40px; margin: 0; background: transparent; cursor: pointer; touch-action: pan-y; }
.lr-range::-webkit-slider-runnable-track { height: 8px; border-radius: 6px; background: var(--btn-grad); }
.lr-range::-moz-range-track { height: 8px; border-radius: 6px; background: var(--btn-grad); }
.lr-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%; background: #fff; border: 4px solid var(--accent-1); box-shadow: 0 4px 12px -2px rgba(49, 46, 129, 0.45); cursor: grab; }
.lr-range::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 4px solid var(--accent-1); box-shadow: 0 4px 12px -2px rgba(49, 46, 129, 0.45); }

.long-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.long-tile { position: relative; overflow: hidden; }
.long-tile::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--mark); }
.long-tile.liquid { --mark: var(--liquid-mark); }
.long-tile.re { --mark: var(--re-mark); }
.long-tile .stat-label { margin: 0 0 4px; display: flex; align-items: center; gap: 6px; }
.long-tile .stat-label .i { margin: 0; }

.ms-wrap { position: relative; margin: 34px 2px 4px; }
.ms-bar { position: relative; height: 18px; border-radius: 9px; background: var(--track); overflow: hidden; }
.ms-seg { position: absolute; left: 0; top: 0; height: 100%; }
.ms-seg.re { background: var(--re-mark); }
.ms-seg.liquid { background: var(--liquid-mark); }
.ms-marker { position: absolute; top: -4px; width: 3px; height: 26px; border-radius: 2px; background: var(--surface); box-shadow: 0 0 0 1px var(--axis); transform: translateX(-1px); }
.ms-flag { position: absolute; transform: translateX(-50%); white-space: nowrap; font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ms-flag .i { width: 14px; height: 14px; vertical-align: -2px; }
.ms-flag.above { bottom: 26px; color: var(--re-ink); }
.ms-flag.below { top: 26px; color: var(--liquid-ink); }
.ms-axis { position: relative; height: 16px; margin-top: 24px; font-size: 11px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ms-tick { position: absolute; top: 0; white-space: nowrap; }
.ms-scale-note { margin-top: 2px; text-align: right; font-size: 11px; font-style: italic; color: var(--ink-3); }
.ms-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.ms-legend span { display: inline-flex; align-items: center; gap: 7px; }
.ms-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 4px; }

/* ==========================================================================
   Notices, empty states, skeletons
   ========================================================================== */
.notice {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  padding: 13px 15px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--info-bg);
  border: 1px solid var(--hairline);
}
.notice > .i { width: 20px; height: 20px; margin-top: 1px; color: var(--accent-1); }
.notice > p { min-width: 0; overflow-wrap: anywhere; }
.notice b, .notice strong, .notice em { color: var(--ink); font-style: normal; font-weight: 700; }
.notice.warn { background: var(--notice-bg); border-color: var(--notice-border); }
.notice.warn > .i { color: var(--warn-ink); }

.empty-state {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  border-radius: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-2);
  border: 1px dashed var(--hairline);
}
.empty-state .card-icon { width: 46px; height: 46px; border-radius: 14px; margin-bottom: 6px; }
.empty-state .card-icon .i { width: 22px; height: 22px; }
.empty-title { font-size: 16px; font-weight: 800; color: var(--ink); }
.empty-hint { font-size: 13.5px; color: var(--ink-2); }
.empty-state .btn, .empty-state .btn-ghost { margin-top: 10px; }

.skeleton {
  display: block;
  min-height: 74px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: linear-gradient(100deg, var(--chip-bg) 20%, var(--glass-hi) 50%, var(--chip-bg) 80%) 0 0 / 250% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -250% 0; } }
.spinner { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 3px solid var(--focus); border-top-color: var(--accent-1); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Bottom sheet dialog (router.js) — sheet on phones, centred ≥ 640px
   ========================================================================== */
.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.sheet::backdrop { background: rgba(11, 10, 26, 0.5); animation: fade 0.25s ease both; }
.sheet-inner {
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
  border-radius: 28px 28px 0 0;
  border: 1px solid var(--glass-border);
  border-bottom: 0;
  background: var(--sheet-bg);
  box-shadow: 0 -24px 60px -24px rgba(15, 12, 40, 0.5), inset 0 1px 0 var(--glass-hi);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
  animation: sheet-up 0.38s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.sheet.closing .sheet-inner { animation: sheet-down 0.2s ease-in both; }
.sheet.closing::backdrop { animation: fade-out 0.2s ease-in both; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-down { from { transform: none; } to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
.sheet-grab { width: 40px; height: 5px; margin: 10px auto 0; flex: none; border-radius: 3px; background: var(--track); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 12px 20px 14px; }
.sheet-title { min-width: 0; }
.sheet-eyebrow { font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-1); }
.sheet-head h2:focus { outline: none; }
.sheet-head h2 { margin-top: 4px; font-size: 20px; font-weight: 800; line-height: 1.25; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px calc(22px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
}
.sheet.has-foot .sheet-body { padding-bottom: 18px; }
/* action bar pinned under the scrolling body (forms) */
.sheet-foot {
  display: flex;
  gap: 10px;
  flex: none;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
}
.sheet-foot > * { flex: 1 1 0; min-width: 0; }
.sheet-foot > .btn-primary, .sheet-foot > .btn-danger { flex-grow: 1.5; }
.sheet .toast-root { bottom: calc(92px + env(safe-area-inset-bottom)); }

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-root { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 80; display: grid; gap: 8px; width: min(calc(100% - 32px), 440px); transform: translateX(-50%); pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  background: var(--glass-solid);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  animation: toast-in 0.24s ease;
  transition: opacity 0.25s, transform 0.25s;
}
.toast .i { width: 19px; height: 19px; color: var(--accent-1); }
.toast.success .i { color: var(--ok-ink); }
.toast.error .i { color: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { transform: translateY(14px); opacity: 0; } }

/* ==========================================================================
   Login / welcome overlay
   ========================================================================== */
.login-root {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 20px);
  background: radial-gradient(120% 70% at 50% -10%, var(--bg-2), var(--bg) 65%);
}
.login-card { width: min(100%, 440px); margin: auto; border-radius: 28px; padding: 26px 22px; }
.login-brand { display: grid; justify-items: center; text-align: center; }
.login-mark { border-radius: 16px; box-shadow: 0 10px 28px -10px rgba(99, 102, 241, 0.7); }
.login-brand h1 { margin-top: 14px; font-size: 32px; }
.login-tag { margin-top: 6px; font-size: 15px; color: var(--ink-2); }
.login-points { display: grid; gap: 8px; margin: 20px 0; padding: 0; list-style: none; }
.login-points li { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 12px; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; }
.login-points b { color: var(--ink); }
.login-actions { display: grid; gap: 10px; }
.google-btn { width: 100%; background: #fff; color: #1f2937; border: 1px solid #dadce0; box-shadow: var(--shadow-sm); }
.login-or { text-align: center; font-size: 12.5px; font-weight: 700; color: var(--ink-3); }
.login-status { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.login-migrate { display: grid; gap: 6px; padding: 16px; border-radius: 18px; border: 1px solid var(--hairline); background: var(--chip-bg); }
.lm-title { font-size: 16px; font-weight: 800; }
.lm-text { font-size: 13.5px; color: var(--ink-2); }
.login-note { display: grid; gap: 8px; margin-top: 18px; }
.login-note .notice { font-size: 12.5px; }

/* ==========================================================================
   Settings
   ========================================================================== */
.acct { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.acct-pic { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--chip-bg); border: 1px solid var(--hairline); color: var(--accent-1); object-fit: cover; }
.acct-main { min-width: 0; }
.acct-name { font-size: 15px; font-weight: 800; }
.acct-email { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; background: var(--good); vertical-align: 0; }
.status-dot.warn { background: var(--rank4); }

/* radio-like option rows (storage mode) */
.option-list { display: grid; gap: 8px; }
.option-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 14px 10px 10px;
  border-radius: 16px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.option-row:hover { border-color: var(--accent-1); }
.option-row[aria-pressed="true"] { border-color: var(--accent-1); box-shadow: 0 0 0 3px var(--focus); background: var(--seg-active); }
.option-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--info-bg); color: var(--accent-1); }
.option-icon .i { width: 18px; height: 18px; }
.option-text b { display: block; font-size: 14.5px; font-weight: 800; line-height: 1.3; }
.option-text span { display: block; font-size: 12.5px; color: var(--ink-3); line-height: 1.4; }
.option-check { width: 20px; height: 20px; color: var(--accent-1); visibility: hidden; }
.option-row[aria-pressed="true"] .option-check { visibility: visible; }

.about { display: grid; justify-items: center; gap: 4px; text-align: center; }
.about img { border-radius: 14px; margin-bottom: 6px; }
.about b { font-size: 16px; font-weight: 800; }
.about span { font-size: 12.5px; color: var(--ink-3); }

/* ==========================================================================
   Larger screens
   ========================================================================== */
@media (min-width: 480px) {
  .class-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 560px) {
  .card { padding: 24px; }
  .stat-value { font-size: 26px; }
  .fgroup { padding: 18px; }
}
@media (min-width: 640px) {
  .sheet { width: min(620px, calc(100% - 48px)); margin: auto; }
  .sheet-inner { max-height: 86dvh; border-radius: 28px; border-bottom: 1px solid var(--glass-border); box-shadow: var(--shadow), inset 0 1px 0 var(--glass-hi); animation-name: pop; }
  .sheet.closing .sheet-inner { animation-name: pop-out; }
  .sheet-grab { display: none; }
  .sheet-head { padding: 22px 24px 14px; }
  .sheet-body { padding: 18px 24px 24px; }
  .sheet-foot { padding: 14px 24px 18px; }
  .sheet .toast-root { bottom: 24px; }
  .class-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (min-width: 720px) {
  .dash-stats { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)); gap: 12px; }
  .dash-stats .stat-tile.wide { grid-column: auto; }
}

/* Desktop: glass sidebar instead of top bar + tab bar */
@media (min-width: 1000px) {
  :root { --sticky-top: 0px; }
  .topbar, .tabbar { display: none; }
  .app-shell { display: flex; align-items: flex-start; min-height: 100vh; min-height: 100dvh; }
  .app-content { flex: 1; min-width: 0; }
  .layout { padding: 22px 32px 56px; }
  .intro { padding: 12px 0 26px; }
  .toast-root { bottom: 24px; }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    flex: none;
    width: var(--sidebar-w);
    height: 100vh;
    height: 100dvh;
    border-width: 0 1px 0 0;
    border-radius: 0 26px 26px 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-backdrop-filter: blur(22px) saturate(170%);
    backdrop-filter: blur(22px) saturate(170%);
    transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .sidebar-top { display: flex; align-items: center; gap: 8px; padding: 18px 14px 14px 18px; }
  .sidebar-brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; min-height: 44px; padding: 0; border: 0; background: none; color: var(--ink); text-align: left; cursor: pointer; }
  .sidebar-brand-text { font-size: 16px; font-weight: 800; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; }
  .sidebar-collapse-btn {
    width: 40px;
    height: 40px;
    flex: none;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--hairline);
    background: var(--chip-bg);
    color: var(--ink-3);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
  }
  .sidebar-collapse-btn:hover { color: var(--ink); border-color: var(--accent-1); }
  .sidebar-collapse-btn .i { width: 18px; height: 18px; transition: transform 0.25s; }
  .sidebar-add { padding: 4px 12px 10px; }
  .sidebar-add .btn { width: 100%; }
  .sidebar-add .nav-label { flex: none; }

  .sidebar-nav { flex: 1; display: grid; align-content: start; gap: 2px; padding: 6px 12px; }
  .nav-link-flat {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 14px;
    background: none;
    color: var(--ink-2);
    font-size: 14.5px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
  }
  .nav-link-flat:hover { background: var(--chip-bg); color: var(--ink); }
  .nav-icon { display: grid; place-items: center; width: 22px; flex: none; }
  .nav-icon .i { width: 20px; height: 20px; }
  .nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav-link-flat[aria-current="page"] { background: var(--seg-active); color: var(--ink); box-shadow: 0 2px 10px -4px rgba(15, 12, 40, 0.3); }
  .nav-link-flat[aria-current="page"] .nav-icon { color: var(--accent-1); }

  .sidebar-bottom { display: grid; gap: 10px; padding: 12px 12px 18px; border-top: 1px solid var(--hairline); }
  .side-sync { width: 100%; max-width: none; min-height: 44px; border-radius: 14px; padding: 0 12px 0 19px; gap: 15px; text-align: left; }
  .side-theme {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 14px;
    border: 1px solid var(--hairline);
    background: var(--chip-bg);
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
  }
  .side-theme:hover { color: var(--ink); border-color: var(--accent-1); }
  .side-theme .i { width: 20px; height: 20px; }

  /* collapsed icon rail (remembered in wealthInsight.sidebar.v1) */
  .sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
  .sidebar-collapsed .sidebar-top { flex-direction: column; padding: 18px 10px 10px; }
  .sidebar-collapsed .sidebar-brand { flex: none; }
  .sidebar-collapsed .sidebar-collapse-btn .i { transform: rotate(180deg); }
  .sidebar-collapsed .sidebar-brand-text,
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .side-sync .sync-count { display: none; }
  .sidebar-collapsed .sidebar-add { padding: 4px 10px 10px; }
  .sidebar-collapsed .sidebar-add .btn { padding: 0; }
  .sidebar-collapsed .sidebar-nav { padding: 6px 10px; }
  .sidebar-collapsed .nav-link-flat,
  .sidebar-collapsed .side-theme,
  .sidebar-collapsed .side-sync { justify-content: center; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .blob, .pulse, .sync-dot, .skeleton { animation: none; }
}
@media (forced-colors: active) {
  .glass, .rcard, .stat-tile, .chip, .fgroup, .class-opt, .option-row { border: 1px solid CanvasText; }
}
