/* ==========================================================================
   MOBILE RESPONSIVE — KeyMarket 移动端适配
   断点: 1024px(平板横屏) / 768px(平板竖屏+侧边栏折叠) / 480px(手机)
   ========================================================================== */

/* ==========================================================================
   [1] 全局重置
   ========================================================================== */
@media (max-width: 768px) {
    html, body {
        -webkit-tap-highlight-color: transparent;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================================================
   [2] ADMIN 侧边栏 → 汉堡菜单覆盖层
   所有 admin 模板内联的 .layout / .sidebar / .main-content 在此统一覆盖
   ========================================================================== */
@media (max-width: 768px) {
    body.admin-page .layout {
        display: block !important;
        height: auto !important;
        min-height: 100vh !important;
        position: relative !important;
    }

    /* 主内容区占满全屏 */
    body.admin-page .main-content {
        padding: 20px 16px 100px 16px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* 侧边栏：固定覆盖层，默认滑出屏幕 */
    body.admin-page .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px !important;
        max-width: 85vw !important;
        z-index: 9999 !important;
        transform: translateX(-100%);
        transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 4px 0 40px rgba(0,0,0,0.3) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* 侧边栏打开 */
    body.admin-page.sidebar-open .sidebar {
        transform: translateX(0);
    }

    /* 遮罩层 */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 9998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 280ms cubic-bezier(0.16, 1, 0.3, 1);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }
    body.admin-page.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* 汉堡按钮 */
    .hamburger-btn {
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 9997;
        width: 42px;
        height: 42px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.25);
        border: 1px solid rgba(255, 130, 185, 0.35);
        box-shadow: 0 4px 14px rgba(255, 95, 162, 0.12), inset 0 1px 0 rgba(255,255,255,0.4);
        display: none;  /* JS 里 admin 页面才显示 */
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        cursor: pointer;
        transition: all 180ms;
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
    }
    .hamburger-btn:active {
        transform: scale(0.94);
        background: rgba(255, 255, 255, 0.45);
    }
    .hamburger-btn span {
        display: block;
        width: 20px;
        height: 2.2px;
        border-radius: 2px;
        background: #4a2038;
        transition: all 200ms;
    }
    /* 打开态动画：变成 X */
    body.admin-page.sidebar-open .hamburger-btn span:nth-child(1) {
        transform: translateY(7.2px) rotate(45deg);
    }
    body.admin-page.sidebar-open .hamburger-btn span:nth-child(2) {
        opacity: 0;
    }
    body.admin-page.sidebar-open .hamburger-btn span:nth-child(3) {
        transform: translateY(-7.2px) rotate(-45deg);
    }

    /* 页面标题下移，给汉堡按钮让位 */
    body.admin-page .page-title {
        padding-left: 48px !important;
        margin-top: 4px !important;
        font-size: 20px !important;
    }
}

/* 平板横屏时侧边栏缩小 */
@media (min-width: 769px) and (max-width: 1024px) {
    body.admin-page .sidebar {
        width: 200px !important;
    }
    body.admin-page .main-content {
        padding: 24px 24px !important;
    }
}

/* ==========================================================================
   [3] 用户端顶部导航折叠
   ========================================================================== */
@media (max-width: 768px) {
    /* 用户页面导航栏 */
    .nav {
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
    }
    .nav-inner {
        padding: 0 14px !important;
        height: 56px !important;
        flex-wrap: nowrap !important;
    }
    .nav-brand {
        font-size: 17px !important;
        flex-shrink: 0;
    }

    /* 导航链接区域：缩成汉堡下拉 */
    .nav-links {
        gap: 4px !important;
        flex-wrap: nowrap !important;
        overflow: hidden;
    }
    /* 手机端只显示少量关键项，其余进汉堡 */
    .nav-links > a, .nav-links > button:not(.nav-more-btn) {
        font-size: 11px !important;
        padding: 6px 8px !important;
        white-space: nowrap;
    }
    /* 隐藏次要链接（通过 JS 或 CSS 做 "更多" 菜单） */
    .nav-links.collapsed > *:not(.nav-essential):not(.nav-more-btn) {
        display: none;
    }

    /* 用户导航汉堡按钮 */
    .nav-more-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: var(--pk-glass, rgba(255,255,255,0.22));
        border: 1px solid var(--pk-stroke, rgba(255,130,185,0.35));
        cursor: pointer;
        font-size: 18px;
        flex-shrink: 0;
        color: #4a2038;
        transition: all 150ms;
    }
    .nav-more-btn:active {
        background: rgba(255,255,255,0.45);
    }
}

/* 手机端进一步收缩 */
@media (max-width: 480px) {
    .nav-inner {
        padding: 0 10px !important;
        height: 50px !important;
    }
    .nav-brand {
        font-size: 15px !important;
    }
    .nav-links > a, .nav-links > button:not(.nav-more-btn) {
        font-size: 10px !important;
        padding: 5px 6px !important;
    }
}

