/**
 * VCS Platform Hub - Styles
 * Dark theme with accent color #00d4aa
 */

/* ============================================================================
   Reset & Base
   ============================================================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0d1528;
    --bg-card: #16213e;
    --bg-hover: #1a2744;
    --bg-input: #1a1a2e;
    --accent: #00d4aa;
    --accent-dark: #00b894;
    --text: #e0e0e0;
    --text-muted: #888;
    --text-dim: #666;
    --success: #00d4aa;
    --warning: #f0c040;
    --danger: #ff6b6b;
    --border: #2a2a4e;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

#app {
    min-height: 100vh;
}

/* ============================================================================
   App Layout
   ============================================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 17px;
    color: var(--accent);
    margin: 0 0 6px 0;
    line-height: 1.2;
    white-space: nowrap;
}

.user-badge {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-type-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
    display: inline-block;
}

.user-type-badge.admin {
    background: var(--accent);
    color: var(--bg-dark);
}

.user-type-badge.viewer {
    background: rgba(100, 149, 237, 0.2);
    color: #6495ed;
}

/* Shared user notice for empty state */
.shared-user-notice {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: 12px;
    margin: 20px 0;
}

.shared-user-notice .notice-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.shared-user-notice h3 {
    color: var(--text);
    margin-bottom: 8px;
}

.shared-user-notice p {
    color: var(--text-muted);
    max-width: 400px;
    margin: 0 auto;
}

/* Shared by badge for device cards */
.shared-by-badge {
    font-size: 11px;
    color: var(--text-dim);
    background: var(--bg-hover);
    padding: 2px 8px;
    border-radius: 4px;
    margin-top: 4px;
}

.nav-menu {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-menu li {
    padding: 12px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-menu li:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.nav-menu li.active {
    background: var(--bg-hover);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-icon {
    font-size: 16px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.license-info {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.sidebar-version {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    opacity: 0.7;
    letter-spacing: 0.3px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    margin-bottom: 10px;
    padding: 6px 10px;
    background: var(--bg-hover);
    border-radius: 6px;
}

.connection-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.connection-status .status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.connection-status .status-dot.offline {
    background: var(--danger);
    animation: blink 1s infinite;
}

.connection-status .status-text {
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    margin-left: 220px;
    padding: 24px;
    background: var(--bg-dark);
    min-height: 100vh;
}

/* ============================================================================
   Content Header
   ============================================================================ */

.content-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.content-header h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.search-input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    min-width: 200px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ============================================================================
   Filter Bar
   ============================================================================ */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: 8px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-dark);
}

.sort-group select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
}

.sort-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.view-toggle {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.view-toggle button {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
}

.view-toggle button:first-child {
    border-radius: 4px 0 0 4px;
}

.view-toggle button:last-child {
    border-radius: 0 4px 4px 0;
}

.view-toggle button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-dark);
}

/* ============================================================================
   Device Grid
   ============================================================================ */

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

.device-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px var(--shadow);
}

.device-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.device-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.offline {
    background: var(--text-dim);
}

.device-card-header .device-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-badges {
    display: flex;
    gap: 6px;
}

.badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.badge.live {
    background: rgba(255, 107, 107, 0.2);
    color: var(--danger);
}

.badge.recording {
    background: rgba(255, 68, 68, 0.25);
    color: #ff4444;
    animation: blink 1s ease-in-out infinite;
}

.badge.gps {
    background: rgba(0, 212, 170, 0.2);
    color: var(--accent);
}

.badge.gps.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.badge.gps.clickable:hover {
    background: rgba(0, 212, 170, 0.4);
    transform: scale(1.1);
}

.badge.used {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-muted);
}

/* Device card recording state */
.device-card.recording {
    border-color: #ff4444;
    box-shadow: 0 0 8px rgba(255, 68, 68, 0.3);
}

/* Table row recording state */
tr.recording {
    background: rgba(255, 68, 68, 0.05);
}

.device-card-body {
    padding: 14px 16px;
}

.device-serial {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.device-model {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.device-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.device-meta .last-seen {
    color: var(--text-dim);
}

.device-card-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-hover);
}

.device-card-actions .btn {
    flex: 1;
}

/* ============================================================================
   Device Table
   ============================================================================ */

.table-container {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.devices-table {
    width: 100%;
    border-collapse: collapse;
}

.devices-table th {
    background: var(--bg-hover);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.devices-table th.sortable {
    cursor: pointer;
}

.devices-table th.sortable:hover {
    color: var(--accent);
}

.devices-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.devices-table tr:last-child td {
    border-bottom: none;
}

.devices-table tr:hover {
    background: var(--bg-hover);
}

.devices-table tr.dragging {
    opacity: 0.5;
}

.devices-table td.mono {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.devices-table td.actions {
    display: flex;
    gap: 6px;
}

/* ============================================================================
   Live View
   ============================================================================ */

.liveview-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 140px);
}

.liveview-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-card);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease;
}

.liveview-sidebar.panel-collapsed {
    width: 48px;
    min-width: 48px;
    padding: 16px 8px;
    overflow: hidden;
}

.liveview-sidebar h4 {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--accent);
}



.camera-list {
    flex: 1;
    overflow-y: auto;
}

.camera-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-hover);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: grab;
    transition: all 0.2s;
}

.camera-item:hover {
    background: var(--bg-input);
}

.camera-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* No longer graying out in-use items */
.camera-item .badge.used {
    background: rgba(0, 212, 170, 0.2);
    color: var(--accent);
    font-size: 9px;
    padding: 2px 5px;
}

.camera-item .sidebar-rec-indicator {
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: #d33;
    padding: 2px 5px;
    border-radius: 3px;
    margin-left: 4px;
    white-space: nowrap;
    animation: sidebarRecPulse 1.4s ease-in-out infinite;
}

@keyframes sidebarRecPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.camera-item .camera-name {
    flex: 1;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.camera-add-btn {
    background: var(--accent);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    color: var(--bg-dark);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.camera-add-btn:hover {
    background: var(--accent-dark);
    transform: scale(1.1);
}

.camera-item.in-use .camera-add-btn {
    background: var(--text-muted);
    opacity: 0.5;
}

.camera-info-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.camera-info-btn:hover {
    opacity: 1;
}

.liveview-grid {
    flex: 1;
    display: grid;
    gap: 12px;
    height: 100%;
}

.liveview-grid.grid-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.liveview-grid.grid-4 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.liveview-grid.grid-6 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.liveview-grid.grid-9 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.liveview-grid.grid-16 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

/* 1+5 Layout: matches VCS Client layout exactly
   3×3 grid: main slot spans cols 1-2 × rows 1-2, 
   2 small slots stack on the right, 3 small slots span the bottom row */
.liveview-grid.grid-1p5 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 2px;
}

/* Slot 0: primary — spans cols 1-2 × rows 1-2 (large left view) */
.liveview-grid.grid-1p5 .liveview-slot.slot-main {
    grid-column: 1 / 3;
    grid-row: 1 / 3;
}

/* Slot 1: right column top */
.liveview-grid.grid-1p5 .liveview-slot:nth-child(2) {
    grid-column: 3;
    grid-row: 1;
}

/* Slot 2: right column bottom */
.liveview-grid.grid-1p5 .liveview-slot:nth-child(3) {
    grid-column: 3;
    grid-row: 2;
}

/* Slots 3-5: bottom row, equal thirds */
.liveview-grid.grid-1p5 .liveview-slot:nth-child(4) {
    grid-column: 1;
    grid-row: 3;
}
.liveview-grid.grid-1p5 .liveview-slot:nth-child(5) {
    grid-column: 2;
    grid-row: 3;
}
.liveview-grid.grid-1p5 .liveview-slot:nth-child(6) {
    grid-column: 3;
    grid-row: 3;
}

/* 1+5 slots use overlay mode like other multi-slot grids */
.liveview-grid.grid-1p5 .liveview-slot {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
    min-height: 0;
}

.liveview-grid.grid-1p5 .liveview-slot .slot-video {
    flex: 1 1 100%;
    height: 100%;
    position: relative;
}

/* Ensure video element fills slot and preserves aspect ratio */
.liveview-grid.grid-1p5 .liveview-slot .slot-video video,
.liveview-grid.grid-1p5 .liveview-slot .slot-video .video-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.liveview-grid.grid-1p5 .liveview-slot .slot-header,
.liveview-grid.grid-1p5 .liveview-slot .slot-footer {
    position: absolute;
    left: 0; right: 0;
    z-index: 10;
    background: rgba(8, 12, 22, 0.0);
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.1s ease;
    pointer-events: none;
}

.liveview-grid.grid-1p5 .liveview-slot .slot-header {
    top: 0;
}

.liveview-grid.grid-1p5 .liveview-slot .slot-footer {
    bottom: 0;
}

.liveview-grid.grid-1p5 .liveview-slot:hover .slot-header,
.liveview-grid.grid-1p5 .liveview-slot:hover .slot-footer {
    opacity: 1;
    background: rgba(8, 12, 22, 0.88);
    pointer-events: auto;
}

.liveview-grid.grid-1p5 .liveview-slot .slot-footer .video-stats-bar {
    position: static;
}

/* Small slot controls */
.liveview-grid.grid-1p5 .liveview-slot:not(.slot-main) .slot-controls-btn {
    font-size: 11px;
    padding: 1px 3px;
}

/* stats-on: keep visible without hover */
.liveview-grid.grid-1p5.stats-on .liveview-slot .video-stats-bar,
.liveview-grid.grid-1p5.stats-on .liveview-slot .slot-header,
.liveview-grid.grid-1p5.stats-on .liveview-slot .slot-footer {
    opacity: 1;
    pointer-events: auto;
    background: rgba(8, 12, 22, 0.88);
}



/* ============================================================================
   Grid-4, Grid-6, Grid-9 and Grid-16: overlay mode
   Headers/controls overlay the video, only visible on hover.
   This maximises video area when many cameras are displayed.
   ============================================================================ */

.liveview-grid.grid-4 .liveview-slot,
.liveview-grid.grid-6 .liveview-slot,
.liveview-grid.grid-9 .liveview-slot,
.liveview-grid.grid-16 .liveview-slot {
    position: relative;
}

/* Video fills the entire cell */
.liveview-grid.grid-4 .liveview-slot .slot-video,
.liveview-grid.grid-6 .liveview-slot .slot-video,
.liveview-grid.grid-9 .liveview-slot .slot-video,
.liveview-grid.grid-16 .liveview-slot .slot-video {
    flex: 1 1 100%;
    height: 100%;
}

/* Header overlays the top of the video */
.liveview-grid.grid-4 .liveview-slot .slot-header,
.liveview-grid.grid-6 .liveview-slot .slot-header,
.liveview-grid.grid-9 .liveview-slot .slot-header,
.liveview-grid.grid-16 .liveview-slot .slot-header {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 10;
    background: rgba(8, 12, 22, 0.0);
    border-bottom: none;
    padding: 5px 8px;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.15s ease;
    pointer-events: none;
}

/* Footer (stats + action buttons) overlays the bottom of the video */
.liveview-grid.grid-4 .liveview-slot .slot-footer,
.liveview-grid.grid-6 .liveview-slot .slot-footer,
.liveview-grid.grid-9 .liveview-slot .slot-footer,
.liveview-grid.grid-16 .liveview-slot .slot-footer {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    z-index: 10;
    background: rgba(8, 12, 22, 0.0);
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.15s ease;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

/* Reveal on hover */
.liveview-grid.grid-4 .liveview-slot:hover .slot-header,
.liveview-grid.grid-4 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-6 .liveview-slot:hover .slot-header,
.liveview-grid.grid-6 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-9 .liveview-slot:hover .slot-header,
.liveview-grid.grid-9 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-16 .liveview-slot:hover .slot-header,
.liveview-grid.grid-16 .liveview-slot:hover .slot-footer {
    opacity: 1;
    pointer-events: auto;
}

/* Fully solid backgrounds on hover for readability */
.liveview-grid.grid-4 .liveview-slot:hover .slot-header,
.liveview-grid.grid-6 .liveview-slot:hover .slot-header,
.liveview-grid.grid-9 .liveview-slot:hover .slot-header,
.liveview-grid.grid-16 .liveview-slot:hover .slot-header {
    background: rgba(8, 12, 22, 0.95);
}

.liveview-grid.grid-4 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-6 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-9 .liveview-slot:hover .slot-footer,
.liveview-grid.grid-16 .liveview-slot:hover .slot-footer {
    background: rgba(8, 12, 22, 0.95);
}

/* Shrink header text and buttons in compact grids */
.liveview-grid.grid-9 .slot-device-name,
.liveview-grid.grid-16 .slot-device-name {
    font-size: 10px;
}

.liveview-grid.grid-4 .slot-device-name {
    font-size: 12px;
}

.liveview-grid.grid-4 .slot-indicators,
.liveview-grid.grid-9 .slot-indicators,
.liveview-grid.grid-16 .slot-indicators {
    gap: 4px;
    font-size: 9px;
}

.liveview-grid.grid-4 .slot-footer-buttons,
.liveview-grid.grid-6 .slot-footer-buttons,
.liveview-grid.grid-9 .slot-footer-buttons,
.liveview-grid.grid-16 .slot-footer-buttons {
    gap: 2px;
}

.liveview-grid.grid-4 .slot-controls-btn,
.liveview-grid.grid-9 .slot-controls-btn,
.liveview-grid.grid-16 .slot-controls-btn {
    font-size: 11px;
    padding: 1px 3px;
}

.liveview-grid.grid-4 .slot-remove,
.liveview-grid.grid-9 .slot-remove,
.liveview-grid.grid-16 .slot-remove {
    font-size: 14px;
    padding: 0 2px;
}

.liveview-grid.grid-4 .slot-controls .btn,
.liveview-grid.grid-9 .slot-controls .btn,
.liveview-grid.grid-16 .slot-controls .btn {
    font-size: 10px;
    padding: 2px 5px;
}

.liveview-grid.grid-4 .vcs-variant-select,
.liveview-grid.grid-9 .vcs-variant-select,
.liveview-grid.grid-16 .vcs-variant-select {
    font-size: 10px;
    padding: 1px 3px;
}

/* Stats bar stays but shrinks */
.liveview-grid.grid-4 .video-stats-bar,
.liveview-grid.grid-9 .video-stats-bar,
.liveview-grid.grid-16 .video-stats-bar {
    font-size: 9px;
    padding: 2px 6px;
}

/* Live/LIVE indicator smaller */
.liveview-grid.grid-4 .live-indicator,
.liveview-grid.grid-9 .live-indicator,
.liveview-grid.grid-16 .live-indicator {
    font-size: 8px;
}

.liveview-grid.grid-4 .vcs-badge,
.liveview-grid.grid-9 .vcs-badge,
.liveview-grid.grid-16 .vcs-badge {
    font-size: 8px;
    padding: 1px 3px;
}

/* Tighter gap between cells */
.liveview-grid.grid-4 {
    gap: 8px;
}

.liveview-grid.grid-9 {
    gap: 6px;
}

.liveview-grid.grid-16 {
    gap: 4px;
}
.liveview-slot {
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Important for grid children */
}

/* Locate highlight: briefly flash the pane that holds a camera the user clicked
   in the sidebar tree, so they can see where it is in the multi-cam layout. */
.liveview-slot.slot-locate {
    position: relative;
}
.liveview-slot.slot-locate::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 3px solid var(--accent);
    border-radius: inherit;
    box-shadow: inset 0 0 18px 2px rgba(0, 212, 170, 0.5);
    pointer-events: none;
    z-index: 10;
    animation: slotLocatePulse 1.7s ease-out forwards;
}
@keyframes slotLocatePulse {
    0%, 60% { opacity: 1; }
    100%    { opacity: 0; }
}

.liveview-slot.empty {
    justify-content: center;
    align-items: center;
    border-style: dashed;
}

.liveview-slot.occupied {
    border-style: solid;
    border-color: var(--border);
}

.liveview-slot.drag-over {
    border-color: var(--accent);
    background: rgba(0, 212, 170, 0.1);
}

.slot-placeholder {
    text-align: center;
    color: var(--text-dim);
}

.slot-placeholder .drop-icon {
    font-size: 32px;
    opacity: 0.5;
    display: block;
    margin-bottom: 8px;
}

.liveview-grid.grid-4 .slot-placeholder .drop-icon,
.liveview-grid.grid-9 .slot-placeholder .drop-icon,
.liveview-grid.grid-16 .slot-placeholder .drop-icon {
    font-size: 18px;
    margin-bottom: 4px;
}

.liveview-grid.grid-4 .slot-placeholder,
.liveview-grid.grid-9 .slot-placeholder,
.liveview-grid.grid-16 .slot-placeholder {
    font-size: 10px;
}

.liveview-grid.grid-4 .video-loading p,
.liveview-grid.grid-9 .video-loading p,
.liveview-grid.grid-16 .video-loading p {
    font-size: 10px;
    margin-top: 4px;
}

.liveview-grid.grid-4 .spinner,
.liveview-grid.grid-9 .spinner,
.liveview-grid.grid-16 .spinner {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

.liveview-grid.grid-4 .liveview-slot,
.liveview-grid.grid-9 .liveview-slot,
.liveview-grid.grid-16 .liveview-slot {
    border-radius: 5px;
}

.slot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
    gap: 6px;
}

/* Non-overlay footer (grid-1, grid-2, grid-3) */
.slot-footer {
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}



.slot-footer-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.slot-title {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.slot-indicators {
    display: flex;
    align-items: center;
    gap: 8px;
}

.recording-indicator {
    font-size: 10px;
    color: #ff4444;
    font-weight: 600;
    background: rgba(255, 68, 68, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    animation: blink 1s ease-in-out infinite;
}

.live-indicator {
    font-size: 10px;
    color: #ffffff;
    font-weight: 600;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.liveview-slot.streaming {
    border-color: var(--accent);
    border-width: 1px;
}

.slot-header-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Footer: stats bar sits above the action buttons */
.slot-footer {
    display: flex;
    flex-direction: column;
}



.slot-footer-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    flex-wrap: nowrap;
}

.slot-controls-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.slot-controls-btn:hover {
    opacity: 1;
    color: var(--accent);
}

.slot-reload-btn {
    background: none;
}

.slot-reload-btn:hover {
    color: var(--accent);
}

.slot-qr-btn {
    background: none;
    font-size: 13px;
}

.slot-qr-btn:hover {
    color: var(--success, #2ecc71);
    opacity: 1;
}

.slot-stats-btn {
    font-size: 13px;
    opacity: 0.5;
}

.slot-stats-btn:hover,
.slot-stats-btn.active {
    opacity: 1;
    color: var(--accent);
}

.slot-info {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.slot-info:hover {
    opacity: 1;
}

.slot-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
}

.slot-remove:hover {
    color: var(--danger);
}

.slot-video {
    flex: 1;
    width: 100%;
    min-height: 0; /* Important for flex children to shrink */
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    position: relative;
    overflow: hidden;
}

/* Recording overlay on video */
.recording-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(255, 0, 0, 0.9);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    animation: blink 1s ease-in-out infinite;
    z-index: 20;
}

/* Viewer count overlay on video */
.viewer-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    z-index: 20;
}

/* Viewer count in slot header */
.viewer-count {
    font-size: 10px;
    color: var(--accent);
    background: rgba(0, 212, 170, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
}

.video-placeholder {
    text-align: center;
    color: var(--text-dim);
}

.video-placeholder .play-icon {
    font-size: 48px;
    cursor: pointer;
    display: block;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.video-placeholder .play-icon:hover {
    color: var(--accent);
    transform: scale(1.1);
}

.video-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    z-index: 1;
}

/* Audio Controls Overlay */
.audio-controls {
    position: absolute;
    bottom: 25px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.85);
    padding: 6px 10px;
    border-radius: 6px;
    z-index: 16;
}

.audio-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 2px;
    color: #888;
    transition: color 0.2s;
}

.audio-btn:hover {
    color: #fff;
}

.audio-btn.unmuted {
    color: #0f0;
}

.audio-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.vu-meter {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
    min-width: 60px;
}

.vu-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, #00d4aa, #00d4aa 60%, #f0c040 75%, #ff6b6b 90%);
    border-radius: 4px;
    transition: width 0.05s ease-out;
}

