/* Glassmorphism + RGB theme.
 *
 * - Dark navy base, large blurred colour blobs bleed through frosted glass.
 * - Accent colours follow Taiwan market convention: 紅漲綠跌 (red = up,
 *   green = down). The semantic CSS vars (`--inc`/`--dec`) carry the
 *   role; the underlying RGB triplets are swapped to honour TW custom.
 * - Backdrop blur is the only effect that actually requires modern browser
 *   support; the rest degrades cleanly on older engines.
 */

:root {
  /* Base palette */
  --bg-base: #07091a;
  --fg: #e9ecff;
  --muted: rgba(233, 236, 255, 0.55);
  --border-soft: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.14);

  /* Glass surfaces */
  --glass-bg: rgba(20, 23, 50, 0.42);
  --glass-bg-strong: rgba(28, 32, 65, 0.55);
  --glass-highlight: rgba(255, 255, 255, 0.07);

  /* Accent RGB — used for the four change types.
   *
   * Taiwan market convention: 紅漲綠跌 (red = up, green = down) — opposite
   * of the West. Variable names map to ROLE not literal colour: `--rgb-r`
   * is the "decrease" hue (now green), `--rgb-g` is the "increase" hue
   * (now red). Swap is contained here; nothing else in the stylesheet
   * needs to know.
   */
  --rgb-r: 51, 255, 168;     /* DECREASE — neon green (TW: 跌) */
  --rgb-g: 255, 64, 129;     /* INCREASE — hot pink (TW: 漲) */
  --rgb-b: 92, 195, 255;     /* NEW */
  --rgb-v: 196, 121, 255;    /* REMOVED */

  --new: rgb(var(--rgb-b));
  --inc: rgb(var(--rgb-g));
  --dec: rgb(var(--rgb-r));
  --rem: rgb(var(--rgb-v));

  --warn-bg: rgba(255, 213, 79, 0.12);
  --warn-fg: #ffe082;
  --warn-border: rgba(255, 213, 79, 0.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  color: var(--fg);
  background: var(--bg-base);
  line-height: 1.55;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* The RGB blobs. Three large radial gradients fixed to the viewport so the
 * background stays alive while the page scrolls. `filter: blur` is overkill
 * here (radial-gradient is already soft) but it adds the dreamy halo. */
body::before {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -1;
  background:
    radial-gradient(45% 55% at 12% 22%, rgba(var(--rgb-r), 0.38), transparent 60%),
    radial-gradient(50% 60% at 88% 18%, rgba(var(--rgb-g), 0.32), transparent 62%),
    radial-gradient(60% 70% at 50% 95%, rgba(var(--rgb-b), 0.42), transparent 65%),
    radial-gradient(40% 50% at 70% 55%, rgba(var(--rgb-v), 0.22), transparent 60%);
  filter: blur(60px) saturate(115%);
  animation: blob-drift 28s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes blob-drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(2%, -3%, 0) scale(1.04); }
  100% { transform: translate3d(-2%, 2%, 0) scale(0.97); }
}

/* ---- Header / nav ---- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}
header .brand {
  font-weight: 700;
  text-decoration: none;
  font-size: 1.05rem;
  background: linear-gradient(90deg,
    rgb(var(--rgb-r)) 0%,
    rgb(var(--rgb-g)) 50%,
    rgb(var(--rgb-b)) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header nav a {
  margin-left: 18px;
  color: var(--fg);
  text-decoration: none;
  opacity: 0.78;
  transition: opacity 0.15s ease, color 0.15s ease;
}
header nav a:hover {
  opacity: 1;
  color: rgb(var(--rgb-b));
}

main { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; }
footer { padding: 32px 24px; text-align: center; color: var(--muted); font-size: 0.85rem; }
footer small { display: block; margin: 2px 0; }
footer .footer-legal { margin-top: 10px; font-size: 0.82rem; }
footer .footer-legal a { color: var(--muted); }
footer .footer-legal a:hover { color: var(--fg); }

/* ---- Legal pages (免責聲明 / 使用條款 / 隱私權政策) ---- */
.legal-page h1 { margin: 0 0 4px; }
.legal-page > .muted { margin: 0 0 24px; font-size: 0.86rem; }
.legal-body { line-height: 1.75; font-size: 0.96rem; }
.legal-body h2 {
  margin-top: 28px;
  margin-bottom: 8px;
  font-size: 1.1rem;
  color: var(--fg);
  border-left: 3px solid var(--inc);
  padding-left: 10px;
}
.legal-body p { margin: 8px 0; color: var(--fg); }
.legal-body ul { margin: 6px 0 12px; padding-left: 24px; }
.legal-body li { margin: 4px 0; color: var(--fg); }
.legal-body hr {
  margin: 28px 0 16px;
  border: 0;
  border-top: 1px solid var(--border-soft);
}
.legal-body code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.legal-nav { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border-soft); font-size: 0.9rem; }
.legal-nav a { color: var(--muted); margin: 0 4px; }
.legal-nav a:hover { color: var(--fg); }

/* ---- Sections (glass cards) ---- */

main > section {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 28px;
  margin-bottom: 22px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 12px 32px rgba(0, 0, 0, 0.35);
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg,
    rgb(var(--rgb-r)) 0%,
    rgb(var(--rgb-g)) 55%,
    rgb(var(--rgb-b)) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.muted { color: var(--muted); }

.warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--warn-border);
}

code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.88em;
  border: 1px solid var(--border-soft);
  color: rgb(var(--rgb-g));
}

a { color: rgb(var(--rgb-b)); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-color: rgba(var(--rgb-b), 0.6); }

