/**
 * FITO CAMERA MANAGER - STYLESHEET CHUẨN MINIMALISM & ENTERPRISE
 * - Thương hiệu: FITO PHARMA GMP-WHO
 * - Tone màu chủ đạo (Primary): Xanh lá FITO (#00A859)
 * - Phong cách: Theme Trắng (Light Mode), Tối giản (Minimalism), Góc cạnh sắc nét (Bớt bo cong: 2px - 4px)
 * - Kiến trúc: Thuần CSS & CSS Variables hiện đại (Zero Dependency, Không cần NodeJS/Build tool)
 */

:root {
    /* 1. MÀU SẮC THƯƠNG HIỆU FITO */
    --primary: #00A859;
    --primary-hover: #008F4C;
    --primary-active: #007840;
    --primary-light: #EBF8F2;
    --primary-border: rgba(0, 168, 89, 0.35);
    --primary-shadow: rgba(0, 168, 89, 0.16);

    /* 2. HỆ THỐNG GIAO DIỆN THEME TRẮNG (LIGHT THEME) */
    --bg-body: #F4F6F9;
    --bg-surface: #FFFFFF;
    --bg-subtle: #F8FAFC;
    --bg-hover: #F1F5F9;
    --bg-muted: #94A3B8;

    --border-color: #E2E8F0;
    --border-input: #CBD5E1;
    --border-focus: var(--primary);
    --border-muted: #c3c7cd;

    --text-main: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    /* 3. TRẠNG THÁI VÀ MÀU NGỮ NGHĨA */
    --success: #00A859;
    --success-light: #EBF8F2;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --danger-light: #FEE2E2;
    --warning: #F59E0B;

    /* 4. HÌNH KHỐI MINIMALISM SẮC NÉT (BỚT BO CONG) */
    --radius-xs: 2px;
    --radius-sm: 3px;
    --radius-md: 4px;

    /* 5. ĐỔ BÓNG TỐI GIẢN */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);
    --shadow-modal: 0 16px 40px rgba(15, 23, 42, 0.14);

    --header-height: 54px;
}

/* ========================================================================== */
/* RESET & CƠ BẢN                                                             */
/* ========================================================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 13px;
    line-height: 1.45;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar phẳng, thanh mảnh */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: var(--radius-xs);
}

::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* ========================================================================== */
/* 1. TOP NAVIGATION HEADER (THEME TRẮNG, DẸP CHỮ BAN GIÁM ĐỐC)              */
/* ========================================================================== */

.top-nav {
    flex-shrink: 0;
    min-width: 0;
    gap: 12px;
    overflow-x: auto;
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-xs);
}

/* Logo & Tên hệ thống */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo-container {
    height: 34px;
    display: flex;
    align-items: center;
}

.brand-img-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.brand-text h1,
.brand-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 1;
    margin: 0;
}

.system-status {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.status-dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--primary-border);
}

/* Bộ điều khiển lưới xem (Grid Buttons: 1x1, 2x2, ...) */
.grid-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctrl-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.grid-buttons {
    display: inline-flex;
    align-items: center;
    height: 32px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
    border: 1px solid var(--border-color);
    gap: 2px;
    box-sizing: border-box;
}

.btn-grid {
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all 0.15s ease;
    box-sizing: border-box;
}

.btn-grid:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.btn-grid.active {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: var(--shadow-xs);
}

/* Bộ phân trang (Trước / Sau) */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Nhóm nút công cụ thao tác */
.action-tools {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    height: 32px;
}

.tool-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-border);
    color: var(--primary-hover);
}

.tool-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #FFFFFF;
}

