:root {
    /* Color Palette */
    --primary: #667eea;
    --primary-dark: #4c51bf;
    --secondary: #2d3748;
    --accent: #38b2ac;
    --bg: #f4f7f6;
    --card-bg: white;
    --text: #2d3748;
    --border: #e2e8f0;
    --online: #38a169;
    --offline: #a0aec0;
    --text-secondary: #718096;

    /* Spacing Scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --shadow-glass: 0 8px 32px rgba(0,0,0,0.1);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Responsive shell (see the RESPONSIVE SHELL section at the end).
       --chrome-h is a fallback: nav.js overwrites it with the measured
       navbar (+ status bar) height on every page. */
    --chrome-h: 100px;
    --tap-min: 44px;
}

body { margin: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: var(--bg); color: var(--text); transition: var(--transition-base); overflow: hidden; }

.dark-theme {
    --primary: #7f9cf5;
    --primary-dark: #5a67d8;
    --secondary: #171923;
    --accent: #4fd1c5;
    --bg: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text: #f1f5f9;
    --border: rgba(255,255,255,0.08);
    --text-secondary: #94a3b8;
}

/* Auth & Modals */
.auth-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 20000; display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--card-bg); padding: 2rem; border-radius: var(--radius-lg); width: 320px; box-shadow: var(--shadow-glass); border: 1px solid var(--border); }
.dark-theme .auth-card { background: rgba(30, 41, 59, 0.8); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.auth-card h2 { margin-top: 0; }
.auth-card input, .auth-card select, .auth-card textarea { width: 100%; margin-bottom: 1rem; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); box-sizing: border-box; }

/* Ensure select dropdowns work in dark mode */
select, input[type="color"] { 
    background: var(--bg); 
    color: var(--text); 
    border: 1px solid var(--border); 
}

/* Ensure all text inputs inherit theme colors */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"] {
    color: var(--text);
}

select option {
    background: var(--card-bg);
    color: var(--text);
}

textarea {
    font-family: inherit;
    resize: vertical;
}

.btn { padding: 8px 16px; border: none; border-radius: var(--radius-md); cursor: pointer; font-weight: bold; transition: var(--transition-fast); font-size: 0.9rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); filter: brightness(1.05); }
.btn-success { background: var(--online); color: white; }
.btn-danger { background: #e53e3e; color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); border-color: var(--primary); }
.btn:hover { filter: brightness(1.1); }

/* Navigation - Glassmorphism */
/* Reserve the navbar's height so the JS-injected nav (built on DOMContentLoaded
   from #navbar-root, see nav.js) doesn't cause a layout jump on first paint. */
#navbar-root {
    min-height: 60px;
}
.navbar {
    background: rgba(45, 55, 72, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    /* The navbar needs its own layer, not just a z-index on the panel inside
       it. backdrop-filter makes this element a stacking context, so a z-index
       on the hamburger panel is scoped to the navbar's own layer - and the
       navbar would otherwise paint in the z-index:auto layer, underneath
       Leaflet's map panes (200-1000, all in the root stacking context because
       #map is position:relative with z-index:auto). The open panel hangs over
       the map on the live-fleet page, so without this it is unclickable below
       the map's top edge. 1500 clears the panes and the 1400 drawer backdrop
       while staying under the modal layers (10000 / 20000). */
    position: relative;
    z-index: 1500;
}
.dark-theme .navbar {
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: bold; font-size: 1.2rem; }
.nav-links { display: flex; gap: 20px; }
.nav-item { cursor: pointer; opacity: 0.8; transition: var(--transition-fast); padding: 5px 10px; border-radius: var(--radius-md); }
.nav-item:hover, .nav-item.active { opacity: 1; background: rgba(255,255,255,0.1); }

.status-bar { background: var(--card-bg); padding: 0.4rem 1.5rem; display: flex; gap: 25px; font-size: 0.8rem; border-bottom: 1px solid var(--border); height: 40px; align-items: center; box-sizing: border-box; }
.dark-theme .status-bar { background: rgba(30, 41, 59, 0.5); }

/* Layout */
/* Height lives with the responsive shell at the end of this file, which sizes
   it from the measured --chrome-h. */
.main-container { display: flex; overflow: hidden; }
#map { flex: 1; margin: var(--space-4); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.sidebar {
    width: 350px;
    background: var(--card-bg);
    margin: var(--space-4) var(--space-4) var(--space-4) 0;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}
