/* Shared chrome for the tornado hindcast site. Dark UI; the domain color
   scales (SPC categories, PPH levels, EF ratings) are fixed conventions and
   live with the data, not the theme. */
:root {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #262a31;
  --border: #343943;
  --ink: #e8eaed;
  --ink-2: #aab0ba;
  --ink-3: #7a8089;
  --accent: #4a90d9;
  --accent-ink: #ffffff;
  --danger: #e15241;
  --radius: 8px;
  font-size: 15px;
}

* { box-sizing: border-box; }

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

/* ---- top nav ---- */
.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav .brand {
  font-weight: 700;
  font-size: 1.05rem;
  margin-right: 18px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.nav a.tab {
  color: var(--ink-2);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  white-space: nowrap;
}
.nav a.tab:hover { background: var(--surface-2); color: var(--ink); }
.nav a.tab.active { background: var(--surface-2); color: var(--ink); }

/* ---- layout ---- */
.page {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}
.sidebar {
  width: 320px;
  min-width: 320px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease, max-height 0.25s ease;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  border: none;
}
#sidebar-toggle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1100;
  width: 22px;
  height: 60px;
  padding: 0;
  border-radius: 0 8px 8px 0;
  border: 1px solid var(--border);
  border-left: none;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
#sidebar-toggle:hover { color: var(--ink); }
.main {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.scroll-page {
  height: calc(100vh - 52px);
  overflow-y: auto;
  padding: 20px;
}

/* ---- controls ---- */
.ctl-group {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.ctl-group:last-child { border-bottom: none; }
.ctl-group h3 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.ctl-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ctl-row label { color: var(--ink-2); font-size: 0.88rem; min-width: 86px; }
.ctl-row output { color: var(--ink); font-size: 0.88rem; min-width: 46px; text-align: right; }

input[type="date"], input[type="number"], input[type="text"], select {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.9rem;
  font-family: inherit;
}
input[type="range"] { flex: 1; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

button {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover:not(:disabled) { border-color: var(--ink-3); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.45; cursor: default; }

.status {
  font-size: 0.85rem;
  color: var(--ink-2);
  margin-top: 8px;
  line-height: 1.4;
  min-height: 1.2em;
  overflow-wrap: anywhere;
}
.status b { color: var(--ink); }

.toggle-list { display: flex; flex-direction: column; gap: 5px; }
.toggle-list label {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.88rem; color: var(--ink-2); cursor: pointer;
}
.toggle-row { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.toggle-row label { display: flex; align-items: center; gap: 5px; font-size: 0.86rem; color: var(--ink-2); cursor: pointer; }

.swatch { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }

.hint { font-size: 0.8rem; color: var(--ink-3); line-height: 1.45; }

.progress-bar {
  height: 4px; border-radius: 2px; background: var(--surface-2);
  overflow: hidden; margin-top: 8px; display: none;
}
.progress-bar .fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.25s; }

/* ---- map overlay boxes (inside the Leaflet container so exports catch them) ---- */
#map { position: absolute; inset: 0; background: #0b0c0e; }

.map-box {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 6px;
  font-family: Arial, sans-serif;
  font-weight: bold;
  color: #F5F5F5;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#map-title {
  top: 10px; left: 50%; transform: translateX(-50%);
  padding: clamp(4px, 0.8vw, 10px) clamp(10px, 1.6vw, 22px);
  font-size: clamp(13px, 1.8vw, 24px);
  border: 2px solid #F5F5F5;
  max-width: 92%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#max-prob-box {
  bottom: 12px; left: 10px;
  padding: clamp(4px, 0.67vw, 8px) clamp(6px, 1.0vw, 12px);
  min-width: clamp(90px, 12vw, 150px);
}
#max-prob-box .hdr { font-size: clamp(13px, 1.9vw, 24px); color: #F5F5F5; margin-bottom: 6px; line-height: 1; }
#max-prob-box .val { font-size: clamp(17px, 2.6vw, 32px); line-height: 1; }
#risk-box {
  left: 10px;
  padding: clamp(4px, 0.67vw, 8px) clamp(6px, 1.0vw, 12px);
  min-width: clamp(90px, 12vw, 150px);
  font-size: clamp(17px, 2.6vw, 32px);
  line-height: 1.1;
}
#rank-box {
  bottom: 12px; right: 10px;
  padding: clamp(4px, 0.8vw, 10px) clamp(10px, 1.6vw, 22px);
  font-size: clamp(13px, 1.9vw, 24px);
  border: 2px solid #F5F5F5;
  white-space: nowrap;
}
#era-box {
  /* sits centered right below #map-title; JS refines top to the title's
     actual height when shown */
  top: 60px; left: 50%; transform: translateX(-50%);
  padding: clamp(3px, 0.5vw, 6px) clamp(8px, 1.1vw, 14px);
  font-size: clamp(10px, 1.3vw, 15px);
  color: #FFD27F;
  border: 1.5px solid #FFD27F;
  white-space: nowrap;
}
#reports-box {
  right: 10px;
  padding: clamp(4px, 0.8vw, 10px) clamp(10px, 1.6vw, 22px);
  font-size: clamp(13px, 1.9vw, 24px);
  border: 2px solid #E10000;
  white-space: nowrap;
}
#colorbar {
  bottom: 8px; left: 50%; transform: translateX(-50%);
  width: min(62%, 520px);
  background: transparent;
  box-shadow: none;
}
#colorbar .cells { display: flex; height: clamp(18px, 2.2vw, 26px); border: 1px solid black; }
#colorbar .cells div {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: white; font-size: clamp(7px, 0.95vw, 12px); font-weight: bold;
  border-right: 1px solid black;
}
#colorbar .cells div:last-child { border-right: none; }
#colorbar .caption {
  margin-top: 4px; font-size: clamp(9px, 1.2vw, 13px); color: white;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, 2px 2px 0 #000;
}