.vu-db {
    font-size: 10px;
    color: #0f0;
    min-width: 42px;
    text-align: right;
    font-family: monospace;
}

.video-error {
    color: var(--danger);
    text-align: center;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    background: rgba(0, 0, 0, 0.8);
}

.video-error span {
    font-size: 14px;
}

.video-error .btn {
    margin-top: 8px;
}

.video-reconnecting {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
    color: var(--accent);
    font-size: 14px;
}

.video-reconnecting span {
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 20px;
    border-radius: 8px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.video-error .icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.video-error .error-detail {
    font-size: 11px;
    color: var(--text-dim);
    margin: 8px 0;
}

.video-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.3);
}

.video-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

.video-loading p {
    font-size: 13px;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Loading overlay - positioned on top of video element */
.video-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-muted);
    z-index: 5;
    transition: opacity 0.3s ease;
}

.video-loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

.video-loading-overlay p {
    font-size: 13px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.slot-controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-hover);
    justify-content: center;
    flex-wrap: wrap;
}

.slot-controls .btn-warning {
    background: #f59e0b;
    color: #000;
    font-weight: bold;
}

/* VCS stream quality selector */
.vcs-variant-select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    min-width: 42px;
    text-align: center;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.vcs-variant-select:focus {
    outline: 1px solid var(--accent);
}

/* ============================================================================
   Device Detail
   ============================================================================ */

.device-detail-container {
    height: calc(100vh - 200px);
    background: var(--bg-card);
    border-radius: 10px;
    overflow: auto;
    padding: 24px;
}

.device-detail-content {
    display: grid;
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
}

.device-info-card,
.device-actions-card {
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 20px;
}

.device-info-card h3,
.device-actions-card h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text);
}

.device-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-item label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.info-item span {
    font-size: 14px;
    color: var(--text);
}

.info-item .status-text.online {
    color: var(--success);
}

.device-actions-grid {
    display: grid;
    gap: 12px;
}

.device-action-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.device-action-btn:hover {
    border-color: var(--accent);
    background: rgba(0, 212, 170, 0.05);
}

.device-action-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.device-action-btn.primary:hover {
    background: var(--accent-hover);
}

.device-action-btn.primary .hint {
    color: rgba(0, 0, 0, 0.6);
}

.device-action-btn .icon {
    font-size: 24px;
}

.device-action-btn .label {
    font-size: 14px;
    font-weight: 500;
}

.device-action-btn .hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* Device View Tabs */
.device-view-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--bg-card);
    padding: 6px;
    border-radius: 8px;
    width: fit-content;
}

.tab-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    text-decoration: none;
}

.tab-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.tab-btn.active {
    background: var(--accent);
    color: var(--bg);
}

.tab-btn.external {
    margin-left: auto;
    color: var(--text-dim);
}

.tab-btn.external:hover {
    color: var(--accent);
}

.tab-btn.external.primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.tab-btn.external.primary:hover {
    background: var(--accent-hover);
}

.device-status-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Iframe loading state */
#iframeContainer {
    position: relative;
    margin: -24px;
    width: calc(100% + 48px);
    height: calc(100% + 48px);
}

#iframeContainer.iframe-loading .device-status-iframe {
    opacity: 0.3;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    z-index: 10;
}

.loading-overlay p {
    margin-top: 16px;
    color: var(--text-muted);
}

.device-header-badges {
    display: flex;
    gap: 10px;
    align-items: center;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.online {
    background: rgba(0, 212, 170, 0.2);
    color: var(--success);
}

.status-badge.offline {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-muted);
}

.offline-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
}

.offline-message .icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.offline-message h3 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text);
}

.device-info-summary {
    margin-top: 24px;
    text-align: left;
    background: var(--bg-hover);
    padding: 16px 24px;
    border-radius: 8px;
}

.device-info-summary p {
    margin: 8px 0;
}

.iframe-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
}

.iframe-error .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.iframe-error h3 {
    margin-bottom: 8px;
    color: var(--text);
}

.iframe-error p {
    margin-bottom: 20px;
}

.error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.iframe-warning {
    padding: 10px 16px;
    text-align: center;
    font-size: 12px;
    color: var(--warning);
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 6px;
    margin-bottom: 12px;
}

.iframe-warning a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.iframe-warning a:hover {
    text-decoration: underline;
}

.iframe-hint {
    padding: 8px 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
}

.iframe-hint a {
    color: var(--accent);
    text-decoration: none;
}

.iframe-hint a:hover {
    text-decoration: underline;
}

/* ============================================================================
   Map View
   ============================================================================ */

.map-layout {
    display: flex;
    height: calc(100vh - 140px);
    gap: 16px;
}

.map-sidebar {
    width: 300px;
    background: var(--bg-card);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-sidebar-header h3 {
    margin: 0;
    font-size: 14px;
}

.live-gps-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
}

.live-gps-toggle input {
    cursor: pointer;
}

.map-device-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.map-device-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-hover);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.map-device-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.map-device-item.selected {
    background: rgba(0, 210, 180, 0.15);
    border: 1px solid var(--accent);
}

.map-device-item.offline {
    opacity: 0.6;
}

.map-device-item .device-info {
    flex: 1;
    min-width: 0;
}

.map-device-item .device-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.map-device-item .device-coords {
    font-size: 10px;
    color: var(--text-dim);
    font-family: monospace;
}

.selected-device-info {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-hover);
}

.selected-device-info h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--accent);
}

.selected-device-info .device-details {
    font-size: 12px;
    margin-bottom: 12px;
}

.selected-device-info .device-details p {
    margin: 4px 0;
}

.selected-device-info .device-actions {
    display: flex;
    gap: 8px;
}

.map-container-wrapper {
    flex: 1;
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    min-height: 400px;
}

.leaflet-map {
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: #1a1a2e;
}

.live-gps-indicator {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.8);
    color: var(--success);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
}

.live-gps-indicator .pulse {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse-scale 1.5s ease-in-out infinite;
}

/* Map Toolbar — offset from left to clear Leaflet zoom control (~34px wide) */
.map-toolbar {
    position: absolute;
    top: 10px;
    left: 50px;
    z-index: 1000;
    display: flex;
    gap: 8px;
    align-items: center;
}

.map-layer-select {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
}

.map-layer-select:hover {
    border-color: var(--accent);
}

.map-toolbar-btn {
    background: rgba(0, 0, 0, 0.8);
    color: #4285f4;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.map-toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: var(--accent);
}

@keyframes pulse-scale {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Custom map markers */
.custom-marker {
    background: none;
    border: none;
}

.map-marker {
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    border: 3px solid var(--success);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.map-marker.offline {
    border-color: var(--text-dim);
    opacity: 0.7;
}

.map-marker.selected {
    border-color: var(--accent);
    background: rgba(0, 210, 180, 0.2);
    transform: rotate(-45deg) scale(1.2);
}

.map-marker .marker-icon {
    transform: rotate(45deg);
    font-size: 16px;
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

/* Ensure Leaflet popup shows on top */
.leaflet-popup {
    z-index: 1000 !important;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.leaflet-popup-content {
    margin: 12px;
}

.map-popup {
    padding: 4px;
    font-size: 13px;
}

.map-popup button,
.map-popup-btn {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.map-popup-btn.primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.map-popup-btn:hover {
    opacity: 0.8;
}

/* Map Video Modal */
.map-video-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.map-video-modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    width: 480px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.map-video-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.map-video-header .device-name {
    font-weight: 600;
    font-size: 14px;
}

.map-video-header .modal-actions {
    display: flex;
    gap: 8px;
}

.map-video-container {
    position: relative;
    background: #000;
    aspect-ratio: 16/9;
}

.map-video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.map-video-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    color: var(--text-muted);
}

.map-video-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.map-video-footer .status-indicator {
    color: var(--text-muted);
}

.map-video-footer .coords {
    color: var(--text-dim);
    font-family: monospace;
}

.gps-count {
    font-size: 13px;
    color: var(--text-muted);
}

.gps-link {
    color: var(--accent);
    text-decoration: none;
}

.gps-link:hover {
    text-decoration: underline;
}

.coords {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-dim);
}

/* ============================================================================
   Users & Settings Views
   ============================================================================ */

.users-container,
.settings-container {
    max-width: 800px;
}

/* ============================================================================
   Stats View
   ============================================================================ */

.stats-container {
    max-width: 1000px;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stats-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}

.stats-card.highlight-user {
    border: 1px solid rgba(100, 150, 255, 0.3);
    background: linear-gradient(135deg, rgba(100, 150, 255, 0.05) 0%, var(--bg-card) 100%);
}

.stats-card.highlight-user .stats-value {
    color: #6496ff;
}

.stats-card.highlight-guest {
    border: 1px solid rgba(0, 212, 170, 0.3);
    background: linear-gradient(135deg, rgba(0, 212, 170, 0.05) 0%, var(--bg-card) 100%);
}

.stats-card.highlight-guest .stats-value {
    color: var(--accent);
}

.stats-card .stats-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.stats-card .stats-label {
    font-size: 14px;
    color: var(--text-muted);
}

.stats-section {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

.stats-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--accent);
}

.stats-devices-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stats-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.stats-empty .icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.stats-empty .hint {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 8px;
}

.stats-device-card {
    background: var(--bg-hover);
    border-radius: 8px;
    padding: 16px;
    border-left: 3px solid var(--border);
}

.stats-device-card.has-viewers {
    border-left-color: var(--accent);
}

.stats-device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.stats-device-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-device-name {
    font-weight: 600;
    color: var(--text);
}

.stats-device-serial {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.stats-viewer-count .viewer-badge {
    background: var(--accent);
    color: var(--bg-dark);
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
}

.viewer-badge.user-badge {
    background: rgba(100, 150, 255, 0.2);
    color: #6496ff;
}

.viewer-badge.guest-badge {
    background: rgba(0, 212, 170, 0.2);
    color: var(--accent);
}

.stats-viewers-section {
    margin-top: 12px;
}

.stats-viewers-section.guest-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.stats-viewers-section .stats-viewers-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: block;
    padding: 0;
    border: none;
}

.stats-viewers-section.guest-section .stats-viewers-header {
    color: var(--accent);
}

.guest-viewer-row {
    background: rgba(0, 212, 170, 0.03);
}

.stats-viewers-list {
    background: var(--bg-dark);
    border-radius: 6px;
    padding: 12px;
}

.stats-viewers-header {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.stats-viewer-row {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 8px;
    font-size: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.stats-viewer-row:last-child {
    border-bottom: none;
}

.viewer-id {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-status {
    color: var(--text-dim);
    font-size: 11px;
}

.viewer-status.connected {
    color: var(--success);
}

.viewer-duration {
    color: var(--text-muted);
    font-size: 11px;
}

.stats-device-meta {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

/* VCS device group in stats - nested camera list */
.stats-vcs-device-card {
    border-left: 3px solid var(--accent);
}

.stats-vcs-cameras {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stats-vcs-camera {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    padding: 8px 12px;
}

.stats-vcs-camera.has-viewers {
    border-color: rgba(52, 199, 89, 0.3);
    background: rgba(52, 199, 89, 0.04);
}

.stats-vcs-camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.stats-vcs-camera-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.stats-vcs-camera-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-card,
.settings-section {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

.user-card h3,
.settings-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--accent);
}

.account-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.account-info .info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.account-info .info-row:last-child {
    border-bottom: none;
}

.account-info .label {
    color: var(--text-muted);
}

.account-info .value {
    font-weight: 500;
}

.account-info .status-active {
    color: var(--success);
}

.license-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 16px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 600;
    color: var(--accent);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.license-bar {
    height: 8px;
    background: var(--bg-hover);
    border-radius: 4px;
    overflow: hidden;
}

.license-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s;
}

/* ============================================================================
   Shares View
   ============================================================================ */

.shares-container {
    max-width: 900px;
}

/* Shares Tabs */
/* Shares Filter Bar */
.shares-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-hover);
    border-radius: 8px;
}

.shares-filter-bar .filter-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-right: 4px;
}

.shares-filter-bar .filter-btn {
    padding: 6px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.shares-filter-bar .filter-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.2);
}

.shares-filter-bar .filter-btn.active {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
    font-weight: 600;
}

.shares-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
}