/* ---- Tables ---- */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 12px 0 8px;
  font-size: 14px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.18);
}
th, td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
}
th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: none;
  color: rgba(233, 236, 255, 0.85);
}
tr:last-child td { border-bottom: none; }
tbody tr {
  transition: background 0.15s ease;
}
tbody tr:hover {
  background: rgba(var(--rgb-b), 0.07);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* RGB-coloured class accents (NEW / INCREASE / DECREASE / REMOVED).
 * The slight text-shadow gives the neon feel without hurting legibility. */
.new, td.num.new, th.num.new, h3.new {
  color: var(--new);
  text-shadow: 0 0 10px rgba(var(--rgb-b), 0.45);
}
.inc, td.num.inc, th.num.inc, h3.inc {
  color: var(--inc);
  text-shadow: 0 0 10px rgba(var(--rgb-g), 0.45);
}
.dec, td.num.dec, th.num.dec, h3.dec {
  color: var(--dec);
  text-shadow: 0 0 10px rgba(var(--rgb-r), 0.45);
}
.rem, td.num.rem, th.num.rem, h3.rem {
  color: var(--rem);
  text-shadow: 0 0 10px rgba(var(--rgb-v), 0.45);
}

/* ---- ETF list grid ---- */

.etf-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px 18px;
  margin: 0;
}
.etf-list li {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.etf-list li:hover {
  transform: translateY(-1px);
  border-color: rgba(var(--rgb-b), 0.45);
  background: rgba(var(--rgb-b), 0.06);
}
.etf-list a { font-weight: 600; }

/* ---- Date picker ---- */

.date-picker { margin-bottom: 18px; }
.date-picker label { color: var(--muted); }
.date-picker select,
.date-picker input[type="date"] {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--glass-bg-strong);
  color: var(--fg);
  font: inherit;
  margin-left: 6px;
  /* Native date input has its own height/baseline — normalize to match select. */
  line-height: 1.2;
  min-width: 150px;
  /* Hide the spinner / dropdown arrow webkit appendage for cleaner look. */
  -webkit-appearance: none;
     -moz-appearance: textfield;
}
.date-picker select:focus,
.date-picker input[type="date"]:focus {
  outline: 2px solid rgba(var(--rgb-b), 0.55);
  outline-offset: 1px;
}
.date-picker option {
  background: #14172e; /* native dropdowns inherit poorly; force readable bg */
  color: var(--fg);
}
/* Calendar icon for date input — invert to fit dark theme. */
.date-picker input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7) brightness(1.4);
  cursor: pointer;
  margin-left: 4px;
}
.hero-date-picker input[type="date"]::-webkit-calendar-picker-indicator,
.holdings-date input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7) brightness(1.4);
}

/* ---- Headings inside cards ---- */

h2 {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  font-size: 1.2rem;
  letter-spacing: 0.4px;
}
h3 { margin: 22px 0 10px; font-size: 1rem; letter-spacing: 0.3px; }

/* Section dividers between cards already come from the gap between
 * glass surfaces, so we kill the old border-top on h2. */

/* ---- Capital flow ranking ---- */

.flow-rank tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* #1 leader gets a neon highlight matching its kind (inc / dec).
 * Box-shadow renders inside the row via inset; outer glow on the tr is
 * clipped by the table's overflow:hidden, so we use a strong inset. */
.flow-rank tr.rank-leader.in {
  background: linear-gradient(
    90deg,
    rgba(var(--rgb-g), 0.18),
    rgba(var(--rgb-g), 0.06) 60%,
    transparent
  );
  box-shadow:
    inset 4px 0 0 rgb(var(--rgb-g)),
    inset 0 0 24px rgba(var(--rgb-g), 0.25);
}
.flow-rank tr.rank-leader.in td:first-of-type + td strong {
  text-shadow: 0 0 14px rgba(var(--rgb-g), 0.55);
}

.flow-rank tr.rank-leader.out {
  background: linear-gradient(
    90deg,
    rgba(var(--rgb-r), 0.18),
    rgba(var(--rgb-r), 0.06) 60%,
    transparent
  );
  box-shadow:
    inset 4px 0 0 rgb(var(--rgb-r)),
    inset 0 0 24px rgba(var(--rgb-r), 0.25);
}
.flow-rank tr.rank-leader.out td:first-of-type + td strong {
  text-shadow: 0 0 14px rgba(var(--rgb-r), 0.55);
}

/* Crown / "1" badge in the leader's # cell — pure CSS, no extra markup. */
.flow-rank tr.rank-leader td:first-child {
  font-weight: 800;
  font-size: 1.05em;
  position: relative;
}
.flow-rank tr.rank-leader td:first-child::after {
  content: "👑";
  margin-left: 4px;
  filter: drop-shadow(0 0 6px rgba(255, 220, 100, 0.65));
}

/* Status pill */
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  border: 1px solid currentColor;
  background: rgba(255, 255, 255, 0.04);
}
.status-pill.inc { color: var(--inc); }
.status-pill.dec { color: var(--dec); }
.status-pill.mixed {
  color: var(--rem);
  border-color: rgba(var(--rgb-v), 0.6);
}

/* ---- Chart cards (Chart.js wrapped in glass) ---- */

.chart-card .chart-wrap {
  position: relative;
  height: 320px;
  margin-top: 12px;
}
@media (max-width: 700px) {
  .chart-card .chart-wrap { height: 240px; }
}

/* ---- Stock detail: news list ---- */

.news-card h2 .muted { font-size: 0.7em; font-weight: 400; }

