/* ================================================
   HoopTrain 移动端H5响应式适配
   断点: 768px，仅影响 <768px 的设备
   PC端样式完全不受影响
   ================================================ */

@media screen and (max-width: 767px) {
    /* ========== 一、全局基础重置 ========== */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body {
        overflow-x: hidden !important;
        font-size: 14px !important;
        -webkit-font-smoothing: antialiased;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y pan-x;
    }

    /* 禁止长按选中 */
    body, button, a, span, div, p, li, h1, h2, h3, h4, h5, h6 {
        -webkit-user-select: none;
        user-select: none;
    }

    /* 输入框允许选中 */
    input, textarea, select {
        -webkit-user-select: text;
        user-select: text;
        font-size: 16px !important; /* 防止iOS自动缩放 */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 0; /* 移除iOS默认圆角 */
    }

    /* ========== 二、导航体系：侧边栏→底部Tab栏 ========== */
    .sidebar {
        display: none !important;
    }

    .topbar {
        left: 0 !important;
        padding: 0 16px !important;
        height: 52px !important;
        z-index: 999;
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
    }

    .topbar-title {
        font-size: 16px !important;
        font-weight: 600 !important;
    }

    .sidebar-toggle-btn {
        display: none !important;
    }

    .topbar-user-avatar {
        width: 34px !important;
        height: 34px !important;
        font-size: 14px !important;
    }

    /* 主内容区适配 */
    .main-content {
        margin-left: 0 !important;
        margin-top: 52px !important;
        padding: 12px !important;
        max-width: 100% !important;
        padding-bottom: 80px !important; /* 底部导航空间 */
    }

    /* 底部固定Tab导航 */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 56px !important;
        background: #fff !important;
        border-top: 1px solid #e0e0e0 !important;
        z-index: 1000 !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05) !important;
    }

    .mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 1 !important;
        height: 100% !important;
        font-size: 11px !important;
        color: #999 !important;
        text-decoration: none !important;
        padding: 4px 0 !important;
        min-height: 44px !important;
    }

    .mobile-nav-item .nav-icon {
        font-size: 20px !important;
        margin-bottom: 2px !important;
    }

    .mobile-nav-item.active {
        color: #FF6B00 !important;
    }

    /* ========== 三、首页适配 ========== */
    /* AI Banner压缩 */
    .hero-section {
        padding: 0 0 12px 0 !important;
        margin-bottom: 12px !important;
    }

    .hero-card {
        flex-direction: column !important;
        padding: 16px !important;
        gap: 8px !important;
    }

    .hero-left {
        flex: none !important;
    }

    .hero-badge {
        font-size: 11px !important;
        padding: 3px 10px !important;
        margin-bottom: 6px !important;
    }

    .hero-title {
        font-size: 18px !important;
        margin-bottom: 4px !important;
    }

    .hero-subtitle {
        font-size: 12px !important;
        line-height: 1.5 !important;
        margin-bottom: 8px !important;
        -webkit-line-clamp: 2 !important;
    }

    .hero-btn {
        width: 100% !important;
        padding: 10px !important;
        font-size: 14px !important;
        height: 40px !important;
    }

    .hero-stats {
        display: none !important; /* 首屏隐藏统计，节省空间 */
    }

    .hero-right {
        display: none !important; /* 隐藏篮球插画 */
    }

    /* 推荐模板区 - 单列纵向卡片流 */
    .recommend-section {
        margin-bottom: 16px !important;
    }

    .section-title-bar {
        margin-bottom: 10px !important;
    }

    .section-title {
        font-size: 16px !important;
    }

    .recommend-scroll {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        overflow-x: visible !important;
        scroll-snap-type: none !important;
    }

    .recommend-scroll > * {
        scroll-snap-align: none !important;
        min-width: 100% !important;
        width: 100% !important;
    }

    .recommend-card {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* 训练分类专区 - 3列网格紧凑 */
    .category-section {
        margin-bottom: 16px !important;
    }

    .category-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }

    .category-card {
        padding: 10px 4px !important;
        min-height: 44px !important;
    }

    .category-icon {
        font-size: 24px !important;
    }

    .category-name {
        font-size: 12px !important;
    }

    /* ========== 四、AI分步生成页面适配 ========== */
    .main-container {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .left-panel {
        width: 100% !important;
        min-width: 100% !important;
        position: static !important;
        top: auto !important;
    }

    .right-panel {
        display: none !important;
    }

    .panel-header {
        padding: 10px 16px !important;
    }

    .panel-title {
        font-size: 15px !important;
    }

    .mode-tabs {
        gap: 8px !important;
    }

    .mode-tab {
        flex: 1 !important;
        padding: 10px !important;
        font-size: 13px !important;
        justify-content: center !important;
    }

    .form-section {
        padding: 12px !important;
    }

    /* 选项卡片改为大尺寸触控按钮 */
    .option-card, .option-btn, .step-option {
        width: 100% !important;
        min-height: 56px !important;
        padding: 12px 16px !important;
        font-size: 14px !important;
        margin-bottom: 8px !important;
    }

    /* 分步引导按钮固定底部 */
    .step-actions, .step-footer, .step-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: #fff !important;
        padding: 12px 16px !important;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08) !important;
        z-index: 100 !important;
        display: flex !important;
        gap: 10px !important;
    }

    .step-actions button, .step-footer button, .step-nav button {
        flex: 1 !important;
        min-height: 44px !important;
        font-size: 14px !important;
    }

    /* ========== 五、训练计划详情页适配 ========== */
    .plan-header {
        padding: 12px 0 !important;
    }

    .plan-header h2, .plan-title {
        font-size: 18px !important;
    }

    /* 教练笔记默认折叠 */
    .coach-notes, .plan-notes, .plan-section.collapsible {
        max-height: 0 !important;
        overflow: hidden !important;
        transition: max-height 0.3s ease !important;
    }

    .coach-notes.expanded, .plan-notes.expanded, .plan-section.collapsible.expanded {
        max-height: 2000px !important;
    }

    /* 折叠标题可点击 */
    .section-title-bar .collapse-toggle {
        cursor: pointer;
        font-size: 12px;
        color: #FF6B00;
    }

    /* 动作清单单列排版 */
    .exercise-item {
        padding: 12px !important;
        margin-bottom: 8px !important;
    }

    .exercise-item .exercise-header {
        flex-wrap: wrap !important;
    }

    .exercise-item .exercise-name {
        font-size: 14px !important;
        font-weight: 600 !important;
    }

    .exercise-item .exercise-params {
        font-size: 12px !important;
    }

    .exercise-item .exercise-detail {
        font-size: 12px !important;
        line-height: 1.5 !important;
    }

    /* 详情页底部操作栏 */
    .plan-actions, .detail-actions {
        position: fixed !important;
        bottom: 56px !important; /* 底部导航上方 */
        left: 0 !important;
        right: 0 !important;
        background: #fff !important;
        padding: 8px 12px !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08) !important;
        z-index: 99 !important;
        display: flex !important;
        gap: 8px !important;
    }

    .plan-actions button, .detail-actions button {
        flex: 1 !important;
        min-height: 40px !important;
        font-size: 12px !important;
        padding: 6px 8px !important;
    }

    /* ========== 六、自选动作组合页面适配 ========== */
    .builder-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .panel {
        width: 100% !important;
    }

    /* 已选列表底部固定操作 */
    .builder-actions {
        position: fixed !important;
        bottom: 56px !important;
        left: 0 !important;
        right: 0 !important;
        background: #fff !important;
        padding: 8px 12px !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08) !important;
        z-index: 99 !important;
    }

    .builder-actions button {
        min-height: 40px !important;
        font-size: 13px !important;
    }

    /* ========== 七、我的训练+个人档案页适配 ========== */
    .content-tabs {
        display: flex !important;
        gap: 0 !important;
        margin-bottom: 12px !important;
        border-bottom: 2px solid #f0f0f0 !important;
    }

    .content-tab {
        flex: 1 !important;
        text-align: center !important;
        padding: 10px 0 !important;
        font-size: 14px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .plans-header {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: stretch !important;
    }

    .plans-header > div:last-child {
        display: flex !important;
        gap: 8px !important;
    }

    .plans-new-btn {
        flex: 1 !important;
        padding: 10px !important;
        font-size: 13px !important;
        min-height: 40px !important;
    }

    /* 计划列表单列卡片 */
    .plans-list {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .plan-item {
        width: 100% !important;
        padding: 12px !important;
    }

    /* 个人档案单列布局 */
    .profile-card {
        padding: 12px !important;
    }

    .profile-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .profile-field {
        width: 100% !important;
    }

    .profile-label {
        font-size: 13px !important;
        margin-bottom: 4px !important;
    }

    .profile-field input,
    .profile-field select {
        width: 100% !important;
        min-height: 44px !important;
        font-size: 16px !important;
        padding: 8px 12px !important;
    }

    /* 单选项改为按钮组 */
    .radio-group, .option-group {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .radio-group label, .radio-group .radio-item,
    .option-group label, .option-group .option-item {
        flex: 1 1 auto !important;
        min-width: 60px !important;
        min-height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 6px 12px !important;
        border: 1px solid #ddd !important;
        border-radius: 8px !important;
        font-size: 13px !important;
    }

    /* ========== 八、登录注册页适配 ========== */
    .login-container {
        max-width: 100% !important;
    }

    .login-box {
        padding: 24px 20px !important;
    }

    .logo-icon {
        width: 60px !important;
        height: 60px !important;
    }

    .logo-text {
        font-size: 20px !important;
    }

    .tabs {
        gap: 0 !important;
        margin-bottom: 20px !important;
    }

    .tab-btn {
        flex: 1 !important;
        text-align: center !important;
        padding: 10px !important;
        font-size: 14px !important;
        min-height: 44px !important;
    }

    .form-group {
        margin-bottom: 14px !important;
    }

    .form-input {
        height: 48px !important;
        font-size: 16px !important;
        padding: 10px 14px !important;
    }

    .btn-primary, .btn-submit, .login-btn {
        width: 100% !important;
        min-height: 48px !important;
        font-size: 16px !important;
    }

    /* ========== 九、通用组件适配 ========== */
    /* 按钮最小触控热区 */
    button, .btn, a[role="button"] {
        min-height: 44px !important;
        min-width: 44px !important;
    }

    /* 图标按钮特殊处理 */
    .icon-btn, .icon-button {
        min-width: 44px !important;
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* 卡片适配 */
    .card {
        width: 100% !important;
        padding: 12px !important;
        margin-bottom: 10px !important;
    }

    /* 表格转纵向列表 */
    table.responsive {
        display: block !important;
        width: 100% !important;
    }

    table.responsive thead, table.responsive tbody {
        display: block !important;
        width: 100% !important;
    }

    table.responsive tr {
        display: block !important;
        margin-bottom: 8px !important;
        border: 1px solid #eee !important;
        border-radius: 8px !important;
        padding: 8px !important;
    }

    table.responsive td, table.responsive th {
        display: block !important;
        text-align: right !important;
        border: none !important;
        padding: 4px 0 !important;
    }

    table.responsive td::before {
        content: attr(data-label) "：";
        float: left !important;
        font-weight: 600 !important;
        color: #666 !important;
    }

    /* 模态框适配 */
    .modal, .modal-content {
        width: 92% !important;
        max-width: 92% !important;
        max-height: 85vh !important;
        margin: 0 auto !important;
        overflow-y: auto !important;
        border-radius: 12px !important;
    }

    .modal-overlay {
        padding: 16px !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Toast适配 */
    .toast {
        left: 16px !important;
        right: 16px !important;
        max-width: none !important;
        bottom: 80px !important; /* 避开底部导航 */
        padding: 10px 16px !important;
        font-size: 13px !important;
    }

    /* 进度条适配 */
    .progress-bar, .step-progress {
        height: 4px !important;
        margin-bottom: 8px !important;
    }

    /* 标签适配 */
    .tag, .badge {
        font-size: 11px !important;
        padding: 2px 8px !important;
    }

    /* 滚动容器去掉横向滚动 */
    .scroll-x, .horizontal-scroll {
        overflow-x: visible !important;
        flex-wrap: wrap !important;
    }

    /* ========== 十、软键盘适配 ========== */
    /* 输入框聚焦时滚动到可视区 */
    input:focus, textarea:focus, select:focus {
        scroll-margin-top: 80px;
        scroll-margin-bottom: 120px;
    }

    /* 键盘弹出时隐藏底部导航 */
    body.keyboard-open .mobile-bottom-nav {
        display: none !important;
    }

    body.keyboard-open .main-content {
        padding-bottom: 12px !important;
    }

    /* ========== 十一、管理后台适配 ========== */
    .admin-container, .admin-content {
        margin-left: 0 !important;
        padding: 12px !important;
    }

    .tabs-bar {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .tab-btn {
        white-space: nowrap !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
    }

    .card {
        margin-bottom: 10px !important;
    }

    /* 模板列表单列 */
    .template-grid {
        grid-template-columns: 1fr !important;
    }

    /* 框架配置模块纵向排列 */
    .module-list {
        flex-direction: column !important;
    }

    .module-item {
        width: 100% !important;
        margin-bottom: 8px !important;
    }
}

/* ========== iOS特定安全区适配 ========== */
@supports (padding: env(safe-area-inset-bottom)) {
    @media screen and (max-width: 767px) {
        .mobile-bottom-nav {
            padding-bottom: env(safe-area-inset-bottom, 0px) !important;
            height: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
        }

        .main-content {
            padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        }

        .topbar {
            padding-top: env(safe-area-inset-top, 0px) !important;
            height: calc(52px + env(safe-area-inset-top, 0px)) !important;
        }

        body {
            padding-top: env(safe-area-inset-top, 0px) !important;
        }
    }
}

/* ========== 横屏适配 ========== */
@media screen and (max-width: 767px) and (orientation: landscape) {
    .login-box {
        max-width: 400px !important;
        margin: 0 auto !important;
    }

    .hero-card {
        max-width: 500px !important;
        margin: 0 auto !important;
    }
}

/* ========== 超小屏(320px)适配 ========== */
@media screen and (max-width: 360px) {
    body {
        font-size: 13px !important;
    }

    .hero-title {
        font-size: 16px !important;
    }

    .category-grid {
        gap: 4px !important;
    }

    .category-name {
        font-size: 11px !important;
    }

    .mobile-nav-item {
        font-size: 10px !important;
    }

    .mobile-nav-item .nav-icon {
        font-size: 18px !important;
    }
}
