:root {
  /* Surfaces are derived from UL blue (#2f66f5, hue 223) held at that hue and
   * dropped to surface lightness. The brand accent itself is far too bright to
   * sit behind a heat ramp, so it is kept for interactive chrome only. */
  --ul-blue: #2f66f5;
  --ul-blue-press: #244fc4;

  --bg: #122044;                      /* canvas  H223 S58 L17 */
  --panel: rgba(19, 30, 57, 0.93);    /* panel   H223 S50 L15 */
  --raised: #273968;                  /* raised  H223 S46 L28 */
  --ink: #eef2fb;
  --muted: #9dabcd;
  --line: rgba(120, 155, 235, 0.26);
  --accent: #ff9d2e;                  /* ties the UI to the data heat ramp */
}
* { box-sizing: border-box; }

/* The UA stylesheet implements [hidden] as display:none, but any rule with an
 * id or class selector outruns it — #modal{display:flex} left a full-screen
 * overlay permanently on top of the map, swallowing every click. Enforce it
 * once here so adding display to a toggled element can't break it again. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute; top: 16px; left: 16px; z-index: 2; width: 264px;
  background: var(--panel); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px 18px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}
#panel h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
#panel .sub { margin: 3px 0 16px; font-size: 12.5px; color: var(--muted); }
.stat { margin-bottom: 12px; }
.stat span { display: block; font-size: 30px; font-weight: 650; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--accent); }
.stat.small span { font-size: 17px; color: var(--ink); }
.stat label { display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); margin-top: 1px; }
#legend { display: flex; align-items: center; gap: 5px; margin: 14px 0 10px;
  padding-top: 12px; border-top: 1px solid var(--line); }
.dot { width: 13px; height: 13px; border-radius: 50%; }
.d1 { background: #ffd24d; } .d2 { background: #ffa32e; }
.d3 { background: #ff6b35; } .d4 { background: #e01f7a; }
#legend em { font-style: normal; font-size: 11px; color: var(--muted); margin-left: 5px; }
.note { margin: 0; font-size: 11.5px; color: var(--muted); }

#loading, #tokenwarn {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 3;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 22px; font-size: 14px; box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#tokenwarn { max-width: 340px; line-height: 1.6; }
#tokenwarn code { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

@media (max-width: 640px) {
  #panel { left: 8px; right: 8px; top: 8px; width: auto; padding: 14px; }
  .stat span { font-size: 25px; }
}

/* ---- drill-down panel ---- */
#detail {
  position: absolute; top: 16px; right: 60px; z-index: 2;
  width: 320px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#detail h2 { margin: 0; font-size: 24px; letter-spacing: -0.02em; color: var(--accent);
  font-variant-numeric: tabular-nums; }
#detail .sub { margin: 2px 0 14px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); }
#detail h3 { margin: 18px 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); font-weight: 600; }
#detail-close { position: absolute; top: 10px; right: 12px; background: none; border: 0;
  color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; }
#detail-close:hover { color: var(--ink); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0;
  font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.bars, .plain, .incidents { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.bars li { display: grid; grid-template-columns: 78px 1fr 44px; align-items: center;
  gap: 8px; margin-bottom: 4px; }
.bars .bl { font-size: 10.5px; letter-spacing: 0.03em; color: var(--muted); }
.bars .bar { background: rgba(255,255,255,0.09); border-radius: 3px; height: 7px; }
.bars .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bars .bn { text-align: right; font-variant-numeric: tabular-nums; }

.plain li { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 3px;
  color: var(--ink); }
.plain em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }

.incidents li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 6px 0; border-top: 1px solid var(--line); }
.incidents .it { font-size: 11.5px; text-transform: capitalize; }
.incidents .id { font-size: 11px; color: var(--muted); text-align: right; }
.incidents .iu { grid-column: 1 / -1; font-size: 10.5px; color: var(--muted); }