.news-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 10px;
}
.news-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 14px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.news-item:hover {
  transform: translateY(-1px);
  border-color: rgba(var(--rgb-b), 0.5);
  background: rgba(var(--rgb-b), 0.05);
}
.news-item a {
  display: block;
  color: var(--fg);
  font-weight: 500;
  line-height: 1.45;
  text-decoration: none;
}
.news-item a:hover {
  color: rgb(var(--rgb-b));
  text-decoration: underline;
  text-decoration-color: rgba(var(--rgb-b), 0.6);
}
.news-meta {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.news-source { font-weight: 600; color: rgba(233, 236, 255, 0.75); }

/* ---- Stock detail: market metric cards ---- */

.market-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-top: 12px;
}
@media (max-width: 900px) {
  .market-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) {
  .market-grid { grid-template-columns: repeat(2, 1fr); }
}
.metric {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}
.metric-label {
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.3px;
  margin-bottom: 4px;
  white-space: nowrap;
}
.metric-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- ETF detail: NAV / 市價 / 溢價 + 警示 ---- */
.premium-bar {
  margin: 12px 0 8px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
}
.premium-bar.premium-warn {
  background: rgba(255, 196, 0, 0.08);
  border-color: rgba(255, 196, 0, 0.45);
}
.premium-bar.premium-danger {
  background: rgba(255, 80, 80, 0.10);
  border-color: rgba(255, 80, 80, 0.55);
}
.premium-bar.premium-discount {
  background: rgba(80, 200, 120, 0.08);
  border-color: rgba(80, 200, 120, 0.40);
}
.premium-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.premium-label {
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.premium-value {
  font-size: 1.3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.premium-warn-msg {
  margin-top: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 230, 200, 0.92);
}
.premium-bar.premium-danger .premium-warn-msg {
  color: rgba(255, 220, 220, 0.96);
  background: rgba(120, 0, 0, 0.30);
}
.premium-bar.premium-discount .premium-warn-msg {
  color: rgba(220, 255, 230, 0.92);
  background: rgba(0, 60, 30, 0.30);
}

/* Inline summary above the holders table */
.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-bottom: 12px;
  font-size: 0.92rem;
  color: var(--muted);
}
.totals strong {
  color: var(--fg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* History table: tint the 動作 cell by action class */
.action-new      { color: var(--new); font-weight: 600; }
.action-increase { color: var(--inc); font-weight: 600; }
.action-decrease { color: var(--dec); font-weight: 600; }
.action-removed  { color: var(--rem); font-weight: 600; }

/* ----- ETF 建倉紀錄 (stock detail trade section) ----- */
.trade-section .trade-block {
  margin-top: 18px;
}
.trade-section .trade-block:first-of-type {
  margin-top: 8px;
}
.trade-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  margin-bottom: 8px;
}
.trade-block-head h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}
.trade-block-sum {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.trade-block-sum strong {
  font-weight: 700;
}
/* Primary trade row (open + closed tables) — click to expand drawer.
 * Mirrors the .flow-row pattern on /flow but a cell-prepended caret instead
 * of a trailing one, since trade tables don't have a "參與 ETF" cell. */
.trade-row {
  cursor: pointer;
  transition: background 0.15s;
}
.trade-row:hover {
  background: rgba(var(--rgb-b), 0.07);
}
.trade-row.is-open {
  background: rgba(var(--rgb-b), 0.10);
}
.trade-caret {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.85em;
  color: var(--muted);
  transition: transform 0.15s, color 0.15s;
}
.trade-row.is-open .trade-caret {
  transform: rotate(90deg);
  color: var(--fg);
}

/* Highlight ETF rows whose holdings on this stock changed in the latest
 * published basket. Subtle inset border on the left + warmer hover tint —
 * the visual cue should read "fresh activity" without competing with the
 * inc/dec coloring on the P&L cells. Applies to:
 *   - .trade-row (trade-table rows, open + closed)
 *   - plain <tr> in 持股總覽 (no .trade-row class — fall through to generic
 *     .has-today-change selector below) */
.trade-row.has-today-change,
tr.has-today-change {
  background: linear-gradient(90deg, rgba(var(--rgb-g), 0.16) 0%, rgba(var(--rgb-g), 0.04) 24%, transparent 60%);
  box-shadow: inset 3px 0 0 var(--inc);
}
.trade-row.has-today-change:hover,
tr.has-today-change:hover {
  background: linear-gradient(90deg, rgba(var(--rgb-g), 0.22) 0%, rgba(var(--rgb-g), 0.07) 24%, transparent 60%);
}
.trade-row.has-today-change.is-open {
  background: linear-gradient(90deg, rgba(var(--rgb-g), 0.24) 0%, rgba(var(--rgb-g), 0.09) 24%, transparent 60%);
}
.today-change-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--inc);
  background: rgba(var(--rgb-g), 0.14);
  border: 1px solid rgba(var(--rgb-g), 0.35);
  border-radius: 10px;
  vertical-align: middle;
  letter-spacing: 0.04em;
}

/* Drawer row: full-width cell holding the per-day events table. */
.trade-detail > td {
  padding: 14px 18px;
  background: rgba(0, 0, 0, 0.18);
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}
.trade-events-head {
  font-size: 0.88rem;
  margin-bottom: 8px;
}
.trade-events-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.trade-events-table th,
.trade-events-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.trade-events-table thead th {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.trade-events-table thead th.num,
.trade-events-table tbody td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.trade-events-table tbody tr:last-child td {
  border-bottom: none;
}
.trade-events-empty {
  padding: 8px 0;
}

/* ---- Home: today-active ETF cards ---- */

.active-grid {
  display: grid;
  /* 200px min lets 5 cards fit per row inside the section's content width
   * (~1096px on desktop). Drops gracefully to 4/3/2/1 on narrower screens
   * via auto-fill. */
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.active-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 14px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.active-card:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--rgb-b), 0.55);
  background: rgba(var(--rgb-b), 0.06);
}
.active-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.active-ticker { font-size: 1.05rem; font-weight: 700; }
.active-total {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.active-name {
  font-size: 0.95rem;
  margin-top: 2px;
  /* Allow long fund names to wrap; the card grows to fit. */
}
.active-issuer, .active-meta { font-size: 0.78rem; margin-top: 2px; }
.active-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.lag-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  color: rgb(var(--rgb-v));
  border: 1px solid rgba(var(--rgb-v), 0.55);
  background: rgba(var(--rgb-v), 0.08);
}
.lag-badge.ahead {
  color: rgb(var(--rgb-g));
  border-color: rgba(var(--rgb-g), 0.55);
  background: rgba(var(--rgb-g), 0.08);
}
.active-stats {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.active-stats .stat {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.2);
  letter-spacing: 0.5px;
}
.active-stats .stat.new { color: var(--new); }
.active-stats .stat.inc { color: var(--inc); }
.active-stats .stat.dec { color: var(--dec); }
.active-stats .stat.rem { color: var(--rem); }

