/* Basic Reset & Body Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Smoother scrolling on touch devices */
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    line-height: 1.6;
    background-color: #f4f7f6;
    /* Light grey background */
    color: #333;
    padding: 0;
    /* Remove default padding */
    font-size: 16px;
    /* Base font size */
    transition: padding 0.2s ease-out;
    /* Smooth padding transition */
}

/* Container */
.container {
    max-width: 72rem;
    margin: 0 auto;
    background-color: #ffffff;
    padding: 1.5rem;
    /* Default padding */
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: padding 0.2s ease-out;
    /* Smooth padding transition */
}

/* Navigation Styles */
.main-nav {
    background-color: #1f2937;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 72rem;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    padding: 1rem 0;
}

.nav-tabs {
    display: flex;
    list-style: none;
}

.nav-item {
    margin-left: 1rem;
}

.nav-link {
    display: block;
    padding: 1rem;
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.2);
    color: #60a5fa;
}

/* Tab Content */
.tab-content {
    width: 100%;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* Headings */
h1 {
    font-size: 1.875rem;
    /* 30px */
    font-weight: 700;
    margin-bottom: 1.5rem;
    text-align: center;
    color: #1f2937;
}

/* Section Header for alignment (e.g., Trip Log + PDF Button) */
.section-header {
    display: flex;
    justify-content: space-between;
    /* Pushes items apart */
    align-items: center;
    /* Vertically aligns items */
    margin-bottom: 1rem;
    /* Space below header */
    margin-top: 2rem;
    /* Space above header */
    border-bottom: 1px solid #e5e7eb;
    /* Separator line */
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    gap: 0.5rem;
    /* Add gap for wrapped items */
}

.section-header h2,
.section-header h3 {
    /* Apply shared styles to H2/H3 in header */
    margin: 0;
    /* Remove default margin */
    border-bottom: none;
    /* Remove double border */
    padding-bottom: 0;
    font-weight: 600;
    color: #374151;
}

.section-header h2 {
    font-size: 1.5rem;
}

/* 24px */
.section-header h3 {
    font-size: 1.25rem;
}

/* 20px */

/* Summary header specific adjustments */
.summary-header {
    margin-top: 0;
    /* Remove extra top margin from base header style */
    border-bottom: none;
    /* No border needed here */
    padding-bottom: 0;
    margin-bottom: 0.75rem;
    /* Restore bottom margin */
}

/* Original H3 style if needed outside a section-header */
h3:not(.section-header h3) {
    font-size: 1.25rem;
    /* 20px */
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #4b5563;
}

/* Form Styles */
.trip-form {
    margin-bottom: 2rem;
    display: grid;
    grid-template-columns: 1fr;
    /* Mobile-first: single column */
    gap: 1rem;
}

/* Form grid for medium screens and up */
@media (min-width: 768px) {
    .trip-form {
        grid-template-columns: repeat(3, 1fr);
    }
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    /* 14px */
    font-weight: 700;
    color: #374151;
    margin-bottom: 0.5rem;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="number"],
.form-group select {
    display: block;
    width: 100%;
    padding: 0.75rem 0.75rem;
    /* Slightly taller padding for easier touch */
    font-size: 1rem;
    /* 16px */
    line-height: 1.5;
    color: #1f2937;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #d1d5db;
    appearance: none;
    border-radius: 0.375rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-group select {
    /* Specific styles for select dropdown arrow */
    appearance: none;
    /* Remove default arrow */
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="%236b7280"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>');
    /* Basic dropdown arrow */
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1em 1em;
    padding-right: 2.5rem;
    /* Add padding to prevent text overlap with arrow */
}

.form-group input:focus,
.form-group select:focus {
    color: #1f2937;
    background-color: #fff;
    border-color: #60a5fa;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

/* Make date/time inputs work better on iOS */
.form-group input[type="date"],
.form-group input[type="time"] {
    min-height: calc(1.5em + 1.5rem + 2px);
    /* Match padding + line-height + border */
}

.form-actions {
    grid-column: 1 / -1;
    /* Span all columns in the grid layout */
    text-align: center;
    margin-top: 1rem;
}

/* Button Styles */
.btn {
    display: inline-block;
    font-weight: 700;
    line-height: 1.5;
    color: #fff;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    border: 1px solid transparent;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    /* 16px */
    border-radius: 0.375rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    -webkit-appearance: none;
    /* Remove default iOS button styles */
    appearance: none;
}

.submit-btn {
    background-color: #3b82f6;
    /* Blue */
    border-color: #3b82f6;
    padding: 0.75rem 1.5rem;
    /* Make main submit button larger */
}

.submit-btn:hover {
    background-color: #2563eb;
    border-color: #1d4ed8;
}

.submit-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.5);
}

.delete-btn {
    background-color: #ef4444;
    /* Red */
    border-color: #ef4444;
    padding: 0.35rem 0.7rem;
    /* Increased padding slightly for easier touch */
    font-size: 0.875rem;
    /* 14px */
}

.delete-btn:hover {
    background-color: #dc2626;
    border-color: #b91c1c;
}

.delete-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(239, 68, 68, 0.5);
}

