:root {
  --bg: #060a08;
  --panel: rgba(16, 32, 26, 0.55);
  --panel-2: rgba(20, 42, 34, 0.65);
  --panel-solid: #10201a;
  --line: rgba(53, 195, 123, 0.16);
  --line-strong: rgba(53, 195, 123, 0.35);
  --text: #eaf3ee;
  --muted: #85a596;
  --green: #35c37b;
  --amber: #e0a530;
  --orange: #ff7a1a;
  --red: #e0483d;
  --blue: #2f8fe0;
  --blur: 18px;
  --radius: 16px;

  /* fluid layout tokens (values only change at breakpoints below,
     visual design/colors are untouched) */
  --sidebar-w: 280px;
  --detail-w: 350px;
  --topbar-h: 64px;
  --touch: 44px;
}

* {
  box-sizing: border-box
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

h2 {
  font-family: 'Sora', sans-serif
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px
}

::-webkit-scrollbar-thumb {
  background: rgba(53, 195, 123, .25);
  border-radius: 8px
}

::-webkit-scrollbar-track {
  background: transparent
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- accessible focus states ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
.field-card:focus-visible,
.wstep:focus-visible,
.nav-pill:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- ambient space background ---------- */
.space-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at top, #0c1712, #060a08 70%)
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, #ffffff55 0, transparent 60%),
    radial-gradient(1.5px 1.5px at 120px 80px, #ffffff40 0, transparent 60%),
    radial-gradient(1px 1px at 220px 150px, #ffffff55 0, transparent 60%),
    radial-gradient(1.5px 1.5px at 320px 60px, #ffffff35 0, transparent 60%),
    radial-gradient(1px 1px at 400px 220px, #ffffff45 0, transparent 60%);
  background-repeat: repeat;
  background-size: 450px 300px;
  animation: drift 90s linear infinite;
  opacity: .6;
}

@media (prefers-reduced-motion: reduce) {

  .stars,
  .dot,
  .parrow,
  .risk-badge.Critical,
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@keyframes drift {
  from {
    background-position: 0 0
  }

  to {
    background-position: -900px 600px
  }
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .18
}

.glow-orange {
  width: 500px;
  height: 500px;
  background: var(--orange);
  top: -150px;
  left: -100px
}

.glow-green {
  width: 600px;
  height: 600px;
  background: var(--green);
  bottom: -200px;
  right: -150px
}

/* ---------- glass surfaces ---------- */
.glass {
  background: var(--panel);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  border: 1px solid var(--line);
}

/* ---------- topbar ---------- */
.topbar {
  position: relative;
  z-index: 1100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  padding: 0 clamp(10px, 2vw, 20px);
  border-bottom: 1px solid var(--line);
  border-left: none;
  border-right: none;
  border-top: none;
}

.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: .15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: var(--green);
  color: var(--green);
  transform: translateY(-1px)
}

.mobile-only {
  display: none
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--orange), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #08120d;
  font-family: 'Sora', sans-serif;
  font-size: 19px;
  box-shadow: 0 0 20px rgba(53, 195, 123, .35);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-name {
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav {
  display: flex;
  gap: 8px;
  margin-left: 12px;
  flex-wrap: wrap;
}

.nav-pill {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: .2s;
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'Inter', sans-serif;
  min-height: var(--touch);
}

.nav-pill:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--panel-2)
}

.nav-pill.active {
  background: linear-gradient(135deg, rgba(255, 122, 26, .18), rgba(53, 195, 123, .18));
  color: var(--green);
  border-color: var(--green)
}

.live-badge {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  animation: pulse 2s infinite
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .35
  }
}

/* ---------- mobile scrim (behind sliding sidebar / bottom sheet) ---------- */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, .5);
  z-index: 1150;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

.sidebar-scrim.show {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- layout ---------- */
.layout {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--detail-w);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: relative;
  z-index: 1200;
  pointer-events: auto;

  border-right: 1px solid var(--line);
  border-top: none;
  border-bottom: none;
  border-left: none;

  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-head {
  padding: 16px 16px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-count {
  background: var(--panel-2);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--green)
}

.search-box {
  margin: 0 16px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--muted);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 100%
}

.filter-row {
  display: flex;
  gap: 8px;
  margin: 0 16px 12px;
  flex-wrap: wrap;
}

.chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: .15s;
  min-height: 32px;
}

.chip:hover {
  border-color: var(--line-strong);
  color: var(--text)
}

.chip.active {
  background: var(--panel-2);
  color: var(--green);
  border-color: var(--green)
}

.field-list {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  position: relative;
  z-index: 1001;
}

.field-card {
  position: relative;
  z-index: 1002;

  padding: 12px 10px;
  margin: 2px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: .18s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  animation: fadeSlideIn .35s ease both;
  min-height: var(--touch);
}

.field-card:hover {
  background: var(--panel-2);
  transform: translateX(2px)
}

.field-card>div:first-child {
  min-width: 0;
  overflow: hidden;
}

.field-card.selected {
  background: var(--panel-2);
  border-color: var(--green)
}

.fc-name {
  font-size: 13.5px;
  font-weight: 600;
  overflow-wrap: break-word;
}

.fc-sub {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: break-word;
}

.fc-score {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: #08120d;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  flex-shrink: 0;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.skeleton-card {
  height: 58px;
  margin: 6px 8px;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--panel-2) 25%, rgba(53, 195, 123, .12) 37%, var(--panel-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0
  }

  100% {
    background-position: 0 0
  }
}