/* Top-rank highlight for the leader card on the home page inflow preview. */
.active-card.rank-leader-card {
  border-color: rgba(var(--rgb-g), 0.55);
  background:
    linear-gradient(135deg, rgba(var(--rgb-g), 0.14), transparent 70%),
    rgba(255, 255, 255, 0.04);
  box-shadow: 0 0 18px rgba(var(--rgb-g), 0.20);
}
.active-card.rank-leader-card .active-ticker {
  text-shadow: 0 0 10px rgba(var(--rgb-g), 0.55);
}
.active-total.inc { color: var(--inc); font-weight: 700; font-size: 0.85rem; }

/* ---- Home: tracked ETFs ranked by 1m perf ---- */

.perf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.perf-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 14px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.perf-card:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--rgb-b), 0.55);
  background: rgba(var(--rgb-b), 0.06);
}
.perf-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.perf-ticker { font-size: 1.05rem; font-weight: 700; }
.perf-1m {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}
.perf-name { font-size: 0.95rem; margin-top: 2px; }
.perf-meta { font-size: 0.78rem; margin-top: 4px; }

.more-etfs {
  margin-top: 14px;
}
.more-etfs > summary {
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
  list-style: none;
  font-weight: 600;
  color: rgba(var(--rgb-b), 1);
  width: fit-content;
}
.more-etfs > summary::-webkit-details-marker { display: none; }
.more-etfs > summary:hover {
  background: rgba(var(--rgb-b), 0.10);
  border-color: rgba(var(--rgb-b), 0.5);
}
.more-etfs > summary::after {
  content: " ▾";
  font-size: 0.85em;
}
.more-etfs[open] > summary::after { content: " ▴"; }
.more-etfs[open] > summary { margin-bottom: 12px; }

/* ---- Signals page (consensus radar cards) ---- */

.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.signal-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.signal-card.buy {
  border-color: rgba(var(--rgb-g), 0.35);
  background:
    linear-gradient(135deg, rgba(var(--rgb-g), 0.10), transparent 70%),
    rgba(255, 255, 255, 0.04);
}
.signal-card.sell {
  border-color: rgba(var(--rgb-r), 0.35);
  background:
    linear-gradient(135deg, rgba(var(--rgb-r), 0.10), transparent 70%),
    rgba(255, 255, 255, 0.04);
}
.signal-card:hover {
  transform: translateY(-2px);
}
.signal-card.buy:hover  { border-color: rgb(var(--rgb-g)); }
.signal-card.sell:hover { border-color: rgb(var(--rgb-r)); }

.signal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.signal-stock { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.signal-code { font-size: 1.05rem; font-weight: 700; }

.signal-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.signal-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.2);
}
.signal-badge.buy  { color: var(--inc); }
.signal-badge.sell { color: var(--dec); }
.signal-badge.days { color: rgb(var(--rgb-v)); border-color: rgba(var(--rgb-v), 0.6); }

.signal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.signal-shares {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.signal-shares.buy  { color: var(--inc); text-shadow: 0 0 10px rgba(var(--rgb-g), 0.45); }
.signal-shares.sell { color: var(--dec); text-shadow: 0 0 10px rgba(var(--rgb-r), 0.45); }

.signal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.signal-chip {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  color: var(--fg);
  text-decoration: none;
}
.signal-chip:hover {
  background: rgba(var(--rgb-b), 0.18);
  border-color: rgba(var(--rgb-b), 0.55);
  text-decoration: none;
}

/* ---- Compare page ---- */

.compare-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}
.compare-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.compare-picker select {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--glass-bg-strong);
  color: var(--fg);
  font: inherit;
  min-width: 280px;
}
.compare-picker option {
  background: #14172e;
  color: var(--fg);
}
.compare-picker .vs {
  color: var(--muted);
  font-style: italic;
  letter-spacing: 1px;
}
.compare-picker button {
  padding: 8px 22px;
  border-radius: 8px;
  border: 1px solid rgba(var(--rgb-b), 0.55);
  background: rgba(var(--rgb-b), 0.18);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.compare-picker button:hover {
  background: rgba(var(--rgb-b), 0.32);
}
.compare-picker button:active { transform: translateY(1px); }

.summary-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
}
.summary-half {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 14px 18px;
}
.summary-vs {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 2px;
  text-align: center;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
@media (max-width: 900px) {
  .compare-grid { grid-template-columns: 1fr; }
  .summary-pair { grid-template-columns: 1fr; }
}

/* ---- Clickable rows / list items (whole-card click target) ---- */
tr.clickable, li.clickable { cursor: pointer; }
tr.clickable:hover { background: rgba(var(--rgb-b), 0.10); }
li.clickable:hover {
  /* the existing .etf-list li:hover already shifts + tints, this is a no-op
   * placeholder to keep the rule local to clickability if .etf-list ever
   * gets a non-clickable variant. */
}

/* ---- Admin (/admin/etfs) ---- */

.admin-flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin: 10px 0;
  font-weight: 500;
  border: 1px solid;
}
.admin-flash.ok  { color: var(--inc); border-color: rgba(var(--rgb-g), 0.5); background: rgba(var(--rgb-g), 0.10); }
.admin-flash.err { color: var(--dec); border-color: rgba(var(--rgb-r), 0.5); background: rgba(var(--rgb-r), 0.10); }

.btn-primary, .btn-secondary {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border);
  margin-right: 6px;
}
.btn-primary {
  background: rgba(var(--rgb-b), 0.20);
  color: var(--fg);
  border-color: rgba(var(--rgb-b), 0.55);
}
.btn-primary:hover { background: rgba(var(--rgb-b), 0.32); }
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.10); }