.pdf-btn {
    background-color: #10b981;
    /* Emerald green */
    border-color: #10b981;
    padding: 0.4rem 0.8rem;
    /* Slightly smaller than main submit */
    font-size: 0.875rem;
    white-space: nowrap;
    /* Prevent button text wrapping */
}

.pdf-btn:hover {
    background-color: #059669;
    border-color: #047857;
}

.pdf-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(16, 185, 129, 0.5);
}

/* Specific style for driver PDF button */
.pdf-btn-driver {
    background-color: #8b5cf6;
    /* Violet */
    border-color: #8b5cf6;
}

.pdf-btn-driver:hover {
    background-color: #7c3aed;
    border-color: #6d28d9;
}

.pdf-btn-driver:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(139, 92, 246, 0.5);
}

.cancel-btn {
    background-color: #6b7280;
    /* Gray */
    border-color: #6b7280;
    padding: 0.5rem 1rem;
    /* Match default btn padding */
    font-size: 1rem;
}

.cancel-btn:hover {
    background-color: #4b5563;
    border-color: #374151;
}

.cancel-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(107, 114, 128, 0.5);
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    /* Enable horizontal scrolling */
    margin-bottom: 2rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    /* Improve scrolling appearance on WebKit */
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    min-width: 650px;
    /* Force minimum width to encourage scrolling rather than wrapping on main table */
    border-collapse: collapse;
    background-color: #fff;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    /* Default padding */
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
    white-space: nowrap;
    /* Prevent text wrapping in main table cells initially */
    font-size: 0.9rem;
    /* Slightly smaller font in tables */
}

.data-table .wrap-text {
    white-space: normal;
}

/* Class to allow wrapping if needed */
.data-table thead th {
    background-color: #f3f4f6;
    font-weight: 600;
    color: #374151;
    border-bottom-width: 2px;
    border-color: #d1d5db;
    position: sticky;
    /* Make header sticky during vertical scroll */
    top: 0;
    /* Required for sticky */
    z-index: 10;
    /* Keep header above scrolling content */
}

/* Driver Color Classes (Pastel Backgrounds) */
.driver-color-1 {
    background-color: #fff1f1;
}

.driver-color-2 {
    background-color: #f1f9ff;
}

.driver-color-3 {
    background-color: #f6fff1;
}

.driver-color-4 {
    background-color: #fffdf1;
}

.driver-color-5 {
    background-color: #f9f1ff;
}

.driver-color-6 {
    background-color: #f1feff;
}

.driver-color-7 {
    background-color: #fff6f1;
}

.driver-color-8 {
    background-color: #f1fff8;
}

/* Hover effect for table rows (overrides driver colors) */
.data-table tbody tr:hover {
    background-color: #dbeafe !important;
    /* Use !important to override specific color classes */
}

/* No border on last row */
.data-table tbody tr:last-child td {
    border-bottom: 0;
}

/* Summary Styles */
.summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.summary-card {
    background-color: #ffffff;
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
}

.summary-card .table-container {
    margin-bottom: 0;
}

/* Remove extra margin for tables in cards */
.summary-table {
    min-width: auto;
}

/* Allow summary tables to shrink more */
.summary-table th,
.summary-table td {
    padding: 0.5rem 0.75rem;
    white-space: normal;
}

