:root {
  --blue: #2e6cf0;
  --blue-dark: #1e4ecf;
  --ink: #1a1d23;
  --ink-2: #4a5568;
  --ink-3: #718096;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --border: #e2e5eb;
  --panel-w: 400px;

  --minimal: #2e7d32;
  --low: #7cb342;
  --moderate: #f9a825;
  --high: #ef6c00;
  --severe: #c62828;
}

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

html, body, #app { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────── */
#app {
  display: flex;
  height: 100%;
}

#map {
  flex: 1 1 auto;
  min-width: 0;
}

/* ── Panel ───────────────────────────────── */
#panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: 2px 0 20px rgba(0,0,0,0.08);
  overflow-y: auto;
  position: relative;
  z-index: 1;
}

/* ── Panel Header ─────────────────────── */
.panel-header {
  padding: 1.1rem 1.25rem 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e2d42 100%);
  color: #fff;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

.brand-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.tagline {
  font-size: 0.77rem;
  color: #94a3b8;
  padding-left: 0.1rem;
}

/* ── Search Section ──────────────────── */
.search-section {
  padding: 1rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.search-input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--ink-3);
  pointer-events: none;
}

#address {
  width: 100%;
  padding: 0.6rem 0.7rem 0.6rem 2.1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

#address::placeholder { color: #a0aab5; }

#address:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(46,108,240,0.12);
}

#screen-btn {
  padding: 0.6rem 1.05rem;
  border: none;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s;
}

#screen-btn:hover:not(:disabled) {
  background: var(--blue-dark);
  box-shadow: 0 2px 8px rgba(46,108,240,0.3);
}

#screen-btn:active:not(:disabled) { transform: scale(0.97); }
#screen-btn:disabled { opacity: 0.6; cursor: default; }

.quick-examples {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.examples-label {
  font-size: 0.73rem;
  color: var(--ink-3);
}

.example-btn {
  font-size: 0.73rem;
  padding: 0.18rem 0.55rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  line-height: 1.5;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.example-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(46,108,240,0.05);
}

/* ── API key ─────────────────────────── */
.api-key-section {
  margin-top: 0.7rem;
}

.api-key-section label {
  font-size: 0.73rem;
  color: var(--ink-3);
  display: block;
  margin-bottom: 0.3rem;
}

.api-key-optional {
  color: var(--ink-3);
  font-weight: 400;
}

.api-key-input-wrap {
  display: flex;
  gap: 0.35rem;
}

.api-key-input-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.api-key-input-wrap input:focus {
  outline: none;
  border-color: var(--blue);
}

#api-key-clear {
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.55rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}

#api-key-clear:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.api-key-hint {
  font-size: 0.7rem;
  color: var(--ink-3);
  margin-top: 0.3rem;
}

.api-key-hint a {
  color: var(--blue);
}

