@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #0b0d10;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, #1a2433 0%, transparent 55%),
    radial-gradient(900px 500px at 90% 0%, #1c1810 0%, transparent 50%),
    #0b0d10;
  --panel: #14181f;
  --panel-2: #1b212b;
  --border: #2a3340;
  --text: #eef2f7;
  --muted: #93a0b4;
  --accent: #3b82f6;
  --accent-2: #38bdf8;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --fire: #fb7185;
  --ems: #34d399;
  --police: #60a5fa;
  --font: "Outfit", system-ui, sans-serif;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-glow);
  line-height: 1.45;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  min-width: 48px;
  height: 48px;
  padding: 0 10px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #1d4ed8);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }

.top-actions { display: flex; align-items: center; gap: 10px; }

.btn, select, input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
.btn {
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover, select:hover { border-color: #3d4b5f; }
.btn.ghost { background: transparent; }
.pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}
.pill.ok { color: var(--good); border-color: rgba(74, 222, 128, 0.35); }
.pill.bad { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }

.map-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
}
#map {
  height: min(340px, 42vh);
  width: 100%;
  background: #15202b;
}
.map-note {
  margin: 0;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
}
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; }
.popup-title { font-weight: 700; margin: 0 0 4px; }
.popup-sub { margin: 0; color: #445; font-size: 0.85rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(20, 24, 31, 0.75);
  backdrop-filter: blur(8px);
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
#filter-q { min-width: min(100%, 280px); flex: 1; }
.status-line { margin: 0; color: var(--muted); font-size: 0.85rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  align-items: start; /* don't stretch short cards to match tall neighbors */
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%),
    var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  animation: rise 280ms ease both;
  min-width: 0; /* allow clamps/ellipsis inside grid */
  height: auto;
  align-self: start;
}
.card:hover {
  transform: translateY(-2px);
  border-color: #405066;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}
.card:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
.card.priority-1 { border-color: rgba(248, 113, 113, 0.55); }
.card.priority-2 { border-color: rgba(251, 191, 36, 0.45); }
.card.closed { opacity: 0.78; }

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}
.badge.type-fire, .badge.type-structure_fire { color: #ffe4e6; background: rgba(251, 113, 133, 0.18); border-color: rgba(251, 113, 133, 0.4); }
.badge.type-ems { color: #d1fae5; background: rgba(52, 211, 153, 0.16); border-color: rgba(52, 211, 153, 0.4); }
.badge.type-mvc, .badge.type-alarm, .badge.type-pursuit, .badge.type-emergency { color: #fef3c7; background: rgba(251, 191, 36, 0.14); border-color: rgba(251, 191, 36, 0.4); }
.badge.type-police, .badge.family-police { color: #dbeafe; background: rgba(96, 165, 250, 0.14); border-color: rgba(96, 165, 250, 0.4); }
.badge.open { color: var(--good); }
.badge.closed { color: var(--muted); }
.badge.pinned {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.45);
}
.card.pinned {
  border-color: rgba(251, 191, 36, 0.45);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.15), var(--shadow);
}

.card-time {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-close-inc {
  appearance: none;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
  border-radius: 999px;
  padding: 2px 10px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-close-inc:hover { background: rgba(248, 113, 113, 0.22); }
.btn-close-inc:disabled { opacity: 0.5; cursor: wait; }

.card-address {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: normal;
}
.card-address.missing { color: var(--muted); font-weight: 600; font-size: 1.05rem; }
.card-plain {
  margin: 0;
  font-size: 0.92rem;
  color: #e7eef8;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
}
.card-plain.missing {
  color: var(--muted);
  font-style: italic;
}
.card-plain.llm {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.28);
}
.beat-list {
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.beat-list.empty-beats {
  padding: 6px 10px;
  background: transparent;
  border-style: dashed;
  opacity: 0.85;
}
.beat-label {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.beat {
  font-size: 0.84rem;
  color: #d5deea;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: normal;
}
.beat > span:nth-child(2) {
  display: inline;
}
.beat-n {
  color: var(--accent-2);
  font-weight: 700;
  margin-right: 4px;
}
.briefing-block {
  margin: 0 0 10px;
  white-space: pre-wrap;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.28);
  max-height: 220px;
  overflow: auto;
}
.detail-beats { margin-top: 8px; }

.player-bar {
  position: sticky;
  bottom: 10px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(16, 20, 28, 0.94);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.player-bar[hidden] { display: none !important; }
.player-meta {
  display: grid;
  gap: 2px;
  min-width: min(100%, 180px);
  flex: 1;
}
.player-meta strong { font-size: 0.9rem; }
.player-sub { color: var(--muted); font-size: 0.78rem; }
#board-player {
  flex: 2;
  min-width: min(100%, 240px);
  height: 36px;
}
.play-btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: #dbeafe;
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(96, 165, 250, 0.45);
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.play-btn:hover { background: rgba(59, 130, 246, 0.3); }
.play-btn.playing {
  color: #052e16;
  background: rgba(74, 222, 128, 0.85);
  border-color: rgba(74, 222, 128, 0.9);
}
.card-audio {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.beat {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
}
.tx-head { align-items: center; }
.assumed {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 999px;
  padding: 1px 7px;
  vertical-align: middle;
}

.card-meta {
  display: grid;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--muted);
}
.card-meta strong { color: var(--text); font-weight: 600; }

.card-narrative {
  margin: 0;
  font-size: 0.9rem;
  color: #d5dde8;
  overflow-wrap: anywhere;
  white-space: normal;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: #c9d4e4;
}
.case-file { display: grid; gap: 6px; }
.chip.case-chip em {
  font-style: normal;
  font-weight: 700;
  color: var(--accent-2);
  margin-right: 2px;
}
.detail-field.empty dd {
  color: var(--muted);
  font-weight: 500;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.78rem;
}

.empty {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.detail-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}
.detail-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.detail-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.detail-head h2 { margin: 0; font-size: 1.25rem; }
.detail-body {
  padding: 16px 18px 20px;
  overflow: auto;
  display: grid;
  gap: 14px;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.detail-field {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.detail-field dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.detail-field dd { margin: 0; font-weight: 600; }

.tx-list { display: grid; gap: 10px; }
.tx {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}
.tx-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.tx-text { margin: 0; white-space: pre-wrap; font-size: 0.92rem; }
.tx-extract { margin: 8px 0 0; color: var(--muted); font-size: 0.8rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  #app { padding: 10px; }
  .brand h1 { font-size: 1.1rem; }
  .card-address { font-size: 1.08rem; }
}
