/**
 * Mobile Native UI - (re)expense
 * Transform the web app into a native mobile experience
 * All styles scoped to max-width: 767.98px to preserve desktop
 */

/* =====================================================
   CSS Custom Properties for Mobile
   ===================================================== */
:root {
    --mobile-nav-height: 60px;
    --mobile-nav-height-safe: calc(60px + env(safe-area-inset-bottom, 0px));
    --mobile-drawer-width: 280px;
    --mobile-transition-timing: cubic-bezier(0.32, 0.72, 0, 1);
    --mobile-transition-duration: 300ms;
    --impersonation-banner-height: 0px;
}

/* =====================================================
   Bottom Navigation Bar
   ===================================================== */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: var(--impersonation-banner-height, 0px);
        left: 0;
        right: 0;
        height: var(--mobile-nav-height);
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        background: #ffffff;
        border-top: 1px solid #e5e7eb;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: 1030;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        transition: bottom 0.2s ease;
    }

    /* Glass effect for iOS feel */
    @supports (backdrop-filter: blur(10px)) {
        .mobile-bottom-nav {
            background: rgba(255, 255, 255, 0.92);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
        }
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 8px 4px;
        color: #6b7280;
        text-decoration: none;
        font-size: 10px;
        font-weight: 500;
        background: none;
        border: none;
        cursor: pointer;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        min-height: 48px;
    }

    .mobile-nav-item:hover,
    .mobile-nav-item:focus {
        color: #3B82F6;
        text-decoration: none;
    }

    .mobile-nav-item.active {
        color: #3B82F6;
    }

    .mobile-nav-icon {
        width: 24px;
        height: 24px;
        margin-bottom: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-nav-icon svg {
        width: 24px;
        height: 24px;
        stroke-width: 1.75;
    }

    .mobile-nav-label {
        font-size: 10px;
        line-height: 1;
        letter-spacing: 0.01em;
    }

    /* Active indicator dot */
    .mobile-nav-item.active .mobile-nav-icon {
        position: relative;
    }

    .mobile-nav-item.active .mobile-nav-icon::after {
        content: '';
        position: absolute;
        bottom: -6px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        background: #3B82F6;
        border-radius: 50%;
    }
}

/* =====================================================
   Side Drawer (replaces top dropdown)
   ===================================================== */
