/* ============================================================
   FloodEWS Thess — Tactical Command-Center UI
   Fonts: Exo 2 (UI labels) + JetBrains Mono (data readouts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300;400;600;700;800;900&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-deep: #f8fafc;
  --bg-panel: rgba(255, 255, 255, 0.98);
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --border: rgba(0, 0, 0, 0.1);
  --border-glow: rgba(0, 0, 0, 0.15);
  --accent: #0284c7;
  --accent-dim: rgba(2, 132, 199, 0.08);
  --accent-glow: rgba(2, 132, 199, 0.15);
  --text-primary: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --danger-green: #22c55e;
  --danger-amber: #f59e0b;
  --danger-orange: #ef4444;
  --danger-red: #7f1d1d;
  --font-ui: 'Exo 2', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: var(--bg-deep);
}

/* ── Map ──────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ── Top Info Panel (upper-left) ──────────────────────────── */
.top-info-panel {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 800;
  min-width: 256px;
  max-width: 340px;
  padding: 14px 16px 14px 14px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: none;
}

.top-info-row {
  display: flex;
  align-items: flex-start;
  gap: 13px;
}

.top-info-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex: 0 0 auto;
  border-radius: 0 !important;
  background: transparent !important;
  padding: 0 !important;
  box-shadow: none !important;
}

.top-info-logo-large {
  width: 82px;
  height: auto;
  max-height: 82px;
}

.top-info-text {
  padding-top: 4px;
  flex: 1;
}

.top-selected-layer {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: #0f172a;
  letter-spacing: 0.01em;
}

.top-metric {
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: #475569;
}

.top-update-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-family: var(--font-mono);
  font-size: 11px;
  color: #64748b;
  line-height: 1.5;
  display: grid;
  gap: 2px;
}

/* Pulse dot removed as data updates once per day */

/* ── Menu Toggle Button ───────────────────────────────────── */
.menu-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 88px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-glow);
  border-radius: 3px;
  background: var(--bg-panel);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.menu-toggle::before {
  content: '☰';
  font-size: 14px;
  line-height: 1;
}

.menu-toggle:hover {
  background: rgba(2, 132, 199, 0.08);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ── Floating Legend ──────────────────────────────────────── */
.floating-legend {
  position: fixed;
  left: 14px;
  bottom: 90px;
  z-index: 820;
  width: 148px;
  padding: 12px 13px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.rainfall-legend {
  bottom: 300px;
}

.legend-heading {
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 9px;
}

.legend-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 9px;
}

.legend-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  column-gap: 9px;
  align-items: center;
  min-height: 22px;
}

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

.legend-line.basegray {
  background: #475569;
}

.legend-line.green {
  background: var(--danger-green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.legend-line.orange {
  background: var(--danger-amber);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
}

.legend-line.red {
  background: var(--danger-orange);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.legend-line.darkred {
  background: #dc2626;
  box-shadow: 0 0 6px rgba(220, 38, 38, 0.5);
}

.legend-item span:last-child {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-dim);
}

.legend-range {
  grid-column: 2;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-muted);
  margin-top: -4px;
  margin-bottom: 2px;
}

.legend-note {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9.5px;
  line-height: 1.4;
}

.map-handle {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
}

/* ── Bottom Brand ─────────────────────────────────────────── */
.bottom-brand {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 22px;
  z-index: 810;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: rgba(100, 116, 139, 0.7);
  pointer-events: none;
}

/* ── Bottom Right Logos ───────────────────────────────────── */
.bottom-logo-box {
  position: fixed;
  right: 14px;
  bottom: 80px;
  z-index: 830;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottom-logo-box img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 4px;
  opacity: 0.85;
  filter: brightness(0.9) contrast(1.1);
  transition: opacity 0.2s;
}

.bottom-logo-box img:hover {
  opacity: 1;
}

/* ── Side Panel ───────────────────────────────────────────── */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000;
  width: 380px;
  max-width: 94vw;
  height: 100vh;
  overflow-y: auto;
  padding: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform: translateX(108%);
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Scrollbar styling */
.side-panel::-webkit-scrollbar {
  width: 4px;
}

.side-panel::-webkit-scrollbar-track {
  background: transparent;
}

.side-panel::-webkit-scrollbar-thumb {
  background: var(--border-glow);
  border-radius: 2px;
}

.side-panel-open {
  transform: translateX(0);
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 990;
  background: rgba(6, 12, 28, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.hidden {
  display: none !important;
}

/* Panel Header */
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 165, 233, 0.04);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}



.panel-title {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.15;
}

.panel-small {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.45;
  letter-spacing: 0.02em;
}

.close-button {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.close-button:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
}

/* Panel Sections */
.panel-section {
  padding: 18px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-section h2 {
  margin: 0 0 14px;
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-section h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Form Controls */
label {
  display: block;
  margin: 12px 0 5px;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

label:first-of-type {
  margin-top: 0;
}

select,
input[type="date"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%230ea5e9' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

select:focus,
input[type="date"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), inset 0 0 0 1px rgba(14, 165, 233, 0.1);
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.6) sepia(1) saturate(3) hue-rotate(175deg);
  cursor: pointer;
}

/* Buttons */
button {
  font-family: var(--font-ui);
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 38px;
  margin-top: 10px;
  border-radius: 3px;
  padding: 9px 14px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}

.primary-button {
  border: 1px solid rgba(14, 165, 233, 0.6);
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);
}

.primary-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0%, transparent 60%);
}

