:root {
    --bg: #020617;
    --panel: #0f172a;
    --panel-soft: rgba(30, 41, 59, 0.5);
    --ink: #f8fafc;
    --muted: #94a3b8;
    --line: rgba(255, 255, 255, 0.08);
    --brand: #38bdf8;
    --brand-strong: #0ea5e9;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #0b0f19;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: var(--brand);
    text-decoration: none;
}

/* --- New Sidebar Layout (Bootstrap based) --- */
.sidebar {
    height: 100vh;
    background-color: #0f172a;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
    z-index: 1050;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
}
.sidebar-brand {
    padding: 1.5rem 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo-box { display: flex; align-items: center; gap: 10px; }
.logo-icon { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-title {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 0.03em;
    background: linear-gradient(to right, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
}
.sidebar-nav {
    flex: 1;
    padding: 1.5rem 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sidebar a {
    color: #94a3b8;
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    gap: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar a:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: #f8fafc;
    padding-left: 20px;
}
.sidebar a:hover i, .sidebar a:hover svg { color: #38bdf8; transform: scale(1.05); }
.sidebar a.active {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.08) 0%, rgba(56, 189, 248, 0.02) 100%);
    color: #38bdf8;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #38bdf8;
    border-radius: 0 8px 8px 0;
}
.sidebar a.active i, .sidebar a.active svg { color: #38bdf8; }
.sidebar a i, .sidebar a svg { width: 18px !important; height: 18px !important; color: #94a3b8; transition: all 0.2s ease; flex-shrink: 0; }
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.user-profile-box {
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(2, 6, 23, 0.4);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.02);
}
.user-avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(129, 140, 248, 0.15));
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700; color: #38bdf8; letter-spacing: 0.05em; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 600; color: #f1f5f9; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; margin: 0; }
.user-role { font-size: 0.7rem; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin: 0; }
.sidebar a.logout-link { color: #f87171; padding: 10px 12px; border-radius: 6px; }
.sidebar a.logout-link i, .sidebar a.logout-link svg { color: #f87171; }
.sidebar a.logout-link:hover { background-color: rgba(239, 68, 68, 0.08); color: #f87171; padding-left: 16px; }

.content-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Mobile Navbar --- */
.mobile-navbar { display: none !important; background-color: #0f172a; border-bottom: 1px solid rgba(255, 255, 255, 0.05); padding: 1rem 1.5rem; justify-content: space-between; align-items: center; }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}
.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

.sidebar svg,
button svg,
.btn svg,
.feed-label svg,
.empty-state svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.1;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 84px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(15, 23, 42, .88);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1.25;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .mobile-navbar {
        display: flex !important;
    }
}

.topbar-subtitle {
    display: block;
    margin-top: 3px;
    color: var(--muted) !important;
    font-size: .88rem;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.topbar-actions form {
    margin: 0;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
}

.icon-button:hover {
    border-color: var(--brand);
    background: var(--panel-soft);
}

.icon-button.subtle {
    background: var(--panel-soft);
}

.content-area {
    display: grid;
    gap: 20px;
    padding: 24px 28px 36px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.metric-tile,
.panel-block,
.camera-card,
.playback-console {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 28px rgba(17, 24, 39, .05);
}

.metric-tile {
    padding: 16px;
}

.metric-tile span {
    display: block;
    color: var(--muted);
    font-size: .86rem;
}

.metric-tile strong {
    display: block;
    margin-top: 8px;
    font-size: 1.65rem;
    line-height: 1.1;
}

.toolbar-line,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toolbar-line {
    flex-wrap: wrap;
}

.section-heading {
    margin-bottom: 14px;
}

.section-heading h2 {
    margin: 0;
    font-size: 1.05rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
}

.btn-sm {
    min-height: 32px;
    padding: 5px 10px;
    font-size: .86rem;
}

.btn-primary {
    border-color: var(--brand);
    background: var(--brand);
    color: #ffffff;
}

.btn-primary:hover {
    border-color: var(--brand-strong);
    background: var(--brand-strong);
    color: #ffffff;
}

.btn-dark {
    border-color: var(--dark);
    background: var(--dark);
    color: #ffffff;
}

.btn-outline-dark,
.btn-outline-secondary {
    border-color: var(--line);
    background: var(--panel);
    color: var(--ink);
}

.btn-group {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
}

.w-100 {
    width: 100%;
}

.mb-3 {
    margin-bottom: 1rem;
}

.form-label {
    display: inline-block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: .86rem;
    font-weight: 700;
}

.form-control,
.form-select {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
}

.form-control:focus,
.form-select:focus {
    outline: 2px solid rgba(23, 105, 224, .22);
    border-color: var(--brand);
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -8px;
    margin-left: -8px;
}

.g-3 {
    row-gap: 1rem;
}

.row > * {
    padding-right: 8px;
    padding-left: 8px;
}

.col-12 {
    flex: 0 0 auto;
    width: 100%;
}

.col-md-2,
.col-md-3,
.col-md-4,
.col-md-6 {
    flex: 0 0 auto;
    width: 100%;
}

.d-grid {
    display: grid;
}

.align-items-end {
    align-items: end;
}

.align-middle {
    vertical-align: middle;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
}

.alert-danger {
    border: 1px solid #f5b7b1;
    background: #fde2e0;
    color: var(--danger);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: none;
    overflow-y: auto;
    padding: 18px;
    background: rgba(17, 24, 39, .62);
}

.modal.show {
    display: grid;
    place-items: center;
}

.modal-dialog {
    width: min(100%, 760px);
}

.modal-content {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .26);
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
}

.modal-header {
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.modal-footer {
    border-top: 1px solid var(--line);
}

.modal-body {
    padding: 18px;
}

.modal-title {
    margin: 0;
}

.fs-5 {
    font-size: 1.1rem;
}

.btn-close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: var(--panel-soft);
    cursor: pointer;
}

.btn-close::before {
    content: "x";
    font-weight: 800;
}

.me-auto {
    margin-right: auto;
}

.live-console {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.live-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 6px;
    background: #0d1422;
}

.live-summary,
.live-layout-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-summary span,
.live-summary time {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #9ca9bc;
    font-size: .78rem;
    white-space: nowrap;
}

.live-summary strong,
.live-summary time {
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
}

.live-summary time {
    padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, .1);
}

.live-dot {
    display: inline-block;
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #64748b;
}

.live-dot.is-online {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, .12);
}

.live-dot.is-recording {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, .12);
}

.live-dot.is-offline {
    background: #64748b;
}

.live-layout-button,
.live-tile-actions button,
.live-tile-actions a {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 5px;
    background: #111b2c;
    color: #9ca9bc;
    cursor: pointer;
}

.live-layout-button:hover,
.live-layout-button.is-active,
.live-tile-actions button:hover,
.live-tile-actions a:hover {
    border-color: rgba(59, 130, 246, .7);
    background: #182844;
    color: #ffffff;
}

.live-layout-button svg,
.live-tile-actions svg {
    width: 17px;
    height: 17px;
}

.live-wall {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    min-height: min(68vh, 760px);
}

.live-wall[data-layout="1"] {
    grid-template-columns: minmax(0, 1fr);
}

.live-wall[data-layout="1"] .live-tile:not(.is-selected) {
    display: none;
}

.live-wall[data-layout="6"],
.live-wall[data-layout="9"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.live-tile {
    position: relative;
    min-width: 0;
    min-height: 220px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 4px;
    background: #030712;
}

.live-tile.is-selected {
    border-color: rgba(59, 130, 246, .72);
}

.live-video,
.live-player {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #030712;
}

.live-no-signal {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    color: #64748b;
    background: #090e18;
}

.live-no-signal svg {
    width: 30px;
    height: 30px;
}

.live-tile-header {
    position: absolute;
    z-index: 2;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.live-camera-name,
.live-camera-state {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(3, 7, 18, .82);
    color: #f8fafc;
    font-size: .74rem;
    font-weight: 700;
}

.live-camera-name {
    max-width: 70%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-camera-state.is-online {
    color: #86efac;
}

.live-camera-state.is-online::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-right: 5px;
    border-radius: 50%;
    background: #22c55e;
}

.live-camera-state.is-offline {
    color: #cbd5e1;
}

.live-tile-actions {
    position: absolute;
    z-index: 3;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity .18s ease;
}

.live-tile:hover .live-tile-actions,
.live-tile:focus-within .live-tile-actions {
    opacity: 1;
}

.live-camera-rail {
    display: flex;
    gap: 8px;
    padding-bottom: 2px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.live-camera-option {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    min-height: 36px;
    max-width: 190px;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 5px;
    background: #0d1422;
    color: #9ca9bc;
    cursor: pointer;
}

.live-camera-option.is-selected {
    border-color: rgba(59, 130, 246, .7);
    color: #ffffff;
}

.live-camera-option span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-empty {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    min-height: 420px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 6px;
    color: #9ca9bc;
    background: #090e18;
}

.live-empty svg {
    width: 36px;
    height: 36px;
}

@media (max-width: 900px) {
    .live-wall[data-layout="6"],
    .live-wall[data-layout="9"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .live-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .live-summary {
        justify-content: space-between;
    }

    .live-layout-controls {
        justify-content: center;
    }

    .live-layout-button {
        flex: 1 1 0;
        width: auto;
        max-width: 64px;
    }

    .live-wall,
    .live-wall[data-layout="6"],
    .live-wall[data-layout="9"] {
        grid-template-columns: minmax(0, 1fr);
        min-height: auto;
    }

    .live-tile {
        min-height: 0;
        aspect-ratio: 16 / 9;
    }

    .live-tile-actions {
        opacity: 1;
    }

    .live-camera-option {
        max-width: 150px;
    }
}

.camera-wall {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.camera-wall[data-cols="3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.camera-wall[data-cols="4"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.camera-card {
    overflow: hidden;
}

.camera-feed {
    position: relative;
    aspect-ratio: 16 / 9;
    min-height: 150px;
    overflow: hidden;
    background:
        linear-gradient(120deg, rgba(23, 105, 224, .23), transparent 48%),
        linear-gradient(180deg, #142033, #0d121c);
}

.camera-feed::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 18% 22%, rgba(255, 255, 255, .16), transparent 18%),
        linear-gradient(0deg, rgba(0, 0, 0, .3), transparent 45%);
}

.camera-feed.has-player {
    background: #0d121c;
}

.camera-feed.has-player::after {
    content: none;
}

.camera-feed.is-offline {
    background: linear-gradient(180deg, #343b48, #171b22);
}

.camera-player {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #0d121c;
}

.feed-grid-lines {
    position: absolute;
    inset: 0;
    opacity: .13;
    background-image:
        linear-gradient(rgba(255, 255, 255, .55) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .55) 1px, transparent 1px);
    background-size: 34px 34px;
}

.feed-label {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 70px);
    padding: 7px 9px;
    border-radius: 8px;
    background: rgba(0, 0, 0, .42);
    color: #ffffff;
    font-size: .82rem;
}

.feed-label span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-open {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .9);
    color: var(--ink);
}

.camera-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
}

.camera-meta strong,
.camera-meta span {
    display: block;
}

.camera-meta strong {
    line-height: 1.2;
}

.camera-meta div > span {
    color: var(--muted);
    font-size: .82rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.status-online,
.status-ativo,
.status-gravando {
    background: #ddfbea;
    color: var(--success);
}

.status-offline,
.status-inativo,
.status-bloqueado {
    background: #fde2e0;
    color: var(--danger);
}

.status-pendente {
    background: #fff4ce;
    color: var(--warning);
}

.split-grid,
.two-column {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, .75fr);
    gap: 20px;
}

.panel-block {
    min-width: 0;
    padding: 18px;
}

.table {
    margin-bottom: 0;
}

.table th {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.table td {
    color: var(--ink);
    font-size: .92rem;
}

code {
    color: #0b4aa2;
    white-space: nowrap;
}

.event-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.event-list li,
.discovery-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.event-list strong,
.event-list small,
.discovery-item strong,
.discovery-item span,
.discovery-item small {
    display: block;
}

.event-list small,
.discovery-item span,
.discovery-item small {
    color: var(--muted);
}

.dot {
    width: 10px;
    height: 10px;
    margin-top: 7px;
    border-radius: 999px;
}

.dot.green {
    background: var(--success);
}

.dot.orange {
    background: var(--warning);
}

.dot.red {
    background: var(--danger);
}

.discovery-list {
    display: grid;
    gap: 12px;
}

.discovery-item {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
}

.discovery-item.is-empty {
    background: var(--panel-soft);
}

.playback-filter {
    margin: 0;
}

.playback-console {
    overflow: hidden;
}

.playback-video {
    display: grid;
    place-items: center;
    gap: 10px;
    min-height: clamp(260px, 48vh, 560px);
    background: #0d121c;
    color: #dbeafe;
}

.playback-video svg {
    width: 54px;
    height: 54px;
}

.timeline {
    position: relative;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0;
    padding: 16px 18px 42px;
    background: rgba(15, 23, 42, 0.45);
    color: var(--muted);
    font-size: .76rem;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.timeline-track {
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 14px;
    height: 12px;
    border-radius: 999px;
    background: var(--panel-soft);
    overflow: hidden;
}

.timeline-track span {
    position: absolute;
    top: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--brand);
}

.json-view {
    max-height: 520px;
    margin: 0;
    padding: 14px;
    overflow: auto;
    border-radius: 8px;
    background: #0d121c;
    color: #e5edf7;
}

.permission-grid {
    display: grid;
    gap: 10px;
}

.permission-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
}

.empty-state {
    display: grid;
    place-items: center;
    gap: 10px;
    min-height: 360px;
    text-align: center;
}

.recording-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(48px, 1fr));
    gap: 6px;
}

.recording-weekdays label {
    display: grid;
    place-items: center;
    min-height: 40px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}

.recording-weekdays input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.recording-weekdays label:has(input:checked) {
    border-color: var(--brand);
    background: rgba(23, 105, 224, .12);
    color: var(--brand);
}

@media (max-width: 576px) {
    .recording-weekdays {
        grid-template-columns: repeat(4, 1fr);
    }
}

.login-panel {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: #030712 !important; /* Deepest dark */
    background-image: 
        radial-gradient(at 50% 0%, rgba(59, 130, 246, 0.1) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(99, 102, 241, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.05) 0px, transparent 50%);
    margin: 0;
    padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    box-sizing: border-box;
    overflow-y: auto;
}

.login-box {
    width: min(100%, 440px);
    padding: 48px 40px;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    border-radius: 8px;
    background: linear-gradient(180deg, #0f1524 0%, #090d16 100%) !important;
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 20px 40px -10px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
    backdrop-filter: none !important;
}

.login-brand {
    margin-bottom: 32px;
}

.logo-hexagon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: #ffffff;
    margin-bottom: 0;
    letter-spacing: 0;
}

.login-title span {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box .form-label {
    font-size: 0.72rem !important;
    font-weight: 700 !important;
    color: #94a3b8 !important;
    text-transform: uppercase !important;
    letter-spacing: 0 !important;
    margin-bottom: 8px !important;
    display: block;
}

.login-box .form-control {
    background: #111726 !important;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
    color: #ffffff !important;
    padding: 14px 16px !important;
    font-size: 16px !important;
    min-height: 48px;
    border-radius: 6px !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.login-box .form-control:focus {
    border-color: #3b82f6 !important;
    background: #151d30 !important;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15) !important;
    outline: none !important;
}

.login-password-field {
    position: relative;
}

.login-password-field .form-control {
    padding-right: 52px !important;
}

.login-password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    transform: translateY(-50%);
    cursor: pointer;
}

.login-password-toggle:hover,
.login-password-toggle:focus-visible {
    background: rgba(255, 255, 255, .06);
    color: #ffffff;
}

.login-password-toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

.login-password-toggle svg {
    width: 19px;
    height: 19px;
}

.login-box .form-check {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding-left: 0;
    gap: 8px;
    margin-bottom: 24px;
}

.login-box .form-check-label {
    font-size: 0.85rem !important;
    color: #94a3b8 !important;
    cursor: pointer;
    user-select: none;
}

.login-box .form-check-input {
    flex: 0 0 18px;
    float: none;
    background-color: #111726 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 6px !important;
    width: 18px !important;
    height: 18px !important;
    margin: 0 !important;
    cursor: pointer;
    transition: all 0.2s ease !important;
}

.login-box .form-check-input:checked {
    background-color: #3b82f6 !important;
    border-color: #3b82f6 !important;
}

.login-box .btn-primary {
    border-radius: 6px !important;
    padding: 14px 20px !important;
    font-weight: 700 !important;
    font-size: 1rem !important;
    letter-spacing: 0 !important;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    border: none !important;
    box-shadow: 
        0 4px 12px rgba(37, 99, 235, 0.2),
        0 1px 2px rgba(0, 0, 0, 0.05) !important;
    margin-top: 12px !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    color: #ffffff !important;
    width: 100%;
}

.auth-main {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0 !important;
}

@media (max-width: 576px) {
    .login-panel {
        place-items: center;
        padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    }

    .login-box {
        padding: 28px 20px;
    }

    .login-brand {
        margin-bottom: 24px;
    }

    .logo-hexagon {
        width: 64px;
        height: 64px;
        margin-bottom: 12px;
    }

    .login-title {
        font-size: 1.5rem;
    }
}

/* Fixed live-view composition slots */
.live-toolbar-separator {
    width: 1px;
    height: 24px;
    margin: 0 2px;
    background: rgba(255, 255, 255, .1);
}

.live-wall[data-layout="1"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
}

.live-wall[data-layout="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

.live-wall[data-layout="9"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
}

.live-wall[data-layout="16"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
}

.live-slot {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 2px;
    background: #000000;
    cursor: pointer;
}

.live-slot:hover {
    border-color: rgba(148, 163, 184, .45);
}

.live-slot.is-selected {
    border-color: #38bdf8;
    box-shadow: inset 0 0 0 1px #38bdf8;
}

.live-slot:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: -2px;
}

.live-slot-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    color: #334155;
    user-select: none;
}

.live-slot-empty span {
    font-size: .66rem;
    font-variant-numeric: tabular-nums;
}

.live-slot-empty svg {
    width: 18px;
    height: 18px;
}

.live-slot.is-selected .live-slot-empty {
    color: #64748b;
}

.live-slot.is-assigned .live-slot-empty {
    display: none;
}

.live-camera-option.is-assigned {
    border-color: rgba(34, 197, 94, .22);
}

.live-camera-option.is-assigned .live-camera-icon {
    color: #86efac;
}

.live-layout-button[data-clear-slot],
.live-layout-button[data-clear-grid] {
    color: #64748b;
}

.live-layout-button[data-clear-slot]:hover,
.live-layout-button[data-clear-grid]:hover {
    border-color: rgba(239, 68, 68, .45);
    background: rgba(127, 29, 29, .18);
    color: #fca5a5;
}

@media (max-width: 760px) {
    .live-layout-desktop {
        display: none;
    }

    .live-stage .live-wall[data-layout="1"] {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto;
    }

    .live-stage .live-wall[data-layout="4"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(2, auto);
    }

    .live-slot {
        aspect-ratio: 16 / 9;
    }

    .live-stage .live-toolbar {
        flex-direction: row;
        align-items: center;
    }

    .live-stage .live-layout-controls {
        justify-content: flex-end;
    }
}

/* User management */
.users-workspace {
    display: grid;
    gap: 14px;
}

.users-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.users-summary article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

.users-summary span {
    color: var(--muted);
    font-size: .72rem;
    font-weight: 650;
    text-transform: uppercase;
}

.users-summary strong {
    color: var(--ink);
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
}

.users-panel {
    padding: 0;
    overflow: hidden;
}

.users-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
}

.users-search {
    position: relative;
    flex: 1 1 auto;
    max-width: 520px;
}

.users-search svg {
    position: absolute;
    top: 50%;
    left: 11px;
    width: 16px;
    height: 16px;
    color: var(--muted);
    transform: translateY(-50%);
    pointer-events: none;
}

.users-search input,
.users-filter {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--panel-soft);
    color: var(--ink);
    font-size: .82rem;
}

.users-search input {
    padding: 8px 12px 8px 36px;
}

.users-filter {
    width: 180px;
    padding: 8px 10px;
}

.users-table-wrap {
    overflow-x: auto;
}

.users-table th,
.users-table td {
    padding: 12px 14px;
    vertical-align: middle;
}

.user-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-initials {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(56, 189, 248, .22);
    border-radius: 5px;
    background: rgba(56, 189, 248, .1);
    color: #38bdf8;
    font-size: .68rem;
    font-weight: 800;
}

.user-identity > span:last-child {
    display: grid;
    min-width: 0;
}

.user-identity strong,
.user-identity small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-identity strong {
    color: var(--ink);
    font-size: .82rem;
}

.user-identity small,
.user-last-login {
    color: var(--muted);
    font-size: .7rem;
}

.user-role-badge {
    display: inline-flex;
    padding: 4px 7px;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--muted);
    font-size: .7rem;
}

