/* Merlin CAD — dispatch console theme.
   Dark, dense, monospace accents. No external libraries. */

:root {
  --bg: #0b0e14;
  --bg2: #0e1220;
  --panel: #12161f;
  --panel2: #161c29;
  --border: #232a38;
  --border2: #2c3648;
  --text: #dbe2f1;
  --muted: #8b93a7;
  --accent: #4da3ff;
  --accent-dim: #1f6feb;
  --green: #3ddc84;
  --red: #ff5a5a;
  --p1: #ff4444;
  --p2: #ff9f1c;
  --p3: #ffd60a;
  --p4: #8b93a7;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
}

.mono { font-family: var(--mono); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16203a 0%, var(--bg) 60%);
}
.login-card {
  width: 380px;
  max-width: 92vw;
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 32px 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: .5px;
}
.login-card h1 .gem { color: var(--accent); }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 12px; text-transform: uppercase; letter-spacing: 2px; }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 12px; }
.login-card input { width: 100%; }
.login-error { color: var(--red); min-height: 20px; margin: 10px 0 4px; font-size: 12px; }
.login-hint {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}
.login-hint code { font-family: var(--mono); color: var(--text); background: var(--panel2); padding: 1px 6px; border-radius: 4px; }

/* ---------- Forms & buttons ---------- */
input, select, textarea {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--sans);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  background: #1c2333;
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: var(--sans);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #242e44; border-color: #3a4a66; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent-dim); border-color: #2f7fe0; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2b7de9; }
.btn-danger { background: #4a1d1d; border-color: #7a2b2b; color: #ffb3b3; }
.btn-danger:hover:not(:disabled) { background: #5c2424; }
.btn-ok { background: #123d28; border-color: #1f6b45; color: #9ff0c3; }
.btn-ok:hover:not(:disabled) { background: #174d33; }
.btn-sm { padding: 4px 9px; font-size: 11.5px; }
.btn-block { width: 100%; padding: 10px; font-size: 14px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.brand .gem { color: var(--accent); }
.brand .agency { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
.clockbox { text-align: center; }
#clock { font-family: var(--mono); font-size: 20px; font-weight: 700; letter-spacing: 2px; color: var(--green); }
#dateline { color: var(--muted); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox .uname { font-weight: 600; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .5px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Command line ---------- */
.cmdbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border2);
}
.cmd-label {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--green);
  white-space: nowrap;
}
.cmd-input {
  flex: 0 1 520px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
.cmd-input:focus { border-color: var(--accent); }
.cmd-input::placeholder { color: var(--muted); }
.cmd-out { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-out.cmd-ok { color: var(--green); }
.cmd-out.cmd-err { color: var(--red); }
.cmd-suggest {
  position: absolute;
  left: 10px;
  min-width: 430px;
  max-width: calc(100% - 20px);
  top: calc(100% + 4px);
  z-index: 70;
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .5);
  overflow: hidden;
  padding: 4px 0;
}
.cmd-sug-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.cmd-sug-row.sel { background: var(--accent-dim); }
.cmd-sug-kind {
  flex: 0 0 52px;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.cmd-sug-row.sel .cmd-sug-kind { color: var(--text); }
.cmd-sug-text { font-size: 13px; font-weight: 700; color: var(--text); }
.cmd-sug-hint { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.cmd-sug-row.sel .cmd-sug-hint { color: var(--text); }
.cmdbar { position: relative; }
.cmdbar.floating {
  position: fixed;
  z-index: 55;
  border: 1px solid var(--border2);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  background: var(--bg2);
}
.cmdbar.floating .cmd-input { flex: 1 1 auto; }
.cmd-placeholder { background: var(--bg2); }
.cmd-popout-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.cmd-popout-body .cmdbar { border: 1px solid var(--border2); border-radius: 8px; }
.cmd-popout-body .cmd-input { flex: 1 1 auto; }
.cmd-popout-hint { color: var(--muted); font-size: 12px; line-height: 1.6; padding: 0 4px; }

/* ---------- Layout ---------- */
.view { padding: 12px 16px; }
.workspace {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}
.workspace > .cpanel { flex: 1 1 320px; min-width: 260px; }
.cpanel { display: flex; flex-direction: column; position: relative; }
.cpanel .panel-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.cpanel .panel-body .scrollcol { flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto; }
.cpanel .panel-body #detail-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.cpanel.floating {
  position: fixed;
  z-index: 50;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  flex: none;
}
.cpanel.popped { opacity: .75; }
.popout-wrap { height: 100vh; padding: 10px; background: var(--bg); }
.popout-panel { height: 100%; width: 100%; }
.popout-panel .panel-head { cursor: default; }
.cpanel.floating .panel-head { cursor: move; }
.panel-tools { display: inline-flex; align-items: center; gap: 6px; }
.panel-count { color: var(--muted); font-weight: 600; letter-spacing: 0; }
.panel-btn {
  background: var(--panel);
  border: 1px solid var(--border2);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10.5px;
  cursor: pointer;
  letter-spacing: .5px;
}
.panel-btn:hover { color: var(--text); border-color: var(--accent); }
.panel-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--border2) 50%, var(--border2) 60%, transparent 60%, transparent 75%, var(--border2) 75%);
  z-index: 3;
}
.console-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.console-hint { color: var(--muted); font-size: 11.5px; }
.panels-menu-wrap { position: relative; }
.panels-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 70;
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 4px;
  min-width: 210px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
}
.panels-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  border-radius: 5px;
}
.panels-menu-item:hover { background: var(--panel); }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel2);
  position: sticky;
  top: 0;
  z-index: 2;
}
.scrollcol { max-height: calc(100vh - 190px); overflow-y: auto; }

