:root {
  --heading: #0c394c;
  --primary: #2a685f;
  --primary-dark: #205149;
  --paper: #f8f7f2;
  --surface: #ffffff;
  --ink: #1e293b;
  --muted: #667085;
  --line: #d9dfdd;
  --very-high: #7f1d1d;
  --high: #c2410c;
  --elevated: #d97706;
  --general: #2a685f;
  --unscored: #94a3b8;
  --shadow: 0 10px 28px rgba(12,57,76,.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
}

body {
  font-family: Inter, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="search"] {
  border-radius: 8px;
}

#app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 108px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-block h1,
.detail-panel h2,
dialog h2 {
  margin: 0;
  color: var(--heading);
  font-family: "EB Garamond", Georgia, serif;
}

.brand-block h1 {
  font-size: clamp(30px, 3vw, 44px);
  line-height: .95;
}

.brand-block p {
  margin: 7px 0 0;
  color: var(--muted);
}

.brand-kicker {
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.primary-button {
  color: white;
  background: var(--primary);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  color: var(--primary);
  background: white;
}

.ghost-button:hover {
  background: #eef5f3;
}

.compact {
  min-height: 38px;
}

.full-width {
  width: 100%;
}

.status-strip {
  min-height: 32px;
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 6px 28px;
  background: #eef5f3;
  color: var(--heading);
  border-bottom: 1px solid #d4e5e0;
  font-size: 12px;
}

.workspace {
  flex: 1;
  min-height: 720px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  overflow: hidden;
}

.control-panel,
.detail-panel {
  background: var(--surface);
  overflow-y: auto;
  z-index: 3;
}

.control-panel {
  padding: 20px;
  border-right: 1px solid var(--line);
}

.detail-panel {
  padding: 20px;
  border-left: 1px solid var(--line);
}

.search-section,
.filter-section,
.legend-section,
.action-section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.action-section {
  border-bottom: 0;
}

.section-heading,
.search-section > label {
  display: block;
  margin-bottom: 10px;
  color: var(--heading);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 19px;
  font-weight: 700;
}

.control-panel label:not(.check-row) {
  display: block;
  margin: 12px 0 6px;
  color: #344054;
  font-size: 12px;
  font-weight: 600;
}

select,
input[type="search"] {
  width: 100%;
  min-height: 39px;
  padding: 8px 10px;
  color: var(--ink);
  background: white;
  border: 1px solid #cbd5d1;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search-results {
  max-height: 240px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-y: auto;
  background: white;
}

.search-result {
  width: 100%;
  display: block;
  padding: 9px 10px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #eef1f0;
  background: white;
  cursor: pointer;
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover {
  background: #f4f8f7;
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.check-grid {
  display: grid;
  gap: 10px;
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #344054;
  font-size: 13px;
  cursor: pointer;
}

.check-row input {
  accent-color: var(--primary);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.very-high { background: var(--very-high); }
.dot.high { background: var(--high); }
.dot.elevated { background: var(--elevated); }
.dot.general { background: var(--general); }
.dot.unscored { background: var(--unscored); }

.text-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--primary);
  font-size: 12px;
}

.map-panel {
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.kpi-stack {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
  pointer-events: none;
}

.kpi-card {
  min-width: 128px;
  padding: 10px 12px;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(217,223,221,.95);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(12,57,76,.10);
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.kpi-card strong {
  display: block;
  margin-top: 2px;
  color: var(--heading);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 24px;
}

.loading-indicator {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 4;
  transform: translateX(-50%);
  padding: 8px 12px;
  color: white;
  background: rgba(12,57,76,.92);
  border-radius: 18px;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.detail-empty {
  color: var(--muted);
}

.detail-panel h2 {
  font-size: 27px;
  line-height: 1;
}

.detail-address {
  margin: 8px 0 2px;
  color: var(--ink);
  font-weight: 600;
}

.detail-pin {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.score-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.score-number {
  color: var(--heading);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 42px;
  line-height: .9;
}

.score-label {
  color: var(--muted);
  font-size: 11px;
}

.tier-chip,
.signal-chip {
  display: inline-block;
  margin: 4px 4px 4px 0;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}

.tier-chip {
  color: white;
  background: var(--primary);
}

.signal-chip {
  color: #7c2d12;
  background: #ffedd5;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-top: 18px;
}

.detail-item {
  min-width: 0;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.detail-item strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.conditional-block {
  margin-top: 22px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.conditional-block h3 {
  margin: 0 0 8px;
  color: var(--heading);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 19px;
}

.conditional-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.conditional-table td {
  padding: 5px 0;
  vertical-align: top;
  border-bottom: 1px solid #eef1f0;
}

.conditional-table td:first-child {
  width: 52%;
  padding-right: 10px;
  color: var(--muted);
}

.site-footer {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  padding: 18px 28px;
  color: #e8efed;
  background: var(--heading);
  font-size: 11px;
}

.site-footer strong,
.site-footer span {
  display: block;
}

.site-footer p {
  margin: 0;
  line-height: 1.45;
}

dialog {
  max-width: 620px;
  padding: 28px;
  border: 0;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15,23,42,.48);
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
}

.maplibregl-popup-content {
  max-width: 280px;
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-family: Inter, Arial, sans-serif;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .detail-panel {
    position: fixed;
    top: 140px;
    right: 12px;
    bottom: 12px;
    width: min(360px, calc(100vw - 24px));
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 8;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 16px;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .status-strip {
    padding: 6px 16px;
  }

  .workspace {
    min-height: 900px;
    grid-template-columns: 1fr;
    grid-template-rows: auto 650px;
    overflow: visible;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-panel {
    min-height: 650px;
  }

  .detail-panel {
    top: 12px;
    right: 12px;
    bottom: 12px;
  }

  .kpi-stack {
    top: 10px;
    left: 10px;
    grid-template-columns: repeat(2, minmax(105px, 1fr));
  }

  .kpi-card {
    min-width: 105px;
  }

  .site-footer {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}
