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

:root {
  --bg: #0a0a0a;
  --panel: #141414;
  --panel-2: #1c1c1c;
  --border: #333;
  --text: #f0f0f0;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --good: #4ade80;
  --danger: #f87171;
  --value: #22d3ee;
  --font: "Outfit", system-ui, sans-serif;
  --shadow: 3px 3px 0 #000;
  --max: 1200px;
  --gap: 12px;
}

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

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

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

#app {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 14px 16px;
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}

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

.brand-mark {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 8px 10px;
  border: 2px solid #000;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
}

.site-header .status-dot {
  flex-shrink: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.live { background: var(--good); box-shadow: 0 0 8px var(--good); }

.ghost-link {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
}

/* Panels */
.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.panel-label {
  margin: 0 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.panel-title {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.panel-hint {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
}

.table-scroll-history {
  max-height: min(320px, 40vh);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head .panel-title { margin: 0; }

.panel-grow { display: flex; flex-direction: column; min-height: 280px; }

.ghost-link {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
}

/* Layout — two equal panels */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  align-items: start;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }

  .panel-grow { min-height: 480px; }
  .incidents-panel,
  .recordings-panel { grid-column: 1 / -1; }
}

/* Audio */
.audio-panel { display: flex; flex-direction: column; gap: 12px; }

.audio-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.audio-status {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.audio-status.live { color: var(--good); }

.vol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.vol-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-height: 28px;
}

.speaker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.speaker-select {
  flex: 1;
  min-width: 140px;
  font-family: inherit;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  min-height: 44px;
}

.speaker-hint {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.speaker-hint.warn { color: var(--danger); }

@media (max-width: 599px) {
  .speaker-row { flex-direction: column; align-items: stretch; }
  .speaker-row .btn-sm { width: 100%; }
  .speaker-select { width: 100%; min-width: 0; }
}

/* Tables */
.now-playing h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 800;
  word-break: break-word;
}

.np-talkgroup {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--value);
}

.np-source {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.np-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 0;
}

.np-meta div { min-width: 0; }

.np-meta dt {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0;
}

.np-meta dd {
  margin: 2px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 10px 14px;
  border: 2px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: #000;
  color: #fff;
  box-shadow: 2px 2px 0 #000;
}

.btn-primary.active {
  background: var(--bg);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-sm {
  min-height: 40px;
  min-width: 44px;
  padding: 8px 12px;
}

.whitelist-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.whitelist-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1 1 180px;
}

.btn-toggle {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-toggle.active {
  background: rgba(46, 125, 70, 0.18);
  border-color: rgba(46, 125, 70, 0.55);
  color: #8fe8a8;
}

.btn-toggle:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.tune-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tune-label {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

/* Channels */
.channels-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ch-card {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}

.ch-card.selected { border-color: var(--accent); }

.ch-play {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 2px solid var(--border);
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
}

.ch-body { flex: 1; min-width: 0; }

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

.ch-name {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.3;
  word-break: break-word;
}

.ch-num {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 7px;
}

.ch-freq {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.ch-tg {
  font-size: 0.8rem;
  font-weight: 700;
}

.ch-tag {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-word;
}

/* Tables */
.input {
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.85rem;
  min-width: 120px;
  flex: 1;
  max-width: 200px;
}

.table-scroll {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  background: var(--bg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  word-break: break-word;
}

.data-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.empty-msg {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Recordings */
.recordings-panel { display: flex; flex-direction: column; gap: 10px; }

.panel-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hist-audio {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.hist-audio-yes {
  color: #8fe8a8;
  background: rgba(46, 125, 70, 0.22);
}

.hist-audio-no {
  color: #ffb4a8;
  background: rgba(180, 60, 40, 0.18);
}

.hist-audio-grant {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
}

.hist-row-emergency td {
  background: rgba(180, 40, 40, 0.08) !important;
}

.hist-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.hist-flag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.hist-emergency {
  color: #ffb4a8;
  background: rgba(180, 40, 40, 0.28);
}

.hist-enc-clear {
  color: #8fe8a8;
  background: rgba(46, 125, 70, 0.18);
}

.hist-enc-encrypted {
  color: #ffc896;
  background: rgba(160, 90, 20, 0.22);
}

.hist-prio {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
}

.data-table td:nth-child(3),
.data-table td:nth-child(4) {
  word-break: break-word;
  max-width: 11rem;
}

.rec-filter {
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 4px;
}

.rec-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.rec-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.rec-day {
  border: 1px solid var(--border);
  background: var(--bg);
}

.rec-day-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  background: var(--panel-2);
  user-select: none;
}

.rec-day-summary::-webkit-details-marker { display: none; }

.rec-day-summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 0.75rem;
  margin-right: 2px;
}

.rec-day[open] > .rec-day-summary::before { content: "▾"; }

.rec-day-label {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.rec-day-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 999px;
}

.rec-day-body {
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.rec-day-body .rec-agency {
  border: none;
  border-bottom: 1px solid var(--border);
}

.rec-day-body .rec-agency:last-child {
  border-bottom: none;
}

.rec-agency {
  border: 1px solid var(--border);
  background: var(--bg);
}

.rec-agency-title {
  margin: 0;
  padding: 8px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.rec-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.rec-item:last-child { border-bottom: none; }

.rec-meta { min-width: 0; }

.rec-time {
  font-size: 0.72rem;
  color: var(--muted);
}

.rec-tag {
  font-size: 0.82rem;
  word-break: break-word;
}

.rec-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.rec-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.rec-item-emergency {
  background: rgba(180, 40, 40, 0.06);
}

.rec-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.rec-play,
.rec-download {
  font-family: inherit;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  text-decoration: none;
}

.rec-play {
  background: var(--accent);
  color: #fff;
  border: none;
}

.rec-download {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.rec-play:hover { filter: brightness(1.08); }

.rec-download:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.rec-player {
  width: 100%;
  margin-top: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-badge {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: 2px solid #000;
  background: var(--danger);
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.alert-badge[hidden] { display: none !important; }

.incidents-panel { display: flex; flex-direction: column; gap: 10px; }

.inc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.inc-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 2px solid var(--border);
  cursor: pointer;
}

.inc-item:hover { border-color: var(--accent); }
.inc-item-priority-1 { border-color: var(--danger); }
.inc-item-priority-2 { border-color: #fbbf24; }

.inc-summary {
  font-weight: 700;
  font-size: 0.95rem;
}

.inc-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.inc-meta-right {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.inc-segs {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-weight: 700;
  color: var(--value);
}

.inc-detail {
  border-top: 2px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inc-detail-title { margin: 0; font-size: 1rem; }
.inc-detail-summary { margin: 0; font-weight: 600; }

.inc-detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  margin: 0;
}

.inc-detail-meta div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 4px 0;
  font-size: 0.85rem;
}

.inc-detail-meta dt { color: var(--muted); margin: 0; }
.inc-detail-meta dd { margin: 0; font-weight: 600; color: var(--value); }

.inc-segments { display: flex; flex-direction: column; gap: 6px; }

.inc-seg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.inc-transcript-wrap {
  border: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--panel-2);
}

.inc-transcript {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 8px 0 0;
  max-height: 220px;
  overflow: auto;
}

.toast-stack {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 24px));
}

.toast {
  background: var(--panel);
  border: 2px solid var(--danger);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

@media (max-width: 480px) {
  .brand h1 { font-size: 0.95rem; }
  .np-meta { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-head .input { max-width: none; }
}
