/* market.css (BUY-024).
 *
 * Trends panel content: toolbar, charts, live buyer figures, district tables.
 * Use the theme variables from style.css :root for any colour that should
 * follow the theme.
 *
 * Loaded after style.css, so a rule here with the same selector refines the
 * BUY-014 base rules. The panel container (#market-panel and its sheet card)
 * belongs to shell.css; everything inside #market-host is styled here. Data
 * colours (the comparison hues, the range bar) stay literal where a theme
 * variable would change their meaning.
 */

/* The sheet card sets the width; the old 820px cap left a gutter on a PC. */
.market-host {
  max-width: none;
}

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

/* ==========================================================================
   Toolbar
   ========================================================================== */

.market-toolbar {
  display: grid;
  gap: 8px;
  padding: 10px 0 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}

.market-toolbar-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.market-toolbar-row--extras {
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.market-toolbar-label {
  flex: 0 0 52px;
  padding-top: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.market-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.market-pill {
  min-height: 34px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--panel-raised, #1e293b);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.market-pill[aria-pressed="true"] {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--text-main);
}

.market-pill:active,
.market-back:active,
.market-action:active {
  transform: scale(0.97);
}

.market-host button:focus-visible,
.market-host select:focus-visible,
.market-host .spark[data-scrub]:focus-visible {
  outline: 2px solid var(--info, #38bdf8);
  outline-offset: 2px;
}

.market-pick {
  margin-bottom: 0;
  margin-right: 4px;
}

.market-pick select {
  min-height: 34px;
  background: var(--input-bg, #111c33);
  border-radius: var(--radius-sm);
}

.market-toolbar-note,
.market-slice-note {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 6px;
}

.market-toolbar-note {
  margin: 0;
}

/* Back out of a drilled-in district: kept in reach while the cards scroll. */
.market-back {
  position: sticky;
  top: 0;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  margin: 10px 0 2px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel-raised, #1e293b);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  color: var(--text-main);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   Series cards and charts
   ========================================================================== */

.market-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.market-card-head h3 {
  margin: 0;
}

.market-charts {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.market-chart figcaption {
  display: grid;
  gap: 1px;
  margin-bottom: 4px;
}

/* The reading under a finger or the mouse; it never wraps the chart down. */
.market-chart figcaption strong {
  min-height: 1.4em;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.market-chart .spark {
  width: 100%;
  height: auto;
}

.spark[data-scrub] {
  touch-action: pan-y;
  cursor: crosshair;
  border-radius: var(--radius-sm);
}

.spark-empty-text {
  fill: var(--text-dim);
  font-size: 11px;
}

/* Neutral rather than amber: amber is the third comparison hue. */
.spark-ref {
  stroke: var(--text-soft, #cbd5e1);
  stroke-width: 1.25;
  stroke-dasharray: 4 3;
  opacity: 0.85;
}

.spark-cursor {
  stroke: var(--text-muted);
  stroke-width: 1;
  pointer-events: none;
}

.spark-cursor-dot {
  fill: var(--text-main);
  stroke: var(--bg-primary);
  stroke-width: 1.5;
  pointer-events: none;
}

.compare-line {
  fill: none;
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* ==========================================================================
   Today's homes beside a series, and the range bar
   ========================================================================== */

.market-live {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card, #111c33);
}

.market-live-title {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.market-live-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
}

.market-live-stats strong {
  color: var(--text-main);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.market-live-wards {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.market-action {
  margin-top: 10px;
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent, #052e16);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.market-action:hover {
  background: var(--accent-hover);
}

.market-action-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.market-range {
  max-width: 440px;
  margin: 8px 0 4px;
}

.market-range-caption,
.market-range-words {
  font-size: 11px;
  color: var(--text-dim);
}

.market-range-caption {
  margin-bottom: 5px;
}

.market-range-words {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.market-range-track {
  position: relative;
  display: block;
  height: 10px;
  border-radius: 5px;
  background: rgba(var(--overlay-rgb, 255, 255, 255), 0.08);
}

.market-range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 5px;
  background: #34d399;
  opacity: 0.55;
}

.market-range--over .market-range-fill {
  background: #f87171;
}

.market-range-median {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--text-main);
}

.market-range-ceiling {
  position: absolute;
  top: -4px;
  bottom: -4px;
  margin-left: -1px;
  border-left: 2px dashed var(--warning-strong, #fbbf24);
}

.market-range--compact {
  display: inline-grid;
  gap: 3px;
  width: 112px;
  margin: 0;
  vertical-align: middle;
}

.market-range--compact .market-range-track {
  height: 8px;
}

.market-range-text {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==========================================================================
   Comparison
   ========================================================================== */

.market-compare {
  padding: 12px 0;
  border-top: 1px solid var(--border-color);
}

.market-compare-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 4px 0 6px;
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
}

.market-compare-legend strong {
  color: var(--text-main);
}

.market-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}

.market-compare-axis {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-dim);
}

.market-compare-empty {
  font-size: 12px;
  color: var(--text-dim);
}

.market-compare-toggle {
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.market-compare-toggle[aria-pressed="true"] {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--text-main);
}

.market-compare-toggle:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ==========================================================================
   Tables: the slice overview and the run-by-run table under each card
   ========================================================================== */

/* The run table scrolls inside its own box so its first column can stick. */
.market-table {
  overflow: visible;
}

.market-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.market-overview td,
.market-overview th,
.market-table td,
.market-table th {
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

/* The first column stays put while the rest scrolls sideways on a phone. */
.market-overview th:first-child,
.market-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-primary);
  box-shadow: 1px 0 0 var(--border-color);
}

.market-overview tbody th {
  font-weight: 600;
  text-align: left;
}

.market-sort {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.market-overview th[aria-sort] .market-sort {
  color: var(--text-main);
  text-decoration-style: solid;
}

.market-district-link,
.market-row-link {
  min-height: 28px;
  background: none;
  border: none;
  padding: 0;
  color: var(--positive, #34d399);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.market-row-sub,
.market-mine {
  display: block;
  max-width: 14rem;
  font-size: 10.5px;
  font-weight: 400;
  line-height: 1.3;
  white-space: normal;
  color: var(--text-dim);
}

.market-mine {
  color: var(--warning-text, #fcd34d);
}

.market-no-history {
  color: var(--text-dim);
  font-style: italic;
}

.market-overview .spark {
  display: block;
}

/* ==========================================================================
   Phone (Pixel 8 Pro, 412px)
   ========================================================================== */

@media (max-width: 600px) {
  .market-toolbar-row:not(.market-toolbar-row--extras) {
    flex-direction: column;
    gap: 4px;
  }

  .market-toolbar-label {
    flex: none;
    padding-top: 0;
  }

  .market-pill,
  .market-back,
  .market-pick select {
    min-height: 38px;
  }

  .market-hero {
    font-size: 22px;
  }

  /* One chart per row: 31 runs across the full width leave a finger about
     12px per run, where two columns would leave 6px. */
  .market-charts {
    grid-template-columns: 1fr;
  }

  /* Two lines of ward names at most beside a sticky column; the drilled-in
     card lists them in full. */
  .market-row-sub,
  .market-mine {
    max-width: 7.5rem;
  }

  .market-row-sub {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  .market-live-stats {
    gap: 4px 12px;
  }
}
