/* 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-img {
  height: 30px;
  width: auto;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.brand-mesoflow-name {
  font-family: 'Berkshire Swash', cursive;
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0;
  opacity: 0.92;
  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-version {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.55;
  vertical-align: middle;
  margin-left: 2px;
}

.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 rows (v2: qualitative pill labels) ---- */
.factors { display: flex; flex-direction: column; gap: 12px; }

.factor-meta {
  display: flex;
  align-items: center;
  gap: 4px;
}
.factor-name { flex: 1; font-size: 13px; font-weight: 500; color: var(--storm-gray); }

.factor-label.risk-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.80rem;
  font-weight: 600;
  background: #37474f;
  color: #eceff1;
  text-transform: capitalize;
  flex-shrink: 0;
}

.factor-detail {
  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); } }

/* ================================================================
   MOBILE RESPONSIVE — bottom sheet layout
   ================================================================ */

@media (max-width: 767px) {

  /* Header: slimmer, hide region label */
  #header {
    height: 52px;
    padding: 0 16px;
  }
  .brand-region { display: none; }
  .brand-product { font-size: 15px; }

  /* Reduce spores to 4 — blur is GPU-heavy on mobile */
  .spore:nth-child(n+5) { display: none; }
  .spore { filter: blur(12px); }

  /* Main area: position context for the full-screen map */
  #main {
    position: relative;
    overflow: hidden;
  }

  /* Map: absolute fill */
  #map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
  }

  /* Sidebar: hidden bottom sheet by default */
  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 72vh;
    border-right: none;
    border-top: 1px solid var(--cloud-gray);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 28px rgba(0, 48, 135, 0.18);
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 600;
    padding: 0 20px 32px;
    overflow-y: auto;
  }

  #sidebar.sheet-open {
    transform: translateY(0);
  }

  /* Drag handle */
  .sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--cloud-gray);
    border-radius: 2px;
    margin: 10px auto 14px;
    flex-shrink: 0;
  }

  /* Hide default sidebar view on mobile (floating legend covers it) */
  #view-default { display: none !important; }

  /* Backdrop */
  #sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 48, 135, 0.25);
    z-index: 500;
    backdrop-filter: blur(1px);
  }
  #sheet-backdrop.visible { display: block; }

  /* Compact detail score on small screens */
  .score-number { font-size: 42px; }

  /* Back button: full-width tap target */
  #back-btn { width: 100%; text-align: left; }

  /* Floating legend card */
  #mobile-legend {
    display: block;
    position: fixed;
    bottom: 16px;
    left: 12px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(6px);
    border-radius: 8px;
    padding: 8px 12px 10px;
    box-shadow: 0 2px 12px rgba(0, 48, 135, 0.14);
    z-index: 400;
    pointer-events: none;
  }

  .ml-title {
    font-family: var(--font);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--slate);
    margin-bottom: 5px;
  }

  .ml-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 11px;
    color: var(--storm-gray);
    padding: 2px 0;
  }

  .ml-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
  }

  /* Loading overlay: full screen on mobile */
  .loading-box { width: 85vw; max-width: 280px; }

  /* Status text: hide on very small screens */
  @media (max-width: 360px) {
    #status-text { display: none; }
    .brand-mesoflow-name { display: none; }
    .brand-pipe { display: none; }
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 768px) {
  .sheet-handle { display: none; }
  #sheet-backdrop { display: none !important; }
  #mobile-legend { display: none; }
}

/* ================================================================
   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; }
