:root {
  --text-main: #111;
  --text-sec: #444;
  --text-ter: #999;
  --border: #e5e7eb;
  --radius: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: #fff; color: var(--text-main); font-family: var(--font-sans); }
.wrap { max-width: 1360px; margin: 0 auto; padding: 24px; }
.header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.brand-stack { display: flex; flex-direction: column; gap: 4px; }
.h1 { font-size: 36px; font-weight: 700; margin: 0; line-height: 1.1; letter-spacing: -0.02em; }
.sub { color: var(--text-sec); font-size: 15px; }
.top-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #f3f4f6;
  border-radius: 100px;
}
.seg-btn {
  font-size: 13px;
  font-weight: 400;
  color: #666;
  padding: 5px 14px;
  border-radius: 100px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  font-family: var(--font-sans);
  width: auto;
}
.seg-btn.active {
  background: #fff;
  color: #111;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
}

.pill-btn { background: #fff; border: 1.5px solid #e5e7eb; border-radius: 100px; padding: 7px 18px; font-size: 13px; font-weight: 400; color: #555; cursor: pointer; font-family: var(--font-sans); width: auto; }

.grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: stretch; }
.left-panels { display: flex; flex-direction: column; gap: 16px; height: 100%; }
.right-grid { display: grid; grid-template-rows: auto auto; gap: 16px; min-height: 760px; }

