/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0a0a0f;
  --surface:      #13131a;
  --surface-2:    #1c1c26;
  --surface-3:    #252532;
  --border:       rgba(255,255,255,0.08);
  --border-focus: rgba(255,255,255,0.18);
  --text:         #f2f2f7;
  --text-2:       #aeaeb2;
  --text-3:       #636366;
  --accent:       #0a84ff;
  --accent-glow:  rgba(10,132,255,0.25);
  --red:          #ff453a;
  --orange:       #ff9f0a;
  --yellow:       #ffd60a;
  --green:        #30d158;
  --teal:         #40c8e0;
  --purple:       #bf5af2;
  --pink:         #ff375f;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    20px;
  --header-h:     64px;
  --filter-h:     52px;
  --sidebar-w:    380px;
  --shadow:       0 4px 24px rgba(0,0,0,0.5);
  --font:         -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-rows: var(--header-h) 44px var(--filter-h) 1fr;
  height: 100dvh;
}

.main-content {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

/* ── Header ──────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.badge-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #1a6ef7, #0a4fd6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(10,132,255,0.4);
}
.badge-icon svg { width: 20px; height: 20px; stroke: white; }

.header-titles h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.header-titles .subtitle {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
  letter-spacing: 0.2px;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(48, 209, 88, 0.12);
  border: 1px solid rgba(48, 209, 88, 0.25);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

.last-updated {
  font-size: 11px;
  color: var(--text-3);
}

/* ── Filter Bar ──────────────────────────────────────────────────── */
.dropdown-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  overflow: hidden;
}

.filter-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  padding: 8px 0;
}
.filter-scroll::-webkit-scrollbar { display: none; }

.filter-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.filter-chip:hover { border-color: var(--border-focus); color: var(--text); }
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.filter-chip .chip-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.filter-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.filter-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--border-focus); color: var(--text); }

.view-toggle {
  width: 32px; height: 32px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-2);
  transition: all 0.15s;
}
.view-toggle:hover { border-color: var(--border-focus); color: var(--text); }
.view-toggle svg { width: 14px; height: 14px; }

/* ── Sidebar / Call List ─────────────────────────────────────────── */
.call-list-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
  flex-shrink: 0;
}

.sort-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.sort-btn:hover { background: rgba(10,132,255,0.1); }
.sort-btn svg { width: 12px; height: 12px; }

.call-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.call-list::-webkit-scrollbar { width: 4px; }
.call-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* ── Call Cards ──────────────────────────────────────────────────── */
.call-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.call-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-color, var(--text-3));
  border-radius: 3px 0 0 3px;
}

.call-card:hover {
  border-color: var(--border-focus);
  background: var(--surface-3);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.call-card.selected {
  border-color: var(--card-color, var(--accent));
  background: var(--surface-3);
  box-shadow: 0 0 0 1px var(--card-color, var(--accent)), var(--shadow);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-type {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.type-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--card-color, var(--text-3));
  box-shadow: 0 0 6px var(--card-color, transparent);
}

.type-glyph {
  font-size: 14px;
  flex-shrink: 0;
  line-height: 1;
}

.type-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.status-arrived  { background: rgba(48,209,88,0.15);  color: var(--green);  }
.status-enroute  { background: rgba(255,159,10,0.15); color: var(--orange); }
.status-assigned { background: rgba(10,132,255,0.15); color: var(--accent); }
.status-default  { background: rgba(99,99,102,0.2);   color: var(--text-3); }

.card-location {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-3);
}
.card-meta span { display: flex; align-items: center; gap: 3px; }
.card-meta svg  { width: 10px; height: 10px; opacity: 0.7; }

.source-pill {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.source-henrico      { background: rgba(10,132,255,0.15);  color: #5ac8fa; }
.source-richmond     { background: rgba(255,69,58,0.15);   color: #ff6b6b; }
.source-chesterfield { background: rgba(48,209,88,0.15);   color: #30d158; }

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.no-results svg { width: 36px; height: 36px; margin-bottom: 12px; opacity: 0.4; }
.no-results p   { font-size: 13px; }

/* ── Map Panel ───────────────────────────────────────────────────── */
.map-panel {
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#map-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-overlay-info {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.map-notice {
  text-align: center;
  padding: 32px;
  max-width: 320px;
}
.map-notice svg   { color: var(--text-3); margin-bottom: 16px; }
.map-notice h3    { font-size: 17px; margin-bottom: 8px; }
.map-notice p     { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.map-notice code  { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── Detail Drawer ───────────────────────────────────────────────── */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.drawer-backdrop.visible { display: block; }

.detail-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface-2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 70dvh;
  overflow-y: auto;
}
.detail-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 36px; height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 10px auto 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
}

.drawer-type-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
}

.drawer-close {
  background: var(--surface-3);
  border: none;
  color: var(--text-3);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.drawer-close:hover { background: var(--surface); color: var(--text); }

.drawer-body {
  padding: 0 20px 32px;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-icon {
  width: 32px; height: 32px;
  background: var(--surface-3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.detail-icon svg { width: 15px; height: 15px; color: var(--text-3); }
.detail-info { flex: 1; }
.detail-label { font-size: 11px; color: var(--text-3); margin-bottom: 3px; letter-spacing: 0.3px; }
.detail-value { font-size: 14px; color: var(--text); font-weight: 500; }

/* ── Legend ──────────────────────────────────────────────────────── */
.legend {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 150;
}

.legend-toggle {
  width: 36px; height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  transition: all 0.15s;
}
.legend-toggle:hover { color: var(--text); border-color: var(--border-focus); }
.legend-toggle svg { width: 18px; height: 18px; }

.legend-panel {
  position: absolute;
  bottom: 44px;
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  min-width: 200px;
  box-shadow: var(--shadow);
}

.legend-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

.legend-items { display: flex; flex-direction: column; gap: 6px; }
.legend-item  { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.legend-dot   { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Loading ─────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  color: var(--text-3);
  gap: 12px;
}

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── View Modes ──────────────────────────────────────────────────── */
.main-content.view-map .call-list-panel  { display: none; }
.main-content.view-map .map-panel        { grid-column: 1 / -1; }
.main-content.view-list .map-panel       { display: none; }
.main-content.view-list .call-list-panel { border-right: none; }

/* ── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --header-h:  56px;
    --filter-h:  48px;
    --sidebar-w: 100%;
  }

  .header-titles .subtitle { display: none; }

  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: 45dvh 1fr;
  }

  .call-list-panel {
    border-right: none;
    border-top: 1px solid var(--border);
    order: 2;
  }

  .map-panel { order: 1; }

  .main-content.view-map  { grid-template-rows: 1fr; }
  .main-content.view-list { grid-template-rows: 1fr; }

  .legend { bottom: 16px; right: 12px; }

  .dropdown-bar {
    gap: 6px;
    padding: 0 8px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .dropdown-bar::-webkit-scrollbar { display: none; }
  .dropdown-bar .filter-select { flex-shrink: 0; font-size: 11px; padding: 4px 6px; }
}

/* ── Mapkit overrides ────────────────────────────────────────────── */
.mk-map-view { background: #1a1a2e !important; }
