/* InvestingSpark v3 — live markets board + asset chart page.
   Extends theme.css tokens. Loaded only on /, /markets and /asset. */

/* ---------- Ticker tape ---------- */
.tape {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden; position: relative;
  margin-top: 18px;
}
.tape::before, .tape::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 42px; z-index: 2; pointer-events: none;
}
.tape::before { left: 0; background: linear-gradient(90deg, var(--surface), transparent); }
.tape::after { right: 0; background: linear-gradient(-90deg, var(--surface), transparent); }
.tape-track {
  display: flex; width: max-content; padding: 9px 0;
  animation: tape-scroll 55s linear infinite;
}
.tape:hover .tape-track { animation-play-state: paused; }
@keyframes tape-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.tape-item {
  display: inline-flex; align-items: baseline; gap: 8px; white-space: nowrap;
  padding: 0 22px; font-family: "IBM Plex Mono", monospace; font-size: .83rem;
  border-right: 1px solid var(--line-soft);
}
.tape-item .t-sym { color: var(--ink-faint); font-weight: 600; font-size: .72rem; letter-spacing: .05em; }
.tape-item .t-price { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tape-item .t-chg { font-variant-numeric: tabular-nums; }
.tape-note { padding: 10px 16px; color: var(--ink-soft); font-size: .9rem; font-family: "Inter", sans-serif; }

/* ---------- Board ---------- */
.board {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-top: 20px; overflow: hidden;
}
.board-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--line-soft);
}
.board-head h2 { font-size: 1.22rem; font-weight: 800; letter-spacing: -0.01em; }
.board-status { display: inline-flex; align-items: center; gap: 8px; font-size: .83rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.board-status .live-dot { width: 7px; height: 7px; }
.board-status.stale { color: var(--gold); }
.board-refresh { margin-left: auto; min-height: 40px; padding: 8px 14px; font-size: .9rem; }
.board-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line-soft);
}
.board-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.board-tab {
  border: 1px solid transparent; background: none; cursor: pointer; min-height: 38px;
  color: var(--ink-soft); font-weight: 600; font-size: .92rem;
  padding: 7px 14px; border-radius: 8px;
}
.board-tab:hover { color: var(--ink); background: var(--surface-2); }
.board-tab[aria-selected="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: rgba(16, 185, 129, .3); }
.board-search { margin-left: auto; position: relative; }
.board-search input {
  width: 210px; min-height: 40px; padding: 8px 12px 8px 34px; font-weight: 500;
  background: var(--field); border: 1px solid var(--line); border-radius: 9px; color: var(--ink);
}
.board-search input::placeholder { color: var(--ink-faint); }
.board-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--ink-faint); fill: none; stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.board-tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.board-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.board-table th {
  font-family: "IBM Plex Mono", monospace; font-size: .68rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint);
  text-align: right; padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.board-table th:first-child, .board-table td:first-child { text-align: left; }
