/* ==========================================================================
   Intel HD Audio Track Admin Dashboard — Premium Dark Theme
   ========================================================================== */

:root {
    /* Core palette */
    --bg:              #0a0c14;
    --bg-secondary:    #0f1117;
    --surface:         #161922;
    --surface-2:       #1c2030;
    --surface-3:       #222638;
    --border:          #2a2e42;
    --border-light:    #353a52;

    /* Accent */
    --accent:          #6c63ff;
    --accent-soft:     rgba(108, 99, 255, 0.15);
    --accent-hover:    #857dff;
    --accent-glow:     rgba(108, 99, 255, 0.3);

    /* Text */
    --text:            #e8eaf0;
    --text-secondary:  #8b90a8;
    --text-dim:        #5c6180;

    /* Status */
    --success:         #34d399;
    --success-soft:    rgba(52, 211, 153, 0.12);
    --danger:          #ff4d6a;
    --danger-soft:     rgba(255, 77, 106, 0.12);
    --warn:            #fbbf24;
    --warn-soft:       rgba(251, 191, 36, 0.12);
    --info:            #38bdf8;
    --info-soft:       rgba(56, 189, 248, 0.12);

    /* Layout */
    --sidebar-width:   260px;
    --radius:          10px;
    --radius-sm:       6px;
    --transition:      0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

body {
    display: flex;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.logo-dot {
    font-size: 22px;
    color: var(--accent);
    line-height: 1;
}

.logo-text {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-subtitle {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 24px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

/* ── Nav Buttons ────────────────────────────────────────────── */
.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    margin-bottom: 4px;
}

.nav-btn:hover {
    background: var(--surface);
    color: var(--text);
}

.nav-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

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

/* ── Agent List ─────────────────────────────────────────────── */
.agent-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.agent-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.agent-item:hover {
    background: var(--surface);
    border-color: var(--border);
}

.agent-item.selected {
    background: var(--accent-soft);
    border-color: var(--accent);
}

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

.agent-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse-glow 2s ease-in-out infinite;
}

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

@keyframes pulse-glow {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--success); }
    50% { opacity: 0.6; box-shadow: 0 0 12px var(--success); }
}

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

.agent-ip {
    font-size: 10px;
    color: var(--text-dim);
}

.agent-user {
    font-size: 10px;
    color: var(--accent);
    font-weight: 500;
}

.agent-placeholder {
    font-size: 12px;
    color: var(--text-dim);
    padding: 8px 12px;
    font-style: italic;
}

/* ── Connection Status ──────────────────────────────────────── */
.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
}

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

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

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

/* ==========================================================================
   MAIN CONTENT
   ========================================================================== */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 28px 32px;
}

/* ── Views ──────────────────────────────────────────────────── */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.view-header {
    margin-bottom: 24px;
}

.view-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.view-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ==========================================================================
   LIVE SCREENS GRID
   ========================================================================== */
.screen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
}

.screen-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
}

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

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

.screen-card-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.screen-card-info .agent-dot {
    width: 8px;
    height: 8px;
}

.screen-card-name {
    font-size: 13px;
    font-weight: 600;
}

.screen-card-user {
    display: block;
    font-size: 10px;
    color: var(--accent);
    font-weight: 500;
}

.screen-card-time {
    font-size: 10px;
    color: var(--text-dim);
}

.screen-card-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.screen-card-badge.live {
    background: var(--success-soft);
    color: var(--success);
}

.screen-card-badge.offline {
    background: var(--danger-soft);
    color: var(--danger);
}

.screen-card-img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.screen-card-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.screen-card-no-image {
    color: var(--text-dim);
    font-size: 12px;
    text-align: center;
}

.screen-card-no-image .big-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 8px;
    opacity: 0.4;
}

.screen-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
}

.placeholder-icon {
    font-size: 56px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.screen-placeholder .hint {
    font-size: 12px;
    margin-top: 8px;
    max-width: 400px;
    margin-inline: auto;
    line-height: 1.6;
}

/* ==========================================================================
   CONTROLS BAR
   ========================================================================== */
.controls-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    transition: border-color var(--transition);
    min-width: 180px;
}

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

/* Fix dark mode date input */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

.btn-refresh {
    padding: 8px 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-refresh:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.command-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}

.command-panel h3 {
    margin: 0 0 16px;
    font-size: 15px;
    color: var(--text);
}

.command-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.command-grid .full-width {
    grid-column: 1 / -1;
}

