/* ---------------------------------------------------------------------------
   Operational design for emergency-management dashboards.
   Dark sidebar (operational console), edge-to-edge map, dense information
   hierarchy, color chips for layer identity.

   Theming: five named palettes, selected via `theme: <name>` in config.yaml.
   All themes share layout, typography, and component patterns; they vary in
   the dark background hue, interactive accent, and status pulse color.
     - operations  default neutral slate + sky blue + amber
     - wildland    warm dark + ember orange — fire / drought dashboards
     - coastal     deep teal + cyan — water / weather monitoring
     - civic       navy + gold — official / public-facing
     - tactical    charcoal + red — high-alert / incident response
   --------------------------------------------------------------------------- */

:root, .theme-operations {
  --ink:           #e2e8f0;
  --ink-dim:       #94a3b8;
  --ink-faint:     #64748b;
  --panel:         #0f172a;
  --panel-2:       #1e293b;
  --panel-line:    #1e293b;
  --panel-line-2:  #334155;
  --accent:        #38bdf8;
  --accent-dim:    #0ea5e9;
  --warn:          #f59e0b;
  --warn-glow:     rgba(245, 158, 11, 0.2);
  --header-bg:     #0b1220;
  --map-bg:        #e9eef2;
  --radius:        6px;
}

.theme-wildland {
  --ink:           #f5f0e8;
  --ink-dim:       #b9ad97;
  --ink-faint:     #7c7460;
  --panel:         #1c1410;
  --panel-2:       #2a1f19;
  --panel-line:    #2a1f19;
  --panel-line-2:  #3d2e24;
  --accent:        #fb923c;
  --accent-dim:    #ea7c1e;
  --warn:          #fde68a;
  --warn-glow:     rgba(253, 230, 138, 0.22);
  --header-bg:     #140d0a;
  --map-bg:        #efe9df;
}

.theme-coastal {
  --ink:           #e0f0f0;
  --ink-dim:       #8ba8a8;
  --ink-faint:     #5b7878;
  --panel:         #0c1f1f;
  --panel-2:       #163030;
  --panel-line:    #163030;
  --panel-line-2:  #2a4747;
  --accent:        #22d3ee;
  --accent-dim:    #06b6d4;
  --warn:          #facc15;
  --warn-glow:     rgba(250, 204, 21, 0.22);
  --header-bg:     #061515;
  --map-bg:        #e6efef;
}

.theme-civic {
  --ink:           #e6ebf2;
  --ink-dim:       #98a3b3;
  --ink-faint:     #6b7588;
  --panel:         #0a1a30;
  --panel-2:       #142a47;
  --panel-line:    #142a47;
  --panel-line-2:  #243d5e;
  --accent:        #eab308;
  --accent-dim:    #ca9a07;
  --warn:          #f97316;
  --warn-glow:     rgba(249, 115, 22, 0.22);
  --header-bg:     #061224;
  --map-bg:        #e9eef2;
}

.theme-tactical {
  --ink:           #e5e5e5;
  --ink-dim:       #a3a3a3;
  --ink-faint:     #737373;
  --panel:         #141414;
  --panel-2:       #1f1f1f;
  --panel-line:    #1f1f1f;
  --panel-line-2:  #2e2e2e;
  --accent:        #f87171;
  --accent-dim:    #dc2626;
  --warn:          #fbbf24;
  --warn-glow:     rgba(251, 191, 36, 0.25);
  --header-bg:     #0a0a0a;
  --map-bg:        #e9eaec;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  color: var(--ink);
  background: var(--panel);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0;
}

main#app.loading {
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  font-size: 14px;
}

/* ----- Top bar ----------------------------------------------------------- */

.dash-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--panel-line-2);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.dash-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  white-space: nowrap;
}
.dash-header .subtitle {
  margin: 0;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--ink-dim);
  border-left: 1px solid var(--panel-line-2);
  padding-left: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-header::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--warn);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--warn-glow);
  flex-shrink: 0;
}

/* ----- Layout ------------------------------------------------------------ */

.dash-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  min-height: 0;
}

/* ----- Sidebar ----------------------------------------------------------- */

.sidebar {
  background: var(--panel);
  padding: 18px 18px 24px;
  overflow-y: auto;
  border-right: 1px solid var(--panel-line-2);
  font-size: 13px;
}