.detail-note { margin: 14px 0 0; font-size: 10.5px; line-height: 1.5; color: var(--muted);
  padding-top: 10px; border-top: 1px solid var(--line); }
.detail-error { color: #ff8b8b; font-size: 12.5px; }
.loading-line { color: var(--muted); font-size: 12.5px; }

@media (max-width: 900px) {
  #detail { right: 8px; left: 8px; width: auto; top: auto; bottom: 8px;
    max-height: 52vh; }
}

/* ---- department card + fire block ---- */
.dept { font-size: 12.5px; }
.dept-name { margin: 0; font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.dept-meta { margin: 2px 0 8px; font-size: 11px; color: var(--muted); }
.dept-link { color: var(--accent); text-decoration: none; word-break: break-all; font-size: 12px; }
.dept-link:hover { text-decoration: underline; }
.dept .kv { margin-top: 8px; }
.dept .kv dd { text-align: right; }

.fire-lab { margin: 12px 0 5px; font-size: 11.5px; color: var(--ink); }
.fire-lab em { font-style: normal; color: var(--muted); font-size: 10.5px; }

.tags { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { background: rgba(255,255,255,0.08); border-radius: 4px;
  padding: 2px 6px; font-size: 10px; text-transform: capitalize; color: var(--muted); }

/* ---- opted-in tier ---- */
.optin { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); display: flex; align-items: baseline;
  gap: 6px; flex-wrap: wrap; line-height: 1.5; }
.optin > span { white-space: nowrap; }
.optin i { width: 9px; height: 9px; border-radius: 2px; background: rgba(74,222,128,0.25);
  border: 1px dashed #4ade80; flex: none; }
.optin a { color: var(--accent); text-decoration: none; }
.optin a:hover { text-decoration: underline; }
.live-badge { font-size: 9.5px; background: rgba(74,222,128,0.16); color: #4ade80;
  padding: 2px 6px; border-radius: 99px; letter-spacing: 0.05em; margin-left: 6px; }
table.units { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-top: 4px; }
table.units th { text-align: left; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 4px 4px 4px 0;
  border-bottom: 1px solid var(--line); }
table.units td { padding: 4px 4px 4px 0; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; }
.live-badge.mock { background: rgba(248,113,113,0.18); color: #f87171; }
.optin.is-mock i { border-color: #f87171; background: rgba(248,113,113,0.2); }
.optin.is-mock::after { content: 'mock'; font-size: 9.5px; letter-spacing: 0.05em;
  background: rgba(248,113,113,0.18); color: #f87171; padding: 1px 6px; border-radius: 99px; }

/* ---- incident modal ---- */
#modal { position: fixed; inset: 0; z-index: 10; background: rgba(4,6,10,0.72);
  backdrop-filter: blur(3px); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 20px; overflow-y: auto; }
#modal-card { position: relative; width: 100%; max-width: 660px; background: #16244a;
  border: 1px solid var(--line); border-radius: 14px; padding: 28px 30px 30px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.6); }
#modal-close { position: absolute; top: 14px; right: 16px; background: none; border: 0;
  color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 2px 6px; }
#modal-close:hover { color: var(--ink); }
.mock-strip { margin: 0 0 16px; background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.35); border-radius: 8px; padding: 9px 12px;
  font-size: 12px; color: #fca5a5; }
.m-eyebrow { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); }
#modal-card h2 { margin: 4px 0 2px; font-size: 24px; letter-spacing: -0.02em; color: var(--accent);
  font-variant-numeric: tabular-nums; }
.m-type { margin: 0 0 20px; font-size: 14px; text-transform: capitalize; color: var(--ink); }
#modal-card h3 { margin: 22px 0 9px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); font-weight: 600; }
#modal-card h3 em { font-style: normal; text-transform: none; letter-spacing: 0;
  color: var(--muted); font-weight: 400; }
