/* Wealth Lens — glassy futuristic */

:root {
  --accent: oklch(0.88 0.22 150);
  --accent-soft: oklch(0.88 0.22 150 / 0.15);
  --accent-glow: oklch(0.88 0.22 150 / 0.35);
  --pos: oklch(0.82 0.18 150);
  --neg: oklch(0.72 0.2 25);

  /* Segment colors (shared across themes) */
  --fwra:   #4ade80;
  --avws:   #38bdf8;
  --spyy:   #fbbf24;
  --s:      #fbbf24;
  --alpha:  #e879f9;
  --ib1t:   #f47274;
  --t212:   #38bdf8;
  --ibkr:   #f47274;
  --rev:    #c2c6cc;
  --etrade: #a78bfa;
  --cash:   #94a3b8;

  /* Dark theme (default) */
  --bg-0: oklch(0.13 0.015 260);
  --bg-card: oklch(0.18 0.02 260 / 0.55);
  --stroke: oklch(1 0 0 / 0.08);
  --stroke-strong: oklch(1 0 0 / 0.14);
  --text-0: oklch(0.98 0 0);
  --text-1: oklch(0.78 0.01 260);
  --text-2: oklch(0.55 0.01 260);
  --text-3: oklch(0.38 0.01 260);

  --blob-1: oklch(0.6 0.2 150 / 0.14);
  --blob-2: oklch(0.55 0.2 290 / 0.11);
  --blob-3: oklch(0.6 0.22 25 / 0.08);

  --row-hover: oklch(1 0 0 / 0.04);
  --row-hover-strong: oklch(1 0 0 / 0.06);

  --radius: 14px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --radius-pill-btn: 24px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
  --display: 'Space Grotesk', 'Inter', sans-serif;

  /* Control tokens */
  --control-height: 26px;
  --control-bg: oklch(0 0 0 / 0.2);
  --control-active: oklch(1 0 0 / 0.08);

  /* Brand */
  --brand-size: 30px;

  /* Semantic color tints */
  --pos-soft: oklch(0.82 0.18 150 / 0.12);
  --pos-border: oklch(0.82 0.18 150 / 0.3);
  --neg-soft: oklch(0.72 0.2 25 / 0.12);
  --neg-border: oklch(0.72 0.2 25 / 0.3);

  /* Motion */
  --duration-fast: 0.15s;
  --duration: 0.2s;

  /* Blur */
  --blur-sm: 12px;
  --blur-md: 16px;
  --blur-lg: 24px;

  /* Typography */
  --tracking-ui: 0.05em;
  --tracking-label: 0.08em;
  --tracking-caps: 0.12em;

  /* Overlays */
  --bg-overlay: oklch(0.12 0.02 260 / 0.94);
  --shadow-dark: oklch(0 0 0 / 0.4);

  /* Layout */
  --card-pad: 28px;
  --grid-gap: 22px;

  /* Components */
  --spinner-size: 26px;

  /* Aurora */
  --blur-aurora: 90px;
}

[data-theme="light"] {
  --bg-0: oklch(0.97 0.005 260);
  --bg-card: oklch(1 0 0 / 0.7);
  --stroke: oklch(0 0 0 / 0.08);
  --stroke-strong: oklch(0 0 0 / 0.14);
  --text-0: oklch(0.18 0.01 260);
  --text-1: oklch(0.38 0.01 260);
  --text-2: oklch(0.55 0.01 260);
  --text-3: oklch(0.70 0.01 260);
  --blob-1: oklch(0.7 0.2 150 / 0.12);
  --blob-2: oklch(0.65 0.2 290 / 0.09);
  --blob-3: oklch(0.7 0.22 25 / 0.06);
  --accent: oklch(0.72 0.22 150);
  --accent-soft: oklch(0.72 0.22 150 / 0.14);
  --accent-glow: oklch(0.72 0.22 150 / 0.28);
  --bg-overlay: oklch(1 0 0 / 0.96);
  --pos: oklch(0.62 0.18 150);
  --neg: oklch(0.58 0.2 25);
  --row-hover: oklch(0 0 0 / 0.03);
  --row-hover-strong: oklch(0 0 0 / 0.05);

  --control-bg: oklch(0 0 0 / 0.04);
  --control-active: oklch(0 0 0 / 0.06);
  --pos-soft: oklch(0.78 0.18 150 / 0.14);
  --pos-border: oklch(0.65 0.18 150 / 0.32);
  --neg-soft: oklch(0.78 0.2 25 / 0.12);
  --neg-border: oklch(0.65 0.2 25 / 0.32);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--text-0);
  background: var(--bg-0);
  min-height: 100vh;
  font-feature-settings: 'ss01','cv11';
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* ── Aurora background ─────────────────────────────────────────────────── */
.aurora {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  overflow: hidden;
}
.aurora::before,
.aurora::after,
.aurora > span {
  content: ''; position: absolute;
  filter: blur(var(--blur-aurora));
  border-radius: 50%;
}
.aurora::before {
  width: 52vw; height: 52vw;
  background: var(--blob-1);
  top: -18vw; left: -10vw;
  animation: float1 22s ease-in-out infinite;
}
.aurora::after {
  width: 48vw; height: 48vw;
  background: var(--blob-2);
  bottom: -22vw; right: -14vw;
  animation: float2 28s ease-in-out infinite;
}
.aurora > span {
  width: 36vw; height: 36vw;
  background: var(--blob-3);
  top: 40%; left: 45%;
  animation: float3 35s ease-in-out infinite;
}
@keyframes float1 { 50% { transform: translate(6vw, 4vw) scale(1.1); } }
@keyframes float2 { 50% { transform: translate(-8vw, -3vw) scale(0.95); } }
@keyframes float3 { 50% { transform: translate(-4vw, 6vw) scale(1.05); } }

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
  position: relative; z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--card-pad) 24px;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.header {
  display: grid;
  grid-template-columns: auto auto auto 1fr auto;
  grid-template-areas: "brand hero scope . actions";
  container-type: inline-size;
  align-items: center;
  gap: 16px; margin-bottom: var(--card-pad);
  padding: 0 4px;
}
.header > .brand-mark    { grid-area: brand; }
.header > .hero          { grid-area: hero; }
.header > .scope-wrap    { grid-area: scope; }
.header > .header-actions { grid-area: actions; }

