/* ========================================================
 * 商会平台 - 移动端公共样式
 * Mobile-first responsive CSS
 * 引入:  <link rel="stylesheet" href="/static/css/mobile.css">
 * ======================================================== */

/* 基础重置 */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
/* 全局图片 EXIF Orientation：浏览器按 EXIF 自动旋转（修复 iPhone 竖屏照片倒过来） */
img { image-orientation: from-image; }
body {
    font-family: 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    background: #f5f7fa;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
}

/* 防止水平滚动 */
html, body { overflow-x: hidden; }
img, video { max-width: 100%; height: auto; }

/* 触摸优化 */
button, a, .clickable { -webkit-tap-highlight-color: rgba(102,126,234,0.1); cursor: pointer; touch-action: manipulation; }
input, textarea, select { font-size: 16px; /* 防止 iOS 缩放 */ }

/* ==========================================================
 * 响应式容器 - 默认 800px, 移动端铺满
 * ========================================================== */
.container { max-width: 800px; margin: 0 auto; padding: 15px; }
.container-wide { max-width: 100%; margin: 0 auto; padding: 15px; }

/* ==========================================================
 * 响应式网格 (1列->2列->4列)
 * ========================================================== */
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-6 { grid-template-columns: repeat(3, 1fr); }

/* ==========================================================
 * 响应式 header
 * ========================================================== */
.page-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.page-header .back-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.page-header .title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.page-header .actions { display: flex; gap: 8px; }
.page-header .action-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* ==========================================================
 * 卡片
 * ========================================================== */
