/* ===== 移动端全局UI修复和优化 ===== */
/* 适用于所有页面的移动端优化 */

/* ===== 基础设置 ===== */
@media (max-width: 768px) {

    /* 防止水平滚动 */
    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* 优化字体渲染 */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
        font-size: 16px !important;
        /* 防止iOS自动缩放 */
        line-height: 1.6;
    }

    /* 所有容器防止溢出 */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* 图片响应式 */
    img {
        max-width: 100%;
        height: auto;
        display: block;
    }
}

/* ===== 导航栏优化 ===== */
@media (max-width: 768px) {

    /* 顶部导航栏 */
    header.priority {
        position: sticky;
        top: 0;
        z-index: 1000;
        padding: 0 !important;
        height: auto !important;
        min-height: 60px;
    }

    .headerCont {
        padding: 0 !important;
    }

    .headerLeft {
        padding: 10px 15px !important;
        height: 60px !important;
    }

    .headerRight {
        padding: 10px 15px 0 0 !important;
        height: 60px !important;
    }

    .headerLogo img {
        height: 50px !important;
        width: auto !important;
    }

    /* 移动端菜单按钮 */
    .navBar {
        width: 50px !important;
        height: 50px !important;
        display: table-cell !important;
        vertical-align: middle !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 1001 !important;
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
    }

    .navBar>div {
        padding: 10px;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .navBarItem {
        width: 28px !important;
        height: 3px !important;
        background: #ffffff !important;
        margin: 4px 0 !important;
        transition: all 0.3s ease;
        border-radius: 2px;
        pointer-events: none !important;
    }

    /* 汉堡按钮打开状态 */
    .navBar.isOpen .navBarItem:nth-child(1) {
        transform: translateY(11px) rotate(45deg);
    }

    .navBar.isOpen .navBarItem:nth-child(2) {
        opacity: 0;
    }

    .navBar.isOpen .navBarItem:nth-child(3) {
        transform: translateY(-11px) rotate(-45deg);
    }

    /* 移动端侧边栏菜单 */
    .navSpTb {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: rgba(10, 10, 10, 0.98);
        backdrop-filter: blur(20px);
        z-index: 9999;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding-bottom: 80px;
        /* 给底部导航栏留空间 */
    }

    .navSpTb.isOpen {
        left: 0;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    /* 侧边栏遮罩层 */
    .navSpTb-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .navSpTb-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .navSpTb .navItem {
        border-bottom: 1px solid rgba(212, 175, 55, 0.2);
    }

    .navSpTb .navItem a {
        padding: 18px 20px;
        font-size: 16px;
        display: flex;
        align-items: center;
        transition: all 0.2s;
    }

    .navSpTb .navItem a:hover,
    .navSpTb .navItem a:active {
        background: rgba(212, 175, 55, 0.15);
        padding-left: 30px;
    }

    /* 遮罩层 */
    .navSpTb-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }

    .navSpTb-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ===== 底部导航栏优化 ===== */
@media (max-width: 768px) {
    .bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 70px;
        background: linear-gradient(180deg, rgba(10, 10, 10, 0.98) 0%, rgba(0, 0, 0, 1) 100%);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border-top: 1px solid rgba(212, 175, 55, 0.3);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
        z-index: 999 !important;
        padding-bottom: env(safe-area-inset-bottom, 0);
        display: flex !important;
        align-items: center;
        justify-content: space-around;
        /* 防止滚动时移动 */
        transform: translate3d(0, 0, 0);
        will-change: transform;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #888;
        padding: 8px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        position: relative;
        min-height: 44px;
    }

    .bottom-nav-item:active {
        transform: scale(0.92);
    }

    .bottom-nav-item i {
        font-size: 1.3rem;
        margin-bottom: 4px;
        transition: all 0.3s;
    }

    .bottom-nav-item span {
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .bottom-nav-item.active {
        color: #d4af37;
    }

    .bottom-nav-item.active i {
        transform: translateY(-3px) scale(1.1);
        filter: drop-shadow(0 2px 4px rgba(212, 175, 55, 0.5));
    }

    /* 徽章 */
    .bottom-nav-badge {
        position: absolute;
        top: 4px;
        right: calc(50% - 8px);
        background: #ef4444;
        color: white;
        border-radius: 10px;
        padding: 2px 6px;
        font-size: 0.65rem;
        font-weight: 700;
        min-width: 18px;
        text-align: center;
    }

    /* 为底部导航栏留出空间 */
    main.priority,
    .container {
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0) + 20px) !important;
    }

    footer.priority {
        margin-bottom: calc(70px + env(safe-area-inset-bottom, 0)) !important;
    }
}

