/* DSE Single-Share Intelligence — visualizer styles.
   Plain CSS, light + dark via prefers-color-scheme, no dependencies. */

:root {
  color-scheme: light dark;
  --bg: #eef0f4;
  --panel: #ffffff;
  --ink: #1b2536;
  --muted: #566173;
  --dim: #6b7588;           /* dimmed-but-readable (weekend dates) */
  --line: #e2e6ee;
  --accent: #4f46e5;
  --on-accent: #ffffff;     /* text on solid accent - dark mode swaps to dark ink */
  --up: #15803d;
  --down: #b91c1c;
  --flat: #6b7280;          /* flat trend in charts/markers */
  --flat-ink: #4b5563;      /* flat trend as TEXT (passes 4.5:1 on tints) */
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --info-bg: #e0e7ff;
  --info-ink: #3730a3;
  --sma20: #d97706;
  --sma50: #0284c7;
  --sma200: #9333ea;
  --cmp1: #0e7490;          /* compare-chart series colours (4 distinct hues) */
  --cmp2: #be185d;
  --cmp3: #4d7c0f;
  --cmp4: #1d4ed8;
  --star: #d97706;          /* watchlist star */
  --grid: #e4e8ef;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 1px 6px rgba(20, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141820;
    --panel: #1a1f28;
    --ink: #e7eaf0;
    --muted: #9aa3b2;
    --dim: #9aa3b2;
    --line: #2a313d;
    --accent: #818cf8;
    --on-accent: #1e1b4b;
    --up: #4ade80;
    --down: #f87171;
    --flat: #9ca3af;
    --flat-ink: #b3bcc9;
    --warn-bg: #3b2f0b;
    --warn-ink: #fcd34d;
    --info-bg: #1e1b4b;
    --info-ink: #a5b4fc;
    --cmp1: #22d3ee;
    --cmp2: #f472b6;
    --cmp3: #a3e635;
    --cmp4: #93c5fd;
    --star: #fbbf24;
    --grid: #20252e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 10px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 26px; color: var(--accent); }
.brand h1 { font-size: 17px; margin: 0; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
/* on small screens the scrolled-down topbar drops the brand row (JS adds .compact) */
@media (max-width: 640px) {
  .topbar.compact .brand { display: none; }
  .topbar.compact { padding: 8px 14px; }
}

select, button, #instrument-search, #compare-add, #explore-search,
.trade-inputs input {
  font: inherit; color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 13px;
}
#instrument-search, #explore-search, #compare-add { background: var(--panel); }
button { cursor: pointer; transition: background .15s, border-color .15s; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: wait; }
/* below 16px iOS zooms on focus */
#instrument-search, #compare-add, #explore-search, select,
.trade-inputs input { font-size: 16px; }
.toggles input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
#run-pipeline { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
#run-pipeline:hover { filter: brightness(1.08); }
#run-pipeline.running .btn-icon { display: inline-block; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--muted); font-size: 12.5px; }
.mini-btn { font-size: 12px; padding: 5px 11px; border-radius: 8px; vertical-align: middle; }
.run-detail {
  margin: 0; padding: 8px 10px; font-size: 12px; color: var(--muted);
  background: var(--bg); border-radius: 8px; white-space: pre-wrap;
}

/* ---- searchable instrument combobox ---- */
.combo { position: relative; }
#instrument-search { min-width: 300px; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  min-width: min(430px, 86vw); max-height: 320px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.combo-list li {
  padding: 9px 10px; border-radius: 7px; cursor: pointer;
  font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-variant-numeric: tabular-nums;
}
.combo-list li .t { font-weight: 700; margin-right: 8px; }
.combo-list li .muted { margin-left: 8px; }
.combo-list li.active, .combo-list li:hover { background: var(--info-bg); color: var(--info-ink); }
.combo-list li.none { color: var(--muted); cursor: default; }
.combo-list li.none:hover { background: none; color: var(--muted); }

/* ---- pipeline-running indicator ---- */
.run-indicator {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600;
  color: var(--warn-ink); background: var(--warn-bg);
  border-radius: 999px; padding: 4px 12px;
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn-ink); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); }
                   50% { opacity: .35; transform: scale(.75); } }