/* Nút Đăng Xuất tinh gọn (Loại bỏ chữ Ban Giám Đốc) */
.btn-logout {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-logout:hover {
    background: var(--danger-light);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

/* ========================================================================== */
/* 2. MA TRẬN CAMERA (WORKSPACE MATRIX)                                       */
/* ========================================================================== */

.matrix-container {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 6px;
    background: #F3F5F8;
}

.camera-grid {
    display: grid;
    gap: 6px;
    width: 100%;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.camera-workspace { display: flex; flex: 1; min-width: 0; min-height: 0; overflow: hidden; }
.group-sidebar { width: 270px; flex-shrink: 0; overflow-y: auto; background: var(--bg-surface); border-right: 1px solid var(--border-color); padding: 10px; transition: width .22s ease, padding .22s ease, opacity .18s ease, transform .22s ease; }
.sidebar-collapsed .group-sidebar { width: 0; padding-left: 0; padding-right: 0; border-right: 0; opacity: 0; transform: translateX(-14px); pointer-events: none; overflow: hidden; }
.sidebar-toggle { flex-shrink: 0; }
.group-sidebar[hidden] { display: none; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.hidden-groups-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 8px 0; }
.group-row { display: flex; align-items: center; gap: 2px; min-height: 32px; border-radius: 3px; position: relative; }
.group-row.insert-before { box-shadow: inset 0 3px 0 var(--primary) !important; }
.group-row.insert-after { box-shadow: inset 0 -3px 0 var(--primary) !important; }
.group-row.drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; background: var(--success-light); }
.group-action, .group-name, .group-select { border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; padding: 5px; border-radius: 3px; }
.group-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-weight: 600; cursor: grab; }
.group-name:active { cursor: grabbing; }
.group-select { display: block; text-align: left; width: 100%; padding: 8px; }
.group-action:hover, .group-name:hover, .group-select:hover { background: var(--bg-hover); }
.selected { background: var(--success-light); color: var(--primary); }
.hidden-group { opacity: .65; }
.sidebar-camera { display: flex; gap: 4px; align-items: center; padding: 5px 0; font-size: 12px; }
.sidebar-camera span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: grab; }
.sidebar-camera.insert-before { box-shadow: inset 0 3px 0 var(--primary); }
.sidebar-camera.insert-after { box-shadow: inset 0 -3px 0 var(--primary); }
.sidebar-camera select { width: 74px; font-size: 11px; border: 1px solid var(--border-color); border-radius: 3px; }
.cam-card-header[draggable] { cursor: grab; user-select: none; }
.cam-card-header[draggable]:active { cursor: grabbing; }
.btn-rename-camera { flex-shrink: 0; border: 0; background: transparent; color: white; cursor: pointer; padding: 3px 6px; border-radius: 3px; font-size: 16px; }
.btn-rename-camera:hover, .btn-rename-camera:focus-visible { background: rgba(255,255,255,.2); }
.camera-grid.grouped-grid { display: block; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; }
.matrix-group-section { padding: 8px; margin-bottom: 12px; border: 1px solid #b8d8c9; border-radius: 5px; background: #edf6f1; }
.matrix-group-children { margin-left: 12px; padding-left: 10px; border-left: 2px solid #8dc4a9; }
.matrix-group-children:empty { display: none; }
.matrix-group-children > .matrix-group-section { margin-top: 10px; margin-bottom: 0; background: var(--bg-surface); }
.section-camera-grid { display: grid; grid-template-columns: repeat(var(--camera-columns, 4), minmax(0, 1fr)); gap: 6px; position: relative; margin-top: 6px; }
.section-camera-grid:empty { display: none; }
.grouped-grid .camera-cell { align-self: start; }
.grouped-grid .cam-card-body { flex: none; aspect-ratio: 16 / 9; }
.matrix-group-heading { grid-column: 1 / -1; min-height: 30px; min-width: 0; display: flex; align-items: center; border-left: 3px solid var(--primary); background: var(--bg-surface); border-radius: 3px; padding: 3px 10px; }
.matrix-group-heading button { border: 0; background: transparent; font-size: 12px; font-weight: 600; color: var(--text-main); cursor: pointer; text-align: left; }
.matrix-group-heading[data-group-id=""] { border-left-color: var(--bg-muted); }
.matrix-group-hint { color: var(--text-muted); font-size: 11px; margin-left: auto; padding-left: 10px; }
.drop-target { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--success-light); }
.drag-source { position: absolute !important; opacity: 0; pointer-events: none; }
.camera-group-end { display: none; min-width: 0; min-height: 70px; aspect-ratio: 16 / 9; border: 2px dashed #b5cfc0; border-radius: 4px; align-items: center; justify-content: center; color: #137847; font-size: 12px; }
.camera-drag-active .camera-group-end, .camera-group-end.is-empty { display: flex; }
/* Preview occupies the complete card, including its 32px header. */
.camera-drop-placeholder { position: relative; min-width: 0; border: 1px dashed var(--primary); border-radius: 4px; background: #dcf3e5; color: #137847; font-size: 12px; font-weight: 600; align-self: start; }
.camera-drop-placeholder::before { content: ''; display: block; padding-top: calc(56.25% + 32px); }
.camera-drop-placeholder > span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; text-align: center; }
.section-camera-grid > .camera-drop-placeholder + .camera-group-end { display: none; }
.section-camera-grid[hidden] { display: none !important; }
#btnPrevPage[hidden], #btnNextPage[hidden], #pageIndicator[hidden] { display: none; }
.group-hint { font-size: 11px; color: var(--text-secondary); line-height: 1.5; margin-top: 12px; }
.view-label { padding: 3px 2px 8px; font-size: 12px; color: var(--text-secondary); font-weight: 600; }
#layoutStatus { font-size: 12px; min-height: 18px; padding: 2px; color: var(--primary); }
#layoutStatus.error { color: var(--danger); }
.group-dialog { width: min(420px, 90vw); border: 1px solid var(--border-color); border-radius: 6px; padding: 22px; color: var(--text-main); }
.group-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.group-dialog h3 { margin-bottom: 16px; }
#groupFormError { color: var(--danger); font-size: 12px; margin-bottom: 8px; }
.group-dialog label:not(.hidden-groups-toggle) { display: block; font-size: 13px; margin-bottom: 12px; }
.group-dialog input:not([type=checkbox]), .group-dialog select { display: block; width: 100%; margin-top: 5px; padding: 8px; border: 1px solid var(--border-color); border-radius: 3px; }
.group-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (max-width: 900px) { .group-sidebar { width: 220px; } }
@media (max-width: 600px) { .group-sidebar { position: absolute; z-index: 20; height: calc(100% - var(--header-height)); box-shadow: var(--shadow-modal); } }
@media (prefers-reduced-motion: reduce) { .group-sidebar { transition: none; } }

.grid-1  { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.grid-4  { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
.grid-9  { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
.grid-16 { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
.grid-25 { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(0, 1fr)); }

/* Ô Camera sắc nét (Card thiết kế hiện đại) */
.camera-cell {
    min-width: 0;
    min-height: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-xs);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.camera-cell:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Header từng ô Camera màu xanh lá FITO (#00A859) */
.cam-card-header {
    height: 32px;
    background-color: var(--primary); /* Xanh lá FITO */
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    flex-shrink: 0;
    user-select: none;
    border-top-left-radius: var(--radius-xs);
    border-top-right-radius: var(--radius-xs);
}

.cam-card-title {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-weight: 700;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
}

.cam-card-badge.offline { background: rgba(127, 29, 29, 0.9); }

/* Phần Body chứa Canvas video */
.cam-card-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000000;
    min-height: 0;
    width: 100%;
}

.cam-card-body canvas.camera-canvas {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block;
    background: #000000;
}

.cam-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
    padding: 3px 8px;
    border-radius: var(--radius-xs);
    font-size: 10px;
    font-weight: 600;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.2s ease;
}

.cell-controls-bottom {
    position: absolute;
    bottom: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 10;
}

.camera-cell:hover .cell-controls-bottom {
    opacity: 1;
}

.btn-cell-tool {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #FFFFFF;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-cell-tool:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* Empty camera slot */
.camera-cell.empty-slot {
    background: #0B0E14;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    font-size: 12px;
}

/* ========================================================================== */
/* 3. MODAL CẤU HÌNH ĐA ĐẦU GHI (NVR SETTINGS - FIX TRIỆT ĐỂ LỖI GIAO DIỆN)  */
/* ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-backdrop.open,
.modal-backdrop.show,
.modal-backdrop[style*="display: block"],
.modal-backdrop[style*="display: flex"] {
    display: flex !important;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-card.modal-xl {
    width: 1060px;
    max-width: 95vw;
    height: 84vh;
}

/* Modal Header */
.modal-header {
    height: 52px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.modal-title-with-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-title-with-logo img {
    height: 28px;
    width: auto;
}

.modal-title-with-logo h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.2px;
}

/* Nút X đóng Modal trên Header */
.modal-header .close-modal {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    font-size: 24px;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all 0.15s ease;
    padding: 0;
}

.modal-header .close-modal:hover {
    color: var(--danger);
    background: var(--danger-light);
    border-color: rgba(239, 68, 68, 0.2);
}

/* Modal Body Layout 2 cột */
.modal-body.settings-multi-layout {
    flex: 1;
    overflow: hidden;
    display: flex;
    background: var(--bg-surface);
}

/* -------------------------------------------------------------------------- */
/* CỘT TRÁI: SIDEBAR DANH SÁCH ĐẦU THU (RỘNG RÃI, THÔNG THOÁNG)               */
/* -------------------------------------------------------------------------- */

.settings-sidebar {
    width: 310px;
    min-width: 310px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-subtle);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-subtle);
}

.sidebar-header h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Danh sách Item đầu thu */
.device-nav-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.device-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    gap: 8px;
}

.device-nav-item:hover {
    border-color: var(--primary-border);
    background: var(--primary-light);
}

.device-nav-item.active {
    background: var(--bg-surface);
    border-color: var(--primary);
    border-left: 3px solid var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Phần chi tiết bên trong thẻ đầu thu */
.dev-item-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.dev-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dev-status-indicator.active {
    background-color: var(--primary);
    box-shadow: 0 0 4px var(--primary-border);
}

.dev-status-indicator.inactive {
    background-color: var(--border-input);
}

.dev-item-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dev-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-nav-item.active .dev-item-title {
    color: var(--primary-hover);
}

.dev-item-host {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.dev-item-ch-badge {
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
}

.device-nav-item.active .dev-item-ch-badge {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}

/* Sidebar Footer (Tab Đổi mật khẩu) */
.sidebar-footer-nav {
    border-top: 1px solid var(--border-color);
    padding: 10px;
    background: var(--bg-subtle);
}

.sidebar-nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sidebar-nav-item:hover,
.sidebar-nav-item.active {
    background: var(--primary-light);
    border-color: var(--primary-border);
    color: var(--primary);
}

/* -------------------------------------------------------------------------- */
/* CỘT PHẢI: CHI TIẾT CẤU HÌNH ĐẦU THU & DANH SÁCH KÊNH                       */
/* -------------------------------------------------------------------------- */

.settings-content-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 24px;
    background: var(--bg-surface);
    overflow: hidden;
    min-width: 0;
}

.tab-pane {
    display: none !important;
}

.tab-pane.active {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    height: 100%;
    min-height: 0;
}

#passwordPane h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 6px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Pane Header & Device Actions */
.pane-header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.pane-header-actions h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.device-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Switch Toggle Kích hoạt */
.switch-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.switch-toggle input {
    display: none;
}

.switch-toggle .slider {
    width: 36px;
    height: 20px;
    background: var(--border-input);
    border-radius: 10px;
    position: relative;
    transition: background-color 0.15s ease;
}

.switch-toggle .slider:before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    top: 2px;
    background: #FFFFFF;
    border-radius: 50%;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch-toggle input:checked + .slider {
    background: var(--primary);
}

.switch-toggle input:checked + .slider:before {
    transform: translateX(16px);
}

.switch-toggle .switch-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}

/* Form Grid thông tin NVR */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-row label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
}

.form-row input,
.form-row select {
    background: var(--bg-surface);
    border: 1px solid var(--border-input);
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-row input:focus,
.form-row select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-shadow);
}

