/**
 * 联创圈 - 移动端专属样式
 * 设计理念：遵循移动端原生交互习惯，底部Tab导航 + 简化顶栏 + 全屏搜索
 * 适配所有手机尺寸（iPhone SE ~ iPad Mini）
 */

/* ========================================
 * 移动端变量
 * ======================================== */
:root {
    --m-tab-height: 56px;
    --m-tab-safe-bottom: env(safe-area-inset-bottom, 0px);
    --m-topbar-height: 50px;
    --m-primary: #4f46e5;
    --m-primary-light: #6366f1;
    --m-bg: #f5f5f7;
    --m-text: #1d1d1f;
    --m-text-secondary: #86868b;
    --m-border: #e5e5ea;
    --m-card-bg: #ffffff;
    --m-card-radius: 14px;
    --m-touch-min: 44px;
    --m-topbar-bg: rgba(255, 255, 255, 0.92);
    --m-tabbar-bg: rgba(255, 255, 255, 0.95);
}

/* ========================================
 * 移动端基础重置
 * ======================================== */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }

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

    body {
        background: var(--m-bg);
        padding-top: var(--m-topbar-height) !important;
        padding-bottom: calc(var(--m-tab-height) + var(--m-tab-safe-bottom)) !important;
        overscroll-behavior-y: none;
        font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Helvetica Neue', sans-serif;
    }

    /* 禁用所有hover效果（移动端无hover） */
    .card:hover,
    .post-item:hover,
    .btn-primary:hover,
    .btn-outline:hover,
    .category-tab:hover {
        transform: none !important;
        box-shadow: var(--shadow) !important;
    }

    .card:hover .card-image img {
        transform: none !important;
    }

    /* ========================================
     * 隐藏桌面端元素
     * ======================================== */
    .navbar,
    .footer,
    .navbar-right,
    .mobile-menu-toggle {
        display: none !important;
    }

    /* ========================================
     * 移动端顶部导航栏
     * ======================================== */
    .m-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--m-topbar-height);
        height: calc(var(--m-topbar-height) + env(safe-area-inset-top, 0px));
        padding-top: env(safe-area-inset-top, 0px);
        background: var(--m-topbar-bg);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 1000;
        border-bottom: 0.5px solid var(--m-border);
    }

    .m-topbar-brand {
        display: flex;
        align-items: center;
        gap: 6px;
        padding-left: 16px;
        font-size: 1.15rem;
        font-weight: 700;
        color: var(--m-primary);
        letter-spacing: -0.3px;
    }

    .m-topbar-brand img {
        height: 28px;
        width: auto;
    }

    .m-topbar-actions {
        display: flex;
        align-items: center;
        gap: 4px;
        padding-right: 8px;
    }

    .m-topbar-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--m-touch-min);
        height: var(--m-touch-min);
        border: none;
        background: transparent;
        font-size: 1.15rem;
        color: var(--m-text);
        cursor: pointer;
        border-radius: 50%;
        transition: background 0.2s;
    }

    .m-topbar-btn:active {
        background: rgba(0, 0, 0, 0.06);
    }

    .m-topbar-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        object-fit: cover;
        border: 2px solid var(--m-border);
    }

    .m-topbar-login {
        padding: 6px 16px;
        font-size: 0.85rem;
        font-weight: 600;
        color: white;
        background: var(--m-primary);
        border-radius: 20px;
        border: none;
        height: 32px;
        line-height: 20px;
    }

    /* ========================================
     * 底部Tab栏 - 核心移动导航
     * ======================================== */
    .m-tabbar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--m-tab-height);
        height: calc(var(--m-tab-height) + var(--m-tab-safe-bottom));
        padding-bottom: var(--m-tab-safe-bottom);
        background: var(--m-tabbar-bg);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 0.5px solid var(--m-border);
        z-index: 1000;
        user-select: none;
    }

    .m-tabbar::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 0.5px;
        background: var(--m-border);
    }

    .m-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 0;
        text-decoration: none;
        color: var(--m-text-secondary);
        font-size: 0.65rem;
        font-weight: 500;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }

    .m-tab i {
        font-size: 1.2rem;
        height: 24px;
        display: flex;
        align-items: center;
        transition: transform 0.2s ease;
    }

    .m-tab.active {
        color: var(--m-primary);
    }

    .m-tab.active i {
        transform: translateY(-1px) scale(1.08);
    }

    .m-tab:active i {
        transform: scale(0.92);
    }

    /* 退出登录Tab - 使用偏暖色调区分 */
    .m-tab-logout {
        color: #9ca3af;
    }

    .m-tab-logout:active {
        color: #ef4444;
    }

    /* 6个Tab时字号微调 */
    .m-tabbar .m-tab:nth-last-child(1):nth-child(6) ~ .m-tab,
    .m-tabbar:has(.m-tab:nth-child(6)) .m-tab {
        font-size: 0.6rem;
    }

    .m-tabbar:has(.m-tab:nth-child(6)) .m-tab i {
        font-size: 1.1rem;
    }

    /* Tab栏中间凸起按钮（发布/快捷操作） */
    .m-tab-center {
        position: relative;
    }

    .m-tab-center .m-tab-icon-wrapper {
        width: 44px;
        height: 44px;
        background: linear-gradient(135deg, var(--m-primary), var(--m-primary-light));
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -20px;
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
        color: white;
        font-size: 1.3rem;
    }

    .m-tab-center.active .m-tab-icon-wrapper {
        background: linear-gradient(135deg, var(--m-primary), var(--m-primary-light));
    }

    /* ========================================
     * 全屏搜索浮层
     * ======================================== */
    .m-search-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 2000;
        opacity: 0;
        transition: opacity 0.25s ease;
    }

    .m-search-overlay.show {
        display: block;
        opacity: 1;
    }

    .m-search-panel {
        background: var(--m-card-bg, white);
        padding: env(safe-area-inset-top, 0px) 16px 20px;
        transform: translateY(-100%);
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
        border-radius: 0 0 20px 20px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    }

    .m-search-overlay.show .m-search-panel {
        transform: translateY(0);
    }

    .m-search-bar {
        display: flex;
        align-items: center;
        gap: 12px;
        padding-top: 12px;
    }

    .m-search-input-wrap {
        flex: 1;
        position: relative;
        display: flex;
        align-items: center;
        background: var(--m-bg);
        border-radius: 12px;
        padding: 0 14px;
        height: 40px;
    }

    .m-search-input-wrap i {
        color: var(--m-text-secondary);
        font-size: 0.9rem;
        margin-right: 8px;
    }

    .m-search-input {
        flex: 1;
        border: none;
        background: transparent;
        font-size: 0.95rem;
        outline: none;
        height: 100%;
    }

    .m-search-input::placeholder {
        color: var(--m-text-secondary);
    }

    .m-search-cancel {
        border: none;
        background: transparent;
        font-size: 0.95rem;
        color: var(--m-primary);
        font-weight: 500;
        padding: 8px 4px;
        min-height: var(--m-touch-min);
    }

    .m-search-hot {
        padding: 16px 0 0;
    }

    .m-search-hot-title {
        font-size: 0.8rem;
        color: var(--m-text-secondary);
        margin-bottom: 10px;
    }

    .m-search-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .m-search-tag {
        padding: 6px 14px;
        background: var(--m-bg);
        border-radius: 16px;
        font-size: 0.82rem;
        color: var(--m-text);
        border: none;
        cursor: pointer;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
    }

    .m-search-tag:active {
        background: #e8e8ed;
    }

    /* ========================================
     * 移动端内容布局
     * ======================================== */
    main {
        padding: 0 !important;
    }

    .container {
        padding: 0 14px;
        max-width: 100%;
    }

    .section {
        padding: 16px 0;
    }

    .section-header {
        margin-bottom: 14px;
        padding: 0 2px;
    }

    .section-title {
        font-size: 1.15rem;
    }

    .section-title::before {
        height: 18px;
        width: 3px;
    }

    /* ========================================
     * Hero区域 - 移动端优化
     * ======================================== */
    .hero {
        padding: 30px 16px;
        border-radius: 0 0 24px 24px;
        margin-bottom: 16px;
    }

    .hero h1 {
        font-size: 1.4rem;
        margin-bottom: 8px;
        line-height: 1.35;
    }

    .hero p {
        font-size: 0.85rem;
        margin-bottom: 18px;
    }

    .hero .btn {
        padding: 10px 18px;
        font-size: 0.85rem;
        margin-bottom: 4px;
    }

    .hero-stats {
        gap: 16px;
        margin-top: 24px;
        flex-wrap: wrap;
        justify-content: space-around;
    }

    .hero-stat .number {
        font-size: 1.3rem;
    }

    .hero-stat .label {
        font-size: 0.72rem;
    }

    /* ========================================
     * 卡片网格 - 移动端2列
     * ======================================== */
    .grid-2,
    .grid-3,
    .grid-4,
    .grid-6 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .card {
        border-radius: var(--m-card-radius);
    }

    .card-image {
        padding-top: 75%;
    }

    .card-body {
        padding: 8px 10px 10px;
    }

    .card-title {
        font-size: 0.82rem;
        line-height: 1.35;
        -webkit-line-clamp: 2;
        margin-bottom: 4px;
    }

    .card-meta {
        font-size: 0.7rem;
    }

    .card-badge {
        font-size: 0.62rem;
        padding: 2px 7px;
        top: 6px;
    }

    /* ========================================
     * 分类标签 - 横向滚动
     * ======================================== */
    .category-tabs {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -14px 12px;
        padding: 0 14px;
        gap: 8px;
    }

    .category-tabs::-webkit-scrollbar {
        display: none;
    }

    .category-tab {
        white-space: nowrap;
        padding: 6px 16px;
        font-size: 0.85rem;
        border-radius: 18px;
        flex-shrink: 0;
    }

    /* ========================================
     * 帖子列表 - 移动端单列
     * ======================================== */
    .post-item {
        padding: 14px;
        margin-bottom: 10px;
        border-radius: var(--m-card-radius);
    }

    .post-avatar {
        width: 36px;
        height: 36px;
    }

    .post-title {
        font-size: 1rem;
    }

    .post-content {
        font-size: 0.85rem;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .post-stats {
        gap: 16px;
        font-size: 0.78rem;
    }

    /* ========================================
     * 会员方案 - 移动端横向滚动
     * ======================================== */
    .grid-4[style*="gap"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* ========================================
     * 分页 - 移动端简化
     * ======================================== */
    .pagination {
        gap: 4px;
        margin-top: 20px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination a,
    .pagination span {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-width: var(--m-touch-min);
        min-height: var(--m-touch-min);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ========================================
     * 按钮优化
     * ======================================== */
    .btn {
        min-height: var(--m-touch-min);
    }

    .btn-sm {
        min-height: 36px;
    }

    /* ========================================
     * 表单优化
     * ======================================== */
    .form-control {
        padding: 12px 14px;
        font-size: 16px; /* 防止iOS自动缩放 */
        border-radius: 10px;
    }

    /* ========================================
     * 详情页优化
     * ======================================== */
    .detail-header,
    .detail-body {
        padding: 16px;
        border-radius: var(--m-card-radius);
    }

    .detail-cover {
        max-height: 220px;
        border-radius: 10px;
    }

    /* ========================================
     * 会员中心 - 移动端单列
     * ======================================== */
    .member-center-info {
        flex-direction: column;
        text-align: center;
    }

    /* ========================================
     * 消息提示 - 移动端顶部居中
     * ======================================== */
    .flash-messages {
        top: calc(var(--m-topbar-height) + env(safe-area-inset-top, 0px) + 8px);
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: 90%;
        width: 360px;
    }

    .flash-message {
        padding: 12px 16px;
        font-size: 0.85rem;
        border-radius: 12px;
    }

    /* ========================================
     * 广告解锁页
     * ======================================== */
    .ad-container {
        padding: 20px;
        border-radius: var(--m-card-radius);
    }

    .ad-timer {
        font-size: 2.2rem;
    }

    /* ========================================
     * 移动端遮罩层（点击搜索外部关闭）
     * ======================================== */
    .m-overlay-mask {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: transparent;
        z-index: 999;
    }

    /* ========================================
     * 超小屏幕适配 (iPhone SE 320px)
     * ======================================== */
    @media (max-width: 360px) {
        .m-topbar-brand {
            font-size: 1rem;
        }

        .m-tab {
            font-size: 0.6rem;
        }

        .m-tab i {
            font-size: 1.05rem;
        }

        .card-title {
            font-size: 0.75rem;
        }

        .container {
            padding: 0 10px;
        }
    }

    /* ========================================
     * 大屏手机/小平板 (481px - 768px)
     * ======================================== */
    @media (min-width: 481px) and (max-width: 768px) {
        .grid-2,
        .grid-3,
        .grid-4,
        .grid-6 {
            grid-template-columns: repeat(3, 1fr) !important;
            gap: 12px !important;
        }

        .card-title {
            font-size: 0.88rem;
        }

        .hero h1 {
            font-size: 1.6rem;
        }
    }

    /* ========================================
     * 横屏适配
     * ======================================== */
    @media (max-width: 768px) and (orientation: landscape) {
        .m-tabbar {
            height: 48px;
        }

        .m-tab i {
            font-size: 1.05rem;
            height: 20px;
        }

        .m-tab span {
            display: none;
        }

        body {
            padding-bottom: 48px !important;
        }
    }
}

/* ========================================
 * 桌面端隐藏移动元素
 * ======================================== */
@media (min-width: 769px) {
    .m-topbar,
    .m-tabbar,
    .m-search-overlay {
        display: none !important;
    }
}

/* ========================================
 * 外部链接访问器 - 移动端适配
 * ======================================== */
@media (max-width: 768px) {
    /* 外部链接窗口不遮住底部Tab栏，用户可随时切换 */
    .ext-link-overlay {
        bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }
    .ext-link-toolbar {
        height: 48px;
        padding: 0 10px;
    }
    .ext-link-title {
        font-size: 0.8rem;
        max-width: 100px;
    }
    .ext-link-actions {
        gap: 6px;
    }
    .ext-link-btn {
        padding: 5px 10px;
        font-size: 0.72rem;
    }
    .ext-link-btn i {
        font-size: 0.8rem;
    }
    .ext-link-blocked i {
        font-size: 2.5rem;
    }
    .ext-link-blocked h3 {
        font-size: 1.1rem;
    }
    .ext-link-blocked p {
        font-size: 0.85rem;
    }
    .ext-link-blocked-btn {
        padding: 10px 24px;
        font-size: 0.9rem;
    }
    .ext-link-hint {
        font-size: 0.7rem;
        padding: 6px 10px;
    }
}
