/* ─── Variables ─────────────────────────────────────────── */
:root {
  --bg:           #0a2214;
  --bg2:          #112b1a;
  --panel-bg:     #f0d890;
  --panel-bg2:    #e8ca78;
  --panel-border: #c8922a;
  --panel-shadow: #6b4700;
  --header-bg:    #0d3d1e;
  --gold:         #f5c518;
  --gold2:        #d4a017;
  --green-bright: #2db84c;
  --green-mid:    #1a6b35;
  --text-dark:    #1a0800;
  --text-light:   #f0d890;
  --text-dim:     #a07030;
  --red:          #c0392b;
  --font-pixel:   'Press Start 2P', monospace;
  --font-mono:    'VT323', monospace;
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text-dark);
  font-family: var(--font-mono);
  font-size: 22px;
  /* pixel-grid background */
  background-image: radial-gradient(rgba(45,184,76,0.12) 1px, transparent 1px);
  background-size: 10px 10px;
}

/* ─── Header ─────────────────────────────────────────────── */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  border-bottom: 4px solid var(--gold2);
  padding: 10px 16px;
  box-shadow: 0 4px 0 var(--panel-shadow);
  z-index: 1000;
  gap: 12px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon { font-size: 24px; }
header h1 {
  font-family: var(--font-pixel);
  font-size: 15px;
  color: var(--gold);
  text-shadow: 3px 3px 0 #000, -1px -1px 0 #000;
  letter-spacing: 1px;
  white-space: nowrap;
}
.header-sub {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--green-bright);
  border-left: 2px solid var(--gold2);
  padding-left: 10px;
  display: none;
}
.docs-link {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--gold);
  text-decoration: none;
  border: 3px solid var(--gold2);
  padding: 6px 10px;
  background: var(--bg);
  white-space: nowrap;
  align-self: center;
}
.docs-link:hover { background: var(--green-mid); }
.header-right { display: flex; gap: 10px; }
.stat-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  border: 3px solid var(--gold2);
  padding: 4px 10px;
  min-width: 80px;
}
.badge-val {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}
.badge-lbl {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--green-bright);
  margin-top: 2px;
}

/* ─── Main layout ────────────────────────────────────────── */
.main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ─── Map ────────────────────────────────────────────────── */
#map {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 180px;
  border-right: 4px solid var(--gold2);
  background: #1a3d25;
  transition: flex-basis 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}
.main-layout.has-selection #map {
  flex: 0 0 40%;
}
/* Game-style green tint on tiles */
.leaflet-tile-pane {
  filter: hue-rotate(85deg) saturate(1.8) brightness(0.88) contrast(1.05);
}
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(0,0,0,0.6) !important;
  color: #aaa !important;
}
.leaflet-control-zoom a {
  font-family: var(--font-pixel) !important;
  font-size: 10px !important;
  background: var(--header-bg) !important;
  color: var(--gold) !important;
  border: 2px solid var(--gold2) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--green-mid) !important;
}

/* Custom marker clusters */
.wbgt-cluster-icon { background: transparent; border: none; }
.cluster-div {
  text-align: center;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  border: 3px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  flex: 0 0 370px;
  background: var(--bg2);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: flex-basis 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--gold2) var(--bg);
}
.main-layout.has-selection .sidebar {
  flex: 1 1 60%;
}

/* In selection mode: table expands to fill available vertical space */
.main-layout.has-selection .table-scroll {
  max-height: calc(100vh - 480px);
  min-height: 180px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: var(--bg); }
.sidebar::-webkit-scrollbar-thumb { background: var(--gold2); border: 1px solid #000; }

/* ─── Panels ─────────────────────────────────────────────── */
.panel {
  background: var(--panel-bg);
  border: 4px solid var(--panel-border);
  box-shadow: 4px 4px 0 var(--panel-shadow);
  margin: 8px;
  overflow: hidden;
}
.panel-title {
  background: var(--green-mid);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 7px 10px;
  border-bottom: 3px solid var(--green-bright);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
  letter-spacing: 1px;
}
.panel > p,
.site-mobile-note {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-dim);
  font-style: italic;
}
.panel-hint {
  font-family: var(--font-mono);
  font-size: 20px;
  color: var(--text-dark);
  padding: 10px 12px 4px;
  line-height: 1.5;
}
.formula {
  font-family: var(--font-mono);
  font-size: 21px;
  color: var(--green-mid);
  padding: 6px 12px 12px;
  font-weight: bold;
}

/* ─── Site details ───────────────────────────────────────── */
#site-details {
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 21px;
  line-height: 1.8;
}
#site-details strong { font-family: var(--font-pixel); font-size: 11px; color: var(--green-mid); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn-back, .btn-load {
  display: block;
  width: calc(100% - 24px);
  margin: 6px 12px 12px;
  font-family: var(--font-pixel);
  font-size: 11px;
  padding: 9px 12px;
  cursor: pointer;
  border: 3px solid #000;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.07s, box-shadow 0.07s;
}
.btn-back {
  background: var(--red);
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.btn-load {
  background: var(--green-bright);
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  margin-top: 8px;
}
.btn-back:hover, .btn-load:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #000;
}
.btn-back:active, .btn-load:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}

/* ─── Date range ─────────────────────────────────────────── */
.date-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
}
.date-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.date-group label {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--green-mid);
}
.date-group input[type="date"] {
  font-family: var(--font-mono);
  font-size: 20px;
  padding: 5px 7px;
  border: 3px solid var(--panel-border);
  background: #fff9e6;
  color: var(--text-dark);
  outline: none;
  width: 100%;
}
.date-group input[type="date"]:focus {
  border-color: var(--green-mid);
}

