/* MoldMap — South Florida Mold Risk Dashboard
   Mesoflow design system: Inter font, ocean blue header, seafoam accents
   Spore bloom animation in header bar.
*/

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Mesoflow palette */
  --deep-ocean:     #003087;
  --seafoam-teal:   #00A99D;
  --pacific-blue:   #0077BE;
  --storm-gray:     #2C3E50;
  --slate:          #697386;
  --cloud-gray:     #E8ECEF;
  --mist-gray:      #F4F6F8;

  /* Risk colors */
  --color-critical: #d32f2f;
  --color-high:     #f57c00;
  --color-moderate: #fbc02d;
  --color-low:      #388e3c;

  /* Layout */
  --sidebar-width:  320px;
  --header-height:  60px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--storm-gray);
  background: var(--mist-gray);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ================================================================
   HEADER — Mesoflow blue bar with spore bloom animation
   ================================================================ */

#header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: var(--header-height);
  background: var(--deep-ocean);
  color: #fff;
  flex-shrink: 0;
  z-index: 1000;
  overflow: hidden;
}

/* ---- Spore bloom animation ---- */
.header-spores {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.spore {
  position: absolute;
  border-radius: 50%;
  filter: blur(18px);
  animation: sporeBloom linear infinite;
  opacity: 0;
}

/* 8 spores: varied organic shapes, mold-green palette, staggered across header */
.spore:nth-child(1) {
  width: 100px; height: 80px;
  background: rgba(74, 124, 89, 0.55);
  border-radius: 60% 40% 55% 45% / 50% 60% 40% 50%;
  top: -30px; left: 5%;
  animation-duration: 14s; animation-delay: 0s;
}
.spore:nth-child(2) {
  width: 70px; height: 95px;
  background: rgba(90, 138, 106, 0.45);
  border-radius: 45% 55% 40% 60% / 55% 45% 60% 40%;
  top: 8px; left: 20%;
  animation-duration: 11s; animation-delay: -3s;
}
.spore:nth-child(3) {
  width: 120px; height: 60px;
  background: rgba(58, 110, 78, 0.42);
  border-radius: 55% 45% 60% 40% / 40% 60% 45% 55%;
  top: -28px; left: 36%;
  animation-duration: 16s; animation-delay: -6s;
}
.spore:nth-child(4) {
  width: 80px; height: 105px;
  background: rgba(106, 154, 118, 0.45);
  border-radius: 40% 60% 50% 50% / 60% 40% 55% 45%;
  bottom: -38px; left: 50%;
  animation-duration: 13s; animation-delay: -9s;
}
.spore:nth-child(5) {
  width: 90px; height: 72px;
  background: rgba(74, 124, 89, 0.5);
  border-radius: 50% 50% 45% 55% / 45% 55% 50% 50%;
  top: -22px; left: 63%;
  animation-duration: 15s; animation-delay: -2s;
}
.spore:nth-child(6) {
  width: 65px; height: 85px;
  background: rgba(58, 110, 78, 0.42);
  border-radius: 55% 45% 50% 50% / 50% 50% 45% 55%;
  bottom: -28px; left: 74%;
  animation-duration: 12s; animation-delay: -7s;
}
.spore:nth-child(7) {
  width: 115px; height: 65px;
  background: rgba(90, 138, 106, 0.45);
  border-radius: 45% 55% 55% 45% / 60% 40% 55% 45%;
  top: -18px; left: 83%;
  animation-duration: 17s; animation-delay: -4s;
}
.spore:nth-child(8) {
  width: 78px; height: 92px;
  background: rgba(74, 124, 89, 0.42);
  border-radius: 50% 50% 40% 60% / 45% 55% 50% 50%;
  bottom: -32px; left: 93%;
  animation-duration: 10s; animation-delay: -8s;
}

@keyframes sporeBloom {
  0%   { transform: scale(0.3) rotate(0deg);  opacity: 0; }
  18%  { opacity: 1; }
  82%  { opacity: 0.7; }
  100% { transform: scale(2.4) rotate(18deg); opacity: 0; }
}

/* ---- Header brand / content (sits above spores) ---- */
.header-brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1;
}

.brand-mesoflow {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
}

.brand-logo-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--seafoam-teal);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  border-radius: 6px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand-mesoflow-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  opacity: 0.85;
  transition: opacity 150ms;
}

.brand-mesoflow:hover .brand-mesoflow-name { opacity: 1; }

