* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent text size adjustment on orientation change */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

:root {
    /* Softer, Eye-Friendly Color Palette */
    --primary-red: #d1001f;
    --dark-red: #C1121F;
    --light-red: #F4A3A8;
    --accent-red: #D62828;
    --pure-white: #FFFFFF;
    --off-white: #F8F9FA;
    --light-bg: #F1F3F5;
    --text-dark: #212529;
    --text-medium: #495057;
    --text-light: #6C757D;
    --border-color: #DEE2E6;
    --shadow-sm: 0 2px 8px rgba(230, 57, 70, 0.08);
    --shadow-md: 0 4px 16px rgba(230, 57, 70, 0.12);
    --shadow-lg: 0 8px 32px rgba(230, 57, 70, 0.16);
    --success-green: #06D6A0;
    --success-dark: #05B085;
    --info-blue: #4A90E2;
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====== MOBILE APP-LIKE BEHAVIORS ====== */

/* Prevent text selection and context menu */
body {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    touch-action: manipulation; /* Prevent double-tap zoom and other gestures */
}

/* Allow text selection only in input fields and textareas */
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior-y: none;
}

/* Prevent image long-press menu on iOS */
img {
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Disable context menu on long press */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

/* But allow selection in tables for better UX */
.table-responsive, 
table, 
td, 
th {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Ensure smooth scrolling */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Prevent bounce effect on iOS */
body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.pages-container {
    -webkit-overflow-scrolling: touch;
    height: 100%;
    overflow-y: auto;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--off-white);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ====== SIDEBAR ====== */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--primary-red) 0%, var(--dark-red) 100%);
    color: var(--pure-white);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    overflow-y: auto;
    transition: transform var(--transition-smooth);
    /* Safe area for sidebar top */
    padding-top: env(safe-area-inset-top);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

.sidebar-header {
    padding: 30px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    animation: fadeInDown 0.5s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.logo-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.logo {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--pure-white);
    padding: 10px;
    object-fit: contain;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.brand-name {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.nav-menu {
    flex: 1;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px 20px;
    background: none;
    border: none;
    color: var(--pure-white);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all var(--transition-smooth);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: var(--pure-white);
    transform: scaleY(0);
    transition: transform var(--transition-smooth);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.nav-item:hover::before {
    transform: scaleY(1);
}

.nav-item.active {
    background: var(--pure-white);
    color: var(--primary-red);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nav-item.active::before {
    transform: scaleY(1);
    background: var(--primary-red);
}

.nav-icon {
    font-size: 22px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    /* Safe area for bottom */
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.logout-btn {
    width: 100%;
    padding: 14px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--pure-white);
    color: var(--pure-white);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    transition: all var(--transition-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.logout-btn:hover {
    background: var(--pure-white);
    color: var(--primary-red);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ====== HAMBURGER MENU ====== */
.hamburger-menu {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    gap: 5px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    justify-content: center;
    align-items: center;
    transition: all var(--transition-smooth);
    border-radius: 8px;
}

.hamburger-menu:active {
    transform: scale(0.95);
}

.hamburger-menu span {
    width: 26px;
    height: 3px;
    background: var(--pure-white);
    border-radius: 3px;
    transition: all var(--transition-smooth);
    display: block;
}

.hamburger-menu.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.hamburger-menu.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-20px);
}

.hamburger-menu.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* ====== MAIN CONTENT ====== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--off-white);
}

.top-header {
    background: var(--pure-white);
    padding: 20px 30px;
    /* FIX: Add safe area padding for notch */
    padding-top: calc(20px + env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    animation: slideInDown 0.4s ease;
    z-index: 100;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.top-header h2 {
    color: var(--primary-red);
    font-size: 28px;
    font-weight: 800;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.user-email {
    color: var(--text-medium);
    font-size: 14px;
    font-weight: 500;
}

.pages-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    animation: fadeInUp 0.5s ease;
    /* Height calculation needs to respect safe areas, but 100% works best with flex parent */
    height: 100%;
    /* Extra space for bottom + safe area */
    padding-bottom: calc(50px + env(safe-area-inset-bottom));
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pages-container::-webkit-scrollbar {
    width: 8px;
}

.pages-container::-webkit-scrollbar-track {
    background: var(--border-color);
}

.pages-container::-webkit-scrollbar-thumb {
    background: var(--light-red);
    border-radius: 10px;
}

.page {
    display: none;
    height: 100%;
}

.page.active {
    display: block;
    animation: pageSlide 0.4s ease;
}

@keyframes pageSlide {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ====== DASHBOARD ====== */
.dashboard-controls {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 25px;
    flex-wrap: wrap;
    background: var(--pure-white);
    padding: 20px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    animation: slideInLeft 0.5s ease;
    /* FIX: Prevent overflow */
    max-width: 100%;
    overflow-x: hidden;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 180px;
}

.control-group label,
.date-selector label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dark);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.date-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 200px;
}

.control-group input,
.control-group select,
.date-selector input,
.dashboard-controls input,
.dashboard-controls select {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-smooth);
    background: var(--pure-white);
    color: var(--text-dark);
    /* FIX: Ensure inputs don't overflow container */
    max-width: 100%;
    width: 100%;
}

.control-group input:focus,
.control-group select:focus,
.date-selector input:focus,
.dashboard-controls input:focus,
.dashboard-controls select:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 4px rgba(255, 0, 0, 0.1);
    transform: translateY(-2px);
}

.control-group select,
.dashboard-controls select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FF0000' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: var(--pure-white);
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all var(--transition-smooth);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    animation: scaleIn 0.4s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary-red);
    transform: scaleY(0);
    transition: transform var(--transition-smooth);
}

.metric-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.metric-card:hover::before {
    transform: scaleY(1);
}

.metric-icon {
    font-size: 48px;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.metric-content {
    flex: 1;
}

.metric-label {
    color: var(--text-medium);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 600;
}

.metric-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary-red);
}