.brand-mark {
  display: inline-flex; align-items: center; gap: 10px;
  white-space: nowrap;
}
.brand-logo {
  width: var(--brand-size); height: var(--brand-size);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), oklch(0.65 0.18 180));
  box-shadow: 0 0 14px var(--accent-glow), inset 0 0 0 1px oklch(1 0 0 / 0.25);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--bg-0);
  font-family: var(--display);
  font-size: 16px; font-weight: 700;
  letter-spacing: -0.04em;
}
.brand-name {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-0);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand-name em {
  font-style: normal;
  color: var(--accent);
  margin: 0 2px;
  font-weight: 700;
}
.brand-divider {
  width: 1px; height: 22px;
  background: var(--stroke-strong);
}
.hero {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: nowrap;
  min-width: 0;
}

/* Scope (history) picker trigger */
.scope-dropdown {
  display: inline-flex; align-items: center; gap: 6px;
  height: var(--control-height); padding: 0 11px;
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 10px;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--duration);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  font-weight: 500;
}
.scope-dropdown:hover { border-color: var(--stroke-strong); color: var(--text-1); }
.scope-dropdown.active { border-color: var(--stroke-strong); color: var(--text-1); }
.scope-wrap { position: relative; }

/* Total number */
.total {
  font-family: var(--display);
  font-size: 24px;
  letter-spacing: -0.025em;
  color: var(--text-0);
  font-weight: 600;
  display: inline-flex; align-items: baseline; gap: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.total .num-anim { white-space: nowrap; }
.total-ccy { font-family: var(--display); font-size: 14px; color: var(--text-2); font-weight: 500; letter-spacing: -0.01em; }

/* Delta tag */
.delta {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  font-family: var(--mono); font-size: 11px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.delta.pos { color: var(--pos); background: var(--pos-soft); border: 1px solid var(--pos-border); }
.delta.neg { color: var(--neg); background: var(--neg-soft); border: 1px solid var(--neg-border); }
.delta svg { width: 12px; height: 12px; }
.delta .delta-abs { opacity: 0.7; }

/* Header right side */
.header-actions { display: flex; align-items: center; gap: 12px; }

/* ── Pull-to-refresh bar ─────────────────────────────────────────────────── */
#ptr-bar {
  height: var(--ptr-h, 0px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#ptr-bar svg {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  transform: rotate(-90deg);
}
.ptr-track { stroke: var(--stroke-strong); }
.ptr-arc   { stroke: var(--accent); }
#ptr-bar.is-spinning svg {
  animation: ptr-spin 0.75s linear infinite;
}
@keyframes ptr-spin {
  from { transform: rotate(-90deg); }
  to   { transform: rotate(270deg); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Theme toggle */
.theme-toggle {
  display: inline-flex; align-items: center;
  width: 52px; height: var(--control-height);
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-pill);
  padding: 2px;
  cursor: pointer;
  position: relative;
  backdrop-filter: blur(var(--blur-sm));
  -webkit-backdrop-filter: blur(var(--blur-sm));
}
.theme-toggle-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: oklch(1 0 0 / 0.18);
  box-shadow: none;
  transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  transform: translateX(0);
  position: relative;
  z-index: 2;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-1);
}
[data-theme="light"] .theme-toggle-dot { background: oklch(0 0 0 / 0.1); color: var(--text-1); }
.theme-toggle-dot svg { width: 12px; height: 12px; display: block; }
.theme-toggle-dot .dot-sun,
.theme-toggle-dot .dot-moon { position: absolute; transition: opacity var(--duration); }
.theme-toggle-dot .dot-moon { opacity: 1; }
.theme-toggle-dot .dot-sun { opacity: 0; }
[data-theme="light"] .theme-toggle-dot { transform: translateX(26px); }
[data-theme="light"] .theme-toggle-dot .dot-moon { opacity: 0; }
[data-theme="light"] .theme-toggle-dot .dot-sun { opacity: 1; }
.theme-toggle svg.bg-icon {
  position: absolute; width: 11px; height: 11px;
  color: var(--text-2); top: 50%;
  transform: translateY(-50%); opacity: 0.5;
}
.theme-toggle svg.bg-sun { right: 7px; }
.theme-toggle svg.bg-moon { left: 7px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(var(--blur-lg));
  -webkit-backdrop-filter: blur(var(--blur-lg));
  padding: var(--card-pad);
  overflow: hidden;
}
.card::before {
  content: ''; position: absolute; inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, oklch(1 0 0 / 0.14), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
}
[data-theme="light"] .card::before {
  background: linear-gradient(135deg, oklch(0 0 0 / 0.06), transparent 40%);
}
.card-label {
  font-family: var(--mono); font-size: 10px;
  color: var(--text-2);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}

