/* Anything hidden stays hidden, whatever its other styles (buttons and links set their own display). */
[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5f6b7a;
  --border: #dde1e7;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --ok: #2e7d32;
  --ok-soft: #e8f5e9;
  --warn: #a15c00;
  --warn-soft: #fff4e0;
  --radius: 10px;
  /* Alarm and safety colours stay the same in dark mode, so white text on them is always readable (AA). */
  --alarm-danger: #c62828;
  --alarm-warn: #a15c00;
  --alarm-ok: #2e7d32;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6e9ee;
    --muted: #9aa5b3;
    --border: #2d3540;
    --accent: #5b9bf0;
    --accent-text: #0d1117;
    --danger: #ef5350;
    --danger-soft: #3a1d1d;
    --ok: #66bb6a;
    --ok-soft: #1c3320;
    --warn: #ffb74d;
    --warn-soft: #3a2c15;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .who { color: var(--muted); font-size: .9rem; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 460px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: auto; }

/* Pop-up forms (such as starting a support visit in the master panel). */
dialog { width: min(520px, calc(100vw - 32px)); border: none; border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; font: inherit; font-weight: 600; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--alarm-danger); border-color: var(--alarm-danger); color: #fff; }
button.ok { background: var(--alarm-ok); border-color: var(--alarm-ok); color: #fff; }
button.big, .button.big { width: 100%; padding: 18px; font-size: 1.15rem; }
button.small { padding: 5px 10px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }

.msg { padding: 10px 12px; border-radius: 8px; margin-top: 12px; font-size: .95rem; }
.msg:empty { display: none; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--warn-soft); color: var(--warn); }
.msg.success { background: var(--ok-soft); color: var(--ok); }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }

.status-pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
}
.status-pill.on { background: var(--ok-soft); color: var(--ok); }
.status-pill.off { background: var(--border); color: var(--muted); }
.status-pill.missing { background: var(--danger-soft); color: var(--danger); }
.status-pill.stale { background: var(--warn-soft); color: var(--warn); }

.big-status { text-align: center; padding: 24px 16px; }
.big-status .state { font-size: 1.6rem; font-weight: 800; }

