/* ============================================================
   DISPATCH // CENTRAL — CAD terminal console
   Cool near-black base, monospace-led, dense, minimal motion.
   ============================================================ */

/* @font-face — IBM Plex Mono / Sans (weights actually used: 400/500/600) */
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-mono@latest/latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-mono@latest/latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 600; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-mono@latest/latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-sans@latest/latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-sans@latest/latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-sans@latest/latin-600-normal.woff2") format("woff2"); }


:root {
  /* Cool near-black base */
  --bg:            #0a0c10;
  --bg-panel:      #0e1117;
  --bg-panel-2:    #11151d;
  --bg-row:        #0e1117;
  --bg-row-alt:    #0c0f15;
  --bg-hover:      #141a23;

  /* Hairlines */
  --line:          #1a212c;
  --line-2:        #232c39;
  --line-strong:   #2e3947;

  /* Text — cool grays */
  --fg:            #c7d0dc;
  --fg-strong:     #e7edf4;
  --fg-dim:        #7a8698;
  --fg-faint:      #55606f;

  /* One restrained interactive accent — cool cyan */
  --accent:        #57b6d4;
  --accent-dim:    #2b6076;
  --accent-tint:   rgba(87, 182, 212, 0.10);

  /* Semantic priority / status — chosen for meaning, AA-checked on dark */
  --p1:            #f0575c;   /* critical */
  --p1-tint:       rgba(240, 87, 92, 0.065);
  --p2:            #e0a53a;   /* urgent */
  --p2-tint:       rgba(224, 165, 58, 0.05);
  --p3:            #5f93b3;   /* routine */

  --st-pending:    #e0a53a;
  --st-dispatched: #57b6d4;
  --st-onscene:    #62c08a;
  --st-cleared:    #6d7889;

  --u-available:   #62c08a;
  --u-dispatched:  #e0a53a;
  --u-onscene:     #57b6d4;
  --u-oos:         #7a5a5c;

  --highlight:     rgba(87, 182, 212, 0.16);

  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", "Menlo", monospace;
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;

  --row-h: 34px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-variant-ligatures: none;
}

/* ---- Scrollbar ---- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 2px solid var(--bg);
  border-radius: 0;
}
*::-webkit-scrollbar-thumb:hover { background: #3a4757; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  display: flex;
  align-items: stretch;
  gap: 28px;
  padding: 0 18px;
  height: 52px;
  background: linear-gradient(180deg, #10141b 0%, #0c0f15 100%);
  border-bottom: 1px solid var(--line-2);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 28px;
  border-right: 1px solid var(--line);
}
.brand-mark {
  width: 9px; height: 9px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(87,182,212,0.5);
}
.brand-name {
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg-strong);
  font-size: 14px;
}
.brand-sep { color: var(--accent); margin: 0 2px; }
.brand-tag {
  font-size: 9.5px;
  letter-spacing: 0.22em;
  color: var(--fg-faint);
  border: 1px solid var(--line-2);
  padding: 2px 6px;
  align-self: center;
}

.readouts {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex: 1;
}
.readout {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 0 22px;
  border-right: 1px solid var(--line);
  min-width: 118px;
}
.readout:first-child { padding-left: 0; }
.readout-label {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--fg-faint);
}
.readout-val {
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
}
.readout[data-key="active"] .readout-val { color: #f0dca0; }
.readout[data-key="available"] .readout-val { color: #a9dcc0; }
.readout-clock { margin-left: auto; border-right: none; }
.readout-clock-val { font-size: 16px; color: var(--fg-dim); letter-spacing: 0.04em; }

/* count tick */
.readout-val.tick { animation: tick 380ms ease-out; }
@keyframes tick {
  0%   { color: var(--accent); transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}
.link-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--u-available);
}
.link-status.link-down { color: var(--p1); }
.link-dot {
  width: 7px; height: 7px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
  animation: linkpulse 2.4s ease-in-out infinite;
}
@keyframes linkpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.btn-report {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--fg-strong);
  background: #161d27;
  border: 1px solid var(--line-strong);
  border-top-color: #37485a;
  padding: 8px 15px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.btn-report:hover { background: #1c2733; border-color: var(--accent-dim); color: #fff; }
.btn-report:active { background: #131922; transform: translateY(1px); }
.btn-report:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   BOARD LAYOUT
   ============================================================ */
.board {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 63fr) minmax(320px, 37fr);
  gap: 1px;
  background: var(--line);
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 11px 16px 10px;
  border-bottom: 1px solid var(--line-2);
  background: #0c0f15;
  flex: 0 0 auto;
}
.panel-head h1, .panel-head h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg-strong);
  text-transform: uppercase;
}
.panel-meta {
  font-size: 10.5px;
  color: var(--fg-faint);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   INCIDENT QUEUE — dense table
   ============================================================ */
.qtable-head,
.incident-row {
  display: grid;
  grid-template-columns: 46px 92px 74px minmax(120px, 1.1fr) minmax(140px, 1.5fr) 104px 62px;
  align-items: center;
  gap: 0;
}

.qtable-head {
  padding: 0 16px;
  height: 26px;
  border-bottom: 1px solid var(--line-2);
  background: #0a0d12;
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--fg-faint);
  flex: 0 0 auto;
}
.qtable-head span { padding-right: 10px; }
.col-time { text-align: right; padding-right: 16px !important; }
.col-unit { text-align: right; padding-right: 0 !important; }
.qtable-head .col-unit { padding-right: 2px !important; }