/* ── Grid ──────────────────────────────────────────────────────────────── */
.grid-top { display: grid; grid-template-columns: 1fr 1fr; gap: var(--grid-gap); margin-bottom: var(--grid-gap); }
.grid-bottom { display: grid; grid-template-columns: 1fr; gap: var(--grid-gap); }

/* ── Donut cards ───────────────────────────────────────────────────────── */
.card:has(> .alloc) {
  display: flex;
  flex-direction: column;
}
.alloc {
  display: grid; grid-template-columns: 154px 1fr; gap: 24px;
  align-items: center;
  flex: 1;
  align-content: center;
}
.donut-wrap {
  position: relative; width: 154px; height: 154px;
}
.donut-wrap svg { display: block; width: 154px; height: 154px; overflow: visible; }
.donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  pointer-events: none;
}
.donut-value {
  font-family: var(--display); font-size: 20px;
  color: var(--text-0);
  letter-spacing: -0.03em;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.donut-value .donut-suffix {
  font-family: var(--mono);
  font-size: 0.55em;
  opacity: 0.7;
  margin-left: 0.15em;
  font-weight: 500;
}
.donut-unit {
  font-family: var(--mono); font-size: 9px;
  color: var(--text-2);
  margin-top: 5px; letter-spacing: 0.14em;
  font-weight: 500;
  text-transform: uppercase;
}

.alloc-list { display: flex; flex-direction: column; gap: 2px; }
.alloc-row {
  display: grid;
  grid-template-columns: 8px 2fr 1fr 1.2fr 1fr;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  min-height: 28px;
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 11px;
  color: var(--text-1);
  transition: background var(--duration-fast), opacity var(--duration-fast);
  cursor: default;
}
.alloc-row:hover { background: var(--row-hover); color: var(--text-0); }
.alloc-row.row-dim { opacity: 0.25; }
.alloc-row .dot { width: 7px; height: 7px; border-radius: 2px; }
.alloc-row .name { color: var(--text-0); font-family: var(--sans); font-size: 12px; font-weight: 500; }
.alloc-row .pct { color: var(--accent); font-variant-numeric: tabular-nums; text-align: right; }
.alloc-row .pcs { color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }
.alloc-row .val { color: var(--text-0); font-variant-numeric: tabular-nums; text-align: right; }

.alloc-head {
  display: grid;
  grid-template-columns: 8px 2fr 1fr 1.2fr 1fr;
  gap: 10px;
  padding: 0 8px 6px;
  font-family: var(--mono); font-size: 9px;
  color: var(--text-3);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  border-bottom: 1px solid var(--stroke);
  margin-bottom: 4px;
}
.alloc-head > div:first-child { grid-column: 1 / 3; }
.alloc-head > div:nth-child(2) { text-align: right; }
.alloc-head > div:nth-child(3) { text-align: right; }
.alloc-head > div:nth-child(4) { text-align: right; }

/* Broker widget: no qty column */
#head-brokers { grid-template-columns: 8px 2fr 1fr 1fr; }
#list-brokers .alloc-row { grid-template-columns: 8px 2fr 1fr 1fr; }
#list-brokers .alloc-row .pcs { display: none; }

/* Donut segment */
.donut-seg { transition: opacity var(--duration-fast); }

/* ── Assets table ──────────────────────────────────────────────────────── */
.table-card { padding: var(--card-pad); }
.table {
  display: grid;
  grid-template-columns: 2fr 1fr 1.1fr 1fr 1.2fr;
  row-gap: 0;
  margin: 0 calc(-1 * var(--card-pad)) calc(-1 * var(--card-pad));
}
.thead, .trow, #tbl-prices { display: contents; }
.thead > div {
  font-family: var(--mono); font-size: 9px;
  color: var(--text-3);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  padding: 8px 14px;
  border-bottom: 1px solid var(--stroke);
  border-top: 1px solid var(--stroke);
}
.thead > div:first-child { padding-left: var(--card-pad); }
.thead > div:last-child { padding-right: var(--card-pad); text-align: right; }
.thead > div.num { text-align: right; }

.trow > div {
  padding: 10px 14px;
  min-height: 44px;
  border-bottom: 1px solid var(--stroke);
  font-family: var(--mono); font-size: 12px;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  display: flex; align-items: center;
  transition: background var(--duration-fast), opacity var(--duration-fast);
}
.trow > div:first-child { padding-left: var(--card-pad); }
.trow > div:last-child { padding-right: var(--card-pad); justify-content: flex-end; color: var(--text-0); white-space: nowrap; }
.trow > div.num.muted { color: var(--text-2); }
.trow > div.num { justify-content: flex-end; }
.trow:hover > div { background: var(--row-hover-strong); }
.trow.row-dim > div { opacity: 0.25; }
.trow:last-of-type > div { border-bottom: none; }
.trow:last-of-type > div:first-child { border-bottom-left-radius: calc(var(--radius) - 1px); }
.trow:last-of-type > div:last-child  { border-bottom-right-radius: calc(var(--radius) - 1px); }

.tick-cell { gap: 8px; min-width: 0; }
.tick-cell .dot { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }
.tick-cell .tick { color: var(--text-0); font-family: var(--sans); font-weight: 500; font-size: 12px; }
.tick-cell .asset-name { color: var(--text-3); font-size: 10px; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tick-cell a { color: inherit; text-decoration: none; }
.tick-cell a:hover .tick { color: var(--accent); }

.trow > .spark-cell { justify-content: flex-end; padding-right: 14px; }
.spark-cell svg { display: block; }
.val-tis { display: none; }

/* ── Portfolio chart ───────────────────────────────────────────────────── */
.chart-card { padding: var(--card-pad); }
.chart-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--control-bg);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-pill);
}
.chart-controls button {
  font-family: var(--mono); font-size: 10px;
  color: var(--text-2);
  background: transparent;
  border: none;
  padding: 4px 10px;
  border-radius: var(--radius-pill-btn);
  cursor: pointer;
  letter-spacing: var(--tracking-ui);
  transition: all var(--duration-fast);
  font-weight: 500;
}
.chart-controls button:hover { color: var(--text-1); }
.chart-controls button.active { color: var(--text-1); background: var(--control-active); }