.btn-link {
  background: none;
  border: none;
  color: rgb(var(--rgb-b));
  cursor: pointer;
  font: inherit;
  padding: 2px 6px;
  margin: 0 2px;
  border-radius: 4px;
}
.btn-link:hover:not(:disabled) { background: rgba(var(--rgb-b), 0.10); }
.btn-link:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-link.danger { color: var(--dec); }
.btn-link.danger:hover { background: rgba(var(--rgb-r), 0.10); }

.admin-table { width: 100%; }
.admin-table .actions { white-space: nowrap; }
.admin-table tr.row-disabled { opacity: 0.45; }
.admin-table tr.row-disabled td:first-child { text-decoration: line-through; }

.toggle-btn {
  border: 1px solid currentColor;
  background: rgba(0,0,0,0.2);
  color: var(--inc);
  font-weight: 700;
  width: 32px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
}
.toggle-btn.off { color: var(--dec); }

/* Form */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 520px;
}
.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 500;
}
.admin-form label.radio,
.admin-form label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}
.admin-form input[type="text"],
.admin-form select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--glass-bg-strong);
  color: var(--fg);
  font: inherit;
}
.admin-form input[readonly] { opacity: 0.6; cursor: not-allowed; }
.admin-form select option { background: #14172e; color: var(--fg); }
.admin-form fieldset {
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px 14px;
}
.admin-form fieldset legend { padding: 0 8px; color: var(--muted); }
.admin-form .radios { display: flex; gap: 18px; }
.admin-form .hint { font-size: 0.78rem; }
.admin-form .form-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---- etfinfo dashboard ---- */
.etfinfo-hero {
  margin: 18px 0 28px;
  padding: 18px 22px;
  background: var(--glass-bg, rgba(255,255,255,.04));
  border: 1px solid var(--border-soft, rgba(255,255,255,.08));
  border-radius: 14px;
}
.etfinfo-hero-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  gap: 16px;
  flex-wrap: wrap;
}
.etfinfo-hero-head h1,
.etfinfo-hero-head h2 { margin: 0; }
.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.hero-stat {
  padding: 10px 14px;
  background: var(--glass-bg-strong, rgba(0,0,0,.18));
  border-radius: 10px;
  text-align: center;
}
.hero-stat-num {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
}
.hero-stat-num.inc { color: var(--inc, #ff6b6b); }
.hero-stat-num.dec { color: var(--dec, #4dabf7); }
.hero-stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
}

/* ---- Tabbed card (homepage) ----
 * Tab nav sits flush at the top of the same card as the body; active button
 * shares background with the body so they read as one continuous surface.
 */
main > section.tab-card { padding: 0; overflow: hidden; }
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px 0;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px 12px 0 0;
  position: relative;
  transition: color 0.15s, background 0.15s;
}
.tab-btn:hover { color: var(--fg); background: var(--glass-highlight); }
.tab-btn.is-active { color: var(--fg); background: var(--glass-bg); }
.tab-btn.is-active::after {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--inc), var(--new));
  border-radius: 2px;
}
.tab-btn:focus-visible { outline: 2px solid var(--inc); outline-offset: -4px; }
.tab-badge {
  min-width: 22px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  text-align: center;
  line-height: 1.4;
}
.tab-btn.is-active .tab-badge {
  background: rgba(var(--rgb-g), 0.18);
  border-color: rgba(var(--rgb-g), 0.4);
  color: var(--inc);
}
.tab-body { padding: 22px 28px 26px; }
.tab-pane[hidden] { display: none; }
.tab-pane-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border-soft);
}
.tab-pane-date {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: 0.3px;
}
.tab-pane-link {
  margin-left: auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.tab-pane-link:hover { color: var(--fg); }
.tab-empty { padding: 32px 4px; text-align: center; }
@media (max-width: 600px) {
  .tab-nav { padding: 4px 4px 0; }
  .tab-btn { padding: 10px 12px; font-size: 0.92rem; }
  .tab-body { padding: 16px 14px 20px; }
}

/* ---- Hero card layout (homepage top: title + live status + stats + footer) ---- */
.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px 24px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}
.hero-title h1 {
  margin: 0 0 4px;
}
.hero-sub {
  margin: 0;
  font-size: 0.88rem;
}
.hero-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.live-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--fg);
  background: rgba(var(--rgb-g), 0.12);
  border: 1px solid rgba(var(--rgb-g), 0.35);
  border-radius: 999px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--inc);
  box-shadow: 0 0 0 0 rgba(var(--rgb-g), 0.6);
  animation: status-pulse 2.2s ease-out infinite;
}
@keyframes status-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(var(--rgb-g), 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(var(--rgb-g), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--rgb-g), 0); }
}
.hero-status-link {
  font-size: 0.86rem;
  color: var(--muted);
  text-decoration: none;
}
.hero-status-link:hover { color: var(--fg); }
.hero-disclaimer {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--border-soft);
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

