:root {
  color-scheme: dark;
  --bg: #0b0e0f;
  --panel: rgba(12, 16, 17, 0.91);
  --panel-solid: #101415;
  --panel-raised: rgba(28, 34, 35, 0.88);
  --border: rgba(224, 231, 225, 0.13);
  --border-strong: rgba(224, 231, 225, 0.25);
  --text-primary: #ece8df;
  --text-secondary: #9eaaa4;
  --muted: #6f7c77;
  --live: #c5ea49;
  --error: #d0705f;
  --shadow: rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #dce5e5;
  --panel: rgba(245, 248, 247, 0.92);
  --panel-solid: #f4f7f6;
  --panel-raised: rgba(228, 234, 232, 0.92);
  --border: rgba(23, 35, 34, 0.15);
  --border-strong: rgba(23, 35, 34, 0.28);
  --text-primary: #171d1c;
  --text-secondary: #53615d;
  --muted: #77847f;
  --live: #617d0b;
  --error: #9c3f32;
  --shadow: rgba(24, 37, 35, 0.17);
}

* { box-sizing: border-box; }

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
}

button,
input,
select { font: inherit; }

button { color: inherit; }

#map { position: fixed; inset: 0; background: var(--bg); }

.map-shade {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(7, 10, 11, 0.2), transparent 22%, transparent 78%, rgba(7, 10, 11, 0.22)),
    linear-gradient(180deg, rgba(7, 10, 11, 0.08), transparent 30%, rgba(7, 10, 11, 0.12));
}

:root[data-theme="light"] .map-shade { opacity: 0.22; }

.shell { position: fixed; inset: 0; z-index: 2; pointer-events: none; }

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 54px var(--shadow);
  backdrop-filter: blur(14px) saturate(115%);
  pointer-events: auto;
}

.topbar {
  position: absolute;
  top: 18px;
  left: 50%;
  display: flex;
  width: min(780px, calc(100vw - 690px));
  min-height: 88px;
  padding: 15px 18px;
  transform: translateX(-50%);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow,
.metric-label,
.section-heading,
.feed-rank,
.count-badge,
.map-controls,
.dossier-metric span,
.status-pill {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.eyebrow,
.metric-label,
.section-heading,
.dossier-metric span { color: var(--text-secondary); }

.title-line { display: flex; align-items: center; gap: 9px; margin-top: 5px; }

h1,
h2,
p { margin: 0; }

h1 { font-size: 20px; line-height: 1.1; letter-spacing: -0.01em; }
h2 { font-size: 18px; line-height: 1.2; letter-spacing: -0.01em; }

.subtle { display: block; margin-top: 7px; color: var(--text-secondary); font-size: 11px; }

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 18%, transparent);
}

.connection-dot[data-state="online"] { background: var(--live); box-shadow: 0 0 0 4px color-mix(in srgb, var(--live) 18%, transparent); }
.connection-dot[data-state="error"] { background: var(--error); }

.topbar-metrics { display: flex; align-items: stretch; gap: 10px; }

.panel-toggles { display: none; }

.metric-chip {
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-raised);
}

.metric-chip strong { display: block; margin-top: 5px; font-size: 14px; }

.icon-button,
.panel-toggle,
.map-controls button,
.locate-button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-raised);
  cursor: pointer;
}

.icon-button {
  display: flex;
  min-width: 86px;
  padding: 10px 12px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.panel-toggle {
  min-height: 38px;
  padding: 0 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.theme-icon { width: 11px; height: 11px; border: 1.5px solid currentColor; border-radius: 50%; box-shadow: inset 5px 0 0 currentColor; }

.left-rail,
.right-drawer {
  position: absolute;
  top: 18px;
  bottom: 18px;
  width: 330px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.left-rail { left: 18px; padding: 20px 16px 18px; }
.right-drawer { right: 18px; padding: 21px 18px; }

.rail-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 0 4px; }
.rail-header h2 { margin-top: 5px; }

.count-badge {
  display: grid;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
}

.filters { display: grid; grid-template-columns: 1fr 108px; gap: 8px; margin: 18px 0 20px; }

.search-field input,
.select-field select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--panel-raised);
  color: var(--text-primary);
  font-size: 11px;
}

.search-field input:focus,
.select-field select:focus { border-color: var(--border-strong); }

.section-heading { display: flex; justify-content: space-between; align-items: center; }
.feed-section + .feed-section { margin-top: 24px; }
.feed-list { display: grid; gap: 7px; margin-top: 10px; }

.feed-row {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 9px;
  width: 100%;
  min-width: 0;
  padding: 11px 10px 13px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-raised);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.feed-row:hover { border-color: var(--border-strong); transform: translateX(2px); }
