/* Mobile UI Fixes and Optimizations */

/* ===== MOBILE UI ENHANCEMENTS ===== */
@media (max-width: 768px) {
    /* Smooth animations */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Better card shadows */
    .rounded-2xl,
    .rounded-xl,
    .therapist-card,
    .service-box {
        box-shadow: 0 4px 20px rgba(212, 175, 55, 0.15) !important;
        transition: transform 0.2s, box-shadow 0.2s !important;
    }

    /* Card hover/active effect */
    .therapist-card:active,
    .service-box:active {
        transform: translateY(2px);
        box-shadow: 0 2px 10px rgba(212, 175, 55, 0.1) !important;
    }

    /* Glass morphism effects */
    .backdrop-blur {
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    }

    /* Gradient text for headings - REMOVED to prevent UI breaking */
    /* h1, h2, h3 {
        background: linear-gradient(135deg, #d4af37 0%, #f4e5c3 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    } */

    /* Better scroll indicators */
    .overflow-x-auto {
        scroll-snap-type: x mandatory;
        scrollbar-width: thin;
        scrollbar-color: rgba(212, 175, 55, 0.3) transparent;
    }

    .overflow-x-auto::-webkit-scrollbar {
        height: 4px;
    }

    .overflow-x-auto::-webkit-scrollbar-track {
        background: rgba(212, 175, 55, 0.1);
        border-radius: 2px;
    }

    .overflow-x-auto::-webkit-scrollbar-thumb {
        background: rgba(212, 175, 55, 0.5);
        border-radius: 2px;
    }
}

/* ===== FORM FIXES ===== */
@media (max-width: 768px) {
    /* Fix form inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    textarea,
    select {
        font-size: 16px !important; /* Prevent zoom on iOS */
        min-height: 44px !important; /* Better touch target */
        padding: 12px 16px !important;
        border-radius: 12px !important;
        width: 100%;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Fix select dropdown */
    select {
        background-image: url('data:image/svg+xml;utf8,<svg fill="%23d4af37" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>');
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 20px;
        padding-right: 40px !important;
    }

    /* Fix checkbox and radio */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        min-height: 20px !important;
    }

    /* Fix file input */
    input[type="file"] {
        padding: 12px !important;
        border: 2px dashed rgba(212, 175, 55, 0.5) !important;
        background: rgba(212, 175, 55, 0.05) !important;
    }
}

/* ===== BUTTON FIXES ===== */
@media (max-width: 768px) {
    /* 只对表单提交按钮应用全宽 */
    button[type="submit"],
    form .btn-gold,
    form .btn-outline-gold {
        min-height: 48px !important;
        padding: 14px 24px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        width: 100%;
        display: block;
        text-align: center;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        font-weight: 600 !important;
        letter-spacing: 0.5px !important;
        transition: all 0.2s ease !important;
    }

    /* 普通按钮保持默认宽度 */
    button:not([type="submit"]),
    a.btn-gold,
    a.btn-outline-gold {
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-size: 15px !important;
        border-radius: 10px !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        font-weight: 600 !important;
        letter-spacing: 0.5px !important;
        transition: all 0.2s ease !important;
    }

    /* Gold button gradient */
    .btn-gold {
        background: linear-gradient(135deg, #d4af37 0%, #f4e5c3 50%, #d4af37 100%) !important;
        background-size: 200% 100% !important;
        box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3) !important;
    }

    .btn-gold:active {
        background-position: 100% 0 !important;
        box-shadow: 0 2px 6px rgba(212, 175, 55, 0.2) !important;
    }

    /* Outline button */
    .btn-outline-gold {
        border: 2px solid #d4af37 !important;
        color: #d4af37 !important;
        background: rgba(212, 175, 55, 0.05) !important;
    }

    .btn-outline-gold:active {
        background: rgba(212, 175, 55, 0.15) !important;
    }

    /* Inline buttons */
    .inline-btn {
        width: auto !important;
        display: inline-block !important;
    }

    /* Button groups */
    .button-group {
        display: flex;
        gap: 12px;
        flex-wrap: wrap;
    }

    .button-group button,
    .button-group .btn-gold,
    .button-group .btn-outline-gold {
        flex: 1;
        min-width: 120px;
    }
}

