/* ============================================
   响应式适配样式 - 手机/平板设备支持
   断点标准:
   - 手机竖屏:  ≤ 480px
   - 手机横屏:  ≤ 768px
   - 平板:     ≤ 1068px
   - 桌面:     > 1068px
   ============================================ */

/* ==================== 通用工具类 ==================== */

/* 桌面端隐藏 */
.mobile-only {
    display: none !important;
}

/* nav-label 默认隐藏（桌面端不需要） */
.nav-label {
    display: none;
}

/* ==================== 平板端 (≤ 1068px) ==================== */
@media (max-width: 1068px) {

    /* --- Header 适配 --- */
    .header {
        height: 44px;
        padding: 0 1rem;
    }

    .header-slogan {
        display: none; /* 隐藏标语 */
    }

    .header-logo:nth-child(1) {
        height: 30px;
    }

    .header-logo:nth-child(2) {
        height: 31px;
        margin-left: -16px;
    }

    /* 移动端按钮在header中显示 */
    .mobile-only {
        display: flex !important;
    }

    .header-mobile-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        cursor: pointer;
        border-radius: 50%;
        transition: background 0.2s ease;
        position: relative;
    }

    .header-mobile-btn:hover {
        background: rgba(0, 0, 0, 0.06);
    }

    .header-mobile-icon {
        width: 18px;
        height: 18px;
        opacity: 0.7;
    }

    .header-msg-count {
        position: absolute;
        top: -2px;
        right: -2px;
        width: 14px;
        height: 14px;
        font-size: 0.5rem;
    }

    /* --- Sidebar → 底部Tab栏 --- */
    .main-container {
        height: calc(100vh - 44px);
        flex-direction: column-reverse; /* 底部Tab在下 */
    }

    .sidebar {
        width: 100% !important;
        height: 56px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border-light);
        padding: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 2000;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
    }

    /* sidebar-bottom 在平板端隐藏（已移入header） */
    .sidebar-bottom {
        display: none;
    }

    /* 设置菜单重新定位 */
    .settings-menu {
        bottom: auto;
        top: auto;
        left: auto;
        right: 10px;
        top: 50px;
        position: fixed;
        z-index: 3000;
    }

    .nav-menu {
        flex-direction: row;
        gap: 0;
        flex: 1;
        justify-content: space-around;
        align-items: center;
        height: 100%;
        padding: 0;
        margin: 0;
    }

    .nav-item {
        flex: 1;
        height: 100%;
        flex-direction: column;
        gap: 2px;
        margin: 0;
        border-radius: 0;
        padding: 4px 0;
        justify-content: center;
    }

    /* 隐藏桌面端悬停背景效果 */
    .nav-item::before {
        display: none;
    }

    /* 隐藏tooltip（Tab栏用文字标签替代） */
    .nav-tooltip {
        display: none !important;
    }

    /* 显示Tab栏文字标签 */
    .nav-label {
        display: block;
        font-size: 10px;
        color: var(--text-tertiary);
        text-align: center;
        line-height: 1;
        white-space: nowrap;
    }

    .nav-item.active .nav-label {
        color: var(--apple-blue);
    }

    /* Tab栏图标尺寸 */
    .nav-icon {
        width: 22px;
        height: 22px;
    }

    .home-icon {
        width: 26px !important;
        height: 26px !important;
    }

    .nav-item.active .nav-icon {
        opacity: 1;
    }

    /* 禁用项的标签颜色 */
    .nav-item-disabled .nav-label {
        opacity: 0.3;
    }

    /* --- 内容区域适配 --- */
    .content-area {
        height: calc(100vh - 44px - 56px); /* header + 底部Tab */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* "更多"导航项在Tab栏隐藏 */
    .nav-item-disabled {
        display: none;
    }

    /* 左侧风格选择栏收窄 */
    .style-sidebar,
    .style-selection-section {
        width: 200px;
    }

    /* --- 消息中心/账户设置 --- */
    .messages-full-container,
    .account-settings-container {
        padding: 12px;
        gap: 12px;
    }

    .messages-left,
    .account-settings-left {
        width: 280px;
    }

    /* 用户卡片紧凑化 */
    .user-profile-card {
        padding: 12px;
    }

    .user-profile-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    /* --- 用户菜单适配 --- */
    .user-menu {
        width: min(380px, calc(100vw - 2rem));
    }

    .user-menu-header {
        padding: 16px;
    }

    /* 菜单项间距调整 */
    .menu-item {
        padding: 11px 16px;
        gap: 12px;
        border-radius: 24px;
    }

    /* 企业标志精简 */
    .menu-enterprise-badge {
        padding: 10px 16px;
    }
}

