/* DPD Desk Ops design tokens — from hi-fi mockup */
:root {
  /* ââ Surfaces (warm black) ââ */
  --bg-0: #0a0c10;       /* page */
  --bg-1: #10131a;       /* surface */
  --bg-2: #171b24;       /* raised */
  --bg-3: #1f2530;       /* hover */
  --bg-4: #29303d;       /* pressed */

  /* ââ Borders ââ */
  --br-1: #232936;
  --br-2: #2f3645;
  --br-3: #3b4456;

  /* ââ Foreground ââ */
  --fg-0: #f4f1ea;       /* high contrast (warm white) */
  --fg-1: #c2c0b6;       /* primary */
  --fg-2: #8a8d97;       /* secondary */
  --fg-3: #5a5e69;       /* tertiary */
  --fg-4: #3a3e48;       /* faint */

  /* ââ Priority / alert palette
        oklch-anchored, similar chroma for harmony   ââ */
  --p1: #ff5547;         /* P1 â shooting, homicide */
  --p1-soft: rgba(255,85,71,0.14);
  --p1-line: rgba(255,85,71,0.45);

  --p2: #f5a623;         /* P2 â violence, major dist */
  --p2-soft: rgba(245,166,35,0.14);
  --p2-line: rgba(245,166,35,0.45);

  --p3: #4a9eff;         /* P3 */
  --p3-soft: rgba(74,158,255,0.12);
  --p3-line: rgba(74,158,255,0.4);

  --p4: #7c8493;         /* P4 â routine */
  --p4-soft: rgba(124,132,147,0.12);

  --warn: #f0d452;       /* pattern alert / cluster */
  --warn-soft: rgba(240,212,82,0.14);
  --ok:   #4dbf7d;       /* at-scene confirmed */
  --air:  #c084f5;       /* air unit highlight */

  /* ââ Type ââ */
  --font-ui: "Geist", "Inter", -apple-system, system-ui, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, monospace;

  /* ââ Radii ââ */
  --r-1: 4px;
  --r-2: 6px;
  --r-3: 10px;

  /* ââ Shadow ââ */
  --shadow-1: 0 1px 0 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 8px 24px rgba(0,0,0,0.5), 0 1px 0 0 rgba(255,255,255,0.04) inset;
  --shadow-glow: 0 0 0 1px rgba(255,255,255,0.06), 0 12px 36px rgba(0,0,0,0.6);

  /* ââ Spacing scale (4px base) ââ */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
}

html, body { margin: 0; padding: 0; background: var(--bg-0); color: var(--fg-1); font-family: var(--font-ui); overflow: hidden; }

#alert-ribbon {
  flex-shrink: 0;
  border-bottom: 1px solid var(--br-1);
}
*, *::before, *::after { box-sizing: border-box; }

/* ââ Typography ââ */
.t-display {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
  color: var(--fg-0);
}
.t-h1 { font-size: 14px; font-weight: 600; color: var(--fg-0); letter-spacing: -0.005em; }
.t-h2 { font-size: 12px; font-weight: 600; color: var(--fg-1); letter-spacing: 0.02em; text-transform: uppercase; }
.t-body { font-size: 13px; color: var(--fg-1); line-height: 1.4; }
.t-body-sm { font-size: 12px; color: var(--fg-1); line-height: 1.4; }
.t-mono { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-2); font-feature-settings: "tnum"; letter-spacing: 0; }
.t-mono-md { font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-1); font-feature-settings: "tnum"; }
.t-mono-lg { font-family: var(--font-mono); font-size: 14px; color: var(--fg-0); font-feature-settings: "tnum"; }
.t-num { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.t-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-3); }
.t-muted { color: var(--fg-2); }
.t-faint { color: var(--fg-3); }

/* ââ Layout helpers ââ */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }
.flex-1 { flex: 1; min-width: 0; min-height: 0; }
.hide-scrollbar::-webkit-scrollbar { display: none; }
.hide-scrollbar { scrollbar-width: none; }