/* ===== 容器和布局优化 ===== */
@media (max-width: 768px) {
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        width: 100% !important;
    }

    .max-w-4xl,
    .max-w-6xl,
    .max-w-7xl {
        max-width: 100% !important;
    }

    /* 网格布局优化 */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .md\:grid-cols-2,
    .md\:grid-cols-3,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .lg\:grid-cols-4,
    .lg\:grid-cols-5 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Flexbox布局优化 */
    .flex-row,
    .md\:flex-row,
    .lg\:flex-row {
        flex-direction: column !important;
    }

    /* 间距优化 */
    .py-8 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .py-12 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }

    .px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .gap-8 {
        gap: 1rem !important;
    }

    .gap-6 {
        gap: 0.75rem !important;
    }
}

/* ===== 卡片和组件优化 ===== */
@media (max-width: 768px) {

    /* 卡片 */
    .rounded-2xl,
    .rounded-xl,
    .rounded-lg {
        border-radius: 16px !important;
    }

    .p-6,
    .p-8 {
        padding: 1.5rem !important;
    }

    .p-4 {
        padding: 1rem !important;
    }

    /* 阴影优化 */
    .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;
    }

    /* 治疗师卡片 */
    .therapist-card {
        border-radius: 16px !important;
        overflow: hidden;
        margin-bottom: 1rem;
        transition: transform 0.2s, box-shadow 0.2s;
    }

    .therapist-card:active {
        transform: translateY(2px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }

    .therapist-image {
        position: relative;
        padding-top: 120%;
        background: #0a0a0a;
        overflow: hidden;
    }

    .therapist-image img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* ===== 表单元素优化 ===== */
@media (max-width: 768px) {

    /* 所有输入框 */
    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;
        /* 防止iOS自动缩放 */
        min-height: 48px !important;
        padding: 14px 16px !important;
        border-radius: 12px !important;
        width: 100%;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border: 1px solid rgba(0, 0, 0, 0.2) !important;
        transition: all 0.2s;
    }

    input:focus,
    textarea:focus,
    select:focus {
        outline: none;
        border-color: #d4af37 !important;
        box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1) !important;
    }

    /* Select下拉箭头 */
    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;
    }

    /* 复选框和单选按钮 */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px !important;
        height: 20px !important;
        min-height: 20px !important;
        margin-right: 8px;
    }

    /* Textarea */
    textarea {
        min-height: 100px !important;
        resize: vertical;
    }

    /* Label */
    label {
        font-size: 15px !important;
        font-weight: 600;
        margin-bottom: 8px !important;
        display: block;
    }

    /* 表单组间距 */
    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .mb-6 {
        margin-bottom: 1.5rem !important;
    }
}

/* ===== 按钮优化 ===== */
@media (max-width: 768px) {

    /* 所有按钮基础样式 */
    button,
    .btn-gold,
    .btn-outline-gold,
    a.btn {
        min-height: 48px !important;
        padding: 14px 24px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        border-radius: 12px !important;
        transition: all 0.2s ease !important;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    /* 表单提交按钮全宽 */
    button[type="submit"],
    form .btn-gold,
    form .btn-outline-gold {
        width: 100% !important;
        display: block;
    }

    /* 金色按钮 */
    .btn-gold {
        background: linear-gradient(135deg, #d4af37 0%, #f4e5c3 50%, #d4af37 100%) !important;
        background-size: 200% 100% !important;
        color: #0a0a0a !important;
        border: none !important;
        box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3) !important;
    }

    .btn-gold:active {
        transform: scale(0.97);
        background-position: 100% 0 !important;
        box-shadow: 0 2px 6px rgba(212, 175, 55, 0.2) !important;
    }

    /* 描边按钮 */
    .btn-outline-gold {
        background: transparent !important;
        border: 2px solid #d4af37 !important;
        color: #d4af37 !important;
    }

    .btn-outline-gold:active {
        background: rgba(212, 175, 55, 0.15) !important;
        transform: scale(0.97);
    }

    /* 按钮组 */
    .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;
    }
}

