/* ========================================
   昭新EDA - 手机端 / 平板适配样式
   加载在所有页面 style.css 与内联样式之后
   覆盖为窄屏优化的布局
   ======================================== */

/* 移动端菜单里由 JS 追加的登录/控制台操作按钮行 */
.mobile-auth-row { display: none; }

/* ========================================
   ≤900px：平板竖屏 / 小平板 / 大屏手机
   提前启用汉堡菜单，避免中段宽度导航溢出
   ======================================== */
@media (max-width: 900px) {
    .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-card);
        flex-direction: column;
        padding: 20px;
        border-bottom: 1px solid var(--border-color);
        gap: 6px;
        max-height: calc(100vh - 70px);
        overflow-y: auto;
        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    }
    .nav-menu.active { display: flex; }
    .nav-actions .btn { display: none; }
    .mobile-toggle { display: flex; }
    .nav-container { padding: 12px 16px; }

    /* 移动下拉菜单底部的操作按钮行 */
    .mobile-auth-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding-top: 14px;
        margin-top: 12px;
        border-top: 1px solid var(--border-color);
    }
    .mobile-auth-row .btn {
        display: flex !important;
        width: 100%;
        padding: 11px 8px;
        font-size: 14px;
    }
    .mobile-auth-row .btn-primary { box-shadow: none; }
}

/* ========================================
   ≤768px：手机 + 小平板通用
   ======================================== */
@media (max-width: 768px) {
    /* 防止 iOS 聚焦输入框时自动放大页面 */
    input[type="text"], input[type="password"], input[type="email"],
    input[type="tel"], input[type="number"], input[type="search"],
    select, textarea { font-size: 16px; }

    .section-header { margin-bottom: 36px; }
    .section-title { font-size: 26px; }
    .section-subtitle { font-size: 15px; }
    .page-subtitle { font-size: 16px; }
    .page-title { font-size: 32px; }

    /* 区块纵向留白压缩 */
    .features-section, .workflow-section, .ai-section, .testimonials,
    .cta-section, .feature-detail, .mission-section, .values-section,
    .team-section, .timeline-section, .rules-section, .faq-section { padding: 56px 0; }

    .hero { padding: calc(90px + var(--announce-offset, 0px)) 0 48px; }
    .hero-actions { margin-bottom: 40px; }
    .hero-stats { margin-bottom: 48px; }
    .stat-item { min-width: 0; }
    .stat-value { font-size: 30px; }
    .stat-suffix { font-size: 20px; }

    /* 展示窗口高度降低，Tab 允许横向滑动 */
    .window-content { min-height: 260px; }
    .showcase-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; justify-content: flex-start; padding-bottom: 4px; }
    .showcase-tabs .tab-btn { flex: none; white-space: nowrap; }
    .window-title { font-size: 12px; }
    .window-status { display: none; }

    .chat-window { height: 60vh; min-height: 420px; }

    .footer { padding: 44px 0 24px; }
    .legal-page { padding: 110px 0 50px; }

    /* toast 适配窄屏 */
    .toast-container { left: 12px; right: 12px; top: 12px; }
    .toast { min-width: 0; width: 100%; }

    /* 在线演示 */
    .demo-main { height: 60vh; min-height: 0; }
    .demo-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .demo-tabs .tab { flex: none; white-space: nowrap; }

    /* 注册/登录卡片 */
    .auth-page { padding: 90px 14px 30px; align-items: flex-start; overflow-y: auto; }
    .auth-page::before { position: fixed; }

    /* 充值/控制台通用面板 */
    .panel, .admin-panel { padding: 18px; }
    .panel-header { flex-wrap: wrap; gap: 10px; }

    /* 弹窗通用 */
    .modal { padding: 22px 18px; }
    .modal-actions { flex-wrap: wrap; }
    .modal-actions .btn-cancel, .modal-actions .btn-primary { flex: 1; min-width: 120px; }
    #refundModal .modal-actions .btn { flex: 1 1 100%; }
}

/* ========================================
   ≤600px：常规手机
   ======================================== */
@media (max-width: 600px) {
    .container { padding: 0 16px; }

    .section-title { font-size: 24px; }
    .page-title { font-size: 28px; }

    .hero-title { font-size: 36px; }
    .hero-subtitle { font-size: 15px; }
    .hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .hero-actions .btn-lg { padding: 12px 8px; font-size: 14px; }
    .cta-actions .btn-lg { padding: 12px 20px; font-size: 14px; }

    .about-hero h1 { font-size: 34px; }
    .about-hero p { font-size: 16px; }
    .mission-content h2 { font-size: 28px; }
    .mission-visual { font-size: 80px; }

    .chat-window { height: 62vh; }
    .feature-icon { width: 48px; height: 48px; }

    .pay-model-bar { border-radius: 14px; padding: 12px 16px; text-align: center; }
    .price-value { font-size: 36px; }
    .price-card { padding: 26px 18px; }
    .rule-card { padding: 20px 16px; }

    .footer-grid { gap: 24px; }
    .footer-col h4 { margin-bottom: 12px; }
}

