:root {
    --adm-bg: #f3f6fb;
    --adm-card: #ffffff;
    --adm-border: #e2e8f0;
    --adm-text: #0f172a;
    --adm-muted: #64748b;
    --adm-sidebar: #0b1220;
    --adm-sidebar-2: #111c34;
    --adm-accent: #2563eb;
    --adm-accent-2: #38bdf8;
    --adm-success: #16a34a;
    --adm-warning: #d97706;
    --adm-danger: #dc2626;
    --adm-shadow: 0 10px 30px rgba(15, 23, 42, .08);
    --adm-surface: #ffffff;
    --adm-surface-2: #f8fafc;
    --adm-topbar-bg: rgba(255, 255, 255, .92);
    --adm-field-border: #cbd5e1;
    --adm-label: #334155;
}

:root[data-adm-theme="dark"] {
    color-scheme: dark;
    --adm-bg: #070d19;
    --adm-card: #111c34;
    --adm-border: #26334d;
    --adm-text: #f8fafc;
    --adm-muted: #94a3b8;
    --adm-sidebar: #050a14;
    --adm-sidebar-2: #0c1528;
    --adm-accent: #3b82f6;
    --adm-accent-2: #22d3ee;
    --adm-shadow: 0 12px 32px rgba(0, 0, 0, .35);
    --adm-surface: #111c34;
    --adm-surface-2: #0d1729;
    --adm-topbar-bg: rgba(7, 13, 25, .92);
    --adm-field-border: #334155;
    --adm-label: #cbd5e1;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--adm-bg);
    color: var(--adm-text);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: .925rem;
}

a { text-decoration: none; }

.adm-shell { min-height: 100vh; }

.adm-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    background: linear-gradient(180deg, var(--adm-sidebar) 0%, var(--adm-sidebar-2) 100%);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    padding: 22px 16px 16px;
    z-index: 1040;
    transition: transform .2s ease;
}

.adm-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 24px;
    border-bottom: 1px solid rgba(148, 163, 184, .18);
    margin-bottom: 18px;
}

.adm-brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    letter-spacing: .5px;
    color: #fff;
    background: linear-gradient(135deg, var(--adm-accent), var(--adm-accent-2));
    box-shadow: 0 8px 18px rgba(37, 99, 235, .35);
    flex: 0 0 auto;
}

.adm-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.adm-brand-text strong { color: #fff; font-size: 1rem; }
.adm-brand-text small { color: #94a3b8; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }

.adm-nav { display: flex; flex-direction: column; gap: 4px; }
.adm-nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #cbd5e1;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.adm-nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.adm-nav-link:hover { background: rgba(148, 163, 184, .12); color: #fff; }
.adm-nav-link.active {
    background: linear-gradient(90deg, rgba(37, 99, 235, .95), rgba(56, 189, 248, .75));
    color: #fff;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .25);
}
.adm-sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(148, 163, 184, .18); display: flex; flex-direction: column; gap: 4px; }

.adm-main { margin-left: 260px; min-height: 100vh; display: flex; flex-direction: column; }

.adm-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 28px;
    background: var(--adm-topbar-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--adm-border);
}

.adm-topbar-title { font-weight: 700; font-size: 1.05rem; }
.adm-toggle { display: none; }
.adm-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.adm-topbar-actions { display: flex; align-items: center; gap: 8px; }
.adm-logout-form { margin: 0; }
.adm-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, .14);
    color: var(--adm-accent);
    font-weight: 700;
    font-size: .8rem;
}
.adm-user-text { display: flex; flex-direction: column; line-height: 1.1; }
.adm-user-text strong { font-size: .85rem; }
.adm-user-text small { color: var(--adm-muted); font-size: .72rem; }

.adm-content { padding: 26px 28px 34px; flex: 1; }
.adm-footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 28px;
    border-top: 1px solid var(--adm-border);
    color: var(--adm-muted);
    font-size: .78rem;
    background: var(--adm-surface);
}

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-heading h1 { font-size: 1.45rem; font-weight: 750; margin: 0 0 4px; }
.page-heading p { margin: 0; color: var(--adm-muted); }
.page-heading .btn { white-space: nowrap; }

