:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #172033;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --canvas: #f3f5f8;
  --accent: #1f4f78;
  --accent-dark: #173a59;
  --accent-soft: #e9f0f6;
  --warning: #8b5e14;
  --warning-soft: #fff4d6;
  --success: #235c42;
  --success-soft: #e8f4ed;
  --danger: #9f2d2d;
  --danger-soft: #fbeaea;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
}

body {
  min-width: 320px;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(31, 79, 120, 0.3);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.subtitle {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.privacy-note {
  max-width: 320px;
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid #bfd0df;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.82rem;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}

.control-panel {
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.panel-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
}

.file-picker {
  display: grid;
  gap: 5px;
  padding: 16px;
  border: 1px dashed #9fb0c0;
  border-radius: 12px;
  background: #fafbfd;
  cursor: pointer;
}

.file-picker:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-picker-title {
  font-weight: 700;
}

.file-picker-help,
.helper-text,
.switch-row small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.file-picker input {
  width: 100%;
  margin-top: 6px;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border-radius: 9px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid #aab4c0;
  background: #ffffff;
  color: var(--ink);
}

.secondary-button:hover:not(:disabled) {
  background: #f5f7fa;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.helper-text {
  margin: 9px 0 0;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfd;
}

.switch-row.compact {
  margin-top: 14px;
  padding: 10px 12px;
}

.switch-row span {
  display: grid;
  gap: 2px;
}

.switch-row input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.field-label {
  display: block;
  margin: 16px 0 6px;
  font-size: 0.82rem;
  font-weight: 700;
}

.text-input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #aab4c0;
  border-radius: 9px;
  background: #ffffff;
  color: var(--ink);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.metric {
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfd;
}

.metric span {
  color: var(--muted);
  font-size: 0.75rem;
}

.metric strong {
  font-size: 1.2rem;
}

.quality-summary {
  margin-top: 12px;
  padding: 10px 11px;
  border-radius: 9px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.quality-summary.success {
  background: var(--success-soft);
  color: var(--success);
}

.quality-summary.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.quality-summary.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.bail-gradient {
  height: 13px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 999px;
  background: linear-gradient(90deg, hsl(220 72% 46%), hsl(120 67% 42%), hsl(56 88% 48%), hsl(0 72% 48%));
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.74rem;
}

.map-panel {
  position: relative;
  min-height: 620px;
  background: #dce3e8;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 620px;
}

.empty-map-message {
  position: absolute;
  z-index: 500;
  top: 50%;
  left: 50%;
  display: grid;
  gap: 5px;
  width: min(360px, calc(100% - 40px));
  padding: 18px;
  transform: translate(-50%, -50%);
  border: 1px solid #c6d0d8;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  text-align: center;
}

.empty-map-message span {
  color: var(--muted);
  font-size: 0.85rem;
}

.progress-panel {
  position: absolute;
  z-index: 1000;
  top: 16px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(430px, calc(100% - 32px));
  padding: 13px 15px;
  transform: translateX(-50%);
  border: 1px solid #b9c4ce;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 6px 20px rgba(26, 40, 55, 0.14);
}

.progress-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid #d5dde4;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.leaflet-popup-content-wrapper {
  border-radius: 10px;
}

.leaflet-popup-content {
  width: min(420px, 72vw) !important;
  max-height: 460px;
  overflow-y: auto;
  margin: 14px 16px;
}

.popup-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.popup-heading h3 {
  margin: 0;
  font-size: 1rem;
}

.popup-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.popup-bail {
  white-space: nowrap;
  padding: 5px 7px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
}

.popup-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.popup-chip {
  padding: 4px 7px;
  border-radius: 999px;
  background: #eef1f4;
  color: #475467;
  font-size: 0.72rem;
  font-weight: 700;
}

.popup-chip.unincorporated {
  background: var(--warning-soft);
  color: var(--warning);
}

.popup-chip.review {
  background: var(--danger-soft);
  color: var(--danger);
}

.record-card {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.record-card:first-of-type {
  border-top: 0;
}

.record-title {
  margin: 0 0 8px;
  font-size: 0.88rem;
}

.record-grid {
  display: grid;
  grid-template-columns: minmax(90px, 0.8fr) minmax(0, 1.5fr);
  gap: 4px 10px;
  font-size: 0.77rem;
  line-height: 1.35;
}

.record-grid dt {
  color: var(--muted);
  font-weight: 700;
}

.record-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.boundary-tooltip {
  font-weight: 700;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    padding: 18px;
  }

  .privacy-note {
    max-width: none;
  }

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

  .control-panel {
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-panel,
  #map {
    min-height: 560px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .control-panel {
    padding: 15px;
  }

  .map-panel,
  #map {
    min-height: 500px;
  }
}

[hidden] {
  display: none !important;
}

.export-button {
  margin-top: 14px;
}

.export-help {
  margin-top: 7px;
}