.shares-tab {
    flex: 1;
    padding: 14px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.shares-tab:hover:not(.active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.shares-tab.active {
    background: var(--bg-card);
    color: var(--accent);
}

.shares-tab .tab-count {
    background: rgba(0, 212, 170, 0.2);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.shares-tab.active .tab-count {
    background: var(--accent);
    color: var(--bg-dark);
}

/* My Devices Shares Tab */
.my-devices-shares {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.device-share-card {

/* VCS Device Group Card — one card per VCS device with cameras nested */
.vcs-device-group-card .vcs-camera-shares-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 4px 0 8px;
}

/* Email-share roster inside a VCS group card */
.vcs-email-shares {
    padding: 8px 16px 10px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.vcs-email-shares-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    font-weight: 600;
}
.vcs-email-share-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.vcs-email-share-row.expired {
    opacity: 0.55;
}
.vcs-email-share-icon {
    font-size: 12px;
    flex: 0 0 auto;
}
.vcs-email-share-addr {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    min-width: 0;
}
.vcs-email-share-exp {
    font-size: 11px;
    color: var(--text-muted);
    flex: 0 0 auto;
}
.vcs-email-share-remove {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    line-height: 1;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-dim);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.vcs-email-share-remove:hover {
    background: rgba(248, 81, 73, 0.12);
    color: #f85149;
    border-color: rgba(248, 81, 73, 0.4);
}

.vcs-camera-share-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 8px 20px;
    border-top: 1px solid var(--border);
    gap: 10px;
}

.vcs-camera-share-row:first-child {
    border-top: 1px solid var(--border);
}

.vcs-cam-row-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.vcs-cam-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.vcs-cam-row-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.vcs-cam-share-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.device-share-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.device-share-header .device-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.device-share-header .device-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.device-share-header .device-serial {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

.device-share-actions {
    display: flex;
    gap: 8px;
}

.device-shares-content {
    padding: 16px;
}

.shares-loading,
.shares-not-loaded {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

.no-shares-message {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 14px;
}

.no-shares-message span {
    font-size: 24px;
    display: block;
    margin-bottom: 8px;
}

/* Share Sections (Accepted, Pending, Rejected) */
.share-section {
    margin-bottom: 16px;
}

.share-section:last-child {
    margin-bottom: 0;
}

.share-section-header {
    font-size: 12px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.share-section-header.accepted {
    background: rgba(0, 212, 170, 0.1);
    color: var(--accent);
}

.share-section-header.pending {
    background: rgba(240, 192, 64, 0.1);
    color: #f0c040;
}

.share-section-header.rejected {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.share-section-header .count {
    background: currentColor;
    color: var(--bg-dark);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

/* Invite Items */
.invite-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-hover);
    border-radius: 6px;
    margin-bottom: 6px;
}

.invite-item:last-child {
    margin-bottom: 0;
}

.invite-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.invite-email {
    font-size: 14px;
    color: var(--text);
}

/* ============================================
   DIRECT ACCESS SHARING STYLES
   ============================================ */

.direct-access-section {
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(0, 212, 170, 0.05) 0%, rgba(0, 150, 136, 0.05) 100%);
    border-bottom: 1px solid var(--border);
}

.direct-access-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.direct-access-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.direct-access-label .icon {
    font-size: 16px;
}

.direct-access-hint {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 26px;
    transition: all 0.3s ease;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
    background: white;
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.3);
}

/* Direct Share Active State */
.direct-access-active {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.direct-share-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.live-badge {
    background: #ff4444;
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    animation: pulse-live 2s infinite;
}

.offline-badge {
    background: #666;
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.view-count {
    font-size: 12px;
    color: var(--text-muted);
}

.offline-note {
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
}

.direct-share-options {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}

.audio-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
}

.audio-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.audio-toggle:hover {
    color: var(--text);
}

.direct-share-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 80px;
}

.toggle-switch.small {
    width: 36px;
    height: 20px;
}

.toggle-switch.small .toggle-slider:before {
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
}

.toggle-switch.small input:checked + .toggle-slider:before {
    transform: translateX(16px);
}

.password-input {
    width: 120px;
    padding: 4px 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
    color: #fff;
    font-size: 12px;
}

.password-input::placeholder {
    color: #666;
}

.password-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.password-toggle input[type="text"] {
    font-size: 12px;
}

.password-toggle input[type="text"]::placeholder {
    color: #666;
}

.direct-share-actions {
    display: flex;
    gap: 8px;
}

.direct-access-section.device-offline {
    background: linear-gradient(135deg, rgba(100, 100, 100, 0.05) 0%, rgba(80, 80, 80, 0.05) 100%);
}

.direct-access-offline-hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 8px;
    font-style: italic;
}

.toggle-switch.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.toggle-switch.disabled .toggle-slider {
    cursor: not-allowed;
}

.device-share-card.has-direct-share {
    border: 1px solid rgba(0, 212, 170, 0.3);
}

/* Direct Share Modal */
.direct-share-modal {
    max-width: 420px;
}

.direct-share-modal .modal-body {
    text-align: center;
    padding: 16px 24px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.share-device-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}

.qr-code-container {
    background: white;
    border-radius: 12px;
    padding: 12px;
    margin: 0 auto 12px;
    display: inline-block;
}

.qr-loading {
    width: 168px;
    height: 168px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666;
    gap: 12px;
}

.qr-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #eee;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.qr-code-image {
    display: block;
    width: 168px;
    height: 168px;
}

.qr-fallback {
    width: 200px;
    padding: 20px;
    text-align: center;
    color: #666;
}

.qr-fallback .url-text {
    font-size: 10px;
    word-break: break-all;
    margin-top: 10px;
    color: #999;
}

.share-url-container {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.share-url-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    font-family: monospace;
}

.share-url-input:focus {
    outline: none;
    border-color: var(--accent);
}

.share-info {
    text-align: left;
    background: var(--bg-hover);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
}

.share-info p {
    margin: 6px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.share-info p:first-child {
    margin-top: 0;
}

.share-info p:last-child {
    margin-bottom: 0;
}

/* ── Direct-share expiration editor (QR modal + shares card) ── */
.share-expiry {
    text-align: left;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
}
.share-expiry-status {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.share-expiry-status.has-expiry {
    color: var(--accent);
    font-weight: 600;
}
.share-expiry-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.share-expiry-input,
.card-expiry-input {
    flex: 1 1 180px;
    min-width: 0;
    padding: 7px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    color-scheme: dark;
}

/* Inline expiry rows on the shares-page guest card */
.option-row-expiry .expiry-current {
    font-size: 12px;
    color: var(--text-dim);
}
.option-row-expiry .expiry-current.has-expiry {
    color: var(--accent);
    font-weight: 600;
}
.option-row-expiry-edit {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}
.option-row-expiry-edit .card-expiry-input {
    flex: 1 1 160px;
    padding: 5px 8px;
    font-size: 12px;
}

.share-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 12px;
    color: var(--text-dim);
}

/* Shared With Me Tab */
.shared-with-me-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sharer-group {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.sharer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.sharer-icon {
    font-size: 24px;
}

.sharer-email {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    flex: 1;
}

.sharer-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 4px 10px;
    border-radius: 12px;
}

.shared-devices {
    padding: 12px;
}

.shared-path-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-hover);
    border-radius: 8px;
    margin-bottom: 8px;
}

.shared-path-item:last-child {
    margin-bottom: 0;
}

.shared-device-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    font-size: 18px;
}

.shared-device-name {
    font-weight: 600;
    color: var(--text);
}

.shared-device-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
}

.shared-device-meta .serial {
    font-family: monospace;
}

.shared-status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.shared-status-badge.accepted {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

.shared-status-badge.pending {
    background: rgba(240, 192, 64, 0.15);
    color: #f0c040;
}

.shared-status-badge.rejected {
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
}

/* Share Modal */
.share-modal-device {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 600;
}

.share-modal-device .icon {
    font-size: 20px;
}

/* By Email Tab Styles */
.by-email-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.email-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.email-search {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.email-search input {
    width: 100%;
    padding: 10px 36px 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.email-search input:focus {
    outline: none;
    border-color: var(--accent);
}

.email-search .search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 14px;
}

.email-search .search-clear:hover {
    color: var(--text);
}

.email-sort {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-label {
    font-size: 13px;
    color: var(--text-muted);
}

.sort-btn {
    padding: 6px 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.sort-btn:hover {
    background: var(--bg-card);
    color: var(--text);
}

.sort-btn.active {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

.email-results-count {
    font-size: 13px;
    color: var(--text-muted);
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
}

.no-results span {
    font-size: 32px;
    display: block;
    margin-bottom: 12px;
}

.email-shares-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.email-share-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.email-share-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.email-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.email-icon {
    font-size: 24px;
}

.email-address {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.email-stats {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.email-stats .stat {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
}

.email-stats .stat.accepted {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

.email-stats .stat.pending {
    background: rgba(240, 192, 64, 0.15);
    color: #f0c040;
}

.email-stats .stat.rejected {
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
}

.email-stats .stat.total {
    background: var(--bg-hover);
    color: var(--text-muted);
}

.email-actions {
    display: flex;
    gap: 8px;
}

.email-devices-list {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.email-device-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-hover);
    border-radius: 6px;
}

.email-device-item .device-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.email-device-item .status-indicator {
    font-size: 14px;
}

.email-device-item .device-name {
    font-weight: 500;
    color: var(--text);
}

.email-device-item .device-serial {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
    margin-left: 8px;
}

/* Legacy shares list styles (kept for backward compatibility) */
.shares-list {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
}

.shares-header {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 80px;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-hover);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.share-item {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 80px;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.share-item:last-child {
    border-bottom: none;
}

.share-item .col-device {
    display: flex;
    align-items: center;
    gap: 8px;
}

.perm-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
    border-radius: 4px;
    font-size: 11px;
    margin-right: 4px;
}

.shares-info-section {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
}

.shares-info-section h3 {
    color: var(--accent);
    margin-bottom: 12px;
}

.shares-info-section ul {
    margin: 12px 0 12px 20px;
    color: var(--text-muted);
}

.shares-info-section li {
    margin: 6px 0;
}

.hint {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: 8px;
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-card);
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
}

.modal-close:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body .form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.modal-body select,
.modal-body input[type="email"],
.modal-body input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
}

.modal-body select:focus,
.modal-body input:focus {
    outline: none;
    border-color: var(--accent);
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px !important;
    color: var(--text) !important;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* Camera Controls Modal */
.camera-controls-modal {
    max-width: 420px;
}

.camera-controls-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.device-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-hover);
    border-radius: 8px;
}

.device-status-bar .device-name {
    font-weight: 600;
    color: var(--text);
}

.device-status-bar .device-serial {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.control-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.control-section:last-child {
    border-bottom: none;
}

.control-section.recording-section.is-recording {
    background: rgba(255, 68, 68, 0.1);
    padding: 12px;
    border-radius: 8px;
    margin: -4px;
}

.control-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.recording-badge {
    font-size: 10px;
    color: #ff4444;
    background: rgba(255, 68, 68, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    animation: blink 1s ease-in-out infinite;
}

.recording-duration {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

.control-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.control-buttons.camera-buttons,
.control-buttons.rotation-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.control-buttons.transform-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.control-buttons .btn {
    flex: none;
}

/* Warning button for reset */
.btn-warning {
    background: linear-gradient(135deg, #f0a030 0%, #e09020 100%);
    color: #000;
    border: none;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #ffa020 0%, #f09010 100%);
}

/* Zoom control */
.zoom-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zoom-control input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    outline: none;
}

.zoom-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.zoom-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Controls loading/error states */
.controls-loading,
.controls-error {
    text-align: center;
    padding: 30px 20px;
}

.controls-loading .spinner {
    margin: 0 auto 12px;
}

.controls-error {
    color: var(--text-muted);
}

.controls-error p {
    margin-bottom: 8px;
}

.controls-error .error-detail {
    font-size: 12px;
    color: #ff6b6b;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item label {
    color: var(--text-muted);
    font-size: 14px;
}

.setting-value {
    font-family: monospace;
    font-size: 13px;
}

.setting-item select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 4px;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-dark);
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-input);
}

.btn-success {
    background: var(--success);
    color: var(--bg-dark);
}

.btn-warning {
    background: #f0c040;
    color: #1a1a2e;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
}

.btn-icon-tiny {
    background: none;
    border: none;
    padding: 2px 4px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    vertical-align: middle;
}

.btn-icon-tiny:hover {
    opacity: 1;
}

.btn-block {
    width: 100%;
}

/* ============================================================================
   Login
   ============================================================================ */

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a2e 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 28px;
    color: var(--accent);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.password-input-wrapper {
    position: relative;
}
.password-input-wrapper input {
    padding-right: 44px;
}
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.15s;
}
.password-toggle:hover {
    color: var(--text);
}

.form-hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
}

.error-message {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 13px;
}

/* ============================================================================
   Toast Notifications
   ============================================================================ */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 14px 24px;
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-info {
    border-left: 4px solid var(--accent);
}

/* ============================================================================
   Loading Overlay
   ============================================================================ */

#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 21, 40, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    min-height: 300px;
}

.loading-state .spinner {
    margin-bottom: 16px;
}

.loading-state p {
    font-size: 14px;
}

/* ============================================================================
   Empty State
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
}

.empty-text {
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

/* ============================================================================
   Grid Select
   ============================================================================ */

.btn-active {
    background: var(--accent) !important;
    color: #000 !important;
    border-color: var(--accent) !important;
}

.grid-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 1024px) {
    .filter-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .view-toggle {
        margin-left: 0;
        margin-top: 10px;
    }
    
    .liveview-container {
        flex-direction: column;
    }
    
    .liveview-sidebar {
        width: 100%;
        max-height: 200px;
    }
}