.metric-value.profit {
    color: #00C853;
}

.performance-section {
    background: var(--pure-white);
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
    animation: slideInUp 0.5s ease;
    max-width: 100%;
    overflow-x: hidden;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.performance-section h3 {
    color: var(--text-dark);
    margin-bottom: 25px;
    font-size: 20px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.performance-section h3::before {
    content: '';
    width: 4px;
    height: 24px;
    background: var(--primary-red);
    border-radius: 2px;
}

/* ====== PAGE HEADER ====== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    animation: fadeIn 0.5s ease;
}

.page-header h3 {
    color: var(--text-dark);
    font-size: 26px;
    font-weight: 800;
}

/* ====== BUTTONS ====== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    font-size: 15px;
    transition: all var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--dark-red) 100%);
    color: var(--pure-white);
}

.btn-success {
    background: linear-gradient(135deg, #00C853 0%, #00A843 100%);
    color: var(--pure-white);
}

.btn-secondary {
    background: linear-gradient(135deg, #666666 0%, #555555 100%);
    color: var(--pure-white);
}

.btn-danger {
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--dark-red) 100%);
    color: var(--pure-white);
    padding: 8px 16px;
    font-size: 13px;
}

.btn-edit {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: var(--pure-white);
    padding: 8px 16px;
    font-size: 13px;
}

.full-width {
    width: 100%;
    justify-content: center;
}

/* ====== FORMS ====== */
.form-container {
    background: var(--pure-white);
    padding: 30px;
    border-radius: 16px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-red);
    animation: slideInRight 0.5s ease;
    max-width: 100%;
    overflow-x: hidden;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

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

.form-row input,
.form-row select,
.form-row textarea {
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    transition: all var(--transition-smooth);
    background: var(--pure-white);
    color: var(--text-dark);
    font-weight: 500;
}

.form-row input::placeholder,
.form-row select::placeholder,
.form-row textarea::placeholder {
    color: var(--text-light);
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 4px rgba(255, 0, 0, 0.1);
    transform: translateY(-2px);
}

.form-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    cursor: pointer;
    accent-color: var(--primary-red);
}

.form-row label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    margin-top: 25px;
    flex-wrap: wrap;
}

.form-row select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FF0000' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
    cursor: pointer;
}

/* ====== TABLES ====== */
.table-responsive {
    overflow-x: auto;
    background: var(--pure-white);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    animation: fadeIn 0.6s ease;
    max-width: 100%;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: var(--border-color);
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--light-red);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--dark-red) 100%);
    color: var(--pure-white);
    font-weight: 700;
}

th {
    padding: 18px;
    text-align: left;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 800;
}

td {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    font-weight: 500;
}

tbody tr {
    transition: all var(--transition-fast);
}