/* Phần danh sách kênh thuộc đầu thu */
.channel-list-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-top: 0;
}

.channel-list-section h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.channel-config-table {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    max-height: none;
    height: 100%;
    overflow-y: auto;
    background: var(--bg-subtle);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.channel-config-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-surface);
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border-color);
    transition: border-color 0.15s ease;
}

.channel-config-row:hover {
    border-color: var(--border-input);
}

.ch-select-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 80px;
    flex-shrink: 0;
}

.ch-enable-cb {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.ch-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
}

.ch-name-input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 5px 8px;
    border-radius: var(--radius-xs);
    color: var(--text-main);
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s ease;
}

.ch-name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary-shadow);
}

/* Modal Footer */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
}

/* ========================================================================== */
/* 4. BUTTONS & UTILITIES THEME TRẮNG                                         */
/* ========================================================================== */

.btn-primary {
    background-color: var(--primary);
    color: #FFFFFF;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-primary:active {
    background-color: var(--primary-active);
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-secondary:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
    border-color: var(--border-input);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-xs);
    border: 1px solid transparent;
    cursor: pointer;
}

.btn-success {
    background-color: var(--primary);
    color: #FFFFFF;
}

.btn-success:hover {
    background-color: var(--primary-hover);
}

.btn-danger {
    background-color: var(--danger-light);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background-color: var(--danger);
    color: #FFFFFF;
}

/* ========================================================================== */
/* 5. MÀN HÌNH ĐĂNG NHẬP (LOGIN OVERLAY - MINIMALISM LIGHT THEME)             */
/* ========================================================================== */

.login-overlay {
    position: fixed;
    inset: 0;
    background: #F1F5F9;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
    box-shadow: var(--shadow-modal);
}

.login-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo-img {
    height: 52px;
    width: auto;
    margin-bottom: 14px;
}

.login-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.2px;
}

.login-header p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-card .form-group {
    margin-bottom: 16px;
}

.login-card .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-input);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-card input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-shadow);
}

.btn-block {
    width: 100%;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

.login-error-msg {
    background: var(--danger-light);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius-xs);
    font-size: 12px;
    margin-bottom: 14px;
}

.login-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 16px;
}

.login-hint code {
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    color: var(--primary);
    font-weight: 600;
}
