:root {
    --primary-bg: rgba(255, 255, 255, 0.94);
    --border-color: #e5e7eb;
    --text-main: #1f2937;
    --text-muted: #4b5563;
    --raptor-green-bright: #10b981;
    --raptor-green-dark: #059669;
    
    /* Enhanced Raptor Card Color States */
    --state-healthy: #10b981;
    --state-resting: #6b7280;
    --state-critical: #ef4444;
    --card-divider: #f3f4f6;
}

body { 
    margin: 0; padding: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    background: #111827;
}

#map { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 100%; height: 100%; z-index: 1; }

.dashboard-container {
    position: absolute;
    top: 15px; left: 15px; bottom: 15px;
    z-index: 10;
    display: flex;
    pointer-events: none;
}
.dashboard-container > * { pointer-events: auto; }

/* Unified Master Menu Container */
.nav-menu {
    height: 100%;
    background: linear-gradient(to right, rgba(5, 74, 181, 0.6) 75px, rgba(47, 80, 133, 0.6) 75px);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-right: none;
    border-radius: 24px 0 0 24px;
    box-shadow: -10px 10px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #ffffff;
    width: 260px;
    padding-top: 20px;
    box-sizing: border-box;
    z-index: 11;
}

.nav-menu.collapsed { 
	width: 75px; 
  	/*border-radius: 24px;*/ 
    /*border-right: 1px solid rgba(255, 255, 255, 0.15);*/ 
}

/* Branding Header Component */
.nav-brand-area {
    height: 50px;
    display: flex;
    align-items: center;
    position: relative;
    margin-bottom: 25px;
    width: 100%;
}

.brand-toggle-icon {
    width: 75px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.brand-toggle-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }

.brand-text-label {
    padding-left: 15px;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    transition: opacity 0.2s ease;
    opacity: 1;
    
    /* Added to align the logo inline with text gracefully */
    display: flex;
    align-items: center;
}

/* New surgical rule for the asset graphic */
.brand-logo {
    height: 1em; /* Explicitly matches the parent font-size (18px) */
    width: auto;
    margin-right: 1px; /* Clean breathing room between asset and text */
    display: inline-block;
    flex-shrink: 0;
}

.nav-menu.collapsed .brand-text-label { opacity: 0; pointer-events: none; }

/* Unified List Layout */
.menu-items-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.menu-row {
    height: 54px;
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
    color: #ffffff;
    text-decoration: none;
    width: 100%;
}

/* Centered Dock Icon */
.row-icon-pane {
    width: 75px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 10;
    transition: color 0.2s ease;
}
.row-icon-pane svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }

/* Trailing Text Labels */
.row-label-pane {
    padding-left: 15px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 10;
    transition: color 0.2s ease, opacity 0.2s ease;
    opacity: 1;
}

/* Centered Dock Icon */
.row-icon-pane {
    width: 75px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 10;
    transition: color 0.2s ease;
}
.row-icon-pane svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }

/* SURGICAL FIX: Size the new image-based navigation assets perfectly on desktop */
.row-icon-pane img.row-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    flex-shrink: 0;
}

.nav-menu.collapsed .row-label-pane { opacity: 0; pointer-events: none; }