.feed-row.is-selected { border-color: var(--text-secondary); background: color-mix(in srgb, var(--panel-raised) 78%, var(--text-secondary)); }
.feed-rank { padding-top: 2px; color: var(--muted); }
.feed-copy { min-width: 0; }
.feed-copy strong { display: block; overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.feed-copy span { display: block; margin-top: 4px; overflow: hidden; color: var(--text-secondary); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.feed-delta { padding-top: 1px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace; font-size: 11px; font-weight: 600; }
.feed-bar { position: absolute; right: 0; bottom: 0; left: 43px; height: 2px; background: var(--border); }
.feed-bar i { display: block; height: 100%; opacity: 0.8; }
.feed-list.compact .feed-row { padding-bottom: 11px; }

.signal-health { margin-top: 25px; padding: 16px 4px 0; border-top: 1px solid var(--border); }
.health-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.health-grid div { display: flex; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-raised); justify-content: space-between; font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace; font-size: 9px; color: var(--text-secondary); }
.health-grid strong { font-size: 10px; }

.empty-copy,
.empty-state p,
.address,
.location { color: var(--text-secondary); font-size: 12px; line-height: 1.55; }
.empty-copy { padding: 13px 2px; }
.empty-state { padding: 2px; }
.empty-state h2 { margin: 7px 0 9px; }

.dossier-header { position: relative; padding-bottom: 19px; border-bottom: 1px solid var(--border); }
.dossier-header h2 { margin-top: 9px; padding-right: 85px; font-size: 20px; }
.location { margin-top: 6px; }
.address { margin-top: 10px; }

.status-pill {
  position: absolute;
  top: 0;
  right: 0;
  padding: 5px 7px;
  border: 1px solid color-mix(in srgb, var(--status) 55%, transparent);
  border-radius: 5px;
  color: var(--status);
  background: color-mix(in srgb, var(--status) 8%, transparent);
}

.dossier-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 17px; }
.dossier-metric { min-width: 0; padding: 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-raised); }
.dossier-metric span { display: block; }
.dossier-metric strong { display: block; margin-top: 6px; overflow-wrap: anywhere; font-size: 12px; text-transform: uppercase; }

.chart-block { margin-top: 22px; }
.sparkline { display: block; width: 100%; height: 92px; margin-top: 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-raised); }
.sparkline line { stroke: var(--border-strong); stroke-width: 1; }
.sparkline polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-empty { display: grid; height: 92px; margin-top: 10px; place-items: center; border: 1px solid var(--border); border-radius: 7px; color: var(--muted); font-size: 11px; }

.locate-button { width: 100%; margin-top: 20px; padding: 11px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace; font-size: 10px; font-weight: 600; letter-spacing: 0.08em; }

.map-controls {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: flex;
  height: 38px;
  padding: 5px 8px;
  transform: translateX(-50%);
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
}

.map-controls button { padding: 6px 9px; border: 0; background: transparent; font-family: inherit; font-size: inherit; font-weight: inherit; letter-spacing: inherit; }
.control-divider { width: 1px; height: 17px; background: var(--border); }

.loading-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 18px; background: var(--bg); transition: opacity 350ms ease, visibility 350ms ease; }
.loading-screen.is-hidden { opacity: 0; visibility: hidden; }
.loader-mark { width: 42px; height: 42px; border: 1px solid var(--border-strong); border-top-color: var(--live); border-radius: 50%; animation: spin 1s linear infinite; }

.maplibregl-ctrl-bottom-right { right: 360px; bottom: 8px; }
.maplibregl-ctrl-group { border: 1px solid var(--border) !important; background: var(--panel) !important; box-shadow: none !important; }
.maplibregl-ctrl-group button { background-color: transparent !important; }
.maplibregl-ctrl-attrib { background: var(--panel) !important; color: var(--text-secondary) !important; }
.maplibregl-ctrl-attrib a { color: inherit !important; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

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

@media (max-width: 1180px) {
  .left-rail,
  .right-drawer { width: 286px; }
  .topbar { width: calc(100vw - 620px); }
  .topbar .metric-chip:first-child { display: none; }
  .maplibregl-ctrl-bottom-right { right: 314px; }
}

@media (max-width: 900px) {
  .topbar { top: 10px; right: 10px; left: 10px; width: auto; min-height: 72px; padding: 11px 13px; transform: none; }
  h1 { font-size: 16px; }
  .topbar .metric-chip { min-width: 90px; }
  .panel-toggles {
    position: absolute;
    top: 96px;
    right: 10px;
    left: 10px;
    z-index: 6;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    pointer-events: auto;
  }
  .panel-toggle {
    flex: 1;
    max-width: 160px;
    background: var(--panel);
  }
  .left-rail,
  .right-drawer {
    top: 142px;
    bottom: 10px;
    z-index: 5;
    display: none;
    width: min(360px, calc(100vw - 20px));
    max-height: calc(100vh - 152px);
    transition: transform 220ms ease, opacity 180ms ease, visibility 180ms ease;
  }
  .left-rail {
    left: 10px;
    transform: translateX(calc(-100% - 16px));
    opacity: 0;
    visibility: hidden;
  }
  .right-drawer {
    right: 10px;
    transform: translateX(calc(100% + 16px));
    opacity: 0;
    visibility: hidden;
  }
  .shell.feed-open .left-rail,
  .shell.dossier-open .right-drawer {
    display: block;
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
  }
  .map-controls { right: 10px; bottom: 10px; left: auto; transform: none; max-width: calc(100vw - 20px); }
  .maplibregl-ctrl-bottom-right { right: 8px; bottom: 56px; }
}

@media (max-width: 620px) {
  .topbar-metrics .metric-chip { display: none; }
  .topbar { min-height: 80px; }
  .panel-toggles { top: 102px; }
  .left-rail,
  .right-drawer {
    top: 148px;
    width: calc(100vw - 20px);
    max-height: calc(100vh - 158px);
  }
  .filters { grid-template-columns: 1fr; }
  .map-controls span:last-child,
  .control-divider { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
