/* =================================== */
/* MOBILE OPTIMIZATIONS CSS */
/* =================================== */

/* Import this file after main.css for mobile-specific enhancements */

/* =================================== */
/* MOBILE NAVIGATION ENHANCEMENTS */
/* =================================== */

/* Mobile-first navigation */
@media (max-width: 768px) {
    .navbar {
        padding: 0.5rem 0;
    }
    
    .navbar-brand {
        font-size: 1.1rem;
        max-width: 60%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .navbar-toggler {
        border: none;
        padding: 0.25rem 0.5rem;
        min-height: 44px;
        min-width: 44px;
    }
    
    .navbar-collapse {
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border-radius: 12px;
        margin-top: 0.5rem;
        padding: 1rem;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    }
    
    .navbar-nav {
        gap: 0.5rem;
    }
    
    .navbar-nav .nav-link {
        border-radius: 8px;
        padding: 0.75rem 1rem;
        transition: all 0.2s ease;
    }
    
    .navbar-nav .nav-link:hover {
        background: rgba(0, 123, 255, 0.1);
        transform: translateY(-1px);
    }
}

/* =================================== */
/* MOBILE TEXT OVERFLOW SAFEGUARDS     */
/* =================================== */
@media (max-width: 576px) {
    /* Contain long words/URLs without altering desktop styles */
    .content-area,
    .card-body,
    .modal-body,
    .page-header p,
    .list-group-item,
    .alert,
    .guide-card,
    .profile-card,
    .subscription-card {
        overflow-wrap: anywhere;
        word-break: break-word;
        hyphens: auto;
    }

    /* Prevent layout shift from long headings */
    h1, h2, h3, h4 {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Keep code blocks readable without breaking layout */
    pre, code {
        white-space: pre-wrap;
        overflow-x: auto;
        word-break: normal;
    }

    /* Optional utility: apply on elements with excessive content */
    .no-overflow-mobile {
        overflow-x: hidden !important;
    }

    /* Optional utility: wrap text more aggressively where needed */
    .wrap-anywhere-mobile {
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        hyphens: auto !important;
    }
}

/* =================================== */
/* MOBILE FORM ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
    }
    
    .form-control, .form-select {
        border-radius: 8px;
        border: 2px solid #e9ecef;
        padding: 0.75rem;
        font-size: 16px;
        transition: all 0.2s ease;
    }
    
    .form-control:focus, .form-select:focus {
        border-color: #007bff;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
        transform: translateY(-1px);
    }
    
    .input-group {
        border-radius: 8px;
        overflow: hidden;
    }
    
    .input-group-text {
        background: #f8f9fa;
        border: 2px solid #e9ecef;
        border-right: none;
        padding: 0.75rem;
        min-height: 44px;
    }
    
    .input-group .form-control {
        border-left: none;
    }
    
    /* Enhanced checkbox and radio */
    .form-check {
        margin-bottom: 1rem;
        padding-left: 2rem;
    }
    
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-left: -2rem;
        margin-top: 0.125rem;
    }
    
    .form-check-label {
        padding-left: 0.5rem;
        line-height: 1.4;
    }
}

/* =================================== */
/* MOBILE TABLE ENHANCEMENTS */
/* =================================== */

@media (max-width: 768px) {
    .table-responsive {
        border: 1px solid #dee2e6;
        border-radius: 12px;
        overflow: hidden;
        margin-bottom: 1.5rem;
    }
    
    .table {
        margin-bottom: 0;
        font-size: 0.875rem;
    }
    
    .table th {
        background: #f8f9fa;
        border-bottom: 2px solid #dee2e6;
        font-weight: 600;
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
    
    .table td {
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid #dee2e6;
        vertical-align: middle;
    }
    
    .table tbody tr:hover {
        background: rgba(0, 123, 255, 0.05);
    }
    
    /* Stack table on very small screens */
    @media (max-width: 480px) {
        .table-responsive {
            overflow: visible;
        }
        
        .table, .table thead, .table tbody, .table th, .table td, .table tr {
            display: block;
        }
        
        .table thead tr {
            position: absolute;
            top: -9999px;
            left: -9999px;
        }
        
        .table tr {
            border: 1px solid #dee2e6;
            border-radius: 8px;
            margin-bottom: 1rem;
            padding: 0.5rem;
            background: #fff;
        }
        
        .table td {
            border: none;
            border-bottom: 1px solid #eee;
            position: relative;
            padding-left: 50%;
            text-align: left;
        }
        
        .table td:before {
            content: attr(data-label);
            position: absolute;
            left: 0.5rem;
            width: 45%;
            padding-right: 0.5rem;
            white-space: nowrap;
            font-weight: 600;
            color: #495057;
        }
        
        .table td:last-child {
            border-bottom: none;
        }
    }
}

/* =================================== */
/* MOBILE CARD ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .card {
        /* Simplified mobile card styling */
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2) !important;
        margin-bottom: 1rem !important;
        overflow: hidden;
        /* Remove complex glassmorphism on mobile for better performance */
        background: rgba(40, 40, 46, 0.8) !important;
        backdrop-filter: blur(8px) !important;
        -webkit-backdrop-filter: blur(8px) !important;
    }
    
    .card-header {
        /* Simplified header styling */
        background: rgba(40, 40, 46, 0.9) !important;
        color: #d1d5db !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        padding: 1rem !important;
        font-weight: 600;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-footer {
        background: rgba(40, 40, 46, 0.7) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        padding: 1rem !important;
    }
    
    /* Simplified mobile interactions */
    .card {
        transition: all 0.2s ease;
    }
    
    .card:hover {
        /* Remove hover effects on mobile for better performance */
        transform: none;
    }
    
    .card:active {
        transform: scale(0.98);
    }
}

