:root {
  --panel-bg: rgba(255, 255, 255, 0.96);
  --ink: #1c2530;
  --muted: #5c6b7a;
  --border: rgba(0, 0, 0, 0.12);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 4px 18px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}

#map {
  position: absolute;
  inset: 0;
  background: #e8eef2;
}

/* Loading / error overlay */
#loading {
  position: absolute;
  inset: 0;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(232, 238, 242, 0.92);
  color: var(--muted);
  font-size: 14px;
}
#loading .spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(33, 113, 181, 0.25);
  border-top-color: #2171b5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#loading p { margin: 0; }
#loading .err {
  max-width: 420px;
  text-align: center;
  line-height: 1.5;
  color: var(--ink);
}
#loading .err code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Generic floating panel */
.panel {
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  border: 1px solid var(--border);
}

/* Header / controls (top-left) */
.app-header { max-width: 320px; }
.app-header h1 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: -0.2px;
}

/* Tabs */
.app-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--border);
}
.app-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 10px;
  margin-bottom: -1px;
  cursor: pointer;
}
.app-tab:hover { color: var(--ink); }
.app-tab.active { color: #2171b5; border-bottom-color: #2171b5; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* About panel */
.about { max-height: 80vh; overflow-y: auto; }
.about p { margin: 0 0 9px; font-size: 12.5px; line-height: 1.5; color: var(--ink); }
.about p:last-child { margin-bottom: 0; }
.about .about-h {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); font-weight: 700; margin: 12px 0 4px;
}

/* Disclaimer panel (reuses .about styling) */
.disclaimer .disc-lead { font-weight: 600; }
.disclaimer ul.disc-list { margin: 0; padding-left: 16px; }
.disclaimer ul.disc-list li {
  font-size: 12px; line-height: 1.45; color: var(--ink); margin-bottom: 6px;
}
.disclaimer ul.disc-list li:last-child { margin-bottom: 0; }
.disclaimer a { color: #2171b5; }

/* Search box */
.search { display: flex; gap: 6px; margin-top: 4px; }
.search-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}
.search-input:focus { outline: 2px solid #2171b5; outline-offset: -1px; border-color: #2171b5; }
.search-go {
  flex: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border: none;
  border-radius: 7px;
  background: #2171b5;
  color: #fff;
  cursor: pointer;
}
.search-go:hover { background: #1a5a96; }
.search-status { font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 6px; }
.search-status.warn { color: #b23b2e; }

/* Basemap toggle */
.basemap-toggle { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 13px; }
.basemap-toggle .bt-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.basemap-toggle label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.basemap-toggle input { accent-color: #2171b5; cursor: pointer; }

/* Info box (top-right) */
.info { max-width: 260px; min-width: 220px; }
.info h2 {
  margin: 0 0 8px;
  font-size: 15px;
}
.info .hint { color: var(--muted); font-size: 12px; font-style: italic; }
.info .oa-code {
  margin: -4px 0 8px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.info table { width: 100%; border-collapse: collapse; font-size: 13px; }
.info td { padding: 3px 0; vertical-align: top; }
.info td.label { color: var(--muted); }
.info td.value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.info .accent { color: #08519c; }

/* Search result panel */
.info { max-width: 300px; }
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.result-head h2 { margin: 0; }
.clear-btn {
  flex: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.clear-btn:hover { color: var(--ink); }
.info .addr { margin: 4px 0 6px; font-size: 13px; line-height: 1.35; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.cmp th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border);
}
table.cmp th:last-child { text-align: right; }
table.cmp tr td { border-bottom: 1px solid rgba(0, 0, 0, 0.05); }
.info .area-detail { margin: 10px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }
.info .compare {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 10px;
  background: rgba(33, 113, 181, 0.08);
  border-radius: 7px;
}

/* Legend (bottom-right) */
.legend { line-height: 1.5; }
.legend .legend-title { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend .swatch {
  width: 18px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex: none;
}
.legend .footnote {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  max-width: 200px;
}

.leaflet-container { font: inherit; }
.credit { font-size: 11px; color: var(--muted); margin-top: 10px; }
.credit a { color: var(--muted); }

@media (max-width: 640px) {
  .app-header { max-width: 60vw; }
  .info { display: none; }
}