/* ============================================================================
   MOBILE RESPONSIVE STYLES
   ============================================================================ */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow);
    /* iOS touch fixes */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.mobile-menu-toggle:active {
    background: var(--bg-hover);
}

/* Mobile Header Bar */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 999;
    align-items: center;
    padding: 0 16px 0 60px;
}

.mobile-header h1 {
    font-size: 16px;
    color: var(--accent);
    margin: 0;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    /* iOS touch fix */
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.sidebar-overlay.visible {
    display: block;
}

/* Tablet Styles (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 180px;
    }
    
    .main-content {
        margin-left: 180px;
    }
    
    .devices-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .liveview-grid.grid-4,
    .liveview-grid.grid-6 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .liveview-slot {
        min-height: 200px;
    }
    
    .map-sidebar {
        width: 280px;
    }
    
    /* iPad touch improvements */
    .nav-menu li {
        padding: 14px 20px;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.2);
    }
    
    .btn {
        min-height: 44px;
    }
}

/* Mobile/Tablet Portrait Styles (< 768px) */
@media (max-width: 768px) {
    /* Prevent horizontal scroll on mobile */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    .app-layout {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Show mobile menu button */
    .mobile-menu-toggle {
        display: block;
    }
    
    .mobile-header {
        display: flex;
    }
    
    /* Sidebar becomes slide-out drawer */
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 20px var(--shadow);
        background: var(--bg-card);
        z-index: 1000; /* Above overlay (999) */
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Make sure nav items are fully visible and clickable on mobile */
    .sidebar .nav-menu {
        opacity: 1;
    }
    
    .sidebar .nav-menu li {
        opacity: 1;
        pointer-events: auto;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.2);
        cursor: pointer;
    }
    
    .sidebar .nav-menu li span {
        display: inline;
        opacity: 1;
    }
    
    /* Hide text labels in sidebar when collapsed - but show when open on mobile */
    .sidebar.open .sidebar-header h1,
    .sidebar.open .sidebar-header .user-badge,
    .sidebar.open .nav-menu li span,
    .sidebar.open .license-info {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
        padding: 70px 12px 12px 12px;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Content header adjustments */
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .content-header h2 {
        font-size: 20px;
    }
    
    .header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .header-actions .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }
    
    /* Filter bar mobile */
    .filter-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .filter-bar .search-box {
        width: 100%;
    }
    
    .filter-bar input[type="text"] {
        width: 100%;
    }
    
    .view-toggle {
        width: 100%;
        justify-content: center;
    }
    
    /* Devices grid - single column */
    .devices-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* Device card mobile optimizations */
    .device-card {
        padding: 14px;
    }
    
    .device-card .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .device-card .card-actions {
        width: 100%;
        display: flex;
        gap: 8px;
        margin-top: 8px;
    }
    
    .device-card .card-actions .btn {
        flex: 1;
        padding: 10px;
        font-size: 14px;
    }
    
    /* Live View mobile */
    .liveview-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 70px);
    }
    
    .liveview-sidebar {
        width: 100%;
        min-height: 120px;
        max-height: 40vh;
        order: 2;
        border-right: none;
        border-top: 1px solid var(--border);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .liveview-sidebar .camera-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
    }
    
    .liveview-sidebar .camera-item {
        padding: 12px;
        margin: 4px 8px;
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.3);
        touch-action: manipulation;
    }
    
    .liveview-sidebar .hint {
        display: none;
    }
    
    /* Add tap hint for mobile */
    .liveview-sidebar .camera-header::after {
        content: "Tap camera to add";
        display: block;
        font-size: 10px;
        color: var(--text-muted);
        margin-top: 2px;
    }
    
    .liveview-main {
        order: 1;
        flex: 1;
        min-height: 250px;
        max-height: 55vh;
    }
    
    .liveview-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        gap: 8px;
        padding: 8px;
        height: auto !important;
    }
    
    .liveview-grid.grid-1 {
        grid-template-columns: 1fr !important;
    }
    
    .liveview-grid.grid-1 .liveview-slot {
        max-height: 55vh;
    }
    
    .liveview-grid.grid-4,
    .liveview-grid.grid-6,
    .liveview-grid.grid-9 {
        grid-template-columns: 1fr !important;
    }
    
    .liveview-slot {
        min-height: 180px;
        max-height: 280px;
        aspect-ratio: 16/9;
    }
    
    .slot-video {
        max-height: 100%;
    }
    
    .video-feed {
        max-height: 100%;
    }
    
    .video-slot {
        min-height: 180px;
        max-height: 280px;
        aspect-ratio: 16/9;
    }
    
    .video-slot .slot-overlay {
        padding: 8px;
    }
    
    .video-slot .slot-controls {
        gap: 4px;
    }
    
    .video-slot .slot-controls .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Toolbar mobile */
    .liveview-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }
    
    .liveview-toolbar .grid-select {
        flex: 1;
        min-width: 100px;
    }
    
    /* Map view mobile */
    .map-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 70px);
    }
    
    .map-sidebar {
        width: 100%;
        min-height: 120px;
        max-height: 35vh;
        order: 2;
        border-right: none;
        border-top: 1px solid var(--border);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .map-sidebar .device-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .map-sidebar .device-item {
        padding: 12px;
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.3);
    }
    
    .map-main {
        order: 1;
        flex: 1;
        min-height: 350px;
    }
    
    .leaflet-map {
        min-height: 350px;
    }
    
    /* Map popup mobile */
    .leaflet-popup-content-wrapper {
        max-width: 280px;
    }
    
    .map-popup-btn {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    /* Device detail mobile */
    .device-detail-container {
        flex-direction: column;
    }
    
    .device-detail-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
    }
    
    .device-detail-main {
        padding: 12px;
    }
    
    .device-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .device-actions .action-btn {
        padding: 14px 10px;
        font-size: 13px;
    }
    
    /* Tab navigation mobile */
    .tab-nav {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .tab-nav button {
        flex: 1;
        min-width: 80px;
        padding: 10px 8px;
        font-size: 12px;
    }
    
    /* Modal mobile - full screen */
    .modal-overlay {
        padding: 0;
    }
    
    .modal-content,
    .modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
    }
    
    .modal-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 10;
    }
    
    .modal-body {
        padding: 16px;
        overflow-y: auto;
        flex: 1;
    }
    
    .modal-footer {
        padding: 16px;
        position: sticky;
        bottom: 0;
        background: var(--bg-card);
    }
    
    /* Map video modal mobile */
    .map-video-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
    }
    
    .map-video-container {
        max-height: 50vh;
    }
    
    /* Form inputs mobile - larger touch targets */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="search"],
    input[type="number"],
    select,
    textarea {
        padding: 14px 12px;
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 48px;
    }
    
    /* Buttons mobile - larger touch targets */
    .btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .btn-xs {
        padding: 8px 12px;
        min-height: 36px;
    }
    
    .btn-sm {
        padding: 10px 14px;
        min-height: 40px;
    }
    
    /* Toast notifications mobile */
    .toast {
        left: 12px;
        right: 12px;
        max-width: none;
        bottom: 70px;
    }
    
    /* Tables mobile */
    .data-table {
        display: block;
        overflow-x: auto;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
        font-size: 13px;
    }
    
    /* Stats cards mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 14px;
    }
    
    .stat-card .value {
        font-size: 24px;
    }
    
    /* Login page mobile */
    .login-container {
        padding: 16px;
    }
    
    .login-card {
        padding: 24px 20px;
        width: 100%;
        max-width: 100%;
    }
    
    /* Device list mobile */
    .device-list {
        gap: 8px;
    }
    
    .device-list-item {
        padding: 12px;
    }
    
    /* Iframe container mobile */
    .iframe-container {
        height: calc(100vh - 200px);
        min-height: 400px;
    }
    
    /* Share modal mobile */
    .share-device-modal .modal-content {
        width: 100%;
    }
}

/* ==========================================================================
   PHONE SPECIFIC STYLES (< 480px) - iPhone, Android phones
   Does NOT affect iPad or desktop
   ========================================================================== */