/* ========================================
   ≤480px：小屏手机
   ======================================== */
@media (max-width: 480px) {
    .section-header { margin-bottom: 28px; }
    .section-title { font-size: 22px; letter-spacing: 0; }
    .section-tag { font-size: 12px; padding: 5px 12px; }

    .hero-title { font-size: 32px; }
    .hero-badge { font-size: 12px; padding: 5px 12px; }
    .stat-value { font-size: 26px; }
    .stat-label { font-size: 12px; }

    .window-content { min-height: 200px; }
    .tab-btn { padding: 6px 12px; font-size: 12px; }
    .chat-window { height: 65vh; min-height: 380px; }
    .chat-messages { padding: 14px; }
    .message { max-width: 92%; }

    .page-header { padding: calc(110px + var(--announce-offset, 0px)) 0 40px; }
    .page-title { font-size: 24px; }

    .demo-main { height: 55vh; }
    .demo-stage { padding: calc(90px + var(--announce-offset, 0px)) 0 40px; }
    .demo-stage h1 { font-size: 26px !important; }

    /* 注册表单：验证码按钮换行、内边距收紧 */
    .auth-form-side { padding: 30px 18px !important; }
    .auth-title { font-size: 24px !important; }
    .wx-card { padding: 28px 20px 24px !important; }
    .wx-field { gap: 8px; }
    .wx-qr-box { width: 180px; height: 180px; }
    .wx-code-btn { padding: 0 10px; font-size: 13px; white-space: nowrap; }

    /* 充值页 */
    .balance-card { padding: 20px 16px; }
    .balance-value { font-size: 34px; }
    .balance-right { gap: 8px; flex-wrap: wrap; }
    .balance-item { flex: 1 1 45%; }
    .ledger-info { flex: 0 0 140px; }
    .ledger-amount { flex: 0 0 76px; font-size: 14px; }
    .recharge-plans { gap: 10px; }
    .recharge-plan { padding: 14px 6px; }

    .toast { font-size: 13px; padding: 10px 14px; }

    /* 法律页 */
    .legal-wrap { padding: 26px 18px; }
    .legal-wrap h1 { font-size: 22px; }
    .legal-wrap h2 { font-size: 16px; }

    /* 管理后台操作按钮/搜索框铺满 */
    .admin-tools input[type="text"], .admin-tools select { width: 100%; }
    .admin-tools { width: 100%; }
    .admin-tools .btn { flex: 1 1 auto; }
    .admin-header h2 { font-size: 18px; }
}

/* ========================================
   ≤380px：iPhone SE / 小安卓
   ======================================== */
@media (max-width: 380px) {
    .hero-title { font-size: 28px; }
    .hero-subtitle { font-size: 14px; }
    .hero-actions { grid-template-columns: 1fr; }
    .hero-actions .btn-lg { font-size: 15px; }

    .price-value { font-size: 32px; }
    .offline-bank-row span { flex: 0 0 72px; font-size: 13px; }

    .demo-tabs .tab { font-size: 12px; }
}

/* ========================================
   管理后台（admin.html）
   ======================================== */
@media (max-width: 900px) {
    /* 侧栏折叠为可横向换行的“胶囊”快捷栏 */
    .admin-sidebar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
        width: 100%;
        margin-bottom: 14px;
        padding: 0;
        position: static;
        max-height: none;
        overflow: visible;
    }
    .admin-sidebar .sidebar-group {
        display: contents;
    }
    .admin-sidebar .sidebar-group + .sidebar-group {
        margin: 0;
        padding: 0;
        border: none;
    }
    .admin-sidebar .sidebar-group-title { display: none; }
    .admin-sidebar .admin-tab {
        display: inline-flex;
        width: auto;
        padding: 7px 14px;
        margin: 0;
        border: 1px solid var(--border-color);
        border-radius: 999px;
        background: var(--bg-secondary);
        color: var(--text-secondary);
        font-size: 13px;
        font-weight: 500;
        white-space: nowrap;
    }
    .admin-sidebar .admin-tab.active {
        background: rgba(13,148,136,.12);
        color: var(--primary);
        border-color: var(--primary);
        box-shadow: none;
    }
}

