:root {
    --bg-main: #0f172a; /* Slate 900 */
    --bg-panel: rgba(30, 41, 59, 0.7); /* Slate 800 with opacity */
    --bg-card: rgba(51, 65, 85, 0.8); /* Slate 700 with opacity */
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --accent: #3b82f6; /* Blue 500 */
    --accent-glow: rgba(59, 130, 246, 0.5);
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.2);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.2);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.2);
    
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.05);
    --table-header-bg: rgba(0, 0, 0, 0.2);
    --table-header-hover: rgba(255, 255, 255, 0.05);
    --table-header-hover-text: #fff;
    --badge-bg: rgba(0, 0, 0, 0.3);
}

:root.theme-light {
    --bg-main: #E2E8F0; /* Slightly darker slate for background to make white pop */
    --bg-panel: #ffffff; /* Solid white */
    --bg-card: #ffffff; /* Solid white */
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-border: 1px solid rgba(0, 0, 0, 0.15); /* Stronger border */
    --border-color: rgba(0, 0, 0, 0.15);
    --hover-bg: rgba(0, 0, 0, 0.05);
    --table-header-bg: rgba(0, 0, 0, 0.05);
    --table-header-hover: rgba(0, 0, 0, 0.1);
    --table-header-hover-text: var(--text-main);
    --badge-bg: rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100dvh;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.1), transparent 25%);
    background-attachment: fixed;
    overflow-x: hidden;
}

.dashboard-wrapper {
    flex: 1;
    min-height: 0;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.top-nav {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px 30px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.top-nav-first-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand > i.fa-shield-halved {
    font-size: 32px;
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.brand .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-card {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    min-width: 130px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
}

.stats-neutral {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.stats-in {
    background: var(--success-bg);
    border: 1px solid var(--success-bg);
}

.stats-out {
    background: var(--danger-bg);
    border: 1px solid var(--danger-bg);
}

.stat-icon {
    font-size: 24px;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--success);
    line-height: 1;
}

.clock {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    letter-spacing: 2px;
}

/* Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    flex: 1;
    min-height: 0;
}

.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.panel-header {
    padding: 20px 24px;
    border-bottom: var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pulse-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--success);
    background: var(--success-bg);
    padding: 4px 12px;
    border-radius: 20px;
}

.pulse-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.panel-content {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

/* Custodia Grid */
#custodia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    align-content: start;
}

#custodia-grid.is-table-view {
    display: block;
}

.car-card {
    background: var(--bg-card);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.car-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.car-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--card-status-color, var(--success));
    z-index: 2;
}

.car-card > * {
    position: relative;
    z-index: 1;
}

.car-card.has-photo-bg::after {
    content: '';
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    background-image: var(--bg-photo);
    background-size: cover;
    background-position: center;
    opacity: 0.25;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    filter: blur(4px);
}

:root.theme-light .car-card.has-photo-bg::after {
    opacity: 0.20; /* Keep it visible in light mode */
}

.car-card.has-photo-bg:hover::after {
    opacity: 0.40;
}

:root.theme-light .car-card.has-photo-bg:hover::after {
    opacity: 0.35;
}

.car-card-in {
    --card-status-color: var(--success);
}

.car-card-out {
    --card-status-color: var(--danger);
    opacity: 0.8;
}