/* ===== THERAPIST REGISTER PAGE FIXES ===== */
@media (max-width: 768px) {
    /* Main container */
    .min-h-screen {
        padding: 1rem !important;
    }

    /* Form sections */
    .rounded-2xl,
    .rounded-xl {
        border-radius: 16px !important;
        padding: 1.5rem !important;
    }

    /* Grid fixes */
    .grid-cols-1.md\:grid-cols-2,
    .grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Spacing fixes */
    .space-y-6 > * {
        margin-bottom: 1.5rem;
    }

    .space-y-4 > * {
        margin-bottom: 1rem;
    }

    .mb-8 {
        margin-bottom: 2rem !important;
    }

    .mb-6 {
        margin-bottom: 1.5rem !important;
    }

    .mb-4 {
        margin-bottom: 1rem !important;
    }

    /* Text sizes */
    .text-3xl,
    .text-4xl {
        font-size: 1.75rem !important;
        line-height: 1.2 !important;
    }

    .text-2xl {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }

    .text-xl {
        font-size: 1.25rem !important;
    }

    .text-lg {
        font-size: 1.125rem !important;
    }

    .text-base {
        font-size: 1rem !important;
    }

    .text-sm {
        font-size: 0.875rem !important;
    }
}

/* ===== BOOKING PAGE FIXES ===== */
@media (max-width: 768px) {
    /* Booking summary sidebar */
    .lg\:col-span-1 {
        position: static !important;
        margin-top: 1.5rem;
    }

    .sticky {
        position: static !important;
    }

    /* Map container */
    #map {
        height: 200px !important;
        border-radius: 12px !important;
    }

    /* Location button */
    #get-current-location,
    #get-therapist-location {
        width: 100%;
        margin-top: 0.75rem !important;
        padding: 12px 16px !important;
        border-radius: 12px !important;
        font-size: 15px !important;
    }

    /* Status messages */
    #location-status,
    #booking-location-status {
        padding: 12px;
        border-radius: 8px;
        background: rgba(212, 175, 55, 0.05);
        margin-top: 0.75rem;
    }
}

/* ===== THERAPIST LIST PAGE FIXES ===== */
@media (max-width: 768px) {
    /* Grid layout */
    #therapists-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Therapist cards */
    .therapist-card {
        border-radius: 16px !important;
        overflow: hidden;
        margin-bottom: 1rem;
    }

    .therapist-image {
        padding-top: 100% !important; /* Square aspect ratio on mobile */
    }

    /* Distance badge */
    .therapist-distance {
        font-size: 0.875rem !important;
        padding: 6px 12px !important;
    }

    /* Filters */
    .filters-mobile {
        position: sticky;
        top: 60px;
        z-index: 50;
        background: rgba(10, 10, 10, 0.98);
        backdrop-filter: blur(20px);
        padding: 12px 16px;
        margin: 0 -1rem;
        border-bottom: 1px solid rgba(212, 175, 55, 0.2);
    }

    .filter-chips {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 4px 0;
    }

    .filter-chips::-webkit-scrollbar {
        display: none;
    }

    .filter-chip {
        flex-shrink: 0;
        padding: 8px 16px;
        background: rgba(212, 175, 55, 0.1);
        border: 1px solid rgba(212, 175, 55, 0.3);
        border-radius: 20px;
        color: #d4af37;
        font-size: 0.875rem;
        white-space: nowrap;
    }

    .filter-chip.active {
        background: #d4af37;
        color: #0a0a0a;
    }
}

/* ===== THERAPIST DETAIL PAGE FIXES ===== */
@media (max-width: 768px) {
    /* Main grid */
    .lg\:col-span-2,
    .lg\:col-span-1 {
        grid-column: span 1 !important;
    }

    /* Photo gallery */
    .grid-cols-4.md\:grid-cols-6 {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
    }

    /* Info sections */
    .grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    /* Booking card */
    .sticky.top-24 {
        position: static !important;
        margin-top: 1.5rem;
    }
}