/* ---- Universal search (homepage hero) ---- */
.hero-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px auto 0;
  max-width: 640px;
  padding: 6px 8px 6px 16px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.hero-search:focus-within {
  border-color: rgba(var(--rgb-b), 0.6);
  box-shadow: 0 0 0 4px rgba(var(--rgb-b), 0.15);
}
.hero-search-label {
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  user-select: none;
}
.hero-search input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  background: transparent;
  border: 0;
  color: var(--fg);
  font: inherit;
  font-size: 0.98rem;
  outline: none;
  /* Strip native search styling so it blends into the pill */
  -webkit-appearance: none;
  appearance: none;
}
.hero-search input[type="search"]::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
.hero-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background:
    linear-gradient(45deg, transparent 45%, var(--muted) 45% 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--muted) 45% 55%, transparent 55%);
  cursor: pointer;
}
.hero-search button {
  padding: 8px 22px;
  background: linear-gradient(135deg, rgb(var(--rgb-b)), rgba(var(--rgb-b), 0.7));
  color: #fff;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.hero-search button:hover { filter: brightness(1.1); }
.hero-search button:active { transform: scale(0.97); }
.hero-nohit {
  margin: 12px auto 0;
  max-width: 640px;
  text-align: center;
  font-size: 0.88rem;
}
@media (max-width: 480px) {
  .hero-search { padding: 4px 6px 4px 12px; gap: 4px; }
  .hero-search input[type="search"] { padding: 9px 4px; font-size: 0.95rem; }
  .hero-search button { padding: 7px 14px; font-size: 0.9rem; }
}
@media (prefers-reduced-motion: reduce) {
  .status-dot { animation: none; }
}
@media (max-width: 600px) {
  .hero-top { align-items: flex-start; }
  .hero-status { align-items: flex-start; }
}

/* ---- ETF detail page: hero card layout ---- */
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.hero-action-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--fg);
  background: var(--glass-bg-strong);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.hero-action-link:hover {
  background: var(--glass-highlight);
  border-color: var(--border);
}
.perf-section { margin-top: 4px; }
.perf-section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.perf-section-head h2 { margin: 0; }
.perf-section-head .muted { font-size: 0.9rem; }

/* ---- Holdings tab-card toolbar (date picker top-right) ---- */
.holdings-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 28px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.holdings-toolbar-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.holdings-toolbar-title h2 { margin: 0; }
.holdings-date { margin: 0; }
.holdings-date select,
.holdings-date input[type="date"] {
  margin-left: 6px;
  padding: 6px 10px;
  background: var(--glass-bg-strong);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  min-width: 150px;
}
@media (max-width: 600px) {
  .holdings-toolbar { padding: 14px 14px 10px; }
}

/* ---- Flow page: hero stat sub-line + inline date picker ---- */
.hero-stat-sub {
  font-size: 0.72rem;
  margin-top: 4px;
  line-height: 1.3;
}
.hero-date-picker {
  margin: 0;
}
.hero-date-picker label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}
.hero-date-picker select,
.hero-date-picker input[type="date"] {
  padding: 4px 10px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--fg);
  background: var(--glass-bg-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 140px;
}

/* ---- Flow rank: expandable row + ETF chips drawer ---- */
.flow-row { cursor: pointer; transition: background 0.15s; }
.flow-row:hover { background: rgba(var(--rgb-b), 0.07); }
.flow-row.is-open { background: rgba(var(--rgb-b), 0.10); }
.flow-row .flow-stock-link {
  text-decoration: none;
  margin-right: 4px;
}
.flow-row .flow-stock-link:hover { text-decoration: underline; }
.flow-funds-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.flow-funds-badge {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.flow-funds-caret {
  display: inline-block;
  color: var(--muted);
  transition: transform 0.2s;
  font-size: 0.9rem;
}
.flow-row.is-open .flow-funds-caret { transform: rotate(180deg); color: var(--fg); }

.flow-detail > td {
  background: rgba(0, 0, 0, 0.25);
  padding: 14px 18px;
}
.etf-chips-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.etf-chips-label {
  font-size: 0.82rem;
  padding-top: 6px;
  white-space: nowrap;
}
.etf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.etf-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--glass-bg-strong);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.etf-chip:hover {
  background: rgba(var(--rgb-b), 0.12);
  border-color: rgba(var(--rgb-b), 0.45);
  text-decoration: none;
  transform: translateY(-1px);
}
.etf-chip strong { font-weight: 700; }
.etf-chip .etf-chip-amt {
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

/* ---- Signals page: in-card sub-section heading ---- */
.signals-section { margin-top: 4px; }
.signals-section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.signals-section-head h2 { margin: 0; }
.signal-count {
  margin-left: 4px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  vertical-align: middle;
}

/* ---- Sortable table headers ---- */
.sortable-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
  padding-right: 18px;
}
.sortable-table th.th-sortable:hover { background: rgba(255, 255, 255, 0.10); }
.sortable-table th.th-sortable::after {
  content: "↕";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7em;
  color: var(--muted);
  opacity: 0.5;
}
.sortable-table th.th-sortable[aria-sort="ascending"]::after {
  content: "▲";
  color: var(--inc);
  opacity: 1;
}
.sortable-table th.th-sortable[aria-sort="descending"]::after {
  content: "▼";
  color: var(--inc);
  opacity: 1;
}

/* ---- Industry heatmap (ETF detail page) ----
 * Flex-based pseudo-treemap: each cell's flex-grow is the industry's weight,
 * so larger industries take more horizontal space within their row. Color
 * intensity (--intensity 0..1) controls background opacity.
 */
.industry-heatmap-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.industry-heatmap-head h2 { margin: 0 0 2px; }
.industry-heatmap-head .hero-sub { margin: 0; }
.industry-heatmap-note { font-size: 0.78rem; }
.treemap-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.treemap-cell {
  flex: var(--flex, 1) 1 180px;
  min-height: 96px;
  padding: 12px 14px;
  background: rgba(var(--rgb-g), calc(var(--intensity, 0) * 0.55 + 0.06));
  border: 1px solid rgba(var(--rgb-g), calc(var(--intensity, 0) * 0.45 + 0.18));
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s, border-color 0.15s;
}
.treemap-cell:hover {
  transform: translateY(-1px);
  border-color: var(--inc);
}
.treemap-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.treemap-name {
  font-size: 0.98rem;
  color: var(--fg);
  letter-spacing: 0.3px;
}
.treemap-weight {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.treemap-stocks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 0.78rem;
  line-height: 1.4;
}
.treemap-stock {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 1px 6px;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.18);
  border-radius: 4px;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.treemap-stock:hover {
  background: rgba(0, 0, 0, 0.3);
  text-decoration: none;
}
.treemap-stock-more {
  padding: 1px 6px;
  font-size: 0.75rem;
}

