/* FireGuard dashboard: light theme.
   Status colours (green / red / grey / amber) always appear with an icon and a text label, never as colour alone. */

:root {
    color-scheme: light;

    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-sunken: #f1f4f9;
    --ink: #0f172a;
    --ink-2: #475569;
    --ink-muted: #94a3b8;
    --hairline: #e8ecf3;
    --baseline: #cbd5e1;
    --border: #e2e8f0;

    --accent: #2a78d6;
    --accent-hover: #256abf;
    --accent-soft: #e8f1fc;
    --series-1: #2a78d6;      /* blue: default chart series, false alarms */
    --series-fire: #eb6834;   /* orange: fire alarms */

    --good: #0ca30c;
    --good-soft: #e6f6e6;
    --good-text: #0a7a0a;
    --warning: #fab219;
    --warning-soft: #fff4d6;
    --warning-text: #8a5d00;
    --critical: #d03b3b;
    --critical-soft: #fdeaea;
    --offline: #7c8aa0;
    --offline-soft: #eceff4;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-menu: 0 12px 40px rgba(15, 23, 42, 0.18);
    --radius: 16px;
    --header-height: 64px;

    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; font-weight: 650; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.hint { color: var(--ink-2); font-size: 0.85rem; margin: 4px 0 8px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.optional { color: var(--ink-2); font-weight: 400; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.inline-form { display: inline; margin: 0; }
.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.empty { color: var(--ink-2); padding: 12px 0; }

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.icon--small { width: 0.95em; height: 0.95em; }

/* ---------- Header ---------- */

.topbar {
    position: sticky; top: 0; z-index: 1000;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1320px; margin: 0 auto; padding: 0 20px; min-height: var(--header-height);
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; column-gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; justify-self: start; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #ff9f43 0%, #ee5a24 55%, #d63031 100%);
    box-shadow: 0 4px 12px rgba(238, 90, 36, 0.35);
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand-name { font-size: 1.15rem; font-weight: 750; letter-spacing: -0.02em; }

.nav { display: flex; align-items: center; gap: 4px; justify-self: center; }
.nav-link {
    padding: 8px 16px; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.nav-link:hover { background: var(--surface-sunken); color: var(--ink); }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent); }

.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; justify-self: end; }

.icon-button {
    position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent; background: transparent;
    color: var(--ink-2); display: grid; place-items: center; cursor: pointer;
}
.icon-button:hover, .icon-button[aria-expanded="true"] { background: var(--surface-sunken); color: var(--ink); }
.icon-button .icon { width: 21px; height: 21px; }
.nav-toggle { display: none; }
.badge {
    position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--critical); color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 18px; text-align: center;
    box-shadow: 0 0 0 2px #fff;
}

.user-button {
    display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid transparent;
    background: transparent; color: var(--ink); cursor: pointer; font: inherit;
}
.user-button:hover, .user-button[aria-expanded="true"] { background: var(--surface-sunken); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 0.85rem;
    background: linear-gradient(135deg, #5598e7, #2a78d6 60%, #4f46e5);
}
.avatar--large { width: 72px; height: 72px; font-size: 1.5rem; }
.user-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; text-align: left; }
.user-name { font-weight: 650; font-size: 0.9rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--ink-2); font-size: 0.75rem; text-transform: capitalize; }

.menu { position: relative; }
.menu-panel {
    position: absolute; right: 0; top: calc(100% + 10px); min-width: 230px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow-menu); padding: 6px; z-index: 1100;
}
.menu-panel--wide { width: 380px; max-width: calc(100vw - 24px); padding: 0; overflow: hidden; }
.menu-title { padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--hairline); display: flex; justify-content: space-between; }
.menu-title .muted { font-weight: 500; font-size: 0.85rem; }
.menu-header { display: flex; flex-direction: column; padding: 10px 12px 12px; border-bottom: 1px solid var(--hairline); margin-bottom: 6px; }
.menu-header .muted { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 10px; border: 0; background: transparent;
    color: var(--ink); font: inherit; font-weight: 550; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover { background: var(--surface-sunken); }
.menu-item--danger { color: var(--critical); }
.menu-item--danger:hover { background: var(--critical-soft); }

.notification-list { max-height: 420px; overflow-y: auto; }
.notification { display: flex; gap: 12px; padding: 12px 16px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--hairline); }
.notification:last-child { border-bottom: 0; }
.notification:hover { background: var(--surface-sunken); }
.notification-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.notification--critical .notification-icon { background: var(--critical-soft); color: var(--critical); }
.notification--warning .notification-icon { background: var(--warning-soft); color: var(--warning-text); }
.notification--info .notification-icon { background: var(--offline-soft); color: var(--offline); }
.notification-title { font-weight: 650; font-size: 0.92rem; }
.notification-detail { color: var(--ink-2); font-size: 0.82rem; }
.notification-list .empty { padding: 28px 16px; text-align: center; }