/* ===== NAVIGATION FIXES ===== */
@media (max-width: 768px) {
    /* Header */
    nav {
        padding: 0.75rem 1rem !important;
    }

    .logo-text {
        font-size: 1.25rem !important;
        letter-spacing: 2px !important;
    }

    /* Mobile menu */
    #mobile-menu {
        background: linear-gradient(180deg, rgba(10, 10, 10, 0.98) 0%, rgba(20, 20, 20, 0.98) 100%) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        padding: 1rem !important;
        border-top: 1px solid rgba(212, 175, 55, 0.3);
        margin-top: 0.5rem;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5) !important;
        animation: slideDown 0.3s ease-out;
    }

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

    #mobile-menu a {
        padding: 14px 16px !important;
        margin: 6px 0 !important;
        border-radius: 10px !important;
        font-size: 15px !important;
        display: flex !important;
        align-items: center !important;
        color: #cccccc !important;
        font-weight: 500 !important;
        transition: all 0.2s ease !important;
        position: relative;
        overflow: hidden;
    }

    #mobile-menu a::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 3px;
        background: #d4af37;
        transform: scaleY(0);
        transition: transform 0.2s ease;
    }

    #mobile-menu a:active,
    #mobile-menu a:hover {
        background: rgba(212, 175, 55, 0.15) !important;
        color: #d4af37 !important;
        transform: translateX(4px);
    }

    #mobile-menu a:active::before,
    #mobile-menu a:hover::before {
        transform: scaleY(1);
    }

    #mobile-menu a i {
        margin-right: 12px;
        width: 24px;
        text-align: center;
        font-size: 16px;
        color: #d4af37;
    }

    #mobile-menu hr {
        border-color: rgba(212, 175, 55, 0.2) !important;
        margin: 12px 0 !important;
    }

    /* Language switcher in mobile menu */
    #mobile-menu .flex.gap-2 {
        margin-top: 8px;
        gap: 8px !important;
    }

    #mobile-menu .flex.gap-2 a {
        flex: 1;
        justify-content: center;
        padding: 12px !important;
        font-weight: 600 !important;
    }
}

/* ===== ALERT/MESSAGE FIXES ===== */
@media (max-width: 768px) {
    .bg-red-100,
    .bg-green-100,
    .bg-yellow-100,
    .bg-blue-100 {
        padding: 12px 16px !important;
        border-radius: 12px !important;
        margin-bottom: 1rem !important;
        font-size: 14px !important;
    }

    .border-l-4 {
        border-left-width: 4px !important;
    }
}

/* ===== TABLE FIXES ===== */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table th,
    table td {
        padding: 12px 8px !important;
        font-size: 14px !important;
    }
}

/* ===== MODAL FIXES ===== */
@media (max-width: 768px) {
    .modal-mobile,
    .filter-modal {
        border-radius: 20px 20px 0 0 !important;
        padding: 20px !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
    }

    .modal-handle {
        width: 40px;
        height: 4px;
        background: rgba(212, 175, 55, 0.3);
        border-radius: 2px;
        margin: 0 auto 16px;
    }
}

/* ===== CONTAINER FIXES ===== */
@media (max-width: 768px) {
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .max-w-4xl,
    .max-w-6xl,
    .max-w-7xl {
        max-width: 100% !important;
    }

    /* Don't override mx-auto for login/register forms */
    /* .mx-auto {
        margin-left: 0 !important;
        margin-right: 0 !important;
    } */
}

/* ===== PADDING/MARGIN FIXES ===== */
@media (max-width: 768px) {
    .py-8 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .p-6 {
        padding: 1.5rem !important;
    }

    .p-4 {
        padding: 1rem !important;
    }
}

/* ===== SHADOW FIXES ===== */
@media (max-width: 768px) {
    .shadow-lg {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    }

    .shadow-xl {
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2) !important;
    }
}