/* ---- banners ---- */
.banner {
  padding: 8px 20px; font-size: 13.5px; font-weight: 600;
  background: var(--warn-bg); color: var(--warn-ink);
  border-bottom: 1px solid var(--line);
}
.banner code { font-weight: 400; }
.fatal {
  margin: 20px; padding: 14px 18px; border: 1px solid var(--down);
  border-radius: 10px; background: var(--panel);
}
.fatal pre { background: var(--bg); padding: 10px; border-radius: 8px; }

/* ---- layout ---- */
main { max-width: 1180px; margin: 0 auto; padding: 8px 20px 40px; }
section { margin-top: 34px; scroll-margin-top: 64px; }
.section-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 19px; margin: 0; }
.caption { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 70ch; }

/* ---- overview cards: flat stat groups, no boxes ---- */
.cards {
  display: grid; gap: 22px 28px; margin-top: 18px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
.card {
  background: transparent; border: 0;
  border-radius: 0; padding: 0; box-shadow: none;
}
.card .k { font-size: 12px; letter-spacing: 0; text-transform: none;
           color: var(--muted); font-weight: 600; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 3px;
           letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.card .s { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card .s.asof { color: var(--ink); }

.rangebar { position: relative; height: 8px; border-radius: 6px;
            background: linear-gradient(90deg, var(--down), var(--flat), var(--up));
            margin: 10px 0 4px; }
.rangebar .marker {
  position: absolute; top: -4px; width: 3px; height: 16px;
  background: var(--ink); border-radius: 2px;
}
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
  background: var(--info-bg); color: var(--info-ink);
}
.badge.up { background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up); }
.badge.down { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }
.badge.flat { background: color-mix(in srgb, var(--flat) 16%, transparent); color: var(--flat-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---- returns strip ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 12px; font-size: 13px;
  font-variant-numeric: tabular-nums; cursor: default;
}
#returns-strip { gap: 6px 22px; }
#returns-strip .chip {
  background: transparent; border: 0; border-radius: 0; padding: 4px 0;
}
.chip b { font-weight: 600; color: var(--muted); margin-right: 6px; }
.chip .pos { color: var(--up); font-weight: 700; }
.chip .neg { color: var(--down); font-weight: 700; }
.chip .flat { color: var(--flat-ink); font-weight: 700; }

/* ---- chart ---- */
.chart-controls {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-top: 12px;
}
.seg { display: inline-flex; gap: 2px; padding: 2px;
       border: 1px solid var(--line); background: var(--bg);
       border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 7px; padding: 6px 13px;
              background: transparent; color: var(--muted); }
.seg button + button { border-left: 0; }
.seg button.active { background: var(--panel); color: var(--ink);
                     font-weight: 600; box-shadow: 0 1px 2px rgba(20,24,40,.12); }
.toggles { display: flex; gap: 14px; font-size: 13px; color: var(--muted);
           flex-wrap: wrap; }
.toggles label { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.sw-sma20 { background: var(--sma20); } .sw-sma50 { background: var(--sma50); }
.sw-sma200 { background: var(--sma200); }

.chart-wrap {
  position: relative; margin-top: 12px; padding: 10px;
  background: var(--panel); border: 0;
  border-radius: 14px; min-height: 420px;
}
.chart-wrap svg { display: block; width: 100%; }
.chart-empty { padding: 40px; text-align: center; color: var(--muted); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: var(--shadow); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip .tt-date { font-weight: 700; margin-bottom: 3px; }
.tooltip .pos { color: var(--up); } .tooltip .neg { color: var(--down); }

/* ---- tables: flat, hairline rows, sentence-case heads ---- */
.table-scroll { overflow-x: auto; margin-top: 14px; }
table { border-collapse: collapse; width: 100%;
        background: transparent; border: 0; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left;
         border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11.5px; text-transform: none; letter-spacing: 0;
     color: var(--muted); background: transparent; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .pos { color: var(--up); } td .neg { color: var(--down); }
td .na { color: var(--muted); }

/* ---- events ---- */
.events { display: grid; gap: 10px; margin-top: 12px;
          grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.event-card {
  background: var(--panel); border: 0;
  border-radius: 10px; padding: 12px 14px;
}
.event-card.flash { outline: 2px solid var(--accent); }
.event-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.event-head .date { font-variant-numeric: tabular-nums; font-weight: 700; }
.event-desc { margin: 4px 0 8px; font-size: 13px; color: var(--muted); }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr);
             gap: 4px 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.mini-grid .h { color: var(--muted); }
.mapped { font-size: 12px; color: var(--warn-ink); background: var(--warn-bg);
          border-radius: 6px; padding: 1px 7px; font-weight: 600; }

/* ---- sources / quality ---- */
h3 { font-size: 14.5px; margin: 20px 0 8px; }
.pill { background: var(--info-bg); color: var(--info-ink);
        border-radius: 999px; font-size: 12px; padding: 1px 9px; }
.quality { display: grid; gap: 8px; }
.q-item {
  display: flex; gap: 10px; align-items: baseline; font-size: 13px;
  background: var(--panel); border: 0; border-radius: 8px; padding: 9px 12px;
}
.q-sev { font-size: 11.5px; font-weight: 700; text-transform: uppercase;
         letter-spacing: .04em; padding: 1px 8px; border-radius: 6px; }
.q-sev.critical { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.q-sev.warning { background: var(--warn-bg); color: var(--warn-ink); }
.q-sev.info { background: var(--info-bg); color: var(--info-ink); }
.q-empty { color: var(--muted); font-size: 13px; }
.methodology { margin-top: 16px; }
.methodology summary { cursor: pointer; font-size: 13.5px; color: var(--muted);
                       font-weight: 600; }
.methodology summary:hover { color: var(--ink); }
.methodology dl { display: grid; grid-template-columns: max-content 1fr;
                  gap: 6px 16px; font-size: 13px; margin: 12px 0 0; }
.methodology dt { font-weight: 700; color: var(--muted); }
.methodology dd { margin: 0; }

/* ---- footer ---- */
footer {
  border-top: 1px solid var(--line); margin-top: 40px;
  padding: 18px 20px 28px; font-size: 12.5px; color: var(--muted);
}
footer p { max-width: 90ch; margin: 4px 0; }

/* ---- simple / detailed modes ---- */
body.mode-simple .detailed-only { display: none !important; }
body.mode-detailed .simple-only { display: none !important; }

/* ---- views: share / explore / compare ---- */
body.view-share .explore-only, body.view-share .compare-only,
body.view-explore .share-only, body.view-explore .compare-only,
body.view-compare .share-only, body.view-compare .explore-only {
  display: none !important;
}

/* ---- static bundle mode: nothing server-side exists ---- */
body.static .server-only { display: none !important; }
.static-only { display: none; }
body.static .static-only { display: block; }

/* ---- info ("?") buttons + popover ---- */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  border: 0; background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 600;
  cursor: help; padding: 0; margin-left: 4px; vertical-align: 1px;
  opacity: .7; position: relative;
}
.info-btn::after { content: ""; position: absolute; inset: -9px; }  /* 38px tap area */
.info-btn:hover, .info-btn:focus { opacity: 1; color: var(--accent); }
.info-btn.demo-static { cursor: inherit; }
#info-popover {
  position: absolute; z-index: 60; max-width: 300px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 13px; font-size: 13px;
  box-shadow: var(--shadow); line-height: 1.45;
}
#info-popover .t { font-weight: 700; margin-bottom: 3px; }
#info-popover .why { color: var(--muted); margin-top: 5px; font-size: 12px; }

/* ---- plain-language summary ---- */
.plain-cards {
  display: grid; gap: 22px 28px; margin-top: 18px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.plain-cards .card .v { font-size: 24px; }
.plain-verdict {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700;
  padding: 5px 14px; border-radius: 999px; margin-top: 2px;
}
.plain-verdict.up { background: color-mix(in srgb, var(--up) 13%, transparent); color: var(--up); }
.plain-verdict.down { background: color-mix(in srgb, var(--down) 13%, transparent); color: var(--down); }
.plain-verdict.flat { background: color-mix(in srgb, var(--flat) 15%, transparent); color: var(--flat-ink); }
.plain-verdict.warn { background: var(--warn-bg); color: var(--warn-ink); }

.plain-story {
  margin-top: 16px; padding: 14px 18px;
  background: var(--panel); border: 0; border-radius: 12px;
}
.plain-story p { margin: 7px 0; font-size: 14.5px; }
.plain-story p:first-child { margin-top: 0; }
.plain-story p:last-child { margin-bottom: 0; }
.plain-note { margin-top: 12px; }
.ev-sentence { border-left: 3px solid var(--line); padding-left: 12px; }
.ev-window { color: var(--muted); font-size: 13px; }
.ev-caveat { color: var(--warn-ink); font-size: 12px; }

/* ---- glossary ---- */
.glossary {
  display: grid; grid-template-columns: max-content 1fr;
  gap: 10px 18px; margin-top: 14px; font-size: 13.5px;
  background: var(--panel); border: 0;
  border-radius: 12px; padding: 16px 20px;
}
.glossary dt { font-weight: 700; color: var(--accent); white-space: nowrap; }
.glossary dd { margin: 0; color: var(--ink); }
@media (max-width: 640px) {
  .glossary { grid-template-columns: 1fr; gap: 4px 0; }
  .glossary dd { margin-bottom: 8px; }
  /* let the search use the whole controls row (must come after the base min-width) */
  #instrument-search { min-width: 0; flex: 1 1 160px; }
}

/* ---- forecast ("what might happen next") ---- */
.fc-meta { margin-top: 14px; font-size: 13.5px; }
.fc-meta p { margin: 8px 0; max-width: 90ch; }
.fc-meta h3 { margin-top: 16px; }

/* ---- event-type filter chips ---- */
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
button.chip {
  position: relative;   /* for the expanded tap area below */
  font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--muted); background: transparent;
  border: 0; border-radius: 7px;
  padding: 6px 9px; cursor: pointer;
}
button.chip::after { content: ""; position: absolute; inset: -4px; }  /* ~44px tap area */
button.chip:hover { background: var(--panel); color: var(--ink); }
button.chip.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent); font-weight: 600;
}
button.chip.active .chip-n { color: inherit; opacity: .75; }
.chip-n { color: var(--muted); font-weight: 500; font-size: 12px; }
.link { background: none; border: none; padding: 0; cursor: pointer;
        color: var(--accent); font: inherit; font-weight: 700;
        text-decoration: underline dotted; }
.link:hover { text-decoration: underline solid; }

/* ---- events calendar ---- */
.cal-bar { display: flex; align-items: center; gap: 14px; margin-top: 10px;
           flex-wrap: wrap; }
.cal-nav { display: flex; gap: 4px; }
.cal-nav button { font: inherit; font-size: 13px; background: var(--panel);
                  border: 1px solid var(--line); border-radius: 8px;
                  padding: 8px 14px; min-width: 44px; min-height: 38px;
                  cursor: pointer; }
.cal-nav button:hover { border-color: var(--accent); }
.cal-month { font-weight: 700; font-size: 14.5px;
             font-variant-numeric: tabular-nums; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(64px, 1fr));
            gap: 4px; margin-top: 10px; overflow-x: auto; }