.status-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 16px;
  margin-top: auto
}

.status-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: .2s;
  min-width: 0;
}

.status-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px)
}

.status-card.sc-warn {
  border-color: rgba(224, 165, 48, .35)
}

.sc-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em
}

.sc-value {
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 20px
}

/* ---------- map ---------- */
.mapwrap {
  position: relative;
  z-index: 1;
  overflow: hidden;
  min-width: 0;
}

#map {
  position: relative;
  z-index: 1;

  height: 100%;
  width: 100%;

  filter: saturate(0.9) brightness(0.97);
}

.map-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 20;
  border-radius: 14px;
  padding: 8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  max-width: calc(100% - 32px);
}

.layer-group {
  display: flex;
  gap: 4px;
  padding-right: 10px;
  border-right: 1px solid var(--line);
  flex-wrap: wrap;
}

.layer-group:last-child {
  border-right: none;
  padding-right: 0
}

.layer-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: .15s;
  min-height: 32px;
}

.layer-btn:hover {
  color: var(--text);
  background: var(--panel-2)
}

.layer-btn.active {
  background: var(--green);
  color: #08120d;
  font-weight: 700
}

.overlay-btn.active {
  background: var(--orange);
  color: #08120d;
  font-weight: 700
}

.map-side-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px
}

.map-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 20;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 11.5px;
  max-width: 200px;
}

.legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 12px
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 2px 0
}

.sw {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0
}

/* ---------- detail panel ---------- */
.detail {
  position: relative;
  z-index: 900;

  border-left: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  animation: fadeSlideIn .3s ease;
  min-width: 0;
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.sheet-handle {
  display: none;
}

.detail-empty {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
  text-align: center;
  margin-top: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px
}

.detail h3 {
  font-family: 'Sora', sans-serif;
  margin: 0 0 4px;
  font-size: 17px
}

.detail .loc {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 16px
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 14px;
}

.risk-badge.Low {
  background: rgba(53, 195, 123, .15);
  color: var(--green);
  border: 1px solid var(--green)
}

.risk-badge.Moderate {
  background: rgba(224, 165, 48, .15);
  color: var(--amber);
  border: 1px solid var(--amber)
}

.risk-badge.High {
  background: rgba(255, 122, 26, .15);
  color: var(--orange);
  border: 1px solid var(--orange)
}

.risk-badge.Critical {
  background: rgba(224, 72, 61, .15);
  color: var(--red);
  border: 1px solid var(--red);
  animation: blink 1.4s infinite
}

@keyframes blink {
  50% {
    opacity: .6
  }
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px
}

.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  transition: .15s;
  min-width: 0;
}