@media (max-width: 480px) {
    /* Phone base layout */
    .main-content {
        padding: 60px 8px 8px 8px;
    }
    
    .content-header {
        padding: 0 4px;
        margin-bottom: 12px;
    }
    
    .content-header h2 {
        font-size: 18px;
    }
    
    /* ===== LIVE VIEW - PHONE LAYOUT ===== */
    .liveview-container {
        flex-direction: column;
        height: calc(100vh - 60px);
        gap: 0;
        padding: 0;
    }
    
    /* Video grid takes most of screen */
    .liveview-grid {
        order: 1;
        flex: 1;
        min-height: 40vh;
        max-height: 60vh;
        height: auto !important;
        padding: 4px !important;
        gap: 4px !important;
    }
    
    /* Single camera - full width, good height */
    .liveview-grid.grid-1 {
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr !important;
        max-height: 65vh;
    }
    
    .liveview-grid.grid-1 .liveview-slot {
        max-height: none;
        height: 100%;
        aspect-ratio: 16/9;
    }
    
    /* Multi-camera on phone - 2 column grid */
    .liveview-grid.grid-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        grid-template-rows: repeat(2, 1fr) !important;
    }
    
    .liveview-grid.grid-6,
    .liveview-grid.grid-9 {
        grid-template-columns: repeat(2, 1fr) !important;
        grid-template-rows: auto !important;
        max-height: 55vh;
        overflow-y: auto;
    }
    
    .liveview-slot {
        min-height: 80px;
        max-height: none;
        aspect-ratio: 16/9;
        border-radius: 6px;
    }
    
    .slot-video {
        height: 100%;
    }
    
    .video-feed {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    /* Camera list - collapsible bottom panel */
    .liveview-sidebar {
        order: 2;
        width: 100%;
        min-height: 50px;
        max-height: 35vh;
        border-top: 2px solid var(--accent);
        background: var(--bg-card);
        transition: max-height 0.3s ease;
    }
    
    .liveview-sidebar .camera-header {
        padding: 8px 12px;
        background: var(--bg-hover);
        position: sticky;
        top: 0;
        z-index: 5;
    }
    
    .liveview-sidebar .camera-header h4 {
        font-size: 13px;
        margin: 0;
    }
    
    .liveview-sidebar .camera-header::after {
        content: "Tap to add • Scroll for more";
        font-size: 10px;
    }
    
    .liveview-sidebar .sidebar-controls {
        display: none; /* Hide search on phone - too cramped */
    }
    
    .liveview-sidebar .camera-list {
        padding: 4px;
        max-height: calc(35vh - 50px);
    }
    
    .liveview-sidebar .camera-item {
        padding: 10px 12px;
        margin: 3px 0;
        border-radius: 8px;
        min-height: 44px;
    }
    
    .liveview-sidebar .camera-item .camera-name {
        font-size: 13px;
    }
    
    .liveview-sidebar .camera-add-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
    
    .liveview-sidebar .camera-info-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .liveview-sidebar .hint {
        display: none;
    }
    
    /* Toolbar - compact for phone */
    .liveview-toolbar {
        padding: 6px 8px;
        gap: 6px;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .liveview-toolbar .btn {
        padding: 8px 10px;
        font-size: 12px;
        white-space: nowrap;
    }
    
    .liveview-toolbar .grid-select {
        min-width: 70px;
    }
    
    /* Slot controls on phone */
    .slot-header {
        padding: 4px 8px;
    }
    
    .slot-title {
        font-size: 11px;
    }
    
    .slot-controls-btn {
        padding: 4px 6px;
        font-size: 10px;
    }
    
    /* ===== MAP VIEW - PHONE LAYOUT ===== */
    .map-layout {
        flex-direction: column;
        height: calc(100vh - 60px);
        gap: 0;
    }
    
    .map-container-wrapper {
        order: 1;
        flex: 1;
        min-height: 45vh;
    }
    
    .leaflet-map {
        height: 100% !important;
        min-height: 45vh;
    }
    
    .map-toolbar {
        padding: 6px 8px;
        gap: 6px;
    }
    
    .map-sidebar {
        order: 2;
        width: 100%;
        min-height: 80px;
        max-height: 45vh;
        border-radius: 0;
        border-top: 2px solid var(--accent);
    }
    
    .map-sidebar-header {
        padding: 8px 12px;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 5;
    }
    
    .map-sidebar-header h3 {
        font-size: 13px;
    }
    
    .map-device-list {
        padding: 4px;
        max-height: calc(45vh - 80px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .map-device-item {
        padding: 10px 12px;
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.3);
    }
    
    .selected-device-info {
        padding: 10px;
        max-height: 150px;
        overflow-y: auto;
    }
    
    .selected-device-info .device-actions {
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .selected-device-info .device-actions .btn {
        flex: 1 1 45%;
        min-height: 44px;
    }
    
    /* Map popup on phone */
    .leaflet-popup-content-wrapper {
        max-width: 260px;
    }
    
    .map-popup-content {
        padding: 8px;
    }
    
    .map-popup-video {
        max-height: 150px;
    }
    
    /* ===== DEVICES LIST - PHONE LAYOUT ===== */
    .devices-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
        padding: 0 4px;
    }
    
    .device-card {
        padding: 12px;
        overflow: visible;
    }
    
    .device-card-header {
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .device-card-header .device-name {
        font-size: 14px;
        flex: 1;
        min-width: 100px;
    }
    
    .device-badges {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .device-card-body {
        padding: 8px 0;
    }
    
    .device-card-actions {
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px 12px;
    }
    
    .device-card-actions .btn {
        flex: 1 1 45%;
        min-width: 70px;
        padding: 10px 8px;
        font-size: 12px;
        min-height: 44px;
    }
    
    /* ===== FILTER BAR - PHONE ===== */
    .filter-bar {
        padding: 8px;
        gap: 8px;
    }
    
    .filter-bar .search-box {
        width: 100%;
    }
    
    .filter-bar input[type="text"] {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .view-toggle {
        width: 100%;
    }
    
    .view-toggle .btn {
        flex: 1;
        padding: 10px;
    }
    
    /* ===== MODALS - PHONE ===== */
    .modal-content {
        width: 95vw !important;
        max-width: none;
        margin: 10px;
        max-height: 90vh;
    }
    
    .camera-controls-panel {
        padding: 12px;
    }
    
    .control-group {
        padding: 10px;
    }
    
    .control-buttons {
        gap: 6px;
    }
    
    .control-buttons .btn {
        padding: 10px 12px;
        font-size: 12px;
        min-height: 44px;
    }
    
    /* ===== STATS VIEW - PHONE ===== */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    /* ===== GENERAL PHONE TOUCH IMPROVEMENTS ===== */
    button, .btn, a, .clickable {
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(0, 212, 170, 0.2);
    }
    
    input, select, textarea {
        font-size: 16px !important; /* Prevent iOS zoom on focus */
        min-height: 44px;
    }
    
    /* Scrollable areas */
    .camera-list,
    .device-list,
    .devices-grid {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

/* Phone landscape mode */
@media (max-width: 480px) and (orientation: landscape) {
    .main-content {
        padding-top: 50px;
    }
    
    .mobile-header {
        height: 50px;
    }
    
    .liveview-container {
        flex-direction: row;
        height: calc(100vh - 50px);
    }
    
    .liveview-grid {
        flex: 1;
        height: 100%;
        max-height: 100%;
        order: 1;
    }
    
    .liveview-sidebar {
        width: 120px;
        max-height: 100%;
        height: 100%;
        order: 2;
        border-top: none;
        border-left: 2px solid var(--accent);
    }
    
    .liveview-sidebar .camera-list {
        max-height: calc(100% - 40px);
    }
    
    .liveview-sidebar .camera-item {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    .liveview-grid.grid-1 .liveview-slot {
        height: 100%;
        max-height: 100%;
    }
    
    /* Map landscape */
    .map-container {
        flex-direction: row;
    }
    
    .map-main {
        flex: 1;
        min-height: 100%;
    }
    
    .map-sidebar {
        width: 120px;
        max-height: 100%;
        border-top: none;
        border-left: 2px solid var(--accent);
    }
}

/* Small phones (< 400px) */
@media (max-width: 400px) {
    .mobile-header h1 {
        font-size: 14px;
    }
    
    .content-header h2 {
        font-size: 18px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .device-actions {
        grid-template-columns: 1fr;
    }
    
    .header-actions .btn {
        min-width: 100%;
    }
    
    .liveview-toolbar {
        flex-direction: column;
    }
    
    .liveview-toolbar > * {
        width: 100%;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 900px) and (orientation: landscape) {
    .main-content {
        padding-top: 60px;
    }
    
    .liveview-container {
        flex-direction: row;
        height: calc(100vh - 60px);
    }
    
    .liveview-sidebar {
        width: 200px;
        max-height: none;
        order: 1;
        border-right: 1px solid var(--border);
        border-top: none;
    }
    
    .liveview-main {
        order: 2;
    }
    
    .liveview-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .video-slot {
        min-height: 150px;
    }
    
    .map-container {
        flex-direction: row;
        height: calc(100vh - 60px);
    }
    
    .map-sidebar {
        width: 220px;
        max-height: none;
        order: 1;
        border-right: 1px solid var(--border);
        border-top: none;
    }
    
    .map-main {
        order: 2;
    }
}

/* iPad / Tablet specific */
@media (min-width: 768px) and (max-width: 1024px) {
    .devices-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .liveview-grid.grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .liveview-grid.grid-6 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .liveview-grid.grid-9 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-menu li {
        padding: 16px 20px;
        min-height: 52px;
    }
    
    .device-card:hover {
        transform: none; /* Disable hover effects */
    }
    
    .btn:hover {
        transform: none;
    }
    
    /* Active states instead of hover */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .device-card:active {
        transform: scale(0.99);
    }
    
    /* Remove hover-only elements */
    .card-actions-hover {
        opacity: 1;
        visibility: visible;
    }
    
    /* Scrolling improvements */
    .device-list,
    .liveview-sidebar,
    .map-sidebar {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    /* Disable text selection on interactive elements */
    .btn,
    .nav-menu li,
    .device-card,
    .tab-nav button {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Safe area insets for notched devices (iPhone X+) */
@supports (padding: max(0px)) {
    .sidebar {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    .main-content {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .mobile-header {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(56px + env(safe-area-inset-top));
    }
    
    @media (max-width: 768px) {
        .main-content {
            padding-top: calc(70px + env(safe-area-inset-top));
        }
    }
    
    .toast {
        bottom: max(70px, calc(70px + env(safe-area-inset-bottom)));
    }
}

/* ============================================================================
   Password Reset Flow
   ============================================================================ */

.login-footer {
    margin-top: 24px;
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.forgot-password-link,
.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
}

.forgot-password-link:hover,
.back-link:hover {
    color: #4ae3c0;
    text-decoration: underline;
}

.help-text {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.success-message {
    text-align: center;
    padding: 24px;
    margin-bottom: 24px;
}

.success-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.success-message p {
    color: var(--text);
    margin: 8px 0;
    line-height: 1.6;
}

.success-message p:first-of-type {
    font-size: 16px;
    font-weight: 500;
    color: var(--success);
}

/* Improved form input styling for password reset */
.login-card input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.login-card input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-card button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================================================
   Custom Scrollbar Styling
   ============================================================================ */

/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* Camera list in live view sidebar */
.camera-list {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.camera-list::-webkit-scrollbar {
    width: 4px;
}

.camera-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.camera-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Table scrollbar */
.device-table-container {
    scrollbar-width: thin;
}

.device-table-container::-webkit-scrollbar {
    height: 6px;
}

/* Sidebar scrollbar */
.liveview-sidebar {
    scrollbar-width: thin;
}

.liveview-sidebar::-webkit-scrollbar {
    width: 4px;
}

/* ============================================================================
   Live View Sidebar Compact Controls
   ============================================================================ */

/* Top row: search input + collapse button */
.liveview-sidebar .sidebar-top-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.liveview-sidebar .sidebar-top-row .sidebar-search {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.sidebar-refresh-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
    transition: color 0.2s, transform 0.2s;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-refresh-btn:hover {
    color: var(--accent);
}

.sidebar-refresh-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.sidebar-refresh-btn.spinning {
    animation: spin 0.7s linear infinite;
    color: var(--accent);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.sidebar-collapse-btn-lv {
    flex-shrink: 0;
    background: var(--bg-hover);
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 11px;
    padding: 5px 8px;
    cursor: pointer;
    line-height: 1;
}
.sidebar-collapse-btn-lv:hover {
    color: var(--text);
    background: var(--bg-active);
}

/* When collapsed: hide everything except the top row, shrink width */
.liveview-sidebar.panel-collapsed {
    width: 42px !important;
    min-width: 42px !important;
    padding: 10px 6px;
}

.liveview-sidebar.panel-collapsed .sidebar-search {
    display: none;
}

.liveview-sidebar.panel-collapsed .sidebar-top-row {
    justify-content: center;
    margin-bottom: 0;
}

.sidebar-panel-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sidebar-panel-body.panel-hidden {
    display: none;
}

.liveview-sidebar .sidebar-search {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.liveview-sidebar .sidebar-empty {
    font-size: 11px;
    color: var(--text-dim);
    padding: 4px 12px 8px;
    margin: 0;
}

/* Hide search when panel is collapsed */
.liveview-sidebar.panel-collapsed .sidebar-search {
    display: none;
}

.sidebar-controls {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.search-input.compact {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 4px;
    min-width: 0;
}

.sort-select.compact {
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 4px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    min-width: 70px;
}

.sort-select.compact:focus {
    outline: none;
    border-color: var(--accent);
}

.liveview-sidebar .hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 8px 0;
}

/* ============================================================================
   Connection Status Indicator
   ============================================================================ */

#connection-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    display: none;
}

.connection-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    animation: slideDown 0.3s ease-out;
}

.connection-indicator.offline {
    background: linear-gradient(135deg, #3d0a0a 0%, #2d0808 100%);
    color: #ff6b6b;
    border-bottom: 2px solid #ff6b6b;
}

.connection-indicator.reconnecting {
    background: linear-gradient(135deg, #3d3a0a 0%, #2d2808 100%);
    color: #f0c040;
    border-bottom: 2px solid #f0c040;
}

.connection-indicator .indicator-icon {
    font-size: 18px;
    animation: pulse 1.5s ease-in-out infinite;
}

.connection-indicator .indicator-text {
    flex: 1;
}

.connection-indicator .indicator-countdown {
    font-size: 12px;
    opacity: 0.8;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile touch drag feedback */
.touch-dragging {
    opacity: 0.6;
    transform: scale(0.95);
    background: var(--accent) !important;
    color: var(--bg) !important;
}

.mobile-hint {
    display: none;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 4px;
}

@media (hover: none) and (pointer: coarse) {
    .mobile-hint {
        display: block;
    }
}

/* Prevent text selection during touch drag */
.camera-item {
    touch-action: none;
}


/* Online count in sidebar */
.online-count {
    font-size: 11px;
    color: #00d4aa;
    font-weight: normal;
    opacity: 0.9;
}

/* Shares page improvements */
.shares-load-prompt {
    background: var(--bg-hover);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.device-share-card.minimal {
    padding: 12px;
}

.device-share-card.minimal .device-shares-content {
    display: none;
}

.more-devices-note {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
    font-style: italic;
}

.no-devices-message {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Stats page improvements */
.stats-device-badges {
    display: flex;
    gap: 8px;
    align-items: center;
}

.bitrate-badge {
    background: var(--bg-hover);
    color: var(--primary);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.stats-viewers-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px;
}

.stats-viewers-table th {
    text-align: left;
    padding: 8px 12px;
    background: var(--bg-hover);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-viewers-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.stats-viewers-table tr:last-child td {
    border-bottom: none;
}

.stats-viewers-table tr.viewer-connected {
    background: rgba(0, 212, 170, 0.05);
}

.viewer-user {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-icon {
    font-size: 14px;
}

.user-name {
    font-weight: 500;
}

.viewer-ip {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.viewer-bitrate {
    font-family: monospace;
    font-size: 12px;
    color: var(--primary);
}

.status-badge.checking {
    background: rgba(240, 192, 64, 0.2);
    color: #f0c040;
}

.stats-no-viewers {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
}

.stats-device-meta {
    display: flex;
    gap: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Remember me checkbox and invite link */
.remember-me-group {
    margin-bottom: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.login-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.invite-link {
    display: block;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    padding: 10px 16px;
    background: rgba(0, 212, 170, 0.1);
    border-radius: 8px;
    margin-top: 8px;
}

.invite-link:hover {
    color: #fff;
    background: var(--primary);
    text-decoration: none;
}

.login-footer {
    text-align: center;
    margin-top: 20px;
}

.login-footer .forgot-password-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
}

.login-footer .forgot-password-link:hover {
    text-decoration: underline;
}

/* Direct URL link in device info */
.direct-url-link {
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
    font-family: monospace;
    font-size: 12px;
}

.direct-url-link:hover {
    text-decoration: underline;
}

/* Map marker recording state */
.map-marker.recording {
    animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Video stats bar - absolute positioned when standalone (outside slot-footer) */
.video-stats-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.85);
    padding: 4px 10px;
    font-size: 11px;
    font-family: 'Consolas', 'Monaco', monospace;
    color: #0f0;
    z-index: 15;
}

/* Video stats bar - sibling of slot-footer, sits just above the buttons overlay.
   In grid modes (4/6/9/16): positioned absolute above the footer.
   In 1-grid: normal flow (below video, above footer). */

/* 1-grid: stats bar is in normal flow (not absolute), sits between video and footer */
.liveview-grid.grid-1 .liveview-slot .video-stats-bar,
.liveview-slot .video-stats-bar {
    position: static;
    bottom: auto;
    z-index: auto;
    opacity: 1;
    background: rgba(8, 12, 22, 0.7);
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 10px;
    padding: 3px 8px;
    display: flex;
    gap: 10px;
    color: var(--accent);
    pointer-events: auto;
    transition: none;
}

/* Grid mode: stats bar is inside slot-footer (normal flow), same fade as footer */
.liveview-grid.grid-4 .liveview-slot .video-stats-bar,
.liveview-grid.grid-6 .liveview-slot .video-stats-bar,
.liveview-grid.grid-9 .liveview-slot .video-stats-bar,
.liveview-grid.grid-16 .liveview-slot .video-stats-bar {
    position: static;
    bottom: auto;
    z-index: auto;
    background: rgba(8, 12, 22, 0.88);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    border-top: none;
    font-size: 9px;
    padding: 3px 6px;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    color: var(--accent);
    opacity: 1;
    transition: none;
    pointer-events: auto;
    order: -1;  /* appear before slot-footer-buttons in flex column */
    overflow: hidden;
    white-space: nowrap;
    min-width: 0;
}

/* Tighter still on 9- and 16-grid where each slot is much narrower */
.liveview-grid.grid-9 .liveview-slot .video-stats-bar,
.liveview-grid.grid-16 .liveview-slot .video-stats-bar {
    font-size: 8px;
    gap: 4px;
    padding: 2px 4px;
}

/* No separate hover rule needed — slot-footer visibility handles it */

/* When Stats toggle is ON: keep stats bar and footer visible without hover */
.liveview-grid.stats-on .liveview-slot .video-stats-bar {
    opacity: 1;
}
.liveview-grid.stats-on .liveview-slot .slot-header,
.liveview-grid.stats-on .liveview-slot .slot-footer {
    opacity: 1;
    pointer-events: auto;
    background: rgba(8, 12, 22, 0.88);
}

.video-stats-bar span {
    white-space: nowrap;
}

.video-stats-bar span::before {
    content: '|';
    margin-right: 4px;
    opacity: 0.5;
    color: #666;
}

.video-stats-bar span:first-child::before {
    content: '';
    margin-right: 0;
}

/* Share count badge and summary styles */
.share-count-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: 500;
}

.shares-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-radius: 8px;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.shares-offline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    user-select: none;
    white-space: nowrap;
}

.shares-offline-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.device-share-card.has-shares {
    border-left: 3px solid var(--accent);
}

.no-devices-message {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.show-more-offline {
    text-align: center;
    padding: 12px;
}

.show-more-offline .btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
}

.show-more-offline .btn-link:hover {
    text-decoration: underline;
}

.no-shares-message {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ==================== VCS Device Styles ==================== */

.vcs-device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.vcs-device-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.vcs-device-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.vcs-device-card.online {
    border-left: 3px solid var(--success);
}

.vcs-device-card.offline {
    opacity: 0.8;
}

.vcs-device-card .device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.vcs-device-card .device-name {
    font-weight: 600;
    font-size: 15px;
}

.vcs-device-card .device-status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
}

.vcs-device-card .device-status.online {
    background: rgba(40, 167, 69, 0.15);
    color: var(--success);
}

.vcs-device-card .device-status.offline {
    background: rgba(108, 117, 125, 0.15);
    color: var(--text-muted);
}

.vcs-device-card .device-card-body {
    padding: 12px 16px;
}

.vcs-device-card .device-info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.vcs-device-card .device-info-row:last-child {
    border-bottom: none;
}

.vcs-device-card .device-info-row .label {
    color: var(--text-muted);
}

.vcs-device-card .device-info-row .value {
    color: var(--text);
    font-family: monospace;
    font-size: 12px;
}

.vcs-device-card .device-card-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
}

.vcs-device-card .device-card-actions .btn {
    flex: 1;
}

/* VCS Modal styles */
.input-with-prefix {
    display: flex;
    align-items: center;
}

.input-with-prefix .input-prefix,
.input-with-prefix .input-suffix {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 13px;
    font-family: monospace;
}

.input-with-prefix .input-prefix {
    border-right: none;
    border-radius: 8px 0 0 8px;
}

.input-with-prefix .input-suffix {
    border-left: none;
    border-radius: 0 8px 8px 0;
}

.input-with-prefix input {
    border-radius: 0;
    flex: 1;
    min-width: 80px;
}

.form-divider {
    text-align: center;
    color: var(--text-muted);
    margin: 16px 0;
    font-size: 12px;
}

.form-section {
    margin: 16px 0 8px 0;
}

.form-section .section-label {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
}

.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.test-result {
    padding: 12px;
    border-radius: 8px;
    margin: 16px 0;
    text-align: center;
    font-size: 14px;
}

.test-result.testing {
    background: rgba(255, 193, 7, 0.15);
    color: #ffc107;
}

.test-result.success {
    background: rgba(40, 167, 69, 0.15);
    color: var(--success);
}

.test-result.error {
    background: rgba(220, 53, 69, 0.15);
    color: var(--danger);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-actions .btn {
    flex: 1;
}

/* Additional VCS form styles */
.form-section-label {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    margin: 20px 0 8px 0;
}

.form-help-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    border-radius: 0;
    flex: 1;
}

.input-group .input-group-text {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 13px;
    font-family: monospace;
    display: flex;
    align-items: center;
}

.input-group .input-group-text:first-child {
    border-right: none;
    border-radius: 8px 0 0 8px;
}

.input-group .input-group-text:last-child {
    border-left: none;
    border-radius: 0 8px 8px 0;
}

.form-or-divider {
    text-align: center;
    color: var(--text-muted);
    margin: 16px 0;
    font-size: 12px;
    position: relative;
}

.form-or-divider::before,
.form-or-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 30px);
    height: 1px;
    background: var(--border);
}

.form-or-divider::before {
    left: 0;
}

.form-or-divider::after {
    right: 0;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.required {
    color: var(--danger);
}

/* Alert styles for VCS modal */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px 0;
    font-size: 14px;
}

.alert-success {
    background: rgba(40, 167, 69, 0.15);
    color: var(--success);
    border: 1px solid rgba(40, 167, 69, 0.3);
}

.alert-danger {
    background: rgba(220, 53, 69, 0.15);
    color: var(--danger);
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.alert-info {
    background: rgba(255, 193, 7, 0.15);
    color: #ffc107;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

/* Filter bar additions */
.filter-count {
    color: var(--text);
    font-weight: 500;
}

.filter-help {
    color: var(--text-muted);
    font-size: 13px;
    margin-left: auto;
}

/* Device info styles */
.device-info {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.device-info:last-child {
    border-bottom: none;
}

.device-info .label {
    color: var(--text-muted);
}

.device-info .value {
    color: var(--text);
}

.device-info .value.monospace {
    font-family: monospace;
    font-size: 12px;
}

/* Device actions */
.device-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
}

.modal-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 16px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
    border-radius: 0 0 12px 12px;
}

.modal-footer .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* VCS Device List Styles */
.vcs-device-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.vcs-device-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.vcs-device-card.online {
    border-left: 4px solid var(--success);
}

.vcs-device-card.offline {
    opacity: 0.7;
}

.vcs-device-header {
    padding: 16px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.vcs-device-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.vcs-device-title .device-name {
    font-weight: 600;
    font-size: 16px;
}

.vcs-device-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.vcs-device-meta .separator {
    opacity: 0.5;
}

/* The shared .device-model rule carries margin-bottom:8px (for the device list).
   Inside this centered flex row that bottom margin pushes the text upward, so it
   reads as "raised". Neutralise margins and match the row's size/line so the
   model + firmware sit on the same baseline as everything else. */
.vcs-device-meta .device-model,
.vcs-device-meta .device-fw {
    margin: 0;
    font-size: 13px;
    line-height: 1;
    color: var(--text-muted);
}

.vcs-camera-list {
    padding: 12px 16px;
}

.vcs-camera-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg-hover);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.vcs-camera-item:last-child {
    margin-bottom: 0;
}

.vcs-camera-item:hover {
    border-color: var(--accent);
}

.camera-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.camera-icon {
    font-size: 18px;
}

.camera-name {
    font-weight: 500;
}

.camera-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.vcs-no-cameras {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
}

.vcs-no-cameras p {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.vcs-device-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border);
}

/* VCS Camera in Live View */
.camera-list-separator {
    padding: 8px 12px;
    margin: 8px 0;
    background: var(--bg-hover);
    border-radius: 8px;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted);
}

.camera-item.vcs-camera {
    border-left: 3px solid var(--accent);
}

.camera-item.vcs-camera.disabled {
    opacity: 0.6;
}

.vcs-badge {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}

/* VCS Device hierarchy in Live View sidebar */
.vcs-device-header-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-hover);
    margin-top: 4px;
    margin-bottom: 2px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.vcs-device-header-item:hover {
    background: var(--bg-input);
}

.vcs-reload-btn {
    font-size: 11px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.2s;
    padding: 2px;
}

.vcs-device-header-item:hover .vcs-reload-btn {
    opacity: 0.8;
}

.vcs-reload-btn:hover {
    opacity: 1 !important;
    transform: scale(1.2);
}

.vcs-reload-btn.spinning {
    animation: spin 0.8s linear infinite;
    opacity: 1 !important;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.vcs-device-header-item .camera-name {
    flex: 1;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vcs-camera-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 8px 24px; /* Indented */
    background: var(--bg-hover);
    margin-left: 8px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s;
}

.vcs-camera-item:hover {
    background: var(--bg-input);
}

.vcs-camera-item.in-use {
    opacity: 0.7;
}

.vcs-camera-item.disabled {
    opacity: 0.5;
    cursor: default;
    font-style: italic;
}

.vcs-camera-item.camera-offline {
    opacity: 0.5;
}

.vcs-camera-item.camera-offline .camera-name {
    color: var(--text-secondary);
}

.vcs-camera-item .camera-name {
    flex: 1;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* VCS device expand/collapse */
.vcs-expand-icon {
    font-size: 10px;
    color: var(--text-secondary);
    margin-right: 4px;
    transition: transform 0.2s;
}

.vcs-device-header-item:hover {
    background: var(--bg-card);
}

.vcs-device-header-item:hover .vcs-expand-icon {
    color: var(--accent);
}

/* VCS reconnecting overlay */
.reconnecting-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 10;
}

.reconnecting-overlay .spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.reconnecting-overlay p {
    margin-top: 10px;
    font-size: 12px;
}

/* VCS error state */
.video-placeholder.error {
    background: rgba(220, 53, 69, 0.1);
    border: 1px dashed var(--danger);
}

.video-placeholder .error-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

/* ============================================================================
   Collapsible Sidebar
   ============================================================================ */

.sidebar-collapse-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    font-size: 12px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.sidebar-collapse-btn:hover {
    opacity: 1;
    color: var(--accent);
}

.sidebar-header {
    position: relative;
}

/* Hide elements when collapsed */
.sidebar-collapsed .sidebar-hide-collapsed,
.sidebar-collapsed .nav-text,
.sidebar-collapsed .sidebar-title-text,
.sidebar-collapsed .online-count {
    display: none !important;
}

/* Show elements only when collapsed */
.sidebar-show-collapsed {
    display: none !important;
}

.sidebar-collapsed .sidebar-show-collapsed {
    display: inline-flex !important;
}

/* Collapsed sidebar width */
.sidebar-collapsed .sidebar {
    width: 60px;
    min-width: 60px;
}

.sidebar-collapsed .sidebar h1 {
    font-size: 20px;
    text-align: center;
    padding-right: 0;
}

.sidebar-collapsed .nav-menu li {
    justify-content: center;
    padding: 12px 0;
}

.sidebar-collapsed .nav-icon {
    margin-right: 0;
    font-size: 20px;
}

.sidebar-collapsed .sidebar-footer {
    padding: 10px 5px;
    text-align: center;
}

.sidebar-collapsed .sidebar-footer .btn {
    width: 40px;
    padding: 8px;
}

.sidebar-collapsed .collapse-icon {
    transform: rotate(180deg);
}

/* Adjust main content when sidebar collapsed */
.sidebar-collapsed .main-content {
    margin-left: 60px;
}

/* Collapsed sidebar header adjustments */
.sidebar-collapsed .sidebar-header {
    padding: 15px 5px;
    text-align: center;
}

.sidebar-collapsed .sidebar-header h1 {
    margin-bottom: 0;
}

.sidebar-collapsed .sidebar-collapse-btn {
    position: static;
    transform: none;
    margin-top: 10px;
}

/* Camera list status colors */
.status-dot.streaming {
    background-color: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.status-dot.online {
    background-color: #ffc107; /* Orange/yellow for online but not streaming */
}

.status-dot.offline {
    background-color: var(--danger);
}

/* Offline camera item in the Live View sidebar: dim it so it visibly reads
   as offline while still being present (so the user can see it's there and
   retrying), matching the red status dot. */
.camera-item.offline .camera-name {
    color: var(--text-dim);
    opacity: 0.7;
}
.camera-item.offline .status-dot.offline {
    box-shadow: 0 0 4px var(--danger);
}

/* Camera item click cursor */
.camera-item,
.vcs-camera-item:not(.disabled) {
    cursor: pointer;
}

.camera-item:hover,
.vcs-camera-item:not(.disabled):hover {
    background: var(--surface-hover);
}

/* Simpler camera name overflow */
.camera-item .camera-name,
.vcs-camera-item .camera-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Badge styling */
.camera-item .badge,
.vcs-camera-item .badge,
.vcs-device-header-item .badge {
    flex-shrink: 0;
    font-size: 10px;
    padding: 2px 5px;
    margin-left: 4px;
}

/* ============================================================================
   Unified Video Stats Bar Styling (VCS Platform + VCS)
   ============================================================================ */

/* Audio controls unified styling */
/* VCS video container fix - prevent overflow */
.vcs-slot .slot-video video,
.liveview-slot .slot-video video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

/* Settings feature section */
.setting-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
    margin-bottom: 15px;
}

/* Single camera view - maximize video area */
.liveview-grid.grid-1 .liveview-slot {
    height: 100%;
}

.liveview-grid.grid-1 .slot-video {
    flex: 1;
    min-height: 300px;
}

/* Fullscreen slot styling */
.liveview-slot.in-fullscreen {
    background: #000;
    border: none;
    border-radius: 0;
}

.liveview-slot.in-fullscreen .slot-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
}

.liveview-slot.in-fullscreen:hover .slot-header {
    opacity: 1;
}

.liveview-slot.in-fullscreen .slot-video {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.liveview-slot.in-fullscreen .slot-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    padding: 10px;
    justify-content: center;
}

.liveview-slot.in-fullscreen:hover .slot-controls {
    opacity: 1;
}

.liveview-slot.in-fullscreen .video-stats-bar {
    bottom: 50px;
}

.liveview-slot.in-fullscreen .audio-controls {
    bottom: 75px;
}

/* Fullscreen mode: Position video properly */
.liveview-slot:-webkit-full-screen,
.liveview-slot:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    background: #000;
}

.liveview-slot:-webkit-full-screen .video-feed,
.liveview-slot:fullscreen .video-feed {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ============================================================================
   Mission View
   ============================================================================ */

#missionViewOverlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #0d1528;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    font-family: var(--font-family);
}

.mv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #16213e;
    border-bottom: 1px solid #1a1a2e;
    flex-shrink: 0;
}
.mv-header-left, .mv-header-right { display: flex; align-items: center; gap: 10px; }
.mv-back-btn {
    background: #3d0a0a; color: #ff6b6b; border: none;
    padding: 5px 14px; border-radius: 5px; cursor: pointer;
    font-size: 12px; font-weight: 600; transition: background 0.2s;
}
.mv-back-btn:hover { background: #5a1515; }
.mv-title { color: #00d4aa; font-weight: 600; font-size: 14px; }
.mv-device-name { color: #8892b0; font-size: 13px; }
.mv-status-badge {
    padding: 2px 10px; border-radius: 10px; font-size: 11px;
    background: #c41e3a; color: #fff; font-weight: 600;
}
.mv-rec-badge {
    padding: 2px 10px; border-radius: 10px; font-size: 11px;
    background: #ff0000; color: #fff; font-weight: 600;
    animation: pulse 2s infinite;
}
.mv-stats { color: #0f0; font-family: monospace; font-size: 11px; }
.mv-gps-view-btn {
    background: #1a4a6d; color: #4fc3f7; border: none;
    padding: 4px 12px; border-radius: 5px; cursor: pointer;
    font-size: 12px; font-weight: 600; transition: all 0.2s;
}
.mv-gps-view-btn:hover { background: #256090; }
.mv-gps-view-btn.active { background: #0a3d2e; color: #00d4aa; }

.mv-body {
    flex: 1; display: flex; overflow: hidden;
}

/* Video panel */
.mv-video-panel {
    flex: 3; display: flex; flex-direction: column;
    background: #000; min-width: 0; overflow: hidden;
}
.mv-video-container {
    flex: 1; position: relative; min-height: 0; overflow: hidden;
}
.mv-video-container video {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    object-fit: contain; background: #000;
}
.mv-video-stats {
    background: #16213e; color: #0f0; font-family: monospace;
    font-size: 11px; padding: 6px 12px; border-top: 1px solid #1a1a2e;
    flex-shrink: 0;
}
.mv-vu-overlay {
    position: absolute; bottom: 12px; left: 12px;
    background: rgba(0,0,0,0.65); padding: 6px 10px;
    border-radius: 6px; pointer-events: none; z-index: 10;
    display: flex; align-items: center; gap: 6px;
}
.mv-vu-icon { color: #0f0; font-size: 12px; }
.mv-vu-track {
    width: 100px; height: 10px; background: #333;
    border-radius: 4px; overflow: hidden;
}
.mv-vu-bar {
    width: 0%; height: 100%;
    background: linear-gradient(90deg, #0f0, #ff0, #f00);
    transition: width 50ms;
}
.mv-vu-db { color: #0f0; font-size: 10px; font-family: monospace; min-width: 36px; }
.mv-rec-overlay {
    position: absolute; top: 12px; right: 12px;
    background: #ff0000; color: #fff; font-size: 12px; font-weight: bold;
    padding: 4px 10px; border-radius: 4px; z-index: 10;
    animation: pulse 2s infinite;
}

/* Controls panel */
.mv-controls-panel {
    flex: 2; display: flex; flex-direction: column;
    border-left: 2px solid #16213e; min-width: 260px; max-width: 380px;
    overflow-y: auto; background: #16213e;
}
.mv-section {
    padding: 8px 10px;
    border-bottom: 1px solid #1a1a2e;
}
.mv-section-header {
    display: flex; justify-content: space-between; align-items: center;
    color: #00d4aa; font-size: 10px; font-weight: 600; margin-bottom: 6px;
}
.mv-map-section { display: flex; flex-direction: column; min-height: 200px; flex: 1; }
.mv-map-section .mv-section-header { padding: 6px 10px; margin-bottom: 0; background: #16213e; }
.mv-map {
    flex: 1; background: #0d1528; position: relative;
    display: flex; align-items: center; justify-content: center;
}

/* Buttons */
.mv-btn {
    background: #1a1a2e; border: 1px solid #2a2a4e; color: #ccc;
    padding: 8px; border-radius: 4px; font-size: 11px;
    cursor: pointer; transition: all 0.2s; text-align: center;
}
.mv-btn:hover { background: #2a2a4e; color: #fff; }
.mv-btn:active { background: #00d4aa; color: #000; }
.mv-btn.sm { padding: 4px 2px; font-size: 9px; white-space: nowrap; }
.mv-btn.wide { width: 100%; }
.mv-btn.active { background: #00d4aa; color: #fff; border-color: #00d4aa; }
.mv-btn.recording { background: #c41e3a; border-color: #ff4444; color: #fff; }

.mv-btn-grid { display: grid; gap: 4px; }
.mv-btn-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.mv-btn-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.mv-btn-grid.cols-5 { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; }

.mv-pan-grid {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: 4px; max-width: 120px; margin: 0 auto;
}
.mv-checkbox {
    display: flex; align-items: center; gap: 4px;
    cursor: pointer; font-size: 11px; color: #ccc;
}
.mv-select {
    background: #1a1a2e; color: #ccc; border: 1px solid #2a2a4e;
    border-radius: 3px; padding: 2px 4px; font-size: 9px;
}
.mv-slider {
    width: 100%; margin-bottom: 6px; cursor: pointer;
    accent-color: #00d4aa;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}


/* ============================================================
 * Invite accept/reject UI (Round 28 addendum 3)
 * ============================================================ */

/* Pending-invites badge in nav */
.badge-pending {
    background: rgba(240, 192, 64, 0.25);
    color: #f0c040;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

/* Accept / Reject buttons next to a pending share row */
.shared-path-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.invite-actions {
    display: flex;
    gap: 6px;
}

.invite-actions .btn-sm {
    font-size: 12px;
    padding: 4px 10px;
}

/* Invite-respond modal extras */
.invite-respond-detail {
    margin-bottom: 12px;
    color: var(--text);
}

.invite-respond-detail code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}


/* ============================================================================
   MOBILE DESIGN SYSTEM v2  (phones <=767px) — implements the approved
   prototype. Replaces rounds 13–17. Desktop/tablet (>=768px) untouched.
   Direction: "pocket operator console" — one dark palette, teal accent used
   sparingly, strict type/space scale, native iOS/Android patterns, 44px+ touch.
   ============================================================================ */

/* Mobile-only chrome is hidden on desktop. */
.mobile-topbar, .mobile-tabbar, .mobile-picker-backdrop { display: none; }

@keyframes mvSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes mvFade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 767px) {
  /* ---- tokens scoped to phones (desktop palette is untouched) ---- */
  :root {
    --bg-dark:#0b1020; --bg-card:#141b30; --bg-hover:#1b2440; --bg-input:#1b2440;
    --border:rgba(255,255,255,.07);
    --text:#eef1f6; --text-muted:#9aa3b5; --text-dim:#5f6b82;
  }

  /* ---- foundations ---- */
  html, body { overflow-x: hidden; overscroll-behavior-y: none; }
  .sidebar, .mobile-menu-toggle, .mobile-header { display: none !important; }
  body, #app, .app-layout { display: block; min-height: 100vh; min-height: 100dvh; background: var(--bg-dark); }
  .main-content {
    margin-left: 0 !important;
    padding: calc(48px + env(safe-area-inset-top)) env(safe-area-inset-right)
             calc(58px + env(safe-area-inset-bottom)) env(safe-area-inset-left) !important;
    min-height: 100dvh; box-sizing: border-box; max-width: 100vw; overflow-x: hidden;
  }
  input, select, textarea { font-size: 16px !important; }
  button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  button:active { transform: scale(.96); }
  .content-header > h2, #mainContent > h1, #mainContent .page-title { display: none !important; }

  /* ---- top bar ---- */
  .mobile-topbar {
    display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: calc(48px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
    padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right));
    align-items: center; gap: 8px;
    background: rgba(11,16,32,.8); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
  }
  .mobile-topbar-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-topbar-action { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
    color: var(--accent); font-size: 16px; font-weight: 600; background: none; border: none; border-radius: 12px; }

  /* ---- bottom tab bar ---- */
  .mobile-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
    height: calc(58px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(11,16,32,.82); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
  }
  .mobile-tabbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; background: none; border: none; color: var(--text-dim); font-size: 10px; font-weight: 600; min-height: 44px; }
  .mobile-tabbar-item-icon { font-size: 23px; line-height: 1; }
  .mobile-tabbar-item-icon svg { width: 25px; height: 25px; display: block; }
  .mobile-tabbar-item.active { color: var(--accent); }
  .mobile-topbar-action svg { width: 22px; height: 22px; display: block; }

  /* ==================== DEVICES — native list rows ==================== */
  .filter-bar { display: flex !important; flex-direction: row !important; flex-wrap: wrap !important;
    gap: 8px !important; align-items: center; padding: 10px 16px !important;
    background: transparent !important; border: none !important; margin: 0 !important; }
  .filter-bar .filter-group { display: contents !important; }
  .filter-bar .filter-label { display: none !important; }
  .filter-bar .filter-btn { flex-shrink: 0; height: 34px; min-height: 34px; padding: 0 16px !important;
    border-radius: 17px !important; font-size: 13px !important; font-weight: 600 !important; white-space: nowrap;
    border: none !important; background: var(--bg-hover) !important; color: var(--text-muted) !important; }
  .filter-bar .filter-btn.active { background: var(--accent) !important; color: #00231c !important; }
  .filter-bar .sort-group { flex-direction: row !important; gap: 8px !important; }
  .filter-bar .sort-group select, .filter-bar .sort-btn, .filter-bar .view-toggle button {
    height: 40px; border: none; border-radius: 11px; background: var(--bg-hover); color: var(--text); }
  .filter-bar .view-toggle { display: flex !important; flex-direction: row !important; gap: 6px !important; }
  .filter-bar .view-toggle button.active { background: var(--accent); color: #00231c; }

  .devices-grid { display: flex !important; flex-direction: column !important; gap: 10px !important;
    padding: 2px 16px 16px !important; grid-template-columns: none !important; }
  .device-card { position: relative; width: 100%; min-height: 64px; cursor: pointer;
    background: var(--bg-card) !important; border: 1px solid var(--border) !important; border-radius: 14px !important;
    padding: 13px 38px 13px 14px !important; display: flex !important; flex-direction: column;
    justify-content: center; gap: 5px; transition: background .12s; transform: none !important; }
  .device-card:hover { transform: none !important; }
  .device-card:active { background: var(--bg-hover) !important; }
  .device-card::after { content: '\203A'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
    font-size: 24px; line-height: 1; font-weight: 300; color: var(--text-dim); }
  .device-card .device-select-checkbox { width: 22px; height: 22px; flex-shrink: 0; }
  .device-card .device-card-header { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; }
  .device-card .device-name { font-size: 16px !important; font-weight: 600 !important; margin: 0 !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
  .device-card .device-badges { flex-shrink: 0; display: flex; gap: 4px; }
  .device-card .device-card-body { display: flex !important; flex-wrap: wrap; gap: 2px 10px; align-items: center; }
  .device-card .device-serial, .device-card .device-model, .device-card .device-meta, .device-card .last-seen {
    font-size: 13px !important; color: var(--text-muted) !important; margin: 0 !important; }

  /* ==================== DEVICE DETAIL ==================== */
  .device-detail-container { padding: 0 !important; }
  .device-view-tabs { display: flex !important; gap: 4px; padding: 5px; margin: 10px 16px; background: var(--bg-hover);
    border-radius: 12px; position: sticky; top: 0; z-index: 6; }
  .device-view-tabs button, .device-view-tabs .tab { flex: 1; min-height: 40px; border: none !important;
    border-radius: 9px !important; background: transparent !important; color: var(--text-muted) !important;
    font-size: 14px !important; font-weight: 600 !important; }
  .device-view-tabs button.active, .device-view-tabs .tab.active { background: var(--accent) !important; color: #00231c !important; }
  .device-detail-content { padding: 0 16px 16px !important; }

  /* ==================== LIVE VIEW ==================== */
  .liveview-container { flex-direction: column !important; height: auto !important; padding: 0 !important; min-height: 0 !important; }
  .content-header { padding: 8px 12px !important; background: transparent !important; border: none !important; }
  .content-header .header-actions { display: flex !important; flex-wrap: nowrap !important; gap: 8px !important;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; align-items: center; }
  .content-header .header-actions::-webkit-scrollbar { display: none; }
  .content-header .header-actions select.grid-select { flex-shrink: 0; height: 38px; border: none; border-radius: 11px;
    background: var(--bg-hover); color: var(--text); padding: 0 30px 0 12px; min-width: 96px; }
  .content-header .header-actions .btn { flex-shrink: 0; height: 38px; min-height: 38px; padding: 0 14px;
    border-radius: 11px; font-size: 14px; white-space: nowrap; }

  .liveview-grid { display: flex !important; flex-direction: column !important; gap: 12px !important;
    padding: 4px 12px !important; height: auto !important; max-height: none !important;
    grid-template-columns: none !important; grid-template-rows: none !important; overflow: visible !important; }
  .liveview-slot { position: relative !important; width: 100% !important; aspect-ratio: 16/9; height: auto !important;
    min-height: 0 !important; max-height: none !important; background: #000; border-radius: 14px !important;
    overflow: hidden; border: 1px solid var(--border); }
  .liveview-slot.empty { order: 99; aspect-ratio: auto; min-height: 120px !important; display: flex !important;
    align-items: center; justify-content: center; background: var(--bg-card); border: 2px dashed var(--border); }
  .liveview-slot.empty ~ .liveview-slot.empty { display: none !important; }
  .liveview-slot.empty .slot-placeholder { display: flex !important; flex-direction: column; align-items: center;
    gap: 8px; padding: 24px; color: var(--text-muted); text-align: center; }
  .liveview-slot.empty .slot-placeholder-desktop { display: none !important; }
  .liveview-slot.empty .slot-placeholder-touch { display: block !important; }
  .liveview-slot.empty .drop-icon { font-size: 36px; color: var(--accent); }

  .liveview-slot video, .liveview-slot .video-feed { position: absolute; inset: 0; width: 100% !important;
    height: 100% !important; object-fit: contain !important; background: #000 !important; }
  .liveview-slot .slot-header, .liveview-slot .slot-footer { opacity: 1 !important; pointer-events: auto !important;
    position: absolute; left: 0; right: 0; z-index: 5; display: flex !important; align-items: center; }
  .liveview-slot .slot-header { top: 0; padding: 10px 12px !important; gap: 8px;
    background: linear-gradient(to bottom, rgba(0,0,0,.7), transparent) !important; }
  .liveview-slot .slot-device-name { flex: 1; font-size: 14px !important; font-weight: 600 !important; color: #fff !important;
    text-shadow: 0 1px 2px rgba(0,0,0,.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0 !important; }
  .liveview-slot .slot-footer { bottom: 0; padding: 10px 12px !important; gap: 8px; justify-content: flex-end;
    background: linear-gradient(to top, rgba(0,0,0,.75), transparent) !important; }
  .liveview-slot .slot-controls-btn, .liveview-slot .slot-footer button { width: 42px !important; height: 42px !important;
    min-width: 42px !important; min-height: 42px !important; border-radius: 12px !important; font-size: 18px !important;
    padding: 0 !important; background: rgba(255,255,255,.16) !important; border: none !important; color: #fff;
    display: flex !important; align-items: center; justify-content: center; }
  .liveview-slot .slot-controls-btn.rec, .liveview-slot .slot-footer button.rec { background: rgba(255,69,58,.9) !important; }
  .liveview-slot .slot-remove, .liveview-slot .slot-remove-btn { width: 34px !important; height: 34px !important;
    border-radius: 17px !important; background: rgba(0,0,0,.45) !important; color: #fff; font-size: 18px;
    border: none !important; display: flex !important; align-items: center; justify-content: center; }
  .liveview-slot .vcs-variant-select, .liveview-slot .slot-footer select { height: 36px !important; border-radius: 10px !important;
    background: rgba(255,255,255,.16) !important; border: none !important; color: #fff !important; font-size: 13px !important; }
  .liveview-slot.picker-selected { outline: 3px solid var(--accent) !important; outline-offset: -3px !important; }

  /* camera picker bottom sheet */
  .liveview-sidebar { display: none !important; }
  body.mobile-picker-open .liveview-sidebar { display: flex !important; position: fixed; left: 0; right: 0; bottom: 0;
    top: auto; max-height: 72dvh; z-index: 200; flex-direction: column; background: var(--bg-card);
    border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.5); animation: mvSheetUp .25s ease-out;
    padding: 18px 12px env(safe-area-inset-bottom); }
  body.mobile-picker-open .liveview-sidebar::before { content: ''; position: absolute; top: 7px; left: 50%;
    transform: translateX(-50%); width: 38px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.25); }
  .mobile-picker-backdrop { display: none; }
  body.mobile-picker-open .mobile-picker-backdrop { display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 199; animation: mvFade .2s; }
  body.mobile-picker-open .camera-item, body.mobile-picker-open .vcs-camera-item { min-height: 56px; padding: 12px 14px !important;
    margin: 0 0 8px 0 !important; border-radius: 12px !important; background: var(--bg-hover) !important;
    border: 1px solid var(--border) !important; display: flex !important; align-items: center; gap: 10px !important; }
  body.mobile-picker-open .camera-item:active, body.mobile-picker-open .vcs-camera-item:active { background: var(--bg-input) !important; }

  /* ==================== MISSION VIEW ==================== */
  #missionViewOverlay { position: fixed !important; inset: 0 !important; z-index: 500 !important; display: flex !important;
    flex-direction: column !important; height: 100vh !important; height: 100dvh !important; background: #000 !important;
    padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  #missionViewOverlay .mv-header { flex-shrink: 0; display: flex !important; align-items: center; gap: 6px;
    height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 !important;
    background: rgba(11,16,32,.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border); }
  #missionViewOverlay .mv-header-left { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
  #missionViewOverlay .mv-header-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
  #missionViewOverlay .mv-back-btn { min-width: 44px; min-height: 44px; background: none !important; border: none !important;
    color: var(--accent) !important; font-size: 17px !important; font-weight: 600; padding: 0 6px !important; }
  #missionViewOverlay .mv-title { display: none !important; }
  #missionViewOverlay .mv-device-name { font-size: 16px !important; font-weight: 600; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #missionViewOverlay .mv-stats { display: none !important; }
  #missionViewOverlay .mv-status-badge { font-size: 11px !important; font-weight: 700; padding: 3px 7px; border-radius: 6px;
    background: rgba(255,69,58,.16); color: #ff6b62; }
  #missionViewOverlay .mv-gps-view-btn { min-height: 40px; padding: 0 12px !important; font-size: 13px !important;
    border-radius: 11px !important; background: var(--bg-hover) !important; border: none !important; color: var(--text) !important; }
  #missionViewOverlay .mv-body { flex: 1; min-height: 0; display: flex !important; flex-direction: column !important;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--bg-dark);
    padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  #missionViewOverlay .mv-video-panel { flex-shrink: 0; width: 100%; aspect-ratio: 16/9; background: #000 !important; position: relative; }
  #missionViewOverlay .mv-video-container { width: 100% !important; height: 100% !important; }
  #missionViewOverlay .mv-video-container video { width: 100% !important; height: 100% !important; object-fit: contain !important; }
  #missionViewOverlay .mv-controls-panel { max-height: none !important; min-width: 0 !important; max-width: none !important;
    border: none !important; padding: 12px !important; display: flex; flex-direction: column; gap: 12px; }
  #missionViewOverlay .mv-section { background: var(--bg-card) !important; border: 1px solid var(--border) !important;
    border-radius: 16px !important; padding: 14px !important; margin: 0 !important; }
  #missionViewOverlay .mv-section-header { font-size: 13px !important; font-weight: 700 !important; letter-spacing: .04em;
    text-transform: uppercase; color: var(--text-muted) !important; margin-bottom: 12px !important;
    display: flex; align-items: center; justify-content: space-between; }
  #missionViewOverlay .mv-map { height: 180px !important; border-radius: 12px; overflow: hidden; }
  #missionViewOverlay .mv-btn, #missionViewOverlay .mv-btn.sm { min-height: 46px !important; border-radius: 11px !important;
    font-size: 15px !important; font-weight: 600 !important; padding: 0 10px !important; background: var(--bg-hover) !important;
    border: 1px solid var(--border) !important; color: var(--text) !important; display: flex; align-items: center; justify-content: center; }
  #missionViewOverlay .mv-btn.active { background: var(--accent) !important; color: #00231c !important; border-color: var(--accent) !important; }
  #missionViewOverlay .mv-btn:active { transform: scale(.96); }
  #missionViewOverlay .mv-btn-grid { display: grid !important; gap: 8px !important; }
  #missionViewOverlay .mv-btn-grid.cols-2 { grid-template-columns: repeat(2,1fr); }
  #missionViewOverlay .mv-btn-grid.cols-3 { grid-template-columns: repeat(3,1fr); }
  #missionViewOverlay .mv-btn-grid.cols-4 { grid-template-columns: repeat(4,1fr); }
  #missionViewOverlay .mv-btn-grid.cols-5 { grid-template-columns: repeat(5,1fr); }
  #missionViewOverlay #mvGpsBtn { min-height: 40px !important; }
  #missionViewOverlay #mvGpsEnableBtn { min-height: 46px !important; font-size: 15px !important; font-weight: 700 !important;
    padding: 0 20px !important; border-radius: 11px !important; }
  #missionViewOverlay .mv-pan-grid { display: grid !important; grid-template-columns: repeat(3,1fr); gap: 8px !important;
    max-width: 220px; margin: 0 auto; }
  #missionViewOverlay .mv-pan-grid .mv-btn { min-height: 58px !important; font-size: 22px !important; }
  #missionViewOverlay .mv-slider { width: 100% !important; height: 44px !important; -webkit-appearance: none;
    appearance: none; background: none; margin: 4px 0 10px; }
  #missionViewOverlay .mv-slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--bg-input); }
  #missionViewOverlay .mv-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px;
    border-radius: 50%; background: var(--accent); margin-top: -11px; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
  #missionViewOverlay .mv-slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--bg-input); }
  #missionViewOverlay .mv-slider::-moz-range-thumb { width: 28px; height: 28px; border: none; border-radius: 50%; background: var(--accent); }
  #missionViewOverlay .mv-select { min-height: 40px !important; border-radius: 11px !important; padding: 0 10px !important;
    background: var(--bg-hover) !important; border: 1px solid var(--border) !important; color: var(--text) !important; font-size: 14px !important; }
  #missionViewOverlay .mv-checkbox { display: flex !important; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
  #missionViewOverlay .mv-checkbox input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

  /* toasts: top-anchored, clear of the top bar */
  .toast, #toast, .toast-container .toast { position: fixed !important; top: calc(56px + env(safe-area-inset-top)) !important;
    bottom: auto !important; left: 50% !important; right: auto !important; transform: translateX(-50%) !important;
    max-width: 90vw !important; font-size: 13px !important; padding: 10px 14px !important; border-radius: 12px !important;
    z-index: 600 !important; box-shadow: 0 6px 20px rgba(0,0,0,.45) !important; }
}

/* iPad (768–1024, touch): keep the desktop sidebar; just hide the phone bars. */
@media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) {
  .mobile-topbar, .mobile-tabbar { display: none !important; }
  .devices-grid { grid-template-columns: repeat(2, 1fr); }
  .liveview-grid.grid-4 { grid-template-columns: repeat(2,1fr); grid-template-rows: repeat(2,1fr); }
  .liveview-grid.grid-6 { grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(2,1fr); }
  .liveview-grid.grid-9 { grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr); }
}

/* Mobile Devices — grouped native list (rendered by renderDevicesMobile). */
@media (max-width: 767px) {
  .mdev { padding: 8px 0 4px; }
  .msearch { margin: 4px 16px 12px; height: 42px; border-radius: 12px; background: var(--bg-hover);
    display: flex; align-items: center; gap: 8px; padding: 0 14px; }
  .msearch-ic { color: var(--text-muted); font-size: 18px; }
  .msearch input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: 16px; }
  .msearch input::placeholder { color: var(--text-muted); }
  .mchips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 14px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .mchips::-webkit-scrollbar { display: none; }
  .mchip { flex-shrink: 0; height: 34px; padding: 0 16px; border-radius: 17px; border: none;
    background: var(--bg-hover); color: var(--text-muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
  .mchip.active { background: var(--accent); color: #00231c; }
  .mdev-grouplabel { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-dim); padding: 14px 18px 8px; }
  .mdev-list { margin: 0 12px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 16px; overflow: hidden; }
  .mdev-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; min-height: 64px;
    border-bottom: 1px solid var(--border); }
  .mdev-row:last-child { border-bottom: none; }
  .mdev-row:active { background: var(--bg-hover); }
  .mdev-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: #48506a; }
  .mdev-dot.on { background: #32d74b; box-shadow: 0 0 8px rgba(50,215,75,.6); }
  .mdev-dot.warn { background: var(--warning, #f7b955); }
  .mdev-dot.off { background: #48506a; }
  .mdev-info { flex: 1; min-width: 0; }
  .mdev-name { font-size: 16px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mdev-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mdev-pill { flex-shrink: 0; font-size: 10px; font-weight: 700; letter-spacing: .03em; padding: 4px 8px; border-radius: 7px; }
  .mdev-pill.live { background: rgba(255,69,58,.16); color: #ff6b62; }
  .mdev-pill.fix { background: rgba(247,185,85,.16); color: var(--warning, #f7b955); }
  .mdev-chev { flex-shrink: 0; color: var(--text-dim); font-size: 22px; font-weight: 300; }
  .mdev-empty { text-align: center; color: var(--text-muted); padding: 60px 20px; font-size: 15px; }
  .mdev-empty-ic { font-size: 40px; margin-bottom: 10px; }
}

/* Mobile Live View toolbar + full-bleed Map (phones only). */
@media (max-width: 767px) {
  /* Live View compact toolbar */
  .mlv-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
  .mlv-toolbar .grid-select { flex: 1; min-width: 0; height: 40px; border: none; border-radius: 11px;
    background: var(--bg-hover); color: var(--text); font-size: 14px; padding: 0 32px 0 14px; }
  .mlv-tool-btn { flex-shrink: 0; height: 40px; padding: 0 14px; border-radius: 11px; border: none;
    background: var(--bg-hover); color: var(--text); font-size: 14px; font-weight: 600; }
  .mlv-tool-btn.active { background: var(--accent); color: #00231c; }

  /* Map: full-bleed map with floating controls + a bottom-sheet device list. */
  .content-header .gps-count { display: none; }
  .map-layout { display: block !important; height: auto !important; }
  .map-container-wrapper { position: fixed !important; left: 0; right: 0;
    top: calc(92px + env(safe-area-inset-top)); bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 1; }
  #leafletMap, .leaflet-map { position: absolute !important; inset: 0 !important; width: 100% !important; height: 100% !important; }
  .map-toolbar { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 500; display: flex; gap: 8px;
    background: transparent !important; padding: 0 !important; border: none !important; }
  .map-toolbar .map-layer-select { height: 38px; border-radius: 10px; border: 1px solid var(--border);
    background: rgba(20,27,48,.92); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    color: var(--text); font-size: 13px; padding: 0 10px; }
  .map-sidebar { position: fixed !important; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 450; width: auto !important; max-height: 38dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: var(--bg-card); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.5);
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom)); border: none !important; }
  .map-sidebar::before { content: ''; display: block; width: 38px; height: 5px; border-radius: 3px;
    background: rgba(255,255,255,.25); margin: 2px auto 8px; }
  .map-sidebar-header { display: flex; align-items: center; justify-content: space-between; }
  .map-sidebar-header h3 { font-size: 14px; margin: 0; }
  .map-device-item { min-height: 52px; border-radius: 12px; background: var(--bg-hover);
    margin-bottom: 8px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
  .map-device-item.selected { outline: 2px solid var(--accent); }
  .selected-device-info { background: var(--bg-hover); border-radius: 12px; padding: 12px; margin-top: 8px; }
  .selected-device-info .device-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .live-gps-indicator { z-index: 600 !important; }
}

/* Mobile camera picker — native bottom sheet (rendered by renderLiveView). */
@media (max-width: 767px) {
  body.mobile-picker-open .liveview-sidebar.mobile-picker { padding: 16px 0 calc(8px + env(safe-area-inset-bottom)); }
  .picker-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 16px 10px; }
  .picker-title { font-size: 17px; font-weight: 600; color: var(--text); }
  .picker-done { min-height: 40px; padding: 0 6px; background: none; border: none; color: var(--accent); font-size: 16px; font-weight: 600; }
  .picker-search { display: flex; align-items: center; gap: 8px; margin: 0 16px 8px; height: 42px;
    border-radius: 12px; background: var(--bg-hover); padding: 0 12px; }
  .picker-search-ic { color: var(--text-muted); font-size: 18px; }
  .picker-search input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); font-size: 16px; }
  .picker-search input::placeholder { color: var(--text-muted); }
  .picker-refresh { flex-shrink: 0; width: 34px; height: 34px; border-radius: 9px; border: none; background: transparent; color: var(--text-muted); font-size: 18px; }

  body.mobile-picker-open .camera-list { padding: 0 12px; }
  body.mobile-picker-open .camera-list-separator { font-size: 12px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-dim); padding: 14px 4px 8px; margin: 0; background: none; border: none; }
  body.mobile-picker-open .camera-item,
  body.mobile-picker-open .vcs-device-header-item,
  body.mobile-picker-open .vcs-camera-item { display: flex !important; align-items: center; gap: 10px;
    min-height: 54px; padding: 12px 14px !important; margin: 0 0 8px !important; border-radius: 12px !important;
    background: var(--bg-hover) !important; border: 1px solid var(--border) !important; }
  body.mobile-picker-open .camera-item:active,
  body.mobile-picker-open .vcs-device-header-item:active,
  body.mobile-picker-open .vcs-camera-item:active { background: var(--bg-input) !important; }
  body.mobile-picker-open .vcs-camera-item { margin-left: 18px !important; }
  body.mobile-picker-open .vcs-camera-item.camera-offline { opacity: .5; }
  body.mobile-picker-open .camera-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.mobile-picker-open .status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: #48506a; }
  body.mobile-picker-open .status-dot.streaming { background: #32d74b; box-shadow: 0 0 8px rgba(50,215,75,.6); }
  body.mobile-picker-open .status-dot.online { background: var(--warning, #f7b955); }
  body.mobile-picker-open .status-dot.offline { background: #48506a; }
  body.mobile-picker-open .vcs-expand-icon { color: var(--text-muted); font-size: 12px; width: 14px; text-align: center; flex-shrink: 0; }
  body.mobile-picker-open .badge { flex-shrink: 0; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 8px;
    background: rgba(255,255,255,.08); color: var(--text-muted); }
  body.mobile-picker-open .badge.used { background: var(--accent); color: #00231c; }
  body.mobile-picker-open .vcs-reload-btn, body.mobile-picker-open .sidebar-rec-indicator { flex-shrink: 0; font-size: 13px; }
  body.mobile-picker-open .sidebar-empty,
  body.mobile-picker-open .empty-text { color: var(--text-muted); padding: 6px 4px 10px; font-size: 14px; text-align: center; }
}

/* ── Devices filter bar: compact layout for narrower PC windows ──────────────
   Between the phone breakpoint (≤767px, which switches to the card layout) and
   a roomy desktop, the filter groups used to wrap into many tall rows. Shrink
   the controls and spacing so they pack into fewer, shorter rows and stop
   wasting vertical space above the table. */
@media (min-width: 768px) and (max-width: 1200px) {
    .filter-bar {
        gap: 6px 10px;
        padding: 10px 12px;
        margin-bottom: 14px;
    }
    .filter-group { gap: 6px; }
    .filter-label {
        font-size: 11px;
        letter-spacing: 0.3px;
    }
    .filter-btn {
        padding: 5px 9px;
        font-size: 11px;
    }
    .filter-bar select,
    .sort-group select {
        padding: 5px 8px;
        font-size: 12px;
    }
    /* Keep the grid/table toggle inline instead of letting margin-left:auto
       bump it onto a row of its own. */
    .view-toggle { margin-left: 0; }
}

/* Even tighter just above the phone breakpoint, where horizontal room is
   scarcest, so the groups still fit a couple per row. */
@media (min-width: 768px) and (max-width: 920px) {
    .filter-bar { gap: 5px 8px; }
    .filter-btn { padding: 4px 8px; }
    .filter-label { font-size: 10px; }
}

/* ── Devices page: section headers + compact VCS list ───────────────────────
   The Devices page now shows CheckMate phones and added VCS camera systems in
   separate sections, so a user with only VCS devices no longer sees an empty
   page. Full VCS camera management still lives on the VCS Devices page. */
.devices-section { margin-bottom: 24px; }
.devices-section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 12px;
}
.devices-section-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.devices-section-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 1px 9px;
}
.devices-section-head .btn { margin-left: auto; }
.devices-section-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: 8px;
}
.devices-section-empty a { color: var(--accent); text-decoration: none; }

.vcs-mini-list {
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
}
.vcs-mini-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.vcs-mini-row:last-child { border-bottom: none; }
.vcs-mini-row:hover { background: var(--bg-hover); }
.vcs-mini-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-dim);
}
.vcs-mini-dot.on { background: #28a745; box-shadow: 0 0 6px rgba(40,167,69,0.6); }
.vcs-mini-dot.off { background: #888; }
.vcs-mini-info { flex: 1; min-width: 0; }
.vcs-mini-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.vcs-mini-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.vcs-mini-status { font-size: 12px; font-weight: 600; flex-shrink: 0; }
.vcs-mini-status.on { color: #28a745; }
.vcs-mini-status.off { color: var(--text-dim); }
.vcs-mini-row .mdev-chev { color: var(--text-dim); font-size: 18px; flex-shrink: 0; }

/* ── Devices filter bar: flat mobile-style chip row ─────────────────────────
   Replaces the stacked Status:/Streaming:/GPS: label groups with a single
   flowing row of pill chips (like the mobile layout), plus a right-aligned
   tools cluster for sort + grid/table toggle. */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.filter-chip {
    flex-shrink: 0;
    height: 34px;
    padding: 0 14px;
    border-radius: 17px;
    border: 1px solid transparent;
    background: var(--bg-hover);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-chip:hover { background: var(--bg-input); color: var(--text); }
.filter-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-dark);
}
.filter-bar-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.filter-sort {
    height: 34px;
    border-radius: 17px;
    padding: 0 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}
.filter-bar-tools .sort-btn { height: 34px; border-radius: 17px; }

/* Slightly smaller chips on narrower PC windows so the row stays compact. */
@media (min-width: 768px) and (max-width: 920px) {
    .filter-chip { height: 30px; padding: 0 11px; font-size: 12px; }
    .filter-sort, .filter-bar-tools .sort-btn { height: 30px; }
}