.card { border: 1px solid var(--adm-border); border-radius: 14px; box-shadow: var(--adm-shadow); }
.card-header { background: var(--adm-surface); border-bottom: 1px solid var(--adm-border); font-weight: 650; padding: 14px 18px; border-radius: 14px 14px 0 0 !important; }
.card-body { padding: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { background: var(--adm-surface); border: 1px solid var(--adm-border); border-radius: 14px; padding: 18px; box-shadow: var(--adm-shadow); display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem; flex: 0 0 auto; }
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green { background: #dcfce7; color: #15803d; }
.stat-icon.amber { background: #fef3c7; color: #b45309; }
.stat-icon.red { background: #fee2e2; color: #b91c1c; }
.stat-icon.purple { background: #ede9fe; color: #6d28d9; }
.stat-value { font-size: 1.55rem; font-weight: 750; line-height: 1; }
.stat-label { color: var(--adm-muted); font-size: .78rem; margin-top: 4px; }

.table { margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .75rem .7rem; vertical-align: middle; }
.table thead th { color: var(--adm-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; border-bottom-width: 1px; white-space: nowrap; }
.table-hover tbody tr:hover { background: var(--adm-surface-2); }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-actions .btn { padding: .25rem .45rem; font-size: .78rem; }

.form-label { font-size: .8rem; font-weight: 650; color: var(--adm-label); margin-bottom: .35rem; }
.form-control, .form-select { background-color: var(--adm-surface); color: var(--adm-text); border-color: var(--adm-field-border); border-radius: 9px; font-size: .9rem; }
.form-control:focus, .form-select:focus { border-color: var(--adm-accent); box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .12); }
.form-text { font-size: .75rem; }
.input-group-text { background: var(--adm-surface-2); border-color: var(--adm-field-border); color: var(--adm-muted); }

.btn { border-radius: 9px; font-weight: 600; }
.btn-primary { background: var(--adm-accent); border-color: var(--adm-accent); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-sm { font-size: .8rem; }

.badge { font-weight: 600; padding: .38em .6em; border-radius: 7px; }
.badge.text-bg-primary { background: #dbeafe !important; color: #1d4ed8 !important; }
.badge.text-bg-success { background: #dcfce7 !important; color: #15803d !important; }
.badge.text-bg-warning { background: #fef3c7 !important; color: #b45309 !important; }
.badge.text-bg-danger { background: #fee2e2 !important; color: #b91c1c !important; }
.badge.text-bg-info { background: #cffafe !important; color: #0e7490 !important; }
.badge.text-bg-secondary { background: #e2e8f0 !important; color: #475569 !important; }
:root[data-adm-theme="dark"] .badge.text-bg-primary { background: rgba(59, 130, 246, .18) !important; color: #93c5fd !important; }
:root[data-adm-theme="dark"] .badge.text-bg-success { background: rgba(22, 163, 74, .18) !important; color: #86efac !important; }
:root[data-adm-theme="dark"] .badge.text-bg-warning { background: rgba(217, 119, 6, .18) !important; color: #fcd34d !important; }
:root[data-adm-theme="dark"] .badge.text-bg-danger { background: rgba(220, 38, 38, .18) !important; color: #fca5a5 !important; }
:root[data-adm-theme="dark"] .badge.text-bg-info { background: rgba(6, 182, 212, .18) !important; color: #67e8f9 !important; }
:root[data-adm-theme="dark"] .badge.text-bg-secondary { background: rgba(148, 163, 184, .18) !important; color: #cbd5e1 !important; }
:root[data-adm-theme="dark"] .stat-icon.blue { background: rgba(59, 130, 246, .18); color: #93c5fd; }
:root[data-adm-theme="dark"] .stat-icon.green { background: rgba(22, 163, 74, .18); color: #86efac; }
:root[data-adm-theme="dark"] .stat-icon.amber { background: rgba(217, 119, 6, .18); color: #fcd34d; }
:root[data-adm-theme="dark"] .stat-icon.red { background: rgba(220, 38, 38, .18); color: #fca5a5; }
:root[data-adm-theme="dark"] .stat-icon.purple { background: rgba(139, 92, 246, .18); color: #c4b5fd; }
:root[data-adm-theme="dark"] .timeline-note { border-left-color: var(--adm-border); }

.empty-state { text-align: center; padding: 44px 20px; color: var(--adm-muted); }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: 10px; opacity: .55; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 160px; }

.mono { font-family: Consolas, "Courier New", monospace; }
.text-muted-sm { color: var(--adm-muted); font-size: .8rem; }
.timeline-note { border-left: 3px solid #cbd5e1; padding: 0 0 14px 14px; margin-left: 6px; }
.timeline-note:last-child { padding-bottom: 0; }
.timeline-note .meta { color: var(--adm-muted); font-size: .75rem; }

.adm-login-body {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 30%, #0b2a45 0%, #04101f 48%, #020617 100%);
    padding: 24px;
    overflow: hidden;
}
.adm-login-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .85rem;
    pointer-events: none;
}
.adm-login-art {
    width: min(420px, 86vw);
    height: min(80vh, 720px);
    border: 0;
    opacity: .92;
}
.adm-login-body--redirect .adm-login-art {
    width: min(560px, 92vw);
    height: min(76vh, 780px);
    opacity: 1;
}
.adm-login-loading {
    position: relative;
    z-index: 2;
}
.adm-login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, .98);
    border: 1px solid rgba(148, 163, 184, .25);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 30px 70px rgba(2, 6, 23, .45);
    opacity: 0;
    transform: translateY(26px) scale(.94);
    animation: admLoginCardIn .8s .2s cubic-bezier(.16, .84, .24, 1) forwards;
}
@keyframes admLoginCardIn {
    from { opacity: 0; transform: translateY(26px) scale(.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .adm-login-card {
        opacity: 1;
        transform: none;
        animation: none;
    }
}
.adm-login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.adm-login-brand h1 { font-size: 1.35rem; font-weight: 800; margin: 0; }
.adm-login-brand p { margin: 2px 0 0; color: var(--adm-muted); font-size: .82rem; }
.adm-login-footer { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--adm-border); color: var(--adm-muted); font-size: .75rem; text-align: center; }

@media (max-width: 991.98px) {
    .adm-sidebar { transform: translateX(-100%); }
    .adm-shell.sidebar-open .adm-sidebar { transform: translateX(0); }
    .adm-main { margin-left: 0; }
    .adm-toggle { display: inline-flex; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 575.98px) {
    .adm-content { padding: 18px 16px 26px; }
    .adm-topbar { padding: 12px 16px; }
    .adm-footer { padding: 12px 16px; flex-direction: column; }
    .stat-grid { grid-template-columns: 1fr; }
    .page-heading { flex-direction: column; }
    .page-heading .btn { width: 100%; }
    .adm-user-text { display: none; }
}

.camera-preview-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 70vh;
    overflow: hidden;
    border-radius: 10px;
    background: #020617;
    display: flex;
    align-items: center;
    justify-content: center;
}
.camera-preview-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity .15s linear;
}
.camera-preview-frame.is-active { opacity: 1; }
.camera-live-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #020617;
}
.camera-preview-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, .55);
    color: #cbd5e1;
}
.camera-ptz-pad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 6px;
}
.camera-ptz-pad .btn,
.camera-ptz-side .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    touch-action: none;
    user-select: none;
}
.camera-ptz-side { display: flex; flex-direction: column; gap: 6px; }
.camera-ptz-presets { flex: 1 1 240px; min-width: 240px; }
@media (max-width: 575.98px) {
    .camera-preview-stage { aspect-ratio: 4 / 3; }
    .camera-ptz-presets { min-width: 100%; }
}

.app-intro {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    opacity: 1;
    visibility: visible;
    transition: opacity .45s ease, visibility .45s ease;
}
.app-intro.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.app-intro-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .85rem;
    width: min(340px, 78vw);
}
.app-intro-art {
    width: min(320px, 72vw);
    height: min(70vh, 560px);
    border: 0;
    pointer-events: none;
    filter: drop-shadow(0 0 18px rgba(2, 6, 23, .45));
}
.app-intro-text {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: #9fdff0;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .16em;
    text-transform: uppercase;
    text-shadow: 0 1px 6px rgba(2, 6, 23, .65);
}
.app-intro-dot {
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: #19c3e6;
    box-shadow: 0 0 12px rgba(25, 195, 230, .9);
    animation: appIntroPulse 1.2s ease-in-out infinite;
}
@keyframes appIntroPulse {
    0%, 100% { opacity: .35; transform: scale(.8); }
    50% { opacity: 1; transform: scale(1); }
}
.app-intro--compact .app-intro-art {
    width: min(150px, 38vw);
    height: min(32vh, 260px);
}
.app-intro--compact .app-intro-text {
    font-size: .68rem;
    opacity: .8;
}
body.app-intro-open {
    overflow: hidden;
}
.camera-live-loading {
    flex-direction: column;
    gap: .5rem;
}
.camera-live-loader {
    width: 96px;
    height: 160px;
    object-fit: contain;
    pointer-events: none;
}

.adm-shell.adm-nav-top .adm-sidebar {
    position: relative;
    inset: auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 18px;
    padding: 10px 20px;
}
.adm-shell.adm-nav-top .adm-brand {
    border-bottom: 0;
    margin-bottom: 0;
    padding: 0;
}
.adm-shell.adm-nav-top .adm-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
}
.adm-shell.adm-nav-top .adm-sidebar-footer {
    margin: 0 0 0 auto;
    padding: 0;
    border-top: 0;
    flex-direction: row;
}
.adm-shell.adm-nav-top .adm-main,
.adm-shell.adm-nav-none .adm-main {
    margin-left: 0;
}
.adm-shell.adm-nav-none .adm-sidebar {
    display: none;
}
@media (max-width: 900px) {
    .adm-shell.adm-nav-top .adm-sidebar {
        transform: none;
    }
}

:root[data-adm-theme="dark"] .form-control,
:root[data-adm-theme="dark"] .form-select {
    color: var(--adm-text);
    background-color: var(--adm-surface);
    border-color: var(--adm-field-border);
}

:root[data-adm-theme="dark"] input::placeholder,
:root[data-adm-theme="dark"] textarea::placeholder {
    color: #cbd5e1 !important;
    opacity: 1;
}

:root[data-adm-theme="dark"] select option {
    background-color: var(--adm-surface);
    color: var(--adm-text);
}

:root[data-adm-theme="dark"] .ts-control,
:root[data-adm-theme="dark"] .ts-control input,
:root[data-adm-theme="dark"] .ts-control .item {
    color: var(--adm-text);
    background-color: var(--adm-surface);
    border-color: var(--adm-field-border);
}

:root[data-adm-theme="dark"] .ts-control input::placeholder {
    color: #cbd5e1 !important;
    opacity: 1;
}

:root[data-adm-theme="dark"] .ts-dropdown,
:root[data-adm-theme="dark"] .ts-dropdown-content {
    background-color: var(--adm-surface);
    border-color: var(--adm-field-border);
}

:root[data-adm-theme="dark"] .ts-dropdown .option,
:root[data-adm-theme="dark"] .ts-dropdown .optgroup-header {
    color: var(--adm-text);
}

:root[data-adm-theme="dark"] .ts-dropdown .active,
:root[data-adm-theme="dark"] .ts-dropdown .selected {
    background-color: rgba(59, 130, 246, .25);
    color: #e5edf8;
}

.adm-toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(360px, calc(100vw - 36px));
}
.adm-toast { width: 100%; border-radius: 10px; box-shadow: var(--adm-shadow); }
.adm-toast .toast-header { border-bottom: 0; border-radius: 10px 10px 0 0; }
.adm-toast .toast-body { padding: 12px 14px; }
@media (max-width: 575.98px) {
    .adm-toast-stack { top: 12px; right: 12px; left: 12px; width: auto; }
}