.qtable-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.incident-row {
  padding: 0 16px;
  min-height: var(--row-h);
  border-bottom: 1px solid var(--line);
  position: relative;
  color: var(--fg);
  transition: background 140ms;
}
.incident-row:hover { background: var(--bg-hover); }
.incident-row > span { padding-right: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* row tinting is the SECONDARY priority cue */
.incident-row.priority-1 { background: var(--p1-tint); }
.incident-row.priority-2 { background: var(--p2-tint); }
.incident-row.priority-1:hover { background: #17181f; }
.incident-row.priority-2:hover { background: #16181d; }

/* Priority tag — the PRIMARY, boxed, fixed-width cue */
.pri-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 19px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
  color: var(--p3);
  font-variant-numeric: tabular-nums;
}
.priority-1 .pri-tag { color: var(--p1); background: rgba(240,87,92,0.10); }
.priority-2 .pri-tag { color: var(--p2); background: rgba(224,165,58,0.09); }
.priority-3 .pri-tag { color: var(--p3); background: rgba(95,147,179,0.08); }

.col-call { color: var(--fg-strong); font-weight: 500; }
.col-time {
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.col-time.overdue { color: var(--p2); }
.col-type { color: var(--fg); }
.col-loc { color: var(--fg-dim); font-size: 12px; }

.col-status { }
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--st-pending);
}
.status-tag::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.status-pending    .status-tag { color: var(--st-pending); }
.status-dispatched .status-tag { color: var(--st-dispatched); }
.status-onscene    .status-tag { color: var(--st-onscene); }
.status-cleared    .status-tag { color: var(--st-cleared); }

.col-unit {
  text-align: right;
  font-weight: 500;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
}
.col-unit.unassigned { color: var(--fg-faint); font-weight: 400; }

/* --- Motion: insert highlight + field pulse --- */
.incident-row.row-enter { animation: rowEnter 1400ms ease-out; }
@keyframes rowEnter {
  0%   { background: var(--highlight); }
  100% { }
}
.pulse { animation: fieldPulse 900ms ease-out; }
@keyframes fieldPulse {
  0%   { background: rgba(87,182,212,0.28); }
  100% { background: transparent; }
}

/* Unresolved P1 — slow, subtle attention pulse on the tag */
.priority-1.status-pending .pri-tag,
.priority-1.status-dispatched .pri-tag {
  animation: p1pulse 2.6s ease-in-out infinite;
}
@keyframes p1pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(240,87,92,0.0); }
  50%     { box-shadow: 0 0 0 2px rgba(240,87,92,0.28); }
}

/* --- Empty state --- */
.queue-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  min-height: 240px;
  color: var(--fg-faint);
  text-align: center;
  padding: 40px;
}
.queue-empty .empty-mark {
  width: 34px; height: 34px;
  border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  color: var(--u-available);
}
.queue-empty .empty-mark::before {
  content: "";
  width: 12px; height: 6px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg) translate(0,-2px);
}
.queue-empty .empty-title {
  color: var(--fg-dim);
  font-size: 12px;
  letter-spacing: 0.16em;
}
.queue-empty .empty-sub { font-size: 11px; color: var(--fg-faint); }

/* ============================================================
   UNIT STATUS BOARD
   ============================================================ */
.unit-grid {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 1px;
  background: var(--line);
  align-content: start;
}

.unit {
  background: var(--bg-panel-2);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 74px;
  border-left: 2px solid transparent;
  transition: background 140ms;
}
.unit:hover { background: #161c26; }

.unit-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.unit-id {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-strong);
  letter-spacing: 0.03em;
}
.unit-kind { font-size: 9px; letter-spacing: 0.14em; color: var(--fg-faint); }