/* ==========================================================================
   [4] 统计卡片 Grid 降级
   ========================================================================== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
}
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    .stat-card {
        padding: 14px 16px !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 12px !important;
    }
    .stat-card .stat-icon {
        font-size: 24px !important;
        flex-shrink: 0;
    }
    .stat-card .stat-value {
        font-size: 22px !important;
        text-align: right;
        flex: 1;
    }
    .stat-card .stat-label {
        font-size: 10px !important;
        text-align: right;
    }
    .stat-card::before {
        display: none;
    }
}

/* ==========================================================================
   [5] 双栏布局 → 单栏
   ========================================================================== */
@media (max-width: 768px) {
    /* 任何使用 grid-template-columns: 1fr 1fr 的双栏卡片区域 */
    .card[style*="1fr 1fr"],
    div[style*="1fr 1fr"],
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
}

/* ==========================================================================
   [6] 表格横向滚动
   ========================================================================== */
@media (max-width: 768px) {
    /* 为所有含表格的卡片添加横向滚动区域 */
    .card > table,
    .key-table-wrap,
    table.doc-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    .card > table table,
    .key-table-wrap table,
    table.doc-table table {
        min-width: 600px;
    }
    thead th {
        padding: 10px 12px !important;
        font-size: 10px !important;
    }
    tbody td {
        padding: 10px 12px !important;
        font-size: 12px !important;
    }

    /* 确保表格外层有滚动 */
    .key-table-wrap {
        max-height: none !important;
        overflow-x: auto !important;
    }
}

/* ==========================================================================
   [7] 商店模型卡片 Grid
   ========================================================================== */
@media (max-width: 900px) {
    .model-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 14px !important;
    }
}
@media (max-width: 560px) {
    .model-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .model-card {
        padding: 20px !important;
    }
    .model-card .model-name {
        font-size: 16px !important;
    }
    .model-card .price {
        font-size: 24px !important;
    }
}

/* ==========================================================================
   [8] 容器间距缩窄
   ========================================================================== */
@media (max-width: 768px) {
    .container {
        padding: 16px 14px 40px !important;
        max-width: 100% !important;
    }
}
@media (max-width: 480px) {
    .container {
        padding: 12px 10px 32px !important;
    }
}

/* ==========================================================================
   [9] 弹窗全屏化
   ========================================================================== */