.board-table td { padding: 11px 16px; border-bottom: 1px solid var(--line-soft); text-align: right; font-variant-numeric: tabular-nums; vertical-align: middle; }
.board-table tbody tr { cursor: pointer; transition: background .12s ease; }
.board-table tbody tr:hover { background: var(--surface-2); }
.board-table tbody tr:last-child td { border-bottom: none; }
.b-rank { color: var(--ink-faint); font-family: "IBM Plex Mono", monospace; font-size: .8rem; width: 34px; }
.b-name { min-width: 0; }
.b-name a { color: var(--ink); text-decoration: none; font-weight: 600; display: inline-flex; flex-direction: column; gap: 1px; }
.b-name a:hover { color: var(--accent-strong); }
.b-name .b-sym { font-family: "IBM Plex Mono", monospace; font-size: .72rem; font-weight: 600; letter-spacing: .05em; color: var(--ink-faint); text-transform: uppercase; }
.b-name .b-full { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.b-name .b-sub { display: block; font-size: .76rem; color: var(--ink-faint); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.b-price { font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: .98rem; white-space: nowrap; }
.b-chg { white-space: nowrap; }
.chg-pill {
  display: inline-block; min-width: 76px; text-align: center;
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: .85rem;
  padding: 4px 9px; border-radius: 7px; font-variant-numeric: tabular-nums;
}
.chg-pill.up { color: var(--up); background: var(--up-soft); }
.chg-pill.down { color: var(--down); background: var(--down-soft); }
.chg-pill.flat { color: var(--ink-faint); background: var(--surface-2); }
.b-spark { width: 108px; }
.b-spark canvas { display: block; width: 96px; height: 28px; margin-left: auto; }
.b-spark .spark-na { color: var(--ink-faint); font-size: .8rem; }
@keyframes flash-up { 0% { background: var(--up-soft); } 100% { background: transparent; } }
@keyframes flash-down { 0% { background: var(--down-soft); } 100% { background: transparent; } }
.b-price.flash-up { animation: flash-up .8s ease; border-radius: 6px; }
.b-price.flash-down { animation: flash-down .8s ease; border-radius: 6px; }
.board-foot { padding: 11px 20px 14px; border-top: 1px solid var(--line-soft); }
.board-foot p { margin: 0; font-size: .79rem; color: var(--ink-faint); line-height: 1.5; }
.board-empty { padding: 26px 20px; color: var(--ink-soft); font-size: .95rem; }
.board-unavail { margin: 16px 20px; }

@media (max-width: 760px) {
  .board-head { padding: 14px 16px 10px; }
  .board-controls { padding: 10px 16px; }
  .board-search { margin-left: 0; width: 100%; }
  .board-search input { width: 100%; }
  .board-refresh { margin-left: 0; }
  .board-table th, .board-table td { padding: 10px 10px; }
  .b-rank { display: none; }
  .board-table th.b-rank-h { display: none; }
  .b-name .b-full { max-width: 128px; }
  .b-name .b-sub { max-width: 128px; }
  .b-spark { width: 62px; }
  .b-spark canvas { width: 54px; height: 22px; }
  .chg-pill { min-width: 66px; font-size: .8rem; padding: 3px 7px; }
  .b-price { font-size: .9rem; }
}

/* ---------- Asset page ---------- */
.asset-head { padding: 30px 0 4px; }
.asset-title-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.asset-title-row h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 800; letter-spacing: -0.02em; }
.asset-sym { font-family: "IBM Plex Mono", monospace; color: var(--ink-faint); font-weight: 600; font-size: 1rem; letter-spacing: .05em; text-transform: uppercase; }
.asset-price-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.asset-price { font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: clamp(1.9rem, 5vw, 2.6rem); font-variant-numeric: tabular-nums; line-height: 1; }
.asset-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 20px; }
.asset-stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.asset-stat .k { font-family: "IBM Plex Mono", monospace; font-size: .66rem; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); display: block; }
.asset-stat .v { font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 1.02rem; margin-top: 4px; display: block; font-variant-numeric: tabular-nums; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 20px; overflow: hidden; }
.chart-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.range-row { display: flex; gap: 4px; flex-wrap: wrap; }
.range-btn {
  border: 1px solid transparent; background: none; cursor: pointer; min-height: 36px;
  color: var(--ink-soft); font-weight: 600; font-size: .88rem; padding: 6px 12px; border-radius: 8px;
  font-family: "IBM Plex Mono", monospace;
}
.range-btn:hover { color: var(--ink); background: var(--surface-2); }
.range-btn[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: rgba(16, 185, 129, .3); }
.chart-type { margin-left: auto; display: flex; gap: 4px; }
#lw-chart { width: 100%; height: 430px; }
@media (max-width: 760px) { #lw-chart { height: 300px; } .chart-type { margin-left: 0; } }
.chart-foot { padding: 10px 16px 13px; border-top: 1px solid var(--line-soft); }
.chart-foot p { margin: 0; font-size: .79rem; color: var(--ink-faint); }
.asset-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

@media (prefers-reduced-motion: reduce) {
  .tape-track { animation: none; }
  .b-price.flash-up, .b-price.flash-down { animation: none; }
}

/* Upgrade 2026-12-06: trading-desk polish + tap targets */
.board-table td,.board-table th,.board td,.board th{font-variant-numeric:tabular-nums;font-feature-settings:"tnum" 1}
.board-tabs button,.board-tab,.filter-btn{min-height:40px;padding:8px 14px}
.board a{min-height:24px}
.up{color:var(--up,#10b981)} .down{color:var(--down,#f43f5e)}

/* Perf 2026-12-06 (homepage): reserve the board-head geometry so the live
   status text arriving with the data cannot reflow the head and shift the
   whole page (was CLS 0.481 of 0.493); keep the tape a constant height;
   skip layout/paint of below-fold homepage tool sections until they near
   the viewport — sections stay fully in the HTML for crawlers, and app.js
   flips a section to content-visibility:visible before its first compute. */
.tape { min-height: 43px; }
.board-status { min-height: 21px; }
@media (max-width: 1100px) {
  .board-status { flex: 1 1 100%; order: 3; min-height: 41px; }
}
main section.tool { content-visibility: auto; contain-intrinsic-size: auto 1000px; }

/* Perf 2026-12-06 (round 2): the loading tape note was ~19px taller than the
   loaded tape, and the status text can need 3 lines on narrow screens —
   both moved the board. Tape track is now a constant 43px; the status is
   clamped to the 2 reserved lines (full source line remains in .board-foot). */
.tape-track { min-height: 43px; box-sizing: border-box; align-items: center; }
.tape-note { padding-top: 0; padding-bottom: 0; }
@media (max-width: 1100px) {
  .board-status { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