/* ---------- Layout ---------- */

.container { max-width: 1320px; margin: 0 auto; padding: 28px 20px 64px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .muted { margin: 4px 0 0; }
.page-head-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.page-head-tools .muted { margin: 0; }
.back-link { display: inline-block; margin-bottom: 6px; font-size: 0.9rem; text-decoration: none; font-weight: 550; }
.section-title { margin: 8px 0 12px; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { min-height: 34px; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card > h2 { margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.card-empty { padding: 20px; }

.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; margin-bottom: 20px; }
.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
@media (max-width: 960px) { .grid-main, .grid-two { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Summary cards ---------- */

.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }

.stat {
    display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.stat-icon .icon { width: 24px; height: 24px; }
.stat--devices .stat-icon { background: var(--accent-soft); color: var(--accent); }
.stat--online .stat-icon { background: var(--good-soft); color: var(--good-text); }
.stat--offline .stat-icon { background: var(--offline-soft); color: var(--offline); }
.stat--alarm .stat-icon { background: var(--critical-soft); color: var(--critical); }
.stat--false .stat-icon { background: var(--warning-soft); color: var(--warning-text); }
.stat-body { display: flex; flex-direction: column; min-width: 0; }
.stat-value { font-size: 1.9rem; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--ink-2); font-size: 0.85rem; font-weight: 550; }
.stat--alarm.is-alarming { border-color: #f3b4b4; background: linear-gradient(180deg, #fff 0%, var(--critical-soft) 100%); }
.stat--alarm.is-alarming .stat-icon { background: var(--critical); color: #fff; }
@media (prefers-reduced-motion: no-preference) {
    .stat--alarm.is-alarming .stat-icon { animation: soft-pulse 1.8s ease-in-out infinite; }
}
@keyframes soft-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(208, 59, 59, 0.45); } 50% { box-shadow: 0 0 0 10px rgba(208, 59, 59, 0); } }

/* ---------- Status pills (icon + label, never colour alone) ---------- */

.pill {
    display: inline-flex; align-items: center; gap: 5px; flex: none; white-space: nowrap; padding: 3px 10px 3px 8px; border-radius: 999px;
    font-size: 0.78rem; font-weight: 650; vertical-align: middle; background: var(--offline-soft); color: var(--ink-2);
}
.pill--online { background: var(--good-soft); color: var(--good-text); }
.pill--alarm { background: var(--critical-soft); color: var(--critical); }
.pill--offline, .pill--never_connected { background: var(--offline-soft); color: var(--ink-2); }

/* ---------- Map ---------- */

.map { height: 440px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-sunken); z-index: 0; position: relative; }
.map--picker { height: 280px; margin-bottom: 12px; }
.map-notice {
    position: absolute; left: 12px; right: 12px; bottom: 30px; z-index: 500; background: #fff; border: 1px solid var(--baseline);
    border-left: 4px solid var(--warning); border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; box-shadow: var(--shadow);
}
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 0; font-size: 0.83rem; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--baseline); }
.dot--online { background: var(--good); }
.dot--alarm { background: var(--critical); }
.dot--offline { background: var(--offline); }
.square { display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--ink); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--baseline); }