/* ---- Responsive: wide tables get horizontal scroll on narrow screens ----
 * Wrap any table that may overflow with <div class="table-scroll"> to confine
 * the scroll to the table itself instead of breaking the parent card.
 * Also auto-applied to known wide table classes site-wide.
 */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}
.table-scroll table { margin-top: 0; margin-bottom: 0; }

@media (max-width: 700px) {
  /* Tighten card padding on mobile so the table has more breathing room. */
  main > section { padding: 18px 16px; }
  .holdings-toolbar { padding: 14px 14px 10px; }
  /* Wide tables: keep cell content from wrapping mid-cell on narrow screens
   * (so the row stays on a single line and the parent scroll container
   * provides horizontal overflow instead of breaking table layout). */
  table.changes td,
  table.holdings td,
  table.flow-rank td {
    white-space: nowrap;
  }
}

/* =====================================================================
   Dashboard page styles
   ===================================================================== */

/* ---- Multi-column row container (auto wraps on narrow) ---- */
.dash-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

/* ---- Reusable dash card (same glass card style as section) ---- */
.dash-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 12px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dash-card[data-href] { cursor: pointer; transition: transform 0.15s, border-color 0.15s; }
.dash-card[data-href]:hover { transform: translateY(-2px); border-color: var(--inc); }

.dash-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.dash-card-title { font-weight: 700; font-size: 1rem; }
.dash-card-subtitle { font-size: 0.82rem; }
.dash-card-link { font-size: 0.85rem; text-decoration: none; }
.dash-card-link:hover { color: var(--fg); }

/* ---- Top mover cards (gainer / loser) ---- */
.mover-card {
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}
.mover-card.inc {
  background: linear-gradient(135deg, rgba(var(--rgb-g), 0.18), var(--glass-bg) 70%);
  border-color: rgba(var(--rgb-g), 0.4);
}
.mover-card.dec {
  background: linear-gradient(135deg, rgba(var(--rgb-r), 0.18), var(--glass-bg) 70%);
  border-color: rgba(var(--rgb-r), 0.4);
}
.mover-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.mover-ticker {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--fg);
  margin: 4px 0 -4px;
}
.mover-name { font-size: 0.88rem; }
.mover-pct {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  margin: 4px 0;
}
.mover-stats { font-size: 0.78rem; }

/* ---- Market breadth bar ---- */
.breadth-card { padding: 18px 20px; }
.breadth-bar {
  display: flex;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}
.breadth-seg {
  height: 100%;
  transition: width 0.3s ease;
}
.breadth-seg.inc { background: rgba(var(--rgb-g), 0.85); }
.breadth-seg.dec { background: rgba(var(--rgb-r), 0.85); }
.breadth-seg.flat { background: rgba(255, 255, 255, 0.18); }
.breadth-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  font-weight: 600;
}
.breadth-leg { font-variant-numeric: tabular-nums; }
.breadth-summary {
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 4px;
}

/* ---- Capital flow gauge ---- */
.flow-gauge-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 26px;
  margin-bottom: 22px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 12px 32px rgba(0, 0, 0, 0.35);
}
.flow-gauge-card .flow-row {
  display: grid;
  grid-template-columns: 56px 1fr auto auto;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.flow-label {
  font-weight: 600;
  color: var(--fg);
  font-size: 0.9rem;
}
.flow-bar-track {
  height: 18px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}
.flow-bar {
  display: block;
  height: 100%;
  transition: width 0.3s;
}
.flow-bar.inc {
  background: linear-gradient(90deg, rgba(var(--rgb-g), 0.7), rgba(var(--rgb-g), 1));
  box-shadow: 0 0 12px rgba(var(--rgb-g), 0.5);
}
.flow-bar.dec {
  background: linear-gradient(90deg, rgba(var(--rgb-r), 0.7), rgba(var(--rgb-r), 1));
  box-shadow: 0 0 12px rgba(var(--rgb-r), 0.5);
}
.flow-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  text-align: right;
}
.flow-pct {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  min-width: 50px;
  text-align: right;
}
.flow-net {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border-soft);
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
}
.flow-net strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

/* ---- Industry distribution bars ---- */
.industry-bars-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 26px;
  margin-bottom: 22px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 12px 32px rgba(0, 0, 0, 0.35);
}
.industry-bar-list { margin-top: 12px; }
.industry-bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 160px) 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}
.industry-bar-row:last-child { border-bottom: none; }
.industry-bar-name {
  font-size: 0.9rem;
  font-weight: 600;
}
.industry-bar-track {
  height: 14px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 7px;
  overflow: hidden;
}
.industry-bar {
  display: block;
  height: 100%;
  transition: width 0.4s;
}
.industry-bar.inc {
  background: linear-gradient(90deg, rgba(var(--rgb-g), 0.6), rgba(var(--rgb-g), 0.95));
}
.industry-bar.dec {
  background: linear-gradient(90deg, rgba(var(--rgb-r), 0.6), rgba(var(--rgb-r), 0.95));
}
.industry-bar-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  text-align: right;
  font-size: 0.92rem;
}
.industry-bar-count {
  font-size: 0.78rem;
  min-width: 48px;
  text-align: right;
}

/* ---- Consensus split (buy/sell side-by-side) ---- */
.consensus-card { padding: 18px 20px; }
.consensus-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}
.consensus-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto auto;
  grid-template-areas:
    "rank stock signal"
    "rank meta   meta";
  align-items: center;
  gap: 4px 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}