/* ── Status ──────────────────────────── */
.status {
  padding: 0.4rem 1.25rem;
  min-height: 2rem;
  font-size: 0.82rem;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.status.error { color: var(--severe); }

.status.loading::before {
  content: "";
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  border: 2px solid #d1d5db;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Result Card ─────────────────────── */
.card {
  display: flex;
  flex-direction: column;
  flex: 1;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.card.hidden { display: none; }
.card.visible { opacity: 1; transform: translateY(0); }

/* ── Score Hero ──────────────────────── */
.score-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, #f8faff, var(--surface));
}

.score-ring-wrap {
  position: relative;
  flex-shrink: 0;
  width: 80px;
  height: 80px;
}

.score-ring {
  width: 80px;
  height: 80px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: #edf0f5;
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 188.496;
  stroke-dashoffset: 188.496;
}

.score-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.score-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.score-max {
  font-size: 0.62rem;
  color: var(--ink-3);
  margin-top: 0.1rem;
}

.score-meta {
  min-width: 0;
  flex: 1;
}

.score-address {
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-bottom: 0.45rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-rating {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.22rem 0.6rem;
  border-radius: 6px;
  color: #fff;
  margin-bottom: 0.3rem;
}

.score-sublabel {
  font-size: 0.72rem;
  color: var(--ink-3);
}

/* ── Breakdown ───────────────────────── */
.breakdown-header {
  padding: 0.7rem 1.25rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.breakdown {
  padding: 0 1.25rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  border-bottom: 1px solid var(--border);
}

.hazard-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.hazard-icon {
  font-size: 1rem;
  line-height: 1.2;
  flex-shrink: 0;
  width: 1.3rem;
  text-align: center;
}

.hazard-body {
  flex: 1;
  min-width: 0;
}

.hazard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.hazard-name {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--ink);
}

.hazard-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.hazard-score {
  font-size: 0.83rem;
  font-weight: 700;
  color: var(--ink-2);
  min-width: 1.8rem;
  text-align: right;
}

.hazard-badge {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.42rem;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
}

.hazard-bar-track {
  height: 5px;
  border-radius: 3px;
  background: #edf0f5;
  overflow: hidden;
}

.hazard-bar-fill {
  height: 100%;
  border-radius: 3px;
  width: 0%;
}

.hazard-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.detail-chip {
  font-size: 0.66rem;
  font-weight: 500;
  padding: 0.08rem 0.38rem;
  border-radius: 4px;
  background: #edf0f5;
  color: var(--ink-2);
  white-space: nowrap;
}

.chip-real {
  background: #e8f5e9;
  color: #2e7d32;
}

.chip-mock {
  background: #fff8e1;
  color: #b45309;
}

/* ── Provenance ──────────────────────── */
.provenance {
  padding: 0.7rem 1.25rem;
  font-size: 0.72rem;
  color: var(--ink-3);
  line-height: 1.55;
  border-bottom: 1px solid var(--border);
}

.provenance a {
  color: var(--blue);
  text-decoration: none;
}

.provenance a:hover { text-decoration: underline; }

.data-versions-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
}

.data-versions-list li {
  position: relative;
  padding-left: 0.85rem;
  margin-bottom: 0.2rem;
}

.data-versions-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--ink-3);
}

.dv-key {
  font-weight: 600;
  color: var(--ink-2);
}

/* ── Disclaimer ──────────────────────── */
.disclaimer {
  padding: 0.75rem 1.25rem;
  font-size: 0.67rem;
  line-height: 1.55;
  color: #9ca3af;
  background: #fafbfc;
}

/* ── MapLibre Marker ─────────────────── */
.risk-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color, #2e6cf0);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  cursor: pointer;
  transition: transform 0.15s;
}

.risk-marker:hover { transform: scale(1.18); }

/* MapLibre popup */
.maplibregl-popup-content {
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  font-size: 0.83rem;
  line-height: 1.4;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
  font-family: inherit;
}

.popup-breakdown {
  margin-top: 0.4rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.popup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-2);
}

.popup-score {
  font-weight: 700;
}

/* ── Rating Color Classes ────────────── */
.rating-minimal { background: var(--minimal); }
.rating-low     { background: var(--low); }
.rating-moderate{ background: var(--moderate); }
.rating-high    { background: var(--high); }
.rating-severe  { background: var(--severe); }

/* ── Basemap style toolbar ───────────── */
#style-toolbar {
  position: absolute;
  bottom: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem;
  max-width: calc(100% - 1.6rem);
  overflow-x: auto;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.style-btn {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.32rem 0.65rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.style-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.style-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* ── Mobile ──────────────────────────── */
@media (max-width: 720px) {
  #app { flex-direction: column; }

  #panel {
    width: 100%;
    flex: 0 0 auto;
    max-height: 58vh;
    order: 2;
    box-shadow: 0 -2px 20px rgba(0,0,0,0.1);
  }

  #style-toolbar {
    max-width: calc(100% - 1.2rem);
  }

  #map {
    flex: 1 1 auto;
    min-height: 0;
    order: 1;
  }
}
