:root {
  --bg: #0b0a0f;
  --bg-panel: #16141d;
  --bg-panel-2: #1e1b27;
  --border: #2c2735;
  --fg: #f3ede0;
  --fg-dim: #b3ab9c;
  --fg-faint: #7d7566;

  --gold: #cda868;
  --emerald: #2fae6e;
  --ruby: #e0435f;
  --citrine: #f0c14b;
  --amethyst: #a78bda;
  --aqua: #4fd1c5;
  --topaz: #f2994a;
  --sapphire: #5b7fd1;

  --map-empty: #211f29;
  --map-low: #3a3350;
  --map-high: var(--gold);

  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(205, 168, 104, 0.08), transparent),
    radial-gradient(1000px 500px at 100% 0%, rgba(167, 139, 218, 0.06), transparent),
    var(--bg);
}

a {
  color: var(--gold);
}

.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* Header */

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand .kicker {
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.brand h1 {
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 30px;
  letter-spacing: 0.04em;
  margin: 0;
  background: linear-gradient(120deg, #fff 0%, var(--gold) 55%, #fff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--fg-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
  display: inline-block;
  animation: pulse 2.4s ease-in-out infinite;
}

.dot.stale {
  background: var(--topaz);
  box-shadow: 0 0 8px var(--topaz);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

button.refresh {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

button.refresh:hover {
  border-color: var(--gold);
}

button.refresh:active {
  transform: scale(0.97);
}

button.refresh svg {
  width: 14px;
  height: 14px;
}

button.refresh.loading svg {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Filter bar */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 22px;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  display: block;
  margin-bottom: 4px;
}

.filter-field {
  display: flex;
  flex-direction: column;
}

.filters input[type="date"],
.filters input[type="search"],
.filters select {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  min-width: 130px;
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--gold);
}

.gem-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 360px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--fg-dim);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.chip.active {
  color: #0b0a0f;
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 600;
}

.chip.state-chip.active {
  background: var(--sapphire);
  border-color: var(--sapphire);
}

.clear-filters {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}

.clear-filters:hover {
  border-color: var(--ruby);
  color: var(--ruby);
}

/* KPI row */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.kpi {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.kpi .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin-bottom: 6px;
}

.kpi .value {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 26px;
  font-weight: 600;
  color: var(--fg);
}

.kpi .value.accent-gold { color: var(--gold); }
.kpi .value.accent-emerald { color: var(--emerald); }
.kpi .value.accent-ruby { color: var(--ruby); }
.kpi .value.accent-aqua { color: var(--aqua); }

/* Panels / grid */

.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.grid-2b {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .grid-2, .grid-2b {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--fg);
}

.panel .sub {
  font-size: 12px;
  color: var(--fg-faint);
  margin: 0 0 14px;
}

/* Map */

#map-wrap {
  position: relative;
}

#us-map {
  width: 100%;
  height: auto;
  display: block;
}

.state-path {
  stroke: var(--bg);
  stroke-width: 1;
  cursor: pointer;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.state-path:hover {
  stroke: var(--gold);
  stroke-width: 1.6;
}

.state-path.selected {
  stroke: #fff;
  stroke-width: 2;
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--fg-faint);
  margin-top: 10px;
}

.legend-bar {
  width: 120px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--map-empty), var(--map-low), var(--map-high));
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: #0e0d13;
  border: 1px solid var(--gold);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.1s ease;
  box-shadow: var(--shadow);
}

.tooltip.visible {
  opacity: 1;
}

.tooltip .t-title {
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 2px;
}

/* Bar charts */

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 12px;
}

.bar-row .bar-label {
  width: 110px;
  flex-shrink: 0;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row .bar-track {
  flex: 1;
  height: 12px;
  background: var(--bg-panel-2);
  border-radius: 6px;
  overflow: hidden;
}

.bar-row .bar-fill {
  height: 100%;
  border-radius: 6px;
}

.bar-row .bar-value {
  width: 76px;
  flex-shrink: 0;
  text-align: right;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

/* Time series (simple SVG line) */

#time-series-chart {
  width: 100%;
  height: 160px;
  display: block;
}

/* Table */

.table-scroll {
  overflow-x: auto;
}

table.sales-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.sales-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
}

table.sales-table th:hover {
  color: var(--gold);
}

table.sales-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-dim);
  white-space: nowrap;
}

table.sales-table tr:hover td {
  background: var(--bg-panel-2);
  color: var(--fg);
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--fg-dim);
}

.empty-state {
  text-align: center;
  color: var(--fg-faint);
  padding: 40px 0;
  font-size: 13px;
}

.error-banner {
  background: rgba(224, 67, 95, 0.12);
  border: 1px solid var(--ruby);
  color: #ffb3c0;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
}

.footer-note {
  margin-top: 28px;
  font-size: 11px;
  color: var(--fg-faint);
  text-align: center;
}