.stat:hover {
  border-color: var(--line-strong)
}

.stat .label {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em
}

.stat .value {
  font-family: 'Sora', sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin-top: 2px;
  overflow-wrap: break-word;
}

.progress-row {
  margin: 10px 0
}

.progress-row .plabel {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px
}

.progress-bar {
  height: 7px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s ease
}

.advisory-box {
  border-radius: 14px;
  padding: 14px;
  margin-top: 6px;
  border: 1px solid var(--line)
}

.advisory-box.Low {
  background: rgba(53, 195, 123, .08);
  border-color: var(--green)
}

.advisory-box.Moderate {
  background: rgba(224, 165, 48, .08);
  border-color: var(--amber)
}

.advisory-box.High {
  background: rgba(255, 122, 26, .1);
  border-color: var(--orange)
}

.advisory-box.Critical {
  background: rgba(224, 72, 61, .1);
  border-color: var(--red)
}

.advisory-box .urgency {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
  margin-bottom: 6px
}

.advisory-box .action {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px
}

.reasoning {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--muted)
}

.reasoning li {
  padding: 4px 0;
  border-top: 1px dashed var(--line)
}

.conf-tag {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px
}

.timeline {
  margin-top: 16px
}

.timeline-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px
}

.timeline-track {
  display: flex;
  align-items: center;
  gap: 2px
}

.timeline-seg {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  position: relative
}

.timeline-seg.done {
  background: var(--green)
}

.timeline-seg.current {
  background: var(--amber)
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--muted);
  margin-top: 6px
}

/* ---------- analyze wizard ---------- */
.analyze-view {
  grid-column: 2/4;
  padding: clamp(14px, 3vw, 30px);
  overflow-y: auto
}

.analyze-card {
  max-width: 680px;
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 28px);
  animation: fadeSlideIn .3s ease
}

.analyze-card h2 {
  margin-top: 0;
  font-size: clamp(18px, 3vw, 22px);
}

.muted {
  color: var(--muted);
  font-size: 13.5px
}

.wizard-steps {
  display: flex;
  gap: 6px;
  margin: 20px 0;
  counter-reset: step;
  flex-wrap: wrap;
}

.wstep {
  flex: 1 1 120px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: .2s;
  cursor: pointer;
  min-height: var(--touch);
}

.wstep.active {
  color: var(--green);
  border-color: var(--green);
  background: rgba(53, 195, 123, .08);
  font-weight: 600
}

.wstep.done {
  color: var(--text);
  border-color: var(--line-strong)
}

.wnum {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.wstep.active .wnum {
  background: var(--green);
  color: #08120d
}

.wpanel {
  animation: fadeSlideIn .25s ease
}

.row {
  display: flex;
  gap: 16px;
  margin: 14px 0;
  flex-wrap: wrap;
}

.row label {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
  color: var(--muted);
  gap: 6px;
  min-width: 0;
}

input,
select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  transition: .15s;
  min-height: var(--touch);
  width: 100%;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--green)
}

.btn-primary {
  background: linear-gradient(135deg, var(--orange), var(--green));
  color: #08120d;
  font-weight: 700;
  border: none;
  padding: 11px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  margin-top: 6px;
  transition: .15s;
  min-height: var(--touch);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px)
}

.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: .15s;
  min-height: var(--touch);
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  color: var(--text)
}

.btn-ghost:disabled {
  opacity: .4;
  cursor: not-allowed
}

.wizard-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 22px;
  gap: 10px;
  flex-wrap: wrap;
}

#analyzeResult {
  margin-top: 24px
}

.loader {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  padding: 14px 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid var(--panel-2);
  border-top-color: var(--green);
  animation: spin .7s linear infinite;
}

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

/* ---------- pipeline ---------- */
.pipeline-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 24px 0;
  gap: 2px
}

.pnode {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 26px;
  font-size: 13px;
  font-weight: 600;
  animation: fadeSlideIn .4s ease both;
  text-align: center;
}

.pnode-final {
  border-color: var(--green);
  color: var(--green)
}