.consensus-item:last-child { border-bottom: none; }
.consensus-item:hover { background: rgba(var(--rgb-b), 0.05); }
.consensus-rank {
  grid-area: rank;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.consensus-stock {
  grid-area: stock;
  font-size: 0.92rem;
}
.consensus-stock strong { margin-right: 4px; }
.consensus-signal {
  grid-area: signal;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
}
.consensus-meta {
  grid-area: meta;
  font-size: 0.78rem;
}
.signal-badge {
  padding: 1px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.signal-badge.buy {
  color: var(--inc);
  background: rgba(var(--rgb-g), 0.14);
  border: 1px solid rgba(var(--rgb-g), 0.4);
}
.signal-badge.sell {
  color: var(--dec);
  background: rgba(var(--rgb-r), 0.14);
  border: 1px solid rgba(var(--rgb-r), 0.4);
}

@media (max-width: 700px) {
  .flow-gauge-card .flow-row { grid-template-columns: 48px 1fr auto; gap: 8px; }
  .flow-pct { display: none; }
  .industry-bar-row { grid-template-columns: minmax(80px, 110px) 1fr auto; }
  .industry-bar-count { display: none; }
  .mover-pct { font-size: 1.8rem; }
}

/* ---- Dashboard: ETF performance bar chart with period tabs ---- */
.etf-bar-section {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px 16px;
  margin-bottom: 22px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 12px 32px rgba(0, 0, 0, 0.35);
}
.bar-tab-nav {
  display: flex;
  gap: 6px;
  margin: 14px 0 16px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 10px;
  width: fit-content;
}
.bar-tab-btn {
  padding: 6px 16px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border-radius: 7px;
  transition: color 0.15s, background 0.15s;
}
.bar-tab-btn:hover { color: var(--fg); background: rgba(255, 255, 255, 0.06); }
.bar-tab-btn.is-active {
  color: var(--fg);
  background: rgba(var(--rgb-g), 0.18);
  box-shadow: inset 0 0 0 1px rgba(var(--rgb-g), 0.4);
}
.bar-chart-wrap {
  position: relative;
  /* Height set dynamically by JS based on ETF count (~34px per row). */
  min-height: 400px;
}
@media (max-width: 700px) {
  .bar-tab-btn { padding: 6px 12px; font-size: 0.88rem; }
}

/* ---- Investor alert cards (dashboard) ---- */
.alert-row {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.alert-card { padding: 16px 18px; }
.alert-card.alert-warn { border-left: 3px solid var(--inc); }
.alert-card.alert-info { border-left: 3px solid var(--dec); }
.alert-card.alert-caution { border-left: 3px solid #ffe082; }
.alert-card.alert-hot { border-left: 3px solid var(--new); }
.alert-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}
.alert-icon { font-size: 1.3rem; line-height: 1.1; flex-shrink: 0; }
.alert-title-wrap { flex: 1; min-width: 0; }
.alert-title { font-weight: 700; font-size: 0.98rem; }
.alert-sub { font-size: 0.74rem; margin-top: 1px; line-height: 1.3; }
.alert-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.alert-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}
.alert-item:last-child { border-bottom: none; }
.alert-item:hover { background: rgba(var(--rgb-b), 0.06); }
.alert-code {
  font-weight: 700;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.alert-name {
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.alert-value {
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.alert-empty {
  font-size: 0.85rem;
  padding: 14px 4px 4px;
}

/* ---- AUM growth table ---- */
.aum-growth-section { padding: 22px 26px; }
.aum-table tbody tr { cursor: pointer; }
.aum-table tbody tr:hover { background: rgba(var(--rgb-b), 0.08); }
.aum-table-note {
  margin-top: 10px;
  font-size: 0.78rem;
  line-height: 1.5;
}

/* ---- Dashboard: dividend calendar ---- */
.dividend-section { padding: 22px 26px; }
.div-upcoming {
  background: rgba(var(--rgb-g), 0.08);
  border: 1px solid rgba(var(--rgb-g), 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}
.div-upcoming-head {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--fg);
}
.div-upcoming-list { list-style: none; margin: 0; padding: 0; }
.div-upcoming-item {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}
.div-upcoming-item:last-child { border-bottom: none; }
.div-upcoming-item:hover { background: rgba(var(--rgb-b), 0.06); }
.div-upcoming-item.div-past { opacity: 0.55; }
.div-row-stock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.div-row-dates {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.86rem;
}
.div-date-cell, .div-amount {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.div-date-cell strong, .div-amount strong { font-variant-numeric: tabular-nums; }
.div-badge {
  padding: 1px 8px;
  font-size: 0.74rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
}
.div-badge.div-today { background: rgba(var(--rgb-g), 0.2); border-color: rgba(var(--rgb-g), 0.5); color: var(--inc); }
.div-badge.div-soon { background: rgba(255, 213, 79, 0.15); border-color: rgba(255, 213, 79, 0.4); color: #ffe082; }
.div-upcoming-empty {
  padding: 16px;
  text-align: center;
  font-size: 0.92rem;
  margin-top: 12px;
  border: 1px dashed var(--border-soft);
  border-radius: 12px;
}
.div-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.div-group {
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 14px;
}
.div-group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.div-group-name {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--fg);
}
.div-group-count {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  background: rgba(var(--rgb-g), 0.15);
  border: 1px solid rgba(var(--rgb-g), 0.3);
  color: var(--inc);
}
.div-group-list { list-style: none; margin: 0; padding: 0; }
.div-group-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 5px 4px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  font-size: 0.88rem;
}
.div-group-list li:last-child { border-bottom: none; }
.div-group-list li:hover { background: rgba(var(--rgb-b), 0.06); }
.div-group-list li strong { font-variant-numeric: tabular-nums; }
.div-group-empty { font-size: 0.85rem; padding: 8px 4px; }

/* ---- Dashboard: dividend pattern small tag (其他組顯示) ---- */
.div-pattern-tag {
  margin-left: auto;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}

/* ---- Admin ETF table: dividend pattern cell ---- */
.div-pattern-cell {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg);
  background: rgba(var(--rgb-g), 0.12);
  border: 1px solid rgba(var(--rgb-g), 0.3);
  border-radius: 999px;
  white-space: nowrap;
}