@media (max-width: 768px) {
    /* 子页签改为横向可滚动，避免被固定 7 列网格挤压 */
    .admin-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
    }
    .admin-tabs .admin-tab {
        flex: none;
        white-space: nowrap;
        padding: 8px 14px;
        font-size: 13px;
        border: 1px solid var(--border-color);
        border-bottom: none;
        border-radius: 10px 10px 0 0;
        background: transparent;
    }
    .admin-tabs .admin-tab.active {
        background: var(--bg-secondary);
        color: var(--primary);
    }

    /* 模型管理表强制可横向滚动（原内联 overflow-x:hidden 会裁切操作列） */
    #tab-models .admin-table-wrap { overflow-x: auto !important; }

    /* 口令确认弹窗在窄屏不超出视口 */
    #adminPinModal, #sensitivePinModal {
        width: 380px;
        max-width: 92vw;
    }

    .summary-cards { gap: 10px; }
    .sub-title { font-size: 14px; }
}

/* ========================================
   工作台（dashboard.html）
   ======================================== */
@media (max-width: 768px) {
    /* 账户设置行：窄屏允许换行，长 ID/手机号自动断行 */
    .account-row { flex-wrap: wrap; }
    .account-row > div { flex-wrap: wrap; }
    .account-row .value code { word-break: break-all; }

    .project-grid { grid-template-columns: 1fr 1fr; }
    .project-info { padding: 10px; }
    .panel table { max-width: 100%; }
}

/* ========================================
   控制台/管理后台 - 窄屏宽表格“卡片化”
   由 js/mobile-tables.js 自动为放不下的表格加 .mob-cards
   扩展到 1024px 触控设备，兼容手机“桌面版网站”模式
   ======================================== */
@media (max-width: 1024px) and (hover: none), (max-width: 1024px) and (pointer: coarse), (max-width: 900px) {
    /* 数据表转卡片：整页只上下滚动，无需横向滑动 */
    table.mob-cards {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        table-layout: auto !important;
    }
    table.mob-cards thead { display: none; }
    table.mob-cards tbody { display: block; width: 100%; }
    table.mob-cards > tbody > tr {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        align-items: start;
        gap: 10px 16px;
        margin: 0 0 12px;
        padding: 12px 14px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
    }
    table.mob-cards > tbody > tr:last-child { margin-bottom: 0; }
    table.mob-cards td {
        display: flex;
        flex-direction: column;
        gap: 3px;
        min-width: 0;
        padding: 0;
        border: none;
        background: transparent !important;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
        text-align: left;
        vertical-align: top;
        font-size: 13px;
        line-height: 1.45;
    }
    table.mob-cards td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        letter-spacing: .2px;
        color: var(--text-secondary);
        line-height: 1.2;
    }
    /* 空单元格隐藏，避免出现孤零零的列名 */
    table.mob-cards td.m-empty { display: none; }
    /* 长 ID / 代码 / 长文本全部可断行 */
    table.mob-cards td code { word-break: break-all; }
    table.mob-cards td span { white-space: normal !important; }
    table.mob-cards td img,
    table.mob-cards td canvas,
    table.mob-cards td video { max-width: 100%; height: auto; }
    table.mob-cards td .status-pill,
    table.mob-cards td .badge { display: inline-flex; align-items: center; }
    /* 操作列：列名独占一行，按钮同行自动换行 */
    table.mob-cards td.m-ops {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
    }
    table.mob-cards td.m-ops::before { flex: 1 1 100%; }
    table.mob-cards td.m-ops > button,
    table.mob-cards td.m-ops .op-btn { margin: 0; }
    /* 加载中 / 空数据等整行占位 */
    table.mob-cards > tbody > tr:has(> td[colspan]) { display: block; text-align: center; }
    table.mob-cards td[colspan] { display: block; padding: 12px 4px; }
    table.mob-cards td[colspan]::before { display: none; }

    /* 内容区子页签允许自动换行，不再要求横向滑动 */
    .admin-tabs { flex-wrap: wrap; overflow-x: visible; }
    .admin-tabs .admin-tab { flex: 0 1 auto; }
    .admin-panel { padding: 14px; }
}