.cal-dow { font-size: 12px; font-weight: 700; text-transform: uppercase;
           letter-spacing: .05em; color: var(--muted); text-align: center;
           padding: 2px 0; }
.cal-dow.wkend { color: var(--dim); }
.cal-cell {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; min-height: 58px; padding: 4px 5px;
  display: flex; flex-direction: column; gap: 2px; align-items: stretch;
  cursor: pointer; overflow: hidden;
}
.cal-cell.empty { background: transparent; border-style: dashed;
                  cursor: default; min-height: 40px; }
.cal-cell.wkend { background: color-mix(in srgb, var(--muted) 7%, var(--panel)); }
.cal-cell.wkend .cal-date { color: var(--dim); }
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.today { border-color: var(--accent);
                  box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-cell.sel { outline: 2px solid var(--accent); }
.cal-date { font-size: 12px; font-weight: 700; color: var(--muted);
            font-variant-numeric: tabular-nums; }
.cal-cell.today .cal-date { color: var(--accent); }
.cal-ev {
  position: relative;                    /* expanded tap area below */
  font: inherit; font-size: 11px; font-weight: 600; text-align: left;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: none; border-radius: 5px; padding: 2px 6px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-ev::after { content: ""; position: absolute; inset: -7px -4px; }
.cal-ev:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
@media (max-width: 640px) {
  /* 44px-wide cells: drop the emoji so the ticker itself stays readable */
  .cal-ev .ev-ic { display: none; }
  .cal-ev { font-size: 10px; padding: 3px 3px; }
}
.cal-more { font: inherit; font-size: 11.5px; color: var(--muted);
            background: none; border: none; padding: 3px 2px;
            cursor: pointer; text-align: left; position: relative; }
.cal-more::after { content: ""; position: absolute; inset: -6px 0; }
.cal-more:hover { color: var(--accent); }
.cal-detail { margin-top: 12px; }
.cal-detail h3 { margin: 6px 0 8px; }
.cal-row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
           padding: 5px 2px; border-bottom: 1px solid var(--line);
           font-size: 13px; }
.cal-row:last-of-type { border-bottom: none; }
.cal-ic { flex: none; }
.cal-name { color: var(--muted); }
.cal-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-desc { font-size: 12.5px; color: var(--muted); padding: 0 2px 8px 26px; }

/* ---- explore / compare / trade planner ---- */

.explore-tools {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-top: 12px;
}
#explore-search { flex: 1 1 240px; max-width: 360px; }

.explore-scroll { max-height: 68vh; overflow: auto; }
.explore-scroll thead th {
  position: sticky; top: 0; z-index: 2;
  padding: 2px 4px;
  box-shadow: 0 1px 0 var(--line);
}
#explore-table th .sort-key {
  font: inherit; color: inherit; background: none; border: 0;
  display: block; width: 100%; text-align: left;
  text-transform: inherit; letter-spacing: inherit;
  font-weight: 600; padding: 6px 8px; border-radius: 6px;
  white-space: nowrap;
}
#explore-table th .sort-key:hover { color: var(--accent); }
.sort-ind { font-size: 10px; }
#explore-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 5%, var(--panel));
}
#explore-table .link, #watch-table .link {
  color: var(--ink); text-decoration: none;
}
#explore-table .link:hover, #watch-table .link:hover {
  color: var(--accent); text-decoration: underline dotted;
}
#explore-table .co-name {
  max-width: 230px; overflow: hidden; text-overflow: ellipsis;
}
.col-star, .col-cmp { text-align: center; }
.star {
  position: relative;                 /* expanded tap area below */
  background: none; border: none; padding: 4px;
  font-size: 16px; line-height: 1; color: var(--dim); cursor: pointer;
}
.star::after { content: ""; position: absolute; inset: -6px; }
.star.on { color: var(--star); }
.dot { font-size: 10px; vertical-align: 2px; }
.dot.fresh { color: var(--up); }
.dot.delayed { color: var(--warn-ink); }
.dot.stale { color: var(--dim); }