.chart-wrap {
  position: relative;
  height: 160px;
  margin: 0;
}
.chart-wrap svg { display: block; width: 100%; height: 100%; overflow: visible; }

.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--bg-overlay);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--mono); font-size: 11px;
  color: var(--text-0);
  pointer-events: none;
  backdrop-filter: blur(var(--blur-md));
  -webkit-backdrop-filter: blur(var(--blur-md));
  white-space: nowrap;
  opacity: 0; transition: opacity var(--duration-fast);
  box-shadow: 0 8px 24px var(--shadow-dark);
  z-index: 10;
}
[data-theme="light"] .chart-tooltip { background: oklch(1 0 0 / 0.95); color: var(--text-0); }
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tip-date { color: var(--text-2); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.chart-tooltip .tip-val { font-size: 14px; color: var(--accent); font-variant-numeric: tabular-nums; }

.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.chart-header .card-label { margin-bottom: 0; }

/* ── Footer ────────────────────────────────────────────────────────────── */
.footer {
  margin-top: 2px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 18px 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}
.footer-copy { color: var(--text-2); }
.footer-info {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text-3);
  flex-wrap: wrap;
  justify-self: center;
}
.footer-info > span { white-space: nowrap; }
.footer-info .sep { color: var(--text-3); opacity: 0.5; }
.footer-info .rate { color: var(--text-3); }

