:root {
  --bg: #0b0e14;
  --bg-elevated: #121620;
  --bg-card: #161b26;
  --border: #232a38;
  --text: #e6e9ef;
  --text-dim: #9aa4b6;
  --text-faint: #6b7688;

  --accent: #2dd4bf;       /* teal — "pulse" accent */
  --accent-soft: rgba(45, 212, 191, 0.15);
  --up: #34d399;
  --down: #f87171;
  --warn: #fbbf24;

  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 46px;
  height: 32px;
  display: inline-flex;
  color: var(--accent);
}

.pulse-line {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-tagline {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.ticker-search {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 320px;
  max-width: 420px;
  position: relative;
}

.ticker-search input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.95rem;
}

.ticker-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ticker-search button {
  background: var(--accent);
  color: #06201c;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}

.ticker-search button:hover {
  opacity: 0.85;
}

/* ---------- Search autocomplete dropdown ---------- */

.search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}

.search-suggestion {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
}

.search-suggestion:hover,
.search-suggestion.is-active {
  background: var(--bg-elevated);
}

.search-suggestion-name {
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 600;
}

.search-suggestion-meta {
  font-size: 0.76rem;
  color: var(--text-faint);
}

.search-suggestion-empty {
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-faint);
}

/* ---------- Main ---------- */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

/* ---------- Status message (loading / error) ---------- */

.status-message {
  margin-bottom: 1.5rem;
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.status-message--error {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}

/* ---------- Dashboard layout ----------
   A single stacked column: full-width history, full-width summary card,
   the metrics grid, then the compact "about" strip - everything shares the
   same content width, in the order the page should actually be read. */

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transition: opacity 0.15s ease;
}

.dashboard.is-loading {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- Heartbeat History chart ---------- */

.panel-history {
  gap: 1rem;
}

.history-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.history-header h2 {
  margin: 0;
}

.range-controls {
  display: flex;
  gap: 0.35rem;
}

.range-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  min-height: 32px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.range-btn:hover {
  color: var(--text);
}

.range-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chart-frame {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.chart-axis-title {
  font-size: 0.68rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-body {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.chart-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 30px;
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--text-faint);
  text-align: right;
  padding: 2px 0;
}

.chart-plot {
  flex: 1;
  min-width: 0;
  height: 220px;
}

.chart-plot svg {
  display: block;
  width: 100%;
  height: 100%;
}

.grid-line-h {
  stroke: var(--border);
  stroke-width: 1;
}

.grid-line-v {
  stroke: var(--border);
  stroke-width: 1;
  opacity: 0.6;
}

#history-polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart-x-axis {
  display: flex;
  justify-content: space-between;
  margin-left: calc(30px + 0.5rem);
  font-size: 0.68rem;
  color: var(--text-faint);
}

.chart-x-axis span {
  white-space: nowrap;
}

#panel-history > p {
  color: var(--text-faint);
  font-size: 0.8rem;
  margin: 0;
  text-align: center;
}

/* ---------- Stock summary card ----------
   Three conceptual areas - identity, heartbeat, market context. One column
   on mobile; identity+heartbeat side by side with market data below on
   tablet; all three side by side on wide desktop. */

.stock-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
  grid-template-areas:
    "identity"
    "heartbeat"
    "quote";
}

@media (min-width: 640px) {
  .stock-card {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "identity heartbeat"
      "quote quote";
    align-items: center;
  }
}

@media (min-width: 1000px) {
  .stock-card {
    grid-template-columns: minmax(180px, 220px) minmax(180px, 220px) 1fr;
    grid-template-areas: "identity heartbeat quote";
  }
}

.stock-card-identity {
  grid-area: identity;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.identity-heading {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.ticker {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.company-name {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.exchange-tag {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.identity-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* State pills use a teal/amber/purple/blue family - deliberately distinct
   from the green/red used for Direction, so "how active" never reads as
   "good or bad". */
.state-resting {
  background: rgba(107, 118, 136, 0.15);
  color: var(--text-dim);
}

.state-compressing {
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
}

.state-tight {
  background: rgba(251, 191, 36, 0.22);
  color: var(--warn);
}

.state-waking-up {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
}

.state-expanding {
  background: var(--accent-soft);
  color: var(--accent);
}

.state-high-energy {
  background: rgba(192, 132, 252, 0.18);
  color: #c084fc;
}

.state-cooling {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}

.direction {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.direction-bullish {
  color: var(--up);
}

.direction-bearish {
  color: var(--down);
}

.direction-neutral {
  color: var(--text-faint);
}

.stock-card-heartbeat {
  grid-area: heartbeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
}

.heartbeat-gauge {
  --value: 0;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) calc(var(--value) * 1%),
    var(--border) 0
  );
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.heartbeat-gauge-inner {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.heartbeat-number {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
}

.heartbeat-label {
  font-size: 0.65rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stock-card-explainer {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  max-width: 26ch;
}

.stock-card-quote {
  grid-area: quote;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1rem 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

@media (min-width: 1000px) {
  .stock-card-quote {
    padding-top: 0;
    padding-left: 1.25rem;
    border-top: none;
    border-left: 1px solid var(--border);
  }
}

.quote-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.quote-label {
  font-size: 0.68rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quote-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.quote-price-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.quote-price {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.quote-change {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-faint);
}

.quote-change.is-up {
  color: var(--up);
}

.quote-change.is-down {
  color: var(--down);
}

/* ---------- Metric panels ----------
   Explicit column counts per breakpoint (rather than auto-fit) so exactly
   8 cards always land as a clean 4x2 / 2x4 / 1x8 grid - never an orphaned
   card on an uneven row. */

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

@media (min-width: 640px) {
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1000px) {
  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 0;
}

.panel-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0;
}

.panel-unit {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 0.3rem;
}

.panel-desc {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
  margin-top: auto;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.bar-fill-compression {
  background: var(--warn);
}

.bar-fill-volume {
  background: #60a5fa;
}

.bar-fill-range {
  background: #c084fc;
}

.bar-fill-overlap {
  background: var(--accent);
}

/* ---------- About strip ----------
   Deliberately styled like any other panel (same muted small-caps heading,
   same card chrome) so it visually reads as supporting information rather
   than a headline - it sits last, after the metrics. */

.about-strip p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  max-width: 75ch;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 2rem 2.5rem;
  background: var(--bg-elevated);
}

.disclaimer {
  max-width: 900px;
  margin: 0 auto;
  color: var(--text-faint);
  font-size: 0.78rem;
  text-align: center;
}

/* ---------- Mobile ----------
   Below ~600px: header stacks and the search field goes full-width, page
   padding tightens so content fits comfortably down to 320px, and the
   summary card centers everything as it stacks into one column. */

@media (max-width: 600px) {
  .site-header {
    padding: 1rem;
  }

  .brand {
    width: 100%;
  }

  .ticker-search {
    flex-basis: 100%;
    max-width: none;
  }

  main {
    padding: 1.5rem 1rem 2rem;
  }

  .stock-card,
  .panel {
    padding: 1.1rem;
  }

  .stock-card-identity {
    align-items: center;
    text-align: center;
  }

  .identity-heading {
    align-items: center;
  }

  .stock-card-quote {
    text-align: center;
  }

  .quote-item {
    align-items: center;
  }

  .quote-price-row {
    justify-content: center;
  }

  .chart-plot {
    height: 160px;
  }

  .heartbeat-gauge {
    width: 96px;
    height: 96px;
  }

  .heartbeat-gauge-inner {
    width: 72px;
    height: 72px;
  }

  .heartbeat-number {
    font-size: 1.5rem;
  }
}
