/* ============================================
   CRITICAL MOBILE FIXES - REALKONNECT
   Phase 1: Authentication, Forms, Touch Targets
   VERSION: 1003 - LOADED ✓
   Last Updated: 2026-07-03
   ============================================ */

/* Test marker - if you see red border, CSS is loaded */
@media (max-width: 768px) {
    body::before {
        content: "Mobile Fixes Loaded ✓";
        position: fixed;
        top: 0;
        left: 0;
        background: green;
        color: white;
        padding: 4px 8px;
        font-size: 10px;
        z-index: 99999;
        display: none; /* Change to block to test */
    }
}

/* ========================================
   GLOBAL MOBILE OPTIMIZATIONS
   ======================================== */

/* Prevent iOS zoom on input focus */
input, textarea, select {
    font-size: 16px !important;
}

/* Touch target minimum 44px */
button, 
a.btn, 
.icon-btn,
.action-btn,
.nav-item {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Checkboxes and radio buttons - normal size */
input[type="checkbox"],
input[type="radio"] {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    cursor: pointer;
    margin: 0;
}

/* Better touch feedback */
button:active, 
a.btn:active,
.icon-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

/* Prevent double-tap zoom */
* {
    touch-action: manipulation;
}

/* ========================================
   AUTHENTICATION PAGES - MOBILE FIX
   Login & Register Single Column Layout
   ======================================== */

@media (max-width: 768px) {
    /* Force single column layout */
    .auth-container {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        min-height: 100vh;
        padding: 0 !important;
    }
    
    /* Auth left section - full width */
    .auth-left {
        width: 100% !important;
        max-width: 100% !important;
        padding: 24px 20px !important;
        order: 1;
    }
    
    /* Hide auth right section on mobile */
    .auth-right {
        display: none !important;
    }
    
    /* Auth header adjustments */
    .auth-header {
        text-align: center;
        margin-bottom: 32px;
    }
    
    .auth-logo {
        width: 64px !important;
        height: 64px !important;
        margin: 0 auto 16px !important;
    }
    
    .auth-header h1 {
        font-size: 1.75rem !important;
        margin-bottom: 8px;
    }
    
    .auth-header p {
        font-size: 0.95rem !important;
    }
    
    /* Form inputs - better mobile experience */
    .auth-form .form-group {
        margin-bottom: 20px;
    }
    
    /* CRITICAL FIX: Input with icon - add more left padding for mobile */
    .input-with-icon {
        position: relative !important;
    }
    
    .input-with-icon i:first-child {
        position: absolute !important;
        left: 12px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        font-size: 0.9rem !important;
        color: #9ca3af !important;
        z-index: 1 !important;
        pointer-events: none !important;
    }
    
    .input-with-icon input,
    .input-with-icon select {
        width: 100% !important;
        padding: 12px 30px 12px 30px !important;
        font-size: 16px !important;
        border: 2px solid #e2e8f0 !important;
        border-radius: 10px !important;
        box-sizing: border-box !important;
        text-indent: 0 !important;
    }
    
    .input-with-icon input[type="email"] {
        padding: 12px 30px 12px 30px !important;
    }
    
    .input-with-icon input[type="password"] {
        padding: 12px 30px 12px 30px !important;
    }
    
    .input-with-icon input:focus {
        border-color: #ec4899 !important;
        box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.1) !important;
    }
    
    .input-with-icon .toggle-password {
        position: absolute !important;
        right: 12px !important;
        left: auto !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        font-size: 0.9rem !important;
        color: #9ca3af !important;
        cursor: pointer !important;
        z-index: 2 !important;
        pointer-events: auto !important;
    }
    
    /* Checkbox and radio - proper touch targets */
    .checkbox-option,
    .radio-option {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 8px 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .checkbox-option input[type="checkbox"],
    .radio-option input[type="radio"] {
        width: 16px !important;
        height: 16px !important;
        min-width: 16px;
        min-height: 16px;
        margin-right: 12px;
        cursor: pointer;
    }
    
    /* Terms checkbox - match login page size */
    .terms-checkbox input[type="checkbox"] {
        width: 16px !important;
        height: 16px !important;
        min-width: 16px !important;
        min-height: 16px !important;
    }
    
    /* Buttons - proper sizing */
    .btn {
        min-height: 52px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        border-radius: 12px !important;
        padding: 0 24px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: all 0.2s ease;
    }
    
    .btn-block {
        width: 100% !important;
    }
    
    .btn-primary {
        background: linear-gradient(135deg, #ec4899 0%, #db2777 100%) !important;
        color: white !important;
        border: none !important;
    }
    
    .btn-primary:active {
        transform: scale(0.98);
    }
    
    /* Auth footer */
    .auth-footer {
        text-align: center;
        margin-top: 24px;
        padding-top: 24px;
        border-top: 1px solid #e2e8f0;
    }
    
    .auth-divider {
        margin: 24px 0;
        text-align: center;
        position: relative;
    }
    
    .auth-divider span {
        background: white;
        padding: 0 16px;
        color: #94a3b8;
        font-size: 0.9rem;
    }
}

/* ========================================
   OTP MODAL - MOBILE OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
    /* Modal overlay */
    .modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 20px;
    }
    
    /* Modal container */
    .modal,
    .otp-modal,
    .email-exists-modal {
        width: 100% !important;
        max-width: 400px !important;
        max-height: 90vh;
        background: white;
        border-radius: 20px;
        padding: 32px 24px;
        position: relative;
        overflow-y: auto;
    }
    
    /* OTP input boxes - proper touch targets */
    .otp-inputs {
        display: flex;
        gap: 8px;
        justify-content: center;
        margin: 24px 0;
    }
    
    .otp-input {
        width: 48px !important;
        height: 56px !important;
        font-size: 1.5rem !important;
        text-align: center !important;
        border: 2px solid #e2e8f0 !important;
        border-radius: 12px !important;
        font-weight: 600;
    }
    
    .otp-input:focus {
        border-color: #ec4899 !important;
        box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.1) !important;
        outline: none;
    }
    
    /* Modal close button */
    .modal-close,
    .close-modal {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: #f1f5f9;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 10;
    }
    
    .modal-close:active {
        background: #e2e8f0;
    }
}