/* ===== 文字优化 ===== */
@media (max-width: 768px) {

    /* 标题 */
    h1 {
        font-size: 1.75rem !important;
        line-height: 1.2 !important;
        margin-bottom: 1rem !important;
    }

    h2 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.875rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
        line-height: 1.4 !important;
        margin-bottom: 0.75rem !important;
    }

    h4 {
        font-size: 1.125rem !important;
        margin-bottom: 0.625rem !important;
    }

    /* 段落 */
    p {
        font-size: 15px !important;
        line-height: 1.6 !important;
        margin-bottom: 1rem;
    }

    /* 文字大小类 */
    .text-3xl,
    .text-4xl {
        font-size: 1.75rem !important;
    }

    .text-2xl {
        font-size: 1.5rem !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;
    }

    .text-xs {
        font-size: 0.75rem !important;
    }
}

/* ===== 列表和表格优化 ===== */
@media (max-width: 768px) {

    /* 表格横向滚动 */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table th,
    table td {
        padding: 12px 8px !important;
        font-size: 14px !important;
        white-space: nowrap;
    }

    /* 列表 */
    ul,
    ol {
        padding-left: 1.5rem;
    }

    li {
        margin-bottom: 0.5rem;
    }
}

/* ===== 模态框和弹窗优化 ===== */
@media (max-width: 768px) {

    /* 底部弹窗 */
    .modal-mobile,
    .filter-modal {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(26, 26, 26, 0.98);
        backdrop-filter: blur(20px);
        border-radius: 20px 20px 0 0;
        padding: 20px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        max-height: 85vh;
        overflow-y: auto;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    }

    .modal-mobile.open,
    .filter-modal.open {
        transform: translateY(0);
    }

    .modal-handle {
        width: 40px;
        height: 4px;
        background: rgba(212, 175, 55, 0.3);
        border-radius: 2px;
        margin: 0 auto 16px;
    }

    /* 遮罩 */
    .modal-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }

    .modal-backdrop.open {
        opacity: 1;
        visibility: visible;
    }
}

/* ===== 提示和消息优化 ===== */
@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;
    }

    /* 状态标签 */
    .status-pending,
    .status-confirmed,
    .status-completed,
    .status-cancelled {
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.75rem;
        font-weight: 600;
        display: inline-block;
    }

    .status-pending {
        background: rgba(251, 191, 36, 0.2);
        color: #f59e0b;
    }

    .status-confirmed {
        background: rgba(59, 130, 246, 0.2);
        color: #3b82f6;
    }

    .status-completed {
        background: rgba(34, 197, 94, 0.2);
        color: #22c55e;
    }

    .status-cancelled {
        background: rgba(239, 68, 68, 0.2);
        color: #ef4444;
    }
}