.menu-row.active { color:#3e50b5; }
.menu-row.active .row-label-pane { font-weight: 600; }

/* Active Carved Out White Pill Layer */
.menu-row::before {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 15px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 27px 0 0 27px;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.menu-row.active::before { opacity: 1; }

/* Clean Inverted Radius Corner Masks on Right Side Edge */
.inverted-corner {
    position: absolute;
    right: 0;
    width: 27px;
    height: 27px;
    background: transparent;
    display: none;
    z-index: 6;
    pointer-events: none;
}
.menu-row.active .inverted-corner { display: block; }

.corner-top {
    top: -27px;
    box-shadow: 15px 0px 0 0 rgba(255, 255, 255, 0.7);
    border-radius: 0 0 15px 0;
}
.corner-bottom {
    bottom: -27px;
    box-shadow: 15px 0px 0 0 rgba(255, 255, 255, 0.7);
    border-radius: 0 15px 0 0;
}

/* Live Map Telemetry Sidebar Panel */
.sidebar-telemetry {
    width: 340px;
    background: rgba(211, 222, 247, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 24px 24px 0;
    box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    transform: translateX(0);
    opacity: 1;
    z-index: 10;
    margin-left: -1px;
}

.sidebar-telemetry.hidden {
    width: 0px !important;
    overflow: hidden;
    transform: translateX(-340px);
    opacity: 0;
    pointer-events: none;
}

.panel-header { padding: 5px 24px; border-bottom: 1px solid var(--border-color); }
.panel-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.device-list { flex-grow: 1; overflow-y: auto; padding: 12px; }

/* Enhanced Device Card Framework */
.device-card {
    padding: 14px; border-radius: 14px; border: 1px solid #e5e7eb;
    background: rgba(255, 255, 255, 0.85); margin-bottom: 10px;
    cursor: pointer; transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.device-card:hover { background: #ffffff; border-color: #9ca3af; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }

.device-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.identity-block { display: flex; flex-direction: column; }
.device-name { font-weight: 700; font-size: 14px; color: var(--text-main); letter-spacing: 0.3px; }

.device-driver {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.status-block { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.status-badge { font-size: 10px; padding: 2px 6px; border-radius: 20px; font-weight: 700; text-transform: uppercase; }
.data-age { font-size: 10px; color: var(--text-muted); font-weight: 500; }

.card-divider { border: 0; border-top: 1px solid var(--card-divider); margin: 10px 0; }

/* Dual Column Layout */
.card-body-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-column { display: flex; flex-direction: column; gap: 6px; }

.telemetry-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-main); }
.telemetry-row strong { color: var(--text-muted); font-weight: 500; }

/* Card Typography SVG Layout Settings */
.telemetry-row .row-icon,
.device-driver .row-icon,
.sim-tag .row-icon {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
    flex-shrink: 0;
}

/* 3-Column Always-On Activity Bar Grid Styling */
.activity-bar-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 6px; 
    margin-bottom: 10px; 
}
.alert-badge { 
    font-size: 9px; 
    font-weight: 700; 
    padding: 4px 2px; 
    border-radius: 6px; 
    text-align: center;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #f3f4f6; color: #374151; }

/* Status Colors */
.text-healthy { color: var(--state-healthy) !important; font-weight: 700; }
.text-resting { color: var(--state-resting) !important; font-weight: 600; }
.text-critical { color: var(--state-critical) !important; font-weight: 700; }

/* Subtle Cost Footer */
.card-footer { display: flex; justify-content: flex-end; margin-top: 8px; font-size: 10px; }
.sim-tag { display: flex; align-items: center; background: #f3f4f6; padding: 2px 6px; border-radius: 4px; color: var(--text-muted); font-weight: 500; border: 1px solid #e5e7eb; }
.sim-tag.critical { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; font-weight: 700; }

/* Map Canvas Markers */
.tracker-marker { 
    width: 22px; 
    height: 22px; 
    border: 2px solid #ffffff; 
    border-radius: 50%; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.4); 
    cursor: pointer; 
    transition: background-color 0.2s ease;
}

/* Style Controls Layout */
/* Style Controls Layout - Styled to match native MapLibre controls */
/* New Standalone Layer Icon Button - Formatted to blend with MapLibre Native UI */
.maplibre-style-btn {
    position: absolute;
    top: 100px; /* Sits perfectly right between the navigation controls and the panel */
    right: 10px;
    z-index: 10;
    width: 29px;
    height: 29px;
    background-color: #ffffff;
    border: 0;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    color: #333333;
    transition: background-color 0.1s;
}

.maplibre-style-btn:hover {
    background-color: #f4f4f4;
}

/* Style Controls Layout - Shifted down slightly to accommodate the button */
.layer-control {
    position: absolute;
    top: 100px; /* Bumped down slightly to maintain a consistent grid spacing */
    right: 42px;
    z-index: 10;
    background: #ffffff;
    padding: 12px;
    border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    font-size: 12px;
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.layer-control strong {
    color: #333333;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.layer-control label {
    display: inline-block;
    margin-top: 6px;
    cursor: pointer;
    user-select: none;
}

/* Generic visibility utility class for absolute elements */
.layer-control.hidden {
    display: none !important;
}

/* Remote Configuration Styles */
.config-field-label {
    display: block; 
    font-size: 11px; 
    font-weight: 600; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    color: var(--text-muted); 
    margin-bottom: 6px;
}

.config-preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.btn-preset {
    padding: 8px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: var(--text-main);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
}

.btn-preset:hover {
    background: #ffffff;
    border-color: var(--raptor-green-dark);
    color: var(--raptor-green-dark);
}

#config-log-terminal {
    flex-grow: 1;
    background: #111827;
    border-radius: 8px;
    padding: 10px;
    font-family: monospace;
    font-size: 11px;
    color: #f3f4f6;
    overflow-y: auto;
    max-height: 220px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.terminal-row {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

.disabled-opacity {
    opacity: 0.4;
}

/* ==========================================================================
   SURGICAL OVERRIDE: Horizontal Bottom Tray for Vehicle History
   ========================================================================== */

/* 1. Recalculate panel footprint to fit across remaining bottom width */
#historical-panel:not(.hidden) {
    position: fixed !important;
    top: auto !important;
    bottom: 15px !important; /* Matches dashboard-container bottom spacing */
    left: 276px !important;  /* Clears side-nav (75px) + telemetry-panel (200px) + spacing */
    right: 15px !important; /* Keeps right margin even */
    width: auto !important;
    /*height: 140px !important; /* Tailored shelf height */
    z-index: 10 !important;
    display: flex !important;
    flex-direction: column !important;
    background: rgba(211, 222, 247, 0.6) !important; /* Matches your theme palette style */
    backdrop-filter: blur(5px) !important;
    -webkit-backdrop-filter: blur(5px) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 0 16px 16px 0 !important;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25) !important;
    padding: 10px 20px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* 2. Re-arrange internal header content to stay neat on the left side */
#historical-panel .panel-header {
    /*margin-bottom: 5px !important;*/
    padding-bottom: 5px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}
#historical-panel .panel-header h2 {
    font-size: 14px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center;
    gap: 15px;
}
#historical-panel .panel-header h2 span {
    margin-top: 0 !important;
}

/* 3. Force form child containers to layout horizontally instead of stacking */
#historical-panel form#historical-filter-form {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-end !important;
    gap: 15px !important;
    width: 100% !important;
}

/* 4. Flatten spacing parameters around individual form items */
#historical-filter-form > div {
    margin-bottom: 0 !important; 
    flex: 1 !important; /* Distribute column boxes evenly */
    min-width: 140px !important;
}

/* 5. Clean layout flow alignment for the main execution buttons */
#historical-filter-form button[type="submit"] {
    height: 34px !important; /* Keeps button proportional with inputs */
    margin-bottom: 0 !important;
    white-space: nowrap !important;
}