/* best-in-row highlighting (compare table + any ranked cell) */
td.best {
  background: color-mix(in srgb, var(--up) 10%, var(--panel));
  font-weight: 700;
}

.compare-bar {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-top: 12px;
}
#compare-add { min-width: 220px; }
.chip.pick {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 6px 8px 6px 12px;
}
.chip.pick .rm {
  position: relative; background: none; border: none;
  font-size: 14px; line-height: 1; padding: 2px 5px;
  color: var(--muted); cursor: pointer;
}
.chip.pick .rm::after { content: ""; position: absolute; inset: -8px; }
.chip.pick .rm:hover { color: var(--down); }
#watchlist-quick { margin-top: 10px; align-items: baseline; }
#watchlist-quick .chip { cursor: pointer; }

.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
  flex: none;
}

.trade-inputs {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
  margin-top: 14px; padding: 14px 16px;
  background: var(--panel); border: 0; border-radius: 12px;
}
.trade-inputs label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.trade-inputs input { width: 118px; }
.trade-inputs .mini-btn { margin-bottom: 3px; }
#trade-table tr.divider td {
  font-size: 12px; color: var(--muted); white-space: normal;
  background: color-mix(in srgb, var(--line) 25%, var(--panel));
}

/* ---- collapsible "more" disclosures: long text hides until asked ---- */
details.more {
  margin-top: 10px; font-size: 12.5px; color: var(--muted);
  max-width: 78ch;
}
details.more summary {
  cursor: pointer; color: var(--muted); font-weight: 600;
  font-size: 12.5px; user-select: none;
}
details.more summary:hover { color: var(--ink); }
details.more summary::marker { color: var(--muted); }
details.more[open] summary { margin-bottom: 4px; }
details.more p { margin: 6px 0; }
details.more p:first-of-type { margin-top: 2px; }
details.more p:last-of-type { margin-bottom: 0; }
.glossary-wrap .glossary { margin-top: 12px; }