.footer-end {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.footer-end .theme-toggle { display: none; }

.locale-toggle {
  display: inline-flex; align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--control-bg);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-pill);
}
.locale-toggle button {
  font-family: var(--mono); font-size: 10px;
  color: var(--text-2);
  background: transparent;
  border: none;
  padding: 4px 10px;
  border-radius: var(--radius-pill-btn);
  cursor: pointer;
  letter-spacing: var(--tracking-ui);
  transition: all var(--duration-fast);
  font-weight: 500;
}
.locale-toggle button:hover { color: var(--text-1); }
.locale-toggle button.active { color: var(--text-1); background: var(--control-active); }

/* ── Calendar picker popover ───────────────────────────────────────────── */
.cal-popover {
  position: fixed;
  min-width: 260px;
  background: var(--bg-overlay);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius);
  padding: 14px;
  backdrop-filter: blur(var(--blur-lg));
  -webkit-backdrop-filter: blur(var(--blur-lg));
  z-index: 50;
  box-shadow: 0 12px 32px var(--shadow-dark);
  font-family: var(--mono);
  color: var(--text-1);
}
[data-theme="light"] .cal-popover { background: oklch(1 0 0 / 0.98); box-shadow: 0 12px 32px oklch(0 0 0 / 0.12); }
.cal-now {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--mono); font-size: 11px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: center;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  margin-bottom: 12px;
  transition: all var(--duration-fast);
}
.cal-now:hover { color: var(--accent); border-color: var(--accent); }
.cal-now.active { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.cal-head button {
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  width: 24px; height: 24px;
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--duration-fast);
}
.cal-head button:hover:not(:disabled) { color: var(--text-1); border-color: var(--stroke-strong); }
.cal-head button:disabled { opacity: 0.3; cursor: default; }
.cal-head .cal-title { font-size: 11px; color: var(--text-0); letter-spacing: var(--tracking-label); text-transform: uppercase; font-weight: 500; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-size: 11px;
}
.cal-dow {
  text-align: center;
  color: var(--text-3);
  font-size: 9px;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-family: var(--mono); font-size: 11px;
  cursor: default;
  transition: all var(--duration-fast);
  padding: 0;
  font-variant-numeric: tabular-nums;
}
.cal-day.has-entry {
  color: var(--text-0);
  cursor: pointer;
  border-color: var(--stroke);
}
.cal-day.has-entry:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.cal-day.active {
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
  box-shadow: none;
}
.cal-day.other-month { opacity: 0.25; }

/* ── Card overlays (loading / error) ───────────────────────────────────── */
.card-overlay {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  min-height: 120px;
}
.card-overlay.is-loading,
.card-overlay.is-error { display: flex; }
.card-overlay.is-loading::after {
  content: '';
  width: var(--spinner-size);
  height: var(--spinner-size);
  border: 2px solid var(--stroke);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.overlay-error-icon {
  width: var(--spinner-size); height: var(--spinner-size);
  border-radius: 50%;
  border: 1.5px solid var(--neg);
  color: var(--neg);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-family: var(--display);
  font-weight: 700;
  flex-shrink: 0;
}
.overlay-error-msg {
  color: var(--text-1);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
}

/* ── Error toaster ─────────────────────────────────────────────────────── */
#update-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: oklch(0.45 0.2 25 / 0.95);
  color: oklch(1 0 0);
  border: 1px solid oklch(0.6 0.22 25 / 0.5);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono); font-size: 12px;
  z-index: 1000;
  box-shadow: 0 12px 32px var(--shadow-dark);
  backdrop-filter: blur(var(--blur-md));
  -webkit-backdrop-filter: blur(var(--blur-md));
  width: max-content;
  max-width: calc(100vw - 48px);
}
.toast-msg { flex: 1; white-space: normal; }
.toast-retry {
  background: oklch(1 0 0 / 0.18);
  border: 1px solid oklch(1 0 0 / 0.4);
  border-radius: 4px;
  color: oklch(1 0 0);
  font-family: var(--mono); font-size: 11px;
  padding: 4px 9px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--duration-fast);
}
.toast-retry:hover { background: oklch(1 0 0 / 0.32); }
.toast-close {
  background: none; border: none;
  color: oklch(1 0 0);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.75;
  flex-shrink: 0;
  transition: opacity var(--duration-fast);
}
.toast-close:hover { opacity: 1; }

/* ── Sparkline ─────────────────────────────────────────────────────────── */
.sparkline { display: block; }

/* Hide scope control while loading */
.is-loading-root .scope-dropdown,
.is-loading-root .total,
.is-loading-root .delta { visibility: hidden; }
.is-loading-root .brand-divider { display: none; }

/* ── Projector widget ──────────────────────────────────────────────────── */

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }

#proj-card { margin-top: var(--grid-gap); }

.proj-settings-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  transition: color var(--duration), border-color var(--duration);
}
.proj-settings-btn:hover { color: var(--text-1); border-color: var(--stroke-strong); }
.proj-settings-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