@media (max-width: 700px) {
    /* 顶部工具条占满宽度、输入框自适应 */
    .admin-tools { width: 100%; }
    .admin-tools input[type="text"],
    .admin-tools select { flex: 1 1 150px; min-width: 0; width: auto; }
    .admin-header h2 { font-size: 17px; }
    .admin-header { gap: 10px; }

    /* 费率管理：右侧固定 440px 的区域改为纵向铺满 */
    .rate-row { flex-direction: column; align-items: stretch; padding: 14px; }
    .rate-row-left { flex: none; width: 100%; }
    .rate-row-right {
        min-width: 0 !important;
        width: 100%;
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .rate-row-right .rate-input {
        width: 100% !important;
        max-width: none;
        box-sizing: border-box;
    }
    .rate-row-right .rate-x { align-self: flex-start; margin-bottom: -4px; }
}

/* ========================================
   触控设备/桌面版网站模式兜底
   针对 admin.html / dashboard.html 里的内联桌面样式做强制覆盖，
   确保手机端（包括被浏览器强制放大到 980px 的“电脑版”模式）
   整页只上下滚动、无需左右滑动。
   ======================================== */
@media (max-width: 1024px) and (hover: none), (max-width: 1024px) and (pointer: coarse), (max-width: 900px) {
    /* --- admin.html 布局 --- */
    .admin-layout { flex-direction: column !important; gap: 16px !important; }
    .admin-sidebar {
        display: flex !important; flex-wrap: wrap !important; gap: 6px !important;
        width: 100% !important; flex: none !important; position: static !important;
        max-height: none !important; overflow: visible !important; padding: 0 !important;
    }
    .admin-sidebar .sidebar-group { display: contents !important; margin: 0 !important; padding: 0 !important; border: none !important; }
    .admin-sidebar .sidebar-group + .sidebar-group { margin: 0 !important; padding: 0 !important; border: none !important; }
    .admin-sidebar .sidebar-group-title { display: none !important; }
    .admin-sidebar .admin-tab {
        display: inline-flex !important; width: auto !important;
        padding: 7px 14px !important; margin: 0 !important;
        border: 1px solid var(--border-color) !important; border-radius: 999px !important;
        background: var(--bg-secondary) !important; white-space: nowrap !important;
        text-align: center !important;
    }
    .admin-sidebar .sidebar-group.collapsed .admin-tab { display: inline-flex !important; }
    .admin-content { min-width: 0 !important; width: 100% !important; }
    .admin-panel { padding: 18px !important; min-width: 0 !important; }
    .admin-header { flex-wrap: wrap !important; gap: 10px !important; }
    .admin-header h2 { font-size: 17px !important; }
    .admin-tools { width: 100% !important; flex-wrap: wrap !important; gap: 8px !important; }
    .admin-tools input[type="text"], .admin-tools select { flex: 1 1 150px !important; min-width: 0 !important; width: auto !important; }

    /* 子页签：把内联的 7 列 grid 改成可换行 flex，防止撑出整页滚动条 */
    .admin-tabs {
        display: flex !important; flex-wrap: wrap !important; gap: 6px !important;
        overflow-x: visible !important; border-bottom: none !important;
        grid-template-columns: none !important;
    }
    .admin-tab { flex: 0 1 auto !important; white-space: normal !important; }

    /* 概览卡片：固定 2 列或自适应，避免 minmax(170px) 在 980px 桌面版模式下排成多列 */
    .summary-cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; gap: 10px !important; }

    /* 供应商余额卡片：覆盖内联 flex:1 1 200px; min-width:200px */
    #overviewBalanceCards, #aiBalanceCards {
        display: grid !important; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; gap: 10px !important;
    }
    #overviewBalanceCards > div, #aiBalanceCards > div { min-width: 0 !important; max-width: none !important; width: 100% !important; flex: none !important; }

    /* 图表/表格容器：禁止出现横向滚动条 */
    .admin-table-wrap { overflow-x: visible !important; min-width: 0 !important; }
    #overviewTrendBox canvas, #aiTrendBox canvas, .admin-table-wrap canvas { max-width: 100% !important; height: auto !important; }

    /* 数据表：在卡片化之前先阻止内联 nowrap 撑宽页面 */
    table.admin-table { min-width: 0 !important; table-layout: auto !important; width: 100% !important; }
    .admin-table th, .admin-table td { white-space: normal !important; word-break: break-word !important; }

    /* --- dashboard.html 布局 --- */
    .dashboard-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
    .dashboard-sidebar { position: static !important; width: 100% !important; padding: 16px !important; }
    .dashboard-content { min-width: 0 !important; width: 100% !important; }
    .welcome-banner { flex-wrap: wrap !important; gap: 12px !important; }
    .stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; gap: 10px !important; }
    .stat-card { min-width: 0 !important; padding: 16px !important; }
    .stat-card .value { font-size: 22px !important; }
    .panel { padding: 18px !important; min-width: 0 !important; }
    .panel-header { flex-wrap: wrap !important; gap: 10px !important; }
    .panel-tabs { flex-wrap: wrap !important; gap: 10px !important; }
    .project-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; gap: 12px !important; }
    .account-row { flex-wrap: wrap !important; gap: 6px !important; align-items: flex-start !important; }

    /* dashboard 表格 */
    .order-table-wrap { overflow-x: visible !important; min-width: 0 !important; }
    .order-table-wrap .order-table, .order-table-wrap .usage-table, .ledger-table { min-width: 0 !important; table-layout: auto !important; width: 100% !important; }
    .order-table th, .order-table td, .usage-table th, .usage-table td, .ledger-table th, .ledger-table td { white-space: normal !important; word-break: break-word !important; }
}