.dark-theme .sidebar {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Dashboard Components */
.fleet-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); margin-bottom: var(--space-5); }
.stat-card { background: var(--bg); padding: var(--space-3); border-radius: var(--radius-md); text-align: center; border: 1px solid var(--border); transition: transform var(--transition-fast), box-shadow var(--transition-fast); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-value { font-size: 1.3rem; font-weight: bold; color: var(--primary); }
.stat-label { font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; }

.asset-item { padding: 15px; border-bottom: 1px solid var(--border); cursor: pointer; transition: var(--transition-fast); display: flex; align-items: center; gap: 10px; }
.asset-item:hover { background: rgba(102, 126, 234, 0.04); }
.asset-item-main { flex: 1; }
.asset-history-btn { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 10px; cursor: pointer; font-size: 1rem; transition: var(--transition-fast); }
.asset-history-btn:hover { background: var(--primary); border-color: var(--primary); }
.asset-name { font-weight: bold; margin-bottom: 5px; }
.asset-details { font-size: 0.75rem; color: var(--text-secondary); line-height: 1.5; }
.mileage-tag { font-weight: bold; color: var(--primary); }

/* Admin View classes */
.admin-sidebar { width: 240px; background: rgba(45, 55, 72, 0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); color: white; display: flex; flex-direction: column; padding: 20px 0; border-right: 1px solid rgba(255,255,255,0.05); }
.dark-theme .admin-sidebar { background: rgba(15, 23, 42, 0.85); }
.admin-nav-item { padding: 12px 25px; cursor: pointer; transition: var(--transition-fast); border-left: 4px solid transparent; color: rgba(255,255,255,0.7); font-size: 0.9rem; }
.admin-nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.admin-nav-item.active { background: rgba(255,255,255,0.12); border-left-color: var(--primary); color: white; }
.admin-content { flex: 1; padding: 40px; overflow-y: auto; background: var(--bg); }

.data-table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.data-table th { text-align: left; padding: 15px; background: var(--bg); font-size: 0.85rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table td { padding: 15px; border-top: 1px solid var(--border); font-size: 0.9rem; }
.data-table tr:hover td { background: rgba(102, 126, 234, 0.04); }

.tag { padding: 3px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: bold; text-transform: uppercase; }
.tag-active { background: #c6f6d5; color: #2f855a; }
.tag-suspended { background: #fed7d7; color: #c53030; }

/* Map Pins */
.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -15px 0 0 -15px;
    border: 2px solid #fff;
    box-shadow: var(--shadow-sm);
}
.pin-online { background: var(--online); }
.pin-offline { background: var(--offline); }

/* Admin Panel specific styles */
.admin-panel { }
.admin-panel.active { display: block; }

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

.panel-header h2 { margin: 0; }

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.filter-select {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text);
}

.pagination-container {
    margin-top: 15px;
    text-align: center;
}

.pagination-info {
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* Modal specific */
.modal-wide { width: 450px; }
.modal-extra-wide { width: 550px; max-height: 90vh; overflow-y: auto; }

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.color-picker-group {
    display: flex;
    gap: 5px;
    align-items: center;
}

.color-picker-input {
    width: 50px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.color-hex-input {
    flex: 1;
    padding: 8px;
}

/* Profile card */
.profile-card {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    transition: box-shadow var(--transition-fast);
}
.profile-card:hover {
    box-shadow: var(--shadow-md);
}
.dark-theme .profile-card {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Profile grid layout for efficient screen utilization */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-6);
}

.profile-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
}

@media (max-width: 900px) {
    .profile-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Profile section styling */
.profile-section {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.profile-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.profile-section h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: var(--primary);
    font-weight: 600;
}

.profile-field {
    display: flex;
    margin-bottom: 8px;
    align-items: baseline;
}

.profile-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 140px;
    flex-shrink: 0;
}

.profile-value {
    color: var(--text);
}

.json-display {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text);
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.form-group {
    margin-bottom: 15px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
    font-family: inherit;
}

/* Nav link inherit */
.nav-link-inherit {
    color: inherit;
    text-decoration: none;
}

/* Button variants */
.btn-nav {
    padding: 4px 8px;
}

.btn-nav-theme {
    border-color: rgba(255,255,255,0.3);
    color: white;
}

.btn-nav-logout {
    background: rgba(255,255,255,0.2);
}

.btn-action-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
    margin-right: 5px;
}

.btn-delete {
    color: #EF4444;
    border-color: #EF4444;
}

.btn-action-manage {
    padding: 4px 8px;
    font-size: 0.7rem;
}

/* Table column widths */
.col-icon { width: 30px; }

/* Reports & Metrics */
.reports-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.dark-theme .metric-card {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.metric-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary);
}