/* ========================================
   ONBOARDING - FORM OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
    .onboarding-container {
        padding: 20px !important;
        min-height: 100vh;
    }
    
    /* Progress bar */
    .onboarding-progress {
        position: sticky;
        top: 0;
        background: white;
        z-index: 100;
        padding: 16px 0;
        margin-bottom: 24px;
    }
    
    .progress-steps {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
    }
    
    .progress-step {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: #e2e8f0;
        color: #94a3b8;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: 0.9rem;
        z-index: 2;
    }
    
    .progress-step.active {
        background: #ec4899;
        color: white;
    }
    
    .progress-step.completed {
        background: #10b981;
        color: white;
    }
    
    /* Form step container */
    .form-step {
        display: none;
        animation: fadeInSlide 0.3s ease;
    }
    
    .form-step.active {
        display: block;
    }
    
    @keyframes fadeInSlide {
        from {
            opacity: 0;
            transform: translateX(20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
    
    /* Select dropdowns - mobile friendly */
    .form-group select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 16px center;
        padding-right: 40px !important;
    }
    
    /* Date picker mobile config */
    .flatpickr-calendar {
        font-size: 14px !important;
    }
    
    .flatpickr-day {
        height: 44px !important;
        line-height: 44px !important;
    }
    
    /* Radio buttons and checkboxes grid */
    .radio-grid,
    .checkbox-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .radio-option,
    .checkbox-option {
        padding: 14px;
        border: 2px solid #e2e8f0;
        border-radius: 12px;
        display: flex;
        align-items: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .radio-option:active,
    .checkbox-option:active {
        background: #f8fafc;
    }
    
    .radio-option input:checked + label,
    .checkbox-option input:checked + label {
        border-color: #ec4899;
        background: rgba(236, 72, 153, 0.05);
    }
    
    /* Photo upload - mobile camera */
    .photo-upload {
        position: relative;
        width: 100%;
        height: 200px;
        border: 2px dashed #e2e8f0;
        border-radius: 16px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .photo-upload:active {
        background: #f8fafc;
        border-color: #ec4899;
    }
    
    .photo-upload input[type="file"] {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
        cursor: pointer;
    }
    
    .photo-upload-icon {
        font-size: 3rem;
        color: #94a3b8;
        margin-bottom: 12px;
    }
    
    /* Gallery preview */
    .photo-preview-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-top: 16px;
    }
    
    .photo-preview-item {
        position: relative;
        aspect-ratio: 1;
        border-radius: 12px;
        overflow: hidden;
    }
    
    .photo-preview-item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .photo-preview-remove {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    /* Navigation buttons */
    .onboarding-nav {
        display: flex;
        gap: 12px;
        margin-top: 32px;
        position: sticky;
        bottom: 0;
        background: white;
        padding: 16px 0;
    }
    
    .btn-prev,
    .btn-next {
        flex: 1;
        min-height: 52px !important;
    }
    
    .btn-prev {
        background: #f1f5f9 !important;
        color: #475569 !important;
    }
}

/* ========================================
   DASHBOARD - CARD LAYOUT FIXES
   ======================================== */

@media (max-width: 768px) {
    /* Search results - proper single column */
    #searchResults {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        padding: 16px !important;
    }
    
    /* Modern match cards - optimized height */
    .modern-match-card {
        width: 100% !important;
        height: 420px !important; /* Reduced from 500px */
        border-radius: 20px !important;
        overflow: hidden;
        position: relative;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .modern-match-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .modern-match-content {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
        padding: 24px 20px !important;
        color: white;
    }
    
    .modern-match-name {
        font-size: 1.5rem !important;
        font-weight: 700;
        margin-bottom: 4px;
    }
    
    .modern-match-occupation {
        font-size: 0.95rem !important;
        opacity: 0.9;
        margin-bottom: 12px;
    }
    
    .modern-match-stats {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap !important;
        margin-bottom: 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .modern-match-stats::-webkit-scrollbar {
        display: none;
    }
    
    .modern-match-stat {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        padding: 6px 12px !important;
        border-radius: 20px;
        font-size: 0.85rem !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .modern-connect-btn {
        width: 100%;
        height: 48px !important;
        background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
        color: white;
        border: none;
        border-radius: 24px;
        font-size: 1rem;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
}

/* ========================================
   BOTTOM NAVIGATION - Z-INDEX FIX
   ======================================== */

@media (max-width: 768px) {
    .bottom-nav,
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        box-sizing: border-box;
        z-index: 900 !important; /* Reduced from 9999 */
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        padding: 8px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
        margin: 0 !important;
    }
    
    /* Modals should be above bottom nav */
    .modal-overlay,
    .otp-modal,
    .email-exists-modal,
    [role="dialog"] {
        z-index: 10000 !important;
    }
    
    /* Hide bottom nav when keyboard is visible */
    body.keyboard-visible .bottom-nav {
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
}

/* ========================================
   PROFILE SECTION - MOBILE OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
    .profile-header-card {
        margin: 0 16px 16px;
        border-radius: 20px;
    }
    
    .profile-cover {
        height: 100px;
        border-radius: 20px 20px 0 0;
    }
    
    .profile-avatar-large {
        width: 90px !important;
        height: 90px !important;
        margin-top: -45px !important;
        border: 4px solid white;
    }
    
    .profile-details-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    .profile-detail-item {
        padding: 12px 14px !important;
        font-size: 0.9rem !important;
    }
}

/* ========================================
   NOTIFICATION DROPDOWN - MOBILE FIX
   ======================================== */

@media (max-width: 768px) {
    /* Make notification wrapper relative for positioning */
    .notification-wrapper {
        position: relative;
    }
    
    .notification-panel {
        position: fixed !important;
        top: 60px !important; /* Position below header */
        right: 10px !important;
        bottom: auto !important;
        left: 10px !important;
        width: calc(100% - 20px) !important;
        max-width: 100% !important;
        max-height: calc(100vh - 140px) !important; /* Leave space at top and bottom */
        border-radius: 16px !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3) !important;
        overflow-y: auto !important;
    }
    
    .notification-panel::before {
        display: none !important;
    }
    
    /* Mobile-optimized clear button */
    .notification-clear-btn {
        opacity: 1 !important;
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        min-height: 28px !important;
        background: #f9fafb !important;
        border: 1px solid #e5e7eb !important;
        color: #6b7280 !important;
        border-radius: 8px !important;
        font-size: 13px !important;
    }
    
    .notification-clear-btn:active {
        background: #fee2e2 !important;
        border-color: #fecaca !important;
        color: #dc2626 !important;
        transform: scale(0.92) !important;
    }
    
    .notification-clear-btn i {
        font-size: 12px !important;
    }
    
    .notification-item {
        padding: 14px 16px !important;
        gap: 10px !important;
    }
}

/* ========================================
   ADMIN DASHBOARD - MOBILE BASICS
   (Complete rebuild needed, but these help)
   ======================================== */

@media (max-width: 768px) {
    /* Hide sidebar, show hamburger */
    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transition: left 0.3s ease;
    }
    
    .admin-sidebar.active {
        left: 0;
    }
    
    /* Main content full width */
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Mobile header for admin */
    .admin-header {
        padding: 12px 16px !important;
    }
    
    /* Stats grid responsive */
    .stats-grid,
    .admin-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    /* Data tables - card view */
    .data-table {
        display: none !important;
    }
    
    .data-table-mobile {
        display: block !important;
    }
    
    .table-card {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    /* Action buttons stack */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
}

/* ========================================
   PERFORMANCE - REDUCE ANIMATIONS
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* ========================================
   DASHBOARD MOBILE SPACING FIXES
   ======================================== */

@media (max-width: 768px) {
    /* Main content proper padding */
    .main-content {
        padding: 16px !important;
        padding-bottom: 100px !important; /* Space for bottom nav */
        min-height: calc(100vh - 72px) !important; /* Full height minus header */
    }
    
    /* Welcome widget spacing */
    .welcome-widget {
        margin-bottom: 20px !important;
    }
    
    /* Status widget spacing */
    .status-widget {
        margin-bottom: 24px !important;
    }
    
    /* Stats grid spacing */
    .stats-grid {
        margin-bottom: 24px !important;
        gap: 12px !important;
    }
    
    /* Section title spacing */
    .section-title {
        margin-top: 32px !important;
        margin-bottom: 16px !important;
    }
    
    /* Quick actions grid spacing */
    .quick-actions-grid {
        margin-bottom: 32px !important;
        padding-bottom: 12px !important;
    }
    
    /* Widget cards consistent spacing */
    .widget-card {
        margin-bottom: 16px !important;
    }
    
    /* Profile section spacing */
    #profileSection .profile-header-card {
        margin-bottom: 20px !important;
    }
    
    #profileSection .profile-stats-row {
        margin-bottom: 20px !important;
    }
    
    #profileSection .info-cards {
        margin-bottom: 24px !important;
    }
    
    /* Search section spacing */
    #searchSection {
        padding: 16px !important;
    }
    
    #searchSection .search-bar-container {
        margin-bottom: 20px !important;
    }
    
    #searchResults {
        padding-top: 8px !important;
        padding-bottom: 24px !important;
    }
    
    /* Matches section spacing */
    #matchesSection .tab-bar {
        margin-bottom: 20px !important;
    }
    
    #matchesSection .matches-scroll {
        padding-bottom: 24px !important;
    }
    
    /* Requests section spacing */
    #requestsSection .tab-bar {
        margin-bottom: 20px !important;
    }
    
    #requestsList {
        padding-bottom: 24px !important;
    }
    
    /* Settings section spacing */
    #settingsSection .settings-actions {
        padding-bottom: 32px !important;
    }
    
    /* Remove excessive empty space */
    .section {
        min-height: auto !important;
    }
    
    /* Ensure sections don't have excessive bottom padding */
    .section.active {
        padding-bottom: 0 !important;
    }
    
    /* App container proper sizing */
    .app-container {
        min-height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Header fixed height */
    .app-header {
        height: 72px !important;
        flex-shrink: 0 !important;
    }
    
    /* Main content flex grow */
    .main-content {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Bottom nav fixed at bottom */
    .bottom-nav {
        flex-shrink: 0 !important;
        height: 72px !important;
    }
    
    /* Fix for greeting and profile card spacing */
    #homeSection .welcome-widget + .status-widget {
        margin-top: 4px !important;
    }
    
    /* Consistent card spacing within sections */
    .section > .widget-card:first-child {
        margin-top: 0 !important;
    }
    
    .section > .widget-card:last-child {
        margin-bottom: 24px !important;
    }
    
    /* Activity list spacing */
    .activity-list {
        gap: 12px !important;
        padding-bottom: 24px !important;
    }
    
    /* Empty state spacing */
    .empty-state {
        padding: 48px 20px !important;
        margin: 24px 0 !important;
    }
    
    /* Tip widget spacing */
    .tip-widget {
        margin-top: 24px !important;
        margin-bottom: 24px !important;
    }
    
    /* Gallery grid spacing */
    .gallery-grid {
        margin-bottom: 24px !important;
        gap: 12px !important;
    }
    
    /* Info cards spacing */
    .info-cards {
        gap: 16px !important;
    }
    
    .info-card {
        margin-bottom: 0 !important;
    }
    
    /* Settings cards spacing */
    .settings-actions {
        gap: 12px !important;
    }
    
    .settings-btn {
        margin-bottom: 0 !important;
    }
}