/* ─── Stats table ────────────────────────────────────────── */
#stats-content { padding: 10px 12px; }
.stats-tbl {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 21px;
}
.stats-tbl th {
  background: var(--green-mid);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 6px 5px;
  border: 2px solid var(--green-bright);
  text-align: center;
}
.stats-tbl td {
  padding: 5px 7px;
  border: 2px solid var(--panel-border);
  text-align: center;
  background: #fffde8;
}
.stats-tbl tr:nth-child(even) td { background: var(--panel-bg2); }
.stats-tbl .row-lbl td:first-child {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-dark);
  background: #e0d080;
  text-align: left;
  padding-left: 8px;
}
.wbgt-cell { font-weight: bold; }
.stats-meta {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--text-dim);
  padding: 5px 2px 0;
}

/* ─── Chart ──────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg);
  margin: 10px;
  padding: 8px;
  border: 3px solid var(--panel-border);
  height: 220px;
  position: relative;
}

/* ─── Readings table ─────────────────────────────────────── */
#readings-count {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--gold);
  font-weight: normal;
  margin-left: 4px;
}
.table-scroll {
  max-height: 340px;
  overflow-y: auto;
  padding: 10px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold2) var(--panel-bg2);
}
.readings-tbl {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 20px;
  white-space: nowrap;
}
.readings-tbl th {
  position: sticky;
  top: 0;
  background: var(--green-mid);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 5px 4px;
  border: 2px solid var(--green-bright);
  text-align: center;
  z-index: 1;
}
.readings-tbl td {
  padding: 3px 6px;
  border: 1px solid var(--panel-border);
  background: #fffde8;
  text-align: center;
}
.readings-tbl tr:nth-child(even) td { background: var(--panel-bg2); }
.readings-tbl td:first-child {
  text-align: left;
  font-size: 19px;
  white-space: nowrap;
}

/* ─── Legend ─────────────────────────────────────────────── */
/* ─── Threshold preset controls ──────────────────────────── */
.threshold-controls {
  padding: 8px 12px 4px;
  border-bottom: 2px solid var(--panel-border);
}
.threshold-controls-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 8px;
  border-bottom: 2px solid var(--panel-border);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.threshold-label {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-dim);
  white-space: nowrap;
}
.threshold-controls-inline .threshold-select {
  flex: 1;
  min-width: 140px;
  width: auto;
}
.threshold-controls-inline .threshold-source {
  font-size: 13px;
  margin-top: 0;
  color: var(--text-dim);
  flex: 0 0 100%;
}
.threshold-select {
  width: 100%;
  background: var(--bg);
  color: var(--gold);
  border: 2px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23f5c518' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.threshold-select:focus { outline: 2px solid var(--gold); }
.threshold-select option { background: var(--bg2); color: var(--gold); }
.threshold-source {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text-dim);
  margin-top: 5px;
  line-height: 1.4;
}

.legend {
  list-style: none;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 21px;
  color: var(--text-dark);
}
.legend-dot {
  width: 18px;
  height: 18px;
  border: 3px solid #000;
  flex-shrink: 0;
  display: inline-block;
}
.legend-range {
  font-size: 18px;
  color: var(--text-dim);
  margin-left: auto;
}

/* ─── Loading / states ───────────────────────────────────── */
.loading-text {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--green-mid);
  padding: 16px 0;
  text-align: center;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.no-data {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--red);
  padding: 16px 0;
  text-align: center;
}

/* ─── WBGT colored value cells ───────────────────────────── */
.wbgt-none    { color: #4499ff; }
.wbgt-low     { color: #22aa44; }
.wbgt-mod     { color: #b8860b; }
.wbgt-high    { color: #dd5500; }
.wbgt-vhigh   { color: #cc1100; }
.wbgt-extreme { color: #880088; }

/* ─── Export buttons ─────────────────────────────────────── */
.export-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 10px 12px 12px;
}
.btn-export {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 8px 6px;
  cursor: pointer;
  border: 3px solid #000;
  box-shadow: 2px 2px 0 #000;
  text-align: center;
  line-height: 1.6;
  transition: transform 0.07s, box-shadow 0.07s;
  text-decoration: none;
  display: block;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.btn-export:hover  { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 #000; }
.btn-export:active { transform: translate(1px,1px);  box-shadow: 1px 1px 0 #000; }
.btn-export-readings { background: #1a6b35; }
.btn-export-full     { background: #0d4a7a; }
.btn-export-hourly   { background: #5a2d82; }
.btn-export-stats    { background: #7a3a00; }
.export-note {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--text-dim);
  padding: 0 12px 8px;
  text-align: center;
}

/* ─── Footer ─────────────────────────────────────────────── */
footer {
  flex-shrink: 0;
  background: var(--header-bg);
  border-top: 3px solid var(--gold2);
  display: flex;
  justify-content: space-between;
  padding: 5px 14px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 800px) {
  .main-layout { flex-direction: column; }
  #map { min-height: 280px; border-right: none; border-bottom: 4px solid var(--gold2); }
  #map, .main-layout.has-selection #map { flex: 0 0 auto; }
  .sidebar, .main-layout.has-selection .sidebar { flex: 0 0 auto; max-width: 100%; width: 100%; }
  header h1 { font-size: 10px; }
  .badge-val { font-size: 11px; }
  footer { display: none; }
  .export-btns { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
  .header-sub { display: block; }
}
