/**
 * 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;
}

.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: 16px;
    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 .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 */
}

.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;
}

.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: 24px;
}

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

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

.qr-loading {
    width: 200px;
    height: 200px;
    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: 200px;
    height: 200px;
}

.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: 20px;
}

.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: 12px 16px;
    margin-bottom: 16px;
}

.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;
}

.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);
}

/* 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 {
    padding: 12px 16px;
    background: var(--bg-hover);
    border-radius: 8px;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.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;
}

.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);
}

/* 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; }
}

/* Responsive - stack vertically on narrow screens */
@media (max-width: 768px) {
    .mv-body { flex-direction: column; }
    .mv-controls-panel {
        max-width: none; min-width: 0;
        border-left: none; border-top: 2px solid #16213e;
        max-height: 50vh;
    }
    .mv-map-section { min-height: 150px; }
}
/* ============================================================================
   ROUND 16 — Mobile redesign (iOS-native patterns)

   Replaces all previous mobile media queries (rounds 13-15 scrapped) with a
   coherent iOS-style mobile experience. Strategy:

   - Below 768px width, hide the desktop layout (sidebar + main-content with
     hamburger drawer) and replace with an iOS-style stack: compact top bar,
     content area, bottom tab bar.
   - Use safe-area-inset for notch/home-indicator awareness throughout.
   - Use 100dvh (dynamic viewport height) instead of 100vh.
   - Live view becomes adaptive: 1 cam = full-bleed video; 2-4 = grid; show
     ONLY occupied + 1 add-card (don't show 4 empty placeholders).
   - Camera picker is a bottom sheet, not a sidebar.
   - Devices page is a vertical scroll list with horizontal-scroll filter
     chips (no wrapping rows).
   - All rules scoped to (max-width: 767px) so desktop is untouched.

   This block is at end-of-cascade so it overrides everything above it. Uses
   !important sparingly — only where existing rules use !important too.
   ============================================================================ */

/* ============================================================================
   Mobile root: hide desktop sidebar & hamburger, show bottom tab bar.
   ============================================================================ */
@media (max-width: 767px) {
    /* Hide everything we're replacing. */
    .sidebar,
    .mobile-menu-toggle,
    .mobile-header {
        display: none !important;
    }

    /* App layout: simple vertical stack now. */
    body, #app, .app-layout {
        display: block;
        min-height: 100vh;
        background: var(--bg-dark);
    }
    @supports (height: 100dvh) {
        body, #app, .app-layout {
            min-height: 100dvh;
        }
    }

    /* Main content fills the screen between the new top bar and bottom tab
       bar. Top bar is 52px + safe-area-top. Bottom tab bar is 56px +
       safe-area-bottom. There's no per-view wrapper in this app, so .main-
       content is what gets the padding. */
    .main-content {
        margin-left: 0 !important;
        padding-top: calc(52px + env(safe-area-inset-top)) !important;
        padding-bottom: calc(56px + env(safe-area-inset-bottom)) !important;
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
        min-height: 100vh;
        min-height: 100dvh;
        box-sizing: border-box;
    }

    /* Live View has its own .liveview-container that goes inside .main-content.
       Since .main-content already has padding, .liveview-container shouldn't
       add its own. */
    .liveview-container {
        flex-direction: column !important;
        height: auto !important;
        padding: 0 !important;
        min-height: 0 !important;
        box-sizing: border-box;
    }

    /* The legacy sidebar inside .liveview-container becomes the bottom-sheet
       picker — hidden by default, shown via .mobile-picker-open class on
       body. */
    .liveview-sidebar {
        display: none !important;
    }
    body.mobile-picker-open .liveview-sidebar {
        display: flex !important;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: 30vh; /* leave 30% of screen showing behind sheet */
        z-index: 200;
        flex-direction: column;
        background: var(--bg-card);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
        animation: slideUpSheet 0.25s ease-out;
        padding-bottom: env(safe-area-inset-bottom);
        max-height: 70vh;
        max-height: 70dvh;
    }
}