.btn-backup-download {
    display: inline-block;
    padding: 6px 12px;
    background: var(--accent);
    color: #ffffff !important;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.btn-backup-download:hover {
    filter: brightness(1.1);
    text-decoration: none;
}

.backup-pending {
    color: var(--warning, #f0ad4e);
    font-size: 12px;
}

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

.btn-send-command {
    padding: 10px 18px;
    background: var(--success);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-send-command:hover {
    background: #28a745;
    transform: translateY(-1px);
}

#command-payload-select:not([hidden]) {
    display: block;
    width: 100%;
    min-width: 180px;
}

#command-payload-select:not([hidden]) + #command-payload {
    display: none;
}

.command-note {
    grid-column: 1 / -1;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.4;
    padding: 10px 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   TABS
   ========================================================================== */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    padding: 10px 18px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Tab Panels ─────────────────────────────────────────────── */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

/* ==========================================================================
   DATA TABLES
   ========================================================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table thead th {
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 12px 14px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table tbody tr:nth-child(even) {
    background: var(--surface-2);
}

.data-table tbody tr:nth-child(even):hover {
    background: var(--surface-3);
}

.data-table tbody td {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tbody td.time-col {
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.data-table tbody td.type-text { color: var(--text-secondary); }
.data-table tbody td.type-image { color: var(--warn); }
.data-table tbody td.type-file { color: var(--success); }
.data-table tbody td.type-drag { color: var(--info); }

.data-table tbody td.name-old { color: var(--danger); }
.data-table tbody td.name-new { color: var(--success); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

.badge-file { background: var(--success-soft); color: var(--success); }
.badge-folder { background: var(--info-soft); color: var(--info); }
.badge-text { background: var(--accent-soft); color: var(--accent); }
.badge-image { background: var(--warn-soft); color: var(--warn); }
.badge-drag { background: var(--info-soft); color: var(--info); }

/* Empty state for tables */
.table-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-dim);
    font-size: 13px;
}

.table-empty .empty-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.3;
}

/* ==========================================================================
   FULLSCREEN MODAL
   ========================================================================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active,
.modal-overlay.is-open {
    display: flex !important;
    visibility: visible;
    opacity: 1;
    animation: fadeIn 0.2s ease;
}

#admin-modal {
    z-index: 2000;
}

#admin-modal .modal-content {
    width: min(640px, 95vw);
    overflow-y: auto;
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 95vw;
    max-height: 95vh;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 10;
}

.modal-close:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.modal-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

#modal-screen-img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 900px) {
    .sidebar {
        width: 64px;
        min-width: 64px;
        padding: 12px 8px;
    }
    .sidebar-header .logo-text,
    .sidebar-subtitle,
    .sidebar-label,
    .nav-btn span:not(.nav-icon),
    .agent-name,
    .agent-ip,
    .connection-status span {
        display: none;
    }
    .nav-btn {
        justify-content: center;
        padding: 12px;
    }
    .nav-icon {
        font-size: 20px;
    }
    .main-content {
        padding: 20px 16px;
    }
    .screen-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   DEVICE EMPTY STATE & LIVE SCREEN TAB
   ========================================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h2 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--text);
}

.device-screen-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: calc(100vh - 260px);
    min-height: 360px;
}

.device-screen-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-remote-control {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-left: auto;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.live-message-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 220px;
    min-width: 180px;
    max-width: 420px;
}

.live-message-input {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    padding: 6px 10px;
}

.btn-live-message {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.btn-live-message:hover {
    border-color: var(--accent, #3b82f6);
}

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

.policy-form-hint {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.policy-selected-count {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

.btn-remote-control:hover {
    border-color: var(--accent, #3b82f6);
    color: var(--text);
}

.btn-remote-control.active {
    background: #166534;
    border-color: #16a34a;
    color: #fff;
}

.remote-control-hint {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.remote-control-hint kbd {
    font-size: 11px;
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
}

.device-screen-frame.remote-controlling,
.device-screen-frame.remote-controlling .device-live-img,
.modal-content-remote {
    width: min(96vw, 1400px);
    max-height: 96vh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.modal-remote-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-right: 36px;
}

.modal-remote-bar h3 {
    margin: 0;
    font-size: 15px;
}

.modal-screen-wrap {
    position: relative;
    flex: 1;
    min-height: 60vh;
    background: #0a0a0a;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-screen-wrap #modal-screen-img {
    max-width: 100%;
    max-height: 78vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
}

.modal-live-video {
    display: none;
    max-width: 100%;
    max-height: 78vh;
    width: 100%;
    height: auto;
    object-fit: contain;
    background: #0a0a0a;
    pointer-events: none;
}

.modal-live-video.active {
    display: block;
}

.modal-screen-wrap.webrtc-live #modal-screen-img,
#fullscreen-modal.webrtc-live #modal-screen-img {
    display: none !important;
}

.device-screen-frame.webrtc-live .device-screen-placeholder {
    display: none !important;
}

.remote-control-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    cursor: crosshair;
    outline: 3px solid #16a34a;
    outline-offset: -3px;
    background: transparent;
}

.remote-control-overlay:focus {
    outline: 3px solid #22c55e;
    outline-offset: -3px;
}

.device-screen-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.device-camera-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-camera-control {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-camera-control:hover:not(:disabled) {
    background: var(--surface-3);
    color: var(--text-primary);
}

.btn-camera-control.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.btn-camera-control:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.camera-policy-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-dim);
}

.camera-policy-badge.allowed {
    background: var(--success-soft);
    color: var(--success);
}

.camera-policy-badge.blocked {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.camera-policy-badge.pending {
    background: rgba(234, 179, 8, 0.12);
    color: #ca8a04;
}

.screen-status-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-secondary);
}

.screen-status-badge.live {
    background: var(--success-soft);
    color: var(--success);
}

.device-screen-frame {
    flex: 1;
    background: #000;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.device-live-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: auto;
    will-change: contents;
    contain: layout paint;
}

.device-live-video {
    display: none;
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #0a0a0a;
}

.device-live-video.active {
    display: block;
}

.device-screen-frame.webrtc-live .device-live-img {
    display: none;
}

.device-camera-frame {
    max-width: 720px;
    margin: 0 auto;
}

.device-camera-img {
    object-fit: contain;
    background: #000;
}

.device-camera-panel .device-screen-placeholder span {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-dim);
    max-width: 320px;
}

.threat-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
}

.threat-badge.quarantined {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.threat-badge.detected {
    background: rgba(234, 179, 8, 0.12);
    color: #ca8a04;
}

.threat-name {
    font-weight: 600;
    color: #ef4444;
}

.url-block-reason {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(108, 99, 255, 0.12);
    color: #a59dff;
}

.device-screen-placeholder {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
}

.sidebar-dimmed {
    opacity: 0.55;
}

/* ==========================================================================
   POLICIES PAGE
   ========================================================================== */
