/* Monitoring – mobile-first UI, no framework */
:root {
    --bg: #0d1015;
    --surface: #151a21;
    --surface-2: #1c232c;
    --surface-3: #252e39;
    --border: #2a333f;
    --text: #e8edf3;
    --muted: #8a96a6;
    --accent: #38bdf8;
    --accent-ink: #04202c;
    --human: #fb923c;
    --vehicle: #a78bfa;
    --motion: #f87171;
    --danger: #ef4444;
    --ok: #22c55e;
    --radius: 14px;
    --radius-sm: 9px;
    --tap: 46px;
    --top-h: 56px;
    --tab-h: 62px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
small { color: var(--muted); font-weight: 400; }

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    height: calc(var(--top-h) + var(--safe-top));
    padding: var(--safe-top) 8px 0;
    background: rgba(13, 16, 21, .86);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar-title {
    flex: 1;
    font-size: 1.08rem;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-logo, .topbar-btn {
    display: inline-grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    border-radius: 50%;
    font-size: 1.3rem;
    flex: none;
}
.topbar-logo { color: var(--accent); }
.topbar-btn:active { background: var(--surface-3); }
.topbar-actions { display: flex; }

/* Page */
.page {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 14px 14px 24px;
}
.has-tabbar .page { padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 24px); }

/* Bottom tab bar */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    height: calc(var(--tab-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(21, 26, 33, .94);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--border);
}
.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 600;
}
.tabbar i { font-size: 1.35rem; }
.tabbar a.active { color: var(--accent); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: 600 .95rem var(--font);
    cursor: pointer;
    user-select: none;
    transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: #7dd3fc; }
.btn-danger { background: transparent; border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.btn-block { width: 100%; }
.btn.disabled { opacity: .35; pointer-events: none; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.actions-row .btn { flex: 1 1 140px; }

/* Flash and alerts */
.flash, .alert {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin: 12px 14px 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: .93rem;
}
.flash { background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .35); color: #bbf7d0; }
.alert { margin: 0 0 14px; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35); color: #fecaca; }
@media (min-width: 1068px) { .flash { max-width: 1012px; margin: 12px auto 0; } }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .filters select {
    width: 100%;
    min-height: var(--tap);
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font: 16px var(--font);
    appearance: none;
}
.field select, .filters select {
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 36px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field select:disabled { opacity: .6; }
.static { min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer;
}
.check input:checked + span { background: rgba(56, 189, 248, .14); border-color: var(--accent); color: var(--accent); }
.check input:focus-visible + span { outline: 2px solid var(--accent); }

.switch { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui {
    position: relative;
    flex: none;
    width: 46px;
    height: 28px;
    border-radius: 999px;
    background: var(--surface-3);
    transition: background .2s;
}
.switch-ui::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    transition: transform .2s;
}
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch input:disabled + .switch-ui { opacity: .5; }

/* Auth pages */
.page-auth .topbar { display: none; }
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth-logo {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 14px;
    border-radius: 22px;
    background: linear-gradient(140deg, #0ea5e9, #6366f1);
    font-size: 2rem;
    box-shadow: 0 10px 30px rgba(14, 165, 233, .25);
}
.auth-title { text-align: center; font-size: 1.35rem; margin-bottom: 20px; }

/* Cards and lists */
.card {
    margin-bottom: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.card-title { font-size: 1rem; margin-bottom: 14px; display: flex; gap: 8px; }
.card-sub { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 2px 10px; display: flex; gap: 8px; }

.profile { display: flex; align-items: center; gap: 12px; }
.profile strong { display: block; font-size: 1.05rem; }
.profile .muted { font-size: .88rem; }
.avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--muted);
    font-size: 1.15rem;
}
.avatar.admin { background: rgba(56, 189, 248, .15); color: var(--accent); }

.list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px; }
.row + .row { border-top: 1px solid var(--border); }
a.row:active { background: var(--surface-2); }
.row.inactive { opacity: .55; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row-sub { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; }
.row-go { color: var(--muted); }

/* Tags and chips */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--muted);
    font-size: .76rem;
    font-weight: 600;
    white-space: nowrap;
}
.tag-human { background: rgba(251, 146, 60, .15); color: var(--human); }
.tag-vehicle { background: rgba(167, 139, 250, .15); color: var(--vehicle); }
.tag-admin { background: rgba(56, 189, 248, .14); color: var(--accent); }
.tag-off { background: rgba(239, 68, 68, .14); color: #fca5a5; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-weight: 600;
    font-size: .9rem;
}
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Cameras */
.cams { display: grid; gap: 14px; }
.cam { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.cam-media { position: relative; display: block; aspect-ratio: 16 / 9; background: #000; }
.cam-media img { width: 100%; height: 100%; object-fit: cover; }
.cam-placeholder { display: grid; place-items: center; height: 100%; font-size: 2.4rem; color: var(--surface-3); }
.cam-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(6px);
    font-size: .8rem;
    font-weight: 700;
}
.cam-body { padding: 14px; }
.cam-title { font-size: 1.15rem; margin-bottom: 4px; }
.cam-meta { color: var(--muted); font-size: .9rem; display: flex; gap: 6px; }
.cam-actions { display: flex; gap: 10px; }
.cam-actions .btn { flex: 1; }

/* Day navigation */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.daynav-btn {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--tap);
    height: var(--tap);
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    font-size: 1.1rem;
}
.daynav-btn:active { background: var(--surface-3); }
.daynav-btn.disabled { opacity: .3; }
.daynav-label { flex: 1; text-align: center; display: flex; flex-direction: column; }
.daynav-label strong { font-size: 1.02rem; }
.daynav-label span { color: var(--muted); font-size: .85rem; }

/* 24h strip */
.strip { margin-bottom: 14px; cursor: pointer; touch-action: pan-y; }
.strip-track {
    position: relative;
    height: 40px;
    border-radius: var(--radius-sm);
    background:
        repeating-linear-gradient(90deg, transparent 0 calc(100% / 24 - 1px), rgba(255, 255, 255, .04) calc(100% / 24 - 1px) calc(100% / 24)),
        var(--surface);
    border: 1px solid var(--border);
    overflow: hidden;
}
.strip-seg { position: absolute; top: 8px; bottom: 8px; min-width: 3px; border-radius: 2px; background: var(--motion); }
.strip-seg.human { background: var(--human); top: 4px; bottom: 4px; }
.strip-seg.vehicle { background: var(--vehicle); }
.strip-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.strip-axis { display: flex; justify-content: space-between; padding: 4px 1px 0; color: var(--muted); font-size: .72rem; }

.day .chips { margin-bottom: 6px; }

/* Hour groups and clip rows */
.hour { scroll-margin-top: calc(var(--top-h) + var(--safe-top) + 10px); }
.hour-title {
    position: sticky;
    top: calc(var(--top-h) + var(--safe-top));
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 2px 8px;
    background: var(--bg);
    font-size: .95rem;
    font-variant-numeric: tabular-nums;
}
.hour-title span { padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: .75rem; }
.clips { display: grid; gap: 8px; }
.clip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    padding-right: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    scroll-margin-top: 120px;
}
.clip:active { background: var(--surface-2); }
.clip:target { border-color: var(--accent); }
.clip-thumb {
    position: relative;
    flex: none;
    display: grid;
    place-items: center;
    width: 128px;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-sm);
    background: #000;
    color: var(--surface-3);
    overflow: hidden;
}
.clip-thumb img { width: 100%; height: 100%; object-fit: cover; }
.clip-dur {
    position: absolute;
    right: 4px;
    bottom: 4px;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, .7);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
}
.clip-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.clip-info strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.clip-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.clip-play { font-size: 1.6rem; color: var(--muted); }