/* =================================== */
/* MOBILE BUTTON ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .btn {
        /* Simplified mobile button styling */
        border-radius: 8px !important;
        font-weight: 600 !important;
        transition: all 0.2s ease !important;
        min-height: 44px !important; /* Better touch targets */
        padding: 0.75rem 1rem !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Remove complex hover effects on mobile */
    .btn:hover {
        transform: none !important;
        box-shadow: none !important;
    }
    
    .btn-primary {
        background: #007bff !important;
        color: white !important;
        border-color: #007bff !important;
    }
    
    .btn-primary:hover {
        background: #0056b3 !important;
        border-color: #0056b3 !important;
    }
    
    .btn-secondary {
        background: #6c757d !important;
        color: white !important;
        border-color: #6c757d !important;
    }
    
    .btn-success {
        background: #28a745 !important;
        color: white !important;
        border-color: #28a745 !important;
    }
    
    .btn-danger {
        background: #dc3545 !important;
        color: white !important;
        border-color: #dc3545 !important;
    }
    
    /* Simplified button group styling */
    .btn-group {
        border-radius: 8px !important;
        overflow: hidden;
    }
    
    .btn-group .btn {
        border-radius: 0 !important;
        border: none !important;
    }
    
    .btn-group .btn:first-child {
        border-top-left-radius: 8px !important;
        border-bottom-left-radius: 8px !important;
    }
    
    .btn-group .btn:last-child {
        border-top-right-radius: 8px !important;
        border-bottom-right-radius: 8px !important;
    }
}

/* =================================== */
/* MOBILE MODAL ENHANCEMENTS */
/* =================================== */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
        max-height: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 16px;
        border: none;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }
    
    .modal-header {
        border-bottom: 1px solid #e9ecef;
        padding: 1.5rem 1.5rem 1rem;
        border-radius: 16px 16px 0 0;
    }
    
    .modal-title {
        font-weight: 600;
        font-size: 1.25rem;
    }
    
    .modal-body {
        padding: 1.5rem;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        border-top: 1px solid #e9ecef;
        padding: 1rem 1.5rem 1.5rem;
        border-radius: 0 0 16px 16px;
    }
    
    .modal .btn-close {
        background: none;
        border: none;
        font-size: 1.5rem;
        padding: 0;
        width: 2rem;
        height: 2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: all 0.2s ease;
    }
    
    .modal .btn-close:hover {
        background: rgba(0, 0, 0, 0.1);
    }
}

/* =================================== */
/* MOBILE DROPDOWN ENHANCEMENTS */
/* =================================== */