/* Allow wrapping */

/* Modal Styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    /* top, right, bottom, left = 0 */
    background-color: rgba(0, 0, 0, 0.6);
    /* Semi-transparent black */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Ensure it's on top */
    padding: 1rem;
    /* Padding for smaller screens */
}

.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 400px;
    /* Max width for the modal */
    display: flex;
    flex-direction: column;
    gap: 1rem;
    /* Space between elements inside modal */
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #1f2937;
}

.modal-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #374151;
}

.modal-form-group input[type="date"],
.modal-form-group select,
.modal-form-group input[type="text"] {
    /* Shared style for inputs */
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 1rem;
    background-color: #fff;
    /* Ensure background */
}

/* Additional CSS for Expense Tracking */

/* Nav bar styles for the new tabs */
@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        padding: 0.5rem;
    }

    .nav-tabs {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        margin-top: 0.5rem;
    }

    .nav-item {
        margin-left: 0;
        margin-right: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .nav-link {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
}

/* Modal textarea styles */
.modal-form-group textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 1rem;
    background-color: #fff;
    resize: vertical;
    min-height: 80px;
}

.modal-form-group textarea:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

/* Expense table specific styles */
.expense-general {
    font-style: italic;
    color: #6b7280;
}

/* Color code for expense categories */
.expense-category-gas {
    background-color: #fbdddd;
}

.expense-category-maintenance {
    background-color: #e0f2fe;
}

.expense-category-marketing {
    background-color: #d1fae5;
}

.expense-category-other {
    background-color: #fef3c7;
}

/* Add spacing between forms and tables */
.trip-form,
.expense-form {
    margin-bottom: 2.5rem;
}

/* Center align action buttons */
.action-cell {
    text-align: center;
}

/* No data message */
.no-data-cell {
    text-align: center;
    padding: 1.5rem;
    color: #6b7280;
    font-style: italic;
}

/* Expense-related action buttons */
.expense-btn {
    background-color: #8b5cf6;
    border-color: #8b5cf6;
}

.expense-btn:hover {
    background-color: #7c3aed;
    border-color: #6d28d9;
}

.expense-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(139, 92, 246, 0.5);
}

/* Add space between tab content and header */
.tab-pane {
    padding-top: 1rem;
}

/* Improve spacing in expense table */
#expenseTable td {
    padding: 0.6rem 0.75rem;
}

/* Make sure the action column doesn't get too wide */
.data-table th:last-child,
.data-table td:last-child {
    width: 1%;
    white-space: nowrap;
}

/* Add some spacing between sections on the home tab */
#homeTab .section-header:not(:first-of-type) {
    margin-top: 3rem;
}

/* More responsive tables for small screens */
@media (max-width: 768px) {
    .data-table {
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.5rem;
    }

    .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* Make sure the description doesn't create too wide rows */
#expenseTable td:nth-child(5) {
    max-width: 200px;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Add more space at the bottom of the page */
.container {
    margin-bottom: 2rem;
}

/* Pagination Styles */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pagination-btn {
    background-color: #3b82f6;
    border-color: #3b82f6;
    padding: 0.4rem 0.8rem;
    font-size: 0.875rem;
}

.pagination-btn:hover {
    background-color: #2563eb;
    border-color: #1d4ed8;
}

.pagination-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.5);
}

.pagination-btn:disabled {
    background-color: #93c5fd;
    border-color: #93c5fd;
    cursor: not-allowed;
    opacity: 0.7;
}

.pagination-info {
    font-weight: 600;
    color: #4b5563;
}

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-size-selector label {
    font-weight: 600;
    color: #4b5563;
    font-size: 0.875rem;
}

.page-size-selector select {
    padding: 0.4rem 0.6rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background-color: #fff;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="%236b7280"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>');
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em 1em;
    padding-right: 2rem;
}

.page-size-selector select:focus {
    outline: 0;
    border-color: #60a5fa;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

@media (max-width: 768px) {
    .pagination-container {
        flex-direction: column;
        align-items: flex-start;
    }

    .pagination-controls {
        width: 100%;
        justify-content: space-between;
    }

    .page-size-selector {
        width: 100%;
        justify-content: flex-end;
    }
}