/* ── Reset & base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --color-bg-header: #1f2933;
  --color-text-header: #f9fafb;
  --color-bg-page: #f3f4f6;
  --color-border: #e5e7eb;
  --color-muted: #6b7280;
  --color-link: #2563eb;
  --color-status-287g: #ef4444;
  --color-status-detainers: #f97316;
  --color-status-none: #e5e7eb;
  --color-status-unknown: #9ca3af;
  --sidebar-width: 380px;
  --header-height: 80px;
  --footer-height: 40px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  font-size: 0.95rem;
  background: var(--color-bg-page);
  color: #111827;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--color-bg-header);
  color: var(--color-text-header);
  min-height: var(--header-height);
}

header h1 {
  font-size: 1.1rem;
  margin: 0 0 0.15rem;
}

.subtitle {
  margin: 0;
  font-size: 0.8rem;
  opacity: 0.75;
  max-width: 560px;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  font-size: 0.78rem;
  opacity: 0.8;
  white-space: nowrap;
}

.about-link {
  color: #93c5fd;
  text-decoration: none;
}
.about-link:hover {
  text-decoration: underline;
}

/* ── Loading overlay ──────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  font-size: 1.1rem;
  font-weight: 500;
  transition: opacity 0.3s;
}
#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Main layout ──────────────────────────────────────────── */
main {
  display: flex;
  flex-wrap: wrap;
  height: calc(100vh - var(--header-height) - var(--footer-height));
}

/* ── Map section ──────────────────────────────────────────── */
#map-section {
  flex: 1 1 60%;
  min-width: 300px;
  position: relative;
  display: flex;
  flex-direction: column;
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.4rem 0.75rem;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.82rem;
}

#toolbar label {
  font-weight: 600;
  color: #374151;
}

#toolbar select,
#toolbar input[type="search"] {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.82rem;
  background: #fff;
}

#map {
  flex: 1;
  min-height: 200px;
}

#map-legend {
  position: absolute;
  bottom: 28px;
  left: 10px;
  background: rgba(255, 255, 255, 0.94);
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
  line-height: 1.7;
  z-index: 500;
}

#map-legend .swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  flex: 0 0 var(--sidebar-width);
  max-width: var(--sidebar-width);
  min-width: 260px;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  background: #fff;
  border-left: 1px solid var(--color-border);
}

#sidebar h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin: 0.5rem 0 0.4rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.3rem;
}

#county-summary h3 {
  margin: 0.4rem 0 0.5rem;
  font-size: 1.1rem;
}

#county-summary p {
  margin: 0.25rem 0;
  line-height: 1.5;
}

#county-summary .status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}
.status-badge.s-287g   { background: var(--color-status-287g); }
.status-badge.s-detainers { background: var(--color-status-detainers); color: #fff; }
.status-badge.s-none   { background: #6b7280; }
.status-badge.s-unknown { background: var(--color-status-unknown); color: #374151; }

.prompt {
  color: var(--color-muted);
  font-style: italic;
}

#charts {
  margin-top: 0.75rem;
}

canvas {
  max-width: 100%;
  margin-bottom: 1.25rem;
  display: block;
}

.muted {
  color: var(--color-muted);
  font-size: 0.82rem;
}

/* ── About box ────────────────────────────────────────────── */
.about-box {
  margin-top: 1rem;
  padding: 0.75rem;
  background: #f9fafb;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.82rem;
}

.about-box p {
  margin: 0.4rem 0;
  line-height: 1.5;
}

.about-box a {
  color: var(--color-link);
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  height: var(--footer-height);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--color-bg-header);
  color: rgba(249, 250, 251, 0.7);
  font-size: 0.75rem;
  overflow: hidden;
}

footer a {
  color: #93c5fd;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  main {
    flex-direction: column;
    height: auto;
  }

  #map-section {
    height: 55vh;
    min-height: 260px;
  }

  #sidebar {
    flex: unset;
    max-width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }

  #map-legend {
    bottom: 10px;
    font-size: 0.72rem;
  }

  footer {
    height: auto;
    padding: 0.5rem 1rem;
  }
}

/* ── Highlighted county ───────────────────────────────────── */
.county-hover {
  filter: brightness(0.82);
}