@keyframes slideUpSheet {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ============================================================================
   Mobile top bar (replaces the old mobile-header + sidebar combo).
   Compact iOS-style title bar. JS injects this element into the DOM.
   ============================================================================ */
.mobile-topbar {
    display: none; /* desktop hides it */
}
@media (max-width: 767px) {
    .mobile-topbar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: calc(52px + env(safe-area-inset-top));
        padding-top: env(safe-area-inset-top);
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        background: rgba(15, 20, 36, 0.92);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        z-index: 100;
        align-items: center;
        gap: 12px;
    }

    .mobile-topbar-title {
        flex: 1;
        font-size: 17px;
        font-weight: 600;
        color: var(--text);
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-topbar-action {
        background: transparent;
        border: none;
        color: var(--accent);
        font-size: 15px;
        font-weight: 500;
        padding: 8px 4px;
        cursor: pointer;
        min-width: 44px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .mobile-topbar-action:active { opacity: 0.5; }

    .mobile-topbar-icon {
        font-size: 20px;
    }
}

/* ============================================================================
   Mobile bottom tab bar — primary navigation on mobile.
   Standard iOS pattern with icon + label.
   ============================================================================ */
.mobile-tabbar {
    display: none;
}
@media (max-width: 767px) {
    .mobile-tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: calc(56px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: rgba(15, 20, 36, 0.92);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        z-index: 100;
        align-items: stretch;
        justify-content: space-around;
    }

    .mobile-tabbar-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 500;
        cursor: pointer;
        min-height: 44px;
        padding: 6px 4px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: color 0.15s;
    }

    .mobile-tabbar-item-icon {
        font-size: 22px;
        line-height: 1;
    }

    .mobile-tabbar-item.active {
        color: var(--accent);
    }
    .mobile-tabbar-item:active { opacity: 0.6; }
}

/* ============================================================================
   Mobile: Devices page redesign
   Class names (from app.js render): .filter-bar (container), .filter-group
   (a row of related buttons + label), .filter-btn (individual chip),
   .filter-label (text label), .sort-group, .view-toggle, .devices-grid
   ============================================================================ */
@media (max-width: 767px) {
    /* Container for the whole filter area: stack vertically with tight
       spacing. */
    .filter-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        padding: 12px 16px !important;
        background: transparent !important;
        margin: 0 !important;
        border: none !important;
    }

    /* Each .filter-group becomes a single horizontal scroll row with the
       label hidden. Multiple groups = multiple rows, all chips visible
       without wrapping. */
    .filter-bar .filter-group {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 6px !important;
        padding: 0 !important;
        margin: 0 !important;
        align-items: center;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .filter-bar .filter-group::-webkit-scrollbar { display: none; }

    /* Hide the inline labels — chips themselves are descriptive enough
       on a small screen. */
    .filter-bar .filter-group .filter-label {
        display: none !important;
    }

    /* Filter chips: pill-shaped, compact, single-line. */
    .filter-bar .filter-btn {
        flex-shrink: 0;
        padding: 6px 14px !important;
        font-size: 13px !important;
        font-weight: 500 !important;
        height: 32px !important;
        min-height: 32px !important;
        border-radius: 16px !important;
        white-space: nowrap;
        background: rgba(255, 255, 255, 0.08) !important;
        border: none !important;
        color: var(--text) !important;
    }
    .filter-bar .filter-btn.active {
        background: var(--accent) !important;
        color: #001b16 !important;
    }

    /* Sort dropdown + view toggle: place inline as a single row, smaller. */
    .filter-bar .sort-group {
        flex-direction: row !important;
        gap: 8px !important;
    }
    .filter-bar .sort-group select {
        flex: 1;
        height: 36px;
        font-size: 14px;
        padding: 0 10px;
        background: rgba(255, 255, 255, 0.08);
        border: none;
        border-radius: 8px;
        color: var(--text);
    }
    .filter-bar .sort-btn,
    .filter-bar .view-toggle button {
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.08);
        border: none;
        border-radius: 8px;
        color: var(--text);
        flex-shrink: 0;
    }
    .filter-bar .view-toggle button.active {
        background: var(--accent);
        color: #001b16;
    }
    .filter-bar .view-toggle {
        display: flex !important;
        gap: 4px !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
    }

    /* "Select Offline" group: keep as small pill button on its own. */
    .filter-bar .filter-group .btn {
        font-size: 13px;
        height: 32px;
        padding: 0 14px;
        border-radius: 16px;
    }

    /* Devices grid → simple vertical list of full-width cards. */
    .devices-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding: 0 16px 16px !important;
        grid-template-columns: none !important;
    }

    .device-card {
        width: 100%;
        background: var(--bg-card);
        border: 1px solid rgba(255, 255, 255, 0.06);
        border-radius: 12px;
        padding: 14px;
        cursor: pointer;
        transition: background 0.1s;
    }
    .device-card:active {
        background: rgba(255, 255, 255, 0.04);
        transform: none;
    }
    .device-card:hover {
        transform: none !important;
    }

    /* Empty state */
    .empty-state {
        padding: 48px 24px;
        text-align: center;
        color: var(--text-muted);
    }

    /* The page title "Devices" rendered before .filter-bar — hide it on
       mobile since the topbar already shows the title. */
    #mainContent > h1,
    #mainContent .page-title {
        display: none !important;
    }
}

