:root {
  --bg: #07101f;
  --surface: #0e1a2c;
  --surface-2: #14233a;
  --surface-3: #192b46;
  --border: #29405f;
  --text: #f7f9fc;
  --muted: #9babc0;
  --primary: #2878ff;
  --primary-hover: #4a91ff;
  --success: #22c55e;
  --success-bg: #0b3520;
  --warning: #f59e0b;
  --warning-bg: #3a2207;
  --danger: #ef334d;
  --danger-bg: #420913;
  --info: #38bdf8;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% -10%, rgba(40, 120, 255, .18), transparent 34%),
    linear-gradient(145deg, #07101f, #0a1424 50%, #050a13);
  line-height: 1.5;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(4, 10, 22, .94);
  border-bottom: 1px solid rgba(148, 163, 184, .18);
  backdrop-filter: blur(16px);
}
.topbar-inner {
  width: min(1240px, 94%);
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  min-width: max-content;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  box-shadow: 0 10px 28px rgba(37, 99, 235, .36);
  font-size: 13px;
  font-weight: 900;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11px; font-weight: 700; margin-top: 3px; }
.main-nav { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.main-nav a {
  color: #dce7f6;
  text-decoration: none;
  font-size: 14px;
  font-weight: 750;
  padding: 9px 11px;
  border-radius: 10px;
}
.main-nav a:hover { background: #16253d; color: #fff; }
.user-chip {
  border: 1px solid var(--border);
  background: #0d1829;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: #dbeafe;
}
.logout-link { color: #fda4af !important; }

.container { width: min(1240px, 94%); margin: 34px auto; }
footer { width: min(1240px, 94%); margin: 20px auto 0; padding: 28px 0 42px; text-align: center; color: #64748b; font-size: 13px; }

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 25px;
}
.page-heading h1 { margin: 5px 0 6px; font-size: clamp(30px, 4vw, 44px); line-height: 1.05; letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--muted); font-size: 16px; }
.eyebrow, .section-eyebrow {
  display: block;
  color: #76b2ff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.heading-summary {
  min-width: 150px;
  padding: 14px 18px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(15, 27, 46, .9);
}
.heading-summary strong { display: block; font-size: 30px; line-height: 1; }
.heading-summary span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.btn {
  min-height: 44px;
  padding: 11px 16px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease, border-color .15s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(96, 165, 250, .42); outline-offset: 2px; }
.btn.primary { background: linear-gradient(135deg, #3485ff, #1d63db); }
.btn.secondary, .btn.ghost { background: #192a43; border: 1px solid #385171; }
.btn.ok { background: #159447; }
.btn.danger { background: #d8203d; }
.btn.warn { background: #c97707; }
.btn.grow { flex: 1; justify-content: space-between; }
.inline { display: inline; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.panel {
  padding: 22px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(14, 26, 44, .96);
  box-shadow: var(--shadow);
}
.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 12px; font-weight: 700; }
.alert.success { background: #11472b; border: 1px solid #22c55e; }
.alert.error { background: #5c101b; border: 1px solid #fb7185; }
.muted { color: var(--muted); }
.empty-state { padding: 55px 22px; text-align: center; border: 1px dashed #385171; border-radius: 20px; background: rgba(14, 26, 44, .74); }
.empty-state > div { font-size: 42px; }
.empty-state h2 { margin: 10px 0 4px; }
.empty-state p { margin: 0; color: var(--muted); }

.site-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.site-card-new {
  position: relative;
  overflow: hidden;
  padding: 23px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(150deg, rgba(19, 34, 56, .98), rgba(8, 17, 31, .98));
  box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease;
}
.site-card-new::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--success); }
.site-card-new:hover { transform: translateY(-3px); border-color: #52729b; }
.site-card-new.has-emergency { border: 2px solid #fb7185; background: linear-gradient(145deg, #3c0713, #130711); }
.site-card-new.has-emergency::before { width: 7px; background: var(--danger); }
.site-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.site-icon { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; background: #192a43; font-size: 25px; }
.site-state { padding: 7px 11px; border-radius: 999px; font-size: 11px; font-weight: 900; letter-spacing: .07em; }
.site-state.normal { color: #86efac; background: #0b3924; }
.site-state.danger { color: #fff; background: #b51235; animation: softPulse 1.1s infinite alternate; }
.site-card-new h2 { margin: 20px 0 4px; font-size: 26px; }
.site-address { min-height: 24px; margin: 0; color: var(--muted); }
.site-card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.site-card-metrics > div { padding: 14px; border: 1px solid rgba(148, 163, 184, .15); border-radius: 14px; background: rgba(3, 9, 20, .48); }
.site-card-metrics strong, .site-card-metrics span { display: block; }
.site-card-metrics strong { font-size: 22px; line-height: 1.15; }
.site-card-metrics span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.site-card-actions { display: flex; gap: 10px; }

label { display: block; margin: 12px 0 7px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid #324968;
  border-radius: 11px;
  color: #fff;
  background: #081323;
}
.row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

.live-status {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  margin: 18px 0;
  padding: 20px;
  border: 2px solid transparent;
  border-radius: 18px;
}
.live-status.is-normal { background: linear-gradient(110deg, #0b3a25, #0d271e); border-color: #22c55e; }
.live-status.is-emergency { background: linear-gradient(110deg, #6f0a18, #36070e); border-color: #ff6578; animation: emergencyGlow 1.2s infinite alternate; }
.live-status-main { display: flex; align-items: center; gap: 15px; }
.status-dot { width: 20px; height: 20px; flex: 0 0 20px; border-radius: 50%; background: #43d875; box-shadow: 0 0 0 8px rgba(34, 197, 94, .16); }
.is-emergency .status-dot { background: #fff; box-shadow: 0 0 0 9px rgba(239, 51, 77, .28), 0 0 28px #ef334d; }
.live-status-label { color: #cbd5e1; font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.live-status-title { margin-top: 3px; font-size: 29px; font-weight: 950; line-height: 1.05; }
.live-status-message { margin-top: 6px; color: #e5edf8; }
.live-status-details { display: flex; gap: 10px; }
.live-status-details > div { min-width: 112px; padding: 11px 13px; text-align: center; border: 1px solid rgba(255,255,255,.12); border-radius: 13px; background: rgba(2, 6, 23, .35); }
.live-status-details strong, .live-status-details span { display: block; }
.live-status-details strong { font-size: 22px; }
.live-status-details span { margin-top: 2px; color: #cbd5e1; font-size: 11px; }
.live-status-details .metric-danger { background: #67101c; border-color: #fb7185; }
.live-status-details .metric-success { background: #0c4326; border-color: #4ade80; }
.site-actions { margin-bottom: 18px; }

.panel-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 13px; }
.panel-heading-row h2 { margin: 3px 0 0; font-size: 26px; }
.table-wrap { overflow: hidden; border: 1px solid var(--border); border-radius: 15px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; text-align: left; border-bottom: 1px solid #273b58; }
th { background: #162640; color: #c7d5e8; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
td { background: rgba(8, 17, 31, .7); }
tr:last-child td { border-bottom: 0; }
.phone-link { color: #7dd3fc; font-weight: 800; text-decoration: none; }

/* CITQ */
.citq-page-heading { align-items: center; }
.citq-toolbar { padding: 19px 20px; }
.citq-toolbar label { margin: 0 0 9px; color: #dbeafe; font-size: 13px; }
.search-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; padding: 0 12px; border: 1px solid #385171; border-radius: 14px; background: #071221; }
.search-row:focus-within { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, .16); }
.search-row > span { color: #7dd3fc; font-size: 25px; }
.search-row input { border: 0; background: transparent; outline: 0; }
.search-row button { width: 32px; height: 32px; border: 0; border-radius: 9px; color: #d3dfef; background: #1b2b43; cursor: pointer; font-size: 20px; }
.citq-toolbar-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.secure-chip { padding: 6px 10px; border-radius: 999px; color: #86efac; background: #0b3924; font-weight: 800; }
.citq-card-grid { display: grid; gap: 13px; }
.citq-card { overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: rgba(14, 26, 44, .97); box-shadow: 0 12px 34px rgba(0, 0, 0, .18); }
.citq-card-summary { width: 100%; padding: 17px 18px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; border: 0; color: #fff; background: transparent; text-align: left; cursor: pointer; }
.citq-card-summary:hover { background: #14243b; }
.citq-pin { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: #19304e; font-size: 21px; }
.citq-summary-text strong, .citq-summary-text small { display: block; }
.citq-summary-text strong { font-size: 17px; }
.citq-summary-text small { margin-top: 4px; color: var(--muted); line-height: 1.35; }
.citq-chevron { color: #60a5fa; font-size: 31px; transition: transform .2s ease; }
.citq-card.open .citq-chevron { transform: rotate(90deg); }
.citq-card-details { display: none; padding: 0 18px 18px; border-top: 1px solid var(--border); }
.citq-card.open .citq-card-details { display: block; }
.citq-contact-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 16px 0; }
.citq-contact-grid > div { min-width: 0; padding: 12px; border: 1px solid #29405f; border-radius: 12px; background: #081424; }
.citq-contact-grid span, .citq-contact-grid strong, .citq-contact-grid a { display: block; }
.citq-contact-grid span { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.citq-contact-grid strong, .citq-contact-grid a { overflow-wrap: anywhere; color: #f8fafc; font-size: 14px; }
.citq-contact-grid a { color: #7dd3fc; }
.citq-map-shell { position: relative; height: 310px; overflow: hidden; border: 1px solid #29405f; border-radius: 15px; background: #081424; }
.citq-map-shell iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.map-placeholder { height: 100%; display: grid; place-items: center; color: var(--muted); }
.citq-action-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.citq-loading-card { padding: 42px; text-align: center; border: 1px dashed var(--border); border-radius: 17px; color: var(--muted); }

/* Emergency command center */
body.emergency-page {
  background:
    radial-gradient(circle at 50% -10%, rgba(239, 51, 77, .38), transparent 36%),
    linear-gradient(145deg, #21040a, #0b0710 52%, #05070d);
}
body.emergency-page .topbar { background: rgba(25, 2, 7, .96); border-bottom: 3px solid var(--danger); box-shadow: 0 0 30px rgba(239, 51, 77, .28); }
body.emergency-page .container { width: min(1320px, 96%); }
.emergency-command-header {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  margin-bottom: 18px;
  padding: 25px 28px;
  border: 3px solid #ff6b7e;
  border-radius: 22px;
  background: linear-gradient(110deg, #790c1e, #bd1736 52%, #520713);
  box-shadow: 0 0 45px rgba(239, 51, 77, .42), inset 0 0 35px rgba(0,0,0,.22);
}
.emergency-command-header::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.12), transparent); transform: translateX(-100%); animation: sweep 2.5s infinite; }
.emergency-command-header > * { position: relative; z-index: 1; }
.emergency-beacon { font-size: 64px; filter: drop-shadow(0 0 15px #fff); animation: beacon .7s infinite alternate; }
.emergency-kicker { color: #fecdd3; font-size: 12px; font-weight: 950; letter-spacing: .15em; }
.emergency-command-header h1 { margin: 7px 0 8px; font-size: clamp(31px, 4vw, 54px); line-height: .98; letter-spacing: -.04em; text-transform: uppercase; }
.emergency-command-header p { max-width: 720px; margin: 0; color: #fff; font-size: 16px; }
.emergency-clock-wrap { min-width: 170px; padding: 14px 18px; text-align: center; border: 1px solid rgba(255,255,255,.28); border-radius: 15px; background: rgba(0,0,0,.34); }
.emergency-clock-wrap span { display: block; color: #fecdd3; font-size: 11px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.emergency-clock-wrap strong { display: block; margin-top: 5px; font: 950 29px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.emergency-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin: 18px 0; }
.emergency-metrics > div { min-height: 104px; padding: 17px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border: 1px solid #475569; border-top: 5px solid #94a3b8; border-radius: 16px; background: #141923; }
.emergency-metrics > div.danger { border-top-color: var(--danger); background: #3d0912; }
.emergency-metrics > div.warning { border-top-color: var(--warning); background: #392106; }
.emergency-metrics > div.success { border-top-color: var(--success); background: #092c19; }
.emergency-metrics span { max-width: 130px; color: #cbd5e1; font-size: 11px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.emergency-metrics strong { font-size: 42px; }
.emergency-roster { border: 2px solid #ef334d; background: rgba(9, 10, 16, .97); box-shadow: 0 0 32px rgba(239, 51, 77, .19); }
.emergency-roster .section-eyebrow { color: #fb7185; }
.emergency-person { border-left: 7px solid transparent; }
.emergency-person.status-missing td { background: rgba(109, 12, 27, .42); }
.emergency-person.status-missing { border-left-color: var(--danger); }
.emergency-person.status-inside td { background: rgba(107, 58, 4, .4); }
.emergency-person.status-inside { border-left-color: var(--warning); }
.emergency-person.status-evacuated td { background: rgba(11, 72, 39, .37); }
.emergency-person.status-evacuated { border-left-color: var(--success); }
.emergency-person.status-cared td { background: rgba(17, 57, 128, .36); }
.emergency-person.status-cared { border-left-color: #60a5fa; }
.person-priority { display: block; width: max-content; margin-top: 6px; padding: 3px 7px; border-radius: 999px; color: #fecdd3; background: #7f1022; font-size: 10px; font-weight: 950; letter-spacing: .07em; }
.status-evacuated .person-priority, .status-cared .person-priority { color: #bbf7d0; background: #14532d; }
.emergency-status-select { min-height: 48px; border-width: 2px; font-weight: 850; }
.emergency-status-select.status-missing { border-color: #fb7185; background: #410a14; }
.emergency-status-select.status-inside { border-color: #f59e0b; background: #382005; }
.emergency-status-select.status-evacuated { border-color: #22c55e; background: #092d19; }
.emergency-status-select.status-cared { border-color: #60a5fa; background: #102655; }

.login-wrap { max-width: 490px; margin: 65px auto; }
.hero { padding: 70px 20px; text-align: center; }
.hero h1 { margin: 0 0 12px; font-size: clamp(36px, 6vw, 56px); }
.hero p { color: var(--muted); font-size: 18px; }

@keyframes softPulse { to { box-shadow: 0 0 20px rgba(244, 63, 94, .55); } }
@keyframes emergencyGlow { to { box-shadow: 0 0 26px rgba(239, 51, 77, .38); } }
@keyframes beacon { from { transform: scale(.92); opacity: .75; } to { transform: scale(1.1); opacity: 1; } }
@keyframes sweep { to { transform: translateX(100%); } }

@media (max-width: 930px) {
  .live-status { grid-template-columns: 1fr; }
  .live-status-details { justify-content: flex-start; flex-wrap: wrap; }
  .live-status-control .btn { width: 100%; }
  .emergency-command-header { grid-template-columns: auto 1fr; }
  .emergency-clock-wrap { grid-column: 1 / -1; }
  .emergency-metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar-inner { min-height: auto; padding: 12px 0; align-items: flex-start; }
  .brand small { display: none; }
  .main-nav { gap: 4px; }
  .main-nav > a:not(.logout-link) { display: none; }
  .user-chip { font-size: 12px; }
  .container { margin-top: 22px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading .btn { width: 100%; }
  .heading-summary { width: 100%; display: flex; align-items: center; justify-content: center; gap: 7px; }
  .heading-summary strong { font-size: 22px; }
  .site-grid { grid-template-columns: 1fr; }
  .site-card-actions { flex-direction: column; }
  .site-card-actions .btn { width: 100%; }
  .row { grid-template-columns: 1fr; }
  .citq-toolbar-bottom { align-items: flex-start; flex-direction: column; }
  .citq-contact-grid { grid-template-columns: 1fr 1fr; }
  .citq-map-shell { height: 250px; }
  .citq-action-row { flex-direction: column; }
  .citq-action-row .btn { width: 100%; }
  .emergency-command-header { grid-template-columns: 1fr; padding: 19px; text-align: center; }
  .emergency-beacon { font-size: 51px; }
  .emergency-command-header h1 { font-size: 29px; }
  .emergency-metrics { grid-template-columns: 1fr; }
  .emergency-metrics > div { min-height: 80px; }
  .emergency-roster .table-wrap { overflow: visible; border: 0; }
  .emergency-roster table, .emergency-roster tbody, .emergency-roster tr, .emergency-roster td { display: block; width: 100%; }
  .emergency-roster thead { display: none; }
  .emergency-roster tr { overflow: hidden; margin-bottom: 12px; padding: 14px; border: 1px solid #5b2630; border-left-width: 7px; border-radius: 15px; }
  .emergency-roster td { padding: 6px 0; border: 0; background: transparent !important; }
  .emergency-roster td::before { content: attr(data-label); display: block; margin-bottom: 2px; color: #94a3b8; font-size: 9px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
  .emergency-roster td:last-child { margin-top: 8px; }
  .panel-heading-row { align-items: flex-start; flex-direction: column; }
  .print-button { width: 100%; }
}

@media (max-width: 480px) {
  .container, .topbar-inner { width: 92%; }
  .brand strong { font-size: 16px; }
  .user-chip { display: none; }
  .site-card-new { padding: 19px; }
  .site-card-metrics { grid-template-columns: 1fr; }
  .citq-card-summary { padding: 14px; }
  .citq-summary-text strong { font-size: 15px; }
  .citq-summary-text small { font-size: 12px; }
  .citq-contact-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, footer, .live-status-control, .print-button { display: none !important; }
  body, body.emergency-page { background: #fff; color: #000; }
  .panel, .emergency-roster, .emergency-command-header { box-shadow: none; background: #fff; color: #000; border-color: #000; }
  .emergency-person td { background: #fff !important; color: #000; }
}