.brand-pipe {
  color: rgba(255, 255, 255, 0.25);
  font-size: 20px;
  font-weight: 200;
  line-height: 1;
}

.brand-product {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-region {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  border-left: 1px solid rgba(255, 255, 255, 0.2);
  padding-left: 10px;
  margin-left: 2px;
}

.header-status {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-left: auto;
  z-index: 1;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  flex-shrink: 0;
}
.status-dot.loading { background: #fbc02d; animation: pulse 1.2s ease-in-out infinite; }
.status-dot.ready   { background: #66bb6a; }
.status-dot.error   { background: #ef5350; }

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

/* ================================================================
   MAIN LAYOUT
   ================================================================ */

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ================================================================
   SIDEBAR
   ================================================================ */

#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #ffffff;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--cloud-gray);
  z-index: 100;
}

#sidebar h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--deep-ocean);
  letter-spacing: -0.2px;
}

#sidebar h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--slate);
  margin-bottom: 10px;
  margin-top: 20px;
}

.sidebar-intro {
  font-size: 13px;
  color: var(--slate);
  line-height: 1.55;
  margin-bottom: 4px;
}

/* ---- Legend ---- */
.legend { margin-top: 20px; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: var(--storm-gray);
}

.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---- Data sources ---- */
.data-note ul {
  list-style: none;
  font-size: 12px;
  color: var(--slate);
  line-height: 1.9;
}
.data-note ul li::before { content: "• "; }
.refresh-note {
  margin-top: 10px;
  font-size: 11px;
  color: #aaa;
}

/* ---- Algorithm summary ---- */
.risk-algorithm { margin-top: 4px; }

.algo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--slate);
}

.algo-weight {
  font-size: 12px;
  font-weight: 700;
  color: var(--seafoam-teal);
  min-width: 34px;
}

.algo-label { flex: 1; }

/* ---- Detail view ---- */
#back-btn {
  background: none;
  border: 1px solid var(--seafoam-teal);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  color: var(--seafoam-teal);
  margin-bottom: 16px;
  display: block;
  transition: background 150ms;
}
#back-btn:hover { background: rgba(0, 169, 157, 0.07); }

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

#detail-zip-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--deep-ocean);
}

.risk-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  background: #888;
  flex-shrink: 0;
  margin-top: 4px;
}
.risk-badge.critical { background: var(--color-critical); }
.risk-badge.high     { background: var(--color-high); }
.risk-badge.moderate { background: var(--color-moderate); color: #333; }
.risk-badge.low      { background: var(--color-low); }

.score-display { margin-bottom: 20px; }

.score-number {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  color: var(--deep-ocean);
}

.score-label {
  font-size: 16px;
  color: var(--slate);
}

/* ---- Factor bars ---- */
.factors { display: flex; flex-direction: column; gap: 14px; }

.factor-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.factor-name   { flex: 1; font-size: 13px; font-weight: 500; color: var(--storm-gray); }
.factor-weight { font-size: 11px; color: #bbb; margin-right: 4px; }
.factor-score  { font-size: 13px; font-weight: 700; min-width: 32px; text-align: right; color: var(--deep-ocean); }

.factor-bar-track {
  width: 100%;
  height: 7px;
  background: var(--cloud-gray);
  border-radius: 4px;
  overflow: hidden;
}
.factor-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--seafoam-teal);
  width: 0%;
  transition: width 0.4s ease;
}
.factor-raw {
  font-size: 11px;
  color: var(--slate);
  margin-top: 3px;
}

.detail-meta {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--cloud-gray);
  font-size: 12px;
  color: var(--slate);
  line-height: 2;
}

/* ================================================================
   MAP
   ================================================================ */

#map {
  flex: 1;
  height: 100%;
  z-index: 0;
}

/* ================================================================
   LOADING OVERLAY
   ================================================================ */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 48, 135, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-box {
  background: #fff;
  border-radius: 10px;
  padding: 32px 40px;
  text-align: center;
  font-size: 15px;
  color: var(--storm-gray);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0, 48, 135, 0.15);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--cloud-gray);
  border-top-color: var(--seafoam-teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   LEAFLET OVERRIDES
   ================================================================ */

.zip-tooltip {
  background: rgba(0, 48, 135, 0.88);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  white-space: nowrap;
  box-shadow: none;
}
.zip-tooltip::before { display: none; }