.m-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.m-card { background: rgba(255,255,255,0.05); border-radius: 8px; padding: 11px 12px; }
.m-card span { display: block; font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums; }
.m-card label { display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-top: 3px; }
table.m-units { width: 100%; border-collapse: collapse; font-size: 12px; }
table.m-units th { text-align: left; font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 5px 6px 5px 0;
  border-bottom: 1px solid var(--line); }
table.m-units td { padding: 6px 6px 6px 0; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; }
table.m-units td.u { font-weight: 600; color: var(--accent); }
table.m-units td.dim { color: var(--muted); text-transform: capitalize; font-size: 11px; }
table.m-units td.num { color: #ffd24d; }
#modal-card .kv { font-size: 13px; gap: 5px 14px; }
#modal-card .kv dd { text-transform: capitalize; }
.m-note { margin: 10px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--muted); }
.incidents.clickable li { padding: 0; }
.incidents.clickable a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 8px 0; text-decoration: none; color: inherit; }
.incidents.clickable a:hover { background: rgba(255,255,255,0.04); }
.incidents.clickable a:hover .it { color: var(--accent); }
@media (max-width: 700px) {
  .m-grid { grid-template-columns: repeat(2, 1fr); }
  #modal { padding: 12px; }
  #modal-card { padding: 22px 18px; }
  table.m-units { font-size: 11px; }
}

/* ---- fireground milestone sequence ---- */
.m-timeline { list-style: none; margin: 0; padding: 0; }
.m-timeline li { display: grid; grid-template-columns: 14px 1fr auto auto; align-items: center;
  gap: 10px; padding: 5px 0; font-size: 12.5px; position: relative; }
.m-timeline li + li::before { content: ''; position: absolute; left: 6px; top: -10px;
  height: 14px; width: 1px; background: var(--line); }
.tl-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  margin-left: 3px; }
.tl-label { color: var(--ink); }
.tl-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.tl-rel { color: #ffd24d; font-variant-numeric: tabular-nums; font-size: 11.5px;
  min-width: 56px; text-align: right; }

/* ---- opt-in promo, bottom left ---- */
#promo {
  position: absolute; left: 16px; bottom: 34px; z-index: 2;   /* above the Mapbox wordmark */
  display: flex; align-items: center; gap: 12px;
  width: 296px; padding: 13px 14px;
  background: var(--panel); backdrop-filter: blur(12px);
  border: 1px solid rgba(120, 155, 235, 0.38); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  text-decoration: none; color: var(--ink);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
#promo:hover { transform: translateY(-2px); border-color: var(--ul-blue);
  background: rgba(30, 44, 80, 0.95); }
#promo:focus-visible { outline: 2px solid var(--ul-blue); outline-offset: 2px; }
#promo.is-dismissed { display: none; }

.promo-pulse { position: relative; flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--ul-blue); }
.promo-pulse::after { content: ''; position: absolute; inset: -5px; border-radius: 50%;
  border: 1px solid var(--ul-blue); opacity: .75; animation: promo-ping 2.4s ease-out infinite; }
@keyframes promo-ping {
  0%   { transform: scale(.55); opacity: .75; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .promo-pulse::after { animation: none; opacity: .4; } }

.promo-body { display: block; min-width: 0; }
.promo-body strong { display: block; font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }
.promo-sub { display: block; margin-top: 2px; font-size: 11px; line-height: 1.45; color: var(--muted); }
.promo-go { flex: none; color: var(--ul-blue); font-size: 15px; }
#promo:hover .promo-go { color: var(--ink); }

#promo-close {
  position: absolute; top: 4px; right: 6px;
  background: none; border: 0; color: var(--muted); font-size: 15px; line-height: 1;
  padding: 2px 5px; cursor: pointer; border-radius: 4px; opacity: 0;
  transition: opacity .16s ease;
}
#promo:hover #promo-close { opacity: 1; }
#promo-close:hover { color: var(--ink); background: rgba(255,255,255,0.1); }

@media (max-width: 640px) {
  #promo { left: 8px; right: 8px; width: auto; bottom: 30px; }
}