.parrow {
  color: var(--muted);
  font-size: 16px;
  animation: pulse 1.8s infinite
}

.pipeline-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 20px
}

.pstep {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  transition: .15s
}

.pstep:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px)
}

.pstep b {
  display: block;
  font-size: 13px;
  margin-bottom: 4px
}

.pstep span {
  font-size: 12px;
  color: var(--muted)
}

.feature-importance {
  margin-top: 20px
}

.fi-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 12px
}

.fi-name {
  width: 110px;
  color: var(--muted);
  flex-shrink: 0
}

.fi-bar-track {
  flex: 1;
  height: 8px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden
}

.fi-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--orange));
  border-radius: 4px
}

.fi-val {
  width: 40px;
  text-align: right;
  color: var(--text);
  flex-shrink: 0
}

/* leaflet popup theme override */
.leaflet-popup-content-wrapper {
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 10px
}

.leaflet-popup-tip {
  background: var(--panel-solid)
}

.leaflet-bar a {
  background: var(--panel-solid) !important;
  color: var(--text) !important;
  border-color: var(--line) !important
}

.leaflet-container {
  z-index: 1 !important;
}

/* =========================================================
   RESPONSIVE BREAKPOINTS
   1440 / 1200 / 1024 / 768 / 600 / 480 / 360
   Only spacing / column widths / wrapping change here —
   no colors, no branding, no structural redesign.
   ========================================================= */

/* ----- 1440px: slightly tighter columns on large-but-not-huge screens ----- */
@media (max-width: 1440px) {
  :root {
    --sidebar-w: 264px;
    --detail-w: 330px;
  }
}

/* ----- 1200px: tighten further, keep 3-column layout ----- */
@media (max-width: 1200px) {
  :root {
    --sidebar-w: 250px;
    --detail-w: 310px;
  }
}

/* ----- 1024px: tablet landscape — sidebar 240px, detail narrower, map fills rest ----- */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 240px;
    --detail-w: 280px;
  }

  .map-legend {
    max-width: 170px;
    font-size: 11px;
  }
}

/* ----- 768px: tablet portrait / mobile — hamburger nav, sliding sidebar, bottom-sheet detail ----- */
@media (max-width: 1024px) and (min-width: 768px) {
  .map-toolbar {
    flex-wrap: wrap;
  }
}

@media (max-width: 767px) {
  .mobile-only {
    display: flex
  }

  .topbar {
    gap: 8px;
  }

  .topnav {
    margin-left: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    max-width: 42vw;
  }

  .topnav::-webkit-scrollbar {
    display: none;
  }

  .nav-pill {
    white-space: nowrap;
    padding: 9px 12px;
    flex-shrink: 0;
  }

  .live-badge {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: min(82vw, 300px);
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform .28s ease;
  }

  .sidebar.open {
    transform: translateX(0)
  }

  .sidebar-scrim {
    display: block;
  }

  .mapwrap {
    width: 100%;
    grid-column: 1;
  }

  .detail {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: 75vh;
    max-height: 75dvh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-top: 1px solid var(--line);
    z-index: 1250;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .5);
    padding-top: 30px;
  }

  .detail.open {
    display: block;
    animation: sheetUp .25s ease;
  }

  @keyframes sheetUp {
    from {
      transform: translateY(30px);
      opacity: .4;
    }

    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .detail-close {
    display: flex;
  }

  .sheet-handle {
    display: block;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 4px;
    border-radius: 4px;
    background: var(--line-strong);
  }

  .pipeline-steps {
    grid-template-columns: 1fr
  }

  .map-toolbar {
    top: 10px;
    left: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
  }

  .map-side-controls {
    top: 10px;
    right: 10px;
  }

  .map-legend {
    bottom: auto;
    top: 66px;
    left: 10px;
    max-width: 150px;
    font-size: 10.5px;
    padding: 8px 10px;
  }

  .icon-btn,
  .layer-btn,
  .chip,
  .nav-pill,
  .btn-primary,
  .btn-ghost,
  input,
  select {
    min-height: var(--touch);
  }

  .icon-btn {
    width: var(--touch);
    height: var(--touch);
  }

  .field-card {
    padding: 12px 10px;
  }
}