.sidebar h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--panel-line-2);
}
.sidebar h2:first-child {
  margin-top: 0;
}

.sidebar .field-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  margin: 14px 0 6px;
}

/* Geography radio group */
.sidebar .radio-group {
  display: flex;
  gap: 0;
  background: var(--panel-2);
  padding: 3px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-line-2);
}
.sidebar .radio-group label {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 80ms, background 80ms;
}
.sidebar .radio-group label:has(input:checked) {
  background: var(--accent-dim);
  color: #fff;
  font-weight: 600;
}
.sidebar .radio-group input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Choropleth selector */
.sidebar select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 28px 8px 10px;
  border: 1px solid var(--panel-line-2);
  border-radius: var(--radius);
  background: var(--panel-2)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%2394a3b8' stroke-width='1.5'/></svg>")
    no-repeat right 10px center;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.sidebar select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Sector headers — small uppercase eyebrow with colored tick */
.sector-header {
  position: relative;
  margin: 16px 0 6px;
  padding-left: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.sector-header::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1px;
  bottom: 1px;
  width: 3px;
  border-radius: 2px;
  background: var(--sector-color, var(--accent));
}

/* Layer rows */
.layer-toggle {
  display: grid;
  grid-template-columns: 16px 10px 1fr;
  gap: 10px;
  align-items: center;
  margin: 4px 0;
  padding: 4px 4px 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: background 80ms;
}
.layer-toggle:hover {
  background: var(--panel-2);
}
.layer-toggle input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.layer-toggle .chip {
  width: 10px;
  height: 10px;
  background: var(--chip);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
}
.layer-toggle .label {
  font-weight: 500;
  letter-spacing: 0.005em;
}
.layer-toggle:has(input:not(:checked)) .label {
  color: var(--ink-dim);
}
.layer-toggle:has(input:not(:checked)) .chip {
  opacity: 0.45;
}

/* About block */
.about {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-dim);
}
.about p {
  margin: 0 0 8px;
}
.about strong {
  color: var(--ink);
  font-weight: 600;
}
.about em {
  font-style: italic;
  color: var(--ink);
}
.about ul {
  margin: 6px 0 0 18px;
  padding: 0;
}
.about li {
  margin-bottom: 3px;
}
.about a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.about a:hover {
  border-bottom-color: var(--accent);
}

hr.divider {
  border: 0;
  border-top: 1px solid var(--panel-line-2);
  margin: 18px 0;
}

/* ----- Map area ---------------------------------------------------------- */

.map-wrap {
  position: relative;
  background: var(--map-bg);
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* Status pill — anchored top-left, shows geography + selector context */
.map-wrap::before {
  content: "";
}

/* Continuous legend */
.legend {
  position: absolute;
  bottom: 18px;
  left: 18px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink-dim) 25%, transparent);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  z-index: 2;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.legend .title {
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.legend .bar {
  width: 160px;
  height: 8px;
  border-radius: 1px;
}
.legend .ends {
  display: flex;
  justify-content: space-between;
  width: 160px;
  margin-top: 4px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* ----- Popups ------------------------------------------------------------ */

.maplibregl-popup-content {
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel-line-2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.maplibregl-popup-content strong {
  color: var(--ink);
  font-weight: 600;
}
.maplibregl-popup-tip {
  border-top-color: var(--panel) !important;
  border-bottom-color: var(--panel) !important;
}
.maplibregl-popup-close-button {
  color: var(--ink-dim);
  font-size: 18px;
  padding: 2px 6px;
}

/* Nav control on dark theme */
.maplibregl-ctrl-group {
  background: color-mix(in srgb, var(--panel) 92%, transparent) !important;
  border: 1px solid color-mix(in srgb, var(--ink-dim) 25%, transparent) !important;
  backdrop-filter: blur(6px);
}
.maplibregl-ctrl-group button {
  background-color: transparent !important;
}
.maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(0.85);
}

/* ----- Scrollbar polish (sidebar) --------------------------------------- */

.sidebar::-webkit-scrollbar {
  width: 8px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--panel-line-2);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--ink-dim) 60%, var(--panel-line-2));
}

/* ----- Responsive -------------------------------------------------------- */

@media (max-width: 900px) {
  .dash-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--panel-line-2);
  }
}