/* Small site watermark, top-right of the map viewer. */
#watermark {
  position: absolute;
  bottom: 64px; left: 50%; transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 3px 8px;
  border-radius: 4px;
  opacity: 0.85;
}

/* Day Stats overlay: covers the map; X or Esc returns to it. */
#stats-panel {
  position: absolute;
  inset: 14px;
  z-index: 1400;
  display: none;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 26px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
#stats-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 15px;
  border-radius: 8px;
}
#stats-body h2 { margin: 0 0 2px; font-size: 1.25rem; }
#stats-body h3 {
  margin: 22px 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
#stats-body .sub { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 6px; }
.stat-tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 130px;
}
.stat-tile .v { font-size: 1.45rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stat-tile .k { font-size: 0.76rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
#stats-body .note { font-size: 0.8rem; color: var(--ink-3); line-height: 1.5; margin-top: 10px; max-width: 860px; }
#stats-body .cig-h { margin: 16px 0 8px; font-size: 0.95rem; font-weight: 700; color: var(--ink-2); }
#stats-body .cig-grid { display: flex; flex-wrap: wrap; gap: 12px; }
#stats-body .cig-chart {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px 2px;
  flex: 0 1 390px;
  min-width: 300px;
}
#cig-cycle { padding: 2px 6px; font-size: 0.85rem; }
#stats-body .rarity { font-size: 0.95rem; color: var(--ink-2); line-height: 1.6; max-width: 860px; }
#stats-body .rarity b { color: var(--ink); }

/* Transient status toast, centered over the map, above every overlay. */
#status-toast {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1500;
  display: none;
  pointer-events: none;
  max-width: min(70%, 560px);
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid #565d68;
  border-radius: 8px;
  color: #F0F2F5;
  font-size: 0.95rem;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
#status-toast b { color: #fff; }
#status-toast .progress-bar { margin-top: 10px; width: 100%; }

#cursor-tip {
  position: absolute; left: 0; top: 0; will-change: transform;
  z-index: 1200; pointer-events: none; display: none;
  font-family: Arial, sans-serif; font-weight: bold; font-size: 12px; line-height: 1;
  padding: 3px 6px; border-radius: 5px; background: rgba(0,0,0,0.72);
  border: 2px solid #CDCDCD; color: #CDCDCD; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.45);
}

.leaflet-control-attribution { font-size: 10px; }

/* Fractional-zoom tile hairlines/jank: force each tile onto its own clean GPU
   compositing layer (ported from the notebook's attribution_css). */
.leaflet-container img.leaflet-tile {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  will-change: transform;
  outline: 1px solid transparent;
  image-rendering: auto;
}
.leaflet-container .leaflet-tile-container {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  will-change: transform;
}
.leaflet-container .leaflet-tile-pane {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* ---- chart pages ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  max-width: 1200px;
}
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card .sub { color: var(--ink-2); font-size: 0.88rem; margin: 0 0 12px; }

.controls-row {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 12px;
}
.controls-row .field { display: flex; flex-direction: column; gap: 4px; }
.controls-row .field > span { font-size: 0.78rem; color: var(--ink-3); font-weight: 600; }

.chart-wrap { position: relative; width: 100%; overflow-x: auto; min-height: 42vh; }
.chart-wrap svg { display: block; max-width: 100%; height: auto; }