.card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.card-title { font-size: 15px; font-weight: 600; color: #333; margin-bottom: 10px; }
.card-meta { color: #999; font-size: 12px; }

/* ==========================================================
 * 按钮
 * ========================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    background: #f0f0f0;
    color: #333;
    text-decoration: none;
    min-height: 36px;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }
.btn-success { background: #4caf50; color: white; }
.btn-danger { background: #f56c6c; color: white; }
.btn-warning { background: #e6a23c; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; min-height: 28px; }
.btn-lg { padding: 14px 24px; font-size: 16px; min-height: 48px; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================
 * 表单
 * ========================================================== */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; font-weight: 500; }
.form-control {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    color: #333;
    outline: none;
    transition: border-color 0.2s;
}
.form-control:focus { border-color: #667eea; }
.form-control[disabled] { background: #f5f5f5; cursor: not-allowed; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { padding: 10px 12px; }

/* ==========================================================
 * 表格 (移动端转卡片)
 * ========================================================== */
.table { width: 100%; border-collapse: collapse; background: white; }
.table th, .table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.table th { background: #fafafa; font-weight: 600; color: #555; }

/* ==========================================================
 * 底部 Tab Bar (移动端)
 * ========================================================== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e8e8e8;
    display: flex;
    z-index: 99;
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}
.tab-bar .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px;
    text-decoration: none;
    color: #999;
    font-size: 11px;
}
.tab-bar .tab .icon { font-size: 20px; margin-bottom: 2px; }
.tab-bar .tab.active { color: #667eea; }
.tab-bar + * { padding-bottom: 64px; }

/* ==========================================================
 * 响应式断点
 * ========================================================== */
@media (min-width: 768px) {
    .container { max-width: 800px; padding: 20px; }
    body { font-size: 15px; }
    .page-header { padding: 15px 30px; }
    .page-header .title { font-size: 18px; }
    .card { padding: 20px; }
}

/* ============= 移动端 (≤ 767px) 重点适配 ============= */
@media (max-width: 767px) {
    /* 侧边栏变顶部抽屉 */
    .sidebar {
        position: fixed !important;
        top: 0; left: 0; bottom: 0;
        width: 80% !important;
        max-width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s;
        box-shadow: 2px 0 20px rgba(0,0,0,0.2);
        padding-top: 60px !important;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        display: none;
    }
    .sidebar-overlay.open { display: block; }

    /* 桌面容器撑满 */
    .container { padding: 10px; }
    .main-container { flex-direction: column !important; }
    .content { padding: 10px !important; }

    /* 网格变 2 列 */
    .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-6 { grid-template-columns: repeat(3, 1fr); }

    /* 表格转卡片: 设置 data-label */
    .table thead { display: none; }
    .table tr { display: block; background: white; border-radius: 8px; padding: 10px; margin-bottom: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
    .table td { display: block; padding: 4px 0; border: none; }
    .table td:before { content: attr(data-label); font-weight: 600; color: #999; display: inline-block; width: 80px; }

    /* 头部压缩 */
    .navbar { padding: 10px 15px !important; }
    .navbar h1 { font-size: 16px !important; }

    /* 主内容滚动 */
    body.has-tabbar { padding-bottom: 60px; }
}

/* ============= 平板 (768-1023) ============= */
@media (min-width: 768px) and (max-width: 1023px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

/* ============= 大屏 ≥ 1024 ============= */
@media (min-width: 1024px) {
    .container { max-width: 1200px; }
}

/* ==========================================================
 * 工具类
 * ========================================================== */
.text-center { text-align: center; }
.text-muted { color: #999; }
.text-primary { color: #667eea; }
.text-danger { color: #f56c6c; }
.text-success { color: #4caf50; }
.text-bold { font-weight: 600; }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.p-1 { padding: 8px; } .p-2 { padding: 16px; } .p-3 { padding: 24px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* ==========================================================
 * 模态框
 * ========================================================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 15px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #999;
    cursor: pointer;
    width: 32px;
    height: 32px;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* 移动端模态框全屏 */
@media (max-width: 767px) {
    .modal-overlay { padding: 0; }
    .modal { max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
}

/* ==========================================================
 * 加载/空状态
 * ========================================================== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}
.empty {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}
.empty .icon { font-size: 40px; margin-bottom: 10px; opacity: 0.5; }

/* ==========================================================
 * 标签 / Badge
 * ========================================================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    background: #f0f0f0;
    color: #666;
}
.badge-primary { background: #e8eaff; color: #667eea; }
.badge-success { background: #e8f5e9; color: #4caf50; }
.badge-warning { background: #fff7e6; color: #e6a23c; }
.badge-danger { background: #ffebee; color: #f56c6c; }

/* ==========================================================
 * 抽屉式侧栏 (admin)
 * ========================================================== */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 5px;
}
@media (max-width: 767px) {
    .mobile-menu-btn { display: block; }
}

/* ==========================================================
 * Hamburger 菜单
 * ========================================================== */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    padding: 5px;
}
.hamburger span {
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s;
}
@media (max-width: 767px) {
    .hamburger { display: flex; }
}

/* ==========================================================
 * 列表项
 * ========================================================== */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: white;
    border-bottom: 1px solid #f5f5f5;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s;
}
.list-item:active { background: #f5f5f5; }
.list-item .avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.list-item .info { flex: 1; min-width: 0; }
.list-item .info .title { font-size: 14px; color: #333; margin-bottom: 2px; font-weight: 500; }
.list-item .info .sub { font-size: 12px; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .arrow { color: #ccc; font-size: 16px; }

/* ==========================================================
 * PWA ר����ʽ �� �ײ� Tab Bar / ��װ��ʾ / ��ȫ��
 * ========================================================== */

/* ---------- Chamber Tab Bar (mobile-nav.js ע��) ---------- */
.chamber-tab-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #ffffff;
    border-top: 1px solid #e8eaf0;
    display: flex;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -4px 16px rgba(15, 52, 96, 0.06);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.chamber-tab-bar .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px 10px;
    text-decoration: none;
    color: #94A3B8;
    font-size: 11px;
    font-weight: 500;
    transition: color 0.2s;
    min-height: 56px;
    position: relative;
}
.chamber-tab-bar .tab-icon {
    font-size: 22px;
    margin-bottom: 3px;
    transition: transform 0.2s;
}
.chamber-tab-bar .tab.active {
    color: #1B4F8C;
}
.chamber-tab-bar .tab.active .tab-icon {
    transform: translateY(-2px);
}
.chamber-tab-bar .tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: #1B4F8C;
    border-radius: 0 0 3px 3px;
}
.chamber-tab-bar .tab-label {
    line-height: 1;
}

/* ���� Tab Bar �������ݣ�����ҳ��ӵײ� padding�����ƶ��ˣ� */
@media (max-width: 900px) {
    body { padding-bottom: 76px; }
}

/* ---------- PWA ��װ��ʾ��� ---------- */
.chamber-install-banner {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    background: linear-gradient(135deg, #1B4F8C 0%, #0F3460 100%);
    color: white;
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(15, 52, 96, 0.35);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    animation: chamberSlideDown 0.4s ease-out;
}
@keyframes chamberSlideDown {
    from { transform: translateY(-120%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.chamber-install-banner .install-icon {
    font-size: 24px;
    flex-shrink: 0;
}
.chamber-install-banner .install-text {
    flex: 1;
    line-height: 1.4;
}
.chamber-install-banner .install-btn {
    background: white;
    color: #1B4F8C;
    border: none;
    padding: 7px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}
.chamber-install-banner .install-btn:active { transform: scale(0.96); }
.chamber-install-banner .install-close {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: -4px;
}

/* ---------- PWA standalone ģʽ����������� UI��������Ļ ---------- */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top, 0);
    }
    .page-header {
        /* PWA ģʽ�����ó�״̬�� */
        padding-top: calc(env(safe-area-inset-top, 0) + 12px);
    }
}

/* ---------- iOS ״̬������ ---------- */
@supports (padding: max(0px)) {
    .chamber-tab-bar {
        padding-bottom: max(env(safe-area-inset-bottom), 8px);
    }
}

/* ---------- �ƶ��˱��������ֺ� 16px �� iOS ���� ---------- */
@media (max-width: 768px) {
    input, select, textarea, .form-control { font-size: 16px !important; }
}

/* ---------- ���� mobile-nav.js ������˸ ---------- */
.chamber-tab-bar:not(.ready) { opacity: 0; }
.chamber-tab-bar.ready { opacity: 1; transition: opacity 0.2s; }

/* ========================================================
 * 【2026-08-19】admin 后台手机适配补丁
 * 覆盖 admin_dashboard.html / admin_fee_audit.html 等内联样式
 * 使用 !important 提升优先级（mobile.css 在内联 style 之前加载）
 * ======================================================== */
@media (max-width: 767px) {
    /* 顶部导航栏：紧凑 + 可换行 */
    .navbar {
        padding: 10px 12px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .navbar h1 {
        font-size: 15px !important;
        flex: 1 1 100% !important;
        order: 2 !important;
        margin-top: 4px !important;
    }
    .navbar .user-info {
        flex: 1 1 100% !important;
        order: 3 !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        font-size: 12px !important;
    }
    .navbar .user-info a, .navbar .user-info span {
        font-size: 12px !important;
    }

    /* 主容器：竖排 */
    .main-container {
        flex-direction: column !important;
    }

    /* 内容区：缩 padding */
    .content {
        padding: 12px !important;
    }

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

    /* 双列 / 三列网格：单列 */
    .grid-2, .grid-3 {
        grid-template-columns: 1fr !important;
    }

    /* 页面标题：换行不挤压 */
    .page-header {
        flex-wrap: wrap !important;
        gap: 8px !important;
        margin-bottom: 14px !important;
    }
    .page-title {
        font-size: 18px !important;
    }

    /* 卡片：缩 padding */
    .card {
        padding: 14px !important;
        border-radius: 10px !important;
    }

    /* 详情模态框：全屏 */
    .detail-box {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100vh !important;
        height: 100vh !important;
        border-radius: 0 !important;
    }
    .detail-header, .detail-body {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* admin 裸表格 → 横滚容器（避免列挤压） */
    table:not(.table):not(.rt-content table) {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: nowrap !important;
        font-size: 12px !important;
    }
    table:not(.table):not(.rt-content table) th,
    table:not(.table):not(.rt-content table) td {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    /* 搜索栏：竖排 */
    .search-bar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .search-bar input {
        flex: 1 1 100% !important;
        min-width: 0 !important;
    }
    .search-bar button, .search-bar select {
        flex: 1 1 auto !important;
    }

    /* Tabs：横滚 */
    .tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: nowrap !important;
        flex-wrap: nowrap !important;
    }
    .tab {
        flex-shrink: 0 !important;
    }

    /* 升级卡片网格：2 列 */
    .upgrade-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .upgrade-card {
        padding: 10px 6px !important;
    }
    .upgrade-card .uc-name {
        font-size: 14px !important;
    }

    /* 详情行：label 换行显示 */
    .detail-row {
        flex-wrap: wrap !important;
    }
    .detail-label {
        width: 100% !important;
        margin-bottom: 2px !important;
        font-size: 12px !important;
    }
    .detail-value {
        font-size: 13px !important;
        padding-left: 0 !important;
    }

    /* 表单组：紧凑 */
    .form-group input, .form-group select, .form-group textarea {
        font-size: 16px !important; /* iOS 不缩放 */
        padding: 10px 12px !important;
    }

    /* 按钮：更大触摸区 */
    .btn {
        padding: 8px 14px !important;
        font-size: 13px !important;
        min-height: 36px !important;
    }

    /* AI 助手聊天按钮：缩小 */
    .ai-chat-btn {
        width: 50px !important;
        height: 50px !important;
        bottom: 70px !important;
        right: 15px !important;
    }
    .ai-chat-btn span { font-size: 22px !important; }
}
/* ===== 手机端便捷性增强：表格/表单/图片 ===== */
@media (max-width: 768px) {
  /* 3. 表格适配：超宽表格允许横向滑动，避免挤压或溢出 */
  .table, table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table table, table table { display: table; width: 100%; }
  th, td { padding: 10px 8px !important; font-size: 14px !important; white-space: nowrap; }
  td:first-child, th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; }

  /* 4. 表单体验：统一触控尺寸、防止 iOS 聚焦放大、合适的输入类型键盘 */
  input, textarea, select, button { font-size: 16px !important; min-height: 44px; padding: 10px 12px !important; }
  input[type="tel"], input[type="number"], input[type="email"] { ime-mode: disabled; }

  /* 5. 图片与内容流式化：图片不超出屏幕，长文自动换行 */
  img { max-width: 100%; height: auto; display: block; }
  p, div, span { word-wrap: break-word; overflow-wrap: break-word; }
  pre, code { white-space: pre-wrap; word-break: break-all; }
}

/* 超小屏手机（iPhone SE/mini）进一步压缩间距 */
@media (max-width: 375px) {
  input, textarea, select, button { min-height: 42px; font-size: 16px !important; }
  th, td { padding: 8px 6px !important; font-size: 13px !important; }
}
