/* SENTINEL DASHBOARD v2 - Modern Design System */
/* Replace entire <style> section with this */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
    /* Modern Dark Theme */
    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    --bg-elevated: #3f3f46;
    
    /* Text */
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    
    /* Brand Colors */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-muted: rgba(99, 102, 241, 0.15);
    
    /* Status Colors */
    --success: #10b981;
    --success-muted: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-muted: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-muted: rgba(239, 68, 68, 0.15);
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ========== LAYOUT ========== */
.app { display: flex; flex-direction: column; height: 100vh; }

.header {
    background: var(--bg-secondary);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-stats { display: flex; gap: 0.75rem; font-size: 0.8rem; }
.header-stat {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-lg);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}
.stat-online { background: var(--success-muted); color: var(--success); }
.stat-offline { background: var(--danger-muted); color: var(--danger); }
.stat-pending { background: var(--warning-muted); color: var(--warning); }

.main { display: flex; flex: 1; overflow: hidden; }

/* ========== SIDEBAR ========== */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
}

.sidebar-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--bg-tertiary);
    display: flex;
    gap: var(--space-sm);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.sidebar-content::-webkit-scrollbar { width: 6px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
.sidebar-content::-webkit-scrollbar-thumb:hover { background: var(--bg-elevated); }

.content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    background: var(--bg-primary);
}

/* ========== BUTTONS ========== */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-elevated); }

.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== TREE / SIDEBAR ITEMS ========== */
.section-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 1rem 0.75rem 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.tree-item {
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2px 0;
    transition: all 0.15s ease;
}
.tree-item:hover { background: var(--bg-tertiary); }
.tree-item.active { background: var(--accent); color: white; }

.tree-tenant { font-weight: 600; }
.tree-site { padding-left: 1.5rem; font-size: 0.9rem; }
.tree-device { padding-left: 2.75rem; font-size: 0.85rem; color: var(--text-secondary); }
.tree-device:hover { color: var(--text-primary); }

.unassigned-device {
    border-left: 2px solid var(--warning);
    margin-left: 0.5rem;
    background: var(--warning-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.badge {
    font-size: 0.7rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-lg);
    font-weight: 500;
}
.badge-count { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ========== PANELS / CARDS ========== */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    border: 1px solid var(--bg-tertiary);
}

.panel-title {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    font-weight: 500;
}

/* ========== OCCUPANCY PANEL ========== */
.occupancy-panel {
    padding: var(--space-md);
    border-top: 1px solid var(--bg-tertiary);
    background: var(--bg-primary);
}

.occupancy-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.occupancy-zone {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--bg-tertiary);
    transition: all 0.2s ease;
}

.zone-info { display: flex; flex-direction: column; gap: 0.125rem; }
.zone-name { font-size: 0.85rem; font-weight: 500; }
.zone-camera { font-size: 0.75rem; color: var(--text-muted); }
.zone-status { text-align: right; }
.zone-count { font-size: 1.25rem; font-weight: 700; }
.zone-dwell { font-size: 0.7rem; color: var(--text-muted); }

.risk-critical { border-left: 3px solid var(--danger); }
.risk-high { border-left: 3px solid var(--warning); }
.risk-medium { border-left: 3px solid var(--accent); }
.risk-low { border-left: 3px solid var(--success); }
.occupied { background: var(--danger-muted); border-color: var(--danger); }

.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ========== STATUS CARD ========== */
.status-card {
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    margin-bottom: var(--space-md);
    border: 1px solid transparent;
}

.status-card.online {
    background: var(--success-muted);
    border-color: rgba(16, 185, 129, 0.3);
}
.status-card.offline {
    background: var(--danger-muted);
    border-color: rgba(239, 68, 68, 0.3);
}
.status-card.pending {
    background: var(--warning-muted);
    border-color: rgba(245, 158, 11, 0.3);
}

.status-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.1);
}

.status-info h3 { font-size: 1rem; font-weight: 600; }
.status-info p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.125rem; }

/* ========== FORMS ========== */
.form-group { margin-bottom: var(--space-md); }
.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-primary);
    border: 1px solid var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-md);
}

.help-text { font-size: 0.75rem; color: var(--text-muted); margin-top: var(--space-xs); }

/* ========== TABS ========== */
.tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
    background: var(--bg-secondary);
    padding: var(--space-xs);
    border-radius: var(--radius-md);
}

.tab {
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
}

.tab:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.tab.active { background: var(--accent); color: white; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== METRICS ========== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: var(--space-sm);
}

.metric {
    background: var(--bg-primary);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--bg-tertiary);
}

.metric-value { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }
.metric-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* ========== INTEGRATION CARDS ========== */
.integration-card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    border: 1px solid var(--bg-tertiary);
}

.integration-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.integration-title { font-weight: 600; font-size: 0.9rem; }

/* ========== SCHEDULE ========== */
.schedule-days { display: flex; gap: var(--space-xs); flex-wrap: wrap; }

.day-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--bg-tertiary);
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.day-btn:hover { border-color: var(--accent); color: var(--accent); }
.day-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ========== EVENTS ========== */
.event-item {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--bg-tertiary);
    font-size: 0.85rem;
}
.event-item:last-child { border-bottom: none; }
.event-time { color: var(--text-muted); font-size: 0.75rem; }