tbody tr:hover {
    background: linear-gradient(90deg, rgba(255, 0, 0, 0.03) 0%, transparent 100%);
    transform: translateX(4px);
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* ====== MODALS ====== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--pure-white);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlide {
    from {
        transform: scale(0.9) translateY(-20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.login-modal {
    width: 100%;
    max-width: 420px;
    padding: 50px;
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.login-logo {
    width: 90px;
    height: 90px;
    margin-bottom: 20px;
    border-radius: 50%;
    background: var(--primary-red);
    padding: 12px;
    box-shadow: 0 8px 24px rgba(255, 0, 0, 0.3);
    animation: logoFloat 3s ease-in-out infinite;
}

.login-header h1 {
    color: var(--primary-red);
    font-size: 28px;
    margin-bottom: 8px;
    font-weight: 900;
}

.login-header p {
    color: var(--text-medium);
    font-size: 14px;
    font-weight: 600;
}

#loginForm {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

#loginForm input {
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    transition: all var(--transition-smooth);
}

#loginForm input:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 4px rgba(255, 0, 0, 0.1);
}

#loginForm button {
    padding: 16px;
    margin-top: 10px;
    font-size: 16px;
}

.error-message {
    color: var(--primary-red);
    font-size: 13px;
    text-align: center;
    margin-top: 10px;
    font-weight: 600;
}

/* ====== UTILITIES ====== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-light);
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 998;
    animation: fadeIn 0.3s ease;
}

.mobile-overlay.active {
    display: block;
}

/* ====== CHARTS ====== */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

/* Chart fix for mobile to prevent overflow */
.chart-wrapper {
    padding: 20px;
    background: var(--off-white);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 100%;
    overflow: hidden; 
    position: relative;
}

.chart-wrapper canvas {
    max-width: 100% !important;
    height: auto !important;
}

.metrics-detailed {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.detail-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--off-white);
    border-radius: 12px;
    border-left: 4px solid var(--primary-red);
    transition: all var(--transition-smooth);
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.detail-metric:hover {
    transform: translateX(5px);
    box-shadow: var(--shadow-sm);
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 8px;
}

.detail-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary-red);
    display: block;
}

.detail-value.profit {
    color: #00C853;
}