/* loading toast over the choropleth area — mirrors the hindcast #status-toast */
#sw-toast, #an-toast {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  display: none;
  pointer-events: none;
  max-width: min(80%, 520px);
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid #565d68;
  border-radius: 8px;
  color: #F0F2F5;
  font-size: 0.95rem;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
#sw-toast b, #an-toast b { color: #fff; }
#sw-toast .hint, #an-toast .hint { color: #aab0ba; }

.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; display: none;
  background: rgba(10, 12, 15, 0.94); color: var(--ink);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 0.82rem; line-height: 1.45;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5); max-width: 260px;
}
.chart-tip b { color: #fff; }

table.data { border-collapse: collapse; font-size: 0.86rem; margin-top: 6px; }
table.data th, table.data td { padding: 5px 12px; text-align: right; border-bottom: 1px solid var(--border); }
table.data th { color: var(--ink-3); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.05em; }
table.data td:first-child, table.data th:first-child { text-align: left; }

select[multiple] { min-width: 130px; }

@media (max-width: 860px) {
  .page { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; max-height: 45vh; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---- hazard home overlay + switcher ---- */
#home-panel {
  position: absolute;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 26, 0.88);
}
.home-inner { text-align: center; max-width: 760px; padding: 24px; }
.home-inner h1 { font-size: 1.55rem; margin-bottom: 8px; }
.home-inner p { color: var(--ink-2); margin-bottom: 26px; }
.home-cards { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.home-card {
  width: 205px;
  padding: 22px 16px;
  cursor: pointer;
  font: inherit;
  text-align: center;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color .15s, transform .15s;
}
.home-card:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.home-card:disabled { opacity: 0.45; cursor: default; }
.home-card .t { font-size: 1.12rem; font-weight: 700; margin-bottom: 6px; }
.home-card .d { font-size: 0.82rem; color: var(--ink-2); line-height: 1.4; }
.hazard-row { display: flex; gap: 6px; }
.hazard-btn {
  flex: 1;
  padding: 6px 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.hazard-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hazard-btn:disabled { opacity: 0.45; cursor: default; }

/* expandable remark inside wind/hail report popups */
.leaflet-popup-content .rk-box { margin-top: 4px; }
.leaflet-popup-content .rk-box i { white-space: pre-wrap; }
.leaflet-popup-content .rk-box.expanded {
  max-height: 150px;
  overflow-y: auto;
  padding-right: 6px;
}
.leaflet-popup-content .rk-more {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85em;
  margin-top: 3px;
  user-select: none;
}

/* per-state distribution popup (anomaly map click) */
#sd-pop {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 600;
  display: none;
  width: min(680px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 14px 48px rgba(0,0,0,0.65);
}
#sd-close {
  position: absolute;
  top: 10px; right: 10px;
  width: 30px; height: 30px;
  padding: 0;
  font-size: 13px;
  border-radius: 6px;
}
#sd-pop h3 { margin: 0 36px 2px 0; font-size: 1.05rem; color: var(--ink); }
#sd-pop .sd-sub { color: var(--ink-2); font-size: 0.85rem; margin: 0 0 10px; line-height: 1.45; }
#sd-pop .sd-loading { color: var(--ink-2); padding: 34px 0; text-align: center; }
#sd-pop .sd-note { color: var(--ink-3); font-size: 0.78rem; margin-top: 8px; line-height: 1.5; }
#sd-pop .sd-cumhead { color: var(--ink-2); font-size: 0.9rem; font-weight: 700; margin: 14px 0 4px; }

/* admin activity-log console */
#log-console {
  background: #0d0f12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  max-height: 540px;
  overflow-y: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  color: #c6cbd2;
}
#log-console .lg-line { white-space: pre-wrap; word-break: break-all; }
#log-console .lg-dim { color: #6b7280; }
#log-console .lg-code { color: #7fbf7f; font-weight: 700; }
#log-console .lg-warn { color: #d9a441; }
#log-console .lg-warn .lg-code { color: #d9a441; }
#log-console .lg-err { color: #e15241; }
#log-console .lg-err .lg-code { color: #e15241; }
#log-console .lg-hot { color: #e08a3c; font-weight: 700; }
#log-console .lg-boot { color: #6ea8e0; margin: 4px 0; }
#log-console .lg-run { color: #9aa0a8; font-style: italic; }
#log-console .lg-dead { color: #ff6b5e; font-weight: 700; }
#log-console .lg-jan { color: #d9a441; margin: 4px 0; }