/* Device pins are HTML markers so they can pulse when an alarm is active. */
.pin { position: relative; width: 22px; height: 22px; }
.pin-core {
    position: absolute; inset: 0; border-radius: 50%; background: var(--offline); border: 3px solid #fff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}
.pin--online .pin-core { background: var(--good); }
.pin--alarm .pin-core { background: var(--critical); }
.pin--picker .pin-core { background: var(--accent); }
.pin-pulse { display: none; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--critical); }
.pin--alarm .pin-pulse { display: block; }
@media (prefers-reduced-motion: no-preference) {
    .pin--alarm .pin-pulse { animation: pin-ring 1.6s ease-out infinite; }
}
@keyframes pin-ring { 0% { transform: scale(0.6); opacity: 0.9; } 100% { transform: scale(1.6); opacity: 0; } }
.station-marker {
    width: 16px; height: 16px; background: var(--ink); border: 2px solid #fff; border-radius: 4px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}
.leaflet-popup-content { font-family: var(--font); color: var(--ink); }
.leaflet-container { font-family: var(--font); }

/* ---------- Alarms ---------- */

.alarm-list { display: flex; flex-direction: column; gap: 10px; max-height: 440px; overflow-y: auto; padding-right: 2px; }
.alarm { border: 1px solid var(--border); border-left: 4px solid var(--baseline); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.alarm.is-open { border-left-color: var(--critical); }
.alarm--clickable { cursor: pointer; position: relative; }
.alarm--clickable:hover, .alarm--clickable:focus-visible { border-color: var(--critical); background: var(--critical-soft); }
.alarm.is-confirmed { background: var(--critical-soft); }
.alarm-title { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; font-weight: 650; }
.alarm-meta { color: var(--ink-2); font-size: 0.85rem; }
.alarm-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.alarm-actions input { flex: 1 1 140px; min-width: 0; }

/* ---------- Insight charts (horizontal bars) ---------- */

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0 14px; flex-wrap: wrap; }
.segmented { display: inline-flex; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow-sm); }
.segmented button {
    border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font: inherit; font-size: 0.85rem; font-weight: 600;
    color: var(--ink-2); cursor: pointer;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.hbars { display: flex; flex-direction: column; gap: 12px; min-height: 120px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) minmax(0, 1fr) 34px; align-items: center; gap: 12px; position: relative; }
.hbar-label { font-size: 0.9rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; background: var(--surface-sunken); border-radius: 6px; overflow: hidden; }
.hbar-fill { height: 100%; width: 0; background: var(--series-1); border-radius: 0 6px 6px 0; transition: width 0.5s ease; }
.hbar-fill--fire { background: var(--series-fire); }
.hbar-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.hbar:hover .hbar-track { background: var(--hairline); }
.hbar-tip {
    position: absolute; left: 34%; top: -30px; background: var(--ink); color: #fff; padding: 4px 9px; border-radius: 7px;
    font-size: 0.78rem; white-space: nowrap; pointer-events: none; z-index: 5;
}
.hbars-empty { display: grid; place-items: center; text-align: center; color: var(--ink-2); padding: 28px 8px; min-height: 120px; }
@media (prefers-reduced-motion: reduce) { .hbar-fill { transition: none; } }

.info-list { margin: 0; display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 8px 16px; }
.info-list dt { color: var(--ink-2); }
.info-list dd { margin: 0; word-break: break-word; }

.table-toggle { margin-top: 14px; }
.table-toggle summary { cursor: pointer; color: var(--ink-2); }
/* position: relative makes this the containing block of the visually hidden .sr-only header text;
   otherwise that text sits at the table's far edge and stretches the whole page sideways on a phone. */
.table-scroll { position: relative; overflow-x: auto; margin-top: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; color: var(--ink-2); font-weight: 650; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); padding: 10px 12px; white-space: nowrap; }
.table td { border-bottom: 1px solid var(--hairline); padding: 12px; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f8fafd; }
.table td.num { text-align: right; }
.cell-title { font-weight: 650; }
.cell-title a { color: var(--ink); text-decoration: none; }
.cell-title a:hover { color: var(--accent); }
.cell-sub { color: var(--ink-2); font-size: 0.82rem; }
.card--flush { padding: 0; overflow: hidden; }
.card--flush .table-scroll { margin-top: 0; }
.card--flush .table th:first-child, .card--flush .table td:first-child { padding-left: 20px; }
.card--flush .table th:last-child, .card--flush .table td:last-child { padding-right: 20px; }

.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 6px; }

/* ---------- Toolbar (Devices page) ---------- */

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-muted); pointer-events: none; }
.search input[type="search"] { padding-left: 40px; border-radius: 999px; }
.count-chip { color: var(--ink-2); font-size: 0.85rem; margin-left: auto; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
    border: 1px solid var(--baseline); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-sunken); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(42, 120, 214, 0.3); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--danger { border-color: var(--critical); color: var(--critical); }