/* ====== RESPONSIVE DESIGN ====== */
@media (max-width: 768px) {
    .hamburger-menu {
        display: flex !important;
    }

    .sidebar {
        position: fixed;
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        z-index: 999;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.3);
    }

    .top-header {
        background: linear-gradient(135deg, var(--primary-red) 0%, var(--dark-red) 100%);
        color: var(--pure-white);
        padding: 15px 20px;
        /* FIX: Ensure notch safe area */
        padding-top: calc(15px + env(safe-area-inset-top));
        gap: 15px;
        /* Ensure header stays at top */
        position: sticky;
        top: 0;
        z-index: 100;
        height: auto;
    }

    .top-header h2 {
        color: var(--pure-white);
        font-size: 20px;
    }

    .user-email {
        display: none;
    }

    .pages-container {
        padding: 15px;
        padding-top: 25px;
        height: 100%;
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    .dashboard-controls {
        flex-direction: column;
        padding: 15px;
        gap: 12px;
        width: 100%;
        box-sizing: border-box;
    }

    .control-group,
    .date-selector {
        width: 100%;
        min-width: 0; /* FIX: Remove fixed min-width to stop swipe issues */
    }

    .control-group input,
    .control-group select,
    .date-selector input {
        width: 100%;
        max-width: 100%; /* FIX: Ensure input fits container */
        font-size: 16px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .metric-card {
        padding: 20px;
    }

    .metric-icon {
        font-size: 42px;
    }

    .metric-value {
        font-size: 24px;
    }

    .performance-section {
        padding: 20px;
        overflow-x: auto;
    }

    .performance-section h3 {
        font-size: 18px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .page-header h3 {
        font-size: 22px;
    }

    .page-header .btn {
        width: 100%;
    }

    .form-container {
        padding: 20px;
    }

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

    .form-row input,
    .form-row select,
    .form-row textarea {
        font-size: 16px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    table {
        font-size: 13px;
    }

    th {
        padding: 14px;
        font-size: 12px;
    }

    td {
        padding: 12px 14px;
    }

    .action-buttons {
        flex-direction: column;
        gap: 6px;
    }

    .btn-edit,
    .btn-danger {
        width: 100%;
        justify-content: center;
    }

    .login-modal {
        width: 90%;
        max-width: 380px;
        padding: 35px;
    }

    .charts-container {
        grid-template-columns: 1fr;
    }

    .metrics-detailed {
        grid-template-columns: 1fr;
    }

    .vehicle-stats {
        grid-template-columns: 1fr 1fr; 
    }
    
    .top-vehicles-grid {
        grid-template-columns: 1fr;
    }

    .advance-summary-grid {
        grid-template-columns: 1fr;
    }
    
    .advance-card {
        padding: 15px;
    }
    
    .advance-card-icon {
        font-size: 36px;
        width: 60px;
        height: 60px;
    }
    
    .advance-card-amount {
        font-size: 20px;
    }

    .report-controls {
        text-align: center;
    }
    
    .btn-report {
        width: 100%;
        justify-content: center;
    }
    
    .report-notification {
        left: 20px;
        right: 20px;
        top: calc(70px + env(safe-area-inset-top));
    }

    .profile-photo {
        width: 40px;
        height: 40px;
        border-width: 2px;
    }
    
    .vehicle-photo {
        width: 60px;
        height: 45px;
    }
    
    .no-photo {
        width: 40px;
        height: 40px;
        font-size: 20px;
        border-width: 2px;
    }
    
    .no-vehicle-photo {
        width: 60px;
        height: 45px;
        font-size: 24px;
    }
    
    .photo-preview {
        max-width: 150px;
        max-height: 150px;
    }
}

/* ====== SPECIFIC iPHONE MINI & SMALL SCREEN FIXES (375px width) ====== */
@media screen and (max-width: 390px) {
    .sidebar {
        width: 100vw;
        max-width: 100vw;
    }

    .sidebar-header {
        padding: 20px 15px;
    }

    .logo {
        width: 60px;
        height: 60px;
    }

    .brand-name {
        font-size: 14px;
    }

    .nav-item {
        padding: 14px 16px;
        font-size: 14px;
    }

    .nav-icon {
        font-size: 20px;
    }

    .top-header {
        padding: 12px 15px;
        /* FIX: Extra adjustment for Mini notches */
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .top-header h2 {
        font-size: 18px;
    }

    .hamburger-menu {
        width: 40px;
        height: 40px;
    }

    .hamburger-menu span {
        width: 24px;
    }

    .pages-container {
        padding: 15px 12px;
        padding-top: 20px; 
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    .dashboard-controls {
        padding: 15px 12px;
        /* FIX: Ensure container clips overflow */
        overflow: hidden;
    }
    
    /* FIX: Force date selector to stay within bounds */
    .date-selector, 
    .control-group {
        min-width: 0;
        width: 100%;
    }
    
    .date-selector input,
    .control-group input {
        width: 100%;
        max-width: 100%;
        /* Prevent font scaling causing zoom */
        font-size: 16px; 
    }

    .metrics-grid {
        gap: 15px;
        grid-template-columns: 100%;
    }

    .metric-card {
        padding: 16px;
        flex-wrap: nowrap; 
    }

    .metric-icon {
        font-size: 32px;
        min-width: 32px;
    }

    .metric-label {
        font-size: 11px;
    }

    .metric-value {
        font-size: 22px; 
        word-break: break-word;
    }

    .performance-section {
        padding: 15px;
        width: 100%;
    }

    .performance-section h3 {
        font-size: 16px;
    }

    .chart-wrapper {
        padding: 10px;
        width: 100%;
        overflow-x: hidden;
    }

    .page-header h3 {
        font-size: 20px;
    }

    .form-container {
        padding: 15px;
    }

    .form-row input,
    .form-row select {
        padding: 12px 14px;
        font-size: 15px;
    }

    .btn {
        padding: 11px 16px;
        font-size: 14px;
        width: 100%;
        justify-content: center;
    }

    table {
        font-size: 12px;
    }

    th {
        padding: 12px;
        font-size: 11px;
    }

    td {
        padding: 10px 12px;
        font-size: 12px;
    }

    .login-modal {
        width: 95%;
        padding: 30px 20px;
    }

    .login-logo {
        width: 75px;
        height: 75px;
    }

    .login-header h1 {
        font-size: 24px;
    }

    #loginForm input {
        padding: 14px 16px;
        font-size: 15px;
    }

    .toast {
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: 15px;
        left: 15px;
        max-width: unset;
        font-size: 13px;
    }
}

/* ====== LOADING ANIMATIONS ====== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ====== SMOOTH SCROLLING ====== */
html {
    scroll-behavior: smooth;
}

/* ====== FOCUS VISIBLE ====== */
*:focus-visible {
    outline: 2px solid var(--primary-red);
    outline-offset: 2px;
}

/* ====== SELECTION ====== */
::selection {
    background: var(--primary-red);
    color: var(--pure-white);
}

::-moz-selection {
    background: var(--primary-red);
    color: var(--pure-white);
}

/* ====== PERFORMANCE TABLE ====== */
.performance-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.performance-table table {
    min-width: 600px;
}

/* ====== EMPTY STATE ====== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
}

.empty-state-subtext {
    font-size: 14px;
    color: var(--text-light);
}

/* ====== TOAST NOTIFICATIONS ====== */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--pure-white);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary-red);
    z-index: 3000;
    animation: slideInRight 0.3s ease;
    max-width: 400px;
}

.toast.success {
    border-left-color: #00C853;
}

.toast.error {
    border-left-color: var(--primary-red);
}

/* Driver Advance Summary Grid */
.advance-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.advance-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    color: white;
}

