/* ===== CSS RESET & VARIABLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark sidebar colors */
    --sidebar-bg: #1a1d29;
    --sidebar-hover: #252938;
    --sidebar-active: #2d3142;
    
    /* Main content colors */
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fc;
    
    /* Text colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;      
    
    /* Accent colors - subdued */
    --color-blue: #3b82f6;
    --color-green: #10b981;
    --color-red: #ef4444;
    --color-yellow: #f59e0b;
    --color-purple: #8b5cf6;
    
    /* Status colors - muted */
    --status-online: #10b981;
    --status-offline: #94a3b8;
    --status-warning: #f59e0b;
    --status-error: #ef4444;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    /* Borders */
    --border-color: #e2e8f0;
    --border-radius: 8px;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: var(--spacing-lg) var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-image {
    width: 180px;
    height: auto;
}

.sidebar-nav {
    flex: 1;
    padding: var(--spacing-md) 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px var(--spacing-md);
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
    margin: 2px 8px;
    border-radius: 6px;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #ffffff;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #ffffff;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--color-blue);
    border-radius: 0 2px 2px 0;
}

.nav-item i {
    font-size: 18px;
    width: 20px;
    text-align: center;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--color-red);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-blue), var(--color-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.user-details {
    flex: 1;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
}

.user-role {
    font-size: 12px;
    color: #94a3b8;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    background: var(--bg-secondary);
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-title p {
    font-size: 14px;
    color: var(--text-secondary);
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.search-box i {
    color: var(--text-muted);
    font-size: 14px;
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    width: 200px;
    color: var(--text-primary);
    font-size: 14px;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

.notification-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--color-red);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

/* ===== CONTENT WRAPPER ===== */
.content-wrapper {
    padding: var(--spacing-xl);
    flex: 1;
}

.view-content {
    display: none;
}

.view-content.active {
    display: block;
}

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--bg-secondary);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    display: flex;
    gap: var(--spacing-md);
    transition: all 0.2s ease;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--text-muted);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.1);
    color: var(--color-blue);
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-green);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-red);
}

.stat-icon.yellow {
    background: rgba(245, 158, 11, 0.1);
    color: var(--color-yellow);
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-change {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-change.positive {
    color: var(--color-green);
}

.stat-change.negative {
    color: var(--color-red);
}

.stat-change.neutral {
    color: var(--text-secondary);
}

.stat-change i {
    font-size: 12px;
}

/* ===== CHARTS ROW ===== */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.chart-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: var(--spacing-lg);
}

.chart-container {
    height: 250px;
    position: relative;
}

.time-filter {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
}

.time-filter:focus {
    outline: none;
    border-color: var(--color-blue);
}

/* ===== MAP STYLES ===== */
#mapPreview {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

#statusOverlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 1000;
}

.map-preview {
    height: 420px;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    position: relative;
    background: white;
}

.map-preview-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.card-header h3 i {
    margin-right: 8px;
    color: var(--color-blue);
}

.btn-link {
    background: none;
    border: none;
    color: #3b82f6;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    padding: 0;
    transition: color 0.2s;
}

.btn-link:hover {
    color: #2563eb;
}

/* Leaflet map marker styles */
.device-marker-icon {
    pointer-events: auto;
}

.device-marker-icon .marker-wrap {
    transform: translate(-50%, -100%);
    position: relative;
    display: inline-block;
    text-align: center;
    white-space: nowrap;
}

.device-marker-icon .marker-label {
    display: inline-block;
    color: #fff;
    padding: 4px 8px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    line-height: 1;
    background: #10b981;
}

.device-marker-icon .marker-pin {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 100%;
    margin-top: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    background: #10b981;
}

/* ===== MAP IFRAME STYLES ===== */
.map-iframe-container {
    width: 100%;
    height: 420px;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}

.map-iframe-preview {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 0 0 8px 8px;
}

.full-map-container {
    width: 100%;
    height: calc(100vh - 280px);
    min-height: 500px;
    border-radius: 8px;
    overflow: hidden;
}

.map-iframe-full {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
}

/* ===== DEVICE STATUS CARD (Device Map View) ===== */
.device-status-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px 28px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.device-status-left {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.device-status-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0;
}

.status-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #374151;
}

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

.status-dot.online {
    background-color: #10b981;
}

.status-dot.alert {
    background-color: #f59e0b;
}

.status-dot.offline {
    background-color: #9ca3af;
}

.device-status-right {
    display: flex;
    align-items: flex-start;
}

.device-filter-buttons {
    display: flex;
    gap: 0;
}

.device-filter-btn {
    min-width: 85px;
    height: 75px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
    padding: 10px 16px;
    line-height: 1.4;
}

.device-filter-btn:first-child {
    border-radius: 10px 0 0 10px;
}

.device-filter-btn:last-child {
    border-radius: 0 10px 10px 0;
}

.device-filter-btn:not(:first-child) {
    border-left: none;
}

.device-filter-btn:hover {
    background: #f9fafb;
    color: #374151;
}

.device-filter-btn.active {
    background: #3b82f6;
    color: #ffffff;
    border-color: #3b82f6;
}

.device-filter-btn.active + .device-filter-btn {
    border-left: 1px solid #e5e7eb;
}