/* ---- newcomer info: one collapsed guide under each section ---- */
.section-info { margin-top: 12px; }
.section-info summary { letter-spacing: .01em; }
.info-terms {
  margin: 8px 0 0;
  display: grid; grid-template-columns: max-content 1fr;
  gap: 4px 12px;
}
.info-terms dt { color: var(--ink); font-weight: 600; }
.info-terms dd { margin: 0; }

/* ---- floating AI chat ---- */
.ai-open {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); font-weight: 600;
  box-shadow: var(--shadow);
}
.ai-open:hover { color: var(--accent); border-color: var(--accent); }
.static .ai-open, .static .ai-chat { display: none !important; }
.ai-chat {
  position: fixed; right: 22px; bottom: 22px; z-index: 41;
  width: min(390px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 44px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.38);
  overflow: hidden;
}
.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 13px; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 14px;
}
.ai-head button { background: none; border: 0; font-size: 20px; line-height: 1;
  color: var(--muted); padding: 0 4px; }
.ai-messages { flex: 1; overflow-y: auto; padding: 12px 13px; display: grid;
  gap: 9px; align-content: start; }
.ai-msg { max-width: 92%; padding: 8px 11px; border-radius: 10px;
  font-size: 13px; line-height: 1.45; white-space: pre-wrap;
  overflow-wrap: anywhere; }