.metric-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Chart containers */
.chart-container {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.dark-theme .chart-container {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.chart-title {
    margin: 0 0 15px 0;
    font-size: 1rem;
    font-weight: 600;
}

.chart-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.chart-item:last-child {
    border-bottom: none;
}

/* User management styles */
.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.user-badge-admin {
    background: #FED7E2;
    color: #97266D;
}

.user-badge-manager {
    background: #C6F6D5;
    color: #276749;
}

.user-badge-viewer {
    background: #E2E8F0;
    color: #4A5568;
}

/* Modal improvements */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

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

/* Status indicators */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot-active { background: #38a169; }
.status-dot-inactive { background: #a0aec0; }
.status-dot-suspended { background: #E53E3E; }

/* Button color variants */
.btn-purple {
    color: #805AD5;
    border-color: #805AD5;
}

.btn-purple:hover {
    background: #805AD5;
    color: white;
}

@media (max-width: 900px) {
    /* box-sizing: the sidebar's 20px padding and 1px border are inside the
       100% width, or the panel overhangs the viewport by 42px. */
    .sidebar { width: 100%; box-sizing: border-box; position: absolute; bottom: 0; height: 40%; z-index: 1000; margin: 0; border-radius: 20px 20px 0 0; }

    .reports-metrics {
        grid-template-columns: 1fr;
    }
    .navbar { padding: 0.6rem 1rem; }
    .nav-brand { font-size: 1rem; }
}

@media (max-width: 768px) {
    .main-container { flex-direction: column; }
    #map { margin: var(--space-2); border-radius: var(--radius-md); }
    .sidebar { margin: 0 var(--space-2) var(--space-2); border-radius: var(--radius-md); }
}

/* Map Layer Switcher Styles */
.layer-switcher {
    background: transparent !important;
    box-shadow: none !important;
}

.layer-switcher-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}
.dark-theme .layer-switcher-btn {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.layer-switcher-btn:hover {
    background: var(--bg);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.layer-switcher-btn.active {
    background: var(--primary);
    color: white;
}

.layer-switcher-menu {
    position: absolute;
    top: 50px;
    right: 0;
    min-width: 180px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
    padding: 8px 0;
    display: none;
    flex-direction: column;
    z-index: 1000;
    border: 1px solid var(--border);
}
.dark-theme .layer-switcher-menu {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.layer-switcher-menu.show {
    display: flex;
}

.layer-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--text);
    font-size: 0.9rem;
}

.layer-option:hover {
    background: var(--bg);
}

.layer-option.active {
    background: var(--primary);
    color: white;
}

.layer-option.active:hover {
    background: var(--primary);
    filter: brightness(1.1);
}

.layer-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.layer-name {
    white-space: nowrap;
}

/* Mobile responsiveness for layer switcher */
@media (max-width: 768px) {
    .layer-switcher-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .layer-switcher-menu {
        min-width: 160px;
        right: -10px;
    }
    
    .layer-option {
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

/* Dark theme adjustments for layer switcher */
.dark-theme .layer-switcher-btn {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid var(--border);
}

.dark-theme .layer-switcher-menu {
    background: rgba(30, 41, 59, 0.85);
    border-color: var(--border);
}

.dark-theme .layer-option:hover {
    background: rgba(255,255,255,0.05);
}

/* Leaflet control positioning adjustment */
.leaflet-top.leaflet-right {
    top: 10px !important;
    right: 10px !important;
}

/* Ensure layer switcher appears above other controls */
.layer-switcher {
    z-index: 1000;
}

/* ==================== ALERT STYLES ==================== */

/* Alert Badge */
.alert-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e53e3e;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* Alert Toast Notifications */
.alert-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 350px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
    border-left: 4px solid var(--primary);
    z-index: 10000;
    animation: slideIn 0.3s ease;
    overflow: hidden;
    border: 1px solid var(--border);
}
.dark-theme .alert-toast {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.alert-toast-info { border-left-color: #4299e1; }
.alert-toast-warning { border-left-color: #ed8936; }
.alert-toast-critical { border-left-color: #e53e3e; }

@keyframes slideIn {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.alert-toast-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
}

.alert-toast-icon {
    font-size: 1.2rem;
}

.alert-toast-title {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
}

.alert-toast-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

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

.alert-toast-body {
    padding: 12px 15px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.alert-toast-actions {
    display: flex;
    gap: 10px;
    padding: 0 15px 15px;
}

/* Alert List Container */
.alerts-list {
    width: 400px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    border: 1px solid var(--border);
}
.dark-theme .alerts-list,
.dark-theme .alerts-detail {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.alerts-detail {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border);
    overflow-y: auto;
}

.alerts-list {
    width: 400px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    border: 1px solid var(--border);
}

.alerts-detail {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border);
    overflow-y: auto;
}

/* Alert Filters */
.alert-filters {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.alert-filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.85rem;
}

/* Alert Items */
.alert-item {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.alert-item:hover {
    background: var(--bg);
}

.alert-item-selected {
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid var(--primary);
}

.alert-item-unread {
    background: rgba(102, 126, 234, 0.05);
}

.alert-item-unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
}

.alert-item-info { border-left: 3px solid #4299e1; }
.alert-item-warning { border-left: 3px solid #ed8936; }
.alert-item-critical { border-left: 3px solid #e53e3e; }

.alert-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.alert-item-icon {
    font-size: 1rem;
}

.alert-item-type {
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    flex: 1;
}

.alert-item-severity {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
}

.alert-severity-info { background: #bee3f8; color: #2b6cb0; }
.alert-severity-warning { background: #feebc8; color: #c05621; }
.alert-severity-critical { background: #fed7d7; color: #c53030; }

.alert-item-time {
    color: var(--text-secondary);
}

.alert-item-content {
    margin-bottom: 8px;
}

.alert-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.alert-item-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.alert-item-geofence {
    font-size: 0.8rem;
    color: var(--primary);
    margin-top: 4px;
}

.alert-item-location {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.alert-item-actions {
    display: flex;
    gap: 8px;
}

/* Alert Empty State */
.alerts-empty {
    text-align: center;
    padding: 60px 40px;
    color: var(--text-secondary);
}

.alerts-empty-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

/* Alert Detail View */
.alert-detail {
    max-width: 600px;
}

.alert-detail-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.alert-detail-icon {
    font-size: 2rem;
}

.alert-detail-title {
    flex: 1;
}

.alert-detail-title h3 {
    margin: 0 0 5px 0;
    font-size: 1.2rem;
}

.alert-detail-time {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.alert-detail-section {
    margin-bottom: 25px;
}

.alert-detail-section h4 {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.alert-detail-field {
    display: flex;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.alert-detail-label {
    min-width: 120px;
    color: var(--text-secondary);
}

.alert-detail-value {
    font-weight: 500;
}

.alert-detail-map {
    height: 250px;
    border-radius: var(--radius-lg);
    margin: 15px 0;
    border: 1px solid var(--border);
}

.alert-detail-actions {
    display: flex;
    gap: 10px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Alert Statistics */
.alert-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.alert-stat-card {
    background: var(--bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border);
}

.alert-stat-active {
    background: rgba(229, 62, 62, 0.1);
    border-color: #e53e3e;
}

.alert-stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

.alert-stat-active .alert-stat-value {
    color: #e53e3e;
}

.alert-stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

.alert-breakdown {
    background: var(--bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.alert-breakdown h4 {
    margin: 0 0 15px 0;
    font-size: 0.95rem;
}

.alert-breakdown-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.alert-breakdown-item:last-child {
    border-bottom: none;
}

.alert-breakdown-type {
    color: var(--text-secondary);
}

.alert-breakdown-count {
    font-weight: 600;
}

/* Alert Markers on Map */
.alert-marker-icon {
    position: relative;
}

.alert-marker-pin {
    width: 36px;
    height: 36px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    border: 2px solid white;
}

.alert-marker-symbol {
    transform: rotate(45deg);
    font-size: 1rem;
}

.alert-pulse-icon {
    position: relative;
}

.alert-pulse {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid;
    animation: pulse 2s infinite;
    opacity: 0.6;
}

@keyframes pulse {
    0% { transform: scale(0.5); opacity: 0.6; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Alert Popup */
.alert-popup {
    min-width: 200px;
}

.alert-popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: 600;
}

.alert-popup-icon {
    font-size: 1.2rem;
}

.alert-popup-body {
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.alert-popup-body p {
    margin: 4px 0;
}

.alert-popup-actions {
    display: flex;
    gap: 8px;
}

/* General Notifications */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: var(--radius-lg);
    color: white;
    font-weight: 500;
    z-index: 10000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification-success { background: #38a169; }
.notification-error { background: #e53e3e; }
.notification-info { background: #4299e1; }

/* Small button variant */
.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* ==================== UTILITY CLASSES ==================== */

/* Display utilities */
.d-none { display: none !important; }
.d-flex { display: flex !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-grid { display: grid !important; }
.d-contents { display: contents !important; }

/* Width utilities */
.w-100 { width: 100% !important; }
.w-50 { width: 50% !important; }
.w-auto { width: auto !important; }
.w-50px { width: 50px !important; }
.w-150px { width: 150px !important; }
.w-320px { width: 320px !important; }
.w-450px { width: 450px !important; }
.w-550px { width: 550px !important; }

/* Height utilities */
.h-100 { height: 100% !important; }
.h-auto { height: auto !important; }
.h-38px { height: 38px !important; }

/* Margin utilities */
.m-0 { margin: 0 !important; }
.m-5 { margin: 5px !important; }
.m-10 { margin: 10px !important; }
.m-15 { margin: 15px !important; }
.m-20 { margin: 20px !important; }
.m-30 { margin: 30px !important; }

.mt-5 { margin-top: 5px !important; }
.mt-10 { margin-top: 10px !important; }
.mt-15 { margin-top: 15px !important; }
.mt-20 { margin-top: 20px !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-5 { margin-bottom: 5px !important; }
.mb-8 { margin-bottom: 8px !important; }
.mb-10 { margin-bottom: 10px !important; }
.mb-15 { margin-bottom: 15px !important; }
.mb-20 { margin-bottom: 20px !important; }
.mb-25 { margin-bottom: 25px !important; }
.mb-30 { margin-bottom: 30px !important; }

.mr-5 { margin-right: 5px !important; }
.mr-8 { margin-right: 8px !important; }

.ml-auto { margin-left: auto !important; }
.mr-auto { margin-right: auto !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

/* Padding utilities */
.p-0 { padding: 0 !important; }
.p-4 { padding: 4px !important; }
.p-6 { padding: 6px !important; }
.p-8 { padding: 8px !important; }
.p-10 { padding: 10px !important; }
.p-12 { padding: 12px !important; }
.p-15 { padding: 15px !important; }
.p-20 { padding: 20px !important; }
.p-25 { padding: 25px !important; }
.p-40 { padding: 40px !important; }
.p-60 { padding: 60px !important; }

.px-8 { padding-left: 8px !important; padding-right: 8px !important; }
.px-10 { padding-left: 10px !important; padding-right: 10px !important; }
.px-15 { padding-left: 15px !important; padding-right: 15px !important; }
.px-25 { padding-left: 25px !important; padding-right: 25px !important; }
.px-40 { padding-left: 40px !important; padding-right: 40px !important; }

.py-8 { padding-top: 8px !important; padding-bottom: 8px !important; }
.py-10 { padding-top: 10px !important; padding-bottom: 10px !important; }
.py-12 { padding-top: 12px !important; padding-bottom: 12px !important; }
.py-15 { padding-top: 15px !important; padding-bottom: 15px !important; }
.py-20 { padding-top: 20px !important; padding-bottom: 20px !important; }

.pb-15 { padding-bottom: 15px !important; }
.pb-20 { padding-bottom: 20px !important; }
.pb-25 { padding-bottom: 25px !important; }

/* Flexbox utilities */
.flex-1 { flex: 1 !important; }
.flex-row { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }

.justify-start { justify-content: flex-start !important; }
.justify-end { justify-content: flex-end !important; }
.justify-center { justify-content: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-around { justify-content: space-around !important; }

.align-start { align-items: flex-start !important; }
.align-end { align-items: flex-end !important; }
.align-center { align-items: center !important; }
.align-baseline { align-items: baseline !important; }
.align-stretch { align-items: stretch !important; }

.gap-5 { gap: 5px !important; }
.gap-6 { gap: 6px !important; }
.gap-8 { gap: 8px !important; }
.gap-10 { gap: 10px !important; }
.gap-15 { gap: 15px !important; }
.gap-20 { gap: 20px !important; }
.gap-25 { gap: 25px !important; }

/* Grid utilities */
.grid-2 { grid-template-columns: repeat(2, 1fr) !important; }
.grid-3 { grid-template-columns: repeat(3, 1fr) !important; }
.grid-4 { grid-template-columns: repeat(4, 1fr) !important; }

/* Text utilities */
.text-center { text-align: center !important; }
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }

.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-success { color: var(--online) !important; }
.text-danger { color: #e53e3e !important; }
.text-white { color: white !important; }
.text-inherit { color: inherit !important; }

.text-bold { font-weight: bold !important; }
.text-semibold { font-weight: 600 !important; }
.text-500 { font-weight: 500 !important; }
.text-normal { font-weight: normal !important; }

.text-xs { font-size: 0.7rem !important; }
.text-sm { font-size: 0.75rem !important; }
.text-sm2 { font-size: 0.8rem !important; }
.text-sm3 { font-size: 0.85rem !important; }
.text-base { font-size: 0.9rem !important; }
.text-md { font-size: 0.95rem !important; }
.text-lg { font-size: 1rem !important; }
.text-xl { font-size: 1.1rem !important; }
.text-2xl { font-size: 1.2rem !important; }
.text-4xl { font-size: 2rem !important; }

.text-uppercase { text-transform: uppercase !important; }
.text-capitalize { text-transform: capitalize !important; }
.text-none { text-transform: none !important; }

.text-no-decoration { text-decoration: none !important; }

/* Line height utilities */
.leading-1 { line-height: 1 !important; }
.leading-1-5 { line-height: 1.5 !important; }

/* Background utilities */
.bg-card { background: var(--card-bg) !important; }
.bg-primary { background: var(--primary) !important; }
.bg-secondary { background: var(--bg) !important; }
.bg-transparent { background: transparent !important; }

/* Border utilities */
.border { border: 1px solid var(--border) !important; }
.border-none { border: none !important; }
.border-left-primary { border-left: 3px solid var(--primary) !important; }
.border-left-4-primary { border-left: 4px solid var(--primary) !important; }

.rounded { border-radius: 4px !important; }
.rounded-6 { border-radius: 6px !important; }
.rounded-8 { border-radius: 8px !important; }
.rounded-full { border-radius: 50% !important; }

/* Cursor utilities */
.cursor-pointer { cursor: pointer !important; }
.cursor-default { cursor: default !important; }

/* Overflow utilities */
.overflow-hidden { overflow: hidden !important; }
.overflow-auto { overflow: auto !important; }
.overflow-y-auto { overflow-y: auto !important; }
.overflow-x-auto { overflow-x: auto !important; }

/* Position utilities */
.relative { position: relative !important; }
.absolute { position: absolute !important; }
.fixed { position: fixed !important; }

/* Resize utilities */
.resize-vertical { resize: vertical !important; }

/* Min/Max utilities */
.min-w-180 { min-width: 180px !important; }
.min-w-200 { min-width: 200px !important; }
.max-w-600 { max-width: 600px !important; }
.max-h-90vh { max-height: 90vh !important; }

/* Box sizing */
.box-border { box-sizing: border-box !important; }

/* Z-index utilities */
.z-100 { z-index: 100 !important; }
.z-1000 { z-index: 1000 !important; }

/* ==================== COMMON COMPONENT PATTERNS ==================== */

/* Form input standard */
.form-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
}

.form-input-sm {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
}

.form-input-secondary {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary, var(--bg));
    color: var(--text);
    box-sizing: border-box;
}

.form-input-secondary-sm {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary, var(--bg));
    color: var(--text);
    box-sizing: border-box;
}

/* Form label standard */
.form-label-std {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* Section title standard */
.section-title {
    margin: 0 0 15px 0;
    color: var(--text-primary, var(--text));
}

/* Panel header standard */
.panel-header-std {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Empty state standard */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.empty-state-lg {
    text-align: center;
    padding: 60px 40px;
    color: var(--text-secondary);
}

/* Card container */
.card-container {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition-fast);
}
.card-container:hover {
    box-shadow: var(--shadow-md);
}
.dark-theme .card-container,
.dark-theme .card-container-lg,
.dark-theme .card-metric {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.card-container-lg {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.card-metric {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border);
}

/* Form grid layouts */
.form-grid-2-10 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-grid-2-15 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Selectable item */
.selectable-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.selectable-item-box {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.selectable-item-box-sm {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 6px 10px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

/* Button group */
.btn-group {
    display: flex;
    gap: 10px;
}

.btn-group-sm {
    display: flex;
    gap: 5px;
}

/* Section divider */
.section-divider {
    margin-bottom: 30px;
    padding-bottom: 25px;
    border-bottom: 1px solid var(--border);
}

.section-divider-sm {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

/* Help text */
.help-text {
    display: block;
    margin-top: 5px;
    color: var(--text-secondary);
}

/* Nav link */
.nav-link {
    color: inherit;
    text-decoration: none;
}

/* Color picker input */
.color-picker {
    width: 50px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Modal sizes */
.modal-width-450 {
    width: 450px;
}

.modal-width-550 {
    width: 550px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-width-750 {
    width: 750px;
}

@media (max-width: 800px) {
    .modal-width-750 {
        width: 100%;
        max-width: 750px;
    }
}

/* Form row */
.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Page subtitle */
.page-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Asset info row */
.asset-info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

/* List group */
.list-group-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
}

/* Toast slide out animation */
@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(400px); opacity: 0; }
}

.slide-out {
    animation: slideOut 0.3s ease forwards;
}

/* ==================== ALERT CONFIGURATION STYLES ==================== */

/* Alert Config Tab Buttons */
.alert-tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.alert-tab-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.alert-tab-btn.active {
    background: var(--primary);
    color: white;
}

/* Alert Config Tab Content */
.alert-config-tab {
    animation: fadeIn 0.3s ease;
}

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

/* Form Sections */
.form-section {
    margin-bottom: 25px;
}

.form-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text);
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

/* Toggle Switch */
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: relative;
    cursor: pointer;
    display: inline-block;
}

/* Alert Rule Cards */
.alert-rule-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: box-shadow var(--transition-fast);
}
.dark-theme .alert-rule-card,
.dark-theme .alert-category-card,
.dark-theme .alert-type-item {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.alert-rule-card:hover {
    box-shadow: var(--shadow-md);
}

.alert-rule-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.alert-rule-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
}

.alert-rule-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Alert Category Cards */
.alert-category-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.alert-category-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.alert-category-icon {
    font-size: 2rem;
    margin-bottom: 12px;
}

.alert-category-color {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    display: inline-block;
}

/* Alert Types Grid */
.alert-type-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 15px;
    text-align: center;
    transition: all var(--transition-fast);
}

.alert-type-item:hover {
    border-color: var(--primary);
    background: var(--card-bg);
}

.alert-type-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.alert-type-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.alert-type-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Severity Tags */
.tag-severity-info {
    background: #DBEAFE;
    color: #1E40AF;
    border: 1px solid #3B82F6;
}

.tag-severity-warning {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #F59E0B;
}

.tag-severity-critical {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #EF4444;
}

/* Status Toggle in Tables */
.table-status-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.table-status-toggle input {
    display: none;
}

.table-status-toggle .toggle-slider {
    width: 40px;
    height: 20px;
    background: var(--offline);
    border-radius: 10px;
    position: relative;
    transition: background 0.3s ease;
}

.table-status-toggle .toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.table-status-toggle input:checked + .toggle-slider {
    background: var(--online);
}

.table-status-toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

/* Dark Theme Adjustments for Alert Config */
.dark-theme .alert-rule-card,
.dark-theme .alert-category-card,
.dark-theme .alert-type-item {
    background: rgba(30, 41, 59, 0.5);
}

.dark-theme .tag-severity-info {
    background: rgba(59, 130, 246, 0.2);
    color: #93C5FD;
    border-color: #3B82F6;
}

.dark-theme .tag-severity-warning {
    background: rgba(245, 158, 11, 0.2);
    color: #FCD34D;
    border-color: #F59E0B;
}

.dark-theme .tag-severity-critical {
    background: rgba(239, 68, 68, 0.2);
    color: #FCA5A5;
    border-color: #EF4444;
}

/* Additional utility classes for refactoring */

/* Margin utilities (additional) */
.mx-2 { margin-left: 2px !important; margin-right: 2px !important; }
.mt-30 { margin-top: 30px !important; }

/* Padding utilities (additional) */
.px-12 { padding-left: 12px !important; padding-right: 12px !important; }
.px-16 { padding-left: 16px !important; padding-right: 16px !important; }
.py-4 { padding-top: 4px !important; padding-bottom: 4px !important; }

/* Flex wrap */
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }

/* Grid column span */
.col-span-full { grid-column: 1 / -1 !important; }

/* Text color utilities */
.text-purple { color: #805AD5 !important; }
.text-danger { color: #E53E3E !important; }
.text-warning { color: #D69E2E !important; }
.text-nowrap { white-space: nowrap !important; }

/* Margin auto */
.mr-auto { margin-right: auto !important; }

/* Overflow utilities */
.overflow-auto { overflow: auto !important; }

/* Status dots */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot-lg {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

/* Panel header small variant */
.panel-header-sm {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

/* Form label with weight */
.form-label-weight {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    font-weight: 600;
}

/* Border top */
.border-top { border-top: 1px solid var(--border) !important; }
.pt-10 { padding-top: 10px !important; }

/* Modal with larger width */
.modal-width-lg {
    width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

/* Modal extra large */
.modal-width-xl {
    width: 900px;
    max-height: 95vh;
    overflow-y: auto;
}

/* Modal with no padding */
.modal-no-padding {
    padding: 0 !important;
}

/* Form panel (for geofence modal) */
.form-panel {
    width: 350px;
    padding: 20px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

/* Map container */
.map-container {
    flex: 1;
    position: relative;
}

/* Map overlay info box */
.map-info-box {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--card-bg);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Modal header with border */
.modal-header-border {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Card with background */
.card-bg {
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    position: relative;
}

.card-bg-sm {
    padding: 15px;
    background: var(--bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

/* Info section */
.info-section {
    margin-top: 30px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

/* Code/monospace input */
.input-code {
    font-family: monospace;
    font-size: 0.85rem;
}

/* Text area inherit font */
.textarea-inherit {
    font-family: inherit;
}

/* Title with primary color */
.title-primary {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--primary);
}

/* Icon large */
.icon-lg {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

/* Top right actions */
.top-right-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
}

/* Alert category icon */
.alert-cat-icon {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
}

/* Toggle slider position */
.toggle-slider-pos {
    position: absolute;
    top: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: var(--transition-base);
}

/* Error message */
.error-message {
    color: red;
    font-size: 0.8rem;
    margin-top: 1rem;
}

/* Alert position */
.alert-badge-pos {
    position: absolute;
    top: -5px;
    right: -5px;
}

/* Progress bar */
.progress-bar {
    height: 8px;
    border-radius: var(--radius-sm);
    background: var(--bg);
}

.progress-bar-fill {
    height: 100%;
    border-radius: var(--radius-sm);
}

/* Width utilities for dynamic content */
.w-20px { width: 20px !important; }
.h-20px { height: 20px !important; }

/* =====================================================
   Historical Playback Panel (Issue #207)
   ===================================================== */

.history-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-glass);
    transform: translateY(100%);
    transition: transform var(--transition-base);
    z-index: 1000;
    padding: 15px 20px;
}
.dark-theme .history-panel {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.history-panel.open {
    transform: translateY(0);
}

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

.history-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--primary);
}

.history-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 5px;
    line-height: 1;
}

.history-close-btn:hover {
    color: var(--text);
}

.history-asset-info {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.history-date-range {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

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

.date-input-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.date-input-group input {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
}

.history-timeline-container {
    margin-bottom: 15px;
}

.history-timeline-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 0.85rem;
}

#historyCurrentTime {
    font-weight: 600;
    color: var(--primary);
}

#historyProgress {
    color: var(--text-secondary);
}

.history-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}

.history-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.history-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-sm);
}

.history-timeline-range {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.history-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.history-ctrl-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.history-ctrl-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.history-play-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.history-play-btn:hover {
    background: var(--primary-dark, #2563eb);
}

.history-speed-control {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 10px;
}

.history-speed-control label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-speed-control select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
}

.history-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.history-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.history-stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.history-actions {
    display: flex;
    gap: 10px;
}

/* History markers on map */
.history-marker-icon {
    background: transparent;
}

.history-marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    color: white;
    box-shadow: var(--shadow-md);
}

.history-marker-start {
    background: #22c55e;
}

.history-marker-end {
    background: #ef4444;
}

.history-marker-playback {
    width: 32px;
    height: 32px;
    background: var(--primary);
    font-size: 0.9rem;
    animation: pulse-marker 1.5s infinite;
}

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

/* Responsive adjustments for history panel */
@media (max-width: 768px) {
    .history-panel {
        padding: 10px 15px;
    }

    .history-date-range {
        flex-direction: column;
        align-items: stretch;
    }

    .date-input-group input {
        width: 100%;
    }

    .history-stats {
        justify-content: space-between;
    }

    .history-controls {
        justify-content: center;
    }
}

/* ==================== RESPONSIVE SHELL ==================== */
/*
 * Breakpoints used across this stylesheet (#201):
 *
 *   <= 768px   phone + small tablet portrait. The app chrome collapses: the
 *              navbar links move into a hamburger panel and the MSP/admin
 *              sidebar becomes an off-canvas drawer.
 *   <= 900px   the live-fleet map/sidebar split stacks (pre-existing).
 *   > 768px    unchanged desktop layout.
 *
 * The chrome height (navbar + optional status bar) is measured at runtime by
 * nav.js and published as --chrome-h, because it is not a constant: only the
 * live-fleet page carries a .status-bar, and that bar wraps to a second row on
 * a phone. Layout below uses that variable instead of the old hardcoded
 * calc(100vh - 100px), which reserved a phantom 40px status bar on every MSP
 * page.
 *
 * --chrome-h and --tap-min are declared with the other tokens at the top.
 *
 * dvh, not vh: the shell is a fixed-viewport app (body has overflow:hidden),
 * so the document never scrolls and a mobile browser's toolbars never retract.
 * 100vh is the *large* viewport - toolbars retracted - so sizing to it puts the
 * bottom of the shell permanently below the fold with no way to scroll to it.
 * 100dvh tracks the toolbars. The vh line stays as the fallback for browsers
 * without dvh (pre-iOS 15.4, pre-Chrome 108).
 */
.main-container {
    height: calc(100vh - var(--chrome-h));
    height: calc(100dvh - var(--chrome-h));
}

/* nav.js wraps the link group and the theme/logout actions in .nav-collapse so
   they can be dropped into a panel together on small screens. On desktop the
   wrapper must not create a box, or the navbar's space-between would bunch the
   links up against the actions - display:contents keeps the old three-child
   layout (brand | links | actions) exactly as it was. */
.nav-collapse { display: contents; }

/* --- Hamburger + drawer controls: desktop hides them entirely --- */
.nav-toggle,
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: var(--tap-min);
    height: var(--tap-min);
    flex: 0 0 auto;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md);
    color: inherit;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.nav-toggle:hover,
.sidebar-toggle:hover { background: rgba(255, 255, 255, 0.12); }

.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1400;
}
.drawer-backdrop.show { display: block; }

@media (max-width: 768px) {
    /* --- Navbar: brand + two icon buttons on one 60px row --- */
    .navbar {
        padding: 0.5rem 0.75rem;
        gap: var(--space-2);
        position: relative;
    }
    .nav-brand {
        font-size: 0.95rem;
        gap: 6px;
        min-width: 0;
        flex: 1 1 auto;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .nav-toggle,
    .sidebar-toggle { display: flex; }

    /* Everything that used to sit inline in the navbar drops into a panel
       below it. .nav-collapse is created by nav.js and wraps both the link
       group and the theme/logout actions. */
    .nav-collapse {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: var(--space-2);
        padding: var(--space-3);
        /* Opaque, unlike the navbar's glass: this panel sits directly over page
           copy, and any translucency leaves the text underneath legible
           through the menu. */
        background: #2d3748;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: var(--shadow-lg);
        /* Above the drawer backdrop within the navbar's own layer; the navbar
           is what lifts the pair above the page (see the base .navbar rule). */
        z-index: 1500;
        max-height: calc(100vh - var(--chrome-h));
        max-height: calc(100dvh - var(--chrome-h));
        overflow-y: auto;
    }
    .dark-theme .nav-collapse { background: #0f172a; }
    .nav-collapse.open { display: flex; }

    .nav-collapse .nav-links {
        flex-direction: column;
        gap: var(--space-1);
        width: 100%;
    }
    .nav-collapse .nav-item {
        display: flex;
        align-items: center;
        min-height: var(--tap-min);
        padding: var(--space-2) var(--space-3);
        opacity: 1;
    }
    .nav-collapse .nav-link {
        display: block;
        width: 100%;
        color: inherit;
        text-decoration: none;
    }
    /* The action row keeps theme + logout side by side, each half-width. */
    .nav-collapse .nav-actions {
        display: flex;
        gap: var(--space-2);
        width: 100%;
        padding-top: var(--space-2);
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }
    .nav-collapse .nav-actions .btn { flex: 1 1 0; }

    /* --- MSP/admin sidebar: off-canvas drawer --- */
    .admin-sidebar {
        position: fixed;
        top: var(--chrome-h);
        bottom: 0;
        left: 0;
        width: min(280px, 82vw);
        transform: translateX(-100%);
        /* visibility, not just transform: a translated-away drawer is still in
           the tab order and the accessibility tree, so keyboard and screen
           reader users would walk an off-screen menu. Transitioning it keeps
           the slide-out animation - visibility flips at the end of the close. */
        visibility: hidden;
        transition: transform var(--transition-base), visibility var(--transition-base);
        z-index: 1450;
        overflow-y: auto;
        border-right: 1px solid rgba(255, 255, 255, 0.08);
    }
    .admin-sidebar.open {
        transform: translateX(0);
        visibility: visible;
    }
    .admin-content { padding: var(--space-4); }

    /* --- Status bar (live-fleet page) ---
       Four items at a 25px gap do not fit a phone, so the bar wraps instead of
       overflowing. It can therefore be taller than its desktop 40px, which is
       safe because nav.js measures the chrome rather than assuming it. */
    .status-bar {
        height: auto;
        min-height: 40px;
        flex-wrap: wrap;
        gap: var(--space-1) var(--space-4);
        padding: var(--space-2) var(--space-3);
    }
    .status-bar .ml-auto { margin-left: 0 !important; }
    /* The alerts item is a tap target, not just a readout. */
    .status-bar [onclick] {
        display: flex;
        align-items: center;
        min-height: var(--tap-min);
        padding: 0 var(--space-2);
    }

    /* --- Touch targets (44px minimum, per #201) --- */
    .btn,
    button,
    .admin-nav-item,
    .nav-item {
        min-height: var(--tap-min);
    }
    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    /* Leaflet's own controls ship at 30px on touch. The .leaflet-touch prefix
       is needed to outrank Leaflet's own rule. The attribution links are text
       credits rather than controls and are deliberately left alone. */
    .leaflet-touch .leaflet-bar a,
    .leaflet-bar a {
        width: var(--tap-min);
        height: var(--tap-min);
        line-height: var(--tap-min);
    }
    .layer-switcher-btn,
    .asset-history-btn,
    .history-close-btn,
    .history-ctrl-btn {
        min-width: var(--tap-min);
        width: var(--tap-min);
        height: var(--tap-min);
    }

    /* The fleet sidebar is absolutely positioned and full-width here, so it is
       inset rather than margined - a left margin on a width:100% box pushes
       its right edge off screen. */
    .sidebar {
        left: var(--space-2);
        right: var(--space-2);
        bottom: var(--space-2);
        width: auto;
        margin: 0;
    }
    .admin-nav-item {
        display: flex;
        align-items: center;
    }
    /* 16px is the threshold below which iOS Safari zooms the page on focus.
       !important is needed to outweigh this stylesheet's own font utilities -
       .text-xs and .text-sm3 are themselves !important and land on the two
       selects in the live-fleet sidebar, the controls a fleet user touches
       most. A bare type selector loses to any class. */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
    input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
    select,
    textarea {
        min-height: var(--tap-min);
    }
}