/* ----- 600px: stack analyze wizard rows, tighten paddings ----- */
@media (max-width: 600px) {
  .row {
    flex-direction: column;
    gap: 10px;
  }

  .row label {
    flex-basis: auto;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .wstep {
    font-size: 11px;
    padding: 8px 4px;
  }

  .wstep span:not(.wnum) {
    display: none;
  }

  .analyze-view {
    padding: 12px;
  }

  .sidebar {
    width: min(88vw, 300px);
  }
}

/* ----- 480px: small phones ----- */
@media (max-width: 480px) {
  .brand-sub {
    display: none;
  }

  .live-badge {
    display: none;
  }

  .map-toolbar {
    gap: 6px;
    padding: 6px;
  }

  .layer-group {
    padding-right: 6px;
    gap: 3px;
  }

  .layer-btn {
    padding: 6px 8px;
    font-size: 11px;
  }

  .status-cards {
    grid-template-columns: 1fr 1fr;
  }

  .detail {
    max-height: 80vh;
    max-height: 80dvh;
  }
}

/* ----- 360px: smallest common phones ----- */
@media (max-width: 360px) {
  .brand-name {
    font-size: 15px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .wizard-nav {
    flex-direction: column;
  }

  .wizard-nav button {
    width: 100%;
  }

  .map-legend {
    max-width: 130px;
  }
}

/* ----- large desktop refinement (kept for completeness, no design change) ----- */
@media (min-width: 1441px) {
  :root {
    --sidebar-w: 280px;
    --detail-w: 350px;
  }
}

.leaflet-heatmap-layer {
  pointer-events: none !important;
}

.leaflet-overlay-pane {
  pointer-events: none !important;
}

.leaflet-marker-pane {
  pointer-events: auto !important;
}

.leaflet-popup-pane {
  pointer-events: auto !important;
}


.location-pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  70% {
    transform: scale(1.4);
    opacity: 0.3;
  }

  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* ---- Contributor Recognition ---- */
.contributors-card {
  max-width: 860px;
}

.contrib-stats {
  display: flex;
  gap: 12px;
  margin: 18px 0 6px;
  flex-wrap: wrap;
}

.contrib-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(53, 195, 123, 0.06);
}

.contrib-stat .cs-value {
  font-family: "Sora", "Inter", sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
}

.contrib-stat .cs-label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.contrib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.contrib-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  animation: fadeSlideIn 0.3s ease;
}

.contrib-card:hover,
.contrib-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--line-strong);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  outline: none;
}

.contrib-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  object-fit: cover;
  background: var(--panel-solid);
}

.contrib-name {
  font-weight: 600;
  font-size: 13.5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contrib-count {
  font-size: 11.5px;
  color: var(--muted);
}

.contrib-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 14px;
  line-height: 1;
}

.contrib-cta {
  margin-top: 20px;
}

.contrib-cta a,
.contrib-error a {
  color: var(--green);
  font-weight: 600;
}

.contrib-empty,
.contrib-error {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.contrib-skeleton {
  height: 132px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(100deg,
      rgba(53, 195, 123, 0.05) 30%,
      rgba(53, 195, 123, 0.14) 50%,
      rgba(53, 195, 123, 0.05) 70%);
  background-size: 200% 100%;
  animation: contribShimmer 1.2s ease-in-out infinite;
}

@keyframes contribShimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

@media (max-width: 560px) {
  .contrib-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }
}

/* ---- Export CSV button (sidebar) ---- */
.btn-export {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(53, 195, 123, 0.08);
  color: var(--green);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-height: var(--touch);
  transition: .15s;
}

.btn-export:hover {
  background: rgba(53, 195, 123, 0.16);
  transform: translateY(-1px);
}

.btn-export.is-loading {
  opacity: .6;
  pointer-events: none;
}

.btn-export.is-loading svg {
  animation: contribShimmer 1s linear infinite;
}

