/**
 * Mobile Experience Enhancements
 * Phase 1: Core mobile improvements
 */

/* Mobile-First Base Styles */
:root {
    --touch-target-min: 44px;
    --mobile-nav-height: 64px;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
}

/* Ensure minimum touch targets */
button, 
a,
input[type="checkbox"],
input[type="radio"],
.clickable {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

/* Mobile Navigation Bar */
@media (max-width: 768px) {
    /* Hide desktop nav on mobile */
    .desktop-nav {
        display: none !important;
    }
    
    /* Mobile bottom navigation */
    .mobile-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-nav-height) + var(--safe-area-inset-bottom));
        background: white;
        border-top: 1px solid #e5e7eb;
        z-index: 1000;
        display: flex;
        align-items: center;
        padding-bottom: var(--safe-area-inset-bottom);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-nav-items {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        height: var(--mobile-nav-height);
    }
    
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: #64748b;
        text-decoration: none;
        transition: color 0.2s;
        padding: 8px;
    }
    
    .mobile-nav-item.active,
    .mobile-nav-item:active {
        color: #7c3aed;
    }
    
    .mobile-nav-item svg {
        width: 24px;
        height: 24px;
    }
    
    .mobile-nav-item span {
        font-size: 11px;
        font-weight: 500;
    }
    
    /* Adjust main content for bottom nav */
    main,
    .main-content {
        padding-bottom: calc(var(--mobile-nav-height) + var(--safe-area-inset-bottom) + 20px) !important;
    }
    
    /* Mobile Header */
    .mobile-header {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: white;
        border-bottom: 1px solid #e5e7eb;
        z-index: 999;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
    }
    
    .mobile-header-logo {
        height: 32px;
    }
    
    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        background: transparent;
        transition: background 0.2s;
    }
    
    .mobile-menu-btn:active {
        background: #f1f5f9;
    }
    
    /* Mobile Menu Overlay */
    .mobile-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 320px;
        height: 100%;
        background: white;
        z-index: 10000;
        transition: right 0.3s ease;
        overflow-y: auto;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-menu.open {
        right: 0;
    }
    
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
    }
    
    .mobile-menu-overlay.open {
        opacity: 1;
        visibility: visible;
    }
    
    /* Mobile Search */
    .mobile-search-bar {
        padding: 12px 16px;
        background: #f8fafc;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .mobile-search-input {
        width: 100%;
        height: 44px;
        padding: 0 16px 0 44px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: white;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .mobile-search-icon {
        position: absolute;
        left: 28px;
        top: 50%;
        transform: translateY(-50%);
        color: #94a3b8;
    }
    
    /* Form improvements */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 12px !important;
        height: auto !important;
        min-height: var(--touch-target-min) !important;
    }
    
    /* Button improvements */
    .btn,
    button,
    [role="button"] {
        padding: 12px 24px !important;
        font-size: 16px !important;
        min-height: var(--touch-target-min) !important;
    }
    
    /* Card improvements */
    .listing-card,
    .profile-card {
        padding: 16px !important;
        margin-bottom: 16px !important;
    }
    
    /* Improved spacing */
    .container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    
    /* Stack columns on mobile */
    .row {
        margin-left: -8px !important;
        margin-right: -8px !important;
    }
    
    .col-md-6,
    .col-lg-4,
    .col-lg-3 {
        width: 100% !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        margin-bottom: 16px !important;
    }
    
    /* Improve readability */
    body {
        font-size: 16px !important;
        line-height: 1.6 !important;
    }
    
    h1 {
        font-size: 28px !important;
    }
    
    h2 {
        font-size: 24px !important;
    }
    
    h3 {
        font-size: 20px !important;
    }
    
    /* Tool pages specific */
    .tool-card {
        margin-bottom: 16px;
    }
    
    /* Checklist improvements */
    .checklist-item {
        padding: 16px;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .checklist-item:last-child {
        border-bottom: none;
    }
    
    .checklist-item label {
        display: flex;
        align-items: flex-start;
        gap: 12px;
    }
    
    .checklist-item input[type="checkbox"] {
        flex-shrink: 0;
        margin-top: 2px;
        width: 20px;
        height: 20px;
    }
    
    /* Cost calculator mobile */
    .step {
        padding: 16px;
    }
    
    .step label {
        display: block;
        margin-bottom: 8px;
    }
    
    /* Profile page mobile */
    .profile-hero {
        padding: 16px;
    }
    
    .profile-actions {
        position: fixed;
        bottom: calc(var(--mobile-nav-height) + var(--safe-area-inset-bottom) + 16px);
        left: 16px;
        right: 16px;
        display: flex;
        gap: 12px;
        background: white;
        padding: 16px;
        border-radius: 12px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        z-index: 100;
    }
    
    .profile-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* Landscape mobile adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-nav {
        height: 56px;
    }
    
    .mobile-nav-item span {
        display: none;
    }
    
    .mobile-header {
        height: 48px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mobile-nav {
        border-top: 2px solid black;
    }
    
    .mobile-nav-item.active {
        text-decoration: underline;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari fixes */
    .mobile-nav {
        padding-bottom: calc(var(--safe-area-inset-bottom) + 8px);
    }
    
    input, textarea, select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
}

/* Print styles - hide mobile nav */
@media print {
    .mobile-nav,
    .mobile-header,
    .mobile-menu {
        display: none !important;
    }
}