@media (max-width: 768px) {
    .dropdown-menu {
        /* Remove problematic positioning overrides */
        /* position: fixed !important; */
        /* top: auto !important; */
        /* left: 1rem !important; */
        /* right: 1rem !important; */
        /* width: auto !important; */
        /* transform: none !important; */
        
        /* Keep styling improvements without breaking positioning */
        border-radius: 14px !important;
        border: 1px solid rgba(255,255,255,0.18) !important;
        box-shadow: 0 12px 30px rgba(0,0,0,0.22) !important;
        background: rgba(255, 255, 255, 0.10) !important;
        backdrop-filter: blur(14px) !important;
        -webkit-backdrop-filter: blur(14px) !important;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 6px !important;
        min-width: 260px !important;
        margin-top: 8px !important;
        
        /* Ensure proper positioning on mobile */
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        right: auto !important;
        width: auto !important;
        z-index: 2100 !important;
        
        /* Special handling for right-aligned dropdowns */
    }
    
    .dropdown-menu.dropdown-menu-end {
        left: auto !important;
        right: 0 !important;
    }
    
    .dropdown-item {
        padding: 10px 12px !important;
        border-radius: 8px !important;
        margin: 0.25rem 0.5rem;
        transition: all 0.2s ease;
        color: #e5e7eb !important;
        /* Ensure proper text positioning */
        display: block !important;
        text-align: left !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .dropdown-item:hover {
        background: rgba(255,255,255,0.12) !important;
        color: #f8fafc !important;
        transform: translateX(4px);
    }
    
    .dropdown-item:hover i {
        color: #e2e8f0 !important;
    }
    
    /* Handle dropdown items with icons */
    .dropdown-item i {
        margin-right: 8px !important;
        width: 16px !important;
        text-align: center !important;
        display: inline-block !important;
    }
    
    .dropdown-item.text-danger {
        color: #b91c1c !important;
    }
    
    .dropdown-item.text-danger:hover {
        background: rgba(185,28,28,0.08) !important;
        color: #7f1d1d !important;
    }
    
    .dropdown-divider {
        margin: 0.5rem 1rem;
        border-color: rgba(0,0,0,0.08) !important;
    }
    
    .dropdown-header {
        color: #6b7280 !important;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        padding: 8px 10px !important;
    }
}

/* =================================== */
/* MOBILE ALERT ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .alert {
        border: none;
        border-radius: 12px;
        padding: 1rem 1.25rem;
        margin-bottom: 1rem;
        font-weight: 500;
        position: relative;
        overflow: hidden;
    }
    
    .alert::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 100%;
        background: currentColor;
        opacity: 0.3;
    }
    
    .alert-success {
        background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
        color: #155724;
    }
    
    .alert-info {
        background: linear-gradient(135deg, #d1ecf1 0%, #bee5eb 100%);
        color: #0c5460;
    }
    
    .alert-warning {
        background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
        color: #856404;
    }
    
    .alert-danger {
        background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
        color: #721c24;
    }
    
    .alert-dismissible .btn-close {
        padding: 0;
        width: 1.5rem;
        height: 1.5rem;
        background: none;
        border: none;
        font-size: 1.25rem;
        opacity: 0.7;
        transition: opacity 0.2s ease;
    }
    
    .alert-dismissible .btn-close:hover {
        opacity: 1;
    }
}

/* =================================== */
/* MOBILE BADGE ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .badge {
        border-radius: 999px;
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.025em;
    }
    
    .badge-primary {
        background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    }
    
    .badge-success {
        background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    }
    
    .badge-warning {
        background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
        color: #212529;
    }
    
    .badge-danger {
        background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    }
    
    .badge-info {
        background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
    }
}

/* =================================== */
/* MOBILE PROGRESS ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    .progress {
        height: 0.75rem;
        border-radius: 999px;
        background: #e9ecef;
        overflow: hidden;
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .progress-bar {
        border-radius: 999px;
        background: linear-gradient(90deg, #007bff 0%, #0056b3 100%);
        transition: width 0.6s ease;
        position: relative;
        overflow: hidden;
    }
    
    .progress-bar::after {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
        animation: shimmer 2s infinite;
    }
    
    @keyframes shimmer {
        0% { left: -100%; }
        100% { left: 100%; }
    }
}

/* =================================== */
/* MOBILE UTILITY ENHANCEMENTS */
/* =================================== */

@media (max-width: 576px) {
    /* Enhanced spacing utilities */
    .m-0 { margin: 0 !important; }
    .mt-0 { margin-top: 0 !important; }
    .mb-0 { margin-bottom: 0 !important; }
    .ml-0 { margin-left: 0 !important; }
    .mr-0 { margin-right: 0 !important; }
    
    .p-0 { padding: 0 !important; }
    .pt-0 { padding-top: 0 !important; }
    .pb-0 { padding-bottom: 0 !important; }
    .pl-0 { padding-left: 0 !important; }
    .pr-0 { padding-right: 0 !important; }
    
    /* Enhanced text utilities */
    .text-center { text-align: center !important; }
    .text-left { text-align: left !important; }
    .text-right { text-align: right !important; }
    
    .text-truncate {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Enhanced display utilities */
    .d-none { display: none !important; }
    .d-block { display: block !important; }
    .d-flex { display: flex !important; }
    .d-inline { display: inline !important; }
    .d-inline-block { display: inline-block !important; }
    
    /* Enhanced flex utilities */
    .flex-column { flex-direction: column !important; }
    .flex-row { flex-direction: row !important; }
    .justify-content-center { justify-content: center !important; }
    .justify-content-between { justify-content: space-between !important; }
    .align-items-center { align-items: center !important; }
    .align-items-start { align-items: flex-start !important; }
    .align-items-end { align-items: flex-end !important; }
    
    /* Mobile-specific layout fixes */
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .row {
        margin-left: -0.5rem !important;
        margin-right: -0.5rem !important;
    }
    
    .col, .col-1, .col-2, .col-3, .col-4, .col-5, .col-6, 
    .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Fix mobile spacing issues */
    .mt-4 { margin-top: 1rem !important; }
    .mb-4 { margin-bottom: 1rem !important; }
    .py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
    .px-4 { padding-left: 1rem !important; padding-right: 1rem !important; }
    
    /* Ensure proper mobile text sizing */
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.25rem !important; }
    h4 { font-size: 1.125rem !important; }
    h5 { font-size: 1rem !important; }
    h6 { font-size: 0.875rem !important; }
    
    /* Mobile table improvements */
    .table-responsive {
        border-radius: 8px !important;
        overflow: hidden !important;
    }
    
    /* Mobile form improvements */
    .form-control, .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px !important; /* Better touch targets */
    }
}