/* Value line */
#proj-card .card-label { margin-bottom: 20px; }
.proj-result-wrap { margin-bottom: 6px; }
.proj-result-row {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
}
.proj-fv {
  font-size: 38px; font-weight: 700; letter-spacing: -0.03em;
  color: var(--text-0); line-height: 1;
}
.proj-result-ccy {
  font-size: 18px; font-weight: 500;
  color: var(--text-2); letter-spacing: -0.01em;
}
.proj-slash {
  font-size: 28px; font-weight: 300;
  color: var(--text-3); line-height: 1;
  margin: 0 2px;
}
.proj-swr-val {
  font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
  color: var(--text-0);
}
.proj-swr-ccy {
  font-family: var(--mono); font-size: 11px; font-weight: 400;
  color: var(--text-2); letter-spacing: 0.04em;
}
/* Params summary line */
.proj-params {
  font-family: var(--mono); font-size: 11px;
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 16px;
}

/* Stacked bar */
.proj-bar-stack {
  display: flex; height: 6px; border-radius: var(--radius-pill);
  gap: 2px;
  margin-bottom: 12px;
}
.proj-seg {
  border-radius: var(--radius-pill);
  min-width: 4px;
  transition: flex 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Legend */
.proj-legend { display: flex; flex-direction: column; gap: 6px; }
.proj-legend-inline { flex-direction: row; column-gap: 16px; row-gap: 6px; flex-wrap: wrap; }
.proj-legend-item {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px;
  color: var(--text-1);
  white-space: nowrap;
}
.proj-ldot { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }
.proj-lname { color: var(--text-2); }
.proj-lval { color: var(--text-0); font-variant-numeric: tabular-nums; }

/* Goal block */
.proj-goal-block {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--stroke);
}
.proj-goal-row {
  display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.proj-goal-pct {
  font-family: var(--display);
  font-size: 38px; font-weight: 700; letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}
.proj-goal-status {
  font-family: var(--mono); font-size: 10px;
  font-weight: 600; letter-spacing: var(--tracking-caps); text-transform: uppercase;
  padding: 3px 9px; border-radius: var(--radius-pill);
  align-self: center;
}
.proj-goal-status.on-track {
  color: var(--accent);
  background: var(--accent-soft);
}
.proj-goal-status.behind {
  color: #fb923c;
  background: rgb(251 146 60 / 0.12);
}
.proj-goal-secondary {
  font-family: var(--mono); font-size: 11px;
  color: var(--text-2);
  margin-bottom: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.proj-goal-bar {
  display: flex; height: 6px; border-radius: var(--radius-pill);
  gap: 2px;
}
.proj-goal-fill {
  border-radius: var(--radius-pill);
  min-width: 4px;
  transition: flex 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.proj-goal-empty {
  border-radius: var(--radius-pill);
  background: oklch(1 0 0 / 0.1);
  min-width: 4px;
}
[data-theme="light"] .proj-goal-empty { background: oklch(0 0 0 / 0.08); }

/* ── Settings modal ──────────────────────────────────────────────────────── */
.proj-modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: oklch(0 0 0 / 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn var(--duration-fast) ease;
}
.proj-modal {
  background: var(--bg-overlay);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius);
  width: 100%; max-width: 400px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 64px var(--shadow-dark);
  animation: modalIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.proj-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--stroke);
  position: sticky; top: 0;
  background: var(--bg-overlay);
  z-index: 1;
}
.proj-modal-title {
  font-family: var(--display); font-size: 15px;
  font-weight: 600; letter-spacing: -0.015em;
  color: var(--text-0);
}
.proj-modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: oklch(1 0 0 / 0.06);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast);
  flex-shrink: 0;
}
.proj-modal-close:hover { color: var(--text-1); border-color: var(--stroke-strong); }
.proj-modal-close svg { width: 12px; height: 12px; display: block; }
[data-theme="light"] .proj-modal-close { background: oklch(0 0 0 / 0.05); }
.proj-modal-body {
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px;
}

/* Fields */
.proj-field { display: flex; flex-direction: column; gap: 8px; }
.proj-field-label {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--text-2);
}
.proj-rate-header {
  display: flex; justify-content: space-between; align-items: center;
}

/* Calendar trigger button */
.proj-cal-trigger-row { display: flex; align-items: center; gap: 12px; }
.proj-cal-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 13px;
  color: var(--text-0);
  background: oklch(1 0 0 / 0.04);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color var(--duration), box-shadow var(--duration);
  font-variant-numeric: tabular-nums;
}
[data-theme="light"] .proj-cal-trigger { background: oklch(0 0 0 / 0.03); }
.proj-cal-trigger:hover { border-color: var(--accent); }
.proj-cal-trigger.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent); }
.proj-cal-trigger svg { color: var(--text-2); flex-shrink: 0; }
.proj-duration {
  font-family: var(--mono); font-size: 11px;
  color: var(--accent); letter-spacing: 0.04em; opacity: 0.85;
  white-space: nowrap;
}