/* ========== MODALS ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--bg-tertiary);
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title { font-weight: 600; font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

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

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--bg-tertiary);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

#modal-body { padding: var(--space-lg); }
#modal-body .form-group { margin-bottom: var(--space-md); }
#modal-body .form-group:last-child { margin-bottom: 0; }

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    padding: 0.875rem 1.5rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    z-index: 2000;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--bg-tertiary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* ========== LOGIN ========== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-box {
    background: var(--bg-secondary);
    padding: var(--space-xl);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--bg-tertiary);
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.login-logo h1 { font-size: 1.5rem; font-weight: 700; }
.login-logo p { color: var(--text-secondary); font-size: 0.875rem; margin-top: var(--space-sm); }

.login-error {
    background: var(--danger-muted);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    display: none;
    font-size: 0.875rem;
}

.login-box .btn-primary { width: 100%; padding: 0.875rem; font-size: 1rem; }

/* ========== UTILITIES ========== */
.hidden { display: none !important; }
.drag-over { background: var(--accent-muted) !important; }

.empty {
    color: var(--text-muted);
    text-align: center;
    padding: var(--space-xl);
    font-size: 0.9rem;
}

.user-menu { display: flex; align-items: center; gap: var(--space-md); }
.user-info { font-size: 0.875rem; color: var(--text-secondary); }
.user-info strong { color: var(--text-primary); font-weight: 500; }

.cred-status { font-size: 0.7rem; padding: 0.125rem 0.5rem; border-radius: var(--radius-sm); margin-left: 0.5rem; font-weight: 500; }
.cred-set { background: var(--success-muted); color: var(--success); }
.cred-empty { background: var(--danger-muted); color: var(--danger); }

.checkbox-grid { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.5rem 0.875rem;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid var(--bg-tertiary);
    transition: all 0.15s ease;
}
.checkbox-item:hover { border-color: var(--accent); }
.checkbox-item input { margin: 0; }

.snapshot-preview img { max-width: 100%; border-radius: var(--radius-md); margin-top: var(--space-sm); }

.model-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.model-modal-content { background: var(--bg-secondary); padding: var(--space-xl); border-radius: var(--radius-xl); width: 90%; max-width: 500px; border: 1px solid var(--bg-tertiary); }

.nis2-tab-content { display: block; }
.nis2-tab-content.hidden { display: none; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        bottom: 0;
        z-index: 200;
        transition: left 0.3s ease;
    }
    
    .sidebar.open { left: 0; }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 199;
        display: none;
    }
    
    .sidebar-overlay.open { display: block; }
    
    .header { padding: 0.75rem 1rem; }
    
    .content { padding: var(--space-md); }
    
    .tabs { overflow-x: auto; flex-wrap: nowrap; }
    
    .form-row { grid-template-columns: 1fr; }
    
    .metrics-grid { grid-template-columns: repeat(3, 1fr); }
    
    .user-info { display: none; }
    
    .modal { width: 95%; max-width: none; margin: var(--space-md); }
}

@media (max-width: 480px) {
    .header-stats { display: none; }
    
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    
    .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.7rem; }
}

/* Icon size fix */
[data-lucide] { width: 14px; height: 14px; }
.btn [data-lucide] { width: 12px; height: 12px; margin-right: 4px; }
.tab [data-lucide] { width: 12px; height: 12px; margin-right: 4px; }
.header-stat [data-lucide] { width: 10px; height: 10px; }
.tree-item [data-lucide] { width: 14px; height: 14px; margin-right: 6px; }

/* Modal form inputs fix */
.modal input,
.modal select,
.modal textarea,
#camera-edit-modal input,
#camera-edit-modal select,
#camera-edit-modal textarea {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-tertiary) !important;
}

.modal input:focus,
.modal select:focus,
#camera-edit-modal input:focus,
#camera-edit-modal select:focus {
    border-color: var(--accent) !important;
    outline: none;
}

/* Checkbox labels */
.modal label,
#camera-edit-modal label {
    color: var(--text-primary);
}

/* Modal form inputs fix */
.modal input,
.modal select,
.modal textarea,
#camera-edit-modal input,
#camera-edit-modal select,
#camera-edit-modal textarea {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-tertiary) !important;
}

.modal input:focus,
.modal select:focus,
#camera-edit-modal input:focus,
#camera-edit-modal select:focus {
    border-color: var(--accent) !important;
    outline: none;
}

.modal label,
#camera-edit-modal label {
    color: var(--text-primary);
}

/* All select and option elements */
select,
select option {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Inline selects in modals */
[style*="margin-left"] select,
label select {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-tertiary) !important;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

/* Camera edit modal specific */
#camera-edit-modal select,
#camera-edit-modal option {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Risk level select */
select[id*="risk"],
select[id*="type"] {
    background: var(--bg-primary) !important;
}

/* Force dark theme on ALL selects */
select.form-control,
#edit-roi-risk,
#edit-speaker-type,
#edit-speaker-audio-person,
#edit-speaker-audio-car,
#edit-speaker-audio-truck {
    background: var(--bg-primary) !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-tertiary) !important;
}

/* Option elements */
select.form-control option,
#edit-roi-risk option,
#edit-speaker-type option,
#edit-speaker-audio-person option,
#edit-speaker-audio-car option,
#edit-speaker-audio-truck option {
    background: var(--bg-primary) !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Form control class - dark theme */
.form-control,
input.form-control,
select.form-control,
textarea.form-control {
    background: var(--bg-primary) !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-tertiary) !important;
    padding: 0.5rem;
    border-radius: 0.375rem;
}

.form-control:focus {
    border-color: var(--accent) !important;
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-muted);
}

/* Zone name input specifically */
#edit-roi-name {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Scrollbar dark theme */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-elevated);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) var(--bg-primary);
}