/* Clip player */
.page-clip .page { padding-top: 0; }
.player { margin: 0 -14px 12px; background: #000; }
.player video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.clipbar { display: flex; gap: 10px; margin-bottom: 6px; }
.clipbar .btn { flex: 1; }
.facts { margin: 8px 0 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; }
.facts div + div { border-top: 1px solid var(--border); }
.facts dt { color: var(--muted); display: flex; gap: 8px; white-space: nowrap; }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

/* Calendar */
.cal { display: flex; flex-direction: column; gap: 6px; }
.cal-head, .cal-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head span { text-align: center; color: var(--muted); font-size: .75rem; font-weight: 600; }
.cal-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.cal-cell b { font-size: .95rem; }
.cal-cell small { font-size: .68rem; color: inherit; opacity: .85; }
.cal-cell.blank { background: none; border: 0; }
.cal-cell.future { opacity: .3; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-human { position: absolute; top: 3px; right: 4px; font-size: .62rem; color: var(--human); }
.lvl-1 { background: rgba(56, 189, 248, .12); }
.lvl-2 { background: rgba(56, 189, 248, .25); }
.lvl-3 { background: rgba(56, 189, 248, .42); }
.lvl-4 { background: rgba(56, 189, 248, .62); color: #fff; }
.legend { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 14px; color: var(--muted); font-size: .8rem; }
.legend span { width: 14px; height: 14px; border-radius: 4px; }

/* Access log */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.log { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.log-row { padding: 10px 14px; border-left: 3px solid transparent; }
.log-row + .log-row { border-top: 1px solid var(--border); }
.log-login_fail { border-left-color: var(--danger); }
.log-login_ok { border-left-color: var(--ok); }
.log-clip_view, .log-clip_download { border-left-color: var(--accent); }
.log-top { display: flex; justify-content: space-between; gap: 10px; }
.log-top time { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.log-sub { display: flex; gap: 14px; color: var(--muted); font-size: .82rem; margin-top: 2px; }
.log-obj { font-size: .8rem; color: var(--muted); margin-top: 2px; word-break: break-all; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty > i { font-size: 2.6rem; display: block; margin-bottom: 10px; color: var(--surface-3); }
.empty h2 { color: var(--text); margin-bottom: 8px; }

/* Larger screens */
@media (min-width: 640px) {
    .cams { grid-template-columns: repeat(2, 1fr); }
    .clips { grid-template-columns: repeat(2, 1fr); }
    .player { margin: 0 0 12px; border-radius: var(--radius); overflow: hidden; }
    .page-clip .page { padding-top: 14px; }
}
@media (min-width: 980px) {
    .cams { grid-template-columns: repeat(3, 1fr); }
    .clips { grid-template-columns: repeat(3, 1fr); }
    .tabbar {
        left: 50%;
        right: auto;
        bottom: 14px;
        width: 360px;
        height: var(--tab-h);
        padding: 0;
        transform: translateX(-50%);
        border: 1px solid var(--border);
        border-radius: 20px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
    }
    .page-clip .page { max-width: 900px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; scroll-behavior: auto !important; }
}