.ai-msg.user { justify-self: end; background: var(--accent); color: var(--on-accent); }
.ai-msg.bot { justify-self: start; background: var(--bg); border: 1px solid var(--line); }
.ai-status { padding: 0 13px 4px; min-height: 14px; }
.ai-form { display: flex; gap: 7px; padding: 8px 10px; border-top: 1px solid var(--line); }
.ai-form input { flex: 1; min-width: 0; }
.ai-note { margin: 0 13px 9px; }
.ai-head-btns { display: inline-flex; align-items: center; gap: 6px; }

/* ---- settings panel: browser-local configuration ---- */
.settings-backdrop {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(10, 12, 20, .38);
}
.settings-modal {
  position: fixed; inset: 0; z-index: 46; margin: auto;
  width: min(480px, calc(100vw - 28px));
  max-height: min(680px, calc(100vh - 44px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 18px 60px rgba(0,0,0,.45);
  overflow: hidden;
}
.settings-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.settings-body > p { margin: 2px 0 10px; }
.settings-modal fieldset {
  border: 1px solid var(--line); border-radius: 10px;
  margin: 0 0 12px; padding: 10px 12px 12px;
}
.settings-modal legend {
  font-weight: 600; font-size: 13px; padding: 0 6px;
  color: var(--accent);
}
.set-row {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; font-weight: 600; margin: 9px 0 0;
}
.set-row input, .set-row textarea, .set-row select {
  font: inherit; font-weight: 400; color: var(--ink); font-size: 16px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
.set-row textarea { resize: vertical; min-height: 58px; }
.set-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; margin: 11px 0 0; cursor: pointer;
}
.set-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.set-grid .set-row:last-child { grid-column: 1 / -1; }
.settings-body .s.muted { margin: 8px 0 0; }
.settings-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line);
}
#settings-save {
  background: var(--accent); color: var(--on-accent);
  border-color: var(--accent); font-weight: 600; padding: 8px 22px;
}
#settings-save:hover { filter: brightness(1.08); }

.hidden { display: none !important; }

/* ---- mobile: must stay last so it wins equal-specificity cascades ---- */
@media (max-width: 640px) {
  .trade-inputs label { flex: 1 1 44%; }
  .trade-inputs input { width: 100%; }
  #compare-add { min-width: 0; flex: 1 1 160px; }
  #explore-search { max-width: none; }
  .info-terms { grid-template-columns: 1fr; gap: 2px 0; }
  .info-terms dd { margin-bottom: 7px; }
  .ai-open { right: 14px; bottom: 14px; }
  .ai-chat { right: 14px; bottom: 14px; max-height: calc(100vh - 28px); }
  #explore-table .co-name { max-width: 140px; }
}

/* ================================================================
   APP SHELL — sidebar navigation + one focused section at a time.
   All existing element IDs / view + mode classes stay intact; this
   block only adds layout and section visibility on top of them.
   ================================================================ */
:root {
  --side-bg: var(--bg);
  --side-ink: var(--ink);
  --side-muted: var(--muted);
  --side-line: var(--line);
  --side-hover: color-mix(in srgb, var(--accent) 6%, var(--bg));
}