/* ==================== 手机横屏 (≤ 768px) ==================== */
@media (max-width: 768px) {

    /* --- 功能页左右分栏 → 上下堆叠 --- */
    .color-plan-container,
    .content-wrapper {
        flex-direction: column;
        gap: 0;
        padding: 0;
    }

    /* 左侧侧栏变为顶部区域 */
    .style-sidebar,
    .style-selection-section {
        width: 100% !important;
        height: auto;
        max-height: none;
        border-right: none !important;
        border-bottom: 1px solid #d0d0d0;
        border-radius: 0 !important;
    }

    /* 风格侧栏标题精简 */
    .style-sidebar-header,
    .style-header {
        padding: 0.4rem 0.8rem !important;
    }

    .style-sidebar h3,
    .style-header h3 {
        font-size: 14px !important;
        padding: 0.4rem !important;
    }

    /* 风格库变为横向滚动 */
    .style-library-container {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0 0.5rem 0.5rem !important;
        max-height: 120px;
    }

    .style-library {
        flex-direction: row !important;
        gap: 0.5rem !important;
        padding-top: 0.5rem !important;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .style-item {
        min-width: 100px;
        max-width: 100px;
        flex-shrink: 0;
    }

    /* 风格项图片在横向模式下正方形 */
    #color-plan-page .style-item,
    #color-master-plan-page .style-item,
    #image-to-drawing-page .style-item {
        aspect-ratio: 1 / 1;
        min-width: 80px;
        max-width: 80px;
    }

    #color-plan-page .style-item span,
    #color-master-plan-page .style-item span,
    #image-to-drawing-page .style-item span {
        font-size: 0.7rem;
        padding: 0.3rem 0.4rem;
    }

    /* plan-box 自适应 */
    .plan-box {
        aspect-ratio: auto !important;
        min-height: 300px;
        width: 100%;
    }

    /* 按钮区域 */
    .action-buttons {
        padding: 0.5rem 1rem;
    }

    /* 文件处理区域（图纸转换的左右分区也堆叠） */
    .file-processing-section {
        flex-direction: column;
        padding: 0.5rem !important;
    }

    .original-plan-section,
    .colored-plan-section {
        width: 100%;
    }

    /* 户型库筛选区 - 折叠/紧凑 */
    .filter-container {
        max-height: none;
        padding: 0.5rem;
    }

    .filter-group-header {
        font-size: 13px;
        padding: 0.3rem 0;
    }

    .filter-options {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.4rem !important;
    }

    .filter-btn {
        padding: 0.3rem 0.5rem !important;
        font-size: 12px !important;
    }

    /* 户型库/家具库网格 */
    .layout-grid,
    .furniture-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 家具分类横向滚动 */
    .furniture-category-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .category-list {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .category-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* --- 消息中心 → 上下堆叠 --- */
    .messages-full-container {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }

    .messages-left {
        width: 100%;
    }

    .messages-right {
        margin-top: 0;
    }

    /* 消息导航横向 */
    .messages-nav-buttons {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .messages-nav-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* --- 账户设置 → 上下堆叠 --- */
    .account-settings-container {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }

    .account-settings-left {
        width: 100%;
    }

    .account-settings-right {
        padding: 16px;
    }

    /* 账户导航横向滚动 */
    .account-nav-buttons {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem;
    }

    .account-nav-button {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .user-profile-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 展示区域占满 */
    .layout-display-section,
    .furniture-display-section {
        flex: 1;
        min-height: 400px;
    }
}

/* ==================== 手机竖屏 (≤ 480px) ==================== */
@media (max-width: 480px) {

    /* Header 进一步精简 */
    .header {
        padding: 0 0.5rem;
    }

    .header-logo:nth-child(1) {
        height: 24px;
    }

    .header-logo:nth-child(2) {
        height: 25px;
        margin-left: -12px;
    }

    /* 底部Tab栏精简 */
    .sidebar {
        height: 50px;
    }

    .nav-label {
        font-size: 9px;
    }

    .nav-icon {
        width: 20px;
        height: 20px;
    }

    .home-icon {
        width: 22px !important;
        height: 22px !important;
    }

    .content-area {
        height: calc(100vh - 44px - 50px);
    }

    /* 用户菜单全屏 */
    .user-menu {
        width: 100vw !important;
        right: -0.5rem;
        border-radius: 0 0 20px 20px !important;
        padding: 16px;
    }

    .user-menu.show {
        border-radius: 0 0 20px 20px !important;
    }

    /* 风格项更小 */
    .style-item {
        min-width: 70px;
        max-width: 70px;
    }

    #color-plan-page .style-item,
    #color-master-plan-page .style-item,
    #image-to-drawing-page .style-item {
        min-width: 65px;
        max-width: 65px;
    }

    /* plan-box */
    .plan-box {
        min-height: 250px;
    }

    /* 上传提示文字缩小 */
    .upload-placeholder p {
        font-size: 14px;
    }

    .upload-icon-svg {
        width: 40px;
        height: 40px;
    }

    /* 筛选按钮 */
    .filter-options {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 网格单列 */
    .layout-grid,
    .furniture-grid {
        grid-template-columns: 1fr !important;
    }

    /* 用户卡片头像缩小 */
    .user-profile-avatar {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* 用户统计数据紧凑 */
    .user-profile-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    /* 安全设置表单紧凑 */
    .security-item {
        padding: 12px;
    }

    .form-group {
        margin-bottom: 12px;
    }

    /* 展示区域最小高度 */
    .layout-display-section,
    .furniture-display-section {
        min-height: 350px;
    }

    /* 风格库高度进一步限制 */
    .style-library-container {
        max-height: 100px;
    }
}

/* ==================== 用户菜单响应式 ==================== */
@media (min-width: 481px) and (max-width: 1068px) {
    .user-menu {
        width: min(380px, 90vw);
    }
}

/* ==================== 深色模式 + 响应式 ==================== */
@media (max-width: 1068px) {
    body.dark-mode .sidebar {
        background: rgba(30, 30, 30, 0.95);
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    body.dark-mode .header-mobile-btn:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    body.dark-mode .nav-label {
        color: #999;
    }

    body.dark-mode .nav-item.active .nav-label {
        color: #4a90e2;
    }
}

@media (max-width: 768px) {
    body.dark-mode .style-sidebar,
    body.dark-mode .style-selection-section {
        border-bottom-color: #444;
    }

    body.dark-mode .messages-full-container,
    body.dark-mode .account-settings-container {
        background: #1a1a1a;
    }
}

/* ==================== 触屏设备 ==================== */
/* 禁用 hover 效果，避免触屏设备"粘滞"高亮 */
@media (hover: none) {
    .nav-item:hover::before {
        opacity: 0;
    }

    .nav-item:hover .nav-icon {
        opacity: inherit;
    }

    /* tooltip 在触屏完全隐藏 */
    .nav-tooltip {
        display: none !important;
    }

    /* 增大触摸目标 */
    .filter-btn,
    .category-btn,
    .process-button,
    .download-button {
        min-height: 44px; /* Apple HIG 最小触摸目标 */
    }

    .nav-item {
        min-height: 44px;
    }

    /* 菜单项增大点击区域 */
    .menu-item {
        min-height: 44px;
    }

    /* 设置项增大 */
    .settings-item {
        min-height: 44px;
    }

    /* 消息/账户导航按钮增大 */
    .messages-nav-btn,
    .account-nav-button {
        min-height: 40px;
    }
}

/* ==================== 登录/注册页适配 ==================== */
@media (max-width: 1068px) {
    .auth-card {
        max-width: 600px;
        min-height: auto;
        border-radius: 20px;
    }

    .auth-right {
        min-height: 200px;
        padding: 30px;
    }

    .auth-left {
        padding: 40px 30px;
    }
}

@media (max-width: 768px) {
    .auth-container {
        padding: 10px;
    }

    .auth-card {
        flex-direction: column;
        border-radius: 16px;
    }

    .auth-right {
        order: -1;
        min-height: 180px;
        padding: 24px 20px;
    }

    .auth-left {
        padding: 24px 16px;
    }

    /* 防止iOS自动缩放 - input字号必须≥16px */
    .auth-form input,
    .auth-form select,
    .auth-form textarea {
        font-size: 16px !important;
    }

    .auth-form .form-group {
        margin-bottom: 12px;
    }

    /* 按钮全宽 */
    .auth-form button,
    .auth-form .submit-btn {
        width: 100%;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .auth-right {
        min-height: 150px;
        padding: 20px 16px;
    }

    .auth-right h2 {
        font-size: 20px;
    }

    .auth-left {
        padding: 20px 12px;
    }

    .auth-form h2 {
        font-size: 22px;
    }
}

/* ==================== 首页Hero区域优化 ==================== */
@media (max-width: 768px) {
    /* Hero轮播区域 */
    .hero-section {
        min-height: 200px;
    }

    .hero-title {
        font-size: 18px;
    }

    .hero-subtitle {
        font-size: 11px;
    }

    .hero-cta {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0 1rem;
    }

    .cta-button {
        width: 100%;
        min-width: auto;
        font-size: 14px;
        padding: 10px 16px;
    }

    /* 竖向内容单列 */
    .cards-grid,
    .resources-grid {
        grid-template-columns: 1fr !important;
    }

    /* 特性版块 */
    .features-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 16px;
    }

    .hero-subtitle {
        font-size: 10px;
    }

    .hero-indicators {
        bottom: 10px;
    }

    .hero-indicator {
        width: 6px;
        height: 6px;
    }
}


/* ==================== 管理员后台适配 ==================== */
@media (max-width: 768px) {
    /* 管理后台表格横向滚动 */
    .admin-table-container,
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-table,
    .data-table {
        min-width: 600px;
    }

    /* Dashboard网格单列 */
    .dashboard {
        grid-template-columns: 1fr !important;
    }

    /* 模态框全屏化 */
    .modal-content,
    .admin-modal-content {
        width: 95vw !important;
        max-width: none !important;
        margin: 10px auto;
        border-radius: 12px;
    }

    /* 管理后台header */
    .admin-header {
        padding: 0 0.5rem;
    }

    /* 统计卡片 */
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }

    .modal-content,
    .admin-modal-content {
        width: 100vw !important;
        border-radius: 12px 12px 0 0;
        position: fixed;
        bottom: 0;
        margin: 0;
    }
}

/* ==================== 性能优化 ==================== */
/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 移动端性能优化 */
@media (max-width: 768px) {
    /* 减少backdrop-filter使用（性能杀手） */
    .sidebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(255, 255, 255, 0.98) !important;
    }

    body.dark-mode .sidebar {
        background: rgba(30, 30, 30, 0.98) !important;
    }

    /* 减少box-shadow复杂度 */
    .style-sidebar,
    .style-selection-section {
        box-shadow: none !important;
    }

    /* 启动动画在移动端加速 */
    .startup-animation {
        animation-duration: 0.5s !important;
    }
}

/* ==================== 细节打磨 ==================== */
/* 安全区域适配（iPhone刘海/底部条） */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 1068px) {
        .sidebar {
            padding-bottom: env(safe-area-inset-bottom);
            height: calc(56px + env(safe-area-inset-bottom));
        }

        .content-area {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }

    @media (max-width: 480px) {
        .sidebar {
            height: calc(50px + env(safe-area-inset-bottom));
        }
    }
}

/* 滚动条在移动端隐藏 */
@media (max-width: 768px) {
    .style-library-container::-webkit-scrollbar,
    .furniture-category-container::-webkit-scrollbar,
    .category-list::-webkit-scrollbar,
    .account-nav-buttons::-webkit-scrollbar,
    .messages-nav-buttons::-webkit-scrollbar {
        display: none;
    }

    .style-library-container,
    .furniture-category-container,
    .category-list,
    .account-nav-buttons,
    .messages-nav-buttons {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* 选中文字防止误选 */
@media (hover: none) {
    .nav-item,
    .nav-label,
    .style-item span,
    .filter-btn,
    .category-btn {
        -webkit-user-select: none;
        user-select: none;
    }
}