.btn--danger:hover { background: var(--critical-soft); }
.btn--ghost { background: transparent; }
.btn--small { padding: 5px 11px; font-size: 0.85rem; border-radius: 8px; }
.btn--block { width: 100%; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"], input[type="search"], input[type="date"], select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--baseline); border-radius: 10px; background: #fff; color: var(--ink); font: inherit;
}
input:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--critical); }
.field-error { color: var(--critical); font-size: 0.85rem; margin: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.subform { background: var(--surface-sunken); border: 1px solid var(--hairline); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }

/* ---------- Pop-up forms (modals) ---------- */

html.has-modal { overflow: hidden; }

.modal {
    width: min(560px, calc(100vw - 32px)); max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px);
    padding: 0; border: 0; border-radius: 20px; overflow: hidden; background: var(--surface); color: var(--ink);
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.3), 0 2px 8px rgba(15, 23, 42, 0.08);
}
.modal--wide { width: min(960px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px); }

/* The header and footer stay in view; only the middle scrolls. */
.modal-form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.modal-head { display: flex; align-items: center; gap: 14px; flex: none; padding: 20px 22px 16px; border-bottom: 1px solid var(--hairline); }
.modal-icon { width: 44px; height: 44px; flex: none; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.modal-icon .icon { width: 22px; height: 22px; }
.modal-titles { flex: 1; min-width: 0; }
.modal-titles h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.modal-titles h2:focus { outline: none; } /* focused only so screen readers start on the title */
.modal-subtitle { margin: 2px 0 0; color: var(--ink-2); font-size: 0.86rem; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 22px 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex: none; padding: 14px 22px; border-top: 1px solid var(--hairline); background: var(--surface-sunken); }
.modal .notice { margin-bottom: 16px; }

.modal-section { border: 0; margin: 0 0 20px; padding: 0; min-width: 0; }
.modal-section legend { padding: 0; margin-bottom: 12px; color: var(--ink-2); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.modal-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 32px; }
.modal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.field--wide { grid-column: 1 / -1; }
.modal .field { margin-bottom: 12px; }
.modal .field .hint { margin: 2px 0 0; }
.modal .modal-section > .hint { margin: 0 0 10px; }
.modal .map--picker { height: 300px; margin-bottom: 14px; }
.modal-section .btn--small { margin-bottom: 8px; }

@media (max-width: 860px) {
    .modal-columns { grid-template-columns: minmax(0, 1fr); }
    .modal .map--picker { height: 260px; }
}

/* On a phone the form slides up from the bottom edge and uses the full width. */
@media (max-width: 560px) {
    .modal, .modal--wide { width: 100%; max-width: 100%; max-height: 94dvh; margin: auto 0 0; border-radius: 20px 20px 0 0; }
    .modal-form { max-height: 94dvh; }
    .modal-head { padding: 16px 16px 12px; gap: 12px; }
    .modal-icon { width: 38px; height: 38px; border-radius: 11px; }
    .modal-icon .icon { width: 19px; height: 19px; }
    .modal-body { padding: 16px 16px 4px; }
    .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
    .modal-foot .btn { flex: 1; }
    .modal-grid { grid-template-columns: minmax(0, 1fr); }
    .modal .map--picker { height: 220px; }
}

@media (prefers-reduced-motion: no-preference) {
    .modal[open] { animation: modal-in 0.2s ease-out; }
    .modal[open]::backdrop { animation: backdrop-in 0.2s ease-out; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 560px) {
    .modal[open] { animation-name: sheet-in; }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(48px); } to { transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Notices, toast ---------- */

.notice { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; border: 1px solid var(--border); background: var(--surface); border-left-width: 4px; }
.notice--success { border-left-color: var(--good); background: var(--good-soft); }
.notice--error { border-left-color: var(--critical); background: var(--critical-soft); }
.notice--warning { border-left-color: var(--warning); background: var(--warning-soft); }

.toast-region { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-menu); font-size: 0.9rem; }
.toast--error { background: var(--critical); }

/* A translucent red tint over the whole viewport (pointer-events: none, so the dashboard underneath
   stays visible and usable) with a solid, clickable panel docked near the top carrying the actual
   alarm list. The tint alone is what makes the "whole screen flashing red" impossible to miss without
   ever blocking the page it is warning about. */
@keyframes alarm-alert-pulse { 0%, 100% { background: rgba(208, 59, 59, 0.22); } 50% { background: rgba(176, 32, 32, 0.5); } }

.alarm-takeover {
    position: fixed; inset: 0; z-index: 3000; pointer-events: none;
    display: flex; flex-direction: column; align-items: center;
    padding: 16px 16px 0; animation: alarm-alert-pulse 1.2s ease-in-out infinite;
}
.alarm-takeover-panel {
    pointer-events: auto; width: 100%; max-width: 540px; margin-top: 8px; max-height: calc(100dvh - 32px);
    display: flex; flex-direction: column; gap: 12px; overflow: hidden;
    background: var(--critical); color: #fff; border-radius: 18px; padding: 16px 18px 18px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.45), 0 2px 8px rgba(15, 23, 42, 0.2);
}
.alarm-takeover-head { display: flex; align-items: center; gap: 10px; flex: none; }
.alarm-takeover-head > .icon { width: 26px; height: 26px; flex: none; }
.alarm-takeover-head h1 { font-size: 1.1rem; margin: 0; }
.alarm-takeover-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.alarm-takeover-item {
    display: flex; flex-direction: column; gap: 4px; background: rgba(255, 255, 255, 0.14);
    border: 2px solid rgba(255, 255, 255, 0.4); border-radius: 12px; padding: 12px 14px;
    color: #fff; text-align: left; justify-content: center;
}
.alarm-takeover-item strong { font-size: 1rem; }
.alarm-takeover-item span { opacity: 0.9; font-size: 0.9rem; }
.alarm-takeover-item:hover, .alarm-takeover-item:focus-visible { background: rgba(255, 255, 255, 0.24); }
@media (prefers-reduced-motion: reduce) { .alarm-takeover { animation: none; background: rgba(208, 59, 59, 0.32); } }

/* ---------- Pagination (audit log) ---------- */

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--hairline); flex-wrap: wrap; }
.pagination .muted { margin: 0; }
details > summary { cursor: pointer; }

