/* ============================================
   Modern Security Dashboard Theme
   ============================================ */
:root {
    /* Brand Colors (60-30-10 Rule) */
    --brand-primary: #102c52;      /* 60% - Main background */
    --brand-secondary: #d3efef;    /* 30% - Accent/content areas */
    --brand-action: #d91821;       /* 10% - Buttons/CTAs */
    
    /* Primary Colors */
    --primary-color: #d91821;
    --primary-dark: #b01419;
    --primary-light: #e63946;
    
    /* Status Colors */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #d91821;
    --info-color: #6ba8cc;
    
    /* Background Colors (60% - #102c52 dominant) */
    --bg-primary: #102c52;
    --bg-secondary: #0d2440;
    --bg-tertiary: #163a66;
    --card-bg: #163a66;
    --card-hover: #1a4575;
    
    /* Text Colors (using brand-secondary #d3efef for readability) */
    --text-primary: #d3efef;
    --text-secondary: #b8d9d9;
    --text-muted: #8ab8b8;
    --text-dim: #6a9898;
    
    /* Border & Divider */
    --border-color: #334155;
    --border-light: #475569;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
    
    /* Glow Effects */
    --glow-success: 0 0 20px rgba(16, 185, 129, 0.3);
    --glow-warning: 0 0 20px rgba(245, 158, 11, 0.3);
    --glow-danger: 0 0 20px rgba(239, 68, 68, 0.3);
    --glow-primary: 0 0 20px rgba(37, 99, 235, 0.3);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}


/* ============================================
   Global Reset & Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Inter', 
                 'Oxygen', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
    background: var(--brand-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Dashboard Layout
   ============================================ */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.dashboard {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============================================
   Header Section
   ============================================ */
.header {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
}

.btn-secondary:hover {
    background: var(--card-hover);
    border-color: var(--brand-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--brand-action);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.refresh-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 0 20px rgba(217, 24, 33, 0.4);
}

.refresh-btn:active {
    transform: translateY(0);
}

.refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.refresh-icon {
    display: inline-block;
    font-size: 1.125rem;
    transition: transform var(--transition-slow);
}

.refresh-btn:disabled .refresh-icon {
    animation: spin 1s linear infinite;
}

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.status-text {
    font-size: 0.875rem;
    font-weight: 500;
}

/* ============================================
   Statistics Grid
   ============================================ */
.statistics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* ============================================
   Navigation Bar
   ============================================ */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(22, 58, 102, 0.95);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-icon {
    font-size: 2rem;
    animation: pulse 2s ease-in-out infinite;
}

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

.nav-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.nav-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: blink 2s ease-in-out infinite;
}

.connection-status.connected .status-dot {
    background: var(--success-color);
    box-shadow: var(--glow-success);
}

.connection-status.error .status-dot {
    background: var(--danger-color);
    box-shadow: var(--glow-danger);
}

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

.btn-refresh {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--brand-action);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.btn-refresh:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 0 20px rgba(217, 24, 33, 0.4);
}

.btn-refresh:active {
    transform: translateY(0);
}

.btn-refresh:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.refresh-icon {
    display: inline-block;
    font-size: 1.125rem;
    transition: transform var(--transition-slow);
}

.btn-refresh:disabled .refresh-icon {
    animation: spin 1s linear infinite;
}

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

/* ============================================
   Statistics Overview
   ============================================ */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-light);
}

.stat-card.stat-primary {
    background: linear-gradient(135deg, var(--primary-dark), var(--brand-action));
    border-color: var(--primary-light);
}

.stat-icon {
    font-size: 2rem;
    opacity: 0.9;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card.stat-primary .stat-value {
    color: white;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-card.stat-primary .stat-label {
    color: rgba(255, 255, 255, 0.9);
}

/* ============================================
   Controls Bar
   ============================================ */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.last-update {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.update-icon {
    font-size: 1rem;
}

.filter-controls {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.filter-btn.active {
    background: var(--brand-action);
    color: white;
    border-color: var(--brand-action);
    box-shadow: 0 0 20px rgba(217, 24, 33, 0.3);
}

/* ============================================
   Loading & Error States
   ============================================ */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.loading-indicator p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

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

.error-message {
    background: rgba(217, 24, 33, 0.1);
    border: 1px solid var(--brand-action);
    border-left: 4px solid var(--brand-action);
    border-radius: 0.5rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    text-align: center;
}

.empty-state p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

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

.hidden {
    display: none !important;
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-content {
    text-align: center;
}

.spinner-large {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ============================================
   Alert Component
   ============================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    border: 1px solid;
    box-shadow: var(--shadow-md);
    animation: slideDown var(--transition-base);
}

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

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
    color: var(--text-primary);
}

.alert-icon {
    font-size: 1.5rem;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.alert-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

.alert-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast);
}

.alert-close:hover {
    color: var(--text-primary);
}

/* ============================================
   Room Grid
   ============================================ */
.room-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

/* ============================================
   Room Card - Enhanced Design
   ============================================ */
.room-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.room-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--brand-action), var(--brand-secondary));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.room-card:hover::before {
    opacity: 1;
}

.room-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-xl);
    border-color: var(--brand-secondary);
}

