/* Night Watch - application styles */
:root {
    --navy: #0f2742;
    --navy-2: #163556;
    --blue: #1565c0;
    --blue-2: #0d47a1;
    --blue-soft: #e3effc;
    --green: #2e7d32;
    --green-soft: #e8f5e9;
    --amber: #f9a825;
    --amber-soft: #fff8e1;
    --red: #d32f2f;
    --red-2: #b71c1c;
    --red-soft: #fdecea;
    --text: #1c2733;
    --muted: #64748b;
    --line: #dde3ea;
    --bg: #f3f6f9;
    --card: #ffffff;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 39, 66, .08), 0 4px 14px rgba(15, 39, 66, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: .85em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.wrap { word-break: break-all; }
.inline { display: inline; }
pre.code {
    background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 8px;
    overflow-x: auto; white-space: pre-wrap; word-break: break-all; font-size: .85rem;
}
details pre.code { margin: 6px 0 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
    background: #e2e8f0; color: var(--text); min-height: 40px;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-2); }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; border-color: var(--line); color: var(--text); }
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: #eef2f6; }
.btn-ghost-light { background: transparent; color: #cfe0f5; border: 1px solid rgba(255,255,255,.25); }
.btn-small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-large { padding: 13px 18px; font-size: 1.05rem; }
.btn-xl { padding: 18px 24px; font-size: 1.2rem; width: 100%; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- Forms ---------- */
.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .9rem; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea,
.filters input, .filters select, .inline-form input {
    display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
    font: inherit; font-weight: 400; color: var(--text);
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form textarea { resize: vertical; min-height: 70px; }
.form input:focus, .form select:focus, .form textarea:focus, .filters input:focus, .filters select:focus {
    outline: 2px solid var(--blue-soft); border-color: var(--blue);
}
.form label.check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 4px; margin: 0 0 16px; }
.form legend { font-weight: 700; padding: 0 6px; }
.form h2 { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.form h2:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-inline label { margin: 0; }
.filters {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
    background: var(--card); padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px;
}
.filters label { font-size: .8rem; font-weight: 600; color: var(--muted); min-width: 130px; flex: 0 1 170px; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { margin: 0; padding: 6px 8px; min-width: 120px; }

/* ---------- Flash / badges ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; border-left: 4px solid; }
.flash-success { background: var(--green-soft); border-color: var(--green); color: #1b5e20; }
.flash-error { background: var(--red-soft); border-color: var(--red); color: var(--red-2); }
.flash-warning { background: var(--amber-soft); border-color: var(--amber); color: #7a5300; }
.flash-info { background: var(--blue-soft); border-color: var(--blue); color: var(--blue-2); }
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700;
    background: #e2e8f0; color: #334155; white-space: nowrap; text-transform: none;
}
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--amber-soft); color: #8a5a00; }
.badge-danger { background: var(--red); color: #fff; }
.badge-blue { background: var(--blue-soft); color: var(--blue-2); }
.level-info { background: #e2e8f0; color: #334155; }
.level-notice { background: var(--blue-soft); color: var(--blue-2); }
.level-warning { background: var(--amber-soft); color: #8a5a00; }
.level-alert, .level-error { background: var(--red); color: #fff; }
.level-security { background: #4a148c; color: #fff; }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
.table tr.row-alert td { background: var(--red-soft); }
.table tr.row-muted td { color: var(--muted); }
.table-logs td { font-size: .85rem; }
.ua { display: inline-block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.pagination { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.pagination a, .pagination span { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); text-decoration: none; font-size: .85rem; }
.pagination .current { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- Manager layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px; flex: 0 0 230px; background: var(--navy); color: #cfe0f5;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; }
.brand small { display: block; font-size: .7rem; color: #9fb7d3; line-height: 1.2; }
.sidebar nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; }
.sidebar nav a { color: #cfe0f5; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-weight: 500; }
.sidebar nav a:hover { background: var(--navy-2); color: #fff; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.sidebar-foot { padding: 12px 16px; font-size: .75rem; color: #7f99b8; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: #fff;
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-weight: 600; font-size: .9rem; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--navy); }
.content { padding: 20px 22px 40px; max-width: 1400px; width: 100%; }
.logo-img { width: 40px; height: 40px; flex: 0 0 40px; }

/* Dashboard */
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 8px; }
.dash-head p { margin: 0; }
.dash-clock { text-align: right; }
.dash-clock span { display: block; color: var(--muted); font-size: .85rem; }
.dash-clock strong { font-size: 1.8rem; color: var(--navy); }
.dash-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; border-left: 5px solid; }
.stats-3 { grid-template-columns: repeat(3, 1fr); }
.stat-num { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat-blue { border-color: var(--blue); }
.stat-green { border-color: var(--green); }
.stat-red { border-color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.dash-grid.no-map { grid-template-columns: 1fr; }
.dash-grid > .card { margin-bottom: 16px; }
.team-map { height: 300px; border-radius: 8px; background: #e8eef4; }
.alerts-card { border: 2px solid var(--red); animation: pulse-border 1.6s infinite; }
.alerts-card h2 { color: var(--red); }
.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; background: var(--amber-soft); }
.alert-item.alert-panic { background: var(--red-soft); }
.alert-item.alert-panic strong { color: var(--red); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid #eef2f6; font-size: .9rem; }
.activity-time { font-weight: 700; color: var(--muted); min-width: 44px; }
.activity li.level-alert span:last-child { color: var(--red); font-weight: 600; }
@keyframes pulse-border { 0%, 100% { box-shadow: 0 0 0 0 rgba(211,47,47,.35); } 50% { box-shadow: 0 0 0 8px rgba(211,47,47,0); } }

/* ---------- Watchman (mobile app) layout ---------- */
.layout-watchman { background: var(--bg); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.app-header {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20;
}
.app-title { flex: 1; min-width: 0; }
.app-title strong { display: block; }
.app-title small { display: block; font-size: .7rem; color: #9fb7d3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-main { max-width: 520px; margin: 0 auto; padding: 14px; }
.offline-banner { background: var(--amber); color: #3e2a00; text-align: center; padding: 8px 12px; font-weight: 600; font-size: .9rem; }
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #fff;
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { flex: 1; text-align: center; padding: 14px 4px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; }
.bottom-nav a.active { color: var(--blue); box-shadow: inset 0 3px 0 var(--blue); }

.countdown-card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); text-align: center; padding: 18px 14px; margin-bottom: 14px; border: 2px solid transparent; }
.countdown-label { color: var(--muted); font-weight: 600; font-size: .9rem; }
.countdown { font-size: 3.2rem; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; line-height: 1.1; }
.countdown-sub { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.countdown-card.is-due { border-color: var(--amber); background: var(--amber-soft); }
.countdown-card.is-due .countdown { color: #8a5a00; }
.countdown-card.is-overdue { border-color: var(--red); background: var(--red-soft); animation: pulse-border 1.2s infinite; }
.countdown-card.is-overdue .countdown, .countdown-card.is-overdue .countdown-sub { color: var(--red); font-weight: 700; }

.checkin-btn, .panic-btn, .signoff-btn {
    display: flex; align-items: center; gap: 16px; width: 100%; border: 0; cursor: pointer; text-align: left;
    font: inherit; border-radius: 18px; -webkit-tap-highlight-color: transparent;
}
.checkin-btn { background: var(--blue); color: #fff; padding: 26px 22px; box-shadow: 0 8px 22px rgba(21,101,192,.35); margin-bottom: 12px; min-height: 110px; }
.checkin-btn:active { transform: scale(.98); }
.checkin-btn.is-busy { opacity: .75; }
.checkin-btn strong, .panic-btn strong, .signoff-btn strong { display: block; font-size: 1.35rem; }
.checkin-btn small, .panic-btn small, .signoff-btn small { display: block; font-size: .9rem; opacity: .9; }
.checkin-icon { flex: 0 0 56px; height: 56px; border-radius: 50%; border: 3px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 800; }
.meta-row { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.queue-status { background: var(--amber-soft); color: #7a5300; border-radius: 8px; padding: 8px 12px; font-weight: 600; font-size: .9rem; margin-bottom: 10px; }
.danger-zone { margin: 26px 0 18px; padding-top: 18px; border-top: 2px dashed var(--line); }
.panic-btn { background: var(--red-soft); color: var(--red-2); border: 2px solid var(--red); padding: 16px 20px; }
.panic-btn:active { background: var(--red); color: #fff; }
.panic-icon { flex: 0 0 44px; height: 44px; border-radius: 50%; background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 900; }
.call-btn { margin-top: 10px; }
.signoff-btn { background: #fff; color: var(--navy); border: 2px solid var(--line); padding: 14px 20px; display: block; }
.signoff-btn strong { font-size: 1.05rem; }
.team-alerts { margin-bottom: 4px; }
.team-alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 10px; font-weight: 700; color: #fff; background: #e65100; }
.team-alert-panic { background: var(--red); animation: pulse-border 1.2s infinite; }
.notify-card { border: 2px solid var(--blue); }
.install-banner { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.install-banner p { margin: 0 0 8px; }
.install-banner .btn-row { margin-top: 4px; }
.code-input { font-size: 1.6rem !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-img { width: 220px; height: 220px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.secret-key code { font-size: 1.05rem; letter-spacing: .05em; word-break: break-all; }
.recovery-codes { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.recovery-codes code { display: block; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-size: 1rem; text-align: center; }
.form label.option { align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.form label.option input { margin-top: 4px; }
.health-list { list-style: none; margin: 0; padding: 0; }
.health-list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid #eef2f6; }
.health-list .badge { min-width: 64px; text-align: center; margin-top: 2px; }
.kv-table th { text-transform: none; letter-spacing: 0; font-size: .9rem; color: var(--text); font-weight: 500; white-space: normal; width: 60%; }
.kv-table td { font-weight: 700; }
.name-list { margin: 4px 0 12px; padding-left: 18px; }
.card h3 { margin-top: 14px; }
.reset-mfa { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
@media print {
    .sidebar, .topbar, .btn-row, .bottom-nav, .app-header { display: none !important; }
    .card { box-shadow: none; }
}
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { padding: 9px 0; border-bottom: 1px solid #eef2f6; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }

/* ---------- Public (login / install) ---------- */
.layout-public { background: linear-gradient(160deg, var(--navy) 0%, #1d4a7a 100%); min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 26px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card-wide { max-width: 720px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-brand strong { display: block; font-size: 1.2rem; color: var(--navy); }
.auth-brand small { display: block; color: var(--muted); font-size: .8rem; }
.auth-links { text-align: center; margin: 14px 0 6px; }
.checklist { list-style: none; padding: 0; columns: 2; }
.checklist .ok { color: var(--green); }
.checklist .fail { color: var(--red); font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
    .menu-toggle { display: block; }
    .topbar { padding: 10px 14px; }
    .user-chip { display: none; }
    .content { padding: 14px 14px 40px; }
    .stats, .stats-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .checklist { columns: 1; }
}
