/* F&O Heatmap — styles.css (rewrite) */
:root {
  --bg:              #0b0e13;
  --surface:         #151a21;
  --surface2:        #1c232d;
  --on-surface:      #e1e6ed;
  --on-surface-muted:#7a8694;
  --primary:         #4fc3f7;
  --primary-muted:   #1e3a4a;
  --neutral:         #3a4250;
  --border:          rgba(255,255,255,0.08);
  --shadow:          0 2px 8px rgba(0,0,0,0.6);
  --shadow-hover:    0 8px 24px rgba(0,0,0,0.8);
  --radius-card:     12px;
  --font-ui:         'Roboto', sans-serif;
  --font-mono:       'Roboto Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;          /* no page scroll — treemap fills viewport */
}

body {
  background: var(--bg);
  color: var(--on-surface);
  font-family: var(--font-ui);
}

/* ── App bar ── */
.app-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--on-surface);
  white-space: nowrap;
}
.app-brand {
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: block;
}

.spacer { flex: 1; }

/* ── Breadth bar ── */
.breadth-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}
.breadth-label {
  font-size: 0.7rem;
  color: var(--on-surface-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.breadth-bar-outer {
  height: 8px;
  border-radius: 4px;
  background: var(--neutral);
  flex: 1;
  overflow: hidden;
  min-width: 80px;
}
.breadth-bar-inner {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(to right, #e53935, #1aa260);
  transition: width 0.6s ease;
}

/* ── Timestamp chip ── */
.updated-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--on-surface-muted);
  white-space: nowrap;
  transition: border-color 0.3s, color 0.3s;
}
.updated-chip.stale { border-color: #f57c00; color: #f57c00; }

/* ── Search ── */
.search-wrap { position: relative; }
.search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 14px 6px 36px;
  font-size: 0.82rem;
  color: var(--on-surface);
  font-family: var(--font-ui);
  width: 170px;
  outline: none;
  transition: border-color 0.2s, width 0.3s;
}
.search-input:focus { border-color: var(--primary); width: 210px; }
.search-icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--on-surface-muted);
  font-size: 1rem;
  pointer-events: none;
}

/* ── Segmented toggle ── */
.seg-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
  flex-shrink: 0;
}
.seg-btn {
  background: none;
  border: none;
  color: var(--on-surface-muted);
  padding: 6px 14px;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.seg-btn.active {
  background: var(--primary-muted);
  color: var(--primary);
  font-weight: 500;
}

/* ── Main / heatmap ── */
.main {
  /* no padding — treemap is full-bleed */
  position: relative;
  height: calc(100vh - 64px);
  overflow: hidden;
}

#heatmap {
  width: 100%;
  height: 100%;
  position: relative;
}

/* SVG fills the heatmap div */
.treemap-svg {
  display: block;
}

/* ── Tile styles (SVG) ── */
.tile rect {
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
  transition: fill 0.6s ease;
}
.tile:hover rect {
  filter: brightness(1.18);
  stroke: rgba(255,255,255,0.35);
  stroke-width: 1.5;
}
.tile text {
  pointer-events: none;
}
.tile .sym {
  font-weight: 700;
}
.tile .pct {
  font-weight: 400;
}
.tile.dimmed { opacity: 0.1; }
.tile .ripple {
  fill: rgba(255,255,255,0.18);
  pointer-events: none;
}

/* ── Hover detail card ── */
#detail-card {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-hover);
  pointer-events: none;
  z-index: 1000;
  min-width: 180px;
  max-width: 240px;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.15s, transform 0.15s;
  backdrop-filter: blur(16px);
}
#detail-card.visible { opacity: 1; transform: scale(1); }
.dc-symbol {
  font-size: 1rem;
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 2px;
}
.dc-sector {
  font-size: 0.7rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.dc-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.dc-label { font-size: 0.7rem; color: var(--on-surface-muted); }
.dc-value { font-family: var(--font-mono); font-size: 0.83rem; color: var(--on-surface); }
.dc-pchange {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 6px;
}
.dc-pchange.pos { color: #66bb6a; }
.dc-pchange.neg { color: #ef5350; }

/* ── Legend ── */
#legend {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 50;
  min-width: 200px;
}
.legend-title {
  font-size: 0.66rem;
  color: var(--on-surface-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.legend-gradient {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #c62828, #e53935, #3a4250, #1aa260, #0b8043);
  margin-bottom: 4px;
}
.legend-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.63rem;
  font-family: var(--font-mono);
  color: var(--on-surface-muted);
}

/* ── Loading spinner ── */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  flex-direction: column;
  gap: 16px;
  color: var(--on-surface-muted);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--surface2);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .tile rect, #detail-card, .breadth-bar-inner { transition: none !important; }
  .spinner { animation: none; }
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .app-bar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .breadth-wrap { min-width: unset; width: 100%; }
  .search-input { width: 130px; }
  .search-input:focus { width: 155px; }
  .main { height: calc(100vh - 112px); }
  #legend { right: 8px; bottom: 8px; min-width: 160px; }
}