/* ---------- Login / errors / profile ---------- */

.login-wrap { min-height: 72vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 420px; padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.25rem; margin-bottom: 6px; }
.login-title { font-size: 1.05rem; font-weight: 550; color: var(--ink-2); margin-bottom: 20px; }
.error-code { font-size: 3rem; font-weight: 750; margin: 0; color: var(--ink-muted); }

.profile-head { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.profile-head h2 { font-size: 1.3rem; }
.role-chip { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; font-weight: 700; text-transform: capitalize; }

/* ---------- Credentials page ---------- */

.credential-list { margin: 0 0 20px; display: flex; flex-direction: column; gap: 12px; }
.credential dt { color: var(--ink-2); font-size: 0.85rem; }
.credential dd { margin: 2px 0 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.credential code { background: var(--surface-sunken); padding: 7px 11px; border-radius: 8px; word-break: break-all; }
.code-block { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 0.85rem; margin: 0 0 10px; }
.steps { margin: 0 0 12px; padding-left: 1.3em; display: flex; flex-direction: column; gap: 10px; }
.credentials + .credentials { margin-top: 20px; }

/* ---------- Small screens: the menu folds under the header ---------- */

@media (max-width: 860px) {
    .topbar-inner { grid-template-columns: auto 1fr; row-gap: 0; padding: 8px 14px; }
    .nav-toggle { display: grid; }
    .nav {
        display: none; grid-column: 1 / -1; grid-row: 2; justify-self: stretch; flex-direction: column; align-items: stretch;
        gap: 2px; padding: 8px 0 10px; border-top: 1px solid var(--hairline); margin-top: 8px;
    }
    .nav.is-open { display: flex; }
    .nav-link { border-radius: 10px; }
    .user-text, .user-button .icon--small { display: none; }
    .container { padding: 20px 14px 56px; }
    .map { height: 340px; }
}
@media (prefers-reduced-motion: no-preference) {
    .btn, .nav-link, .icon-button { transition: background-color 0.15s ease, color 0.15s ease; }
}