.users-actions-heading {
    width: 92px;
    text-align: right;
}

.user-row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.user-action {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--panel-soft);
    color: var(--muted);
    cursor: pointer;
}

.user-action:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.user-action.is-danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.user-action svg {
    width: 15px;
    height: 15px;
}

.users-mobile-list {
    display: none;
}

.users-empty-filter {
    padding: 28px;
    color: var(--muted);
    text-align: center;
}

.user-role-guide {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.user-role-guide article {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

.user-role-guide svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    color: var(--brand);
}

.user-role-guide div {
    display: grid;
    gap: 3px;
}

.user-role-guide strong {
    color: var(--ink);
    font-size: .78rem;
}

.user-role-guide span,
.field-hint {
    color: var(--muted);
    font-size: .7rem;
}

@media (max-width: 760px) {
    .users-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .users-summary article {
        align-items: flex-start;
        flex-direction: column;
        min-height: 66px;
        padding: 9px;
    }

    .users-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .users-search,
    .users-filter {
        width: 100%;
        max-width: none;
    }

    .users-table-wrap {
        display: none;
    }

    .users-mobile-list {
        display: grid;
        gap: 0;
    }

    .user-mobile-card {
        display: grid;
        gap: 10px;
        padding: 12px;
        border-bottom: 1px solid var(--line);
    }

    .user-mobile-card:last-child {
        border-bottom: 0;
    }

    .user-mobile-top,
    .user-mobile-bottom {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .user-mobile-bottom > span {
        color: var(--muted);
        font-size: .72rem;
    }

    .user-role-guide {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Top navigation and operator workspace */
.app-body {
    min-height: 100dvh;
    background: #050b14;
}

.global-header {
    position: sticky;
    top: 0;
    z-index: 1100;
    display: grid;
    grid-template-columns: minmax(190px, auto) 1fr auto;
    align-items: center;
    min-height: 64px;
    padding: 0 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: #08111f;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

.global-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: max-content;
    color: #f8fafc;
    font-size: .95rem;
    font-weight: 700;
}

.global-brand img {
    width: 34px;
    height: 34px;
}

.global-brand strong {
    color: #38bdf8;
}

.global-nav {
    display: flex;
    align-self: stretch;
    justify-content: center;
    gap: 2px;
}

.global-nav a {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 104px;
    padding: 0 14px;
    color: #8d9bb0;
    font-size: .8rem;
    font-weight: 600;
}

.global-nav a::after {
    content: "";
    position: absolute;
    right: 14px;
    bottom: 0;
    left: 14px;
    height: 2px;
    background: transparent;
}

.global-nav a:hover,
.global-nav a.active {
    color: #f8fafc;
    background: #0c192b;
}

.global-nav a.active::after {
    background: #38bdf8;
}

.global-nav svg,
.global-account svg,
.global-menu-toggle svg {
    width: 17px;
    height: 17px;
}

.global-account {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.global-account form {
    margin: 0;
}

.global-theme-toggle,
.global-logout,
.global-menu-toggle {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 5px;
    background: #0d1929;
    color: #dce6f3;
}

.global-theme-toggle,
.global-logout,
.global-menu-toggle {
    cursor: pointer;
}

.global-logout:hover {
    border-color: rgba(239, 68, 68, .5);
    color: #fca5a5;
}

.global-theme-toggle:hover {
    border-color: rgba(56, 189, 248, .5);
    color: #7dd3fc;
}

.global-menu-toggle {
    display: none;
}

.app-main {
    min-height: calc(100dvh - 64px);
    padding: 18px;
}

.app-main.is-live-page {
    height: calc(100dvh - 64px);
    min-height: 620px;
    padding: 12px;
    overflow: hidden;
}

.app-content {
    min-width: 0;
}

.is-live-page .app-content {
    height: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.page-header h1 {
    margin: 0;
    color: #f8fafc;
    font-size: 1.25rem;
    font-weight: 750;
    letter-spacing: 0;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-workspace {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 10px;
    height: 100%;
    min-height: 0;
}

.live-camera-sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 6px;
    background: #08111f;
}

.live-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 64px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.live-sidebar-header div {
    display: grid;
    gap: 2px;
}

.live-sidebar-header span,
.live-section-label {
    color: #64748b !important;
    font-size: .65rem !important;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.live-sidebar-header strong,
.live-summary strong {
    color: #f8fafc;
    font-size: .9rem;
}

.live-sidebar-header > a,
.live-sidebar-action {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 4px;
    color: #94a3b8;
}

.live-sidebar-action {
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.live-sidebar-action:hover,
.live-sidebar-action:focus-visible {
    border-color: #38bdf8;
    color: #38bdf8;
}

.live-sidebar-header svg {
    width: 16px;
    height: 16px;
}

.live-camera-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    padding: 8px;
    overflow-y: auto;
}

.live-camera-option {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 8px;
    align-items: center;
    gap: 9px;
    width: 100%;
    max-width: none;
    min-height: 52px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: #94a3b8;
    text-align: left;
}

.live-camera-option:hover {
    background: #0c192a;
}

.live-camera-option.is-selected {
    border-color: rgba(56, 189, 248, .32);
    background: #0d1d31;
}

.live-camera-icon {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 4px;
    background: #111e30;
    color: #7dd3fc;
}

.live-camera-icon svg {
    width: 17px;
    height: 17px;
}

.live-camera-copy {
    display: grid;
    min-width: 0;
}

.live-camera-copy strong,
.live-camera-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-camera-copy strong {
    color: #dce6f3;
    font-size: .78rem;
    font-weight: 650;
}

.live-camera-copy small {
    color: #64748b;
    font-size: .66rem;
}

.live-sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 42px;
    padding: 9px 12px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.live-sidebar-footer span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #7f8da1;
    font-size: .66rem;
}

.live-stage {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 6px;
    background: #03070d;
}

.live-stage .live-toolbar {
    flex: 0 0 auto;
    min-height: 52px;
    border: 0;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    border-radius: 0;
    background: #08111f;
}

.live-stage .live-summary {
    display: flex;
    align-items: center;
    gap: 12px;
}

.live-stage .live-summary > div {
    display: grid;
    gap: 1px;
}

.live-stage .live-summary time {
    margin-left: 4px;
}

.live-stage .live-wall {
    flex: 1 1 auto;
    min-height: 0;
    padding: 6px;
    background: #02050a;
}

.live-wall[data-layout="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

.live-wall[data-layout="4"] .live-tile:nth-child(n+5),
.live-wall[data-layout="6"] .live-tile:nth-child(n+7),
.live-wall[data-layout="9"] .live-tile:nth-child(n+10) {
    display: none;
}

.live-wall[data-layout="6"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

.live-wall[data-layout="9"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
}

.live-wall[data-layout="1"] {
    grid-template-rows: minmax(0, 1fr);
}

.live-stage .live-tile {
    min-height: 0;
    border-color: rgba(255, 255, 255, .12);
    border-radius: 2px;
    cursor: default;
}

.live-stage .live-tile.is-selected {
    border-color: rgba(255, 255, 255, .12);
}

.live-stage .live-tile:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: -2px;
}

nvr-live-player {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000000;
    opacity: 0;
    transition: opacity 180ms ease;
}

nvr-live-player.is-ready {
    opacity: 1;
}

.live-slot-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #000000;
    color: #94a3b8;
    font-size: .75rem;
    font-weight: 600;
}

.live-slot-loading[hidden] {
    display: none;
}

.live-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(148, 163, 184, .28);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: live-loading-spin .8s linear infinite;
}

@keyframes live-loading-spin {
    to { transform: rotate(360deg); }
}

nvr-live-player video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.live-sidebar-empty {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    flex: 1;
    color: #64748b;
}

@media (max-width: 1080px) {
    .global-header {
        grid-template-columns: auto 1fr auto;
    }

    .global-nav a {
        min-width: auto;
        padding: 0 10px;
    }

    .global-nav a span {
        display: none;
    }

    .live-workspace {
        grid-template-columns: 220px minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    .global-header {
        grid-template-columns: 1fr auto auto;
        min-height: 58px;
        padding: 0 12px;
    }

    .global-menu-toggle {
        display: inline-grid;
    }

    .global-nav {
        position: absolute;
        top: calc(100% + 1px);
        right: 8px;
        left: 8px;
        display: none;
        align-self: auto;
        flex-direction: column;
        gap: 2px;
        padding: 8px;
        border: 1px solid rgba(255, 255, 255, .1);
        border-radius: 6px;
        background: #08111f;
        box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
    }

    .global-nav.is-open {
        display: flex;
    }

    .global-nav a {
        min-height: 42px;
        padding: 0 12px;
        border-radius: 4px;
    }

    .global-nav a span {
        display: inline;
    }

    .global-nav a::after {
        top: 8px;
        right: auto;
        bottom: 8px;
        left: 0;
        width: 2px;
        height: auto;
    }

    .app-main,
    .app-main.is-live-page {
        height: auto;
        min-height: calc(100dvh - 58px);
        padding: 8px;
        overflow: visible;
    }

    .is-live-page .app-content {
        height: auto;
    }

    .live-workspace {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
    }

    .live-camera-sidebar {
        min-height: auto;
    }

    .live-sidebar-header,
    .live-sidebar-footer {
        display: none;
    }

    .live-camera-list {
        flex-direction: row;
        padding: 7px;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .live-camera-option {
        flex: 0 0 168px;
        width: 168px;
    }

    .live-stage {
        min-height: 62vh;
    }

    .live-stage .live-wall,
    .live-wall[data-layout="4"],
    .live-wall[data-layout="6"],
    .live-wall[data-layout="9"] {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto;
        overflow: visible;
    }

    .live-wall[data-layout="4"] .live-tile:nth-child(n),
    .live-wall[data-layout="6"] .live-tile:nth-child(n),
    .live-wall[data-layout="9"] .live-tile:nth-child(n) {
        display: block;
    }

    .live-stage .live-tile {
        min-height: 0;
        aspect-ratio: 16 / 9;
    }
}

@media (max-height: 600px) {
    .login-panel {
        place-items: start center;
    }

    .login-box {
        padding-top: 20px;
        padding-bottom: 20px;
    }

    .login-brand {
        margin-bottom: 16px;
    }

    .logo-hexagon {
        width: 48px;
        height: 48px;
        margin-bottom: 8px;
    }
}

.login-box .btn-primary:hover {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 
        0 8px 20px rgba(37, 99, 235, 0.35),
        0 1px 2px rgba(0, 0, 0, 0.05) !important;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    color: var(--muted);
}

.form-status {
    color: var(--muted);
    font-size: .9rem;
}

@media (max-width: 1180px) {
    .camera-wall[data-cols="4"],
    .camera-wall[data-cols="3"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 991.98px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1050;
        width: min(84vw, 300px);
        transform: translateX(-102%);
        transition: transform .2s ease;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .topbar {
        min-height: 76px;
        padding: 14px 16px;
    }

    .content-area {
        padding: 18px 16px 28px;
    }

    .split-grid,
    .two-column {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) {
    .col-md-2 {
        width: 16.666667%;
    }

    .col-md-3 {
        width: 25%;
    }

    .col-md-4 {
        width: 33.333333%;
    }

    .col-md-6 {
        width: 50%;
    }
}

@media (max-width: 680px) {
    .topbar {
        align-items: flex-start;
    }

    .topbar h1 {
        font-size: 1.22rem;
    }

    .topbar-subtitle {
        display: none;
    }

    .metric-grid,
    .camera-wall,
    .camera-wall[data-cols="3"],
    .camera-wall[data-cols="4"] {
        grid-template-columns: 1fr;
    }

    .metric-tile strong {
        font-size: 1.35rem;
    }

    .camera-meta {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Custom Table styling matching Premium Dark theme */
.table {
    --bs-table-bg: transparent !important;
    --bs-table-color: var(--ink) !important;
    color: var(--ink) !important;
}

.table th, .table td {
    background-color: transparent !important;
    color: var(--ink) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.table tbody tr {
    background-color: rgba(15, 23, 42, 0.25) !important;
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03) !important;
}

.table thead th {
    background-color: rgba(30, 41, 59, 0.8) !important;
    color: var(--muted) !important;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.text-muted {
    color: var(--muted) !important;
}

/* Premium Mobile/Smartphone Layout Optimizations */
@media (max-width: 768px) {
    .content-wrapper {
        padding: 8px !important;
    }
    .content-area {
        padding: 8px 4px !important;
        gap: 12px !important;
    }
    .panel-block {
        padding: 12px !important;
        border-radius: 8px !important;
    }
    .mobile-navbar {
        display: flex !important;
        position: sticky;
        top: 0;
        z-index: 1030;
        background: rgba(15, 23, 42, 0.9) !important;
        backdrop-filter: blur(16px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 0.75rem 1rem !important;
        box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
    }
    .topbar {
        background: transparent !important;
        border: 0 !important;
        padding: 0 !important;
        margin-top: 4px !important;
        margin-bottom: 14px !important;
        box-shadow: none !important;
        position: relative !important;
        backdrop-filter: none !important;
        min-height: auto !important;
    }
    .topbar-subtitle {
        display: none !important;
    }
    .topbar h1 {
        font-size: 1.18rem !important;
    }
    .topbar-actions {
        margin-left: auto;
    }
}

@media (max-width: 576px) {
    .modal {
        padding: 8px !important;
    }
    .modal-dialog {
        margin: 8px !important;
    }
    .modal-body {
        padding: 12px !important;
    }
    .modal-header, .modal-footer {
        padding: 10px 12px !important;
    }
    .btn-create-camera {
        height: 34px !important;
        padding: 4px 10px !important;
        font-size: 0.85rem !important;
    }
    
    /* DVR Timeline Panel Responsive scaling */
    .camera-recording-panel {
        padding: 12px !important;
        border-radius: 8px !important;
    }
    .recording-panel-top {
        gap: 8px !important;
        margin-bottom: 10px !important;
    }
    .recording-controls {
        width: 100%;
        display: flex;
        justify-content: space-between;
        gap: 6px !important;
    }
    .recording-select, .recording-btn {
        flex: 1;
        height: 32px !important;
        font-size: 0.75rem !important;
        padding: 0 8px !important;
    }
    .dvr-current-row {
        margin: 8px 0 12px !important;
        padding: 6px 12px !important;
        font-size: 0.85rem !important;
    }
    .dvr-current-row span:first-child {
        font-size: 0.95rem !important;
    }
}

@media (max-width: 760px) {
    .live-layout-desktop {
        display: none !important;
    }

    .live-stage .live-wall[data-layout="1"] {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-rows: auto !important;
    }

    .live-stage .live-wall[data-layout="4"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        grid-template-rows: repeat(2, auto) !important;
    }

    .live-slot {
        aspect-ratio: 16 / 9;
    }
}

.mobile-live-mosaic {
    display: none;
}

@media (max-width: 760px) {
    .live-workspace {
        display: block;
    }

    .live-workspace > .live-camera-sidebar,
    .live-workspace > .live-stage {
        display: none;
    }

    .mobile-live-mosaic {
        display: grid;
        gap: 10px;
    }

    .mobile-mosaic-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 48px;
        padding: 8px 10px;
        border: 1px solid rgba(255, 255, 255, .08);
        border-radius: 6px;
        background: #08111f;
    }

    .mobile-mosaic-header > div {
        display: flex;
        align-items: baseline;
        gap: 7px;
    }

    .mobile-mosaic-header span {
        color: #64748b;
        font-size: .68rem;
        text-transform: uppercase;
    }

    .mobile-mosaic-header strong {
        color: #dce6f3;
        font-size: .8rem;
    }

    .mobile-mosaic-header > a {
        display: inline-grid;
        place-items: center;
        width: 34px;
        height: 34px;
        border: 1px solid rgba(255, 255, 255, .1);
        border-radius: 5px;
        color: #94a3b8;
        background: #0d1929;
    }

    .mobile-mosaic-header svg {
        width: 16px;
        height: 16px;
    }

    .mobile-mosaic-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .mobile-camera-card {
        display: grid;
        min-width: 0;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, .09);
        border-radius: 5px;
        background: #08111f;
        color: #dce6f3;
    }

    .mobile-camera-card:active {
        border-color: #38bdf8;
        background: #0d1d31;
    }

    .mobile-camera-preview {
        position: relative;
        display: block;
        aspect-ratio: 16 / 9;
        overflow: hidden;
        background: #000000;
    }

    .mobile-camera-preview img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .mobile-camera-offline {
        position: absolute;
        inset: 0;
        display: grid;
        place-items: center;
        color: #475569;
        background: #03070d;
    }

    .mobile-camera-offline svg {
        width: 24px;
        height: 24px;
    }

    .mobile-camera-meta {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 7px;
        min-height: 38px;
        padding: 7px 9px;
    }

    .mobile-camera-meta strong {
        overflow: hidden;
        color: #dce6f3;
        font-size: .72rem;
        font-weight: 650;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-mosaic-empty {
        display: grid;
        place-content: center;
        justify-items: center;
        gap: 8px;
        min-height: 52vh;
        color: #64748b;
    }
}

@media (max-width: 360px) {
    .mobile-mosaic-grid {
        gap: 6px;
    }

    .mobile-camera-meta {
        padding-right: 7px;
        padding-left: 7px;
    }
}

/* Light theme */
html[data-theme="light"] {
    color-scheme: light;
    --bg: #eef2f7;
    --panel: #ffffff;
    --panel-soft: #f1f5f9;
    --ink: #172033;
    --muted: #64748b;
    --line: #dbe3ee;
    --dark: #ffffff;
}

html[data-theme="light"] body,
html[data-theme="light"] .app-body {
    background: #eef2f7;
    color: #172033;
}

html[data-theme="light"] .global-header {
    border-bottom-color: #dbe3ee;
    background: #ffffff;
    box-shadow: 0 6px 20px rgba(15, 23, 42, .08);
}

html[data-theme="light"] .global-brand {
    color: #172033;
}

html[data-theme="light"] .global-nav a {
    color: #64748b;
}

html[data-theme="light"] .global-nav a:hover,
html[data-theme="light"] .global-nav a.active {
    color: #0f172a;
    background: #f1f5f9;
}

html[data-theme="light"] .global-theme-toggle,
html[data-theme="light"] .global-logout,
html[data-theme="light"] .global-menu-toggle,
html[data-theme="light"] .icon-button {
    border-color: #dbe3ee;
    background: #f8fafc;
    color: #475569;
}

html[data-theme="light"] .page-header {
    border-bottom-color: #dbe3ee;
}

html[data-theme="light"] .page-header h1,
html[data-theme="light"] .section-heading h2,
html[data-theme="light"] .recording-panel-title {
    color: #172033;
}

html[data-theme="light"] .panel-block,
html[data-theme="light"] .metric-tile,
html[data-theme="light"] .modal-content,
html[data-theme="light"] .camera-card,
html[data-theme="light"] .camera-recording-panel,
html[data-theme="light"] .player-control-bar {
    border-color: #dbe3ee !important;
    background: #ffffff !important;
    color: #172033;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .07) !important;
}

html[data-theme="light"] .form-control,
html[data-theme="light"] .form-select,
html[data-theme="light"] .recording-select,
html[data-theme="light"] .recording-btn,
html[data-theme="light"] .dvr-nav-btn,
html[data-theme="light"] .dvr-live-btn,
html[data-theme="light"] .player-control-bar .control-btn {
    border-color: #d7e0eb !important;
    background: #f8fafc !important;
    color: #334155 !important;
}

html[data-theme="light"] .form-control:focus,
html[data-theme="light"] .form-select:focus {
    border-color: #38bdf8 !important;
    background: #ffffff !important;
    color: #172033 !important;
}

html[data-theme="light"] .table,
html[data-theme="light"] .table td,
html[data-theme="light"] .table th {
    color: #273449;
    border-color: #e2e8f0;
}

html[data-theme="light"] .live-camera-sidebar,
html[data-theme="light"] .live-stage,
html[data-theme="light"] .live-stage .live-toolbar,
html[data-theme="light"] .mobile-mosaic-header,
html[data-theme="light"] .mobile-camera-card {
    border-color: #dbe3ee;
    background: #ffffff;
    color: #172033;
}

html[data-theme="light"] .live-sidebar-header,
html[data-theme="light"] .live-sidebar-footer,
html[data-theme="light"] .live-stage .live-toolbar {
    border-color: #dbe3ee;
}

html[data-theme="light"] .live-sidebar-header strong,
html[data-theme="light"] .live-summary strong,
html[data-theme="light"] .live-camera-copy strong,
html[data-theme="light"] .mobile-mosaic-header strong,
html[data-theme="light"] .mobile-camera-meta strong {
    color: #172033;
}

html[data-theme="light"] .live-camera-option:hover {
    background: #f1f5f9;
}

html[data-theme="light"] .live-camera-option.is-selected {
    border-color: #7dd3fc;
    background: #eaf7ff;
}

html[data-theme="light"] .live-camera-icon,
html[data-theme="light"] .mobile-mosaic-header > a {
    border-color: #dbe3ee;
    background: #f1f5f9;
    color: #0284c7;
}

html[data-theme="light"] .live-layout-button {
    border-color: #dbe3ee;
    background: #f8fafc;
    color: #64748b;
}

html[data-theme="light"] .live-layout-button:hover,
html[data-theme="light"] .live-layout-button.is-active {
    border-color: #38bdf8;
    background: #eaf7ff;
    color: #0369a1;
}

html[data-theme="light"] .live-stage .live-wall,
html[data-theme="light"] .camera-video-box,
html[data-theme="light"] .live-slot,
html[data-theme="light"] .mobile-camera-preview {
    background: #000000;
}

html[data-theme="light"] .recording-timeline,
html[data-theme="light"] .dvr-overview,
html[data-theme="light"] .json-view {
    border-color: #dbe3ee;
    background: #f8fafc;
    color: #334155;
}

@media (max-width: 760px) {
    html[data-theme="light"] .global-nav {
        border-color: #dbe3ee;
        background: #ffffff;
        box-shadow: 0 18px 40px rgba(15, 23, 42, .14);
    }
}