/* ---- 7-Day Weather Forecast ---- */
.weather-card {
  max-width: 920px;
}

.forecast-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 18px 0 6px;
}

.forecast-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.forecast-form input {
  width: 130px;
}

.fc-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(47, 143, 224, 0.08);
}

.fc-current-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.fc-current-icon {
  font-size: 44px;
  line-height: 1;
}

.fc-current-temp {
  font-family: "Sora", "Inter", sans-serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
}

.fc-current-cond {
  font-size: 14px;
  color: var(--muted);
}

.fc-current-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
}

.fc-current-meta b {
  color: var(--text);
}

.fc-recommendation {
  margin-top: 14px;
  padding: 12px 16px;
  border-left: 3px solid var(--green);
  border-radius: 8px;
  background: rgba(53, 195, 123, 0.08);
  font-size: 13.5px;
  color: var(--text);
}

.fc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.fc-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  text-align: center;
  animation: fadeSlideIn .3s ease;
}

.fc-day-name {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text);
}

.fc-day-icon {
  font-size: 28px;
  line-height: 1;
}

.fc-day-temp {
  font-size: 13px;
  color: var(--text);
}

.fc-day-temp b {
  color: var(--amber);
}

.fc-day-rain,
.fc-day-humidity,
.fc-day-wind {
  font-size: 11.5px;
  color: var(--muted);
}

.fc-source {
  margin-top: 14px;
  font-size: 11.5px;
}

.forecast-error {
  margin-top: 18px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.forecast-skeleton {
  height: 150px;
  margin-top: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(100deg,
      rgba(47, 143, 224, 0.05) 30%,
      rgba(47, 143, 224, 0.14) 50%,
      rgba(47, 143, 224, 0.05) 70%);
  background-size: 200% 100%;
  animation: contribShimmer 1.2s ease-in-out infinite;
}

@media (max-width: 560px) {
  .forecast-form input {
    width: 100%;
  }

  .forecast-form label {
    flex: 1 1 100%;
  }

  .fc-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
  }
}

/* =====================================================================
   THEME TOGGLE  (Dark / Light)
   The whole UI is driven by the CSS custom properties declared in :root
   (the dark theme). The light theme simply re-declares those tokens on
   html[data-theme="light"]; every component picks the new values up for
   free. Only a few hard-coded ambient surfaces need explicit overrides.
   ===================================================================== */

/* ---- Light theme tokens ---- */
html[data-theme="light"] {
  --bg: #eaf1ec;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-2: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --line: rgba(20, 83, 55, 0.18);
  --line-strong: rgba(20, 83, 55, 0.42);
  --text: #0f2419;
  --muted: #4b6a5c;
  /* Deepen the accent green so it keeps AA contrast as text/icon on the
     now-light surfaces (healthy dots, active nav pill, focus rings, etc). */
  --green: #0b7a43;
}

/* Ambient background is hard-coded (not tokenised) — swap it for light. */
html[data-theme="light"] .space-bg {
  background: radial-gradient(ellipse at top, #f4f9f5, #e3ede7 70%);
}

/* White starfield is invisible on a light sky — hide it, soften the glows. */
html[data-theme="light"] .stars {
  opacity: 0;
}

html[data-theme="light"] .glow {
  opacity: 0.1;
}

/* ---- Toggle button: show the icon of the theme you'll switch TO ---- */
html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

/* ---- Smooth cross-fade between themes ----
   The transition is applied ONLY while a theme switch is in progress: JS
   adds the .theme-transition class to <html> for ~300ms, then removes it.
   This lets every surface cross-fade together, while never permanently
   overriding any element's own transition — so hover lifts, the mobile
   sidebar slide, card animations, etc. are left exactly as they were.
   (Only color-family properties are transitioned, so transforms/layout
   are unaffected even during the switch.) */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.25s ease, border-color 0.25s ease,
    color 0.25s ease, fill 0.25s ease, opacity 0.25s ease !important;
}

@media (prefers-reduced-motion: reduce) {

  html.theme-transition,
  html.theme-transition *,
  html.theme-transition *::before,
  html.theme-transition *::after {
    transition: none !important;
  }
}