.unit-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
}
.unit-state::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.unit-assign {
  font-size: 10.5px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--line);
  padding-top: 5px;
  margin-top: auto;
}
.unit-assign .assign-call { color: var(--fg-dim); }

.unit.u-available   { border-left-color: var(--u-available); }
.unit.u-dispatched  { border-left-color: var(--u-dispatched); }
.unit.u-onscene     { border-left-color: var(--u-onscene); }
.unit.u-oos         { border-left-color: var(--u-oos); }
.unit.u-available   .unit-state { color: var(--u-available); }
.unit.u-dispatched  .unit-state { color: var(--u-dispatched); }
.unit.u-onscene     .unit-state { color: var(--u-onscene); }
.unit.u-oos         .unit-state { color: var(--u-oos); }
.unit.u-oos .unit-id { color: var(--fg-dim); }

.unit.state-change { animation: fieldPulse 900ms ease-out; }

/* ============================================================
   PROVENANCE
   ============================================================ */
.provenance {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--fg-faint);
  background: #0a0d12;
  border-top: 1px solid var(--line);
}
.prov-mark {
  width: 5px; height: 5px;
  background: var(--fg-faint);
  transform: rotate(45deg);
}

/* ============================================================
   DETAIL PANEL — inspector drawer for a clicked incident/unit
   ============================================================ */
.incident-row { cursor: pointer; }
.unit { cursor: pointer; }
.incident-row.is-inspected,
.unit.is-inspected {
  background: var(--accent-tint);
  box-shadow: inset 2px 0 0 var(--accent);
}

.detail-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 37vw);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--line-strong);
  box-shadow: -12px 0 24px rgba(0, 0, 0, 0.45);
  border-radius: 0;
  z-index: 5;
  animation: detailExit 100ms ease-in forwards;
}
.detail-panel[hidden] { display: none; }
.detail-panel.is-open { animation: detailEnter 140ms ease-out forwards; }

@keyframes detailEnter {
  from { transform: translateX(12px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes detailExit {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(12px); opacity: 0; }
}

.detail-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.detail-kicker {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  text-transform: uppercase;
}
.detail-title {
  flex: 1;
  margin: 0;
  font-size: 15px;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-close {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--fg-dim);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  cursor: pointer;
}
.detail-close:hover { color: var(--fg-strong); border-color: var(--fg-dim); }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 18px;
}

.detail-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.detail-pri, .detail-status, .unit-state-tag {
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

.detail-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0 0 16px;
  font-size: 11.5px;
}
.detail-fields dt {
  color: var(--fg-faint);
  letter-spacing: 0.04em;
}
.detail-fields dd {
  margin: 0;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.detail-timeline { border-top: 1px solid var(--line); padding-top: 12px; }
.tl-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  font-size: 11px;
}
.tl-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--fg-faint);
  flex: 0 0 auto;
}
.tl-label {
  flex: 1;
  color: var(--fg-dim);
  letter-spacing: 0.03em;
}
.tl-time {
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}
.tl-delta {
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

.detail-assignment { border-top: 1px solid var(--line); padding-top: 12px; }
.da-head {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.da-row { font-size: 11.5px; }
.da-call { color: var(--fg-strong); font-variant-numeric: tabular-nums; margin-right: 8px; }
.da-type { color: var(--fg-dim); }
.da-loc { color: var(--fg-faint); display: block; margin-top: 2px; }
.da-empty .da-none { color: var(--fg-faint); font-size: 11.5px; }

.detail-gone {
  padding-top: 8px;
  text-align: center;
}
.dg-mark {
  width: 8px; height: 8px;
  margin: 0 auto 10px;
  background: var(--fg-faint);
  transform: rotate(45deg);
}
.dg-title {
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.dg-sub {
  font-size: 10.5px;
  color: var(--fg-faint);
  margin-top: 4px;
}

/* ============================================================
   RESPONSIVE — stack below 900px
   ============================================================ */
@media (max-width: 900px) {
  .board { grid-template-columns: 1fr; grid-auto-rows: minmax(0, auto); }
  .panel-queue .qtable-body { max-height: 55vh; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 14px; gap: 14px; }
  .readouts { order: 3; flex-basis: 100%; }
  .readout:first-child { padding-left: 0; }
  .brand { border-right: none; padding-right: 0; }

  .detail-panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 60vh;
    border-left: none;
    border-top: 1px solid var(--line-strong);
    box-shadow: 0 -12px 24px rgba(0, 0, 0, 0.45);
  }
  @keyframes detailEnter {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
  @keyframes detailExit {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(12px); opacity: 0; }
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
