/* --- Global Variables & Base Styles --- */
:root {
    --primary-color: #005A9C;
    --accent-color: #D9232D;
    --success-color: #28a745;
    --text-color: #333;
    --text-light: #6c757d;
    --bg-color: #f8f9fa;
    --card-bg-color: #ffffff;
    --border-radius: 8px;
    --box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    --border-color: #e9ecef; /* Added for consistency */
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    animation: fadeInAnimation ease 0.5s;
    animation-iteration-count: 1;
    animation-fill-mode: forwards;
}

@keyframes fadeInAnimation { 
    0% { opacity: 0; } 
    100% { opacity: 1; } 
}

/* --- Welcome Page (index.html) Specific Styles --- */
.split-screen-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}
.left-pane, .right-pane {
    width: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    box-sizing: border-box;
}

/* --- Image Carousel Styles --- */
.left-pane {
    position: relative;
    overflow: hidden;
    color: white;
    flex-direction: column;
    text-align: center;
    z-index: 1;
}
.carousel-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    z-index: 2;
}
.carousel-slide.active {
    opacity: 1;
}
.carousel-slide::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(rgba(0, 90, 156, 0.7), rgba(0, 0, 0, 0.6));
    z-index: 3;
}
.left-pane-content {
    position: relative;
    z-index: 4;
}
.left-pane-content h1 {
    color: white;
    font-size: 2.8rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.left-pane-content p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    max-width: 400px;
}

.right-pane .container {
    box-shadow: none;
    background: none;
    text-align: left;
    width: 100%;
    max-width: 450px;
}
.logo-container {
    text-align: center;
    margin-bottom: 2rem;
}
.logo-container img {
    max-width: 250px;
    height: auto;
}
.right-pane h2 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}
.right-pane .intro-text {
    font-size: 1.1rem;
    margin-bottom: 2.5rem;
    color: var(--text-light);
}

/* --- Modern "How It Works" Section --- */
.how-it-works {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e9ecef;
}
.how-it-works h3 {
    text-align: center;
    font-size: 1.4rem;
    color: var(--primary-color);
    margin-bottom: 2rem;
}
.benefits-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.benefit-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.benefit-icon {
    flex-shrink: 0;
    background-color: rgba(0, 90, 156, 0.1);
    color: var(--primary-color);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.benefit-icon svg {
    width: 24px;
    height: 24px;
}
.benefit-text h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1.1rem;
    color: var(--text-color);
}
.benefit-text p {
    margin: 0;
    color: var(--text-light);
    font-size: 0.9rem;
    line-height: 1.6;
}


.button-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2.5rem;
}

/* --- Layout for vertically centered pages like login --- */
.centered-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    box-sizing: border-box;
}