/* Handle dynamic adjustment if your vertical nav menu collapses */
.nav-menu.collapsed ~ #historical-panel:not(.hidden) {
    left: 90px !important; /* Snaps left edge smoothly to meet minimized layout width */
}

@media (max-width: 768px) {
    .dashboard-container { flex-direction: column; top: auto; left: 0; right: 0; bottom: 0; width: 100%; }
    .nav-menu { width: 100% !important; height: 60px; flex-direction: row; margin-right: 0; border-radius: 0; background: var(--raptor-green-bright); padding-top: 0; border: none; }
    .nav-brand-area { display: none !important; }
    .menu-items-group { flex-direction: row; justify-content: space-around; height: 100%; }
    .menu-row { width: auto; height: 100%; flex: 1; /* Distributes menu items evenly across the width */ }
    .row-icon-pane { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
    
    /* SURGICAL ADDITION: Constrain the img assets inside the row icon panes on mobile */
    .row-icon-pane img.row-icon {
        width: 22px !important;
        height: 22px !important;
        object-fit: contain;
    }
    
    .row-label-pane, .menu-row::before, .inverted-corner { display: none !important; }
    .sidebar-telemetry { width: 100%; height: 38vh; border-radius: 24px 24px 0 0; border-left: 1px solid var(--border-color); margin-left: 0; }
    .sidebar-telemetry.hidden { transform: translateY(100%); }
    .maplibre-style-btn { top: auto; top: 110px; right: 10px; }
    .layer-control { top: auto; top: 100px; right: 42px; }
}