.primary-button:hover {
  background: #0369a1;
  box-shadow: 0 4px 8px rgba(2, 132, 199, 0.3);
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(0);
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--bg-input);
}

.secondary-button:hover {
  border-color: var(--border-glow);
  color: var(--text-primary);
  background: rgba(14, 165, 233, 0.07);
}

.reset-button {
  margin-top: 8px;
}

/* Muted Text */
.muted {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.small-note {
  margin-top: 10px;
}

.citation-note {
  display: block;
  margin-top: 4px;
  color: var(--danger-amber);
  font-family: var(--font-mono);
  font-size: 10.5px;
  opacity: 0.8;
}

.read-more-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 3px;
  border: 1px solid rgba(14, 165, 233, 0.4);
  color: var(--accent);
  background: var(--accent-dim);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all 0.15s;
}

.read-more-link::after {
  content: '↗';
}

.read-more-link:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}

/* Attribution / Data Sources */
.attribution-block {
  padding: 10px 12px;
  background: rgba(14, 165, 233, 0.04);
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
}

.attribution-label {
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.attribution-ref {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 10.5px;
  line-height: 1.55;
  font-style: normal;
}

.attribution-ref em {
  font-style: italic;
}

.inline-link,
.doi-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s;
}

.inline-link:hover,
.doi-link:hover {
  text-decoration: underline;
  color: #38bdf8;
}

.doi-link {
  display: inline-block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
}

/* Credits */
.credits-list {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.credits-list a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.credits-list a:hover {
  text-decoration: underline;
}

/* Status Box */
.status-box {
  position: sticky;
  bottom: 0;
  margin: 0;
  padding: 11px 18px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.status-box::before {
  content: '> ';
  color: var(--accent);
  font-weight: 700;
}

.status-error {
  color: #f87171;
  border-top-color: rgba(248, 113, 113, 0.3);
}

.status-error::before {
  color: #f87171;
}

/* ── Loading Overlay ──────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.loading-inner {
  text-align: center;
  padding: 32px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border-radius: 999px;
  border: 2px solid rgba(14, 165, 233, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}

#loadingText {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

#loadingText::before {
  content: '';
  display: block;
  width: 120px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 0 auto 14px;
}

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

/* ── Leaflet Overrides ────────────────────────────────────── */
.leaflet-top.leaflet-right {
  top: 60px !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  padding-right: 14px;
  /* Align with menu button */
}

.leaflet-top.leaflet-right .leaflet-control {
  float: none !important;
  clear: none !important;
  margin-top: 0 !important;
  margin-right: 0 !important;
  margin-left: 10px !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-dim) !important;
  border-color: var(--border) !important;
  font-weight: 600 !important;
  transition: background 0.15s, color 0.15s !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(14, 165, 233, 0.12) !important;
  color: var(--accent) !important;
}

.leaflet-control-attribution {
  right: 8px !important;
  bottom: 4px !important;
  background: rgba(255, 255, 255, 0.8) !important;
  color: #475569 !important;
  border-radius: 3px;
  font-size: 9.5px;
  border: 1px solid var(--border);
  padding: 2px 6px !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
  color: var(--text-primary) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}

.leaflet-popup-content {
  margin: 14px 16px !important;
}

.popup-title {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.popup-table {
  border-collapse: collapse;
  font-size: 11.5px;
  width: 100%;
}

.popup-table td {
  padding: 4px 8px 4px 0;
  vertical-align: top;
  font-family: var(--font-mono);
}

.popup-table td:first-child {
  color: var(--text-muted);
  white-space: nowrap;
  padding-right: 14px;
  font-size: 10.5px;
}

.popup-table td:last-child {
  color: var(--text-primary);
  font-weight: 500;
}

.popup-note {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 820px) {
  .top-info-panel {
    top: 10px;
    left: 10px;
    max-width: calc(100vw - 80px);
    padding: 11px 13px;
  }

  .top-info-logo-large {
    width: 62px;
  }

  .top-selected-layer {
    font-size: 11.5px;
  }

  .top-metric {
    font-size: 11px;
  }

  .menu-toggle {
    top: 10px;
    right: 10px;
    min-width: 76px;
    font-size: 10px;
  }

  .floating-legend {
    left: 10px;
    bottom: 78px;
    width: 136px;
  }

  .bottom-brand {
    font-size: 10px;
    bottom: 18px;
  }

  .bottom-logo-box {
    right: 10px;
    bottom: 62px;
  }

  .bottom-logo-box img {
    width: 46px;
    height: 46px;
  }

  .side-panel {
    width: 340px;
  }
}

@media (max-width: 520px) {
  .top-update-block {
    font-size: 10px;
  }

  .floating-legend {
    width: 128px;
    font-size: 10.5px;
  }

  .legend-line {
    width: 12px;
    height: 3px;
  }

  .side-panel {
    width: 100%;
    max-width: 100%;
  }
}