/* Inline calendar panel — reuses .cal-head/.cal-grid/.cal-day from app CSS */
.proj-cal-inline {
  background: oklch(1 0 0 / 0.03);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 12px;
  animation: slideDown 0.18s ease;
}
[data-theme="light"] .proj-cal-inline { background: oklch(0 0 0 / 0.02); }

/* Rate slider */
.proj-rate-badge {
  font-family: var(--mono); font-size: 13px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.proj-slider-wrap { display: flex; align-items: center; gap: 10px; }
.proj-slider-tick {
  font-family: var(--mono); font-size: 10px;
  color: var(--text-3); white-space: nowrap;
}
.proj-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 4px;
  border-radius: var(--radius-pill);
  background: linear-gradient(to right, var(--accent) var(--pct, 0%), oklch(1 0 0 / 0.12) var(--pct, 0%));
  outline: none; cursor: pointer; border: none;
}
[data-theme="light"] .proj-slider {
  background: linear-gradient(to right, var(--accent) var(--pct, 0%), oklch(0 0 0 / 0.08) var(--pct, 0%));
}
.proj-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 14px var(--accent-glow);
  border: none;
  transition: box-shadow var(--duration-fast);
}
.proj-slider::-webkit-slider-thumb:hover { box-shadow: 0 0 0 5px var(--accent-soft), 0 0 18px var(--accent-glow); }
.proj-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
  cursor: pointer;
}

/* Contributions toggle */
.proj-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.proj-toggle {
  position: relative;
  width: 40px; height: 22px;
  border-radius: var(--radius-pill);
  background: oklch(1 0 0 / 0.08);
  border: 1px solid var(--stroke-strong);
  cursor: pointer;
  transition: background var(--duration), border-color var(--duration), box-shadow var(--duration);
  flex-shrink: 0; padding: 0;
}
[data-theme="light"] .proj-toggle { background: oklch(0 0 0 / 0.06); }
.proj-toggle.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.proj-toggle-knob {
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-2);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), background 0.22s;
  display: block;
}
.proj-toggle.on .proj-toggle-knob { transform: translateX(18px); background: var(--accent); }

/* Contribution amount input */
.proj-contrib-row {
  display: flex; align-items: center; gap: 10px;
  animation: slideDown 0.2s ease;
}
.proj-number {
  font-family: var(--mono); font-size: 14px;
  color: var(--text-0);
  background: oklch(1 0 0 / 0.04);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px; outline: none;
  width: 130px;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--duration), box-shadow var(--duration);
  -moz-appearance: textfield;
}
[data-theme="light"] .proj-number { background: oklch(0 0 0 / 0.03); }
.proj-number::-webkit-inner-spin-button,
.proj-number::-webkit-outer-spin-button { -webkit-appearance: none; }
.proj-number:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.proj-ccy {
  font-family: var(--mono); font-size: 11px;
  color: var(--text-2); letter-spacing: 0.06em;
}

/* Responsive tweaks for projector */
@media (max-width: 480px) {
  .proj-fv { font-size: 26px; }
  .proj-slash { font-size: 20px; }
  .proj-swr-val { font-size: 17px; }
  .proj-result-ccy { font-size: 14px; }
  .proj-params { white-space: normal; }
  .proj-goal-pct { font-size: 26px; }
  .proj-goal-secondary { white-space: normal; }
}

/* ── Responsive ────────────────────────────────────────────────────────── */

/*
 * Three breakpoints: lg ≤1024px | md ≤768px | sm ≤480px
 *
 * lg: header moves to 2-row (brand/actions top, hero bottom); alloc stacks
 *     inside the still-2-col card grid (cards too narrow for donut+legend).
 * md: card grid collapses to 1-col → alloc can go side-by-side again;
 *     footer wraps; table loses qty column.
 * sm: phone-size tweaks — smaller donuts, etc.
 */

@media (max-width: 1024px) {
  /* Alloc: cards too narrow for side-by-side donut+legend → stack */
  .alloc { grid-template-columns: 1fr; gap: 20px; }
  .donut-wrap { margin: 0 auto; }

  /* Header: 4 cols — actions absorbs remaining space and aligns right (one gap only) */
  .header {
    grid-template-columns: auto auto auto 1fr;
    grid-template-areas: "brand hero scope actions";
  }
  .header-actions { justify-self: end; }
  .brand-name { display: none; }
  .brand-divider { display: none; }
  .hero { justify-content: flex-start; }
}