/* =================================== */
/* MOBILE ANIMATION ENHANCEMENTS */
/* =================================== */

@media (max-width: 768px) {
    /* Simplified animations for mobile performance */
    .fade-in {
        animation: fadeIn 0.3s ease-in;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    /* Remove complex animations on mobile for better performance */
    .slide-in-left, .slide-in-right, .bounce {
        animation: none !important;
        transform: none !important;
    }
    
    /* Mobile-specific performance optimizations */
    * {
        /* Reduce motion for better mobile performance */
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Disable hover effects on mobile */
    .btn:hover, .card:hover, .nav-link:hover {
        transform: none !important;
        box-shadow: none !important;
    }
}

/* =================================== */
/* MOBILE ACCESSIBILITY ENHANCEMENTS */
/* =================================== */

@media (max-width: 768px) {
    /* Enhanced focus indicators for mobile - only for interactive elements */
    .btn:focus, .form-control:focus, .form-select:focus, 
    input:focus, select:focus, textarea:focus {
        outline: 3px solid #007bff;
        outline-offset: 2px;
        border-radius: 4px;
    }
    
    /* Remove outline for navigation elements to avoid ugly borders */
    .nav-link:focus, .navbar-brand:focus, .navbar-nav .nav-link:focus {
        outline: none;
    }
    
    /* Preserve nice dropdown styling without focus outlines */
    .dropdown-item:focus {
        outline: none;
        background: rgba(255, 255, 255, 0.12);
        color: #f8fafc;
    }
    
    .dropdown-item:focus i {
        color: #e2e8f0;
    }
    
    /* Enhanced touch targets */
    button, a, input, select, textarea, label {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Enhanced contrast for mobile */
    .text-muted {
        color: #6c757d !important;
        font-weight: 500;
    }
    
    .text-light {
        color: #495057 !important;
        font-weight: 500;
    }
    
    /* Enhanced readability */
    p, li, td, th {
        line-height: 1.6;
        margin-bottom: 0.5rem;
    }
    
    /* Enhanced form labels */
    label {
        font-weight: 600;
        color: #495057;
        margin-bottom: 0.5rem;
    }
    
    /* Enhanced error states */
    .is-invalid {
        border-color: #dc3545 !important;
        box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    }
    
    .invalid-feedback {
        color: #dc3545;
        font-size: 0.875rem;
        font-weight: 500;
        margin-top: 0.25rem;
    }
    
    /* CRITICAL: Mobile-specific glassmorphism overrides */
    .card, .period-selector, .metric-card, .chart-container, .monthly-breakdown, 
    .detailed-breakdown, .income-breakdown, .financial-insights, 
    .financial-summary-section, .report-actions, .profile-reports-section,
    .page-header, .lookback-display, .custom-date-range, .no-data-message,
    .feature-card, .auth-container, .alert, .navbar, .container > .row > .col,
    .main-content, .sidebar, .content-wrapper, .form-container, .settings-card,
    .subscription-card, .profile-card, .calculator-card, .guide-card {
        /* Simplified mobile styling for better performance */
        background: rgba(40, 40, 46, 0.9) !important;
        backdrop-filter: blur(6px) !important;
        -webkit-backdrop-filter: blur(6px) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
    }
    
    /* Mobile-specific text color overrides */
    h1, h2, h3, h4, h5, h6, p, span, div, label, a, li, td, th, strong, small {
        color: #d1d5db !important;
    }
    
    /* Mobile-specific link colors */
    a {
        color: #93c5fd !important;
    }
    
    a:hover {
        color: #bfdbfe !important;
    }
}