.room-card.stale-data {
    border-color: var(--warning-color);
    opacity: 0.85;
}

.room-card.stale-data::before {
    background: var(--warning-color);
    opacity: 1;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.room-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.room-icon {
    font-size: 1.5rem;
}

.room-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.room-status-badge {
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.room-status-badge.empty {
    background: rgba(14, 165, 233, 0.15);
    color: var(--info-color);
}

.room-status-badge.low {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

.room-status-badge.moderate {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning-color);
}

.room-status-badge.high {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

.room-status-badge .status-dot {
    width: 6px;
    height: 6px;
}

.room-status-badge.empty .status-dot {
    background: var(--info-color);
}

.room-status-badge.low .status-dot {
    background: var(--success-color);
}

.room-status-badge.moderate .status-dot {
    background: var(--warning-color);
    animation: blink 1.5s ease-in-out infinite;
}

.room-status-badge.high .status-dot {
    background: var(--danger-color);
    animation: blink 1s ease-in-out infinite;
}

.room-body {
    flex: 1;
}

.occupancy-display {
    text-align: center;
    padding: 1.5rem 0;
}

.occupancy-number {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.occupancy-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.capacity-bar-container {
    margin-top: 1rem;
}

.capacity-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.capacity-fill {
    height: 100%;
    transition: width var(--transition-slow), background var(--transition-base);
    border-radius: 4px;
}

.capacity-fill.empty {
    background: var(--info-color);
}

.capacity-fill.low {
    background: var(--success-color);
}

.capacity-fill.moderate {
    background: var(--warning-color);
}

.capacity-fill.high {
    background: var(--danger-color);
}

.capacity-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-text {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-text.empty {
    color: var(--info-color);
}

.status-text.low {
    color: var(--success-color);
}

.status-text.moderate {
    color: var(--warning-color);
}

.status-text.high {
    color: var(--danger-color);
}

.room-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.timestamp {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.timestamp.stale {
    color: var(--warning-color);
}

.time-icon {
    font-size: 0.875rem;
}

.stale-badge {
    background: var(--warning-color);
    color: var(--bg-primary);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.625rem;
    margin-left: auto;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--card-bg);
    border: 1px dashed var(--border-color);
    border-radius: 1rem;
    margin-bottom: 2rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.5;
}

.empty-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-message {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.empty-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ============================================
   Footer
   ============================================ */
.dashboard-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--border-color);
    margin-top: 2rem;
}

.dashboard-footer p {
    margin: 0.25rem 0;
}

.status-operational {
    color: var(--success-color);
    font-weight: 600;
}

.footer-hint {
    color: var(--text-dim);
    font-size: 0.75rem;
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden {
    display: none !important;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .stats-overview {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .room-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 768px) {
    .navbar {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        position: relative;
    }
    
    .nav-brand {
        width: 100%;
    }
    
    .nav-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .btn-text {
        display: none;
    }
    
    .controls-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .filter-controls {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
    
    .filter-btn {
        text-align: center;
    }
}

@media (max-width: 640px) {
    .stats-overview {
        grid-template-columns: 1fr;
    }
    
    .room-grid {
        grid-template-columns: 1fr;
    }
    
    .occupancy-number {
        font-size: 2.5rem;
    }
    
    .nav-title {
        font-size: 1.25rem;
    }
}

/* ============================================
   Floor Headers
   ============================================ */
.floor-header {
    grid-column: 1 / -1;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.floor-header:first-child {
    margin-top: 0;
}

.floor-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-secondary);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--brand-action);
    display: inline-block;
    margin: 0;
}

/* ============================================
   Room Card - No Data State
   ============================================ */
.room-card.no-data {
    opacity: 0.7;
    border-style: dashed;
    border-color: var(--border-light);
}

.room-card.no-data:hover {
    transform: none;
    box-shadow: var(--shadow-md);
}

.room-card.no-data .occupancy-number {
    font-size: 3rem;
}

.room-card.no-data .timestamp.no-data {
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .navbar,
    .controls-bar,
    .dashboard-footer,
    .btn-refresh,
    .filter-controls {
        display: none;
    }
    
    .room-card {
        break-inside: avoid;
    }
    
    .floor-header {
        page-break-after: avoid;
    }
}