:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e6e8eb;
  --text-dim: #9aa1ac;
  --p1: #e5484d;
  --p2: #f5a623;
  --p3: #e8d44d;
  --p4: #6b7280;
  --accent: #4da3ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.05em;
}

nav { display: flex; gap: 0.5rem; }

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}
.tab-btn.active { color: var(--text); border-color: var(--accent); }

.priority-select,
.region-select,
.discipline-toggle {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  width: 11rem;
  max-width: 40vw;
}
.priority-select { margin-left: auto; }

.discipline-toggle {
  text-align: left;
  cursor: pointer;
  font: inherit;
  position: relative;
}
.discipline-toggle::after {
  content: "▾";
  position: absolute;
  right: 0.6rem;
  color: var(--text-dim);
}

.discipline-filter { position: relative; }

.discipline-panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  min-width: 14rem;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: 0.3rem;
  z-index: 20;
}
.discipline-panel.hidden { display: none; }

.discipline-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.discipline-option:hover { background: #20242e; }
.discipline-option-all {
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.2rem;
  padding-bottom: 0.5rem;
}

.conn-status {
  margin-left: 0;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.conn-connecting { background: #3a3520; color: var(--p2); }
.conn-open { background: #1f3a2a; color: #4ade80; }
.conn-closed { background: #3a1f1f; color: var(--p1); }

main { padding: 1rem; max-width: 900px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.filter-bar input, .filter-bar select, .filter-bar button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}

.message-list { display: flex; flex-direction: column; gap: 0.5rem; }

.message {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--p4);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
.message.p1 { border-left-color: var(--p1); }
.message.p2 { border-left-color: var(--p2); }
.message.p3 { border-left-color: var(--p3); }
.message.p4 { border-left-color: var(--p4); }

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

.priority-badge {
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  color: #17181c;
}
.priority-badge.p1 { background: var(--p1); color: #fff; }
.priority-badge.p2 { background: var(--p2); }
.priority-badge.p3 { background: var(--p3); }
.priority-badge.p4 { background: transparent; color: var(--text-dim); padding: 0; }

.discipline-badges { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.discipline-badge {
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
}
.disc-ambulance       { background: #16532620; color: #4ade80; }
.disc-brandweer       { background: #7c2d1220; color: #fb923c; }
.disc-politie         { background: #1e3a8a20; color: #60a5fa; }
.disc-knrm            { background: #164e6320; color: #38bdf8; }
.disc-reddingsbrigade { background: #164e6320; color: #22d3ee; }
.disc-lifeliner       { background: #581c8720; color: #c084fc; }
.disc-gmk             { background: #33415520; color: #94a3b8; }
.disc-gemeente        { background: #33415520; color: #94a3b8; }
.disc-overig          { background: #33415520; color: #94a3b8; }
.disc-onbekend        { background: #33415520; color: var(--text-dim); }

.region-text { color: var(--text-dim); }

.message-body { font-size: 0.95rem; line-height: 1.4; word-break: break-word; }

.capcode-chips { margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip {
  font-size: 0.7rem;
  background: #20242e;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  color: var(--text-dim);
}

.load-more {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.map { height: 70vh; border-radius: 6px; overflow: hidden; }

@media (max-width: 600px) {
  header { flex-wrap: wrap; }
  .conn-status { order: 3; margin-left: 0; }
}