/* ---------- Queue cards ---------- */
.qcard {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  cursor: pointer;
}
.qcard:hover { background: var(--panel2); }
.qcard.selected { background: #18202f; border-left-color: var(--accent); }
.qcard-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.qcard .inc-no { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.qcard .ctype { font-weight: 600; margin-bottom: 3px; }
.qcard .addr { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.qcard-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--muted); }
.qcard .elapsed { font-family: var(--mono); color: var(--p2); font-weight: 700; }
.empty-note { padding: 24px 16px; color: var(--muted); text-align: center; font-size: 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  font-family: var(--mono);
}
.pri-1 { background: var(--p1); color: #1a0000; }
.pri-2 { background: var(--p2); color: #221100; }
.pri-3 { background: var(--p3); color: #221a00; }
.pri-4 { background: #3a4152; color: #c6cede; }
.status-pending { background: #3d2c10; color: var(--p2); border: 1px solid #7a5a1e; }
.status-active { background: #10283d; color: var(--accent); border: 1px solid #1f5a8a; }
.status-closed { background: #232a38; color: var(--muted); border: 1px solid var(--border2); }
.status-cancelled { background: #3d1010; color: var(--red); border: 1px solid #7a2b2b; }
.role-badge { background: #1a2b1f; color: var(--green); border: 1px solid #2b5a3d; text-transform: uppercase; font-size: 10px; }
.disc { font-size: 10px; padding: 2px 7px; border-radius: 4px; font-weight: 700; letter-spacing: .5px; font-family: var(--mono); }
.disc-law { background: #10283d; color: #7cc0ff; border: 1px solid #1f5a8a; }
.disc-fire { background: #3d1010; color: #ff9a9a; border: 1px solid #7a2b2b; }
.disc-ems { background: #102f1e; color: #8fe6ae; border: 1px solid #2b5a3d; }

/* ---------- Incident detail ---------- */
.detail-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.detail-head .row1 { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.detail-head .inc-no { font-family: var(--mono); font-size: 17px; font-weight: 700; }
.detail-head .ctype { color: var(--muted); font-size: 13px; }
.fields-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 18px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.field label { display: block; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px; }
.field .val { font-size: 13px; }
.narr-box {
  margin: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  white-space: pre-wrap;
  font-size: 12.5px;
  min-height: 44px;
}
.section-title {
  padding: 10px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.timeline { list-style: none; margin: 0 16px 8px; padding: 0; max-height: 180px; overflow-y: auto; }
.timeline li { padding: 5px 0; border-bottom: 1px dotted var(--border); font-size: 12px; display: flex; gap: 10px; }
.timeline .ts { font-family: var(--mono); color: var(--muted); white-space: nowrap; font-size: 11px; padding-top: 1px; }
.dispatch-row {
  display: flex;
  gap: 8px;
  padding: 6px 16px 12px;
  align-items: center;
}
.dispatch-row select { flex: 1; }
.btn-row { display: flex; gap: 8px; padding: 0 16px 14px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  text-align: left;
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .callsign { font-family: var(--mono); font-weight: 700; }
.tbl-wrap { margin: 0 16px 14px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tbl-wrap .tbl th { border-top: none; }

/* ---------- Roster ---------- */
.roster-group { border-bottom: 1px solid var(--border); }
.roster-group:last-child { border-bottom: none; }
.roster-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--muted);
}
.roster-head .count { font-family: var(--mono); color: var(--text); }
.unit-row { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.unit-row:last-child { border-bottom: none; }
.unit-row.clickable { cursor: pointer; }
.unit-row.clickable:hover { background: var(--panel2); }
.unit-main { display: flex; align-items: center; gap: 8px; }
.unit-main .callsign { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.unit-sub { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.unit-sub .linked { color: var(--p2); font-family: var(--mono); }
.unit-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* status dot colors for group headers */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-available { background: var(--green); }
.dot-dispatched { background: var(--p2); }
.dot-enroute { background: var(--accent); }
.dot-onscene { background: var(--p1); }
.dot-out_of_service { background: #5a6376; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  width: 540px;
  max-width: 94vw;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--panel2);
}
.modal-x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.form-error { color: var(--red); font-size: 12px; min-height: 18px; margin-top: 8px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12.5px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease-out;
}
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Misc ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar h2 { margin: 0; font-size: 15px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.placeholder { padding: 60px 24px; text-align: center; color: var(--muted); }
.placeholder .big { font-size: 40px; margin-bottom: 12px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #2a3346; border-radius: 5px; }
