/* =====================================================================
   Pruksa Ville 79 — Emergency Command Center
   Colour is never decoration: every hue below maps to a real state.
   ===================================================================== */
:root {
  --bg: #0c1a2b;
  --bg-deep: #08121f;
  --panel: #12243a;
  --panel-2: #183049;
  --line: #22405f;
  --line-soft: #1b3550;
  --text: #e9eff6;
  --muted: #93a7bd;
  --dim: #5f7690;
  --paper: #f5f7fa;

  /* status vocabulary (section 37) */
  --s-normal: #2fb36d;
  --s-watch: #f2c230;
  --s-assist: #3d8bfd;
  --s-urgent: #f57c1f;
  --s-emergency: #e5383b;
  --s-evacuated: #9b5de5;
  --s-offline: #6c7a89;
  --s-info: #7c93b0;

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif;
  --focus: 0 0 0 3px rgba(61, 139, 253, .55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: #8cc0ff; text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[data-lucide], svg.lucide { width: 18px; height: 18px; stroke-width: 2; flex: none; }

/* ------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-deep); border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 18px 18px 14px; border-bottom: 1px solid var(--line-soft); display: flex; gap: 10px; align-items: center; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; background: var(--s-emergency); display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 15px; letter-spacing: -.5px;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { padding: 10px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 14.5px; text-decoration: none; position: relative;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.nav a.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--s-assist); }
.nav .badge-count { margin-left: auto; }
.nav-sep { height: 1px; background: var(--line-soft); margin: 8px 6px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--line-soft); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; background: rgba(12, 26, 43, .94); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.topbar-title strong { font-size: 16px; letter-spacing: .3px; }
.topbar-title span { font-size: 12.5px; color: var(--muted); }
.sys-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.sys-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--s-normal); box-shadow: 0 0 0 3px rgba(47, 179, 109, .2); }
.sys-pill.offline .sys-dot { background: var(--s-emergency); box-shadow: 0 0 0 3px rgba(229, 56, 59, .25); }
.clock { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.topbar-spacer { flex: 1; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn .dot-count {
  position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--s-emergency); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.menu-btn { display: none; }
.content { padding: 20px; flex: 1; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* global search */
.gsearch { position: relative; width: min(340px, 34vw); }
.gsearch input { padding-left: 36px; }
.gsearch > [data-lucide], .gsearch > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--dim); }
.gsearch-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 16px 40px rgba(0, 0, 0, .45); max-height: 420px; overflow-y: auto; z-index: 50;
}
.gsearch-results h6 { margin: 0; padding: 8px 12px 4px; font-size: 12px; color: var(--dim); font-weight: 600; }
.gsearch-results a { display: flex; gap: 10px; align-items: center; padding: 8px 12px; color: var(--text); text-decoration: none; }
.gsearch-results a:hover, .gsearch-results a.active { background: var(--panel-2); }