.advance-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.advance-card-icon {
    font-size: 48px;
    background: rgba(255, 255, 255, 0.2);
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.advance-card-content {
    flex: 1;
}

.advance-card-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 5px;
    color: white;
}

.advance-card-amount {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 5px;
    color: #fff;
}

.advance-card-label {
    font-size: 12px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Report Button Styles */
.report-controls {
    margin-bottom: 20px;
    text-align: right;
}

.btn-report {
    background: linear-gradient(135deg, #DC143C 0%, #A00000 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(220, 20, 60, 0.3);
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-report:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 20, 60, 0.4);
}

.btn-report:active {
    transform: translateY(0);
}

.btn-report:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Report Success Notification */
.report-notification {
    position: fixed;
    top: 80px;
    right: 20px;
    background: #27AE60;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-weight: 600;
    z-index: 10000;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease;
}

.report-notification.show {
    opacity: 1;
    transform: translateX(0);
}

/* ====== PHOTO DISPLAY STYLES ====== */

/* Driver Profile Photos */
.profile-photo {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary-red);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.profile-photo:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 16px rgba(220, 20, 60, 0.3);
}

/* Vehicle Photos */
.vehicle-photo {
    width: 80px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--primary-red);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.vehicle-photo:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(220, 20, 60, 0.3);
}

/* Placeholder when no photo */
.no-photo {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-light);
    border: 2px dashed var(--border-color);
    transition: all 0.3s ease;
}

.no-photo:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    transform: scale(1.1);
}

.no-vehicle-photo {
    width: 80px;
    height: 60px;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--text-light);
    border: 2px dashed var(--border-color);
    transition: all 0.3s ease;
}

.no-vehicle-photo:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    transform: scale(1.05);
}

/* Photo Preview in Forms */
.photo-preview-container {
    margin-top: 15px;
    text-align: center;
    padding: 15px;
    background: var(--light-bg);
    border-radius: 12px;
    border: 2px dashed var(--border-color);
}

.photo-preview {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    border: 3px solid var(--primary-red);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin: 10px auto;
    display: block;
    object-fit: cover;
}

/* Photo input field helper text */
.form-row small {
    display: block;
    color: var(--text-light);
    font-size: 12px;
    margin-top: 5px;
    font-style: italic;
}

/* Photo column in tables */
td .profile-photo,
td .vehicle-photo,
td .no-photo,
td .no-vehicle-photo {
    margin: 0 auto;
    display: block;
}

/* Lightbox effect on click (optional enhancement) */
.photo-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
    animation: fadeIn 0.3s ease;
}

.photo-lightbox.active {
    display: flex;
}

.photo-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Photo upload tips styling */
.photo-upload-tip {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 10px;
    font-size: 13px;
    color: #856404;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.photo-upload-tip::before {
    content: "💡";
    font-size: 18px;
    flex-shrink: 0;
}

/* Loading state for photos */
.photo-loading {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Photo error state */
.photo-error {
    color: var(--primary-red);
    font-size: 12px;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.photo-error::before {
    content: "⚠️";
}

/* Receipt Upload Styles */
.receipt-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: #DC143C;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.receipt-link:hover {
    background: #B00020;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(220, 20, 60, 0.3);
}

input[type="file"] {
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    background: #DC143C;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: #B00020;
}

#uploadProgress {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#currentReceipt {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

#removeReceiptBtn:hover {
    background: #C0392B;
    transform: scale(1.05);
}

/* Mobile responsiveness for receipt links */
@media (max-width: 768px) {
    .receipt-link {
        font-size: 12px;
        padding: 4px 10px;
    }
}

/* Top Performing Vehicles Grid */
.top-vehicles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.top-vehicle-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border: 2px solid #ECF0F1;
    border-radius: 12px;
    padding: 20px;
    position: relative;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.top-vehicle-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(220, 20, 60, 0.15);
    border-color: #DC143C;
}

.rank-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #DC143C;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(220, 20, 60, 0.3);
}

.vehicle-info {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #ECF0F1;
}

.vehicle-name {
    font-size: 18px;
    font-weight: 700;
    color: #2C3E50;
    margin-bottom: 5px;
}

.vehicle-type {
    font-size: 12px;
    color: #7F8C8D;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.vehicle-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    color: #95A5A6;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 14px;
    font-weight: 700;
    color: #2C3E50;
}

.stat-value.profit {
    color: #27AE60;
}