.app-shell { min-height: 100vh; }

/* ---- sidebar ---- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  width: 224px; display: flex; flex-direction: column;
  background: var(--side-bg); color: var(--side-ink);
  border-right: 1px solid var(--side-line);
  overflow-y: auto; scrollbar-width: thin;
}
.side-brand {
  display: flex; gap: 10px; align-items: center;
  padding: 16px 14px; border-bottom: 1px solid var(--side-line);
}
.side-brand .logo { font-size: 21px; }
.side-brand strong { display: block; font-size: 14px; letter-spacing: -.01em; }
.side-brand > div > span { display: block; font-size: 10.5px; color: var(--side-muted); }
.side-current {
  margin: 14px 16px 6px; padding: 0;
  background: none; border: 0;
}
.side-current-label {
  display: block; font-size: 9.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em; color: var(--side-muted);
}
.side-current strong { display: block; font-size: 17px; margin-top: 2px; }
.side-current-name { display: block; font-size: 11px; line-height: 1.35; color: var(--side-muted); }
.side-nav { display: flex; flex-direction: column; gap: 1px; padding: 4px 10px 16px; }
.nav-group {
  margin: 15px 12px 4px; font-size: 9.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; color: var(--side-muted);
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 36px; padding: 7px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--side-ink);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--side-hover); }
.nav-item.active {
  background: transparent; color: var(--ink);
  font-weight: 700;
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-ic { width: 18px; flex: none; text-align: center; font-size: 13px; color: var(--side-muted); }
.nav-item.active .nav-ic { color: var(--accent); }
.side-foot {
  margin-top: auto; padding: 14px 16px; font-size: 10.5px;
  color: var(--side-muted); border-top: 1px solid var(--side-line);
}
/* sections with no content in the active mode are not navigable */
body.mode-detailed .nav-item[data-section="glossary"] { display: none; }

/* ---- main column ---- */
.app-main { margin-left: 224px; min-width: 0; }
.topbar { padding: 10px 28px; gap: 12px; }
.topbar-brand { display: none; align-items: center; gap: 10px; }
.topbar-brand strong { display: block; font-size: 14px; }
.topbar-brand > div > span { display: block; font-size: 11.5px; color: var(--muted); }
.controls { flex: 1 1 auto; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
#instrument-combo { flex: 1 1 260px; max-width: 420px; }
#instrument-search { width: 100%; }
.control-actions {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; justify-content: flex-end;
}

/* topbar secondary actions are ghost buttons; only Update data is solid */
.topbar #mode-toggle, .topbar #lang-toggle, .topbar #open-settings {
  border-color: transparent; background: transparent; color: var(--muted);
  font-weight: 500;
}
.topbar #mode-toggle:hover, .topbar #lang-toggle:hover,
.topbar #open-settings:hover {
  background: var(--panel); border-color: var(--line); color: var(--ink);
}

main { max-width: 1240px; padding: 34px 36px 64px; }
.page { display: none; }
body.section-overview    .page[data-section="overview"],
body.section-price       .page[data-section="price"],
body.section-performance .page[data-section="performance"],
body.section-events      .page[data-section="events"],
body.section-forecast    .page[data-section="forecast"],
body.section-planner     .page[data-section="planner"],
body.section-calendar    .page[data-section="calendar"],
body.section-explore     .page[data-section="explore"],
body.section-watchlist   .page[data-section="watchlist"],
body.section-compare     .page[data-section="compare"],
body.section-sources     .page[data-section="sources"],
body.section-glossary    .page[data-section="glossary"] { display: block; }

