/* PULSE design system — dark operations-center theme */
:root {
  --bg: #0a0e15;
  --bg2: #0d131d;
  --panel: #111a28;
  --panel2: #0d1420;
  --line: #1d2a3e;
  --line2: #27374f;
  --text: #d9e4f1;
  --muted: #8398b3;
  /* was #5a6d86 — only 3.30:1 on --panel, which fails WCAG AA (4.5:1) for the
     emails, phone numbers, credential IDs and timestamps that use it. Same hue
     and saturation, lifted to 4.51:1. */
  --faint: #6f839e;
  --acc: #38b6ff;
  --acc-dim: #1c5f86;
  --teal: #2adfb8;
  --ok: #3ddc84;
  --warn: #ffb02e;
  --bad: #ff5d5d;
  --purple: #b18cff;
  --radius: 10px;
  --sidebar-w: 236px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: Consolas, "Cascadia Mono", Menlo, monospace;
  /* renders native widgets — dropdown lists, date/time pickers, scrollbars —
     against the dark shell instead of the light default */
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font);
}
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 600; margin: 0 0 .5em; }
h1 { font-size: 21px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #223146; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Shell layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 12px; border-bottom: 1px solid var(--line);
}
.brand img { width: 30px; height: 30px; }
.brand .t { font-size: 17px; font-weight: 700; letter-spacing: 2px; }
.brand .s { font-size: 10.5px; color: var(--muted); display: block; letter-spacing: .4px; }
.nav { padding: 8px 0 20px; flex: 1; }
.nav .grp {
  padding: 12px 16px 4px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--faint);
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px; color: var(--text); font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: #131e30; text-decoration: none; }
.nav a.active { background: #14233a; border-left-color: var(--acc); color: #fff; }
.nav a .ico { width: 18px; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 52px; padding: 0 18px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .org { font-weight: 600; font-size: 14px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 12.5px; text-align: right; line-height: 1.35; }
.topbar .who b { color: var(--text); display: block; font-size: 13px; margin-bottom: 3px; }
#menu-btn { display: none; }

.content { padding: 20px 22px 48px; max-width: 1560px; width: 100%; margin: 0 auto; }

/* Page header */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; width: 100%; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards & stat tiles ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.card > h2, .card > h3 { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 12px; }
.cards { display: grid; gap: 14px; margin-bottom: 16px; }
/* grid items default to min-width:auto, so a wide table inside a card widens the
   whole track and pushes the page into horizontal scroll — opt out. */
.cards > * { min-width: 0; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.grid5 { grid-template-columns: repeat(5, 1fr); }
.grid6 { grid-template-columns: repeat(6, 1fr); }
.cards .card { margin-bottom: 0; }

.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
/* The three parts always stack, whether a template uses <div> or <span>. */
.stat .lbl, .stat .val, .stat .sub { display: block; }
.stat .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
/* line-height must clear the 26px glyph box (~1.33em) or the digits collide with .sub */
.stat .val { font-size: 26px; font-weight: 700; line-height: 1.35; margin: 2px 0 3px; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.ok .val { color: var(--ok); }
.stat.warn .val { color: var(--warn); }
.stat.bad .val { color: var(--bad); }
.stat.info .val { color: var(--acc); }
a.stat { display: block; }
a.stat:hover { text-decoration: none; border-color: var(--line2); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 8px 10px; color: var(--muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px;
  border-bottom: 1px solid var(--line2); white-space: nowrap;
}
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:hover { background: #14203255; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.clickable { cursor: pointer; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px;
  background: #223146; color: var(--text); white-space: nowrap;
}
.badge.ok     { background: #123626; color: var(--ok); }
.badge.warn   { background: #3a2c10; color: var(--warn); }
.badge.bad    { background: #3d1820; color: var(--bad); }
.badge.info   { background: #10304a; color: var(--acc); }
.badge.purple { background: #2b2145; color: var(--purple); }
.badge.neutral{ background: #1d2a3e; color: var(--muted); }
/* MCI triage categories */
.badge.t-red    { background: #c22f2f; color: #fff; }
.badge.t-yellow { background: #d8a012; color: #17130a; }
.badge.t-green  { background: #1f9e57; color: #fff; }
.badge.t-black  { background: #0c0f14; color: #aab6c6; border: 1px solid #39465c; }
.badge.t-purple { background: #6d4bb5; color: #fff; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); } .dot.info { background: var(--acc); }
.dot.neutral { background: var(--faint); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #1b2a40; color: var(--text); border: 1px solid var(--line2);
  padding: 7px 14px; border-radius: 8px; font: 600 13px var(--font);
  cursor: pointer; text-decoration: none !important;
}
.btn:hover { background: #22344e; }
.btn.primary { background: var(--acc-dim); border-color: #2a7cab; color: #e9f6ff; }
.btn.primary:hover { background: #1f6f9e; }
.btn.danger { background: #4a1d24; border-color: #7c2c37; color: #ffb9b9; }
.btn.danger:hover { background: #5d232c; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Forms ---------- */
/* Controls outside .field and without .inp (toolbars, table cells) were falling
   back to the light UA theme — white boxes with black text on the dark shell.
   Style by element; deliberately no width here so toolbar layouts are unchanged.
   The .field / .inp rules below are more specific and still win where they apply. */
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="color"]),
select, textarea {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line2); border-radius: 8px;
  padding: 7px 10px; font: 13.5px var(--font);
  /* a <select> sizes to its widest option; without this the service-code and
     incident pickers push past a phone viewport */
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acc); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea,
input.inp, select.inp, textarea.inp {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line2); border-radius: 8px;
  padding: 8px 10px; font: 13.5px var(--font);
}
.field input:focus, .field select:focus, .field textarea:focus,
.inp:focus { outline: none; border-color: var(--acc); }
.field .hint { font-size: 11.5px; color: var(--faint); margin-top: 3px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form-row > * { min-width: 0; }
/* UA default is min-width:min-content, which stops a fieldset shrinking below its
   widest child and forces the page to scroll sideways (ICS form editor). */
fieldset { min-width: 0; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--acc); }

/* ---------- Toolbar / search ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar input[type="search"], .toolbar input[type="text"] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line2);
  border-radius: 8px; padding: 7px 12px; font: 13px var(--font); min-width: 220px;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line2); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a, .tabs button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 14px; font: 600 13px var(--font);
  border-bottom: 2px solid transparent; text-decoration: none !important;
}
.tabs a.active, .tabs button.active { color: #fff; border-bottom-color: var(--acc); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- Alerts / banners ---------- */
.alert { border-radius: var(--radius); padding: 11px 14px; margin-bottom: 14px; border: 1px solid; font-size: 13.5px; }
.alert.ok    { background: #0f2c1e; border-color: #1d5c3c; color: #b9f2d4; }
.alert.warn  { background: #33270e; border-color: #6b5416; color: #ffe1a3; }
.alert.error, .alert.bad { background: #391a20; border-color: #742f3a; color: #ffc9c9; }
.alert.info  { background: #0e2940; border-color: #1e507f; color: #bfe3ff; }

/* Incident banner */
.inc-banner {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(90deg, #3d1820, #2a1420);
  border: 1px solid #7c2c37; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px;
}
.inc-banner .pulse-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--bad);
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Progress ---------- */
.progress { background: #17233a; border-radius: 999px; height: 10px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--acc); border-radius: 999px; }
.progress > i.ok { background: var(--ok); }
.progress > i.warn { background: var(--warn); }
.progress > i.bad { background: var(--bad); }

/* ---------- KV list ---------- */
/* minmax(0, 1fr) + wrapping keeps long values (file paths, product strings)
   inside the card instead of pushing the page sideways on small screens. */
.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
/* three templates build .kv from <div> rather than <dt>/<dd>, so target children */
.kv > * { min-width: 0; overflow-wrap: anywhere; }
/* .kv value cells are narrow by design; a long pill ("Supply Unit Leader (SPUL)")
   would otherwise spill out of its cell. Pills elsewhere stay unbroken. */
.kv .badge { white-space: normal; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line2); }
.timeline li { position: relative; padding: 0 0 14px 14px; }
.timeline li::before {
  content: ""; position: absolute; left: -24px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--acc); border: 2px solid var(--bg);
}
.timeline li .when { font-size: 11.5px; color: var(--faint); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kanban .kcol { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.kanban .kcol h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; }
.kanban .kcard { background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 12.5px; }

/* ---------- Modal ---------- */
.modal-back {
  display: none; position: fixed; inset: 0; background: #04070cd0;
  z-index: 100; align-items: flex-start; justify-content: center; padding: 6vh 16px;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--line2); border-radius: 12px;
  width: 100%; max-width: 640px; max-height: 86vh; overflow-y: auto; padding: 18px 20px;
}
.modal h3 { margin-top: 0; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--line2); border-left: 4px solid var(--acc);
  border-radius: 8px; padding: 10px 14px; min-width: 240px; max-width: 380px;
  font-size: 13px; box-shadow: 0 6px 24px #0009; animation: slidein .18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* ---------- Map ---------- */
.map { height: 520px; border-radius: var(--radius); border: 1px solid var(--line2); background: #0c1119; }
.map.short { height: 300px; }
.leaflet-container { background: #0c1119; font: 12px var(--font); }

/* ---------- Charts ---------- */
canvas.chart { width: 100%; }

/* ---------- Utility ---------- */
.muted { color: var(--muted); } .faint { color: var(--faint); }
/* .sub is styled under .page-head; used bare inside a card it had no styling at
   all and read as body copy (admin/about, admin/audit, people/skills, …). */
.sub { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; } .big { font-size: 17px; }
.right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex .grow { flex: 1; }
.gap { gap: 14px; }
.wfull { width: 100%; }
.hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.empty { text-align: center; color: var(--faint); padding: 34px 10px; font-size: 13px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 6px; }
.count { color: var(--faint); font-weight: 400; }

/* ---------- Login / setup ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 30% 0%, #10203a 0%, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 28px; }
.auth-card .brand { border: none; padding: 0 0 18px; }
.auth-card.wide { max-width: 560px; }

/* ---------- Print (ICS forms, IAPs, reports) ---------- */
@media print {
  body { background: #fff; color: #111; font-size: 12px; }
  .sidebar, .topbar, .page-head .actions, .noprint, #toasts { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card, .stat { border: 1px solid #999; background: #fff; break-inside: avoid; }
  a { color: #111; }
  .table th { color: #333; border-bottom: 1.5px solid #333; }
  .table td { border-bottom: 1px solid #bbb; }
  /* the screen grays are tuned for the dark shell and wash out on paper
     (--muted is only 2.95:1 on white); ICS forms and SITREPs print with them. */
  .muted, .sub, .stat .lbl, .stat .sub { color: #444; }
  .faint, .timeline li .when { color: #555; }
  /* keep form controls from printing as dark boxes */
  input, select, textarea { background: #fff; color: #111; border-color: #999; }
  /* a horizontal scroll container is meaningless on paper: it silently clipped
     the right-hand columns of wide tables (the 13-column evacuation manifest
     lost Departed/Arrived/Status with no visual cue). */
  .table-wrap { overflow: visible; }
  .print-doc { font-family: Arial, sans-serif; }
  .print-doc h1, .print-doc h2 { color: #000; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid4, .grid5, .grid6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: calc(-1 * var(--sidebar-w)); transition: left .18s; height: 100vh; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px #000c; }
  #menu-btn { display: inline-flex; }
  .grid2, .grid3, .grid4, .grid5, .grid6 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .grid2, .grid3, .grid4, .grid5, .grid6 { grid-template-columns: 1fr; }
  .content { padding: 14px 12px 40px; }
  /* the topbar row is wider than a phone viewport and was scrolling the whole page */
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar .org { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* only wrap flex rows on phones — wrapping them at desktop stacks table-cell
     action buttons and inflates row heights (e.g. ICS-211 check-in board). */
  .flex { flex-wrap: wrap; }
  /* long ICS position names ("Supply Unit Leader (SPUL)") are wider than a phone
     viewport; pills stay unbroken everywhere else. */
  .badge { white-space: normal; }
}
