:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --hot: #f97316;
  --cool: #60a5fa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  z-index: 1000;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-bar {
  width: 90px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #22c55e, #eab308, #ef4444);
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.map-container {
  flex: 1;
  height: 100%;
  min-width: 0;
  min-height: 360px;
  transition: width 0.25s ease, flex 0.25s ease;
}

.detail-panel {
  width: 460px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, flex-basis 0.25s ease;
}

/* Expanded station view: leaves a slim map strip on the left so you can minimise or pick another pin */
.layout.station-expanded .map-container {
  flex: 0 0 240px;
}

.layout.station-expanded .detail-panel {
  flex: 1;
  width: auto;
  max-width: none;
}

/* Minimised station view: keeps a compact panel while map fills the screen */
.layout.station-minimised .detail-panel {
  width: 310px;
  padding: 12px 14px;
}

.layout.station-minimised .latest-cards,
.layout.station-minimised .doy-section {
  display: none;
}

.empty-state {
  margin: auto 0;
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
}

.empty-state h2 {
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 8px;
}

.hidden {
  display: none !important;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.muted {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 1rem;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.latest-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card,
.mini-card {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.stat-value.small {
  font-size: 0.9rem;
}

.stat-value.hot {
  color: var(--hot);
}

.stat-value.cool {
  color: var(--cool);
}

.mini-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.doy-section {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.section-heading h3 {
  margin: 0;
  font-size: 0.98rem;
}

.doy-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.field-group {
  flex: 1 1 135px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-group label {
  font-size: 0.72rem;
  color: var(--muted);
}

.doy-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

/* Two-column workspace: Left = Histogram + Matching Day Table, Right = Time Series + Range Table */
.two-col-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.layout.station-expanded .two-col-workspace {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.workspace-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.chart-box,
.table-card {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.chart-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chart-caption {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.chart-header-row .chart-caption {
  margin-bottom: 0;
}

.agg-control select {
  width: auto;
  padding: 4px 8px;
  font-size: 0.8rem;
}

.chart-canvas-wrap {
  position: relative;
  height: 230px;
}

.layout.station-expanded .chart-canvas-wrap {
  height: 265px;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 8px;
}

.sub-heading {
  margin: 0;
  font-size: 0.88rem;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sort-controls select {
  width: auto;
  padding: 6px 8px;
  font-size: 0.82rem;
}

.range-select-inline {
  flex: 1;
  min-width: 140px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.sort-th-btn {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sort-th-btn:hover {
  color: var(--accent);
}

.sort-ind {
  color: var(--accent);
  font-size: 0.78rem;
}

select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.88rem;
}

.secondary-btn {
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.secondary-btn:hover {
  border-color: var(--accent);
}

.table-wrap {
  height: 250px;
  overflow-y: auto;
  border: 1px solid rgba(51, 65, 85, 0.75);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
}

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

@media (max-width: 960px) {
  .doy-summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .layout.station-expanded .two-col-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .layout,
  .layout.station-expanded {
    flex-direction: column;
  }

  .map-container,
  .layout.station-expanded .map-container {
    height: 36vh;
    flex: none;
  }

  .detail-panel,
  .layout.station-expanded .detail-panel {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--panel-border);
  }
}
