/* Reset & Base Variables */
:root {
    --bg-dark: #000000;
    --bg-card: rgba(10, 10, 10, 0.8);
    --bg-card-hover: rgba(20, 20, 20, 0.9);
    --text-main: #ffffff;
    --text-muted: #cccccc;
    --primary: #0081cc;
    /* Corporate Blue */
    --primary-hover: #0066a3;
    --accent-blue: #007bff;
    --accent-orange: #d97706;
    --accent-purple: #8b5cf6;
    --accent-green: #10b981;
    --danger: #ef4444;
    --border: rgba(0, 129, 204, 0.3);
    /* Subtle Blue Border */
    --input-bg: #111111;
    --font-family: 'Garamond', 'Cormorant Garamond', serif;
    --font-heading: 'Garamond', 'Cormorant Garamond', serif;
    --transition: all 0.3s ease;
    --glow: 0 0 10px rgba(0, 129, 204, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background-color: #000000;
    color: #ffffff;
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    text-shadow: 0 0 3px rgba(0, 129, 204, 0.4);
    /* Lighter blue border around text */
}

/* Enforce white text color across all general text elements to prevent browser override */
h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
div,
li,
td,
th {
    color: inherit;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-dark);
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.7));
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    display: none;
    /* Hidden until logged in */
    flex-direction: column;
    padding: 2rem 1rem;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.sidebar.visible {
    display: flex;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2rem;
    padding: 0 1rem;
}

.logo img {
    max-width: 100%;
    height: auto;
    max-height: 100px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(0, 129, 204, 0.4));
}

.logo i {
    font-size: 1.75rem;
    background: linear-gradient(135deg, var(--primary), var(--accent-purple));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-links li {
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-weight: 500;
    transition: var(--transition);
}

.nav-links li:hover {
    background-color: var(--bg-card-hover);
    color: var(--text-main);
}

.nav-links li.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    border-left: 4px solid var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 3rem;
    display: none;
    /* Hidden until logged in */
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--bg-dark);
}

.main-content.visible {
    display: flex;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.top-header h1 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: #111;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.admin-only-badge {
    background: var(--accent-orange);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
}

.truck-id-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.admin-only {
    display: none;
}

.admin-only-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    transition: var(--transition);
}

.card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6), var(--glow);
}

.welcome-card {
    text-align: center;
    padding: 4rem 2rem;
    max-width: 800px;
    margin: 2rem auto;
}

.welcome-card i {
    font-size: 5rem;
    color: var(--primary);
    margin-bottom: 2rem;
    filter: drop-shadow(0 0 10px rgba(0, 129, 204, 0.4));
}

.welcome-card h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
    border-bottom: none;
}

.card h2 {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.card h2 i {
    color: var(--primary);
    font-size: 1.4rem;
}

/* Forms */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

input,
select {
    background-color: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.9rem 1.2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 162, 255, 0.4), inset 0 2px 4px rgba(0, 0, 0, 0.5);
    background-color: rgba(0, 0, 0, 0.8);
}

/* Checkbox Styles */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--input-bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.route-selection-group {
    margin-top: 1.5rem;
}

#desglose-estados-container {
    display: none;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.badge {
    padding: 6px 14px;
    border-radius: 6px;
    background: #1a1a1a;
    color: white;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
}

.badge i {
    color: var(--primary);
}

.calc-indicator strong {
    font-size: 1.25rem;
}

.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(197, 160, 89, 0.4), var(--glow);
}

.btn-primary:active,
.btn-secondary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
    color: var(--primary);
}

/* Reports Section */
.reports-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.summary-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.1;
    z-index: 0;
}

.summary-card.gradient-blue::before {
    background: linear-gradient(135deg, var(--primary), transparent);
}

.summary-card.gradient-purple::before {
    background: linear-gradient(135deg, var(--accent-purple), transparent);
}

.summary-icon {
    width: 60px;
    height: 60px;
    background: var(--bg-dark);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    position: relative;
    z-index: 1;
}

.summary-card.gradient-blue .summary-icon {
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.summary-card.gradient-purple .summary-icon {
    color: var(--accent-purple);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.summary-info {
    position: relative;
    z-index: 1;
}

.summary-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.summary-info p {
    font-size: 1.8rem;
    font-weight: 700;
}

/* Weekly List */
.weekly-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.weekly-list::-webkit-scrollbar {
    width: 6px;
}

.weekly-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 4px;
}

.weekly-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.week-item {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    transition: var(--transition);
}

.week-item:hover {
    border-color: var(--primary);
    transform: translateX(5px);
}

.week-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

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

.week-header .trip-count {
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.week-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-main);
}

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

.stat-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Mobile Adjustments */
@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .top-header {
        padding: 1rem;
    }

    .top-header h1 {
        font-size: 1.2rem;
    }

    .user-info span {
        display: none;
        /* Hide truck ID on small screens */
    }

    .user-info #active-driver-name {
        display: block;
    }

    .card {
        padding: 1.2rem;
    }

    .btn-primary {
        padding: 1.2rem;
        /* Larger touch area */
    }

    input,
    select {
        font-size: 16px !important;
        /* Prevents auto-zoom on iOS */
        padding: 12px;
    }
}