/* ===== OVERFLOW FIXES ===== */
@media (max-width: 768px) {
    body {
        overflow-x: hidden !important;
    }

    .overflow-hidden {
        overflow: hidden !important;
    }

    .overflow-x-auto {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* ===== TEXT TRUNCATE FIXES ===== */
@media (max-width: 768px) {
    .truncate {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    .line-clamp-2 {
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }
}

/* ===== LOCATION BUTTON IMPROVEMENTS ===== */
@media (max-width: 768px) {
    button[id*="location"],
    button[id*="get-"] {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        min-height: 48px;
        font-size: 15px;
        font-weight: 500;
    }

    button[id*="location"] i,
    button[id*="get-"] i {
        font-size: 16px;
    }
}

/* ===== IMPROVED TOUCH FEEDBACK ===== */
@media (max-width: 768px) {
    button:active,
    .btn-gold:active,
    .btn-outline-gold:active,
    a.btn:active {
        transform: scale(0.97);
        transition: transform 0.1s;
    }

    .therapist-card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
}

/* ===== SAFE AREA INSETS ===== */
@supports(padding: max(0px)) {
    @media (max-width: 768px) {
        body {
            padding-bottom: max(20px, env(safe-area-inset-bottom));
        }

        .bottom-nav {
            padding-bottom: max(0px, env(safe-area-inset-bottom));
        }

        nav {
            padding-top: max(12px, env(safe-area-inset-top));
        }
    }
}

/* ===== FIX HORIZONTAL SCROLL ===== */
@media (max-width: 768px) {
    * {
        max-width: 100%;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    pre {
        overflow-x: auto;
        max-width: 100%;
    }
}

/* ===== IMPROVED READABILITY ===== */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        line-height: 1.6;
    }

    p {
        margin-bottom: 1rem;
    }

    h1, h2, h3, h4, h5, h6 {
        margin-bottom: 0.75rem;
        line-height: 1.3;
    }
}

/* ===== LAZY LOADING IMAGES (DISABLED - 直接显示所有图片) ===== */
/* 移除 lazy-load 的隐藏效果，避免刷新后图片消失 */
img.lazy-load {
    opacity: 1 !important;
    transition: opacity 0.3s ease-in;
}

img.lazy-load[src*="data:image"] {
    opacity: 1 !important;
}

img:not(.lazy-load),
img.lazy-load:not([src*="data:image"]) {
    opacity: 1 !important;
}

/* ===== BOTTOM NAV FIX - FORCE FIXED POSITION ===== */
@media (max-width: 768px) {
    .bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
        z-index: 9999 !important;
        width: 100% !important;
        /* Prevent any scrolling behavior */
        overscroll-behavior: none !important;
        /* Force hardware acceleration */
        will-change: transform !important;
        backface-visibility: hidden !important;
        -webkit-backface-visibility: hidden !important;
        /* Prevent touch actions that might move it */
        touch-action: none !important;
    }

    /* Ensure body doesn't cover bottom nav - REMOVED DUPLICATE */
    /* body {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom)) !important;
        overscroll-behavior-y: contain !important;
    } */

    /* Ensure footer doesn't overlap - REMOVED DUPLICATE */
    /* footer {
        margin-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom)) !important;
    } */

    /* Ensure main content doesn't overlap - REMOVED DUPLICATE */
    /* main {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom) + 20px) !important;
    } */
}

/* ===== HAMBURGER MENU FIX ===== */
@media (max-width: 768px) {
    /* Hide desktop menu on mobile */
    nav .hidden.md\:flex {
        display: none !important;
    }

    /* Mobile header flex layout */
    nav .container > div:first-child {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100%;
    }

    /* Hamburger button stays right */
    #mobile-menu-button {
        margin-left: auto !important;
        flex-shrink: 0 !important;
    }

    /* Logo */
    .logo-text {
        font-size: 1.25rem !important;
        white-space: nowrap;
    }

    /* Mobile menu dropdown - hidden by default */
    #mobile-menu {
        display: none;
    }

    /* Mobile menu shown state */
    #mobile-menu:not(.hidden) {
        display: block !important;
    }
}

/* Desktop: ensure mobile menu button is hidden */
@media (min-width: 769px) {
    #mobile-menu-button {
        display: none !important;
    }

    #mobile-menu {
        display: none !important;
    }
}



/* ===== GLOBAL: Remove top gap between header and first content on mobile ===== */
@media (max-width: 768px) {
    main.priority > *:first-child {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}