@media (max-width: 768px) {
  /* Card grid: 1-col → full-width cards → alloc can go side-by-side again */
  .grid-top { grid-template-columns: 1fr; }
  .alloc { grid-template-columns: 154px 1fr; gap: 24px; }
  .donut-wrap { margin: 0; }

  /* Footer: rates row wraps below copy + locale */
  .footer {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "copy .    locale"
      "info info info";
    row-gap: 10px;
  }
  .footer-copy { grid-area: copy; }
  .footer-info { grid-area: info; justify-self: start; gap: 10px; }
  .footer-end { grid-area: locale; }

  /* Table: hide qty column; keep asset / price / 30D / value */
  .table { grid-template-columns: 2fr 1fr 1fr 1.2fr; font-size: 11px; }
  .trow > div:nth-child(3),
  .thead > div:nth-child(3) { display: none; }
  .chart-wrap { height: 150px; }
  .tick-cell .asset-name { display: none; }

  /* Alloc: hide ks (qty) column */
  #head-assets { grid-template-columns: 8px 2fr 1fr 1fr; }
  #head-assets > div:nth-child(3) { display: none; }
  #list-assets .alloc-row { grid-template-columns: 8px 2fr 1fr 1fr; }
  #list-assets .alloc-row .pcs { display: none; }

  /* Header: hero fills middle, scope right */
  .header {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand hero scope";
  }
  /* header-actions only has the theme toggle, which is shown in the footer on mobile */
  .header-actions { display: none; }

  /* Scope overflow: JS adds .scope-overflow when scope won't fit row 1 */
  .header.scope-overflow {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "brand hero"
      "scope scope";
    row-gap: 12px;
  }

  /* Footer: show theme toggle alongside locale */
  .footer-end .theme-toggle { display: flex; }


}

@media (max-width: 480px) {
  .brand-prefix { display: none; }

  /* Smaller donuts */
  .alloc { grid-template-columns: 124px 1fr; gap: 16px; }
  .donut-wrap { width: 124px; height: 124px; }
  .donut-wrap svg { width: 124px; height: 124px; }
  .donut-value { font-size: 16px; }

  /* Condensed legend rows */
  .alloc-row { padding: 3px 6px; min-height: 26px; gap: 6px; font-size: 10px; }
  .alloc-list { gap: 2px; }
  .alloc-head { gap: 6px; padding: 0 6px 4px; }

  /* Hide qty column in asset widget */
  #head-assets { grid-template-columns: 8px 1fr 1.2fr 1.1fr; }
  #head-assets > div:nth-child(3) { display: none; }
  #list-assets .alloc-row { grid-template-columns: 8px 1fr 1.2fr 1.1fr; }
  #list-assets .alloc-row .pcs { display: none; }
  #head-brokers { grid-template-columns: 8px 1fr 1.2fr 1.1fr; }
  #list-brokers .alloc-row { grid-template-columns: 8px 1fr 1.2fr 1.1fr; }

  /* Table value: show tis. only, squeeze sparkline */
  .val-full { display: none; }
  .val-tis { display: inline; }
  .trow > .spark-cell { padding-right: 4px; }
  .spark-cell svg { width: 56px; }

  /* Full-width timeframe selector */
  .chart-header { flex-direction: column; align-items: stretch; gap: 16px; }
  .chart-controls { display: flex; width: 100%; }
  .chart-controls button { flex: 1; padding: 4px 0; }

  /* Cal picker: scrollable on small screens */
  .cal-popover { max-height: 70vh; overflow-y: auto; }
  #cal-backdrop {
    position: fixed;
    inset: 0;
    background: oklch(0 0 0 / 0.5);
    z-index: 49;
  }
}

.num-anim { font-variant-numeric: tabular-nums; }

/* ── Page loader ────────────────────────────────────────────────────────── */
#page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-0);
  display: flex;
  align-items: center;
  justify-content: center;
}
#page-loader.is-hidden {
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.loader-w-svg {
  width: 100px;
  height: 72px;
  filter: drop-shadow(0 0 18px oklch(0.88 0.22 150 / 0.55));
  animation: loader-glow 1.6s ease-in-out infinite;
}
.loader-w-path {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: loader-draw 1.6s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes loader-draw {
  0%   { stroke-dashoffset: 200; opacity: 0.2; }
  55%  { stroke-dashoffset: 0;   opacity: 1;   }
  78%  { stroke-dashoffset: 0;   opacity: 1;   }
  100% { stroke-dashoffset: 0;   opacity: 0;   }
}
@keyframes loader-glow {
  0%, 100% { filter: drop-shadow(0 0 10px oklch(0.88 0.22 150 / 0.35)); }
  55%       { filter: drop-shadow(0 0 26px oklch(0.88 0.22 150 / 0.75)); }
}
