/*
 * Florida Emerging: styles.
 * Colours are CSS variables so charts (read via getComputedStyle in app.js) and the page share
 * one palette. The dark-mode block swaps every variable; nothing else changes for dark mode.
 */

/* ---------- design tokens (light) ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --up: #006300;
  --down: #c03030;
  --accent: #2a78d6;
  /* --s1..--s8: industry series colours (fixed slot per industry, colourblind-checked order) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  /* --seq-*: one-hue blue ramp for momentum (light = low, dark = high) */
  --seq-1: #b7d3f6; --seq-2: #6da7ec; --seq-3: #256abf; --seq-4: #104281;
  /* growth bars: blue for up, red for down */
  --div-pos: #2a78d6; --div-neg: #e34948;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
/* ---------- design tokens (dark): same roles, steps re-picked for the dark surface ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --up: #0ca30c;
    --down: #e66767;
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-1: #184f95; --seq-2: #256abf; --seq-3: #5598e7; --seq-4: #9ec5f4;
    --div-pos: #3987e5; --div-neg: #e66767;
    --shadow: none;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select { font: inherit; color: inherit; }

/* ---------- header, tabs and filter bar ---------- */
.sample-banner { background: var(--surface-2); color: var(--ink-2); text-align: center; padding: 6px 16px; font-size: 12.5px; border-bottom: 1px solid var(--border); }

.app-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 22px 32px 0; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; }
.brand-mark { flex: none; /* never squash the logo on narrow screens */ width: 30px; height: 30px; border-radius: 8px; background: conic-gradient(from 200deg, var(--s1), var(--s3), var(--s1)); position: relative; }
/* the ring in the logo: a solid circle punched out of the conic gradient */
.brand-mark::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--page); }
.brand h1 { font-size: 18px; letter-spacing: -0.01em; }
.brand-sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }

/* Tabs scroll sideways when they don't fit (phones) instead of widening the page. */
.tabs { display: flex; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; white-space: nowrap; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px 12px; color: var(--ink-2); cursor: pointer; font-weight: 500; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* filter bar sticks to the top while scrolling */
.filters { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; padding: 12px 32px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 500; }
.filters label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.filters select { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 6px 28px 6px 10px; color: var(--ink); }
.filters-note { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* ---------- layout ---------- */
main { padding: 24px 32px 48px; max-width: 1440px; margin: 0 auto; }
.view[hidden] { display: none; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
/* Market pulse tab has three headline numbers instead of four. */
.kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { color: var(--ink-2); font-size: 12.5px; }
.kpi-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin: 6px 0 4px; line-height: 1.1; }
.kpi-value.text { font-size: 20px; letter-spacing: -0.01em; }
.kpi-foot { font-size: 12.5px; color: var(--muted); }
.delta-up { color: var(--up); font-weight: 600; }
.delta-down { color: var(--down); font-weight: 600; }

/* ---------- cards and chart containers ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.card-sub { margin: 3px 0 0; color: var(--ink-2); font-size: 12.5px; max-width: 70ch; }
.chart { width: 100%; }

.table-toggle { margin-top: 8px; color: var(--ink-2); font-size: 12.5px; }
.table-toggle summary { cursor: pointer; width: max-content; }
.table-toggle .data-table { margin-top: 8px; }

.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 0; font-weight: 500; white-space: nowrap; }
.btn { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }

/* ---------- fastest-growing list ---------- */
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: grid; grid-template-columns: 22px minmax(0, 1fr) 120px; gap: 10px; align-items: center; padding: 9px 4px; border-top: 1px solid var(--grid); cursor: pointer; border-radius: 6px; }
.leaderboard li:first-child { border-top: 0; }
.leaderboard li:hover, .leaderboard li:focus-visible { background: var(--surface-2); outline: none; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.lb-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-meta { color: var(--ink-2); font-size: 12px; display: flex; gap: 6px; align-items: center; }

/* industry colour square and momentum mini-bar, reused across views */
.swatch { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }
.meter { display: flex; align-items: center; gap: 8px; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.meter-track { width: 64px; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }

/* ---------- map ---------- */
.map-card { padding-bottom: 20px; }
#map { height: calc(100vh - 290px); min-height: 460px; border-radius: 8px; border: 1px solid var(--border); }
.legend-seq { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.legend-seq i { width: 18px; height: 10px; display: inline-block; border-radius: 2px; }
.legend-seq span:first-child { margin-right: 4px; }
.legend-seq span:last-child { margin-left: 4px; }
.leaflet-popup-content { font: 13px/1.4 var(--font); }
.popup-name { font-weight: 600; margin-bottom: 2px; }
.popup-meta { color: #52514e; }

/* ---------- businesses table ---------- */
.table-tools { display: flex; gap: 8px; }
.table-tools input { width: 280px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-weight: 500; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; user-select: none; }
.data-table th[data-sort] { cursor: pointer; }
.data-table th[data-sort]:hover { color: var(--ink); }
/* sort arrow on the active column */
.data-table th.sorted::after { content: " ↓"; }
.data-table th.sorted.asc::after { content: " ↑"; }
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.cell-name { font-weight: 500; }
.cell-sub { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sector-cell { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; color: var(--ink-2); font-size: 12.5px; }
.pager div { display: flex; gap: 6px; }

/* ---------- emerging: alert cards and breakout cards ---------- */
.alerts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.alert { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--page); display: grid; gap: 8px; }
.alert-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.alert-tag { font-size: 12px; font-weight: 600; display: inline-flex; gap: 5px; align-items: center; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
.alert-tag.up { color: var(--up); }
.alert-tag.down { color: var(--down); }
.alert-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.alert-text { color: var(--ink-2); font-size: 12.5px; }
.alert svg { width: 100%; height: 44px; display: block; }
.empty { color: var(--muted); padding: 12px 0; }

.breakouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.breakout { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--page); cursor: pointer; }
.breakout:hover, .breakout:focus-visible { background: var(--surface-2); outline: none; }
.breakout-name { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }

/* ---------- data sources tab ---------- */
.sub-h { font-size: 14px; margin: 24px 0 8px; }
/* About tab: readable line length and spacing for long-form text. */
.prose { max-width: 760px; }
.prose h2 { font-size: 18px; margin: 0 0 8px; }
.prose h3 { font-size: 14px; margin: 22px 0 6px; }
.prose p, .prose li { color: var(--ink-2); line-height: 1.6; }
.prose ul { padding-left: 18px; margin: 0; }
.prose li { margin: 4px 0; }
.prose a { color: var(--accent); }
.prose .credits { font-size: 12.5px; color: var(--muted); }
.method { margin: 0; padding-left: 18px; color: var(--ink-2); }
.method li { margin: 4px 0; }
.role { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }

/* ---------- detail drawer (slides in from the right) ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--surface); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .22s ease; z-index: 1000; overflow-y: auto; box-shadow: -8px 0 32px rgba(0,0,0,.08); }
.drawer.open { transform: none; }
.drawer-inner { padding: 24px; position: relative; }
.drawer-close { position: absolute; top: 14px; right: 14px; border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink-2); width: 32px; height: 32px; border-radius: 6px; }
.drawer-close:hover { background: var(--surface-2); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 999; }
.d-name { font-size: 19px; letter-spacing: -0.01em; padding-right: 36px; }
.d-meta { color: var(--ink-2); margin: 6px 0 16px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 20px; }
.d-grid dt { color: var(--muted); font-size: 12px; }
.d-grid dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
/* signal history: vertical line with a dot per event */
.timeline { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--axis); margin-left: 5px; }
.timeline li { position: relative; padding: 0 0 14px 18px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); box-sizing: border-box; }
.timeline .t-date { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline .t-src { font-size: 11.5px; color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; margin-left: 6px; }

/* mute map colours so the data dots stand out */
.leaflet-tile-pane { filter: saturate(.35); }
/* OSM tiles are light only; dim and invert them in dark mode */
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
}
/* ---------- narrow screens: stack the grid, two KPI columns ---------- */
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.kpis-3 { grid-template-columns: minmax(0, 1fr); } /* stack the Market pulse numbers */
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .app-header, .filters, main { padding-left: 16px; padding-right: 16px; }
  .filters-note { margin-left: 0; width: 100%; }
  .table-tools input { width: 100%; }
  .card-head { flex-direction: column; }
  /* Narrow screens: smaller tab padding so more tabs show. */
  .tabs button { padding: 10px 10px 12px; }
  .app-header { padding-top: 16px; gap: 8px; }
  .table-tools { width: 100%; }
}
/* Phones only: filters stack full width, and the bar scrolls away (too tall to pin). */
@media (max-width: 600px) {
  .filters { position: static; }
  .filters label { flex: 1 1 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .filters select { flex: 0 1 65%; }
}