/* ========================================
   CONTENT CONTAINER HEIGHT FIX
   Remove excessive empty space at bottom
   ======================================== */

@media (max-width: 768px) {
    /* Prevent excessive height on sections */
    #homeSection,
    #searchSection,
    #matchesSection,
    #requestsSection,
    #profileSection,
    #settingsSection,
    #boostSection {
        min-height: auto !important;
        height: auto !important;
        max-height: none !important;
    }
    
    /* Content should not stretch unnecessarily */
    .main-content > .section {
        flex-grow: 0 !important;
    }
    
    /* Last child in section should have proper bottom margin */
    .section > *:last-child {
        margin-bottom: 24px !important;
    }
    
    /* Remove any conflicting padding/margin */
    .main-content .section {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Proper spacing for first element in section */
    .section > *:first-child {
        margin-top: 0 !important;
    }
}

/* ========================================
   SPECIFIC CARD ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Welcome widget internal spacing */
    .welcome-widget .welcome-content {
        padding: 4px !important;
        gap: 14px !important;
    }
    
    .welcome-icon {
        width: 52px !important;
        height: 52px !important;
    }
    
    .welcome-text h3 {
        font-size: 1.25rem !important;
        margin-bottom: 4px !important;
    }
    
    .welcome-text p {
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
    }
    
    /* Status widget internal spacing */
    .status-widget {
        padding: 18px !important;
    }
    
    .status-content {
        margin-bottom: 14px !important;
    }
    
    .status-progress {
        margin-top: 8px !important;
    }
    
    /* Stats grid proper sizing */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .stat-widget {
        padding: 16px 14px !important;
    }
    
    /* Quick actions proper sizing */
    .action-btn {
        min-width: 80px !important;
        padding: 14px 16px !important;
    }
    
    .action-icon {
        width: 48px !important;
        height: 48px !important;
        margin-bottom: 8px !important;
    }
    
    .action-btn span {
        font-size: 0.8rem !important;
    }
}