/* ===== TABLE CARD (General) ===== */
.table-card {
    background: #fff;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    margin-bottom: var(--spacing-lg);
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead th {
    background: #f8fafc;
    padding: 0.875rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e5e7eb;
}

.data-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table tbody td {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    color: #475569;
    vertical-align: middle;
}

/* Device Cell */
.device-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.device-cell i {
    color: #64748b;
}

/* Severity Badge */
.severity-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.severity-badge.critical {
    background: #fef2f2;
    color: #dc2626;
}

.severity-badge.high {
    background: #fff7ed;
    color: #ea580c;
}

.severity-badge.medium {
    background: #fefce8;
    color: #ca8a04;
}

.severity-badge.low {
    background: #f0f9ff;
    color: #0284c7;
}

/* Status Badge (General) */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.active {
    background: #dcfce7;
    color: #16a34a;
}

.status-badge.resolved {
    background: #f1f5f9;
    color: #64748b;
}

.status-badge.online {
    background: transparent;
    color: #10b981;
}

.status-badge.offline {
    background: transparent;
    color: #ef4444;
}

/* ===== DEVICES VIEW STYLES ===== */
.devices-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    padding: 1.25rem 1.5rem;
    background: #fff;
    border-radius: 0.5rem 0.5rem 0 0;
    border: 1px solid #e5e7eb;
    border-bottom: none;
}

.devices-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

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

.filter-buttons {
    display: flex;
    gap: 0;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    overflow: hidden;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-right: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.filter-btn:last-child {
    border-right: none;
}

.filter-btn:hover {
    background: #f8fafc;
    color: #3b82f6;
}

.filter-btn.active {
    background: #3b82f6;
    color: #fff;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-primary i {
    font-size: 0.75rem;
}

/* Devices Table Card - Connected to header */
#devices-view .table-card {
    border-radius: 0 0 0.5rem 0.5rem;
    border-top: 1px solid #f1f5f9;
    margin-top: 0;
}

/* Devices Table */
.devices-table {
    width: 100%;
    border-collapse: collapse;
}

.devices-table thead th {
    background: #fff;
    padding: 1rem 1.25rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #f1f5f9;
}

.devices-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.devices-table tbody tr:hover {
    background: #fafbfc;
}

.devices-table tbody tr:last-child {
    border-bottom: none;
}

.devices-table tbody td {
    padding: 1rem 1.25rem;
    font-size: 0.875rem;
    color: #475569;
    vertical-align: middle;
}

/* Device Cell with Icon Box */
.devices-table .device-cell {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.devices-table .device-cell .device-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 0.5rem;
    color: #64748b;
    font-size: 1.125rem;
    flex-shrink: 0;
}

.devices-table .device-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.devices-table .device-name {
    font-weight: 600;
    color: #1e293b;
    font-size: 0.875rem;
}

.devices-table .device-type {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Alert Count Badge */
.alert-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.5rem;
    background: #f59e0b;
    color: #fff;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.alert-count.zero {
    background: transparent;
    color: #94a3b8;
    font-weight: 400;
}

/* Actions Cell */
.actions-cell {
    display: flex;
    gap: 0.375rem;
    justify-content: flex-start;
}

.action-btn {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.action-btn:hover {
    background: #f1f5f9;
    color: #3b82f6;
}

.action-btn.location {
    color: #3b82f6;
}

.action-btn.location:hover {
    background: #eff6ff;
}

/* Loading, Error, Empty States */
.loading-row,
.error-row,
.empty-row {
    text-align: center;
    padding: 3rem 1rem !important;
    color: #64748b;
    font-size: 0.875rem;
}

.loading-row i,
.error-row i,
.empty-row i {
    margin-right: 0.5rem;
}

.error-row {
    color: #ef4444;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .device-status-card {
        flex-direction: column;
        gap: 20px;
    }
    
    .device-status-right {
        width: 100%;
    }
    
    .device-filter-buttons {
        width: 100%;
    }
    
    .device-filter-btn {
        flex: 1;
        min-width: auto;
    }
    
    .devices-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .devices-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .filter-buttons {
        flex: 1;
    }
    
    .filter-btn {
        flex: 1;
        text-align: center;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 70px;
    }
    
    .sidebar .nav-item span,
    .sidebar .user-details,
    .sidebar .logo-image {
        display: none;
    }
    
    .sidebar .nav-item {
        justify-content: center;
        padding: 12px;
    }
    
    .sidebar .user-avatar {
        margin: 0 auto;
    }
    
    .main-content {
        margin-left: 70px;
    }
    
    .content-wrapper {
        padding: var(--spacing-md);
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .top-bar {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .search-box input {
        width: 150px;
    }
}
/* ===== REAL-TIME STATUS UPDATE ANIMATION ===== */
.status-updated {
    animation: statusHighlight 2s ease-out;
}

@keyframes statusHighlight {
    0% {
        background-color: rgba(59, 130, 246, 0.2);
    }

    100% {
        background-color: transparent;
    }
}

/* Connection indicator (optional) */
.connection-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px;
}

    .connection-indicator.connected {
        background-color: #10b981;
    }

    .connection-indicator.reconnecting {
        background-color: #f59e0b;
        animation: pulse 1s infinite;
    }

    .connection-indicator.disconnected {
        background-color: #ef4444;
    }

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}