/* ===== 加载和动画优化 ===== */
@media (max-width: 768px) {

    /* 加载动画 */
    .skeleton {
        background: linear-gradient(90deg,
                rgba(212, 175, 55, 0.1) 25%,
                rgba(212, 175, 55, 0.2) 50%,
                rgba(212, 175, 55, 0.1) 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
        border-radius: 8px;
    }

    @keyframes skeleton-loading {
        0% {
            background-position: 200% 0;
        }

        100% {
            background-position: -200% 0;
        }
    }

    /* 触摸反馈 */
    .ripple {
        position: relative;
        overflow: hidden;
    }

    .ripple:active {
        transform: scale(0.97);
        transition: transform 0.1s;
    }

    /* GPU加速 */
    .gpu-accelerated {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        will-change: transform;
    }
}

/* ===== 滚动优化 ===== */
@media (max-width: 768px) {

    /* 平滑滚动 */
    html {
        scroll-behavior: smooth;
    }

    /* iOS弹性滚动 */
    body {
        -webkit-overflow-scrolling: touch;

    }

    /* 横向滚动容器 */
    .overflow-x-auto {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .overflow-x-auto::-webkit-scrollbar {
        display: none;
    }

    /* 滚动捕捉 */
    .snap-x {
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .snap-center {
        scroll-snap-align: center;
        scroll-snap-stop: always;
    }
}

/* ===== 特殊页面优化 ===== */
@media (max-width: 768px) {

    /* 登录/注册页面 */
    .min-h-screen {
        padding: 1rem !important;
        min-height: calc(100vh - 70px) !important;
    }

    /* 首页Hero区域 */
    .mainView {
        height: calc(100vh - 60px) !important;
        min-height: 500px !important;
    }

    .mainViewCont::after {
        background-position: center center !important;
        background-size: cover !important;
        background-attachment: scroll !important;
    }

    /* 内页Hero */
    .innerHero {
        height: 30vh !important;
        min-height: 200px !important;
    }

    /* 侧边栏在移动端堆叠 */
    .lg\:col-span-1,
    .lg\:col-span-2,
    .lg\:col-span-3 {
        grid-column: span 1 !important;
    }

    .sticky {
        position: static !important;
    }
}

/* ===== 过滤器和筛选优化 ===== */
@media (max-width: 768px) {

    /* 移动端筛选器 */
    .filters-mobile {
        position: sticky;
        top: 60px;
        background: rgba(10, 10, 10, 0.98);
        backdrop-filter: blur(20px);
        padding: 12px 16px;
        z-index: 50;
        border-bottom: 1px solid rgba(212, 175, 55, 0.2);
        margin: 0 -1rem;
    }

    /* 筛选芯片 */
    .filter-chips {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 4px 0;
        -webkit-overflow-scrolling: touch;
    }

    .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;
        text-decoration: none;
        transition: all 0.2s;
    }

    .filter-chip.active {
        background: #d4af37;
        color: #0a0a0a;
    }

    .filter-chip:active {
        transform: scale(0.95);
    }
}

/* ===== 可访问性优化 ===== */
@media (max-width: 768px) {

    /* 触摸目标最小尺寸 */
    a,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }

    /* 触摸高亮 */
    a,
    button {
        -webkit-tap-highlight-color: rgba(212, 175, 55, 0.1);
    }

    /* Focus可见性 */
    a:focus,
    button:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #d4af37;
        outline-offset: 2px;
    }
}

/* ===== 性能优化 ===== */
@media (max-width: 768px) {
    /* 减少动画（如果用户偏好） */
    @media (prefers-reduced-motion: reduce) {

        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* 暗色模式支持 */
    @media (prefers-color-scheme: dark) {
        body {
            background: #0a0a0a;
        }
    }
}

/* ===== 横屏模式优化 ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .mainView {
        height: 100vh !important;
        min-height: auto !important;
    }

    .bottom-nav {
        height: 56px;
    }

    .bottom-nav-item span {
        display: none;
    }

    .bottom-nav-item i {
        font-size: 1.1rem;
        margin-bottom: 0;
    }

    main.priority {
        padding-bottom: calc(56px + 20px) !important;
    }
}

/* ===== Safe Area支持（iPhone刘海屏等） ===== */
@supports(padding: max(0px)) {
    @media (max-width: 768px) {
        body {
            padding-top: env(safe-area-inset-top, 0);
        }

        .bottom-nav {
            padding-bottom: env(safe-area-inset-bottom, 0);
        }

        header.priority {
            padding-top: env(safe-area-inset-top, 0);
        }
    }
}

/* ===== 打印样式优化 ===== */
@media print {

    .bottom-nav,
    .navSpTb,
    .navBar,
    button {
        display: none !important;
    }

    body {
        background: white !important;
        color: black !important;
    }
}