/* ============================================================================
   Mobile: Live View page redesign
   Markup:
     .content-header
       h2 (page title)
       .header-actions (grid select, retry, stats, close all buttons)
     .liveview-container (flex row → flex column on mobile)
       .liveview-sidebar (camera picker — hidden, becomes bottom sheet)
       .liveview-grid (slot grid — becomes vertical list on mobile)
   ============================================================================ */
@media (max-width: 767px) {
    /* Hide the redundant page title on mobile (topbar already shows it). */
    #liveview-view .content-header > h2,
    .liveview-container ~ .content-header > h2,
    .content-header > h2 {
        display: none !important;
    }

    /* Toolbar: compact horizontal scroll row at the top of the grid. */
    .content-header {
        padding: 8px 12px !important;
        background: transparent !important;
        border: none !important;
    }
    .content-header .header-actions {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .content-header .header-actions::-webkit-scrollbar { display: none; }

    .content-header .header-actions select.grid-select {
        flex-shrink: 0;
        height: 36px;
        font-size: 14px;
        background: rgba(255, 255, 255, 0.08);
        border: none;
        border-radius: 8px;
        padding: 0 30px 0 12px;
        color: var(--text);
        min-width: 110px;
    }
    .content-header .header-actions .btn {
        flex-shrink: 0;
        height: 36px;
        padding: 0 12px;
        font-size: 13px;
        min-height: 36px;
        white-space: nowrap;
    }

    /* The grid container: vertical list of slots. */
    .liveview-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding: 0 12px !important;
        height: auto !important;
        max-height: none !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        overflow: visible !important;
    }

    /* All slots: full width, 16:9 aspect, rounded corners. */
    .liveview-slot {
        position: relative !important;
        width: 100% !important;
        aspect-ratio: 16 / 9;
        max-height: none !important;
        min-height: 0 !important;
        height: auto !important;
        background: #000;
        border-radius: 12px !important;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, 0.06);
    }

    /* Empty slots: only the FIRST one is visible (CSS sibling rule below).
       Push to end of flex order so add-card always appears last. */
    .liveview-slot.empty {
        order: 99;
        aspect-ratio: auto;
        min-height: 100px !important;
        background: rgba(255, 255, 255, 0.03);
        border: 2px dashed rgba(255, 255, 255, 0.15);
        display: flex !important;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    /* Hide every empty slot that has a previous empty sibling — leaves
       exactly ONE add-card visible regardless of how many empty slots
       the grid has. */
    .liveview-slot.empty ~ .liveview-slot.empty {
        display: none !important;
    }

    /* Empty slot inner content. */
    .liveview-slot.empty .slot-placeholder {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        padding: 24px 16px;
        color: var(--text-muted);
        text-align: center;
    }
    .liveview-slot.empty .slot-placeholder .drop-icon {
        font-size: 32px;
        opacity: 0.5;
    }
    .liveview-slot.empty .slot-placeholder p {
        font-size: 14px;
        margin: 0;
    }
    .liveview-slot.empty .slot-placeholder small {
        font-size: 12px;
        opacity: 0.7;
    }
    /* The desktop placeholder text "Drop camera here" — hide it on mobile.
       The touch placeholder ("Tap to select slot") is what we want. */
    .liveview-slot.empty .slot-placeholder-desktop {
        display: none !important;
    }
    .liveview-slot.empty .slot-placeholder-touch {
        display: block !important;
    }

    /* Slot header & footer: ALWAYS visible on mobile (no hover dependence). */
    .liveview-slot .slot-header,
    .liveview-slot .slot-footer {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    .liveview-slot .slot-header {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: linear-gradient(to bottom, rgba(0,0,0,0.65) 0%, transparent 100%) !important;
        padding: 8px 10px !important;
        z-index: 5 !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        font-size: 12px !important;
    }
    .liveview-slot .slot-device-name {
        flex: 1;
        font-size: 13px !important;
        font-weight: 600 !important;
        color: #fff !important;
        text-shadow: 0 1px 2px rgba(0,0,0,0.6);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0 !important;
    }
    .liveview-slot .slot-footer {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%) !important;
        padding: 6px 8px !important;
        z-index: 5 !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        align-items: center !important;
        justify-content: flex-end !important;
    }

    /* Slot footer buttons: compact icon-only with 32px hit area */
    .liveview-slot .slot-controls-btn,
    .liveview-slot .slot-footer button {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        font-size: 14px !important;
        padding: 0 !important;
        background: rgba(255, 255, 255, 0.18);
        border: none !important;
        border-radius: 6px !important;
        color: #fff;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }
    .liveview-slot .slot-controls-btn:active {
        background: rgba(255, 255, 255, 0.35);
    }

    /* Variant selector (SD/HD picker) inside slot footer */
    .liveview-slot .vcs-variant-select,
    .liveview-slot .slot-footer select {
        font-size: 11px !important;
        padding: 0 6px !important;
        height: 28px !important;
        background: rgba(255, 255, 255, 0.18);
        border: none !important;
        border-radius: 6px !important;
        color: #fff !important;
    }

    /* Remove × button in slot header */
    .liveview-slot .slot-remove,
    .liveview-slot .slot-remove-btn {
        width: 32px !important;
        height: 32px !important;
        background: rgba(0, 0, 0, 0.5);
        border: none !important;
        border-radius: 16px !important;
        color: #fff;
        font-size: 16px;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0;
    }

    /* Picker-selected highlight: simple, no pulsing animation */
    .liveview-slot.picker-selected {
        outline: 3px solid var(--accent) !important;
        outline-offset: -3px !important;
        animation: none !important;
    }

    /* Video element sizing inside slot */
    .liveview-slot video,
    .liveview-slot .video-feed {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        background: #000 !important;
        position: absolute;
        top: 0;
        left: 0;
    }
}

/* ============================================================================
   Mobile: Camera picker bottom sheet
   ============================================================================ */
@media (max-width: 767px) {
    /* Sheet drag handle */
    .mobile-picker-handle {
        display: flex;
        justify-content: center;
        padding: 8px 0 4px;
    }
    .mobile-picker-handle::before {
        content: '';
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }

    /* Sheet header */
    body.mobile-picker-open .liveview-sidebar > .sidebar-header,
    body.mobile-picker-open .liveview-sidebar .camera-list-header {
        padding: 8px 16px 12px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        flex-shrink: 0;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
    }
    body.mobile-picker-open .liveview-sidebar h2,
    body.mobile-picker-open .liveview-sidebar h3,
    body.mobile-picker-open .liveview-sidebar .sidebar-title {
        font-size: 17px !important;
        font-weight: 600;
        margin: 0;
    }

    /* Scrollable list inside the sheet */
    body.mobile-picker-open .camera-list,
    body.mobile-picker-open .liveview-sidebar .camera-list,
    body.mobile-picker-open .liveview-sidebar > div {
        flex: 1;
        overflow-y: auto;
        padding: 8px 16px !important;
        -webkit-overflow-scrolling: touch;
    }

    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: 10px !important;
        background: rgba(255, 255, 255, 0.04) !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }
    body.mobile-picker-open .camera-item:active,
    body.mobile-picker-open .vcs-camera-item:active {
        background: rgba(255, 255, 255, 0.08) !important;
    }
    body.mobile-picker-open .camera-item.in-use,
    body.mobile-picker-open .vcs-camera-item.in-use {
        opacity: 0.5;
    }

    /* Sheet backdrop */
    .mobile-picker-backdrop {
        display: none;
    }
    body.mobile-picker-open .mobile-picker-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 199;
        animation: fadeIn 0.2s ease-out;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================================================
   Mobile: tighter toasts, compact + top-anchored
   ============================================================================ */
@media (max-width: 767px) {
    .toast,
    #toast,
    .toast-container .toast {
        position: fixed !important;
        top: calc(60px + 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: 10px !important;
        z-index: 300 !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
    }
}

/* ============================================================================
   Mobile: input font-size 16px to prevent iOS zoom-on-focus
   ============================================================================ */
@media (max-width: 767px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="search"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ============================================================================
   Mobile: kill iOS rubber-band, prevent touch text selection on chrome
   ============================================================================ */
@media (max-width: 767px) {
    html, body {
        overscroll-behavior-y: none;
    }
    .mobile-topbar,
    .mobile-tabbar,
    .liveview-slot .slot-header,
    .liveview-slot .slot-footer,
    .liveview-slot .slot-controls-btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* ============================================================================
   Mobile: video element sizing
   ============================================================================ */
@media (max-width: 767px) {
    .liveview-slot video,
    .liveview-slot .video-feed {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        background: #000;
    }
}

/* ============================================================================
   Tablet (iPad portrait, 768-1024 with touch): keep desktop layout but with
   tweaks. iPad gets the desktop sidebar — it has room. We just polish the
   touch interaction.
   ============================================================================ */
@media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) {
    /* Don't show mobile bars on iPad */
    .mobile-topbar,
    .mobile-tabbar {
        display: none !important;
    }
    /* iPad uses desktop sidebar, but ensure devices grid is 2-col */
    .devices-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    /* iPad live grid: real grid layouts */
    .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); }
}