.policy-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.policy-page-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.policy-stats {
    display: flex;
    gap: 12px;
}

.policy-stat {
    min-width: 120px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.policy-stat-value {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: var(--accent-hover);
    line-height: 1.1;
}

.policy-stat-label {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.policy-layout {
    display: grid;
    grid-template-columns: minmax(320px, 380px) 1fr;
    gap: 20px;
    align-items: start;
    height: calc(100vh - 180px);
}

.policy-form-card,
.policy-list-card {
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.policy-form-card {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
    overflow: hidden;
}

.policy-form-header {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 22px 22px 0;
}

.policy-form-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 18px;
    flex-shrink: 0;
}

.policy-form-subtitle,
.policy-list-subtitle {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

.policy-form-body {
    padding: 20px 22px 22px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.policy-field label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.policy-input,
.policy-select {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    color: var(--text);
    font-size: 13px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.policy-input:focus,
.policy-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.policy-action-preview {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
}

.policy-preview-badge {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.policy-preview-badge.block {
    background: var(--danger-soft);
    color: var(--danger);
}

.policy-preview-badge.allow {
    background: var(--success-soft);
    color: var(--success);
}

.policy-preview-badge.system {
    background: var(--info-soft);
    color: var(--info);
}

.policy-preview-badge.security {
    background: var(--warn-soft);
    color: var(--warn);
}

#policy-preview-text {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.policy-devices-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.policy-devices-tools {
    display: flex;
    align-items: center;
    gap: 6px;
}

.policy-link-btn {
    background: none;
    border: none;
    color: var(--accent-hover);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}

.policy-link-btn:hover {
    text-decoration: underline;
}

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

.policy-selected-count {
    font-size: 11px;
    color: var(--text-dim);
    margin: -4px 0 8px;
}

.policy-device-list {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    background: var(--bg-secondary);
}

.policy-device-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
}

.policy-device-item:hover {
    background: var(--surface-3);
}

.policy-device-item.selected,
.policy-device-item:has(input:checked) {
    background: var(--accent-soft);
    border-color: rgba(108, 99, 255, 0.35);
}

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

.policy-device-meta {
    flex: 1;
    min-width: 0;
}

.policy-device-meta strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.policy-device-meta small {
    display: block;
    color: var(--text-dim);
    font-size: 11px;
    margin-top: 2px;
}

.policy-device-status {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
}

.policy-device-status.online {
    color: var(--success);
}

.btn-policy-submit {
    width: 100%;
    margin-top: 4px;
    padding: 13px 18px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-policy-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px var(--accent-glow);
}

.policy-list-card {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
    overflow: hidden;
}

.policy-card-title {
    font-size: 16px;
    font-weight: 700;
}

.policy-list-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 22px 0;
}

.policy-refresh-btn {
    flex-shrink: 0;
}

.policy-cards {
    padding: 16px 22px 22px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    align-content: start;
}

.policy-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color var(--transition), transform var(--transition);
}

.policy-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.policy-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.policy-card-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
}

.policy-badge {
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.policy-badge.block { background: var(--danger-soft); color: var(--danger); }
.policy-badge.allow { background: var(--success-soft); color: var(--success); }
.policy-badge.system { background: var(--info-soft); color: var(--info); }
.policy-badge.security { background: var(--warn-soft); color: var(--warn); }

.policy-card-value {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 8px 10px;
    background: var(--surface);
    border-radius: 8px;
    word-break: break-all;
}

.policy-card-value.empty {
    color: var(--text-dim);
    font-style: italic;
}

.policy-select optgroup {
    font-weight: 700;
    color: var(--text-secondary);
    background: var(--surface);
}

.policy-select option {
    background: var(--surface-2);
    color: var(--text);
    padding: 6px;
}

.policy-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
}

.policy-card-devices-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.policy-card-date {
    color: var(--text-dim);
}

.policy-device-chip.muted {
    opacity: 0.6;
}

#view-policies.view.active {
    min-height: calc(100vh - 56px);
}