@media (max-width: 767.98px) {
    /* Transform sidebar to slide-from-left drawer */
    .navbar.navbar-vertical {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: var(--mobile-drawer-width) !important;
        height: 100vh !important;
        height: 100dvh !important;
        transform: translateX(-100%);
        transition: transform var(--mobile-transition-duration) var(--mobile-transition-timing);
        z-index: 1040 !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .navbar.navbar-vertical.mobile-drawer-open {
        transform: translateX(0);
    }

    /* Override Bootstrap collapse - always show content in drawer */
    .navbar.navbar-vertical .navbar-collapse {
        display: flex !important;
        flex-direction: column;
        height: auto;
        visibility: visible !important;
    }

    .navbar.navbar-vertical .navbar-collapse.collapse:not(.show) {
        display: flex !important;
    }

    /* Drawer backdrop */
    .mobile-drawer-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--mobile-transition-duration) ease,
                    visibility 0s var(--mobile-transition-duration);
        z-index: 1035;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-drawer-backdrop.active {
        opacity: 1;
        visibility: visible;
        transition: opacity var(--mobile-transition-duration) ease,
                    visibility 0s 0s;
    }

    /* Hide hamburger - using bottom nav instead */
    .navbar-toggler {
        display: none !important;
    }

    /* Drawer nav items - larger touch targets */
    .navbar-vertical .nav-link {
        padding: 14px 16px !important;
        min-height: 52px;
        display: flex;
        align-items: center;
    }

    .navbar-vertical .nav-link-icon {
        margin-right: 12px;
    }

    .navbar-vertical .nav-link-title {
        font-size: 15px;
    }

    /* Drawer header - brand area */
    .navbar-vertical .navbar-brand {
        padding: 20px 16px;
        margin: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* =====================================================
       Enhanced Drawer Menu Styling
       ===================================================== */

    /* Remove all container padding - apply to items instead */
    .navbar-vertical .container-fluid,
    .navbar-vertical > .container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Nav items container */
    .navbar-vertical .navbar-nav {
        padding: 8px 0 !important;
        margin: 0 !important;
    }

    /* Enhanced nav link styling - all padding on the link itself */
    .navbar-vertical .nav-link,
    .navbar-vertical .navbar-nav .nav-link {
        margin: 2px 8px 2px 0 !important;
        padding: 12px 12px 12px 16px !important;
        border-radius: 8px;
        transition: all 0.2s ease;
        border-left: 3px solid transparent;
    }

    /* Hover state */
    .navbar-vertical .nav-link:hover:not(.active) {
        background: rgba(255, 255, 255, 0.08);
    }

    /* Active item with pill background */
    .navbar-vertical .nav-link.active {
        background: rgba(59, 130, 246, 0.18) !important;
        border-left-color: #3B82F6;
        color: #60a5fa !important;
    }

    .navbar-vertical .nav-link.active .nav-link-icon {
        color: #60a5fa;
    }

    /* Tap feedback */
    .navbar-vertical .nav-link:active {
        transform: scale(0.98);
        background: rgba(255, 255, 255, 0.12);
    }

    /* Larger icons */
    .navbar-vertical .nav-link-icon svg {
        width: 22px;
        height: 22px;
    }

    /* Section divider */
    .nav-section-divider {
        height: 1px;
        background: rgba(255, 255, 255, 0.08);
        margin: 8px 20px;
        list-style: none;
    }

    /* Staggered animation for menu items */
    @keyframes drawerItemFadeIn {
        from {
            opacity: 0;
            transform: translateX(-12px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    .navbar.navbar-vertical.mobile-drawer-open .nav-item {
        animation: drawerItemFadeIn 0.25s ease forwards;
    }

    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(1) { animation-delay: 0.02s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(2) { animation-delay: 0.04s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(3) { animation-delay: 0.06s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(4) { animation-delay: 0.08s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(5) { animation-delay: 0.10s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(6) { animation-delay: 0.12s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(7) { animation-delay: 0.14s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(8) { animation-delay: 0.16s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(9) { animation-delay: 0.18s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(10) { animation-delay: 0.20s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(11) { animation-delay: 0.22s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(12) { animation-delay: 0.24s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(13) { animation-delay: 0.26s; }
    .navbar.navbar-vertical.mobile-drawer-open .nav-item:nth-child(14) { animation-delay: 0.28s; }

    /* Initial state for animation (hidden until drawer opens) */
    .navbar.navbar-vertical:not(.mobile-drawer-open) .nav-item {
        opacity: 0;
    }

    /* Warning/danger text colors override for active state */
    .navbar-vertical .nav-link.text-warning:hover {
        background: rgba(251, 191, 36, 0.15);
    }

    .navbar-vertical .nav-link.text-danger:hover {
        background: rgba(239, 68, 68, 0.15);
    }
}

/* =====================================================
   Mobile Menu Bottom Sheet
   ===================================================== */
.mobile-menu-sheet {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-menu-sheet {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1050;
        pointer-events: none;
        visibility: hidden;
    }

    .mobile-menu-sheet.open {
        pointer-events: auto;
        visibility: visible;
    }

    /* Backdrop */
    .menu-sheet-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-menu-sheet.open .menu-sheet-backdrop {
        opacity: 1;
    }

    /* Content container */
    .menu-sheet-content {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: #1e293b;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s var(--mobile-transition-timing);
        max-height: 85vh;
        max-height: 85dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-menu-sheet.open .menu-sheet-content {
        transform: translateY(0);
    }

    /* Drag handle */
    .menu-sheet-handle {
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        margin: 12px auto 8px;
    }

    /* Navigation container */
    .menu-sheet-nav {
        padding: 8px 0 16px;
    }

    /* Menu items */
    .menu-sheet-item {
        display: flex;
        align-items: center;
        padding: 14px 20px;
        color: rgba(255, 255, 255, 0.85);
        text-decoration: none;
        font-size: 15px;
        font-weight: 500;
        transition: background 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .menu-sheet-item:hover,
    .menu-sheet-item:focus {
        text-decoration: none;
        color: #fff;
        background: rgba(255, 255, 255, 0.08);
    }

    .menu-sheet-item:active {
        background: rgba(255, 255, 255, 0.12);
    }

    .menu-sheet-item .menu-sheet-icon {
        width: 22px;
        height: 22px;
        margin-right: 14px;
        opacity: 0.7;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .menu-sheet-item .menu-sheet-icon svg {
        width: 22px;
        height: 22px;
    }

    .menu-sheet-item.active {
        color: #60a5fa;
        background: rgba(59, 130, 246, 0.15);
    }

    .menu-sheet-item.active .menu-sheet-icon {
        opacity: 1;
        color: #60a5fa;
    }

    /* Divider */
    .menu-sheet-divider {
        height: 1px;
        background: rgba(255, 255, 255, 0.1);
        margin: 8px 20px;
    }

    /* Danger item (Sign Out) */
    .menu-sheet-item.text-danger {
        color: #f87171;
    }

    .menu-sheet-item.text-danger:hover {
        background: rgba(239, 68, 68, 0.15);
    }

    /* Warning item (Submit Bug) */
    .menu-sheet-item.text-warning {
        color: #fbbf24;
    }

    .menu-sheet-item.text-warning:hover {
        background: rgba(251, 191, 36, 0.15);
    }

    /* Staggered animation for items */
    @keyframes sheetItemSlideIn {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .mobile-menu-sheet.open .menu-sheet-item {
        animation: sheetItemSlideIn 0.25s ease forwards;
    }

    .mobile-menu-sheet.open .menu-sheet-item:nth-child(1) { animation-delay: 0.02s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(2) { animation-delay: 0.04s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(3) { animation-delay: 0.06s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(4) { animation-delay: 0.08s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(5) { animation-delay: 0.10s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(6) { animation-delay: 0.12s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(7) { animation-delay: 0.14s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(8) { animation-delay: 0.16s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(9) { animation-delay: 0.18s; }
    .mobile-menu-sheet.open .menu-sheet-item:nth-child(10) { animation-delay: 0.20s; }

    /* Initial state (hidden until sheet opens) */
    .mobile-menu-sheet:not(.open) .menu-sheet-item {
        opacity: 0;
    }

    /* Prevent body scroll when sheet is open */
    body.menu-sheet-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* =====================================================
   Bottom Sheet Modals
   ===================================================== */
@media (max-width: 767.98px) {
    /* Convert modals to bottom sheets */
    .modal-dialog {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        transform: translateY(100%);
        transition: transform var(--mobile-transition-duration) var(--mobile-transition-timing) !important;
    }

    .modal.show .modal-dialog {
        transform: translateY(0);
    }

    /* Override centered positioning */
    .modal-dialog-centered {
        min-height: auto !important;
        align-items: flex-end !important;
    }

    .modal-content {
        border-radius: 16px 16px 0 0 !important;
        border: none !important;
        max-height: 90vh;
        max-height: 90dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Drag indicator at top */
    .modal-content::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 4px;
        flex-shrink: 0;
    }

    /* Safe area padding at bottom */
    .modal-footer {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Modal body scrollable */
    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Remove Bootstrap fade animation (we use slide) */
    .modal.fade .modal-dialog {
        transform: translateY(100%);
        transition: transform var(--mobile-transition-duration) var(--mobile-transition-timing) !important;
    }

    .modal.fade.show .modal-dialog {
        transform: translateY(0);
    }

    /* Large modals should have constrained height */
    .modal-lg .modal-body,
    .modal-xl .modal-body {
        max-height: calc(90vh - 180px);
        max-height: calc(90dvh - 180px);
    }
}

/* =====================================================
   Content Area Adjustments
   ===================================================== */
@media (max-width: 767.98px) {
    /* Add padding for fixed bottom nav */
    .page-body {
        padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 16px) !important;
    }

    /* Page wrapper fills screen */
    .page-wrapper {
        min-height: 100vh;
        min-height: 100dvh;
    }

    /* Simplify page header */
    .page-header {
        padding: 12px 0 !important;
    }

    .page-pretitle {
        display: none;
    }

    .page-title {
        font-size: 1.25rem !important;
    }

    /* Compact container padding */
    .container-xl {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Hide desktop footer on mobile */
    .footer {
        display: none !important;
    }
}

/* =====================================================
   Touch-Optimized Controls
   ===================================================== */
@media (max-width: 767.98px) {
    /* Buttons - larger touch targets */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    /* Form controls - prevent iOS zoom */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="tel"],
    textarea {
        min-height: 44px;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        padding: 10px 12px;
    }

    /* Select arrow adjustment */
    .form-select {
        padding-right: 36px;
    }

    /* Checkboxes and radios */
    .form-check-input {
        width: 20px;
        height: 20px;
    }

    /* Table cells - better spacing */
    .table td,
    .table th {
        padding: 12px 8px;
    }

    /* Cards */
    .card {
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .card-body {
        padding: 16px;
    }

    /* List group items */
    .list-group-item {
        padding: 14px 16px;
    }
}

/* =====================================================
   Mobile-Specific Utilities
   ===================================================== */
@media (max-width: 767.98px) {
    /* Full-width buttons on mobile */
    .btn-mobile-full {
        width: 100%;
    }

    /* Stack button lists vertically */
    .btn-list {
        flex-direction: column;
        gap: 8px;
    }

    .btn-list .btn {
        width: 100%;
    }

    /* Hide elements on mobile */
    .d-mobile-none {
        display: none !important;
    }

    /* Show elements only on mobile */
    .d-mobile-block {
        display: block !important;
    }

    .d-mobile-flex {
        display: flex !important;
    }
}

/* Hide mobile elements on desktop */
@media (min-width: 768px) {
    .d-mobile-block,
    .d-mobile-flex {
        display: none !important;
    }
}

/* =====================================================
   Safe Area Support (notched devices)
   ===================================================== */
@media (max-width: 767.98px) {
    /* Bottom navigation with safe area */
    .mobile-bottom-nav {
        height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    /* Side drawer safe area */
    .navbar.navbar-vertical {
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Ensure body doesn't overflow */
    body {
        overflow-x: hidden;
    }

    /* Prevent body scroll when drawer is open */
    body.drawer-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* =====================================================
   Stat Cards Mobile Layout
   ===================================================== */
@media (max-width: 767.98px) {
    /* 2x2 grid for stat cards ONLY (not col-12 containers) */
    .row-deck > [class*="col-sm-6"],
    .row-deck > [class*="col-lg-3"] {
        flex: 0 0 50%;
        max-width: 50%;
        padding: 6px;
    }

    /* Ensure col-12 remains full width */
    .row-deck > .col-12,
    .row-deck > [class*="col-12"] {
        flex: 0 0 100%;
        max-width: 100%;
        padding: 12px;
    }

    .row-deck {
        margin: 0 -6px;
    }

    /* Compact stat cards */
    .row-deck .card .h1 {
        font-size: 1.25rem;
    }

    .row-deck .card .subheader {
        font-size: 11px;
    }
}

/* =====================================================
   Pull-to-Refresh Indicator (future enhancement)
   ===================================================== */
@media (max-width: 767.98px) {
    .pull-refresh-indicator {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%) translateY(-100%);
        background: white;
        padding: 12px 20px;
        border-radius: 0 0 12px 12px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        z-index: 1025;
        transition: transform 0.3s ease;
    }

    .pull-refresh-indicator.visible {
        transform: translateX(-50%) translateY(0);
    }
}

/* =====================================================
   Theme-Aware Mobile Styles
   ===================================================== */
@media (max-width: 767.98px) {
    /* Dark theme adjustments */
    [data-theme="luxury-estate"] .mobile-bottom-nav,
    [data-theme="commission"] .mobile-bottom-nav {
        background: rgba(26, 26, 26, 0.95);
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    [data-theme="luxury-estate"] .mobile-nav-item,
    [data-theme="commission"] .mobile-nav-item {
        color: rgba(255, 255, 255, 0.6);
    }

    [data-theme="luxury-estate"] .mobile-nav-item.active,
    [data-theme="commission"] .mobile-nav-item.active {
        color: #D4AF37;
    }

    [data-theme="luxury-estate"] .mobile-nav-item.active .mobile-nav-icon::after {
        background: #D4AF37;
    }
}

/* =====================================================
   Data Cards (Expenses, Mileage, etc.) - Base Styles
   ===================================================== */

/* Base card container - works on all screen sizes */
.mobile-cards-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Base card styles - all screen sizes */
.mobile-data-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
}

.mobile-data-card .card-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.mobile-data-card .card-row:last-child {
    margin-bottom: 0;
}

.mobile-data-card .card-title {
    font-weight: 600;
    font-size: 15px;
    color: #1f2937;
    margin: 0;
    flex: 1;
    padding-right: 12px;
}

.mobile-data-card .card-amount {
    font-weight: 700;
    font-size: 18px;
    color: #3B82F6;
    white-space: nowrap;
}

.mobile-data-card .card-amount.negative {
    color: #ef4444;
}

.mobile-data-card .card-amount.positive {
    color: #10b981;
}

.mobile-data-card .card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 13px;
    color: #6b7280;
}

.mobile-data-card .card-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mobile-data-card .card-meta-item svg {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

.mobile-data-card .card-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.mobile-data-card .card-badge.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.mobile-data-card .card-badge.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.mobile-data-card .card-badge.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.mobile-data-card .card-badge.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.mobile-data-card .card-map-container {
    margin: -16px -16px 12px -16px;
    border-radius: 11px 11px 0 0;
    overflow: hidden;
    height: 150px;
    background: #f3f4f6;
}

.mobile-data-card .card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

.mobile-data-card .card-actions .btn {
    flex: 1;
    font-size: 13px;
}

/* Receipt thumbnail in expense cards */
.expense-receipt-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    flex-shrink: 0;
    margin-left: 12px;
    transition: border-color 0.2s, transform 0.2s;
}

.expense-receipt-thumb:hover {
    border-color: #3B82F6;
    transform: scale(1.05);
}

.expense-receipt-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.expense-receipt-thumb .icon {
    color: #9ca3af;
}

/* =====================================================
   Mobile Data Cards - Mobile-specific overrides
   ===================================================== */
@media (max-width: 767.98px) {
    /* Mobile data card container */
    .mobile-cards-container {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Individual data card */
    .mobile-data-card {
        background: white;
        border-radius: 12px;
        padding: 16px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
        border: 1px solid #e5e7eb;
    }

    .mobile-data-card .card-row {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
    }

    .mobile-data-card .card-row:last-child {
        margin-bottom: 0;
    }

    .mobile-data-card .card-title {
        font-weight: 600;
        font-size: 15px;
        color: #1f2937;
        margin: 0;
        flex: 1;
        padding-right: 12px;
    }

    .mobile-data-card .card-amount {
        font-weight: 700;
        font-size: 18px;
        color: #3B82F6;
        white-space: nowrap;
    }

    .mobile-data-card .card-amount.negative {
        color: #ef4444;
    }

    .mobile-data-card .card-amount.positive {
        color: #10b981;
    }

    .mobile-data-card .card-meta {
        color: #6b7280;
        font-size: 13px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .mobile-data-card .card-route {
        color: #6b7280;
        font-size: 12px;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid #f3f4f6;
        display: flex;
        align-items: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-data-card .card-route svg {
        flex-shrink: 0;
        opacity: 0.6;
    }

    .mobile-data-card .card-meta-item {
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    .mobile-data-card .card-meta-item svg {
        width: 14px;
        height: 14px;
        opacity: 0.6;
    }

    .mobile-data-card .card-badge {
        display: inline-flex;
        align-items: center;
        padding: 2px 8px;
        font-size: 11px;
        font-weight: 500;
        border-radius: 4px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .mobile-data-card .card-badge.badge-success {
        background: rgba(16, 185, 129, 0.1);
        color: #10b981;
    }

    .mobile-data-card .card-badge.badge-warning {
        background: rgba(245, 158, 11, 0.1);
        color: #f59e0b;
    }

    .mobile-data-card .card-badge.badge-info {
        background: rgba(59, 130, 246, 0.1);
        color: #3B82F6;
    }

    .mobile-data-card .card-badge.badge-danger {
        background: rgba(239, 68, 68, 0.1);
        color: #ef4444;
    }

    .mobile-data-card .card-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #e5e7eb;
    }

    .mobile-data-card .card-actions .btn {
        flex: 1;
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    /* View toggle on mobile */
    .mobile-view-toggle {
        display: flex;
        gap: 0;
        margin-bottom: 16px;
    }

    .mobile-view-toggle .btn {
        flex: 1;
        border-radius: 0;
    }

    .mobile-view-toggle .btn:first-child {
        border-radius: 8px 0 0 8px;
    }

    .mobile-view-toggle .btn:last-child {
        border-radius: 0 8px 8px 0;
    }

    /* Hide table on mobile when cards are shown */
    .mobile-hide-table {
        display: none !important;
    }

    /* Show cards only on mobile */
    .mobile-show-cards {
        display: flex !important;
    }
}

/* Hide mobile-only elements on desktop (but NOT cards container - it's toggled by JS) */
@media (min-width: 768px) {
    .mobile-view-toggle,
    .d-md-none-cards {
        display: none !important;
    }
}

/* =====================================================
   Collapsible Mobile Filters
   ===================================================== */
@media (max-width: 767.98px) {
    /* Filter toggle button */
    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 12px 16px;
        background: #f9fafb;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        margin-bottom: 12px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-filter-toggle:active {
        background: #f3f4f6;
    }

    .mobile-filter-toggle .filter-label {
        font-weight: 500;
        font-size: 14px;
        color: #374151;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-filter-toggle .filter-count {
        background: #3B82F6;
        color: white;
        font-size: 11px;
        font-weight: 600;
        padding: 2px 6px;
        border-radius: 10px;
        min-width: 18px;
        text-align: center;
    }

    .mobile-filter-toggle .filter-count.empty {
        background: #d1d5db;
        color: #6b7280;
    }

    .mobile-filter-toggle .filter-chevron {
        width: 20px;
        height: 20px;
        color: #9ca3af;
        transition: transform 0.2s ease;
    }

    .mobile-filter-toggle.open .filter-chevron {
        transform: rotate(180deg);
    }

    /* Filter panel */
    .mobile-filter-panel,
    .mobile-filters {
        display: none;
        padding: 16px;
        background: #f9fafb;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        margin-bottom: 16px;
    }

    .mobile-filter-panel.show,
    .mobile-filters.show {
        display: block;
    }

    .mobile-filter-panel .form-group {
        margin-bottom: 12px;
    }

    .mobile-filter-panel .form-group:last-child {
        margin-bottom: 0;
    }

    .mobile-filter-panel .form-label {
        font-size: 12px;
        font-weight: 500;
        color: #6b7280;
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .mobile-filter-panel .form-control,
    .mobile-filter-panel .form-select {
        width: 100%;
    }

    .mobile-filter-panel .filter-actions {
        display: flex;
        gap: 8px;
        margin-top: 16px;
        padding-top: 12px;
        border-top: 1px solid #e5e7eb;
    }

    .mobile-filter-panel .filter-actions .btn {
        flex: 1;
    }

    /* Desktop filters hidden on mobile */
    .desktop-filters {
        display: none !important;
    }
}

/* Show desktop filters on larger screens */
@media (min-width: 768px) {
    .mobile-filter-toggle,
    .mobile-filter-panel {
        display: none !important;
    }

    .desktop-filters {
        display: flex !important;
    }
}

/* =====================================================
   Mobile Chart Optimization
   ===================================================== */
@media (max-width: 767.98px) {
    /* Responsive chart containers */
    .chart-container {
        height: 200px !important;
        min-height: 180px;
        max-height: 250px;
    }

    /* Dashboard charts - reduce height + allow vertical scroll through */
    #chart-mileage,
    #chart-expenses {
        height: 200px !important;
        touch-action: pan-y;
    }

    #chart-categories {
        height: 160px !important;
        touch-action: pan-y;
    }

    /* ApexCharts specific adjustments - allow scroll through */
    .apexcharts-canvas {
        width: 100% !important;
        touch-action: pan-y;
    }

    .apexcharts-inner,
    .apexcharts-graphical {
        touch-action: pan-y;
    }

    .apexcharts-legend {
        padding: 8px 0 0 0 !important;
    }

    .apexcharts-legend-text {
        font-size: 11px !important;
    }

    /* Horizontal legend on mobile */
    .apexcharts-legend.apx-legend-position-bottom {
        justify-content: center !important;
        flex-wrap: wrap !important;
    }

    /* Dashboard Stats Cards - 2x2 Grid */
    .page-body .row-deck.row-cards {
        margin-left: -4px;
        margin-right: -4px;
    }

    .page-body .row-deck.row-cards > [class*="col-"] {
        padding-left: 4px;
        padding-right: 4px;
        margin-bottom: 8px;
    }

    /* Stats cards - compact on mobile */
    .page-body .row-deck.row-cards .card .card-body {
        padding: 12px;
    }

    .page-body .row-deck.row-cards .card .h1 {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }

    .page-body .row-deck.row-cards .card .subheader {
        font-size: 11px;
    }

    .page-body .row-deck.row-cards .card .progress-sm {
        height: 3px;
    }

    /* Welcome banner - compact */
    #welcome-banner .card-body {
        padding: 16px;
    }

    #welcome-banner .h1 {
        font-size: 1.25rem;
    }

    #welcome-banner .btn-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    #welcome-banner .btn-list .btn {
        width: 100%;
    }

    /* Email forward card - compact */
    #email-forward-card .card-body {
        padding: 12px;
    }

    #email-forward-card code {
        font-size: 11px;
        word-break: break-all;
    }

    /* Quick Actions - full width on mobile */
    .col-6.col-md-3 .btn.py-3 {
        padding-top: 12px !important;
        padding-bottom: 12px !important;
        font-size: 12px;
    }

    .col-6.col-md-3 .btn.py-3 .icon-lg {
        width: 20px;
        height: 20px;
    }

    /* Insights cards - stack on mobile */
    #insights-container .card-sm .card-body {
        padding: 12px;
    }

    #insights-container .avatar {
        width: 32px;
        height: 32px;
    }

    #insights-container .font-weight-medium {
        font-size: 13px;
    }

    #insights-container .text-secondary.small {
        font-size: 11px;
    }

    /* Recent Trips Table - compact */
    #recent-trips-table td {
        padding: 8px 6px;
        font-size: 12px;
    }

    /* Activity Feed - compact */
    #activity-feed .list-group-item {
        padding: 10px 12px;
    }

    /* Upcoming events - compact */
    #upcoming-events .list-group-item {
        padding: 10px 12px;
    }
}

/* =====================================================
   Mobile Table Improvements
   ===================================================== */
@media (max-width: 767.98px) {
    /* Make table horizontally scrollable with visual hint */
    .table-responsive {
        position: relative;
    }

    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .table-responsive.has-scroll::after {
        opacity: 1;
    }

    /* Compact table cells */
    .table-mobile-compact td,
    .table-mobile-compact th {
        padding: 8px 6px;
        font-size: 13px;
    }

    /* Truncate long text */
    .table-mobile-compact .text-truncate-mobile {
        max-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* =====================================================
   Pull-to-Refresh Indicator
   ===================================================== */
.pull-to-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.pull-to-refresh-indicator .pull-spinner {
    width: 24px;
    height: 24px;
    color: #6b7280;
    transition: transform 0.2s ease;
}

.pull-to-refresh-indicator .pull-spinner svg {
    width: 100%;
    height: 100%;
}

.pull-to-refresh-indicator .pull-text {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

.pull-to-refresh-indicator.ready .pull-spinner {
    color: #3B82F6;
    transform: rotate(180deg);
}

.pull-to-refresh-indicator.ready .pull-text {
    color: #3B82F6;
}

.pull-to-refresh-indicator.refreshing .pull-spinner {
    color: #3B82F6;
    animation: spin 1s linear infinite;
}

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

/* Hide on desktop */
@media (min-width: 768px) {
    .pull-to-refresh-indicator {
        display: none !important;
    }
}

/* =====================================================
   Admin Impersonation Banner (Mobile)
   ===================================================== */
@media (max-width: 767.98px) {
    #impersonation-banner {
        padding: 8px 12px !important;
        font-size: 12px;
    }

    #impersonation-banner .container-xl {
        padding: 0;
    }

    #impersonation-banner .d-flex {
        flex-wrap: wrap;
        gap: 6px;
    }

    #impersonation-banner .d-flex > .d-flex:first-child {
        flex: 1;
        min-width: 0;
    }

    #impersonation-banner strong.me-2 {
        display: none;
    }

    #impersonation-banner .icon.me-2 {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    #impersonation-banner span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #impersonation-banner .btn {
        padding: 4px 10px;
        font-size: 11px;
        white-space: nowrap;
    }

    #impersonation-banner .btn .icon {
        display: none;
    }
}
