/* The Market Dashboard panel (showcase/chapters/stocks/_dashboard.html, sd-dashboard.js), the `dashboard` tab of
   the Stocks Data chapter on /how-it-works/.
   One app window with the real page (intrinio_stock/templates/stock_data/market_dashboard.html) condensed into a
   view that scrolls inside itself. Colours inside the window are the page's own: its :root palette (:5-16,
   #22263a to #2a2f45 card gradient, #374151 borders), candles #10b981 / #ef4444, the breadth bar #00c46d /
   #ff4d4d (:240-252), the chart colours (#4CD68F, #E24E4C, #d3d3d3, rgba(105,137,197)), the treemap's #121212
   borders, the selects #2E2E40 / #333754 (:186-194). The panel around the window uses landing.css tokens.
   Everything is sd-dash-* and scoped under .sd-dash. JS state: on the root .sd-dash is-ready (data loaded),
   is-nodata, is-paused, is-still (reduced motion); on the auto label is-idle / is-stopped; everything else is a
   data attribute (data-sd-dash-lamp / -lit / -flash / -dir / -ema-off / -hot), never a class.
   Only transform and opacity animate (plus SVG clip widths, set by the JS). Reduced motion (landing.css section
   13, plus .is-still) and the paused state stop it all. */

.sd-dash {
  --sd-dash-bg: #1a1d2e; --sd-dash-card: linear-gradient(135deg, #22263a 0%, #2a2f45 100%); --sd-dash-line: #374151;
  --sd-dash-up: #10b981; --sd-dash-down: #ef4444; --sd-dash-gold: #ffc107; --sd-dash-accent: #6759d1;
  --sd-dash-muted: rgba(255, 255, 255, .65);
  position: relative; min-width: 0;
}
.sd-dash [hidden] { display: none !important; }
html:not(.js) .sd-dash-js, .sd-dash.is-nodata .sd-dash-js { display: none !important; }

/* ---- panel head ---- */
.sd-dash-head { max-width: 72ch; margin: 0 auto var(--lp-sp-5); text-align: center; }
.sd-dash .sd-dash-title { margin: 0; color: var(--lp-text); font: 700 var(--lp-fs-lg)/1.25 var(--lp-font-title); letter-spacing: -.01em; }
.sd-dash .sd-dash-lead { margin: var(--lp-sp-2) 0 0; color: var(--lp-muted); font-size: var(--lp-fs-base); line-height: 1.6; }