.policy-card-devices {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.policy-device-chip {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.policy-card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
}

.btn-policy-apply,
.btn-policy-delete {
    flex: 1;
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity var(--transition);
}

.btn-policy-apply {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.btn-policy-apply:hover {
    background: rgba(108, 99, 255, 0.25);
}

.btn-policy-delete {
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(255, 77, 106, 0.35);
}

.btn-policy-delete:hover {
    background: var(--danger-soft);
}

.policy-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
}

.policy-empty-icon {
    display: block;
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.8;
}

.policy-empty-state p {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.policy-empty-state span {
    font-size: 13px;
}

@media (max-width: 1100px) {
    .policy-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .policy-form-card,
    .policy-list-card {
        max-height: none;
    }

    .policy-page-header {
        flex-direction: column;
    }
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen-card {
    animation: slideInUp 0.4s ease forwards;
}

.screen-card:nth-child(2) { animation-delay: 0.05s; }
.screen-card:nth-child(3) { animation-delay: 0.1s; }
.screen-card:nth-child(4) { animation-delay: 0.15s; }
.screen-card:nth-child(5) { animation-delay: 0.2s; }
.screen-card:nth-child(6) { animation-delay: 0.25s; }

/* ==========================================================================
   DEVICE OVERVIEW & INSTALLED APPS
   ========================================================================== */
.device-overview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.device-overview-updated {
    font-size: 12px;
    color: var(--text-dim);
}

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

.device-stat-card {
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.device-stat-card.highlight {
    border-color: var(--accent-glow);
    box-shadow: 0 8px 28px rgba(108, 99, 255, 0.12);
}

.device-stat-card.wide {
    grid-column: 1 / -1;
}

.device-stat-icon {
    font-size: 22px;
}

.device-stat-card h4 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
}

.device-stat-main {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.35;
}

.device-stat-note {
    font-size: 12px;
    color: var(--text-secondary);
}

.device-stat-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.device-stat-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.device-stat-list li span {
    color: var(--text-dim);
    flex-shrink: 0;
}

.device-stat-list li strong {
    text-align: right;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.device-metric-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 4px;
}

.device-metric-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.device-metric-fill.cpu { background: linear-gradient(90deg, var(--accent), var(--accent-hover)); }
.device-metric-fill.ram { background: linear-gradient(90deg, #38bdf8, #6c63ff); }
.device-metric-fill.disk { background: linear-gradient(90deg, var(--success), #34d399); }

.device-disk-row {
    margin-bottom: 12px;
}

.device-disk-row:last-child {
    margin-bottom: 0;
}

.device-disk-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.device-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
}

.device-empty-state .big-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
}

.installed-apps-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.installed-apps-toolbar .control-input {
    min-width: 200px;
}

.installed-apps-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 600;
}

.scope-chip {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent-hover);
}

/* ==========================================================================
   LOGIN
   ========================================================================== */

body.auth-locked {
    display: block;
    overflow: auto;
}

body.auth-locked .app-shell {
    display: none !important;
}

body:not(.auth-locked) {
    display: flex;
}

body:not(.auth-locked) .login-screen {
    display: none !important;
}

.app-shell {
    display: contents;
}

.login-screen {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(108, 99, 255, 0.18), transparent 45%),
        radial-gradient(ellipse at 80% 80%, rgba(56, 189, 248, 0.1), transparent 40%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px 28px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand .logo-dot {
    font-size: 22px;
    color: var(--accent);
    display: block;
    margin-bottom: 8px;
}

.login-brand h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.login-brand p {
    color: var(--text-secondary);
    font-size: 13px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.login-field .control-input {
    width: 100%;
}

.login-error {
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid rgba(255, 77, 106, 0.35);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12px;
}

.btn-login {
    margin-top: 4px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), #4f46e5);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-login:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
}

.login-hint {
    margin-top: 18px;
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
}

.login-hint code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-secondary);
}

/* Session footer */
.user-session {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.user-session-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-session-name {
    font-weight: 700;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-session-role {
    font-size: 11px;
    color: var(--text-dim);
}

.btn-logout {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.btn-logout:hover {
    color: var(--danger);
    border-color: rgba(255, 77, 106, 0.4);
}

.tab[hidden],
.nav-btn[hidden] {
    display: none !important;
}

/* Users & Roles */
.users-layout {
    display: grid;
    grid-template-columns: minmax(300px, 380px) 1fr;
    gap: 20px;
    align-items: start;
}

@media (max-width: 980px) {
    .users-layout {
        grid-template-columns: 1fr;
    }
}

.perm-checks {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.tab-perm-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    max-height: 180px;
    overflow: auto;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.tab-perm-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
}

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

.role-legend {
    margin-top: 20px;
    padding: 16px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.role-legend h4 {
    font-size: 12px;
    margin-bottom: 8px;
    color: var(--text);
}

.role-legend ul {
    margin: 0;
    padding-left: 18px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.6;
}

.btn-user-action {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    margin-right: 4px;
}

.btn-user-action.danger:hover {
    color: var(--danger);
    border-color: rgba(255, 77, 106, 0.45);
}

.perm-pill {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
}

.perm-pill.yes {
    background: var(--success-soft);
    color: var(--success);
}

.perm-pill.no {
    background: var(--danger-soft);
    color: var(--danger);
}

.text-dim {
    color: var(--text-dim);
    font-weight: 500;
}

/* Live Speaker */
.device-speaker-panel .speaker-live-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 360px;
    gap: 20px;
    padding: 32px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.speaker-visual {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 6px;
    height: 96px;
    opacity: 0.35;
    transition: opacity 0.2s ease;
}

.speaker-visual.live {
    opacity: 1;
}

.speaker-bar {
    width: 8px;
    height: 18%;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--accent-hover), var(--info));
    transform-origin: bottom;
    transition: height 0.08s linear;
}

.speaker-visual.live .speaker-bar {
    animation: speakerPulse 0.9s ease-in-out infinite alternate;
}

.speaker-visual.live .speaker-bar:nth-child(2) { animation-delay: 0.08s; }
.speaker-visual.live .speaker-bar:nth-child(3) { animation-delay: 0.16s; }
.speaker-visual.live .speaker-bar:nth-child(4) { animation-delay: 0.04s; }
.speaker-visual.live .speaker-bar:nth-child(5) { animation-delay: 0.2s; }
.speaker-visual.live .speaker-bar:nth-child(6) { animation-delay: 0.12s; }
.speaker-visual.live .speaker-bar:nth-child(7) { animation-delay: 0.24s; }
.speaker-visual.live .speaker-bar:nth-child(8) { animation-delay: 0.06s; }

@keyframes speakerPulse {
    from { height: 18%; }
    to { height: 90%; }
}

.speaker-placeholder {
    position: static;
    background: transparent;
    border: none;
    min-height: 0;
}

.speaker-hint {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 600;
}