.car-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.car-mat {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    background: var(--badge-bg);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.car-room {
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    background-color: var(--accent);
    padding: 4px 8px;
    border-radius: 4px;
}

.car-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.car-details span {
    font-size: 13px;
    color: var(--text-muted);
}

.car-details strong {
    color: var(--text-main);
    font-weight: 600;
}

.car-photo-btn {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

:root.theme-light .car-photo-btn {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.car-photo-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

:root.theme-light .car-photo-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Movimientos List */
.list-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.mov-item {
    background: var(--bg-card);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.mov-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.mov-in {
    background: var(--success-bg);
    color: var(--success);
}

.mov-out {
    background: var(--danger-bg);
    color: var(--danger);
}

.mov-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0; /* Important for flex child to truncate text */
}

.mov-title {
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mov-sub {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mov-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--badge-bg);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90vh;
}

.modal-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* =========================================================
   HEADER CONTROLS & TOGGLE
   ========================================================= */
.header-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.view-toggle-btn {
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 15px;
    min-width: 250px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.settings-dropdown h4 {
    margin: 0 0 15px 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.toggle-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
}

.toggle-switch-wrapper:last-child {
    margin-bottom: 0;
}

.toggle-switch-wrapper input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    position: relative;
    transition: background-color 0.3s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-switch-wrapper input[type="checkbox"]:checked + .toggle-slider {
    background-color: var(--accent);
}

.toggle-switch-wrapper input[type="checkbox"]:checked + .toggle-slider::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-main);
}

.view-toggle-btn:hover {
    background: var(--table-header-hover);
    color: var(--accent);
}

/* =========================================================
   TABLE VIEW (ADVANCED MODE)
   ========================================================= */
.data-table-container {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--table-header-bg);
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, color 0.2s;
}

.data-table th.sortable:hover {
    background-color: var(--table-header-hover);
    color: var(--table-header-hover-text);
}

.data-table tr:hover {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: var(--hover-bg);
}

.data-table td.highlight {
    font-weight: 700;
    color: var(--text-main);
}

.data-table .btn-foto-mini {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    font-weight: 600;
}

.data-table .btn-foto-mini:hover {
    background: var(--accent);
    color: white;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.status-in { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.status-out { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* =========================================================
   RESPONSIVE DESIGN (MOBILE)
   ========================================================= */
@media (max-width: 767px) {
    .dashboard-wrapper {
        padding: 12px;
        overflow-y: auto;
        display: block; /* Remove flex constraint to allow natural scrolling */
    }
    
    .top-nav {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
        margin-bottom: 20px;
    }

    .top-nav-first-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    .brand {
        display: flex;
        align-items: center;
        flex: 1 1 100%;
        min-width: 100%;
        margin-bottom: 4px;
    }
    
    .brand .subtitle {
        display: none;
    }
    
    .header-stats {
        flex: 1 1 auto;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 4px !important;
        overflow-x: auto;
    }

    .stats-card {
        flex: 1 1 auto;
        min-width: 0;
        padding: 6px 10px;
        justify-content: center;
        gap: 6px;
    }

    .brand h1 {
        font-size: 16px !important;
    }

    .stat-value {
        font-size: 18px !important;
    }

    .stat-icon {
        font-size: 18px !important;
    }

    .stat-label {
        font-size: 10px !important;
    }
    
    .header-controls {
        width: 100%;
        justify-content: flex-end;
        gap: 10px;
        flex-wrap: wrap;
    }

    .clock {
        font-size: 20px; /* Smaller clock on mobile to prevent overflow */
    }
    
    .dashboard-grid {
        display: flex;
        flex-direction: column;
        gap: 20px;
        overflow-y: visible; /* Prevent double scrollbar on the grid */
    }
    
    #custodia-grid {
        grid-template-columns: 1fr;
    }
    
    .panel {
        height: 550px; /* Fixed height to allow internal panel scrolling */
        min-height: 400px;
        flex: none; /* Prevent flex shrinking */
    }
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.loader {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.loader i {
    font-size: 24px;
    color: var(--accent);
}

.status-out {
    background-color: rgba(220, 38, 38, 0.15); /* Red 600 with opacity */
    color: #ef4444; /* Red 500 */
}

.status-cout {
    background-color: rgba(234, 179, 8, 0.15); /* Yellow 500 with opacity */
    color: #eab308; /* Yellow 500 */
}

.mov-out {
    background-color: rgba(220, 38, 38, 0.15);
    color: #ef4444;
}

.mov-cout {
    background-color: rgba(234, 179, 8, 0.15);
    color: #eab308;
}