/* ââ Components ââ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--bg-3);
  color: var(--fg-1);
  border: 1px solid var(--br-1);
  white-space: nowrap;
  line-height: 1.2;
}
.chip.solid-p1 { background: var(--p1); color: #1a0606; border-color: var(--p1); font-weight: 600; }
.chip.solid-p2 { background: var(--p2); color: #1a0e02; border-color: var(--p2); font-weight: 600; }
.chip.solid-p3 { background: var(--p3); color: #021022; border-color: var(--p3); font-weight: 600; }
.chip.solid-p4 { background: var(--p4); color: #0a0d12; border-color: var(--p4); font-weight: 600; }
.chip.solid-warn { background: var(--warn); color: #1a1503; border-color: var(--warn); font-weight: 600; }
.chip.solid-air { background: var(--air); color: #150620; border-color: var(--air); font-weight: 600; }
.chip.ghost-p1 { background: var(--p1-soft); color: var(--p1); border-color: var(--p1-line); }
.chip.ghost-p2 { background: var(--p2-soft); color: var(--p2); border-color: var(--p2-line); }
.chip.ghost-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(240,212,82,0.4); }
.chip.ghost { background: transparent; color: var(--fg-2); }
.chip.dot { padding-left: 5px; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-2);
  background: var(--bg-2);
  border: 1px solid var(--br-2);
  color: var(--fg-1);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 80ms ease, border-color 80ms ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); color: var(--fg-0); border-color: var(--br-3); }
.btn:active { background: var(--bg-4); }
.btn.primary { background: var(--fg-0); color: var(--bg-0); border-color: var(--fg-0); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.danger { background: var(--p1); color: #0e0202; border-color: var(--p1); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover { color: var(--fg-0); background: var(--bg-2); }
.btn.sm { padding: 3px 8px; font-size: 11.5px; }
.btn.icon { padding: 5px; width: 28px; justify-content: center; }
.btn.icon.sm { width: 24px; height: 24px; padding: 0; }

.kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-3);
  border: 1px solid var(--br-2);
  border-bottom-width: 2px;
  color: var(--fg-1);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.2;
}

/* surface */
.surface {
  background: var(--bg-1);
  border: 1px solid var(--br-1);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
}
.surface-2 { background: var(--bg-2); border: 1px solid var(--br-2); border-radius: var(--r-2); }

/* divider */
.div-h { height: 1px; background: var(--br-1); }
.div-v { width: 1px; background: var(--br-1); align-self: stretch; }

/* status dot */
.sdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.sdot.live { background: var(--p1); box-shadow: 0 0 0 2px rgba(255,85,71,0.18); animation: livepulse 1.6s ease-in-out infinite; }
@keyframes livepulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255,85,71,0.18); }
  50% { box-shadow: 0 0 0 5px rgba(255,85,71,0.06); }
}

/* link-ish */
.link {
  color: var(--fg-1);
  text-decoration: underline;
  text-decoration-color: var(--br-3);
  text-underline-offset: 2px;
  cursor: pointer;
}
.link:hover { color: var(--fg-0); text-decoration-color: var(--fg-2); }

/* Leaflet overrides */
.leaflet-container { background: var(--bg-0); font-family: var(--font-ui); }
.leaflet-control-attribution {
  background: rgba(10, 12, 16, 0.7) !important;
  color: var(--fg-3) !important;
  font-family: var(--font-mono) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}
.leaflet-control-attribution a { color: var(--fg-2) !important; }
.leaflet-control-zoom { display: none !important; }

/* custom marker (DivIcon) */
.mk {
  position: relative;
  border-radius: 50%;
  border: 1.5px solid var(--bg-0);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1), 0 2px 6px rgba(0,0,0,0.55);
  transform: translate(-50%, -50%);
}
.mk.p1 { background: var(--p1); }
.mk.p2 { background: var(--p2); }
.mk.p3 { background: var(--p3); }
.mk.p4 { background: var(--p4); opacity: 0.7; }
.mk-halo {
  position: absolute;
  border-radius: 50%;
  border: 1.5px dashed currentColor;
  pointer-events: none;
  animation: halopulse 2s ease-out infinite;
}
@keyframes halopulse {
  0%   { transform: scale(0.85); opacity: 0.9; }
  100% { transform: scale(1.5);  opacity: 0;   }
}
.mk-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0.55;
  pointer-events: none;
}

/* cluster lasso — stroke only (no fill; avoids stacking on re-render) */
.cluster-lasso {
  fill: none;
  stroke: var(--warn);
  stroke-width: 1.4;
  stroke-dasharray: 5 5;
}

.map-toggle.on {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(240, 212, 82, 0.4);
}

.rail-top {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--br-1);
  flex-shrink: 0;
}

.rail-top .tabs {
  flex: 1;
  min-width: 0;
}

#toggle-rail {
  flex-shrink: 0;
  margin: 4px 8px 4px 0;
  font-size: 11px;
}

.show-rail-fab {
  position: absolute;
  top: 52px;
  right: 12px;
  z-index: 550;
}

/* Author display rules override the UA [hidden] default in Chromium. */
#right-rail[hidden],
#show-rail-fab[hidden],
#map-legend[hidden],
#alert-ribbon[hidden],
#inspector[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.main-grid.map-only #right-rail {
  display: none !important;
}