/* --- General Components & Containers --- */
.container {
    max-width: 1200px; /* Default for dashboard, tables etc. */
    margin: auto;
    background: var(--card-bg-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}
.form-container {
    max-width: 600px; /* For form pages */
    margin: auto;
    background: var(--card-bg-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}
.centered-layout .container {
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-sizing: border-box;
}
main {
    padding: 2rem;
    max-width: 1200px;
    margin: auto;
}
h1 {
    color: var(--accent-color);
    font-weight: 700;
    margin: 0 0 0.5rem 0;
}
p {
    color: var(--text-light);
    margin-bottom: 2rem;
}
.page-header {
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}
.nav-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

/* --- Buttons --- */
.btn {
    padding: 0.8rem 1.5rem;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background-color: var(--primary-color);
    border: none;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:disabled { background-color: #ccc; cursor: not-allowed; transform: none; }
.driver-btn { background-color: var(--primary-color); }
.driver-btn:hover { background-color: #004a80; }
.admin-btn { background-color: #6c757d; }
.admin-btn:hover { background-color: #5a6268; }
.btn-logout { background-color: #6c757d; padding: 0.5rem 1rem; font-size: 0.9rem;}
.btn-logout:hover { background-color: #5a6268; }
.btn-redeem { color: var(--primary-color); background-color: white; }
.btn-redeem:hover { transform: scale(1.05); }
.btn-approve { background-color: var(--success-color); }
.btn-reject { background-color: var(--accent-color); }
.btn-view-receipt {
    background-color: #6c757d;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

/* --- Forms --- */
form { display: flex; flex-direction: column; gap: 1rem; text-align: left; }
label { font-weight: 600; margin-bottom: -0.5rem; }
input, select {
    padding: 0.75rem;
    border: 1px solid #ced4da;
    border-radius: var(--border-radius);
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
    outline: none;
}
input:focus, select:focus { box-shadow: 0 0 0 0.2rem rgba(0, 90, 156, 0.25); }
.input-group { display: flex; border: 1px solid #ced4da; border-radius: var(--border-radius); overflow: hidden; }
.input-group:focus-within { box-shadow: 0 0 0 0.2rem rgba(0, 90, 156, 0.25); }
.input-prefix { padding: 0.75rem; background-color: #e9ecef; border-right: 1px solid #ced4da; font-weight: 600; }
.input-group input { border: none; }
.otp-input { text-align: center; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 1rem; border-bottom: 1px solid #e9ecef; }
th { font-weight: 600; color: var(--text-light); text-transform: uppercase; font-size: 0.9rem;}
.points-earned { color: var(--success-color); font-weight: 600; }
.points-redeemed { color: var(--accent-color); font-weight: 600; }
.no-data-message { text-align: center; padding: 3rem; color: var(--text-light); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* --- Header --- */
.header {
    background-color: var(--card-bg-color);
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}
.header h1 { font-size: 1.25rem; }
.header h1 span { color: var(--primary-color); font-weight: 700; }

/* --- Dashboard Grid --- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }
.tool-card {
    background-color: var(--card-bg-color);
    padding: 2rem;
    text-align: center;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative; 
}
.tool-card:hover { transform: scale(1.03); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
.tool-card a { text-decoration: none; color: var(--primary-color); font-size: 1.25rem; font-weight: 600; }
.tool-card a::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; }

/* --- Global & Receipt Modals --- */

/* Base overlay style for all pop-ups */
.global-modal-overlay,
.receipt-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex; /* Default to flex for simple alerts */
    justify-content: center; 
    align-items: center;
    opacity: 0; visibility: hidden; transition: all 0.3s ease;
    padding: 1rem; /* Add padding for mobile */
    box-sizing: border-box;
}

/* Specific modal overlays */
#profileModal {
    z-index: 10000;
    display: block; /* Override flex to allow scrolling */
    overflow-y: auto;
    padding: 2rem 0;
}
#receiptModal {
    z-index: 10001; /* Z-INDEX FIX: Higher than profile modal */
    display: flex;
}
.global-modal-overlay {
    z-index: 10002; /* Z-INDEX FIX: Highest for alerts */
}


.global-modal-overlay.active, .receipt-modal-overlay.active { opacity: 1; visibility: visible; }

/* Content box for simple alerts */
.global-modal-content {
    background: white; padding: 2rem; border-radius: 8px;
    max-width: 400px; width: 90%; text-align: center;
    transform: scale(0.9); transition: transform 0.3s ease;
}
.global-modal-overlay.active .global-modal-content { transform: scale(1); }
.global-modal-content p { margin: 0 0 1.5rem 0; font-size: 1.1rem; color: var(--text-color); line-height: 1.6; }
.global-modal-buttons { display: flex; justify-content: center; gap: 1rem; }
.global-modal-buttons button { padding: 0.6rem 1.5rem; border-radius: 8px; font-size: 1rem; font-weight: 600; border: none; cursor: pointer; }
.global-btn-confirm { background-color: var(--primary-color); color: white; }
.global-btn-cancel { background-color: #6c757d; color: white; }


/* --- MODAL CONTENT STYLES (THE FIX) --- */

/* This is the DEFAULT style for modal content (good for receipts) */
.receipt-modal-content {
    background: white; 
    padding: 1rem; 
    border-radius: 8px; 
    max-width: 500px;  /* <-- FIX: Narrower for receipts */
    width: auto;
    margin: 0 auto; 
    position: relative; /* Needed for the close button */
}

/* This is the OVERRIDE for the wide profile modal */
#profileModal .receipt-modal-content {
    max-width: 900px;
    width: 90vw;
    background: var(--bg-color); /* Profile modal has a light grey bg */
}
/* --- END MODAL CONTENT STYLES --- */


.receipt-modal-content img { 
    max-width: 100%; 
    height: auto; 
    display: block; 
}
.receipt-modal-close {
    /* Updated close button for non-profile modals */
    position: absolute;
    top: 10px;
    right: 15px;
    color: #333; /* Dark color for white background */
    font-size: 2.5rem;
    font-weight: bold;
    cursor: pointer;
    text-shadow: none;
    z-index: 10;
}

/* Profile modal has a different close button style */
#profileModal .receipt-modal-close {
    position: absolute; 
    top: 1rem; 
    right: 1.5rem;
    color: var(--text-light); /* Light color for grey background */
    font-size: 2rem;
    text-shadow: none;
    line-height: 1;
}

/* --- Responsive Styles --- */
@media (max-width: 900px) {
    /* Responsive Welcome Page */
    .split-screen-layout { flex-direction: column; }
    .left-pane, .right-pane { width: 100%; min-height: 50vh; }
    .right-pane { min-height: auto; padding: 2rem; }
    .left-pane h1 { font-size: 2.2rem; }
    
    /* === RESPONSIVE TABLE REFACTOR - START === */
    table thead { display: none; }
    
    table tbody { display: block; width: 100%; }
    
    table tr {
        display: block; 
        margin-bottom: 1.5rem; 
        border: 1px solid #e9ecef;
        border-radius: var(--border-radius); 
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        padding: 1rem;
    }
    
    table td {
        display: block; 
        text-align: right; 
        padding-left: 50%; 
        position: relative; 
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e9ecef;
    }
    
    table td:last-child {
        border-bottom: 0;
    }
    
    table td::before {
        content: attr(data-label); 
        position: absolute;
        left: 1rem; 
        width: calc(50% - 2rem); 
        font-weight: 600;
        color: var(--text-light); 
        text-align: left;
        white-space: nowrap;
    }
    /* === RESPONSIVE TABLE REFACTOR - END === */
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }
    main, .header { 
        padding: 1rem; 
    }
    .container, .form-container { 
        padding: 1.5rem; 
        box-shadow: none;
        border-radius: 0;
    }
    h1 { font-size: 1.5rem; }
    .header h1 { font-size: 1.25rem; }
    .tool-grid { grid-template-columns: 1fr; }

    /* Further refine table cell content on very small screens */
    table td {
        padding-left: 40%;
    }
    table td::before {
        width: calc(40% - 1.5rem);
    }
    .actions {
        justify-content: flex-start; 
    }
}

/* --- Added Styles for Profile Modal & Edit Driver --- */

.profile-details-list {
    list-style: none;
    padding: 1.5rem; /* <-- LOOKS GOOD: Added padding */
    margin: 0 0 1.5rem 0;
    background: var(--card-bg-color); /* <-- LOOKS GOOD: Added white card bg */
    border-radius: var(--border-radius); /* <-- LOOKS GOOD: Added rounded corners */
    box-shadow: var(--box-shadow); /* <-- LOOKS GOOD: Added shadow */
}
.profile-details-list li {
    display: grid; 
    grid-template-columns: 120px 1fr; 
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e9ecef;
    min-height: 30px; 
}
.profile-details-list li:last-child {
    border-bottom: none;
}
.profile-details-list li strong {
    color: var(--text-light);
    font-weight: 600;
}

.profile-modal-grid {
    display:grid; 
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.profile-modal-card {
    background: var(--card-bg-color); /* <-- LOOKS GOOD: Changed to white */
    padding: 1rem;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: var(--box-shadow); /* <-- LOOKS GOOD: Added shadow */
}
.profile-modal-card p {
    color: var(--text-color);
    font-weight: 600;
    margin: 0 0 0.5rem 0;
}
.profile-modal-card img {
    width: 100%;
    height: 200px;
    object-fit: contain; 
    border-radius: var(--border-radius);
    background-color: #eee;
    cursor: zoom-in; 
}

.profile-modal-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e9ecef;
}

/* Styles for Edit Mode */
.profile-edit-mode .edit-input,
.profile-edit-mode .edit-select {
    display: block;
    width: 100%;
}
.profile-edit-mode span {
    display: none; 
}
.edit-input,
.edit-select {
    display: none; 
    padding: 0.5rem; 
}
/* Keep mobile number span visible even in edit mode */
.profile-details-list li:nth-child(2) span {
    display: inline !important;
}

/* Loading overlay for profile modal */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10002; /* Make sure it's on top of all modals */
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid #fff;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-right: 15px;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}