@media (max-width: 480px) {
    .modal-overlay {
        padding: 8px !important;
        align-items: flex-end !important;  /* 底部弹出更方便拇指操作 */
    }
    .modal-box {
        max-width: 100% !important;
        width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 20px 16px 28px !important;
        max-height: 85vh !important;
        animation: slideUpMobile 300ms cubic-bezier(0.16, 1, 0.3, 1) !important;
    }
    @keyframes slideUpMobile {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* ==========================================================================
   [10] 按钮和表单
   ========================================================================== */
@media (max-width: 480px) {
    .btn {
        padding: 8px 14px !important;
        font-size: 13px !important;
        border-radius: 10px !important;
    }
    .btn-lg {
        padding: 12px 24px !important;
        font-size: 14px !important;
    }
    .btn-sm {
        padding: 6px 10px !important;
        font-size: 11px !important;
    }
    .input, input, textarea, select {
        padding: 10px 12px !important;
        font-size: 14px !important;  /* 防 iOS 缩放 */
        border-radius: 10px !important;
    }
    .flex-row {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .flex-row select,
    .flex-row .input {
        min-width: 0 !important;
        flex: 1 1 auto !important;
    }
}

/* ==========================================================================
   [11] 登录/注册页
   ========================================================================== */
@media (max-width: 768px) {
    .login-left {
        display: none !important;
    }
    .login-bg {
        grid-template-columns: 1fr !important;
    }
    .login-card, .reg-card,
    .glass-shell {
        width: 100% !important;
        max-width: 100% !important;
        padding: 24px 20px !important;
        border-radius: 20px !important;
    }
    .reg-bg {
        padding: 20px !important;
    }
    .lede h1 {
        font-size: 32px !important;
    }
    .lede p.sub {
        font-size: 14px !important;
    }
}

/* ==========================================================================
   [12] Landing 首页
   ========================================================================== */
@media (max-width: 480px) {
    .landing {
        padding: 16px !important;
    }
    .glass-shell {
        padding: 16px 14px 24px !important;
        border-radius: 20px !important;
    }
    .shell-top {
        margin-bottom: 24px !important;
    }
    .brand-block .brand-title {
        font-size: 18px !important;
        letter-spacing: 2px !important;
    }
    .lede h1 {
        font-size: 28px !important;
    }
    .cta-row {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .cta {
        width: 100% !important;
        text-align: center !important;
        justify-content: center !important;
    }
    .feature-list {
        grid-template-columns: 1fr !important;
    }
    .shell-body {
        gap: 20px !important;
    }
}

/* ==========================================================================
   [13] 图表容器
   ========================================================================== */
@media (max-width: 768px) {
    .chart-box {
        max-height: 220px !important;
    }
    .chart-box canvas {
        max-height: 220px !important;
    }
}
@media (max-width: 480px) {
    .chart-box {
        max-height: 180px !important;
    }
    .chart-box canvas {
        max-height: 180px !important;
    }
}

/* ==========================================================================
   [14] 联系作者 footer & 客服 FAB
   ========================================================================== */
@media (max-width: 480px) {
    .author-contact {
        left: 6px !important;
        right: 6px !important;
        bottom: 8px !important;
    }
    .author-contact-inner {
        padding: 8px 10px !important;
        gap: 6px !important;
    }
    .author-contact-note {
        max-width: 150px !important;
        font-size: 11px !important;
    }
    .contact-icon-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 10px !important;
    }
    .support-fab {
        right: 8px !important;
        bottom: 72px !important;
        min-width: 100px !important;
        height: 38px !important;
        padding: 0 10px !important;
        font-size: 12px !important;
        border-radius: 10px !important;
    }
}

/* ==========================================================================
   [15] 用户仪表盘元信息网格
   ========================================================================== */
@media (max-width: 480px) {
    .meta {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .quick-actions {
        flex-direction: column !important;
    }
    .quick-actions .btn {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* ==========================================================================
   [16] Toast 提示
   ========================================================================== */
@media (max-width: 480px) {
    .toast {
        top: 8px !important;
        right: 8px !important;
        left: 8px !important;
        min-width: 0 !important;
        font-size: 13px !important;
        padding: 12px 16px !important;
    }
}

/* ==========================================================================
   [17] 深色模式移动端补充
   ========================================================================== */
@media (max-width: 768px) {
    [data-theme="dark"] .sidebar-backdrop {
        background: rgba(0, 0, 0, 0.7);
    }
    [data-theme="dark"] .hamburger-btn {
        background: rgba(30, 41, 59, 0.8) !important;
        border-color: rgba(99, 102, 241, 0.3) !important;
    }
    [data-theme="dark"] .hamburger-btn span {
        background: #e2e8f0;
    }
}

/* ==========================================================================
   [18] 性能优化 — 移动端减少视觉效果
   ========================================================================== */
@media (max-width: 480px) {
    /* 减少樱花粒子数量由 bg-tech.js 处理；此处降级背景计算量 */
    body {
        background-attachment: scroll !important;
    }
    /* 减少模糊叠加层 */
    .card, .stat-card, .modal-box {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    /* 弱化 hover 动画（触屏没有 hover） */
    .card:hover, .stat-card:hover {
        transform: none !important;
    }
}

/* ==========================================================================
   [19] 搜索/筛选行
   ========================================================================== */
@media (max-width: 600px) {
    .flex-row select,
    .flex-row .input {
        width: 100% !important;
        min-width: 0 !important;
    }
    .flex-row {
        flex-direction: column !important;
    }
}

/* ==========================================================================
   [20] 用户导航下拉菜单（更多菜单）
   ========================================================================== */
.nav-dropdown {
    position: absolute;
    top: 56px;
    right: 8px;
    z-index: 200;
    min-width: 180px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 130, 185, 0.3);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.15);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 2px;
}
.nav-dropdown.show {
    display: flex;
}
.nav-dropdown a,
.nav-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: #4a2038;
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms;
    text-align: left;
    width: 100%;
}
.nav-dropdown a:hover,
.nav-dropdown button:hover {
    background: rgba(255, 95, 162, 0.08);
}
.nav-dropdown-backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
    display: none;
}
.nav-dropdown-backdrop.show {
    display: block;
}

/* ==========================================================================
   [21] Key 卡片网格（用户我的 Key 页面）
   ========================================================================== */
@media (max-width: 768px) {
    .key-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
    .key-card {
        padding: 18px !important;
    }
    .key-card .key-value {
        font-size: 11px !important;
        padding: 8px 10px !important;
    }
    .key-card .balance {
        font-size: 20px !important;
    }
}

/* ==========================================================================
   [22] 客服聊天页面
   ========================================================================== */
@media (max-width: 600px) {
    .chat-messages {
        height: min(50vh, 400px) !important;
    }
    .chat-send {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .chat-send textarea {
        height: 60px !important;
    }
    .bubble {
        max-width: 92% !important;
        font-size: 12px !important;
    }
}

/* ==========================================================================
   [23] 订单通知徽章（移动端位置调整）
   ========================================================================== */
@media (max-width: 480px) {
    #order-badge {
        position: fixed !important;
        top: 14px !important;
        right: 60px !important;
        z-index: 101 !important;
    }
}

/* ==========================================================================
   [24] Hero 区域
   ========================================================================== */
@media (max-width: 480px) {
    .hero {
        padding: 20px 0 16px !important;
    }
    .hero h2 {
        font-size: 22px !important;
    }
    .hero p {
        font-size: 13px !important;
    }
    .page-title {
        font-size: 20px !important;
        margin-bottom: 16px !important;
    }
    .section-title {
        font-size: 16px !important;
        margin-bottom: 12px !important;
    }
}
