:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #1a2434;
  --border: #243044;
  --text: #e6edf6;
  --muted: #8a99ad;
  --accent: #4f8cff;
  --buy: #2ecc71;
  --sell: #ff5c5c;
  --hold: #b0b8c4;
  --add: #36c98a;
  --trim: #ffb648;
  --warn: #ffb648;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
.hidden { display: none !important; }

/* ---- Auth ---- */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center start;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #16121f 0%, #07060c 70%);
}
/* Dragon's-lair 3D background (canvas fills the auth screen, sits behind the card) */
.dragon-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  opacity: 0;
  transition: opacity 1.6s ease;
}
.dragon-bg.ready { opacity: 1; }
.auth-card {
  position: relative;
  z-index: 1;
  margin-left: clamp(24px, 16vw, 300px);
  background: rgba(19, 26, 38, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.brand { font-weight: 800; letter-spacing: -0.5px; }
.tagline { color: var(--muted); margin-top: 4px; }
.tabs { display: flex; gap: 6px; margin: 20px 0 16px; background: var(--panel-2); border-radius: 10px; padding: 4px; }
.tab { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 9px; border-radius: 7px; cursor: pointer; font-weight: 600; }
.tab.active { background: var(--accent); color: white; }
form { display: flex; flex-direction: column; gap: 10px; }
input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 9px;
  font-size: 14px;
  width: 100%;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  user-select: none;
}
.remember input { width: auto; margin: 0; cursor: pointer; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.65; cursor: default; }
/* Loading state: hide the label and center a spinner (used by Re-analyze while it recomputes). */
.btn.loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.loading::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: btnspin 0.6s linear infinite;
}
@keyframes btnspin { to { transform: rotate(360deg); } }

