/* ============================================================
   mobile.css - 移动端优化（底部 Tab、安全区、触控、响应式布局）
   ============================================================ */

/* 商户端底部 Tab（悬浮玻璃胶囊，仅移动端显示） */
.tabbar {
    position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 12px; right: 12px;
    display: flex;
    background: rgba(255,255,255,.8);
    backdrop-filter: blur(22px) saturate(180%); -webkit-backdrop-filter: blur(22px) saturate(180%);
    border: 1px solid rgba(255,255,255,.7); border-radius: 20px;
    box-shadow: 0 10px 34px rgba(40,55,110,.16);
    z-index: 40;
}
.tabbar a {
    flex: 1; text-align: center; padding: 9px 0 7px;
    font-size: 11px; color: var(--text-secondary); line-height: 1.3;
    text-decoration: none;
}
.tabbar a::first-letter { font-size: 20px; }
.tabbar a span { display: block; }
.tabbar a.active { color: var(--primary); font-weight:600; }
/* 中间突出的收银按钮 —— 完整圆形，图标+文字都在圆内 */
.tabbar-center { position: relative; font-size: 0 !important; padding-top: 4px !important; }
.tabbar-center::before {
    content: ''; position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
    width: 58px; height: 58px; border-radius: 50%;
    background: linear-gradient(135deg,var(--primary),var(--primary-2));
    border: 3px solid rgba(255,255,255,.95); box-shadow: 0 6px 18px var(--primary-glow); z-index: 1;
}
.tabbar-center::after {
    content: '💳'; position: absolute; top: -19px; left: 50%; transform: translateX(-50%);
    font-size: 20px; z-index: 2; line-height: 1;
}
.tabbar-center span {
    position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
    font-size: 10px !important; color: #fff; z-index: 2; display: block; font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.tabbar-center.active span { color: #fff; }

/* 移动端内容区给底部 Tab 留出空间（含中间凸起圆钮 + 悬浮间距 + 呼吸量） */
.merchant-content { padding-bottom: 96px !important; }

/* 桌面端隐藏底部 Tab */
@media (min-width: 1024px) {
    .tabbar { display: none; }
    .merchant-content { padding-bottom: 16px !important; }
}

/* ============================================================
   移动端响应式布局适配（屏幕 < 768px）
   ============================================================ */
@media (max-width: 767px) {
    /* 页面头部：按钮换行 */
    .page-header {
        flex-wrap: wrap; gap: 8px; padding: 12px 16px;
    }
    .page-header h2 { font-size: 18px; margin: 0; }
    .page-header .btn { font-size: 13px; padding: 6px 12px; }

    /* 卡片内边距缩小 */
    .card { border-radius: 10px; }
    .card-body { padding: 12px; }
    .card-header { padding: 10px 12px; font-size: 15px; }

    /* 表单两列变单列 */
    .form-row {
        display: block !important;
    }
    .form-row .form-group {
        margin-bottom: 12px;
    }
    .form-row .form-group:last-child {
        margin-bottom: 0;
    }

    /* 表单控件尺寸 */
    .form-control {
        font-size: 14px;
        padding: 8px 10px;
        min-height: 38px;
    }
    .form-group label { font-size: 13px; margin-bottom: 4px; }

    /* 按钮组：自动换行 */
    .btn-group { flex-wrap: wrap; }
    .btn { font-size: 13px; padding: 8px 14px; }
    .btn-sm { font-size: 12px; padding: 5px 10px; }

    /* 表格：横向滚动，防止溢出 */
    .table-wrap, .card-body > .table, .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table {
        min-width: 600px;
        font-size: 13px;
    }
    .table th, .table td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    /* 统计卡片网格：两列 */
    .stat-grid, .stats-grid, .dashboard-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    .stat-card, .stat-item {
        padding: 12px;
    }
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-label { font-size: 12px; }

    /* 功能卡片网格：两列 */
    .category-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    .category-card {
        padding: 16px 10px;
    }
    .category-card-icon { font-size: 28px; margin-bottom: 6px; }
    .category-card-name { font-size: 13px; }
    .category-card-desc { font-size: 11px; }

    /* 详情网格：单列 */
    .detail-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* 导航Tab：横向滚动 */
    .nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .nav li { flex-shrink: 0; }

    /* 标签页 */
    .nav-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* 搜索/筛选栏：堆叠 */
    .filter-bar, .search-bar, .toolbar {
        flex-direction: column;
        gap: 8px;
    }
    .filter-bar .form-control, .search-bar .form-control {
        width: 100%;
    }

    /* 弹窗适配 */
    .modal-dialog, .modal-content {
        width: 92vw !important;
        max-width: 92vw !important;
        margin: 5vh auto;
    }
    .modal-body { padding: 12px; max-height: 70vh; overflow-y: auto; }

    /* 分页 */
    .pagination { flex-wrap: wrap; justify-content: center; }

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

    /* 空状态 */
    .empty-state { padding: 40px 20px; }
    .empty-state .empty-icon { font-size: 48px; }

    /* 金额/数字右对齐在小屏保持 */
    .text-right { text-align: right; }

    /* 隐藏桌面端才需要的元素 */
    .desktop-only { display: none !important; }

    /* 侧边栏打开时内容区不缩放 */
    .admin-shell { padding-left: 0 !important; }

    /* 顶部操作栏 */
    .action-bar {
        flex-wrap: wrap;
        gap: 6px;
    }
}

/* ============================================================
   平板适配（768px - 1023px）
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
    .category-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .stat-grid, .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* 触控友好：最小点击区域 */
.btn, .form-control, .nav a, .category-card, .tabbar a {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* 防止 iOS 双击缩放 */
* { touch-action: manipulation; }

/* 安全区适配 */
@supports (padding: max(0px)) {
    .tabbar { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .merchant-content { padding-bottom: max(96px, calc(env(safe-area-inset-bottom) + 84px)); }
}

/* ============================================================
   移动端表单页面 UI 全面优化（液态玻璃风）
   ============================================================ */
@media (max-width: 767px) {
    /* 内容区：丰富渐变背景 + 微妙光斑 */
    .merchant-content {
        background: linear-gradient(160deg, #eef2ff 0%, #f5f0ff 30%, #f0f7ff 60%, #fff5f5 100%);
        min-height: 100vh;
        position: relative;
    }
    .merchant-content::before {
        content: ''; position: fixed; top: -10%; right: -20%; width: 300px; height: 300px;
        background: radial-gradient(circle, rgba(99,102,241,.12) 0%, transparent 70%);
        border-radius: 50%; pointer-events: none; z-index: 0;
    }
    .merchant-content::after {
        content: ''; position: fixed; bottom: 20%; left: -15%; width: 260px; height: 260px;
        background: radial-gradient(circle, rgba(236,72,153,.08) 0%, transparent 70%);
        border-radius: 50%; pointer-events: none; z-index: 0;
    }
    .merchant-content > * { position: relative; z-index: 1; }

    /* 页面标题 */
    .page-header {
        background: rgba(255,255,255,.6); backdrop-filter: blur(12px);
        border: 1px solid rgba(255,255,255,.8); border-radius: 16px;
        padding: 14px 16px !important; margin-bottom: 14px !important;
        box-shadow: 0 4px 16px rgba(99,102,241,.08);
    }
    .page-header h2 { font-size: 19px !important; font-weight: 700; background: linear-gradient(135deg,var(--primary),var(--primary-2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

    /* 卡片：更强的玻璃质感 */
    .card {
        background: rgba(255,255,255,.72) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border: 1px solid rgba(255,255,255,.9) !important;
        border-radius: 18px !important;
        box-shadow: 0 8px 32px rgba(99,102,241,.10), 0 2px 8px rgba(0,0,0,.04) !important;
        margin-bottom: 14px !important;
    }
    .card-header {
        background: linear-gradient(135deg, rgba(99,102,241,.06), rgba(236,72,153,.04)) !important;
        border-bottom: 1px solid rgba(99,102,241,.08) !important;
        padding: 14px 18px !important; font-weight: 700 !important; font-size: 15px !important;
        color: var(--primary) !important;
    }
    .card-body { padding: 18px !important; }

    /* 表单输入框：玻璃质感 + 聚焦光晕 */
    .form-group { margin-bottom: 18px !important; }
    .form-group label {
        font-size: 13px !important; font-weight: 600 !important;
        color: #4a5568 !important; margin-bottom: 8px !important;
        display: flex; align-items: center; gap: 6px;
    }
    .form-group label::before {
        content: ''; width: 3px; height: 14px; border-radius: 2px;
        background: linear-gradient(180deg, var(--primary), var(--primary-2));
    }
    .form-control {
        background: rgba(255,255,255,.85) !important;
        border: 1.5px solid rgba(99,102,241,.15) !important;
        border-radius: 12px !important;
        min-height: 48px !important; padding: 12px 16px !important;
        font-size: 15px !important; color: #1a202c !important;
        box-shadow: 0 2px 8px rgba(99,102,241,.05) !important;
        transition: all .2s ease !important;
    }
    .form-control:focus {
        background: #fff !important;
        border-color: var(--primary) !important;
        box-shadow: 0 0 0 4px rgba(99,102,241,.12), 0 4px 16px rgba(99,102,241,.12) !important;
    }
    .form-control::placeholder { color: #a0aec0 !important; }
    select.form-control { padding-right: 40px !important; }

    /* 按钮：更强的渐变和阴影 */
    .btn-primary {
        background: linear-gradient(135deg, var(--primary), var(--primary-2)) !important;
        box-shadow: 0 6px 20px rgba(99,102,241,.35) !important;
        border-radius: 14px !important; font-weight: 600 !important;
    }
    .btn-block { min-height: 50px !important; font-size: 16px !important; }

    /* 表格/列表优化：允许横向滚动，不裁剪内容 */
    .table {
        background: rgba(255,255,255,.6) !important; border-radius: 14px !important;
        display: block !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch !important;
        max-width: 100% !important; white-space: nowrap !important;
    }
    .table th, .table td { white-space: nowrap !important; padding: 10px 12px !important; }
    .table th { background: rgba(99,102,241,.06) !important; font-weight: 600 !important; }

    /* 统计卡片 */
    .stat-card, .stats-grid > div {
        background: rgba(255,255,255,.72) !important;
        backdrop-filter: blur(16px) !important; border-radius: 16px !important;
        border: 1px solid rgba(255,255,255,.85) !important;
        box-shadow: 0 4px 16px rgba(99,102,241,.08) !important;
    }

    /* ============================================================
       全局自适应：解决所有页面溢出/截断问题
       ============================================================ */
    /* 禁止页面横向滚动 */
    body, html { overflow-x: hidden; max-width: 100%; }
    .merchant-content { overflow-x: hidden; }
    * { box-sizing: border-box; }

    /* 表单用 table 布局的，手机端全部改成上下堆叠 */
    form table, form tbody, form tr, form td, form th {
        display: block !important; width: 100% !important;
    }
    form table { border: none !important; }
    form td { padding: 0 0 14px 0 !important; }
    form td .form-control, form td input, form td select, form td textarea {
        width: 100% !important; max-width: 100% !important;
    }
    /* 表单里的标签td */
    form td:first-child {
        font-weight: 600; font-size: 13px; color: #4a5568;
        padding-bottom: 6px !important;
    }

    /* 数据表格：加横向滚动，不截断 */
    .table-wrap, .card-body > table, .card > table {
        display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    table.data-table, table.list-table {
        display: block; overflow-x: auto; min-width: 600px;
    }
    /* 普通数据表格保留table布局但可横向滚动 */
    .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .table th, .table td { white-space: nowrap; padding: 10px 12px !important; }

    /* 栅格系统：手机端全部单列 */
    .row { flex-direction: column !important; gap: 12px; }
    [class*="col-"], .col-md-*, .col-sm-*, .col-lg-* {
        width: 100% !important; flex: 0 0 100% !important; max-width: 100% !important;
        padding: 0 !important;
    }

    /* 左右两栏布局：手机端上下堆叠 */
    .two-col, .grid-2, .layout-split, [style*="display:flex"] > [style*="flex:1"],
    .card-body > div[style*="display:flex"] {
        flex-direction: column !important;
    }
    /* 权益配置页左右两栏 */
    .benefits-layout, .member-level-benefits { flex-direction: column !important; }
    .benefits-left, .benefits-right { width: 100% !important; flex: 0 0 100% !important; }

    /* 筛选/搜索区域：自动换行 */
    .filter-form, .search-bar, .toolbar, .filter-bar {
        flex-wrap: wrap !important; gap: 8px !important;
    }
    .filter-form .form-control, .search-bar .form-control {
        flex: 1 1 calc(50% - 8px) !important; min-width: 140px !important; width: auto !important;
    }
    .filter-form .btn, .search-bar .btn { flex: 0 0 auto; }

    /* 下拉框文字不截断 */
    select.form-control { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; padding-right: 36px !important; }

    /* 多列输入框行：手机端单列 */
    .form-row, .input-group-row, [style*="display:flex"] > .form-group {
        flex-direction: column !important;
    }
    .form-row > .form-group { width: 100% !important; flex: 0 0 100% !important; }

    /* Grid多列布局：手机端统一改双列（3列/4列/5列/7列全部改双列） */
    [style*="grid-template-columns:repeat(2"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(3"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(4"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(5"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(6"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(7"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns:repeat(8"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-template-columns"] { max-width: 100% !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; }
    /* 带gap的grid保持gap */
    [style*="grid-template-columns"][style*="gap"] { gap: 10px !important; }

    /* 按钮组不溢出 */
    .btn-group, .action-buttons { flex-wrap: wrap !important; gap: 6px; }
    .btn-group .btn, .action-buttons .btn { flex: 0 0 auto; }

    /* 图片/媒体不溢出 */
    img, video, iframe { max-width: 100%; height: auto; }

    /* 长文本不溢出 */
    .card, .card-body, .p-card { word-break: break-word; overflow-wrap: break-word; }

    /* 底部内容不被tabbar遮挡（再加一层保险） */
    .merchant-content { padding-bottom: 110px !important; }
    .merchant-content > :last-child { margin-bottom: 20px; }
}