/* Print Styles (PDF Export) */
@media print {
    body {
        background-color: white;
        color: black;
    }

    .sidebar,
    .form-section,
    .btn-secondary,
    .top-header {
        display: none !important;
    }

    .main-content {
        padding: 0;
        overflow: visible;
    }

    .dashboard-grid {
        display: block;
    }

    .reports-section {
        width: 100%;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
        margin-bottom: 20px;
        background: white;
    }

    .text-muted {
        color: #555 !important;
    }

    .week-item {
        background: white;
        border: 1px solid #ccc;
    }

    * {
        color: black !important;
        background: transparent !important;
    }

    .summary-icon i,
    .week-header h4 {
        color: #333 !important;
    }
}

/* Audit Table & Administration Styles */
.audit-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.audit-table th,
.audit-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.audit-table th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
}

.audit-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    width: 100px;
    outline: none;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.audit-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.gradient-green {
    background: linear-gradient(135deg, #10b981 0%, #047857 100%);
}

.gradient-orange {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.admin-only-badge {
    background: var(--accent-orange);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 10px;
    vertical-align: middle;
    text-transform: uppercase;
    font-weight: bold;
}

@media (max-width: 768px) {
    .audit-table {
        font-size: 0.8rem;
    }

    .audit-input {
        width: 70px;
    }

    .audit-table th,
    .audit-table td {
        padding: 8px 4px;
    }
}

/* ==========================================
   LOGIN OVERLAY - Mobile First
   ========================================== */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #000000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 2rem));
    overflow-y: auto;
}

.login-overlay .login-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.login-overlay .login-logo img {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    border: 2px solid var(--border);
    object-fit: cover;
    box-shadow: 0 0 30px rgba(0, 129, 204, 0.3);
}

.login-overlay .login-logo p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.login-box {
    background: rgba(10, 10, 10, 0.9);
    backdrop-filter: blur(25px);
    border: 1px solid rgba(0, 129, 204, 0.25);
    border-radius: 20px;
    padding: 2rem 1.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 30px rgba(0, 129, 204, 0.08);
    width: 100%;
    max-width: 400px;
    animation: fadeInScale 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(15px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.login-box h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.3rem;
    background: linear-gradient(135deg, #ffffff 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box .form-group label {
    font-size: 0.85rem;
    font-weight: 500;
}

.login-box input,
.login-box select {
    width: 100%;
    font-size: 1rem;
}

/* ==========================================
   RESPONSIVE LAYOUT
   ========================================== */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar.visible {
        display: none;
        /* hidden on mobile by default, opened via toggle */
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        padding: 2rem;
    }

    .sidebar.visible.active {
        display: flex;
    }

    .main-content.visible {
        display: flex;
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 5rem));
        /* Extra padding so scrolling past nav bar works */
    }

    .top-header {
        margin-bottom: 1rem;
    }

    .top-header h1 {
        font-size: 1.3rem;
    }

    .user-info {
        gap: 0.5rem;
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        flex-wrap: wrap;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .card {
        padding: 1.2rem;
    }

    .welcome-card {
        padding: 2rem 1rem;
        margin: 0;
    }

    .welcome-card h2 {
        font-size: 1.8rem;
    }

    .btn-menu-toggle {
        display: flex !important;
    }

    .audit-table {
        font-size: 0.8rem;
    }

    .audit-input {
        width: 70px;
    }

    .audit-table th,
    .audit-table td {
        padding: 8px 4px;
    }
}

/* Enhancements */
.nav-links li.active {
    background: linear-gradient(90deg, rgba(0, 129, 204, 0.15) 0%, transparent 100%);
    color: var(--primary);
    border-left: 4px solid var(--primary);
    box-shadow: inset 4px 0 10px rgba(0, 129, 204, 0.1);
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #000;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 129, 204, 0.3);
    border-radius: 10px;
    border: 2px solid #000;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 129, 204, 0.5);
}

/* ==========================================
   PDF PREVIEW MODAL
   ========================================== */
.pdf-preview-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pdf-preview-backdrop.visible {
    display: flex;
}

.pdf-preview-container {
    width: 95%;
    max-width: 1200px;
    height: 90vh;
    background: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 129, 204, 0.3);
}

.pdf-preview-header {
    background: #0a0a0a;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.pdf-preview-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--primary);
}

.pdf-preview-body {
    flex: 1;
    background: #333;
    position: relative;
}

.pdf-preview-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.pdf-preview-footer {
    padding: 1rem 1.5rem;
    background: #0a0a0a;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
    .pdf-preview-container {
        height: 95vh;
        width: 100%;
    }
    
    .pdf-preview-header h3 {
        font-size: 1rem;
    }
}