/* ================= LOCATION SEARCH (Analyze — Step 1) ================= */
/* Autocomplete over OpenStreetMap Nominatim. Uses the same design tokens as
   the rest of the app, so it themes correctly in both dark and light modes. */
.loc-search {
  position: relative;
  margin: 4px 0 8px;
}

.loc-search-label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.loc-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--muted);
  transition: border-color .15s;
}

.loc-search-box:focus-within {
  border-color: var(--green);
}

/* Override the global input styles for the inline search field. */
.loc-search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  min-height: auto;
  color: var(--text);
  font-size: 14px;
}

.loc-search-box input:focus {
  border: none;
}

.loc-spinner {
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--green);
  animation: locSpin .6s linear infinite;
}

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

.loc-clear-input {
  flex: none;
  width: auto;
  min-height: auto;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.loc-clear-input:hover {
  color: var(--text);
}

.loc-suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 40;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
  max-height: 260px;
  overflow-y: auto;
}

.loc-suggestion {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.loc-suggestion small {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 2px;
}

.loc-suggestion mark {
  background: transparent;
  color: var(--green);
  font-weight: 700;
}

.loc-suggestion:hover,
.loc-suggestion.active {
  background: var(--panel-2);
}

.loc-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.loc-status.is-error {
  color: var(--red);
}

.loc-retry {
  width: auto;
  min-height: auto;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.loc-retry:hover {
  border-color: var(--green);
}

.loc-history {
  margin-top: 10px;
}

.loc-history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.loc-history-clear {
  width: auto;
  min-height: auto;
  background: transparent;
  border: none;
  color: var(--green);
  font-size: 11.5px;
  cursor: pointer;
  padding: 0;
}

.loc-history-clear:hover {
  text-decoration: underline;
}

.loc-history-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.loc-history-chip {
  width: auto;
  min-height: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s;
}

.loc-history-chip:hover {
  border-color: var(--line-strong);
}

/* Mobile-friendly: larger touch targets, contained dropdown height. */
@media (max-width: 560px) {
  .loc-suggestions {
    max-height: 210px;
  }

  .loc-suggestion {
    padding: 11px 10px;
  }
}

/* =====================================================================
   ANALYTICS  (Interactive Chart.js charts)
   A wider card than the other views: the charts sit in a responsive grid
   that collapses to a single column on tablets/phones. All colours come
   from the shared theme tokens, so light/dark work without extra rules.
   ===================================================================== */
.analytics-card {
  max-width: 1180px;
}

.analytics-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 18px 0 6px;
}

.analytics-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 1 150px;
  min-width: 130px;
  font-size: 12.5px;
  color: var(--muted);
}

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 18px 0 4px;
}

.analytics-summary:empty {
  display: none;
}

.an-stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.an-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.an-value {
  font-size: 16px;
  font-weight: 700;
  font-family: 'Sora', sans-serif;
}

.analytics-status {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.analytics-status.is-error {
  color: var(--red);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-top: 16px;
  transition: opacity .2s ease;
}

.chart-grid.is-loading {
  opacity: .45;
  pointer-events: none;
}

.chart-grid.is-hidden {
  display: none;
}

.chart-card {
  margin: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
  animation: fadeSlideIn .3s ease;
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.chart-dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  min-height: auto;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.chart-dl:hover {
  color: var(--green);
  border-color: var(--line-strong);
}

/* Fixed-height box: Chart.js is responsive with maintainAspectRatio:false,
   so the canvas fills this box instead of growing unbounded. */
.chart-box {
  position: relative;
  height: 260px;
}

.chart-card-wide .chart-box {
  height: 300px;
}

.chart-source {
  margin-top: 14px;
  font-size: 11.5px;
}

@media (max-width: 767px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .analytics-form label {
    flex: 1 1 100%;
  }

  .chart-box,
  .chart-card-wide .chart-box {
    height: 230px;
  }
}

@media (max-width: 480px) {
  .analytics-summary {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .an-value {
    font-size: 14px;
  }
}