.page-head {
  padding-bottom: 2px; margin-bottom: 30px;
  scroll-margin-top: 82px;
}
.eyebrow {
  margin: 0 0 8px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
.page-title {
  margin: 0; font-size: 34px; line-height: 1.15; letter-spacing: -.01em;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
.page-sub { margin: 9px 0 0; font-size: 14px; color: var(--muted); max-width: 78ch; }
.page > section { margin-top: 0; scroll-margin-top: 82px; }
.page > section + section { margin-top: 36px; }

/* slightly roomier surfaces for the sectioned layout */
.chart-wrap { min-height: 440px; }
.section-head { margin-bottom: 6px; gap: 14px; }
.section-head h2 { font-size: 18px; }
.caption { font-size: 12px; }

/* ---- responsive: sidebar becomes a horizontal section bar ---- */
@media (max-width: 900px) {
  .sidebar { position: static; inset: auto; width: auto; height: auto; flex-direction: column; overflow: visible; }
  .side-brand { padding: 12px 16px; }
  .side-current, .nav-group, .side-foot { display: none; }
  .side-nav {
    flex-direction: row; overflow-x: auto; gap: 4px;
    padding: 8px 12px; scrollbar-width: thin;
  }
  .nav-item { width: auto; flex: none; min-height: 38px; white-space: nowrap; padding: 8px 12px; }
  .app-main { margin-left: 0; }
  .topbar-brand { display: flex; }
  .topbar { padding: 10px 16px; }
  main { padding: 20px 16px 44px; }
}
@media (max-width: 640px) {
  .topbar { padding: 9px 12px; gap: 8px; }
  .topbar-brand { display: none; }
  .controls { gap: 7px; }
  .control-actions { gap: 7px; }
  #instrument-combo { flex: 1 1 140px; }
  #instrument-search { min-width: 0; }
  .page-head { padding-bottom: 14px; margin-bottom: 18px; }
  .page-title { font-size: 24px; }
  .page-sub { font-size: 13px; }
}

/* ---- data health (session gaps + quality issues) ---- */
.card .v.up { color: var(--up); }
.card .v.down { color: var(--down); }
.card .v.warn { color: var(--warn-ink); }
.warn-text { color: var(--warn-ink); font-weight: 600; }
.health-summary { margin-top: 14px; }
.health-panel {
  max-width: 80ch; padding: 16px 18px;
  background: var(--panel); border: 0;
  border-radius: 12px;
}
.health-panel p { margin: 8px 0 10px; font-size: 13px; color: var(--muted); }
.health-issue {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: 12.5px;
}
.health-issue .s { flex: none; }
#explore-health .info-btn { margin-left: 2px; }

/* ---- dividend record + event grouping ---- */
.event-year {
  margin: 18px 0 6px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em; color: var(--muted);
}
.divhist-panel {
  margin-top: 14px; padding: 16px;
  background: var(--panel); border: 0;
  border-radius: 12px;
}
.divhist-summary { margin: 0 0 14px; gap: 6px 22px; }
.divhist-summary .chip {
  background: transparent; border: 0; border-radius: 0; padding: 4px 0;
}
.divhist-table { margin-top: 10px; }
.divhist-panel h3 { margin: 18px 0 6px; }
.cycle-list { margin: 6px 0 0; padding-left: 20px; font-size: 13px; line-height: 1.6; }

/* ---- watchlist ---- */
.watch-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.file-btn { cursor: pointer; }
.watch-changes { font-size: 12px; line-height: 1.45; white-space: normal; min-width: 190px; }
#watch-table .col-name { max-width: 220px; }

/* ---- one-page research note: screen-hidden, print-only ---- */
.print-only { display: none; }
.print-btn {
  margin: 10px 0 0; padding: 0; border: 0; background: transparent;
  color: var(--muted); font-weight: 500;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.print-btn:hover { color: var(--accent); border-color: transparent; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .sidebar, .topbar, .banner, .fatal, main, footer, #info-popover {
    display: none !important;
  }
  .app-main { margin: 0; }
  .print-only { display: block !important; }
  #research-note h1 { font-size: 20pt; margin: 0 0 4pt; }
  #research-note h1 span { font-size: 12pt; color: #444; font-weight: 400; }
  .note-meta { color: #444; margin: 0 0 12pt; font-size: 9pt; }
  .note-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10pt; }
  #research-note h2 {
    font-size: 11pt; margin: 12pt 0 4pt; padding-bottom: 2pt;
    border-bottom: 1px solid #bbb;
  }
  #research-note table { width: 100%; border: 0; font-size: 9pt; }
  #research-note th, #research-note td {
    border: 0; border-bottom: 1px solid #ddd; padding: 3pt 4pt;
    text-align: left; white-space: normal;
  }
  #research-note th {
    width: 38%; color: #444; font-weight: 600; text-transform: none;
    background: none; font-size: 9pt;
  }
  #research-note p, #research-note li { font-size: 9pt; line-height: 1.35; }
  .note-caveat { color: #444; }
}