/* incident row hover */
.inc-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--br-1);
  cursor: pointer;
  position: relative;
  transition: background 80ms ease;
}
.inc-row:hover { background: var(--bg-2); }
.inc-row.active { background: var(--bg-3); }
.inc-row.flagged { background: var(--p1-soft); border-left: 2px solid var(--p1); padding-left: 12px; }
.inc-row.flagged:hover { background: rgba(255,85,71,0.18); }
.inc-row.pinned::before {
  content: "â";
  position: absolute;
  left: 4px;
  top: 12px;
  color: var(--p2);
  font-size: 9px;
}

/* tabs */
.tabs { display: flex; border-bottom: 1px solid var(--br-1); position: relative; }
.tab {
  flex: 1;
  padding: 12px 8px;
  background: transparent;
  border: 0;
  color: var(--fg-2);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  transition: color 80ms ease;
}
.tab:hover { color: var(--fg-1); }
.tab.on { color: var(--fg-0); }
.tab.on::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 8px; right: 8px;
  height: 2px;
  background: var(--p1);
}
.tab .count {
  display: inline-block;
  margin-left: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-3);
  font-weight: 400;
}
.tab.on .count { color: var(--fg-1); }

/* sparkline */
.spark { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 18px; }
.spark i { display: block; width: 3px; background: var(--fg-3); border-radius: 1px; }
.spark.warn i { background: var(--warn); }
.spark.danger i { background: var(--p1); }

/* alert ribbon row variants */
.alert-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  position: relative;
}
.alert-row.danger { background: linear-gradient(90deg, rgba(255,85,71,0.18), rgba(255,85,71,0.06) 60%, transparent); border-bottom: 1px solid var(--p1-line); }
.alert-row.warn { background: linear-gradient(90deg, rgba(240,212,82,0.14), rgba(240,212,82,0.04) 60%, transparent); border-bottom: 1px solid rgba(240,212,82,0.3); }
.alert-row.danger::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--p1);
}
.alert-row.warn::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--warn);
}

/* Annotation overlays for Cursor handoff */
.spec-pill {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--fg-0);
  color: var(--bg-0);
  padding: 3px 7px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.spec-pill::before {
  content: "";
  position: absolute;
  width: 0; height: 0;
}
.spec-line {
  position: absolute;
  background: var(--fg-0);
  pointer-events: none;
  z-index: 9998;
}
.spec-box {
  position: absolute;
  border: 1px dashed var(--fg-0);
  pointer-events: none;
  z-index: 9997;
}

/* App layout */
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 440px;
  min-height: 0;
}

.main-grid.map-only {
  grid-template-columns: 1fr;
}

.map-col {
  position: relative;
  min-width: 0;
  min-height: 0;
}

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

#right-rail {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--br-1);
  background: var(--bg-1);
  overflow: hidden;
}

#rail-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.section-hdr {
  padding: 8px 14px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--br-1);
  border-top: 1px solid var(--br-1);
  position: sticky;
  top: 0;
  z-index: 5;
}

.section-hdr.danger {
  background: var(--p1-soft);
}

.sort-btn.on {
  color: var(--fg-0) !important;
  background: var(--bg-3) !important;
  font-weight: 600;
}

.sdot.dim {
  opacity: 0.5;
  animation: none;
  box-shadow: none;
}

#hide-routine.on {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(240, 212, 82, 0.4);
}

.call-type-line {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.call-type-tip {
  flex-shrink: 0;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 1px solid var(--br-2);
  background: var(--bg-2);
  color: var(--fg-3);
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  font-family: ui-serif, Georgia, serif;
  line-height: 1;
  cursor: help;
  padding: 0;
  position: relative;
}

.call-type-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 0.35rem);
  width: min(16rem, calc(100vw - 2.5rem));
  padding: 0.45rem 0.55rem;
  background: var(--bg-2);
  border: 1px solid var(--br-2);
  border-radius: var(--r-2);
  font-size: 0.72rem;
  font-weight: 400;
  font-style: normal;
  font-family: var(--font-ui);
  color: var(--fg-0);
  line-height: 1.35;
  white-space: normal;
  box-shadow: var(--shadow-2);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 9000;
}

.call-type-tip:hover::after,
.call-type-tip:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

#filter-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 500;
  pointer-events: none;
}

#filter-bar > * {
  pointer-events: auto;
}

#zoom-controls {
  position: absolute;
  top: 60px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#inspector {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 600;
}

#map-legend {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 500;
  width: 220px;
  padding: 10px 12px;
}

#map-stats {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 16px;
}

@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 240px 1fr;
  }

  .main-grid.map-only {
    grid-template-rows: 1fr;
  }
}