/* ========================================
   SCROLLABLE CONTENT FIX
   ======================================== */

@media (max-width: 768px) {
    /* Ensure main content is scrollable */
    .main-content {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Hide scrollbar but keep functionality */
    .main-content::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }
    
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden !important;
    }
    
    .app-container {
        overflow-x: hidden !important;
    }
    
    /* All sections should fit within viewport */
    .section {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* ========================================
   BOTTOM SAFE AREA FIX
   Account for iPhone home indicator
   ======================================== */

@media (max-width: 768px) {
    /* Bottom nav with safe area */
    .bottom-nav,
    .mobile-bottom-nav {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important;
    }
    
    /* Main content bottom padding with safe area */
    .main-content {
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0)) !important;
    }
}

/* ========================================
   DEBUG HELPERS (Remove in production)
   ======================================== */

/* Uncomment to visualize spacing issues
@media (max-width: 768px) {
    .widget-card {
        outline: 1px solid red !important;
    }
    
    .section {
        outline: 2px solid blue !important;
    }
    
    .main-content {
        outline: 3px solid green !important;
    }
}
*/


/* ========================================
   EDIT PROFILE MODAL - MOBILE FIX
   ======================================== */

@media (max-width: 768px) {
    /* Ensure the main content is hidden when modal is active */
    body:has(#editProfileModal.active) .main-content,
    body:has(#editProfileModal.active) .bottom-nav {
        pointer-events: none !important;
    }
    
    /* Edit Profile Modal - Override all other styles */
    #editProfileModal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
        z-index: 100000 !important;
        padding: 20px !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-radius: 0 !important;
        display: none !important;
        margin: 0 !important;
        box-shadow: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        transition: opacity 0.3s ease, visibility 0.3s ease !important;
    }
    
    #editProfileModal.active {
        display: flex !important;
        flex-direction: column !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Ensure modal overlay is below the edit modal */
    #modalOverlay {
        z-index: 99999 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(0, 0, 0, 0.5) !important;
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }
    
    #modalOverlay.active {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Edit Profile Modal Content */
    #editProfileModal .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        max-height: none !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        text-align: left !important;
        background: white !important;
        border-radius: 16px !important;
        flex: 1 !important;
        overflow-y: auto !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
        padding: 16px !important;
    }
    
    /* Modal Header */
    #editProfileModal .modal-header {
        position: sticky !important;
        top: 0 !important;
        background: white !important;
        z-index: 11 !important;
        padding: 0 0 12px 0 !important;
        border-bottom: 1px solid #e5e7eb !important;
        margin-bottom: 16px !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        flex-shrink: 0 !important;
    }
    
    #editProfileModal .modal-header h3 {
        font-size: 1.25rem !important;
        margin: 0 !important;
        text-align: left !important;
        color: #1f2937 !important;
        font-weight: 700 !important;
    }
    
    #editProfileModal .close-modal {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f3f4f6 !important;
        border: none !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
        font-size: 1.2rem !important;
    }
    
    #editProfileModal .close-modal:active {
        background: #e5e7eb !important;
    }
    
    /* Edit Profile Form */
    #editProfileModal .edit-profile-form {
        padding: 0 !important;
        width: 100% !important;
        overflow-y: auto !important;
    }
    
    /* Form sections */
    #editProfileModal .edit-form-section {
        margin-bottom: 20px !important;
    }
    
    #editProfileModal .edit-form-section h4 {
        font-size: 0.95rem !important;
        margin-bottom: 12px !important;
        color: #ff6b9d !important;
        font-weight: 600 !important;
    }
    
    /* Form rows */
    #editProfileModal .form-row {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }
    
    /* Form groups */
    #editProfileModal .form-group {
        margin-bottom: 12px !important;
        width: 100% !important;
    }
    
    #editProfileModal .form-group label {
        font-size: 0.85rem !important;
        display: block !important;
        margin-bottom: 5px !important;
        color: #666 !important;
        font-weight: 500 !important;
    }
    
    #editProfileModal .form-group input,
    #editProfileModal .form-group select,
    #editProfileModal .form-group textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        border: 1px solid #ddd !important;
        border-radius: 8px !important;
        background: white !important;
    }
    
    #editProfileModal .form-group input[disabled],
    #editProfileModal .form-group select[disabled] {
        background: #f3f4f6 !important;
        cursor: not-allowed !important;
        color: #9ca3af !important;
    }
    
    #editProfileModal .form-group textarea {
        min-height: 80px !important;
        resize: vertical !important;
    }
    
    /* Save button */
    #editProfileModal .btn-primary {
        width: 100% !important;
        padding: 14px !important;
        font-size: 1rem !important;
        margin-top: 16px !important;
        background: linear-gradient(135deg, #ff6b9d 0%, #c026d3 100%) !important;
        color: white !important;
        border: none !important;
        border-radius: 12px !important;
        cursor: pointer !important;
        font-weight: 600 !important;
    }
    
    #editProfileModal .btn-primary:active {
        transform: scale(0.98) !important;
    }
}

@media (max-width: 640px) {
    #editProfileModal {
        padding: 16px !important;
    }
    
    #editProfileModal .modal-content {
        padding: 12px !important;
    }
    
    #editProfileModal .modal-header h3 {
        font-size: 1.1rem !important;
    }
}