/* dropdown */
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); width: 360px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 44px rgba(0, 0, 0, .5); z-index: 60;
}
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.dropdown-body { max-height: 380px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.notif-item:hover { background: var(--panel-2); }
.notif-item.unread { background: rgba(61, 139, 253, .08); }
.notif-item .bar { width: 4px; border-radius: 2px; flex: none; background: var(--s-info); }

/* ------------------------------------------------------------- panels & cards */
.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius-lg); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line-soft); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 15.5px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.panel-body { padding: 14px 16px; }
.panel-body.flush { padding: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi {
  background: var(--panel-2); border-radius: var(--radius); padding: 10px 12px; border-left: 3px solid transparent;
  display: flex; flex-direction: column; min-width: 0; text-decoration: none; color: inherit;
}
a.kpi:hover { background: #1e3a58; text-decoration: none; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.kpi.wide { grid-column: span 2; }
.kpi.hot { background: rgba(229, 56, 59, .14); border-left-color: var(--s-emergency); }
.kpi.hot .v { color: #ff7072; }
.kpi.warn { border-left-color: var(--s-urgent); }
.kpi.watch { border-left-color: var(--s-watch); }
.kpi.ok { border-left-color: var(--s-normal); }

/* ------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 650; white-space: nowrap; border: 1px solid transparent; line-height: 1.6;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.b-NORMAL, .b-RESOLVED, .b-AVAILABLE, .b-OCCUPIED, .b-OPEN { color: #59d391; background: rgba(47, 179, 109, .14); border-color: rgba(47, 179, 109, .3); }
.b-WATCH, .b-TEMP_AWAY, .b-STANDBY { color: #f6d35e; background: rgba(242, 194, 48, .13); border-color: rgba(242, 194, 48, .3); }
.b-ASSISTANCE { color: #78adff; background: rgba(61, 139, 253, .14); border-color: rgba(61, 139, 253, .32); }
.b-URGENT, .b-BUSY { color: #ff9d52; background: rgba(245, 124, 31, .15); border-color: rgba(245, 124, 31, .35); }
.b-EMERGENCY { color: #fff; background: var(--s-emergency); }
.b-EVACUATED { color: #c39cf5; background: rgba(155, 93, 229, .16); border-color: rgba(155, 93, 229, .35); }
.b-OFFLINE, .b-VACANT, .b-CLOSED, .b-CANCELLED { color: #aab6c3; background: rgba(108, 122, 137, .16); border-color: rgba(108, 122, 137, .35); }
.b-INFORMATION { color: #b3c3d8; background: rgba(124, 147, 176, .16); border-color: rgba(124, 147, 176, .35); }
.b-flow { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 5px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); margin: 2px 4px 2px 0; }
.tag.health { border-color: rgba(245, 124, 31, .45); color: #ffbe8a; }
.tag.vuln { border-color: rgba(229, 56, 59, .5); color: #ff9799; }

/* ------------------------------------------------------------- forms & buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; min-height: 38px;
}
.btn:hover { background: #21405f; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--s-assist); border-color: var(--s-assist); color: #fff; }
.btn.primary:hover { background: #2f78e6; }
.btn.danger { background: var(--s-emergency); border-color: var(--s-emergency); color: #fff; }
.btn.danger:hover { background: #cc2a2d; }
.btn.warn { background: var(--s-urgent); border-color: var(--s-urgent); color: #1a0d00; }
.btn.success { background: var(--s-normal); border-color: var(--s-normal); color: #04210f; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.lg { padding: 13px 20px; font-size: 16px; min-height: 52px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--muted); }
label.field > span { font-weight: 600; }
.input, input[type=text], input[type=search], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-deep);
  color: var(--text); font: inherit; font-size: 14.5px; min-height: 40px;
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--dim); }
select option { background: var(--panel); }
.field-error { color: #ff8a8c; font-size: 12.5px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--s-emergency); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .span-2 { grid-column: span 2; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); padding: 6px 0; }
.check input { width: 18px; height: 18px; accent-color: var(--s-assist); }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.fieldset legend { padding: 0 6px; font-weight: 650; font-size: 13.5px; color: var(--text); }
.fieldset.sensitive { border-color: rgba(245, 124, 31, .5); }

/* segmented / chip pickers */
.seg { display: grid; gap: 8px; }
.seg.cols-4 { grid-template-columns: repeat(4, 1fr); }
.seg.cols-3 { grid-template-columns: repeat(3, 1fr); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  border: 2px solid var(--line); border-radius: 10px; padding: 10px 6px; text-align: center; cursor: pointer;
  font-weight: 700; font-size: 14px; display: flex; flex-direction: column; gap: 2px; align-items: center; background: var(--bg-deep);
}
.seg label small { font-weight: 500; font-size: 11.5px; color: var(--muted); }
.seg input:focus-visible + label { box-shadow: var(--focus); }
.seg .p-EMERGENCY input:checked + label { border-color: var(--s-emergency); background: rgba(229, 56, 59, .2); }
.seg .p-URGENT input:checked + label { border-color: var(--s-urgent); background: rgba(245, 124, 31, .18); }
.seg .p-ASSISTANCE input:checked + label { border-color: var(--s-assist); background: rgba(61, 139, 253, .18); }
.seg .p-INFORMATION input:checked + label { border-color: var(--s-info); background: rgba(124, 147, 176, .2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; }
.chip span, button.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-deep); color: var(--text); font: inherit; font-size: 13.5px; cursor: pointer;
}
.chip input:checked + span, button.chip.on { background: var(--s-assist); border-color: var(--s-assist); color: #fff; }
.chip input:focus-visible + span { box-shadow: var(--focus); }
.chip .sw { width: 9px; height: 9px; border-radius: 50%; }

/* ------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tr:hover td { background: rgba(255, 255, 255, .02); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; color: var(--muted); font-size: 13px; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------- modal & toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 9, 17, .72); z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 5vh 14px; overflow-y: auto;
}
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); width: 100%; max-width: 560px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.modal.lg { max-width: 820px; }
.modal.xl { max-width: 1040px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 9px; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.modal-open { overflow: hidden; }
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: modal-in .16s ease-out; }
  @keyframes modal-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
}
#toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--s-assist); padding: 10px 14px; border-radius: 9px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45); font-size: 14px; display: flex; gap: 9px; align-items: flex-start; }
.toast.success { border-left-color: var(--s-normal); }
.toast.error { border-left-color: var(--s-emergency); }
.toast.warn { border-left-color: var(--s-urgent); }

/* ------------------------------------------------------------- full screen emergency alert */
.alert-overlay {
  position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(70, 6, 8, .92);
}
.alert-card {
  width: min(620px, 100%); background: var(--bg-deep); border: 3px solid var(--s-emergency); border-radius: 18px;
  padding: 26px 26px 22px; text-align: center; box-shadow: 0 0 0 10px rgba(229, 56, 59, .18), 0 40px 90px rgba(0, 0, 0, .7);
}
.alert-card .siren { font-size: 44px; line-height: 1; }
.alert-card h2 { margin: 6px 0 2px; font-size: 34px; letter-spacing: 2px; color: #ff5a5d; }
.alert-card .house { font-size: 30px; font-weight: 800; margin: 6px 0; }
.alert-card .what { font-size: 19px; margin-bottom: 4px; }
.alert-card .meta { color: var(--muted); font-size: 14px; }
.alert-card .phone { font-size: 22px; font-weight: 700; margin: 10px 0 16px; font-variant-numeric: tabular-nums; }
.alert-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.alert-foot { margin-top: 12px; display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
@media (prefers-reduced-motion: no-preference) {
  .alert-overlay { animation: alert-flash 1.6s ease-in-out infinite; }
  @keyframes alert-flash { 0%, 100% { background: rgba(70, 6, 8, .92); } 50% { background: rgba(120, 10, 14, .92); } }
}

/* ------------------------------------------------------------- dashboard grid */
.cc-grid { display: grid; grid-template-columns: 290px minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.cc-grid > .col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cc-bottom { display: grid; grid-template-columns: 1.1fr 1.4fr 1fr; gap: 14px; margin-top: 14px; }
.motto { font-size: 13px; color: var(--muted); margin-top: 3px; }
.big-metric { display: flex; flex-direction: column; }
.big-metric .v { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big-metric .l { color: var(--muted); font-size: 13px; }
.meter { height: 10px; border-radius: 6px; background: var(--bg-deep); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--s-normal); }
.meter.mid > span { background: var(--s-watch); }
.meter.high > span { background: var(--s-emergency); }

/* queue */
.queue { display: flex; flex-direction: column; }
.q-item { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); border-left: 4px solid var(--s-info); display: flex; flex-direction: column; gap: 6px; }
.q-item.EMERGENCY { border-left-color: var(--s-emergency); background: rgba(229, 56, 59, .07); }
.q-item.URGENT { border-left-color: var(--s-urgent); }
.q-item.ASSISTANCE { border-left-color: var(--s-assist); }
.q-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.q-house { font-size: 18px; font-weight: 750; }
.q-title { font-size: 14.5px; }
.q-meta { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.q-wait { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.q-wait.late { color: #ff7072; }

/* critical house list */
.crit { display: flex; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; align-items: flex-start; }
.crit:hover { background: var(--panel-2); }
.crit .sw { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; }
.crit strong { font-size: 15px; }

/* ------------------------------------------------------------- village map */
.vmap { position: relative; background: #e9eef3; border-radius: var(--radius); overflow: hidden; user-select: none; touch-action: none; }
.vmap.tall { height: calc(100vh - 210px); min-height: 420px; }
.vmap.fit { aspect-ratio: 1295 / 832; }
.vmap-stage { position: absolute; left: 0; top: 0; width: 100%; transform-origin: 0 0; will-change: transform; }
.vmap-stage img { display: block; width: 100%; height: auto; pointer-events: none; }
.vmap-layer { position: absolute; inset: 0; }
.vmap.adding { cursor: crosshair; }
.vmap.panning { cursor: grabbing; }
.house {
  position: absolute; border-radius: 3px; border: 1.5px solid rgba(0, 0, 0, .45); display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 10px; line-height: 1; cursor: pointer; text-shadow: 0 1px 1px rgba(0, 0, 0, .55);
  background: var(--s-normal); overflow: visible; font-variant-numeric: tabular-nums; container-type: size;
}
.house span { font-size: clamp(7px, 42cqh, 14px); pointer-events: none; }
.house.st-NORMAL, .house.st-RESOLVED { background: var(--s-normal); }
.house.st-WATCH { background: var(--s-watch); color: #2a2000; text-shadow: none; }
.house.st-ASSISTANCE { background: var(--s-assist); }
.house.st-URGENT { background: var(--s-urgent); }
.house.st-EMERGENCY { background: var(--s-emergency); border-color: #fff; z-index: 3; }
.house.st-EVACUATED { background: var(--s-evacuated); }
.house.occ-VACANT { background: #c9d2dc !important; color: #5c6a79; border-style: dashed; text-shadow: none; }
.house.occ-TEMP_AWAY { box-shadow: inset 0 -4px 0 rgba(255, 255, 255, .75); }
.house.dimmed { opacity: .18; }
.house.selected { outline: 3px solid #0b1726; outline-offset: 2px; z-index: 5; }
.house.flash { outline: 3px solid #fff; outline-offset: 3px; z-index: 6; }
.house .rz { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #fff; border: 2px solid #0b1726; border-radius: 2px; cursor: nwse-resize; display: none; }
.vmap.editing .house .rz { display: block; }
.vmap.editing .house { cursor: move; }
@media (prefers-reduced-motion: no-preference) {
  .house.st-EMERGENCY::after {
    content: ''; position: absolute; inset: -3px; border-radius: 5px; border: 2px solid var(--s-emergency);
    animation: pulse 1.5s ease-out infinite; pointer-events: none;
  }
  @keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(2.4); opacity: 0; } }
}
.vmap-controls { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 10; }
.vmap-controls button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid #b9c4d0; background: #fff; color: #0c1a2b; display: grid; place-items: center; cursor: pointer; }
.vmap-controls button:hover { background: #eef3f8; }
.vmap-hint { position: absolute; left: 10px; bottom: 10px; z-index: 10; background: rgba(12, 26, 43, .86); color: #fff; font-size: 12.5px; padding: 5px 10px; border-radius: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* house quick popup (section 43) */
.house-pop {
  position: absolute; z-index: 20; width: 260px; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 18px 40px rgba(0, 0, 0, .5); padding: 12px 14px; font-size: 14px;
}
.house-pop h4 { margin: 0; font-size: 18px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.house-pop ul { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 2px; }
.house-pop .last { padding: 7px 9px; border-radius: 7px; background: rgba(229, 56, 59, .12); margin: 6px 0; font-size: 13.5px; }
.house-pop .x { position: absolute; top: 6px; right: 6px; }

/* ------------------------------------------------------------- incident detail */
.stepper { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.step { text-align: center; font-size: 12px; color: var(--dim); }
.step .bar { height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 6px; }
.step.done { color: var(--muted); }
.step.done .bar { background: var(--s-normal); }
.step.current { color: var(--text); font-weight: 700; }
.step.current .bar { background: var(--s-assist); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 62px 16px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.timeline .t { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--s-assist); margin-top: 6px; position: relative; z-index: 1; }
.timeline li:not(:last-child)::after { content: ''; position: absolute; left: 77px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline .dot.RESOLVED { background: var(--s-normal); }
.timeline .dot.NEW { background: var(--s-emergency); }
.timeline .dot.NOTE { background: var(--dim); }

/* ------------------------------------------------------------- emergency mode (mobile) */
.em-wrap { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.em-btn {
  display: flex; align-items: center; gap: 16px; padding: 20px 20px; border-radius: 16px; font-size: 21px; font-weight: 750;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); text-decoration: none; cursor: pointer; width: 100%; font-family: inherit;
}
.em-btn:hover { text-decoration: none; background: var(--panel-2); }
.em-btn .ico { font-size: 30px; width: 40px; text-align: center; }
.em-btn small { display: block; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.em-btn.red { background: var(--s-emergency); border-color: var(--s-emergency); color: #fff; padding: 28px 20px; font-size: 26px; }
.em-btn.red small { color: rgba(255, 255, 255, .85); }
.em-count { margin-left: auto; font-size: 26px; font-variant-numeric: tabular-nums; }

/* floating report button (mobile) */
.fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 90; display: none; align-items: center; gap: 8px; padding: 14px 20px;
  border-radius: 999px; background: var(--s-emergency); color: #fff; font-weight: 750; font-size: 16px; border: 0;
  box-shadow: 0 12px 30px rgba(229, 56, 59, .45); cursor: pointer; font-family: inherit;
}

/* ------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.15fr 1fr; }
.login-art { position: relative; background: var(--bg-deep); overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; padding: 40px; }
.login-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .32; filter: saturate(.6); }
.login-art .copy { position: relative; max-width: 520px; }
.login-art h1 { font-size: 34px; line-height: 1.25; margin: 0 0 10px; }
.login-art p { color: var(--muted); margin: 0; font-size: 16px; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 30px; }
.login-form form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }

/* ------------------------------------------------------------- utilities */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.res-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); align-items: flex-start; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-weight: 700; flex: none; border: 1px solid var(--line); }
.notice { padding: 10px 12px; border-radius: 8px; background: rgba(61, 139, 253, .1); border: 1px solid rgba(61, 139, 253, .3); font-size: 13.5px; }
.notice.warn { background: rgba(245, 124, 31, .1); border-color: rgba(245, 124, 31, .35); }
.skeleton { background: linear-gradient(90deg, var(--panel-2), #203a56, var(--panel-2)); background-size: 200% 100%; border-radius: 8px; min-height: 18px; }
@media (prefers-reduced-motion: no-preference) { .skeleton { animation: sk 1.3s linear infinite; } @keyframes sk { to { background-position: -200% 0; } } }
.spin { animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1360px) {
  .cc-grid { grid-template-columns: 260px minmax(0, 1fr) 320px; }
}
@media (max-width: 1180px) {
  .cc-grid { grid-template-columns: minmax(0, 1fr) 340px; }
  .cc-grid > .col-kpi { grid-column: 1 / -1; }
  .cc-grid > .col-kpi .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .cc-grid > .col-kpi .kpi.wide { grid-column: span 1; }
  .cc-bottom { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 200; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55); }
  .menu-btn { display: inline-grid; }
  .gsearch { display: none; }
  .gsearch.open { display: block; position: absolute; left: 10px; right: 10px; top: 58px; width: auto; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .clock, .topbar .user-name { display: none; }
  .content { padding: 14px 12px 90px; }
  .cc-grid, .cc-bottom, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .fab { display: inline-flex; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { min-height: 220px; padding: 24px; }
  .login-art h1 { font-size: 24px; }
  .seg.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .alert-actions { grid-template-columns: 1fr; }
  .stepper .step span { display: none; }
}
@media (min-width: 901px) { .search-toggle { display: none; } }

@media print {
  body { background: #fff; color: #000; }
  .sidebar, .topbar, .fab, .no-print, #toast-root { display: none !important; }
  .shell { display: block; }
  .panel { border: 0; background: #fff; }
  table.data th, table.data td { color: #000; border-color: #ccc; }
  .content { padding: 0; }
}