label { font-size: 12px; color: var(--text-sec); font-weight: 500; padding-left: 4px; }
.address-autocomplete-wrap { position: relative; }
input, button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  font-family: var(--font-sans);
  font-size: 13px;
}
.address-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
  display: none;
  max-height: 220px;
  overflow-y: auto;
}
.address-suggestions.open { display: block; }
.address-suggestion-item {
  padding: 8px 10px;
  font-size: 12px;
  color: #334155;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}
.address-suggestion-item:last-child { border-bottom: none; }
.address-suggestion-item:hover { background: #f8fafc; }
input:focus { outline: none; border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
button { cursor: pointer; background: #1f2937; color: #fff; font-weight: 500; border: none; }
#convertBtn { border-radius: 100px; }

.log { font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; overflow: auto; color: var(--text-sec); }
.summary-card { display: none; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.summary-label { font-size: 11px; font-weight: 500; letter-spacing: 0.07em; text-transform: uppercase; color: #aaa; margin-bottom: 10px; }
.summary-text { font-size: 13px; line-height: 1.8; color: #333; margin: 0; flex: 1 1 0; min-height: 0; overflow-y: auto; }
.log-card summary { cursor: pointer; font-size: 11px; font-weight: 500; letter-spacing: 0.07em; text-transform: uppercase; color: #aaa; list-style: none; display: flex; align-items: center; justify-content: space-between; margin-bottom: 0; }
.log-card summary::-webkit-details-marker { display: none; }
.log-card summary::after { content: '▸'; font-size: 11px; color: #bbb; }
.log-card[open] summary::after { content: '▾'; }
.log-card[open] .log { margin-top: 10px; max-height: 200px; overflow-y: auto; }

.chat-divider { height: 1px; background: var(--border); margin: 14px 0 12px; margin-top: auto; }
.chat-thread { display: flex; flex-direction: column; gap: 8px; max-height: 140px; overflow-y: auto; margin-bottom: 10px; }
.chat-msg { font-size: 13px; line-height: 1.6; padding: 8px 12px; border-radius: 10px; max-width: 88%; word-wrap: break-word; }
.chat-msg.user { background: #f3f4f6; color: #111; align-self: flex-end; border-radius: 10px 10px 2px 10px; }
.chat-msg.assistant { background: #f0f2ff; color: #333; align-self: flex-start; border: 1px solid #e0e4f8; border-radius: 10px 10px 10px 2px; }
.chat-input-row { display: flex; gap: 8px; align-items: center; }
.chat-input { flex: 1; border-radius: 100px !important; font-size: 13px; padding: 8px 14px !important; border: 1px solid var(--border) !important; background: #f9fafb !important; width: auto; }
.chat-send-btn { width: 30px !important; min-width: 30px; height: 30px; border-radius: 100px !important; background: #1f2937 !important; color: #fff !important; border: none !important; padding: 0 !important; }
.privacy-note { margin-top: 10px; font-size: 11px; line-height: 1.5; color: var(--text-ter); background: #f9fafb; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }

/* ── Radar teaser ─────────────────────────────────────────────────────────── */
.radar-teaser-card { padding: 14px 16px 10px; }
.radar-blur-wrap { position: relative; margin: 4px auto 0; max-width: 200px; }
.radar-svg { width: 100%; height: auto; display: block; }
.radar-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 10px;
  gap: 5px;
}
.radar-lock-icon  { font-size: 22px; line-height: 1; }
.radar-lock-title { font-size: 13px; font-weight: 600; color: #1e293b; font-family: var(--font-sans); }
.radar-lock-price { font-size: 22px; font-weight: 700; color: #1d4ed8; font-family: var(--font-sans); }
.radar-unlock-btn {
  background: #1d4ed8; color: #fff; border: none; border-radius: 100px;
  padding: 7px 18px; font-size: 13px; font-weight: 500; font-family: var(--font-sans);
  cursor: pointer; margin-top: 2px;
}
.radar-unlock-btn:hover { background: #1e40af; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.chart-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; gap: 8px; }
.chart-title { font-size: 13px; font-weight: 500; color: var(--text-sec); }
.tab-desc { font-size: 11.5px; color: var(--text-ter); line-height: 1.5; margin-bottom: 8px; }
.panel-placeholder {
  height: calc(100% - 24px);
  min-height: 140px;
  border: 1px dashed #d3d8e0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #80889a;
  background: #fbfcfe;
  padding: 16px;
}

/* ── Contextual terrain controls ────────────────────────────────────────── */
.terrain-controls {
  border: 1px solid #edf1f5;
  border-radius: 10px;
  padding: 6px 12px;
  margin-bottom: 10px;
  background: #fafcff;
  /* Fixed height = tallest state (elevation: units row + contours row).
     Prevents map from shifting when switching between tabs. */
  height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
}

/* Tabs with no controls: keep the fixed-height spacer, just hide its border/bg */
#terrainControls[data-tab="satellite"] {
  border-color: transparent;
  background: transparent;
}
/* Hide the rows for those tabs */
#terrainControls[data-tab="satellite"] .ctrl-row {
  display: none;
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
}

/* All rows hidden by default */
.ctrl-units, .ctrl-contours, .ctrl-hazards { display: none; }

/* Show units for elevation, hydro, soil, solar */
#terrainControls[data-tab="elevation"] .ctrl-units,
#terrainControls[data-tab="hydro"]     .ctrl-units,
#terrainControls[data-tab="soil"] .ctrl-units,
#terrainControls[data-tab="solar"]     .ctrl-units { display: flex; }

/* Show contours for elevation, hydro */
#terrainControls[data-tab="elevation"] .ctrl-contours,
#terrainControls[data-tab="hydro"]     .ctrl-contours { display: flex; }

/* Show hazard sub-selector only on hazards tab */
#terrainControls[data-tab="hazards"] .ctrl-hazards { display: flex; }

.ctrl-label { font-size: 11px; color: #64748b; font-family: var(--font-mono); white-space: nowrap; }
.ctrl-units   { justify-content: flex-start !important; gap: 8px; }
.ctrl-hazards { justify-content: flex-end !important; }
.ctrl-hint  { font-size: 11px; color: #64748b; font-family: var(--font-mono); white-space: nowrap; }

.checkline {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  margin: 0 !important;
  font-size: 12px !important;
  color: #374151 !important;
  font-weight: 400 !important;
  padding-left: 0 !important;
}
.checkline input { width: auto; }

/* ── Map panel ──────────────────────────────────────────────────────────── */
#leftMapPanel {
  display: block;
  padding: 0;
  overflow: hidden;
}
/* 4:3 aspect ratio for terrain map — this is the main display, fixes right column height */
#terrainPanel {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  height: auto;
  display: block;
  padding: 0;
  overflow: hidden;
}
.gesture-mouse {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  opacity: 0.8;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
  transition: opacity 0.4s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.gesture-label {
  background: rgba(255,255,255,0.38);
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  color: #1d4ed8;
  font-family: var(--font-sans);
  white-space: nowrap;
  font-weight: 500;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.65);
}

/* ── Elevation / Hazard legend ──────────────────────────────────────────── */
.elevation-legend {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 5;
  width: 210px;
  background: rgba(255,255,255,0.38);
  border: 1px solid rgba(255,255,255,0.52);
  color: #1e293b;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 11px;
  line-height: 1.45;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 4px 20px rgba(0,0,0,0.09), inset 0 1px 0 rgba(255,255,255,0.65);
}
.elevation-legend .bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg,
    #40835f 0%,
    #b0c992 15%,
    #e1e1ab 30%,
    #ccb97e 50%,
    #b1884d 70%,
    #a57c74 90%,
    #f5f4f2 100%);
}
.elevation-legend .hydro-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #e2e8f0 0%, #bae6fd 25%, #38bdf8 55%, #0ea5e9 75%, #0369a1 100%);
}
.elevation-legend .seismic-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #ffffb2 0%, #fecc5c 25%, #fd8d3c 55%, #f03b20 78%, #bd0026 100%);
}
.elevation-legend .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  color: #64748b;
}

/* Hazard legend swatches */
.hleg-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  line-height: 1.7;
  color: #334155;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-block;
}
.swatch-ae  { background: #7db8e8; border: 1px solid #3a80c0; }
.swatch-xsh { background: #cfc09a; border: 1px solid #a08060; }
.swatch-xu  { background: #f0f0ee; border: 1px solid #bbb; }
.swatch-ve  { background: #e89090; border: 1px solid #c05050; }
.fault-ln { display: inline-block; width: 18px; height: 3px; border-radius: 1px; flex-shrink: 0; }
.elevation-legend .fire-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #7bc67b 0%, #d4ed5a 20%, #ffd966 40%, #ff9933 60%, #ff4400 80%, #aa0000 100%);
}
.elevation-legend .nri-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #7bc67b 0%, #d4ed5a 25%, #ffd966 50%, #ff9933 75%, #aa0000 100%);
}
.elevation-legend .solar-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #3b6fba 0%, #4db3a2 35%, #f5d04a 65%, #f07030 85%, #c03020 100%);
}
.elevation-legend .soil-bar {
  height: 10px;
  border-radius: 999px;
  margin: 6px 0;
  background: linear-gradient(90deg, #f5f0e8 0%, #d4b896 30%, #a07850 60%, #6b4423 85%, #3d2010 100%);
}
.legend-source { font-size: 9px; color: #94a3b8; margin-top: 5px; letter-spacing: 0.02em; }
.fault-holo { background: #c0392b; }
.fault-late { background: #e07020; }
.fault-quat { background: #b08030; }

/* ── Vertical exaggeration float ────────────────────────────────────────── */
/* Pin the profile card to a fixed footprint so Chart.js init doesn't shift the layout */
.panel-card { min-height: 180px; overflow: hidden; }
#profilePanel { height: 220px; min-height: 220px; max-height: 220px; overflow: hidden; position: relative; }
.panel-card.tall {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.panel-card.tall .panel-placeholder {
  aspect-ratio: 4 / 3;
  height: auto;
  min-height: 0;
  width: 100%;
}

.exag-float {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.32);
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 24px;
  padding: 12px 8px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 8px 32px rgba(0,0,0,0.10), inset 0 1px 0 rgba(255,255,255,0.7);
  pointer-events: all;
}
.exag-label {
  font-size: 9px;
  font-family: var(--font-mono);
  color: #475569;
  line-height: 1;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  user-select: none;
}
.exag-title {
  font-size: 8px;
  font-family: var(--font-mono);
  color: #94a3b8;
  letter-spacing: 0.03em;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  user-select: none;
}
.exag-float input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  height: 220px !important;
  width: 20px !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
  accent-color: #1d4ed8;
  margin: 0 !important;
}

/* ── Mini map ────────────────────────────────────────────────────────────── */
.mini-map {
  margin-top: 10px;
  height: 170px;
  border: 1px solid #d3d8e0;
  border-radius: 12px;
  overflow: hidden;
  background: #f7f9fc;
}

/* ── Help modal ──────────────────────────────────────────────────────────── */
.help-modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.42);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.help-inner {
  background: #fff;
  border-radius: 18px;
  max-width: 660px;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  padding: 28px 32px 32px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}
.help-header h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: #111;
}
.help-close {
  background: #f1f5f9 !important;
  color: #64748b !important;
  border: none !important;
  border-radius: 100px !important;
  width: 30px !important;
  height: 30px !important;
  min-width: 30px;
  padding: 0 !important;
  font-size: 13px !important;
  cursor: pointer;
  flex-shrink: 0;
}
.help-close:hover { background: #e2e8f0 !important; }
.help-body section {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid #f1f5f9;
}
.help-body section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.help-body h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: #111; }
.help-body h4 { font-size: 12px; font-weight: 600; margin: 10px 0 4px; color: #334155; }
.help-body p  { font-size: 13px; line-height: 1.75; color: #374151; margin: 0 0 7px; }
.help-body p:last-child { margin: 0; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer-divider {
  height: 1px;
  background: var(--border);
  margin-top: 48px;
}
.footer-wrap {
  padding-top: 24px;
  padding-bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.footer-copy {
  margin: 0;
  font-size: 12px;
  color: var(--text-ter);
  font-weight: 500;
}
.footer-disclaimer {
  margin: 0;
  font-size: 11px;
  line-height: 1.75;
  color: #b0b7c3;
  max-width: 860px;
  text-align: center;
}
.footer-disclaimer strong {
  font-weight: 600;
  color: #94a3b8;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; }
  .right-grid { grid-template-rows: none; display: flex; flex-direction: column; min-height: auto; }
}