/* ---- the window ---- */
.sd-dash-window {
  position: relative; overflow: hidden; min-width: 0;
  border: 1px solid var(--lp-border-strong); border-radius: 16px; background: var(--sd-dash-bg);
  box-shadow: var(--lp-shadow), 0 0 80px color-mix(in srgb, var(--lp-primary) 10%, transparent);
}
.sd-dash-chrome {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 14px;
  background: #0c0a17; border-bottom: 1px solid rgba(255, 255, 255, .07); white-space: nowrap; overflow: hidden;
}
.sd-dash-lights { display: inline-flex; gap: 6px; flex: none; }
.sd-dash-lights i { width: 10px; height: 10px; border-radius: 50%; background: #ff5f57; }
.sd-dash-lights i + i { background: #febc2e; }
.sd-dash-lights i + i + i { background: #28c840; }
.sd-dash-chrome-tab { overflow: hidden; text-overflow: ellipsis; padding: 4px 12px; border-radius: 8px 8px 0 0; background: var(--sd-dash-bg); color: #a7a3c9; font-size: 12px; }
.sd-dash-chrome-tab b { color: #f4f2ff; font-weight: 800; letter-spacing: -.01em; }
.sd-dash-chrome-url { overflow: hidden; text-overflow: ellipsis; color: #8e8ab4; font: 11.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.sd-dash-app { min-width: 0; color: #f9fafb; font-size: 13px; line-height: 1.45; background: var(--sd-dash-bg); }
.sd-dash .sd-dash-app p { margin: 0; }

.sd-dash-pghead {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 18px;
  background: linear-gradient(90deg, #5aae8c, #6dbf9d); color: #fff;
}
.sd-dash .sd-dash-pgname { color: #fff; font: 700 18px/1.2 var(--lp-font-title); letter-spacing: .01em; }
.sd-dash-pghead .lp-tier { --lp-tier-c: #fff; }
.sd-dash-pghead-end { margin-left: auto; }
.sd-dash-pghead .lp-sample { border-color: rgba(255, 255, 255, .7); color: #fff; background: rgba(12, 10, 23, .25); }

/* ---- the rail: one chip per section ---- */
.sd-dash-rail {
  display: flex; gap: 6px; padding: 10px 18px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid rgba(139, 125, 232, .16); background: rgba(255, 255, 255, .02);
}
.sd-dash-rail::-webkit-scrollbar { display: none; }
.sd-dash .sd-dash-chip {
  flex: none; margin: 0; padding: 6px 13px; border: 1px solid rgba(139, 125, 232, .25); border-radius: 999px;
  background: rgba(255, 255, 255, .04); color: var(--sd-dash-muted); font: 700 12px/1.2 var(--lp-font); white-space: nowrap; cursor: pointer;
  transition: background-color .2s var(--lp-ease), color .2s var(--lp-ease);
}
.sd-dash .sd-dash-chip[aria-current="true"] { border-color: transparent; background: linear-gradient(135deg, #6759d1 0%, #8b7de8 100%); color: #fff; }
.sd-dash .sd-dash-chip:hover:not([aria-current="true"]) { background: rgba(255, 255, 255, .08); color: #fff; }
.sd-dash .sd-dash-chip:focus-visible { outline: 2px solid var(--lp-accent); outline-offset: 2px; }

/* ---- the view: the page, scrolling inside itself once JS runs ---- */
.sd-dash-view { position: relative; min-width: 0; padding: 14px 16px 18px; }
html.js .sd-dash:not(.is-nodata) .sd-dash-view {
  height: 600px; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(103, 89, 209, .5) transparent;
}
.sd-dash-view:focus-visible { outline: 2px solid var(--lp-accent); outline-offset: -2px; }
.sd-dash-sec { min-width: 0; }
.sd-dash-sec + .sd-dash-sec { margin-top: 14px; }

.sd-dash-icard, .sd-dash-bcard, .sd-dash-ccard, .sd-dash-filter {
  min-width: 0; border: 1px solid var(--sd-dash-line); background: var(--sd-dash-card); box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .35);
}

/* SVG text and lines shared by the charts */
.sd-dash svg text { fill: #fff; font-family: var(--lp-font); }
.sd-dash .sd-dash-ax { font-size: 8.5px; fill: rgba(255, 255, 255, .92); }
.sd-dash .sd-dash-ax--x { text-anchor: middle; }
.sd-dash .sd-dash-ax--r { text-anchor: end; }
.sd-dash .sd-dash-ax--t { text-anchor: middle; font-size: 9.5px; }
.sd-dash-grid { stroke: rgba(255, 255, 255, .07); stroke-width: 1; }
.sd-dash-grid--2 { stroke: rgba(255, 255, 255, .14); }

/* ---- 1. index cards ---- */
.sd-dash-idx { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sd-dash-icard { padding: 12px 12px 10px; border-radius: 15px; }
.sd-dash-ihead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; }
.sd-dash .sd-dash-iname { color: #fff; font: 700 13px/1.3 var(--lp-font); }
.sd-dash-ichg { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sd-dash-ichg[data-sd-dash-dir="up"] { color: var(--sd-dash-up); }
.sd-dash-ichg[data-sd-dash-dir="down"] { color: var(--sd-dash-down); }
.sd-dash-ichg[data-sd-dash-dir="flat"] { color: var(--sd-dash-muted); }
.sd-dash-isvg { display: block; width: 100%; height: auto; margin-top: 6px; }
.sd-dash-candle line { stroke-width: 1; }
.sd-dash-candle--up rect { fill: var(--sd-dash-up); }
.sd-dash-candle--up line { stroke: var(--sd-dash-up); }
.sd-dash-candle--down rect { fill: var(--sd-dash-down); }
.sd-dash-candle--down line { stroke: var(--sd-dash-down); }
.sd-dash .sd-dash-ilast { margin-top: 2px; color: var(--sd-dash-gold); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* ---- 2. breadth ---- */
.sd-dash-br { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sd-dash-bcard { display: flex; flex-direction: column; justify-content: center; padding: 9px 12px 11px; border-radius: 8px; }
.sd-dash .sd-dash-btitle { margin-bottom: 2px; color: #fff; font-weight: 700; text-align: center; }
.sd-dash .sd-dash-brow { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sd-dash .sd-dash-brow--l { margin-top: 0; font-weight: 700; font-size: 13px; }
.sd-dash-g { color: var(--sd-dash-up); }
.sd-dash-r { color: var(--sd-dash-down); }
.sd-dash-bar { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 5px; background: #ff4d4d; }
.sd-dash-bar i { display: block; height: 100%; background: #00c46d; transform-origin: 0 50%; }

/* ---- 3. Market Direction by premium ---- */
.sd-dash-dir { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 6px 4px; }
.sd-dash .sd-dash-dirl { display: flex; flex-direction: column; min-width: 140px; color: #fff; font: 700 17px/1.15 var(--lp-font-title); text-align: center; }
.sd-dash .sd-dash-lamps { display: flex; flex: 1 1 0; flex-wrap: wrap; justify-content: space-between; gap: 12px 10px; margin: 0; padding: 0; list-style: none; }
.sd-dash-lamp { display: flex; flex-direction: column; align-items: center; min-width: 56px; margin: 0; }
.sd-dash-house {
  position: relative; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 11px;
  background: linear-gradient(160deg, #34363f 0%, #121318 55%, #050506 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), inset 0 -2px 4px rgba(0, 0, 0, .7), 0 3px 8px rgba(0, 0, 0, .5);
}
.sd-dash-house i {
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #5b5d66 0, #2a2b31 45%, #111215 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .55);
  transition: opacity .25s var(--lp-ease);
}
.sd-dash-lamp[data-sd-dash-lit="1"][data-sd-dash-lamp="up"] .sd-dash-house i {
  background: radial-gradient(circle at 36% 30%, #eafff1 0, #6ee7a0 18%, #16a34a 55%, #064e25 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .45), 0 0 16px rgba(34, 197, 94, .65);
}
.sd-dash-lamp[data-sd-dash-lit="1"][data-sd-dash-lamp="down"] .sd-dash-house i {
  background: radial-gradient(circle at 36% 30%, #ffecec 0, #fb7f7f 18%, #dc2626 55%, #5f0b0b 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .45), 0 0 16px rgba(239, 68, 68, .65);
}
.sd-dash-lamp[data-sd-dash-lit="1"][data-sd-dash-lamp="flat"] .sd-dash-house i {
  background: radial-gradient(circle at 36% 30%, #fff8e1 0, #fcd34d 18%, #d97706 58%, #5c3303 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .45), 0 0 16px rgba(245, 158, 11, .6);
}
.sd-dash-lamp[data-sd-dash-flash] .sd-dash-house i { animation: sd-dash-pop .5s var(--lp-ease); }
@keyframes sd-dash-pop { 0% { transform: scale(.82); } 60% { transform: scale(1.08); } 100% { transform: none; } }
.sd-dash-lname { margin-top: 6px; color: #fff; font-size: 12.5px; font-weight: 600; white-space: nowrap; }

/* ---- 4. the two charts ---- */
.sd-dash-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.sd-dash-ccard { display: flex; flex-direction: column; justify-content: flex-end; padding: 12px; border-radius: 16px; }
.sd-dash-ctop { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.sd-dash .sd-dash-ema {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px; border-radius: 20px;
  background: rgba(255, 255, 255, .08); color: #fff; font-size: 11px; cursor: pointer;
}
.sd-dash .sd-dash-ema input { width: 13px; height: 13px; margin: 0; accent-color: var(--sd-dash-accent); }
.sd-dash-csvg { display: block; width: 100%; height: auto; }
.sd-dash .sd-dash-leg text { font-size: 10px; }
.sd-dash-ln { fill: none; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.sd-dash-ln--w { stroke-width: 1.8; }
.sd-dash .sd-dash-tag text { font-size: 8px; font-weight: 700; text-anchor: middle; }
.sd-dash .sd-dash-wm { fill: rgba(211, 211, 211, .2); font: 18px Arial, sans-serif; text-anchor: middle; }
.sd-dash-ccard[data-sd-dash-ema-off] .sd-dash-tags,
.sd-dash-ccard:has(input[data-sd-dash-ema]:not(:checked)) .sd-dash-tags { display: none; }

/* ---- 5. heatmap ---- */
.sd-dash-filter {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px;
  margin-bottom: 12px; padding: 14px 16px; border-radius: 16px;
}
.sd-dash-fsel { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sd-dash .sd-dash-frow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: #fff; }
.sd-dash .sd-dash-frow b { margin-right: 2px; font-weight: 700; }
.sd-dash .sd-dash-frow b + .sd-dash-pill + b { margin-left: 8px; }
.sd-dash-pill {
  display: inline-block; padding: 4px 12px; border: 1px solid rgba(255, 255, 255, .55); border-radius: 999px;
  background: var(--sd-dash-accent); color: #fff; font-size: 11.5px; font-weight: 700; line-height: 1.3;
  transition: transform .25s var(--lp-ease), box-shadow .25s var(--lp-ease);
}
.sd-dash-pill[data-sd-dash-hot] { transform: translateY(-2px); box-shadow: 0 0 0 2px rgba(169, 158, 245, .55), 0 4px 10px rgba(103, 89, 209, .5); }
.sd-dash-fctl { display: flex; flex-wrap: wrap; gap: 8px; }
.sd-dash-fbtn, .sd-dash-fsel-box { position: relative; display: inline-flex; align-items: center; min-height: 36px; font-size: 13.5px; white-space: nowrap; }
.sd-dash-fbtn { padding: 0 28px 0 13px; border: 1px solid var(--sd-dash-accent); border-radius: 8px; color: #b4abf7; }
.sd-dash-fsel-box { min-width: 120px; padding: 0 30px 0 11px; border: 1px solid #333754; border-radius: 10px; background: #2E2E40; color: #fff; }
.sd-dash-fbtn::after, .sd-dash-fsel-box::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
  border: solid currentColor; border-width: 0 1.6px 1.6px 0; transform: rotate(45deg);
}

.sd-dash .sd-dash-tree {
  position: relative; aspect-ratio: 2 / 1; margin: 0; padding: 0; list-style: none; overflow: hidden;
  border: 1px solid var(--sd-dash-line); border-radius: 12px; background: #121212;
}
.sd-dash-tile {
  position: absolute; display: flex; align-items: center; justify-content: center; margin: 0; overflow: hidden;
  box-sizing: border-box; border: 2px solid #121212; color: #fff; text-align: center; container-type: size;
  transition: background-color .45s var(--lp-ease);
}
.sd-dash-tl { font-size: 11px; font-size: clamp(7px, 14cqmin, 16px); line-height: 1.15; font-variant-numeric: tabular-nums; }
.sd-dash-tl b { display: block; font-weight: 700; }
.sd-dash-tl span { font-size: .86em; }
@container (max-width: 34px) { .sd-dash-tl span { display: none; } }
@container (max-height: 26px) { .sd-dash-tl span { display: none; } }
@container (max-width: 20px) { .sd-dash-tl { display: none; } }
@container (max-height: 13px) { .sd-dash-tl { display: none; } }
.sd-dash-tile[data-sd-dash-flash]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, .38) 50%, transparent 70%);
  animation: sd-dash-shimmer .7s var(--lp-ease) both;
}
@keyframes sd-dash-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---- the readout: what the demo shows now ---- */
.sd-dash .sd-dash-readout {
  display: flex; align-items: flex-start; gap: 10px; min-height: 60px; margin: 0; padding: 11px 18px 13px;
  border-top: 1px solid rgba(139, 125, 232, .16); background: rgba(103, 89, 209, .1); color: #fff; font-size: 13px; line-height: 1.5;
}
.sd-dash-readout-dot { flex: none; width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--lp-accent); }

/* ---- controls under the window (as the other panels) ---- */
.sd-dash-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--lp-sp-3) var(--lp-sp-5); margin-top: var(--lp-sp-4); }
.sd-dash-play { display: flex; flex-wrap: wrap; align-items: center; gap: var(--lp-sp-2); }
.sd-dash-auto {
  position: relative; display: inline-flex; align-items: center; gap: var(--lp-sp-2); min-height: 38px; padding: 0 var(--lp-sp-3);
  border: 1px solid var(--lp-border); border-radius: var(--lp-r-sm); background: var(--lp-surface-2);
  color: var(--lp-muted); font-size: var(--lp-fs-xs); font-weight: 600;
}
.sd-dash-auto-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lp-green); }
.sd-dash-auto.is-idle .sd-dash-auto-dot, .sd-dash-auto.is-stopped .sd-dash-auto-dot { background: var(--lp-amber); }
.sd-dash-auto-bar { position: absolute; left: 12px; right: 12px; bottom: 5px; height: 2px; overflow: hidden; border-radius: 2px; background: color-mix(in srgb, var(--lp-text) 10%, transparent); }
.sd-dash-auto-bar i { display: block; height: 100%; background: var(--lp-primary); transform-origin: 0 50%; transform: scaleX(0); }
.sd-dash-auto.is-idle .sd-dash-auto-bar i, .sd-dash-auto.is-stopped .sd-dash-auto-bar i { background: var(--lp-amber); }
.sd-dash-ico-play, .sd-dash.is-paused .sd-dash-ico-pause { display: none; }
.sd-dash.is-paused .sd-dash-ico-play { display: inline; }
.sd-dash .sd-dash-sample-note { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--lp-sp-2); margin: 0; color: var(--lp-muted); font-size: var(--lp-fs-xs); }
.sd-dash.is-still .sd-dash-play { display: none; }

/* ---- motion off ---- */
.sd-dash.is-paused *, .sd-dash.is-paused *::before, .sd-dash.is-paused *::after { animation-play-state: paused !important; }
.sd-dash.is-still *, .sd-dash.is-still *::before, .sd-dash.is-still *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .sd-dash *, .sd-dash *::before, .sd-dash *::after { animation: none !important; transition: none !important; }
}

/* ---- smaller screens ---- */
@media (max-width: 960px) {
  .sd-dash-idx, .sd-dash-br { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sd-dash-charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .sd-dash-chrome-url { display: none; }
  .sd-dash-pghead { padding: 10px 12px; }
  .sd-dash .sd-dash-pgname { font-size: 16px; }
  .sd-dash-rail { padding: 8px 12px; }
  .sd-dash-view { padding: 12px 10px 14px; }
  html.js .sd-dash:not(.is-nodata) .sd-dash-view { height: 560px; }
  .sd-dash .sd-dash-dirl { flex-direction: row; gap: 6px; width: 100%; justify-content: center; font-size: 15px; }
  .sd-dash .sd-dash-lamps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sd-dash-house { width: 48px; height: 48px; }
  .sd-dash-house i { width: 32px; height: 32px; }
  .sd-dash .sd-dash-tree { aspect-ratio: 1 / 1; }
  .sd-dash-filter { padding: 12px; }
  .sd-dash-fctl { width: 100%; }
  .sd-dash-fbtn, .sd-dash-fsel-box { flex: 1 1 auto; min-width: 0; font-size: 12.5px; }
  .sd-dash .sd-dash-readout { min-height: 84px; padding: 10px 12px 12px; font-size: 12.5px; }
  .sd-dash-controls { justify-content: center; }
  .sd-dash .sd-dash-sample-note { justify-content: center; text-align: center; }
}
@media (max-width: 520px) {
  .sd-dash-idx, .sd-dash-br { grid-template-columns: minmax(0, 1fr); }
  /* the 420 wide chart viewBox shrinks to the phone: larger type in viewBox units keeps it readable */
  .sd-dash .sd-dash-csvg .sd-dash-ax { font-size: 10.5px; }
  .sd-dash .sd-dash-csvg .sd-dash-ax--t { font-size: 11px; }
  .sd-dash .sd-dash-csvg .sd-dash-leg text { font-size: 11.5px; }
}