/* Re-analyze progress: a real, staged bar with phase label + percent — not a blind spinner. */
.pf-progress { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 0 0 14px; }
.pf-progress.hidden { display: none; }
.pf-progress .pf-progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 9px; }
.pf-progress .pf-progress-label { font-weight: 600; font-size: 13.5px; color: var(--text); }
.pf-progress .pf-progress-detail { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pf-progress .pf-progress-pct { font-size: 12.5px; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.pf-progress .pf-progress-track { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.pf-progress .pf-progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.35s ease; }
.pf-progress.error .pf-progress-fill { background: var(--sell); }
.pf-progress.error .pf-progress-label { color: var(--sell); }
.error { color: var(--sell); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---- Trending now (popularity context on the Opportunities page) ---- */
.trending-panel { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; }
.trending-panel.hidden { display: none; }
.trending-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.trending-title { font-weight: 700; font-size: 14px; }
.trending-note { color: var(--muted); font-size: 12px; }
.trend-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trend-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px; cursor: pointer; color: var(--text); font: inherit; }
.trend-chip:hover { border-color: var(--accent); }
.trend-chip .trend-sym { font-weight: 700; font-size: 13px; }
.trend-chip .pill { font-size: 10.5px; padding: 1px 6px; }
.trend-chip .pill.buy { background: rgba(46,204,113,0.15); color: var(--buy); }
.trend-chip .pill.sell { background: rgba(255,92,92,0.15); color: var(--sell); }
.trend-chip .pill.hold { background: rgba(176,184,196,0.15); color: var(--hold); }
.trend-chip .trend-conv { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.trend-chip .trend-flag { font-size: 10px; color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; padding: 0 4px; }
.trend-chip.uncovered { opacity: 0.8; }
.trend-chip .trend-uncov { font-size: 11px; color: var(--muted); }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand-row .brand { font-size: 18px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.nav-btn.active, .nav-btn:hover { background: var(--panel-2); color: var(--text); }
.user-row { display: flex; align-items: center; gap: 10px; }
.user-email { color: var(--muted); font-size: 13px; }
.badge { background: var(--sell); color: white; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700; }

/* ---- Account badge ---- */
.account { position: relative; display: flex; align-items: center; gap: 10px; }

/* ---- Language picker (top-right, and auth screen corner) ---- */
.lang-select {
  width: auto; height: 40px; padding: 5px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  font-size: 13px; cursor: pointer;
}
.lang-select:hover { border-color: var(--accent); }
.auth-view { position: relative; }
.auth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.auth-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.auth-lang { margin: 0; flex: none; border-radius: 9px; }
.auth-switch { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; cursor: pointer; }
.auth-switch a:hover { text-decoration: underline; }

/* ---- Title screen ---- */
.title-card { text-align: center; }
.title-brand {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(180deg, #ffffff, #cdd6e6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title-tagline { color: var(--muted); margin: 6px 0 22px; font-size: 14px; }
.title-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.title-actions .btn { padding: 12px 14px; font-size: 14px; }
.title-register {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.title-register:hover { color: var(--accent); text-decoration: underline; }
.account-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 5px 10px 5px 5px; border-radius: 8px; cursor: pointer; font: inherit;
}
.account-badge:hover { border-color: var(--accent); }
.account-badge .user-email { color: var(--text); }
.account-badge .caret { color: var(--muted); font-size: 11px; }
.account-avatar {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 13px; font-weight: 700; flex: none;
}
.account-menu { min-width: 160px; }
.account-email-row { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
.account-email-row b { color: var(--text); }

.content { padding: 26px 22px 60px; max-width: 1140px; margin: 0 auto; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -0.4px; }
.controls { display: flex; align-items: center; gap: 10px; }
.controls label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.controls select { width: auto; }
.controls .meta { margin: 0; }
.meta { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.head-text { display: flex; flex-direction: column; gap: 3px; }
.head-disclaimer { margin: 0; color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---- Cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card-head { display: flex; align-items: center; gap: 10px; }
.coin-img { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); }
.coin-name { font-weight: 700; }
.coin-sym { color: var(--muted); text-transform: uppercase; font-size: 12px; }
.price { margin-left: auto; text-align: right; }
.price .num { font-weight: 700; }
.chg { font-size: 12px; }
.chg.up { color: var(--buy); }
.chg.down { color: var(--sell); }

.action-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 6px; }
.pill {
  font-weight: 800; font-size: 12px; letter-spacing: 0.4px;
  padding: 3px 10px; border-radius: 999px; text-transform: uppercase;
}
.pill.BUY, .pill.ADD { background: rgba(46,204,113,0.15); color: var(--buy); }
.pill.SELL { background: rgba(255,92,92,0.15); color: var(--sell); }
.pill.TRIM { background: rgba(255,182,72,0.15); color: var(--trim); }
.pill.HOLD { background: rgba(176,184,196,0.15); color: var(--hold); }

.conviction { flex: 1; }
.bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.alloc { font-weight: 700; }

.rationale { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.metrics { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.metrics b { color: var(--text); font-weight: 600; }

/* ---- Recommendation asset-class filter: dropdown of checkboxes ---- */
.filters {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 4px;
}
.filters-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; margin-right: 4px; }
.filter-dropdown { position: relative; display: inline-block; }
.filter-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: 10px; cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 600;
}
.filter-toggle:hover { border-color: var(--accent); }
.filter-toggle .caret { color: var(--muted); font-size: 11px; }
.filter-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 200px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.filter-opt {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; user-select: none;
}
.filter-opt:hover { background: var(--panel-2); }
.filter-opt input { width: auto; margin: 0; cursor: pointer; accent-color: var(--accent); }

/* ---- Recommendation sections (per asset class) ---- */
/* Each asset class is its own clearly bounded card so sections never blur together. */
.rec-section {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 20px 20px; margin-bottom: 18px;
}
/* Signal calibration scorecard (Backtest tab) */
.scorecard { margin-top: 28px; }
.scorecard-head { margin-bottom: 10px; padding-bottom: 8px; }
.scorecard-head h2 { font-size: 18px; }
.scorecard-head h2.sub { font-size: 15px; }
.scorecard-table { width: 100%; margin: 4px 0 6px; }
.scorecard-table.weights-table { max-width: 480px; }
.scorecard-table .num.up { color: var(--buy); }
.scorecard-table .num.down { color: var(--sell); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.section-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.section-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Two risk-tier tables side by side per section (stack on narrow screens). */
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px 40px; }
/* min-width:0 lets the grid track shrink below the table's natural width; pairing it with
   overflow-x:auto keeps a too-wide table scrolling *inside* its column instead of bulging
   out past the panel's right edge (the 8-column nowrap table can't compress any further). */
.tier { min-width: 0; overflow-x: auto; }
/* Each tier gets a labelled header bar with a colour-coded accent edge so the
   "safer" and "high risk" columns read as two distinct lists at a glance. */
.tier-head {
  display: flex; align-items: baseline; gap: 8px; margin: 0 0 8px;
  padding: 7px 10px; border-radius: 8px; background: var(--panel-2);
  border-left: 3px solid var(--border);
}
.tier-head h4 { margin: 0; font-size: 13px; }
.tier-sub { color: var(--muted); font-size: 11px; }
.tier.highrisk .tier-head { border-left-color: var(--trim); }
.tier.highrisk .tier-head h4 { color: var(--trim); }
.tier.safer .tier-head { border-left-color: var(--buy); }
.tier.safer .tier-head h4 { color: var(--buy); }
.tier.emerging .tier-head { border-left-color: #c084fc; }
.tier.emerging .tier-head h4 { color: #c084fc; }
.empty.small { font-size: 12px; padding: 8px 2px; }
/* Regime chip in the section head — green for broadening, amber for narrowing.
   Sits inline next to the section title so a leader board can never appear without
   the tape context that frames it. */
.regime-chip {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; vertical-align: middle; cursor: help;
}
.regime-chip.regime-broadening { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.regime-chip.regime-narrowing  { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

/* EDGAR panel on the asset detail page — insider activity + material 8-Ks pulled live from SEC. */
.asset-edgar { margin-top: 16px; padding: 14px 16px; border: 1px solid #243044; border-radius: 10px; background: #0f1622; }
.asset-edgar.loading, .asset-edgar.error { padding: 10px 14px; }
.asset-edgar-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.asset-edgar-head h3 { margin: 0; font-size: 14px; font-weight: 700; color: #c084fc; }
.edgar-block { margin-top: 12px; }
.edgar-block:first-of-type { margin-top: 0; }
.edgar-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.edgar-head h4 { margin: 0; font-size: 13px; font-weight: 600; }
.edgar-summary { font-size: 11.5px; margin-bottom: 8px; }
.edgar-subhead { font-size: 11px; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.edgar-pill {
  display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: 10.5px; font-weight: 600;
  background: rgba(255,255,255,0.05); color: var(--muted);
}
.edgar-pill.cluster { background: rgba(34, 197, 94, 0.18); color: #22c55e; }
.edgar-pill.warn    { background: rgba(245, 158, 11, 0.18); color: #f59e0b; }
.edgar-pill.score.up   { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.edgar-pill.score.down { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.edgar-pill.score.flat { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }
.edgar-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.edgar-table th, .edgar-table td { padding: 5px 8px; text-align: left; border-bottom: 1px solid #1a2332; }
.edgar-table th { color: var(--muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.edgar-table td.num, .edgar-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.edgar-table tr.high-mat td { background: rgba(245, 158, 11, 0.05); }
.spinner.small { font-size: 11px; color: var(--muted); padding: 6px 0; }

/* News + LLM analysis panel — on-demand sentiment, mechanism, narrative, and the second-order
   ripple. The second-order block is the front-running edge: "what moves next because of this". */
.asset-news { margin-top: 16px; padding: 14px 16px; border: 1px solid #243044; border-radius: 10px; background: #0f1622; }
.asset-news.loading, .asset-news.error, .asset-news.disabled { padding: 10px 14px; }
.asset-news-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.asset-news-head h3 { margin: 0; font-size: 14px; font-weight: 700; color: #60a5fa; }
.news-pill {
  display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: 10.5px; font-weight: 600;
  background: rgba(255,255,255,0.05); color: var(--muted);
}
.news-pill.small { font-size: 9.5px; padding: 1px 5px; }
.news-pill.sent.up   { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.news-pill.sent.down { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.news-pill.sent.flat { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }
.news-pill.novelty.ok   { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.news-pill.novelty.warn { background: rgba(245, 158, 11, 0.15); color: #f59e0b; cursor: help; }
.news-pill.narrative { background: rgba(192, 132, 252, 0.15); color: #c084fc; }
.news-pill.faint { background: rgba(148, 163, 184, 0.08); color: #64748b; }
.news-second-order { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; background: rgba(96, 165, 250, 0.05); }
.news-subhead { font-size: 11px; font-weight: 600; color: #60a5fa; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.news-so-grid { display: grid; gap: 5px; }
.news-so-row { display: grid; grid-template-columns: 60px 60px 1fr; gap: 10px; align-items: baseline; font-size: 12px; padding: 3px 0; border-bottom: 1px solid #1a2332; }
.news-so-row:last-child { border-bottom: none; }
.news-so-sym { font-weight: 700; }
.news-so-row.up .news-so-impact { color: #22c55e; }
.news-so-row.down .news-so-impact { color: #ef4444; }
.news-so-row.flat .news-so-impact { color: #94a3b8; }
.news-so-impact { font-variant-numeric: tabular-nums; }
.news-so-rat { font-size: 11px; }
.news-articles { display: flex; flex-direction: column; gap: 10px; }
.news-article { padding: 8px 10px; border-radius: 6px; background: rgba(255,255,255,0.02); border-left: 2px solid #243044; }
.news-article.scored.up   { border-left-color: #22c55e; }
.news-article.scored.down { border-left-color: #ef4444; }
.news-article.unscored { opacity: 0.65; }
.news-art-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.news-art-head a { color: var(--fg); text-decoration: none; }
.news-art-head a:hover { text-decoration: underline; }
.news-art-date { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; min-width: 75px; }
.news-art-sent { font-weight: 700; font-variant-numeric: tabular-nums; }
.news-art-sent.up   { color: #22c55e; }
.news-art-sent.down { color: #ef4444; }
.news-art-sent.flat { color: #94a3b8; }
.news-art-mech { font-size: 11.5px; color: #cbd5e1; margin-top: 4px; padding-left: 4px; border-left: 2px solid #1e293b; padding-left: 8px; }
.news-art-meta { display: flex; gap: 10px; margin-top: 5px; flex-wrap: wrap; font-size: 10.5px; }

.rec-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rec-table th, .rec-table td {
  padding: 7px 8px; text-align: left; white-space: nowrap;
}
.rec-table th {
  color: var(--muted); font-weight: 700; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
}
.rec-table td { border-bottom: 1px solid rgba(36,48,68,0.5); }
.rec-table tbody tr:last-child td { border-bottom: 0; }
.rec-table td.num, .rec-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Zebra striping + hover make individual rows easy to track across columns. */
.rec-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.022); }
.rec-table tbody tr:hover { background: var(--panel-2); }
.rec-table .asset { display: flex; flex-direction: column; line-height: 1.2; }
.rec-table .asset .sym { font-weight: 700; }
.earn-badge {
  display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 6px;
  font-size: 9px; font-weight: 600; vertical-align: middle; white-space: nowrap;
  background: rgba(176,184,196,0.16); color: var(--muted);
}
.earn-badge.warn { background: rgba(255,182,72,0.18); color: var(--trim); }
.facs { margin-left: 6px; display: inline-flex; gap: 3px; vertical-align: middle; }
.fac {
  display: inline-block; padding: 0 4px; border-radius: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.2px;
}
.fac.up { background: rgba(46,204,113,0.16); color: var(--buy); }
.fac.down { background: rgba(255,92,92,0.16); color: var(--sell); }
.appr {
  display: inline-block; margin-left: 6px; padding: 0 4px; border-radius: 4px;
  font-size: 9px; font-weight: 700; vertical-align: middle;
}
.appr.up { background: rgba(46,204,113,0.16); color: var(--buy); }
.appr.down { background: rgba(255,92,92,0.16); color: var(--sell); }
.rec-table .asset .nm {
  color: var(--muted); font-size: 11px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
.rec-table .chg.up { color: var(--buy); }
.rec-table .chg.down { color: var(--sell); }
.rec-table .alloc { font-weight: 700; }
.rec-table .pill { font-size: 10px; padding: 1px 7px; }

.holding-meta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 13px; }
.pl.up { color: var(--buy); }
.pl.down { color: var(--sell); }
.card-actions { margin-top: 12px; display: flex; justify-content: flex-end; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; }
/* ---- Sortable headers ---- */
.rec-table th.sortable { cursor: pointer; user-select: none; }
.rec-table th.sortable:hover { color: var(--text); }
.rec-table th.active { color: var(--text); }
.sort-ind { font-size: 9px; margin-left: 4px; opacity: 0.35; }
.sort-ind.active { opacity: 1; color: var(--accent); }

/* ---- Row kebab menu ---- */
.kebab {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 17px; line-height: 1; padding: 2px 7px; border-radius: 6px;
}
.kebab:hover { background: var(--panel-2); color: var(--text); }
.row-menu {
  position: absolute; z-index: 60; min-width: 132px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 4px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}
.row-menu .menu-item {
  background: none; border: 0; color: var(--text); text-align: left;
  padding: 8px 11px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.row-menu .menu-item:hover { background: var(--panel-2); }
.row-menu .menu-item.danger { color: var(--sell); }

/* ---- Portfolio table ---- */
.portfolio-table {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.portfolio-table .pl.up { color: var(--buy); }
.portfolio-table .pl.down { color: var(--sell); }

/* ---- Sell suggestions ---- */
.sell-panel {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--sell);
  border-radius: 12px; padding: 14px 18px; margin-bottom: 18px;
}
.sell-panel.none { border-left-color: var(--buy); }
.sell-panel h3 { margin: 0 0 4px; font-size: 15px; }
.sell-panel.none h3 { color: var(--buy); }
.sell-panel > p { margin: 0; color: var(--muted); font-size: 12.5px; }
.sell-sub { margin: 0 0 10px !important; }
.rebal-macro { margin: 0 0 8px !important; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; }
.pill-new { background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.4px; }
.sell-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sell-item { border-top: 1px solid rgba(36,48,68,0.6); padding-top: 10px; }
.sell-item:first-child { border-top: 0; padding-top: 0; }
.sell-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sell-head .sym { font-weight: 700; }
.sell-head .nm { color: var(--muted); font-size: 12.5px; }
.sell-head .conv { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.sell-head .pl { margin-left: auto; font-weight: 700; font-size: 13px; }
.sell-actions { display: flex; gap: 6px; }
.sell-confirm {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.sell-confirm:hover:not(:disabled) { border-color: var(--accent); }
.sell-confirm:disabled { opacity: 0.5; cursor: default; }
.sell-why { margin: 5px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--text); }

/* ---- Totals ---- */
.totals { display: flex; gap: 14px; margin: 4px 0 18px; flex-wrap: wrap; }
.totals .stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; min-width: 130px; }
.totals .stat .label { color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.totals .stat .val { font-size: 21px; font-weight: 800; margin-top: 5px; letter-spacing: -0.3px; }

/* ---- Alerts ---- */
.alerts { display: flex; flex-direction: column; gap: 10px; }
.alert {
  background: var(--panel); border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px; padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start;
}
.alert.unread { background: var(--panel-2); }
.alert.SELL { border-left-color: var(--sell); }
.alert.TRIM { border-left-color: var(--trim); }
.alert.ADD, .alert.BUY { border-left-color: var(--buy); }
.alert .a-body { flex: 1; }
.alert .a-time { color: var(--muted); font-size: 11.5px; }

/* ---- Settings ---- */
.setting { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; max-width: 560px; }
.setting label { display: block; margin-bottom: 10px; font-weight: 600; }
.risk-value { margin: 8px 0; font-weight: 700; color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; }

/* Segmented buy-list stance control: two mutually-exclusive options; the chosen one fills accent. */
.stance-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stance-opt { padding: 8px 16px; border: none; background: var(--panel-2); color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.stance-opt + .stance-opt { border-left: 1px solid var(--border); }
.stance-opt:hover { color: var(--text); }
.stance-opt.active { background: var(--accent); color: white; }

/* Conviction + rank badge on a suggestion (e.g. "conviction 68 · #14/503"). */
.rebal-rank { color: var(--muted); }

/* ---- Global asset search (top bar) ---- */
.global-search { position: relative; flex: 0 1 280px; min-width: 150px; }
.global-search input {
  width: 100%; height: 40px; padding: 6px 12px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  font-size: 14px;
}
.global-search input::placeholder { color: var(--muted); }
.global-search input:focus { outline: none; border-color: var(--accent); }
/* The result list floats below the box as a dropdown rather than pushing the page down. */
.global-search-results {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 60;
  margin-top: 0; min-width: 300px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; box-shadow: 0 14px 34px rgba(0,0,0,0.45);
}

/* ---- Asset detail page ---- */
.asset-page-bar { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: grid; place-items: center; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 100%; max-width: 420px; position: relative; max-height: 90vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 14px; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; }
.search-results { max-height: 220px; overflow-y: auto; margin-top: 8px; }
.search-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.search-item:hover, .search-item.active { background: var(--panel-2); }
.search-item .rank { color: var(--muted); font-size: 11px; margin-left: auto; }
.selected-asset { background: var(--panel-2); padding: 8px 10px; border-radius: 8px; margin: 4px 0 12px; }
.add-progress { background: var(--panel-2); border-left: 3px solid var(--buy, #2ecc71); padding: 8px 10px; border-radius: 6px; margin: 0 0 12px; font-size: 12.5px; color: var(--text); }
.tag-opening { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
#holding-form label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.field-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; }
#holding-form .field-label { color: var(--accent); }
.optional { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.type-chips { display: flex; gap: 6px; margin-bottom: 4px; }
.chip { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }
.search-status { color: var(--muted); padding: 12px 10px; font-size: 13px; }
.search-status.error { color: var(--sell); }
.est-value { color: var(--text); font-size: 13px; font-weight: 600; margin: 0 0 12px; }

/* ---- Asset detail modal (clicked-row deep view) ---- */
.modal-card.asset-detail { max-width: 880px; padding: 22px 24px 24px; }
.asset-detail-header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px 14px; padding-right: 32px; margin-bottom: 14px; }
.asset-detail-header .ad-sym { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.asset-detail-header .ad-name { color: var(--muted); font-size: 14px; }
.asset-detail-header .ad-price { margin-left: auto; font-size: 22px; font-weight: 800; }
.asset-detail-header .ad-change { font-size: 14px; font-weight: 700; }
.asset-detail-header .ad-change.up { color: var(--buy); }
.asset-detail-header .ad-change.down { color: var(--sell); }
.asset-detail-ranges { display: flex; gap: 4px; margin: 4px 0 10px; background: var(--panel-2); border-radius: 8px; padding: 3px; width: fit-content; }
.range-btn { background: transparent; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 12.5px; }
.range-btn.active { background: var(--accent); color: white; }
.range-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.asset-chart-wrap { position: relative; width: 100%; }
.asset-detail-chart { width: 100%; height: 280px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; cursor: crosshair; display: block; }
.asset-chart-tooltip { position: absolute; pointer-events: none; background: rgba(11,18,32,0.95); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,0.35); white-space: nowrap; z-index: 2; }
.asset-chart-tooltip .cht-date { color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0.3px; }
.asset-chart-tooltip .cht-price { font-weight: 700; font-size: 14px; margin-top: 1px; }
.asset-chart-tooltip.hidden { display: none; }
.asset-detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0 8px; }
.asset-detail-stats .stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.asset-detail-stats .stat .label { color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.asset-detail-stats .stat .val { font-size: 16px; font-weight: 700; margin-top: 4px; }
.asset-detail-stats .stat .val.up { color: var(--buy); }
.asset-detail-stats .stat .val.down { color: var(--sell); }
.asset-detail-signal { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-top: 12px; }
.asset-detail-signal .ad-sig-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.asset-detail-signal .ad-sig-head h4 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.asset-detail-signal .ad-rationale { color: var(--text); font-size: 13.5px; line-height: 1.55; margin: 8px 0 0; }
.asset-detail-indicators { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.asset-detail-indicators .ind { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.asset-detail-indicators .ind .ind-label { color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.asset-detail-indicators .ind .ind-val { font-weight: 700; margin-top: 2px; }
.asset-detail-error { color: var(--muted); padding: 30px 0; text-align: center; }
/* Make rows in the rec/portfolio/housing tables look clickable for the detail view. */
.rec-table tbody tr.clickable { cursor: pointer; transition: background 0.12s ease; }
.rec-table tbody tr.clickable:hover { background: rgba(79, 140, 255, 0.07); }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 10px; z-index: 100; font-size: 14px;
}

.empty { color: var(--muted); padding: 30px; text-align: center; }
.spinner { color: var(--muted); padding: 30px; text-align: center; }

/* Asset-class chip. Each class carries a distinct colour so types
   (crypto, stock, commodity…) are scannable at a glance. */
.src {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.5px; padding: 1px 6px;
  border-radius: 5px; vertical-align: middle;
  background: rgba(176,184,196,0.14); color: var(--muted);
}
.src.stock     { background: rgba(79,140,255,0.16);  color: #6ea2ff; }
.src.crypto    { background: rgba(247,147,26,0.18);  color: #f7931a; }
.src.commodity { background: rgba(212,175,55,0.16);  color: #d4af37; }
.src.housing   { background: rgba(38,198,218,0.16);  color: #2bc6da; }
.src.property  { background: rgba(38,198,218,0.16);  color: #2bc6da; }
.src.cardeprec { background: rgba(255,92,92,0.15);   color: #ff7a7a; }
.src.cash      { background: rgba(46,204,113,0.14);  color: #5fd99a; }
.src.nft       { background: rgba(167,108,255,0.18); color: #b98cff; }
/* "Owned under <business>" tag on holdings held inside a business. */
.owner-chip { font-size: 9.5px; font-weight: 700; letter-spacing: 0.3px; padding: 1px 6px; border-radius: 5px; vertical-align: middle; background: rgba(255,182,72,0.16); color: #f0b85c; white-space: nowrap; }

/* Footer action row inside a recommendations section (e.g. "track a property"). */
.section-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
/* .section-meta defaults to white-space:nowrap so short head metas ("15 buy signals") never wrap.
   The foot variant carries a long sources/disclaimer paragraph — keep nowrap and it blows out the
   page width (1750px of text → horizontal scroll), so let the footnote wrap normally. */
.section-foot .section-meta { white-space: normal; }

/* ---- Housing: trend pills + property cards ---- */
.trend-pill {
  font-weight: 800; font-size: 11px; letter-spacing: 0.3px;
  padding: 2px 9px; border-radius: 999px; cursor: default;
}
.trend-pill.Rising { background: rgba(46,204,113,0.15); color: var(--buy); }
.trend-pill.Cooling { background: rgba(255,182,72,0.16); color: var(--trim); }
.trend-pill.Falling { background: rgba(255,92,92,0.15); color: var(--sell); }
.trend-pill.Rebounding { background: rgba(79,140,255,0.16); color: var(--accent); }
.trend-pill.Flat { background: rgba(176,184,196,0.15); color: var(--hold); }
.trend-pill.Depreciating { background: rgba(255,182,72,0.16); color: var(--trim); }

#property-list { margin-bottom: 18px; }
.asset-table-section { margin-bottom: 22px; }
.asset-table-section:last-child { margin-bottom: 0; }
.asset-table-title { font-size: 14px; font-weight: 700; margin: 0 0 8px; color: var(--text); }
.table-scroll, .asset-table-section .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Some portfolio render paths drop a bare <table> straight into #portfolio-list with no
   .table-scroll wrapper. The 8-column nowrap table is wider than a phone viewport, so without
   this the table stretches the whole page and the entire body scrolls sideways. Making the
   container itself an x-scroller keeps the overflow inside the panel on every render path. */
#portfolio-list, #log-list { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* These per-class tables carry up to 13 columns (the housing momentum trio + financing),
   ~90px wider than the 1096px content column — enough to push the Signal and row-actions
   columns off the right edge behind the scrollbar. Tightening the cell padding and dropping
   to a 12px body font claws that back so the full row fits at standard widths; overflow-x
   above still scrolls the table on genuinely narrow screens. */
.portfolio-table { font-size: 12px; }
.asset-table-section .portfolio-table th,
.asset-table-section .portfolio-table td { padding-left: 5px; padding-right: 5px; }
.asset-table-section .portfolio-table .asset .nm { max-width: 130px; }
.prop-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.prop-card { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; padding: 14px 16px; }
.prop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prop-head > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.prop-city { font-weight: 700; font-size: 14.5px; }
.prop-metrics { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0 4px; }
.prop-metrics .metric { display: flex; flex-direction: column; line-height: 1.3; }
.prop-metrics .m-label { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.prop-metrics .m-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.prop-metrics .m-val.up { color: var(--buy); }
.prop-metrics .m-val.down { color: var(--sell); }
.prop-why { color: var(--text); font-size: 12.5px; line-height: 1.45; margin: 6px 0 4px; }
.prop-src { color: var(--muted); font-size: 11px; margin: 0; }
.prop-caveat { color: var(--warn); font-size: 11px; line-height: 1.4; margin: 4px 0 0; }
/* Data-source caveat sub-row: hangs under its asset row (no top border) so it reads as attached. */
.asset-table-section .portfolio-table tr.caveat-row td { padding-top: 0; padding-bottom: 8px; border-top: none; }
.asset-table-section .portfolio-table tr.caveat-row .prop-caveat { margin: 0; display: block; white-space: normal; }
/* Anchor-refresh nudge sub-row: same attached treatment, muted/accent rather than warning amber. */
.asset-table-section .portfolio-table tr.valnudge-row td { padding-top: 0; padding-bottom: 8px; border-top: none; }
.prop-valnudge { color: var(--muted); font-size: 11px; line-height: 1.4; display: block; white-space: normal; }
.prop-valnudge a { color: var(--accent); text-decoration: none; }
.prop-valnudge a:hover { text-decoration: underline; }
.linklike { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike:hover { text-decoration: underline; }

.bt-search { position: relative; max-width: 560px; }
.chart { width: 100%; max-width: 900px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-top: 14px; }

/* ---- Tooltip ---- */
.tooltip {
  position: fixed;
  z-index: 200;
  max-width: 360px;
  /* A shade lighter than --panel-2 so the whole popover (arrow included) lifts off the
     near-black page background; brighter border gives it a crisp edge. */
  background: #202c40;
  border: 1px solid #34465f;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  padding: 11px 14px;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.08s ease;
}
.tooltip.show { opacity: 1; visibility: visible; }

/* Formatted popover content */
.tip-headline { font-weight: 700; margin-bottom: 7px; }
.tip-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.tip-list li { font-size: 13px; color: var(--text); padding-left: 12px; position: relative; }
.tip-list li::before { content: '·'; position: absolute; left: 2px; color: var(--muted); }
.tip-event {
  margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--warn);
  padding-top: 8px; border-top: 1px solid var(--border);
}
.tip-event + .tip-event { margin-top: 4px; padding-top: 0; border-top: 0; }
.tip-footer { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.tip-text { margin: 0; }

/* Pointing arrow: a fill triangle (::after) over a slightly larger border triangle (::before).
   Vertically tracks the hovered row via --tip-arrow-y set in JS. */
.tooltip.tip-arrow-left::before, .tooltip.tip-arrow-left::after,
.tooltip.tip-arrow-right::before, .tooltip.tip-arrow-right::after {
  content: ''; position: absolute; width: 0; height: 0;
  top: var(--tip-arrow-y, 50%); transform: translateY(-50%);
}
.tooltip.tip-arrow-left::before { left: -9px; border: 8px solid transparent; border-right-color: #34465f; }
.tooltip.tip-arrow-left::after  { left: -7px; border: 7px solid transparent; border-right-color: #202c40; }
.tooltip.tip-arrow-right::before { right: -9px; border: 8px solid transparent; border-left-color: #34465f; }
.tooltip.tip-arrow-right::after  { right: -7px; border: 7px solid transparent; border-left-color: #202c40; }

/* ===================== Mobile (≤ 760px) =====================
   Stacks the topbar into three rows (brand+account, full-width search,
   scrollable nav), drops side gutters, collapses multi-column grids to
   single column, and bumps input font-size to 16px so iOS Safari doesn't
   zoom on focus. */
@media (max-width: 760px) {
  input, select, textarea { font-size: 16px; }

  /* ---- Auth ---- */
  .auth-view { place-items: center; padding: 18px 14px; }
  .auth-card { margin-left: 0; padding: 22px 18px; max-width: 420px; border-radius: 14px; }
  .auth-title { font-size: 20px; }
  /* Canvas backdrop is decorative; never let it eat taps on the form. */
  .dragon-bg { pointer-events: none; }

  /* ---- Topbar: three rows on small screens ---- */
  .topbar { gap: 8px; padding: 10px 12px; }
  .brand-row { flex: 1 1 auto; }
  .brand-row .brand { font-size: 16px; }
  /* Account stays on row 1 next to brand, but compacts to just the avatar. */
  .account { flex: 0 0 auto; gap: 6px; order: 0; }
  .account-badge { padding: 4px 7px 4px 4px; }
  .account-badge .user-email { display: none; }
  .account-badge .caret { display: none; }
  .account .lang-select { height: 34px; padding: 4px 6px; font-size: 12px; }
  /* Search becomes its own full-width row. */
  .global-search { order: 2; flex: 1 1 100%; min-width: 0; }
  .global-search input { height: 38px; font-size: 16px; }
  .global-search-results { right: 0; left: 0; min-width: 0; }
  /* Nav becomes a horizontally scrollable strip so all tabs stay reachable. */
  .nav {
    order: 3; flex: 1 1 100%; gap: 2px;
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -ms-overflow-style: none;
    margin: 0 -12px; padding: 0 12px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn { flex: 0 0 auto; padding: 8px 11px; font-size: 13px; white-space: nowrap; }

  /* ---- Content / panels ---- */
  .content { padding: 16px 12px 48px; }
  .panel-head { gap: 8px; margin-bottom: 10px; padding-bottom: 10px; }
  .panel-head h2 { font-size: 19px; }
  .head-disclaimer { font-size: 11.5px; }
  .controls { gap: 6px; flex-wrap: wrap; }

  /* ---- Recommendations: collapse risk-tier grid, scroll each table ---- */
  .rec-section { padding: 12px 12px 14px; border-radius: 12px; }
  .tiers { grid-template-columns: 1fr; gap: 14px; }
  .tier { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .rec-table { font-size: 12px; }
  .rec-table th, .rec-table td { padding: 6px 6px; }
  .rec-table .asset .nm { max-width: 110px; }
  .section-head { gap: 6px; margin-bottom: 10px; padding-bottom: 8px; flex-wrap: wrap; }
  .section-head h3 { font-size: 14.5px; }

  /* ---- Totals row: 2 per row on phones ---- */
  .totals { gap: 8px; }
  .totals .stat { min-width: 0; flex: 1 1 calc(50% - 8px); padding: 10px 12px; }
  .totals .stat .val { font-size: 18px; }

  /* Card grids (rare paths) — full width on phones. */
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .prop-card-grid { grid-template-columns: 1fr; gap: 10px; }
  .prop-card { padding: 12px 14px; }

  /* ---- Modals: edge-to-edge with safe padding, larger close target ---- */
  .modal { padding: 10px; }
  .modal-card { padding: 18px 16px; max-width: 100%; max-height: calc(100vh - 20px); border-radius: 12px; }
  .modal-card.asset-detail { padding: 18px 14px; }
  .modal-close {
    top: 6px; right: 8px; width: 40px; height: 40px;
    display: grid; place-items: center; font-size: 26px;
  }
  .modal-actions { flex-wrap: wrap; gap: 8px; }
  .modal-actions .btn { flex: 1 1 auto; min-width: 110px; padding: 11px 14px; }

  /* ---- Asset detail page ---- */
  .asset-page-bar { flex-wrap: wrap; gap: 8px; }
  .asset-detail-header { gap: 6px 10px; padding-right: 0; margin-bottom: 10px; }
  .asset-detail-header .ad-sym { font-size: 18px; }
  .asset-detail-header .ad-name { font-size: 13px; width: 100%; }
  .asset-detail-header .ad-price { margin-left: 0; font-size: 19px; }
  .asset-detail-chart { height: 220px; }
  .asset-detail-ranges { width: 100%; overflow-x: auto; }
  .asset-detail-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .asset-detail-stats .stat { padding: 8px 10px; }
  .asset-detail-stats .stat .val { font-size: 14.5px; }
  .asset-detail-indicators { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* ---- Sell suggestions: stack actions, let p/l drop below symbol ---- */
  .sell-panel { padding: 12px 14px; }
  .sell-head .pl { margin-left: 0; }
  .sell-actions { width: 100%; }
  .sell-confirm { flex: 1 1 auto; padding: 8px 12px; }

  /* ---- Settings ---- */
  .setting { padding: 14px; }

  /* Long-form .section-meta footnotes (e.g. car-deprec sources) must wrap on
     mobile — desktop nowrap is intended for short tags ("13 buy signals"). */
  .section-meta { white-space: normal; }

  /* ---- Tooltip: clamp to a card, never span the full row/page on touch ---- */
  .tooltip { max-width: min(320px, calc(100vw - 28px)); font-size: 13px; max-height: 60vh; overflow-y: auto; }

  /* ---- Toast: lifted above iOS home-bar, capped to viewport width ---- */
  .toast { bottom: 14px; max-width: calc(100vw - 28px); }

  /* ---- Tappable button minimum sizing ---- */
  .btn { padding: 10px 14px; }
  .chip { padding: 10px 8px; }
}

/* ===== Phones ≤ 420px: tighten further, collapse final two-column grids ===== */
@media (max-width: 420px) {
  .auth-card { padding: 20px 14px; }
  .auth-title { font-size: 19px; }
  .content { padding: 12px 10px 48px; }
  .panel-head h2 { font-size: 17px; }
  .totals .stat { flex-basis: 100%; }
  .asset-detail-stats { grid-template-columns: 1fr; }
  .asset-detail-indicators { grid-template-columns: 1fr; }
  .rec-table .asset .nm { max-width: 90px; }
  .brand-row .brand { font-size: 15px; }
}

/* rebalance: concrete order line + per-row "done" button */
.rebal-order { font-weight: 600; color: var(--text); }
.sell-head .rebal-done { margin-left: auto; padding: 5px 10px; font-size: 12px; }
/* group heading that splits the sell block from the buy block */
.rebal-group { margin: 14px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.rebal-group:first-child { margin-top: 4px; }

/* Rebalancing aggressiveness slider */
.agg-slider { margin: 6px 0 4px; }
.agg-slider #agg-range { width: 100%; accent-color: var(--accent, var(--buy)); }
.agg-scale { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.agg-scale .agg-level { font-weight: 800; color: var(--text); font-size: 12.5px; }

/* CORE badge — a holding excluded from the rebalance engine + benchmark */
.core-badge { display: inline-block; font-size: 9.5px; font-weight: 800; letter-spacing: 0.06em; padding: 1px 5px; border-radius: 5px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }

/* "Your picks vs VOO" honest-scoreboard panel */
.bench-panel { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 8px 0 4px; background: var(--panel-2); border-left: 4px solid var(--muted); }
.bench-panel.ahead { border-left-color: var(--buy); }
.bench-panel.behind { border-left-color: var(--sell); }
.bench-head { margin: 0 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }
.bench-cmp { display: flex; align-items: center; gap: 14px; }
.bench-col { flex: 1; }
.bench-lbl { font-size: 11.5px; color: var(--muted); }
.bench-val { font-size: 20px; font-weight: 800; }
.bench-vs { font-size: 12px; color: var(--muted); font-weight: 700; }
.bench-verdict { margin: 8px 0 2px; font-size: 13.5px; font-weight: 700; }
.bench-verdict.ahead { color: var(--buy); }
.bench-verdict.behind { color: var(--sell); }
.bench-verdict.even { color: var(--muted); }
.bench-note { margin: 0; font-size: 11.5px; color: var(--muted); }

/* cash stat card edit affordance + rebalance cash-flow note */
#cash-stat .label { display: flex; align-items: center; gap: 6px; }
#cash-stat .cash-edit { font-size: 11px; }
#cash-stat .cash-input { width: 100%; padding: 2px 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700; }
.rebal-cash { margin: 2px 0 6px; font-size: 12.5px; }
.rebal-cash.warn { color: var(--sell); font-weight: 600; }

/* rebalance order amounts: sell earns cash (green), buy costs cash (red) */
.rebal-order.gain { color: var(--buy); }
.rebal-order.cost { color: var(--sell); }

/* Rebalance rows: make each move a clearly-bounded card so its "I've done this"
   button is unmistakably tied to that row (previously a thin top border made
   adjacent rows blur together). */
#rebalance-panel .sell-list { gap: 0; }
#rebalance-panel .sell-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}
#rebalance-panel .sell-item:first-child { padding-top: 12px; } /* override the list's first-child reset */
#rebalance-panel .sell-item:last-child { margin-bottom: 0; }
#rebalance-panel .sell-head .rebal-done { flex-shrink: 0; }

/* rebalance move: symbol/name click through to the asset detail page */
.sell-head .rebal-asset { cursor: pointer; }
.sell-head .rebal-asset:hover { text-decoration: underline; }