.alarm {
  background: var(--alarm-danger); color: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  animation: pulse 1.6s ease-in-out infinite;
}
.alarm.drill { background: var(--alarm-warn); animation: none; }
.alarm h2 { margin: 0 0 4px; }
.alarm button { background: #fff; color: var(--alarm-danger); border-color: #fff; }
.alarm.drill button { color: var(--alarm-warn); }
/* Lockdown: a dark, still screen that doesn't light up a hiding place. */
.alarm.lockdown { background: #111; color: #ddd; animation: none; }
.alarm.lockdown button { background: #333; color: #fff; border-color: #555; }
.alarm.lockdown button.help { background: #7a1010; border-color: #a33; }
@keyframes pulse { 50% { filter: brightness(1.15); } }
@media (prefers-reduced-motion: reduce) { .alarm { animation: none; } }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table-wrap { overflow-x: auto; }

nav.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
nav.tabs button {
  border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted); white-space: nowrap;
}
nav.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.stat .n { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.bad .n { color: var(--danger); }
.stat.good .n { color: var(--ok); }

.map { height: 480px; border-radius: var(--radius); border: 1px solid var(--border); }
.map.short { height: 320px; }

.hidden { display: none !important; }
#print-area { display: none; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .map { height: 360px; }
}

@media print {
  body { background: #fff; color: #000; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; padding: 0; }
  #print-area table { font-size: 11pt; }
  #print-area th, #print-area td { border-bottom: 1px solid #999; color: #000; }
  .tick { display: inline-block; width: 14px; height: 14px; border: 1.5px solid #000; }
}

/* A checkbox with its label beside it (sign-up Terms). */
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: normal; margin-top: 12px; }
label.check input { width: auto; margin-top: 3px; }

/* An organisation ID (such as K7M-42Q), styled so it can't be mistaken for part of a name. */
.org-id { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  letter-spacing: 0.05em; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--accent);
  color: var(--accent); background: transparent; white-space: nowrap; }

/* An organisation's own logo: never on alarm screens, which stay plain. */
.org-logo { max-height: 32px; max-width: 160px; object-fit: contain; vertical-align: middle; margin-right: 8px; }
.org-logo.big { max-height: 72px; max-width: 280px; margin: 0 0 12px; display: block; }

/* An email box with the organisation's domain already filled in (join page). */
.email-split.joined { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.email-split.joined:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.email-split.joined input { border: none; border-radius: 8px 0 0 8px; min-width: 0; flex: 1; }
.email-split.joined input:focus { outline: none; }
.email-domain { display: flex; align-items: center; padding: 0 12px; font-weight: 600; color: var(--muted);
  border-left: 1px solid var(--border); white-space: nowrap; border-radius: 0 8px 8px 0; background: var(--surface); }
/* A visitor's photo in the dashboard lists: tap to see it larger. */
button.vphoto { width: 40px; height: 40px; padding: 0; border-radius: 50%; overflow: hidden; flex: none; border: 2px solid var(--border); }
button.vphoto img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Ending a roll call: three plain answers, keeping it open first. */
.end-dialog { border: none; border-radius: 12px; padding: 20px; background: var(--surface); color: var(--text); max-width: 440px; width: calc(100% - 32px); }
.end-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.end-dialog h2 { margin: 0 0 8px; }
.end-missing { font-weight: 700; margin: 0 0 12px; }
.end-missing.warn { color: var(--danger); }
.end-text { margin: 0 0 16px; padding: 10px 12px; border-left: 3px solid var(--border); background: var(--bg); border-radius: 4px; }
.end-actions { display: grid; gap: 8px; }
.end-actions button { width: 100%; }
/* During a lockdown the whole page goes dark and dim, whatever the phone's setting, so a screen doesn't light up a
   hiding place. Pages add the "lockdown" class to <body>. */
body.lockdown {
  --bg: #050608; --surface: #0d0f12; --text: #a9b0ba; --muted: #6d7580; --border: #1c2027;
  --accent: #4f7fc4; --accent-text: #000; --danger: #b5413e; --danger-soft: #1d0e0e; --ok: #4f9a55; --ok-soft: #0f1a10;
  --warn: #b98a3a; --warn-soft: #1a140a; color-scheme: dark; background: var(--bg); color: var(--text);
}
body.lockdown img { filter: brightness(0.6); }
/* On the check-in page only the alarm stays: no status, check-out button or map to tap by mistake. */
body.lockdown.staff-page main > :not(#alarm):not(#offline) { display: none; }
.start-warning { margin: -20px -20px 14px; padding: 10px 20px; background: var(--alarm-danger); color: #fff; font-weight: 800;
  letter-spacing: .04em; text-transform: uppercase; border-radius: 12px 12px 0 0; }
.start-warning.drill { background: var(--alarm-warn); }
.stale-banner { background: var(--alarm-danger); color: #fff; font-weight: 700; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.delivery-strip { background: var(--warn-soft, #fff3cd); color: var(--text, #1a1a1a); border: 1px solid var(--warn, #b7791f);
  border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; font-weight: 600; }
body.lockdown .delivery-strip { background: #2a2410; color: #e8dcb0; border-color: #5a4a14; }
.help-strip { background: var(--alarm-danger); color: #fff; font-weight: 800; font-size: 1.1rem; padding: 12px 14px;
  border-radius: var(--radius); margin-bottom: 12px; }
body.lockdown .help-strip { background: #5a1414; color: #e8c9c9; }
.person-dialog hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.person-dialog h3 { margin: 0 0 4px; font-size: 1rem; }
.warn-text { color: var(--warn); }
.kiosk-qr { background: #fff; display: inline-block; padding: 8px; border-radius: 8px; margin: 10px 0; }
.kiosk-qr svg { display: block; width: 220px; height: 220px; }
.link-button { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font: inherit; cursor: pointer; min-height: 0; }
.all-clear { border: 2px solid var(--alarm-ok); background: var(--ok-soft); }
.all-clear h2 { color: var(--ok); }
/* Set-up forms that fold away under the people list on the Staff tab. */
details.add-section > summary { cursor: pointer; list-style: none; }
details.add-section > summary::-webkit-details-marker { display: none; }
details.add-section > summary h2 { display: inline; margin: 0; }
details.add-section > summary::before { content: "▸ "; color: var(--muted); }
details.add-section[open] > summary::before { content: "▾ "; }
details.add-section[open] > summary { margin-bottom: 12px; }
.getting-started { border: 2px solid var(--accent); }
.gs-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.gs-list li { display: flex; gap: 10px; align-items: baseline; }
.gs-list li.done { color: var(--muted); text-decoration: line-through; }
.gs-list li > span:first-child { width: 1.2em; font-weight: 700; color: var(--accent); }
.gs-list li.done > span:first-child { color: var(--ok); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* S38: errors from buttons, without blocking the page. */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100; max-width: min(560px, calc(100vw - 32px));
  background: var(--alarm-danger, #c62828); color: #fff; padding: 12px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3); cursor: pointer; }

/* Sections within a tab (Site, Visitors): a row of buttons that wraps onto a second line on a phone, never hidden sideways. */
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.subtabs button { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: .95rem; }
.subtabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text, #fff); }
.subtabs button[hidden] { display: none !important; }

/* Unsaved changes: Save and Discard at the bottom of the screen while the changed form is showing. */
.save-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 90; display: flex; gap: 12px;
  align-items: center; justify-content: space-between; flex-wrap: wrap; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-radius: 12px; padding: 10px 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3); font-weight: 600; }
.save-bar-actions { display: flex; gap: 8px; margin-left: auto; }
/* The toast sits above the save bar when both show. */
.save-bar:not(.hidden) ~ .toast { bottom: 96px; }

/* Getting started folds to one line on a phone. */
.gs-toggle { all: unset; cursor: pointer; font: inherit; }
.gs-toggle .muted { font-weight: 400; font-size: .9em; }
@media (max-width: 640px) {
  .getting-started:not(.open) .gs-body { display: none; }
  .gs-toggle::after { content: ' ▸'; }
  .getting-started.open .gs-toggle::after { content: ' ▾'; }
  /* The main tabs stay at the top of the screen while scrolling, and fade at the edge to show there are more. */
  nav.tabs { position: sticky; top: 0; z-index: 40; background: var(--bg); margin-left: -16px; margin-right: -16px;
    padding: 0 16px; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent); }
  nav.tabs.at-end { -webkit-mask-image: none; mask-image: none; }
}
