/* ====== 基础 ====== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --c-bg: #f5f7fa;
    --c-card: #ffffff;
    --c-text: #2c3e50;
    --c-muted: #90a4ae;
    --c-primary: #2c7be5;
    --c-primary-d: #1a68d4;
    --c-danger: #e74c3c;
    --c-success: #27ae60;
    --c-warn: #f39c12;
    --c-border: #e3e8ef;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
    line-height: 1.6;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { color: var(--c-primary-d); text-decoration: underline; }

/* ====== 顶栏 ====== */
.topbar {
    background: linear-gradient(90deg, #1a68d4 0%, #2c7be5 100%);
    color: #fff;
    box-shadow: var(--shadow);
}
.topbar-inner {
    max-width: 1280px; margin: 0 auto;
    padding: 0 20px; height: 56px;
    display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.brand-mark {
    width: 28px; height: 28px;
    background: #fff; color: var(--c-primary);
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.menu { display: flex; gap: 4px; flex: 1; align-items: center; }
.menu a {
    color: rgba(255,255,255,0.85);
    padding: 6px 12px; border-radius: 6px;
    font-size: 14px; transition: all .15s;
}
.menu a:hover { background: rgba(255,255,255,0.15); color: #fff; text-decoration: none; }
.menu a.active { background: rgba(255,255,255,0.22); color: #fff; font-weight: 500; }

/* ====== 顶栏分组下拉菜单（往来管理 / 库存管理）====== */
.nav-group { position: relative; display: flex; align-items: center; }
.menu .nav-parent { cursor: pointer; user-select: none; }
.nav-group .submenu {
    display: none;
    position: absolute; top: calc(100% + 4px); left: 0;
    background: #2c7be5;
    flex-direction: column;
    min-width: 132px;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    padding: 4px;
    z-index: 60;
}
.nav-group .submenu a {
    white-space: nowrap;
    text-align: left;
    padding: 8px 12px;
}
/* 仅点击（加 .open 类）才弹出，不 hover 自动弹出 */
.nav-group.open .submenu { display: flex; }
/* 父菜单右侧下箭头（移动端在「移动端适配」段覆盖为 ＋/－ 展开符号） */
.menu .nav-parent::after { content: ' ▾'; font-size: 11px; opacity: .85; }
/* 抽屉底部的用户信息块：默认隐藏，仅移动端显示（见移动端段） */
.menu-user { display: none; }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-name { color: #fff; cursor: pointer; text-decoration: none; }
.user-name:hover { text-decoration: underline; }
.user-role { font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.role-admin { background: #fff3cd; color: #856404; }
.role-user  { background: #d4edda; color: #155724; }
.btn-logout {
    color: #fff; padding: 4px 10px;
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: 4px; font-size: 12px;
}
.btn-logout:hover { background: rgba(255,255,255,0.15); text-decoration: none; }
.nav-toggle {
    display: none;
    background: rgba(255,255,255,0.2); border: none; color: #fff;
    font-size: 20px; line-height: 1; cursor: pointer;
    padding: 6px 12px; border-radius: 6px;
}
.nav-toggle:hover { background: rgba(255,255,255,0.3); }

/* ====== 容器 ====== */
.container { max-width: 1280px; margin: 20px auto; padding: 0 20px; }
.footer {
    max-width: 1280px; margin: 30px auto; padding: 16px 20px;
    border-top: 1px solid var(--c-border);
    color: var(--c-muted); font-size: 12px;
    display: flex; justify-content: space-between;
}

/* 页脚文案居中 */
.site-footer { text-align: center; padding: 14px 0; color: var(--c-muted); font-size: 12px; }

/* 搜索框自动补全下拉 */
.ac-wrap { position: relative; display: inline-block; }
.ac-box {
    position: absolute; display: none; z-index: 50; top: 100%; left: 0;
    background: #fff; border: 1px solid #d0d7e2; border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12); max-height: 220px; overflow: auto; min-width: 220px;
}
.ac-box .ac-item { padding: 6px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f3f7; display: flex; justify-content: space-between; gap: 8px; }
.ac-box .ac-item:last-child { border-bottom: none; }
.ac-box .ac-item:hover, .ac-box .ac-item.active { background: #eef4ff; }
.ac-box .ac-item .ac-name { color: #2c3e50; }
.ac-box .ac-item .ac-meta { color: #90a4ae; font-size: 12px; }

/* 首页「最近单据」：单击行展开/收起明细（简约版） */
.recent-table .main-row { cursor: pointer; }
.recent-table .main-row:hover { background: #f3f7fd; }
.recent-table .caret { display: inline-block; color: #2c7be5; transition: transform .15s; font-size: 11px; margin-right: 2px; }
.recent-table .main-row.open .caret { transform: rotate(90deg); }
/* 展开时由 JS 清空 inline 的 display:none，这里给出默认形态（移动端见文件末尾覆盖为 block） */
.detail-row { display: table-row; }
.detail-row > td { padding: 0 !important; border-top: none !important; background: #f7f9fc; }
.order-detail-mini { padding: 8px 14px 12px; }
.order-detail-mini table { width: 100%; border-collapse: collapse; font-size: 12px; }
.order-detail-mini th { text-align: left; color: #6b7785; font-weight: 500; padding: 4px 10px; border-bottom: 1px solid #e6ebf1; }
.order-detail-mini td { padding: 4px 10px; border-bottom: 1px solid #eef1f5; }
.order-detail-mini th.num, .order-detail-mini td.num { text-align: right; }
.order-detail-mini tbody tr:last-child td { border-bottom: none; }

/* ====== 卡片 ====== */
.card {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}
.card-title {
    font-size: 16px; font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--c-border);
    display: flex; justify-content: space-between; align-items: center;
}

/* ====== 表格 ====== */
.table {
    width: 100%; border-collapse: collapse;
}
.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    font-size: 14px;
}
.table th { background: #f8fafc; font-weight: 600; color: #5a6877; }
.table tr:hover td { background: #fafbfc; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--c-muted); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; color: #d9534f; }

/* ====== 按钮 ====== */
.btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--c-border);
    background: #fff;
    color: var(--c-text);
    font-size: 13px;
    cursor: pointer;
    line-height: 1.5;
    transition: all .15s;
}
.btn:hover { text-decoration: none; border-color: var(--c-primary); color: var(--c-primary); }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-d); color: #fff; }
.btn-danger { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-danger:hover { background: #c0392b; color: #fff; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-in  { background: #2e9e5b; color: #fff; border-color: #2e9e5b; }
.btn-in:hover  { background: #248a4c; color: #fff; }
.btn-out { background: #d9534f; color: #fff; border-color: #d9534f; }
.btn-out:hover { background: #c0392b; color: #fff; }

/* ====== 表单 ====== */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 500; color: #5a6877; }
.form-row .required { color: var(--c-danger); }
.input, .select, .textarea {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--c-border);
    border-radius: 6px; font-size: 14px;
    background: #fff; color: var(--c-text);
    transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(44,123,229,0.1);
}
.textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; }

/* ====== 提示 ====== */
.alert {
    padding: 10px 14px; border-radius: 6px;
    margin-bottom: 16px; font-size: 13px;
}
.alert-info { background: #d9ecff; color: #1a68d4; border: 1px solid #b3d7ff; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warn { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }

/* ====== 统计卡 ====== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: var(--c-card);
    border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--c-muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 600; color: var(--c-text); }
.stat-value.danger { color: var(--c-danger); }

/* ====== 标签 ====== */
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.tag-active { background: #d4edda; color: #155724; }
.tag-void   { background: #f8d7da; color: #721c24; }
.tag-admin  { background: #fff3cd; color: #856404; }
.tag-user   { background: #d1ecf1; color: #0c5460; }
.tag-on     { background: #d4edda; color: #155724; }
.tag-off    { background: #f8d7da; color: #721c24; }

/* ====== 工具栏 ====== */
.toolbar {
    display: flex; gap: 10px; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar .input, .toolbar .select { width: auto; min-width: 140px; }

/* ====== 分页 ====== */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span {
    padding: 5px 10px; border: 1px solid var(--c-border);
    border-radius: 4px; font-size: 13px; background: #fff;
}
.pagination a:hover { background: #f0f4f8; text-decoration: none; }
.pagination .current { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* ====== 我的单据筛选栏 ====== */
.filter-bar {
    display: flex; gap: 10px; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar .select, .filter-bar .input { width: auto; min-width: 120px; }
.filter-bar .select-sm, .filter-bar .input-sm { width: auto; padding: 6px 8px; font-size: 13px; }
.filter-bar .input-sm[type="date"]   { min-width: 150px; }
.filter-bar .input-sm[type="number"] { min-width: 110px; }
.filter-bar .input-sm[type="text"]   { min-width: 130px; }
.filter-bar .range { display: inline-flex; align-items: center; gap: 6px; }
.filter-bar .range-sep { color: var(--c-muted); }
.filter-bar .range input { width: auto; }

/* ====== 分页 + 每页条数 ====== */
.pager-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-top: 14px;
}
.pager { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.per-form { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.per-form .select-sm { width: auto; padding: 6px 8px; font-size: 13px; }

/* ====== 收据预览/打印 ====== */
.receipt-preview-wrap { background: #ececec; padding: 24px 0; }
.receipt {
    width: 210mm; min-height: 130mm;
    background: #fff; margin: 0 auto;
    padding: 18mm 16mm;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    font-family: "SimSun", "宋体", serif;
    color: #000;
    position: relative;
}
.receipt .r-title {
    text-align: center; font-size: 28px; font-weight: 700;
    letter-spacing: 6px; margin-bottom: 6px;
    font-family: "SimHei", "黑体", sans-serif;
}
.receipt .r-subtitle {
    text-align: center; font-size: 16px; color: #333;
    font-weight: 500; margin-bottom: 16px;
}
.receipt .r-no {
    text-align: right; font-size: 13px; margin-bottom: 8px;
}
.receipt .r-line {
    height: 1px; background: #000; margin: 4px 0 12px;
}
.receipt table.r-table {
    width: 100%; border-collapse: collapse;
    font-size: 14px;
}
.receipt table.r-table th, .receipt table.r-table td {
    border: 1px solid #000;
    padding: 6px 8px;
    vertical-align: middle;
}
.receipt table.r-table th {
    background: #f5f5f5; font-weight: 700; text-align: center;
    font-family: "SimHei", "黑体", sans-serif;
}
/* ====== 收据：额外信息与金额框（屏幕/预览统一，打印由 print.css 覆盖） ====== */
.receipt .r-extra-info {
    margin: 6px 0;
    padding: 12px 16px;
    font-size: 15px; font-weight: 600;
    color: #1a2a3c;
    background: linear-gradient(to right, #eef4ff, #f8faff);
    border-left: 5px solid #2c7be5;
    border-radius: 4px;
    line-height: 1.8;
    box-shadow: 0 1px 4px rgba(44,123,229,0.1);
}
.receipt .r-amount-box {
    margin: 10px 0;
    border: 2px solid #000;
    border-radius: 2px;
    overflow: hidden;
}
.receipt .r-amount-box .r-amount-cn-line,
.receipt .r-amount-box .r-amount-num-line {
    display: flex; align-items: center;
    border-bottom: 1px solid #000;
}
.receipt .r-amount-box .r-amount-num-line { border-bottom: none; }
/* 合计三栏按 1:1:2 固定占比（合计数量/金额各 1/4，大写 1/2），避免大写较长时整行换行 */
.receipt .r-amount-num-line .r-amt-cell {
    display: flex; align-items: stretch; flex: 1 1 0; min-width: 0;
    border-right: 1px solid #000;
}
.receipt .r-amount-num-line .r-amt-cell:last-child { border-right: none; }
.receipt .r-amount-num-line .r-amt-cell.r-amt-cn { flex: 2 1 0; }
.receipt .r-amount-num-line .r-amt-cell .r-amount-cn { white-space: nowrap; }
.receipt .r-amount-box .r-amt-label {
    flex: 0 0 auto; padding: 8px 12px;
    font-weight: 700; font-size: 14px;
    background: #f0f0f0; border-right: 1px solid #000;
    font-family: "SimHei", "黑体", sans-serif;
}
.receipt .r-amount-box .r-amount-cn {
    flex: 1; padding: 8px 14px;
    font-size: 18px; font-weight: 900; letter-spacing: 1px;
    font-family: "SimSun", "宋体", serif;
}
.receipt .r-amount-box .r-amount-num {
    flex: 1; padding: 8px 14px;
    font-size: 24px; font-weight: 900; color: #c0392b;
    font-variant-numeric: tabular-nums;
}
.receipt .r-foot {
    margin-top: 10px;
    display: flex; justify-content: space-between;
    font-size: 14px;
}
.receipt .r-foot div { line-height: 1.6; }
.receipt .r-seal {
    position: absolute; right: 24mm; bottom: 24mm;
    width: 150px; height: 150px;
    border: 3px solid #c0392b; border-radius: 50%;
    color: #c0392b; font-size: 22px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: space-evenly;
    text-align: center; opacity: 0.85;
    transform: rotate(-12deg);
    font-family: "SimHei", "黑体", sans-serif;
    line-height: 1.3;
    padding: 8px 0;
}
.receipt .r-note {
    margin-top: 6px; font-size: 15px; color: #222;
    border-top: 1px solid #999; padding-top: 6px;
}
.receipt .r-remark {
    margin-top: 6px; font-size: 14px; color: #222;
    border-top: 1px dashed #999; padding-top: 5px;
}
.receipt .r-remark-label { font-weight: 700; }
/* 1/2、1/3 纸不显示印章（仅 A4 显示），预览与打印一致 */
body.paper-half .receipt .r-seal,
body.paper-third .receipt .r-seal {
    display: none;
}
/* 1/3 纸预览：A4 宽(210mm) × 99mm 高的横条，与打印一致 */
body.paper-third .receipt { min-height: 95mm; }
body.paper-third .receipt table.r-items tbody tr { height: 6mm; }
body.paper-third .receipt table.r-items td.prod-name { font-size: 13px; font-weight: 700; }
body.paper-third .receipt .r-amount-box .r-amt-label { flex: 0 0 50px; font-size: 10px; padding: 2px 3px; }
body.paper-third .receipt .r-amount-cn { font-size: 11px; }
body.paper-third .receipt .r-amount-num { font-size: 13px; }
.btn-print-bar {
    text-align: center; margin: 20px 0;
}

/* ====== 登录页 ====== */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a68d4 0%, #4a90e2 50%, #6fb1e8 100%);
}
.login-card {
    width: 360px; background: #fff;
    border-radius: 10px; padding: 32px 28px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-title { text-align: center; font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--c-muted); font-size: 13px; margin-bottom: 24px; }
.login-card .btn-primary { width: 100%; padding: 10px; font-size: 15px; }
.login-tip { text-align: center; margin-top: 16px; font-size: 12px; color: var(--c-muted); }

@media (max-width: 768px) {
    .container { margin: 12px auto; padding: 0 12px; }
    .stats { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .card { padding: 12px; }

    /* 顶栏：折叠为汉堡菜单（抽屉样式见文件末尾「移动端适配」段） */
    .nav-toggle { display: flex; }
    .topbar-inner { flex-wrap: nowrap; height: 56px; padding: 0 14px; gap: 10px; }
    .brand { flex: 1 1 auto; min-width: 0; }
    .user-box { display: none; }          /* 移动端用户信息移入抽屉底部 */
    .menu { display: none; }              /* 具体抽屉样式见移动端段 */

    /* 工具栏/筛选：纵向铺满 */
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .input,
    .toolbar .select,
    .toolbar input,
    .toolbar select,
    .toolbar button { width: 100% !important; }
    .toolbar .muted { display: none; }

    /* 我的单据筛选栏：窄屏纵向铺满 */
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .select, .filter-bar .input,
    .filter-bar input, .filter-bar select, .filter-bar button { width: 100% !important; }
    .filter-bar .range { width: 100%; }
    .filter-bar .range input { flex: 1; min-width: 0; }

    /* 列表表格：不再用 min-width:680px 横向滚动（会导致整页横向溢出）。
       改为纵向卡片堆叠，样式见文件末尾「移动端适配（全站统一）」段。 */

    /* 开具明细：窄屏竖向堆叠卡片，输入框全宽、触控友好 */
    .table.items-table,
    .table.items-table thead,
    .table.items-table tbody,
    .table.items-table tr,
    .table.items-table td,
    .table.items-table tfoot { display: block; }
    .table.items-table { border: none; }
    .table.items-table thead { display: none; }
    .table.items-table .item-row {
        border: 1px solid var(--c-border);
        border-radius: 10px;
        padding: 12px 12px 10px;
        margin-bottom: 12px;
        background: #fff;
        position: relative;
        box-shadow: var(--shadow);
    }
    .table.items-table .item-row td {
        display: flex; align-items: center; gap: 8px;
        padding: 5px 0; border: none !important; white-space: normal !important;
    }
    .table.items-table .item-row td::before {
        content: attr(data-label);
        flex: 0 0 56px; font-weight: 600; color: #5a6877; font-size: 13px;
    }
    .table.items-table .item-row td .input { flex: 1; width: 100%; font-size: 16px; padding: 9px 10px; }
    .table.items-table .item-row td.amount { justify-content: space-between; font-size: 16px; }
    .table.items-table .item-row td.cell-del { display: block; position: absolute; top: 8px; right: 8px; padding: 0; }
    .table.items-table .item-row td.cell-del::before { content: none; }
    .table.items-table .item-row td.cell-del .btn { padding: 6px 10px; font-size: 14px; }
    .table.items-table tfoot tr td { border: none !important; display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
    .table.items-table tfoot .amount { font-size: 18px; }

    /* 打印条按钮换行 */
    .btn-print-bar {
        display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
    }
    .btn-print-bar .btn,
    .btn-print-bar .select { flex: 1 1 auto; }

    /* 收据预览在手机上可横向滚动，文本缩小 */
    .print-area { overflow-x: auto; }
    .receipt { width: 100%; min-width: 360px; }
    .receipt .r-title { font-size: 22px; letter-spacing: 3px; }
    .receipt .r-subtitle { font-size: 13px; }
    .receipt .r-no { font-size: 11px; }
    .receipt table.r-table { font-size: 12px; }
    .receipt .r-amount-box .r-amt-label { flex: 0 0 110px; }
}

@media (max-width: 480px) {
    .login-card { width: 92%; padding: 24px 18px; }
    .receipt .r-amount-box .r-amt-label { flex: 0 0 92px; font-size: 12px; }
}

/* ====== 收据明细：手机端竖向卡片（仅屏幕，打印不受影响） ====== */
@media (max-width: 600px) {
    .receipt table.r-items,
    .receipt table.r-items thead,
    .receipt table.r-items tbody,
    .receipt table.r-items tr,
    .receipt table.r-items td { display: block; width: 100% !important; }
    .receipt table.r-items { margin: 6px 0; }
    .receipt table.r-items thead { display: none; }
    .receipt table.r-items tr {
        border: 1px solid #000; border-radius: 6px;
        padding: 6px 8px; margin-bottom: 8px; background: #fff;
    }
    .receipt table.r-items td {
        border: none !important; padding: 3px 0 !important;
        display: flex; justify-content: space-between; align-items: baseline;
        gap: 10px; text-align: right !important; font-size: 13px;
        white-space: normal !important; word-break: break-word;
    }
    .receipt table.r-items td::before {
        content: attr(data-label);
        flex: 0 0 auto; font-weight: 700; color: #333; text-align: left;
        font-family: "SimHei", "黑体", sans-serif;
    }
    .receipt table.r-items td.text-center,
    .receipt table.r-items td.text-right { text-align: right !important; }
    .receipt table.r-items td.amount { color: #d9534f; font-weight: 700; }
}

/* ====== 导出 PDF 时强制桌面版式（仅 JS 给 <html> 加 .force-desktop 时生效） ======
   html2pdf 用 html2canvas 截图当前屏幕 DOM，手机窄屏下会沿用 @media 卡片堆叠。
   加此类后强制按电脑 Web 端完整收据表格渲染，保证导出 PDF 与桌面一致。
   收据宽度由 JS 按所选纸张（A4/1/2/1/3）内联设置，这里只清掉 min-width 限制。 */
html.force-desktop .receipt { min-width: 0 !important; min-height: auto !important; }
/* 导出 A4 时中和 paper-third/half 的紧凑屏样式（行高 5mm / min-height 95mm 等），
   避免 1/3 横条的尺寸被带进完整 A4 页面导致内容被压扁 */
html.force-desktop .receipt table.r-items tbody tr { height: auto !important; }
/* 注意：导出 PDF 不再强制放大字号/间距（旧逻辑会覆盖 paper-third 的紧凑样式，
   导致合计/大写行被撑得“高得离谱”）。改为直接沿用屏幕预览的真实样式，
   仅保留下方“手机卡片堆叠 -> 桌面表格”的修正，使导出与单据详情预览布局一致。 */
html.force-desktop .receipt table.r-items { display: table !important; width: 100% !important; border-collapse: collapse !important; }
html.force-desktop .receipt table.r-items thead { display: table-header-group !important; }
html.force-desktop .receipt table.r-items tbody { display: table-row-group !important; }
html.force-desktop .receipt table.r-items tr { display: table-row !important; border: none !important; padding: 0 !important; margin: 0 !important; background: transparent !important; box-shadow: none !important; border-radius: 0 !important; }
html.force-desktop .receipt table.r-items td {
    display: table-cell !important;
    width: auto !important;
    text-align: left !important;
    border: 1px solid #000 !important;
    padding: 6px 8px !important;
    font-size: 14px !important;
    white-space: normal !important;
    justify-content: normal !important;
    color: #000 !important;
    vertical-align: middle !important;
}
html.force-desktop .receipt table.r-items td::before { display: none !important; content: none !important; }
html.force-desktop .receipt table.r-items th { display: table-cell !important; width: auto !important; }
html.force-desktop .receipt table.r-items td.text-right { text-align: right !important; }
html.force-desktop .receipt table.r-items td.text-center { text-align: center !important; }
html.force-desktop .receipt table.r-items td.amount { color: #d9534f !important; font-weight: 600 !important; }

/* 开具明细录入表（编辑页）同样恢复桌面表格，保持一致 */
html.force-desktop .table.items-table { display: table !important; }
html.force-desktop .table.items-table thead { display: table-header-group !important; }
html.force-desktop .table.items-table tbody { display: table-row-group !important; }
html.force-desktop .table.items-table tr { display: table-row !important; }
html.force-desktop .table.items-table td { display: table-cell !important; }
html.force-desktop .table.items-table .item-row { border: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; }
html.force-desktop .table.items-table td::before { display: none !important; content: none !important; }

/* ====== 徽章 / 结算状态 ====== */
.badge { display: inline-block; padding: 2px 9px; border-radius: 4px; font-size: 12px; font-weight: 500; line-height: 1.6; }
.badge-ok   { background: #d4edda; color: #155724; }
.badge-void { background: #f8d7da; color: #721c24; }
.badge-in   { background: #eafaf0; color: #2e9e5b; }
.badge-out  { background: #fdeeee; color: #d9534f; }
.badge-warn { background: #fff3cd; color: #856404; }
.badge-svc  { background: #e7e3ff; color: #5b3fd6; font-weight: 600; }
.chk-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--c-text); cursor: pointer; white-space: nowrap; }
.chk-inline input { width: auto; }
.settle-row { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 12px; }
.settle-row > div { display: flex; flex-direction: column; gap: 2px; }
.settle-row .muted { font-size: 12px; }
.settle-row strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.ok   { color: var(--c-success); }
.warn { color: var(--c-danger); }

/* ====== 统计卡（首页 / 统计 / 账款） ====== */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-box {
    display: block; background: var(--c-card); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow); color: var(--c-text);
    transition: all .15s; border: 1px solid var(--c-border);
}
.stat-box:hover { text-decoration: none; box-shadow: 0 4px 14px rgba(0,0,0,.1); transform: translateY(-1px); }
.stat-box.in  { border-top: 3px solid #2e9e5b; }
.stat-box.out { border-top: 3px solid #d9534f; }
.stat-box .stat-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-box .stat-label { font-size: 13px; color: var(--c-muted); margin-top: 4px; }
.stat-box .stat-sub { font-size: 12px; color: var(--c-muted); margin-top: 2px; }
@media (max-width: 768px) { .stat-row { grid-template-columns: 1fr 1fr; } }

/* ====== 基础资料 CRUD 列表（单位/分类） ====== */
.crud-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.crud-row .crud-main { flex: 1; }
.crud-row .crud-main b { font-size: 14px; }
.crud-row .crud-main span { color: var(--c-muted); font-size: 12px; margin-left: 8px; }
.crud-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.crud-form .form-row { margin-bottom: 0; min-width: 180px; }

/* 分类行：可点击选中 */
.crud-row .crud-pick { flex: 1; cursor: pointer; text-decoration: none; color: var(--c-text); }
.crud-row .crud-pick:hover b { color: var(--c-primary); }
.crud-row.sel { border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(44,123,229,.15); background: #f5f9ff; }

/* ====== 弹窗（新增/编辑货品） ====== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 420px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-title { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--c-border); font-weight: 600; font-size: 15px; }
.modal-close { border: none; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--c-muted); }
.modal-close:hover { color: var(--c-danger); }
.modal-body { padding: 18px; }
.modal-body .form-row { margin-bottom: 14px; }
.modal-body .form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ====== 归入分类：多选货品面板 ====== */
.pick-panel { margin-top: 18px; border: 1px solid var(--c-border); border-radius: 10px; padding: 16px; background: #fafbfd; }
.pick-panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pick-panel-head b { font-size: 14px; }
.pick-list { max-height: 320px; overflow: auto; border: 1px solid var(--c-border); border-radius: 8px; background: #fff; }
.pick-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid #f0f2f5; cursor: pointer; }
.pick-item:last-child { border-bottom: none; }
.pick-item:hover { background: #f5f9ff; }
.pick-item.checked { background: #eef5ff; }
.pick-item input[type=checkbox] { width: 16px; height: 16px; flex: none; }
.pick-name { font-size: 14px; flex: 1; }
.pick-meta { color: var(--c-muted); font-size: 12px; }
.pick-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }

/* 选中分类后的「添加产品」工具条 */
.pick-toolbar { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 10px 12px; border: 1px dashed var(--c-primary); border-radius: 8px; background: #f5f9ff; }
.pick-toolbar b { font-size: 14px; }
.pick-toolbar .btn { margin-left: auto; }

/* 产品列表过滤（未分类 / 全部） */
.pick-filter { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pick-filter .pfilter { border: 1px solid var(--c-border); background: #fff; color: var(--c-text); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.pick-filter .pfilter.active { border-color: var(--c-primary); background: var(--c-primary); color: #fff; }
.pick-filter #pickSearch { margin-left: auto; width: 200px; }
.pick-item.is-uncat .pick-name::after { content: '未分类'; color: #c0392b; font-size: 11px; border: 1px solid #f0c0b8; border-radius: 4px; padding: 1px 5px; margin-left: 8px; }
.pick-empty { font-size: 13px; }

/* ==========================================================================
   移动端适配（全站统一）
   目标：320–430px（至少覆盖 iPhone SE 375px 与常见安卓 360px）
   策略：只改排布、不删减数据；所有点击区域 ≥44×44；安全区适配；
        正文 ≥15px、辅助文字 ≥13px；列表表格改纵向卡片，消除横向滚动。
   断点：≤768px（平板+手机通用） → ≤430px（主流手机） → ≤360px（极窄屏）
   注意：全部限定 screen，不影响打印与 PDF 导出。
   ========================================================================== */

/* 图片/图标按屏幕自适应，永不撑破布局 */
img, svg, video { max-width: 100%; height: auto; }
/* iOS 横竖屏切换时禁止字体自动放大（否则排版会跳变） */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

@media screen and (max-width: 768px) {
    /* ---------- 1. 布局：消除横向滚动 ---------- */
    html, body { overflow-x: hidden; }
    body { font-size: 15px; line-height: 1.65; }

    /* 安全区：左右避让刘海（横屏），底部避让 Home 横条 */
    .topbar-inner {
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
    }
    .container {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    .footer, .site-footer {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    /* 顶栏品牌名过长时省略号，不挤压汉堡按钮 */
    .brand { min-width: 0; }
    .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* ---------- 1b. 导航抽屉（移动端核心改造） ----------
       顶栏保持单行：品牌名（省略号） + 汉堡按钮；
       菜单改为顶栏下方的滑出面板，整行可点、左对齐，不撑开文档流。 */
    .topbar { position: relative; z-index: 90; }
    .nav-toggle {
        width: 44px; height: 44px; min-width: 44px; padding: 0;
        display: flex; align-items: center; justify-content: center;
        background: rgba(255,255,255,.18); font-size: 18px; line-height: 1;
        flex: none;
    }
    .nav-toggle-icon { display: block; line-height: 1; }

    .menu {
        position: absolute; top: 100%; left: 0; right: 0;
        display: none;
        flex-direction: column; gap: 0;
        background: #1a68d4;
        box-shadow: 0 12px 28px rgba(0,0,0,.28);
        max-height: calc(100vh - 56px);
        overflow-y: auto; -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .menu.open { display: flex; }

    /* 菜单项：整行可点、左对齐、细分隔线 */
    .menu > a, .menu > .nav-group > .nav-parent {
        display: flex; align-items: center;
        min-height: 50px; padding: 0 18px;
        font-size: 15px; color: #fff;
        text-align: left; justify-content: flex-start;
        border-radius: 0;
        border-bottom: 1px solid rgba(255,255,255,.10);
    }
    .menu > a.active {
        background: rgba(255,255,255,.16);
        box-shadow: inset 3px 0 0 #fff;
        font-weight: 500;
    }
    .menu > a:active, .menu > .nav-group > .nav-parent:active { background: rgba(255,255,255,.26); }

    /* 分组父项：右侧显示展开/收起符号 */
    .nav-group { width: 100%; display: block; }
    .menu > .nav-group > .nav-parent { justify-content: space-between; }
    .nav-group .nav-parent::after { content: '＋'; font-size: 17px; opacity: .9; }
    .nav-group.open .nav-parent::after { content: '－'; }
    .nav-group .submenu {
        position: static; display: none;
        flex-direction: column;
        background: rgba(0,0,0,.18);
        box-shadow: none; padding: 0; border-radius: 0; min-width: 0;
    }
    .nav-group.open .submenu { display: flex; }
    .nav-group .submenu a {
        display: flex; align-items: center;
        min-height: 46px; padding: 0 18px 0 34px;
        font-size: 14px; color: rgba(255,255,255,.94);
        text-align: left; justify-content: flex-start;
        border-radius: 0; border-bottom: 1px solid rgba(255,255,255,.07);
    }
    .nav-group .submenu a:last-child { border-bottom: none; }
    .nav-group .submenu a.active { background: rgba(255,255,255,.14); }

    /* 抽屉底部：用户信息 + 退出（桌面端隐藏，由右上 .user-box 呈现） */
    .menu-user {
        display: flex; align-items: center; justify-content: space-between;
        gap: 10px; padding: 10px 18px;
        background: rgba(0,0,0,.22);
        border-top: 1px solid rgba(255,255,255,.14);
    }
    .menu-user-name {
        display: flex; align-items: center; gap: 8px;
        min-height: 44px; color: #fff; font-size: 15px; font-weight: 500;
        min-width: 0;
    }
    .menu-user-name:hover { color: #fff; text-decoration: none; }
    .menu-user .user-role { font-size: 12px; padding: 2px 6px; border-radius: 4px; flex: none; }
    .menu-user-logout {
        display: flex; align-items: center; flex: none;
        min-height: 44px; padding: 0 16px;
        color: #fff; font-size: 14px;
        border: 1px solid rgba(255,255,255,.5); border-radius: 6px;
    }
    .menu-user-logout:hover { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }

    /* ---------- 2. 触控：点击区域 ≥44×44，去掉 300ms 点击延迟 ---------- */
    a, button, .btn, input, select, textarea, label, .pager-item { touch-action: manipulation; }
    .btn, .btn-sm, .btn-primary, .btn-danger, .btn-ghost, .btn-in, .btn-out {
        min-height: 44px; padding: 10px 16px; font-size: 15px;
        display: inline-flex; align-items: center; justify-content: center;
    }
    .btn-sm { font-size: 14px; padding: 8px 12px; }
    /* 触控尺寸在抽屉段统一定义，此处只处理顶栏按钮本体 */
    .nav-toggle { min-width: 44px; min-height: 44px; font-size: 20px; padding: 8px 14px; }

    /* 分页器：此前 .pager-item 完全没有定义过样式，这里首次补齐并满足触控尺寸 */
    .pager a, .pager-item, .pagination a, .pagination span {
        min-width: 44px; min-height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
        padding: 0 12px; font-size: 15px;
        border: 1px solid var(--c-border); border-radius: 6px; background: #fff;
    }
    .pager-item.active, .pagination .current {
        background: var(--c-primary); color: #fff; border-color: var(--c-primary);
    }
    .pager a:hover, .pager-item:hover { text-decoration: none; }

    /* 输入框 16px：防止 iOS Safari 聚焦时整页自动放大 */
    .input, .select, .textarea { min-height: 44px; font-size: 16px; padding: 10px 12px; }
    .filter-bar .select-sm, .filter-bar .input-sm, .per-form .select-sm { min-height: 44px; font-size: 16px; }

    /* 自动补全下拉项 */
    .ac-box .ac-item { min-height: 44px; align-items: center; font-size: 15px; padding: 8px 12px; }
    /* 勾选框放大，便于手指点按 */
    input[type="checkbox"] { width: 20px; height: 20px; }
    .pick-item input[type="checkbox"] { width: 22px; height: 22px; }
    .chk-inline { min-height: 44px; font-size: 15px; }

    /* 归入分类面板 */
    .pick-item { min-height: 44px; padding: 10px 12px; }
    .pick-filter { flex-wrap: wrap; }
    .pick-filter .pfilter { min-height: 44px; padding: 10px 14px; font-size: 15px; }
    .pick-filter #pickSearch { width: 100%; margin-left: 0; min-height: 44px; }
    /* 弹窗关闭按钮 */
    .modal-close { min-width: 44px; min-height: 44px; font-size: 26px; }

    /* 基础资料行 / 表单：窄屏纵向铺满 */
    .crud-row { flex-wrap: wrap; }
    .crud-form { flex-direction: column; align-items: stretch; }
    .crud-form .form-row { min-width: 0; width: 100%; }

    /* ---------- 3. 字号：辅助信息不小于 13px ---------- */
    .stat-label, .stat-box .stat-sub, .muted,
    .crud-row .crud-main span, .ac-box .ac-item .ac-meta,
    .settle-row .muted, .login-tip { font-size: 13px; }
    .table td, .table th { font-size: 14px; }

    /* ---------- 4. 列表表格：纵向卡片堆叠（消除横向滚动） ----------
       列名由 app.js 从 <thead> 注入到每个 <td data-label>，无需改动各 PHP 页面 */
    .table:not(.items-table),
    .table:not(.items-table) tbody,
    .table:not(.items-table) tr,
    .table:not(.items-table) td { display: block; width: 100%; }
    .table:not(.items-table) { min-width: 0; border: none; background: transparent; }
    .table:not(.items-table) thead { display: none; }
    .table:not(.items-table) tbody tr {
        border: 1px solid var(--c-border); border-radius: 10px;
        padding: 10px 12px; margin-bottom: 10px; background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,.05);
    }
    .table:not(.items-table) tbody td {
        display: flex; align-items: baseline; justify-content: space-between;
        gap: 12px; padding: 7px 0; border: none !important;
        white-space: normal !important; text-align: right; font-size: 14px;
    }
    .table:not(.items-table) tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto; max-width: 40%;
        color: #5a6877; font-weight: 600; font-size: 13px; text-align: left;
    }
    .table:not(.items-table) tbody td:not([data-label])::before { display: none; }
    .table:not(.items-table) tbody td:not([data-label]) { justify-content: flex-end; }
    .table:not(.items-table) tbody td.amount { font-size: 15px; }

    /* 展开的明细行：紧贴主卡片，不再套一层卡片边框 */
    .table:not(.items-table) tbody tr.detail-row {
        display: block; border: none; box-shadow: none;
        background: transparent; padding: 0; margin: -6px 0 10px;
    }
    .recent-table tbody tr.main-row { cursor: pointer; }
    /* 明细小表：卡片内保持表格形态，列名可见、行高够点按 */
    .order-detail-mini table { font-size: 13px; }
    .order-detail-mini th, .order-detail-mini td { padding: 6px 8px; }

    /* ---------- 5. 性能：弱化阴影、滚动区启用惯性 ---------- */
    .card, .stat-card, .stat-box { box-shadow: 0 1px 4px rgba(0,0,0,.05); }
    .print-area, .pick-list, .modal, .ac-box { -webkit-overflow-scrolling: touch; }
}

/* ---------- 主流手机（≤430px）：进一步收紧间距 ---------- */
@media screen and (max-width: 430px) {
    .container { margin: 10px auto; }
    .card { padding: 12px; }
    .card-title { font-size: 15px; margin-bottom: 12px; padding-bottom: 10px; }
    .stats, .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card, .stat-box { padding: 12px; }
    .stat-value, .stat-box .stat-num { font-size: 20px; }
    .topbar-inner { gap: 10px; }
    .brand-name { font-size: 14px; }
    /* 金额区间：两个输入框上下排，避免挤在一行 */
    .filter-bar .range { flex-direction: column; align-items: stretch; gap: 6px; }
    .filter-bar .range-sep { display: none; }
    .settle-row { gap: 14px; }
    .settle-row strong { font-size: 16px; }

    /* 收据预览：取消 360px 最小宽，铺满屏幕并收缩金额框，避免横向滚动 */
    .receipt { width: 100%; min-width: 0; padding: 12mm 8mm; }
    .receipt .r-title { font-size: 20px; letter-spacing: 2px; }
    .receipt .r-amount-box .r-amt-label { flex: 0 0 62px; font-size: 11px; padding: 6px 6px; }
    .receipt .r-amount-box .r-amount-cn { font-size: 14px; padding: 6px 8px; letter-spacing: 0; }
    .receipt .r-amount-box .r-amount-num { font-size: 18px; padding: 6px 8px; }
    .receipt .r-seal { width: 96px; height: 96px; font-size: 14px; right: 12mm; bottom: 12mm; }
}

/* ---------- 极窄屏（≤360px，含 iPhone SE 一代等） ---------- */
@media screen and (max-width: 360px) {
    .container { padding-left: 10px; padding-right: 10px; }
    .stats, .stat-row { grid-template-columns: 1fr; }
    .table:not(.items-table) tbody td { font-size: 13px; }
    .table:not(.items-table) tbody td::before { font-size: 12px; max-width: 44%; }
    .btn, .btn-sm { padding: 10px 12px; }
    .menu a, .nav-parent { padding: 10px; font-size: 14px; }
}

/* ---------- 导出 PDF 时还原列表表格为桌面形态 ----------
   html2pdf 导出会给 <html> 加 .force-desktop；
   这里兜底还原，避免卡片堆叠被带进导出的 PDF（收据/明细已有各自的还原规则）。 */
html.force-desktop .table:not(.items-table) { display: table !important; }
html.force-desktop .table:not(.items-table) thead { display: table-header-group !important; }
html.force-desktop .table:not(.items-table) tbody { display: table-row-group !important; }
html.force-desktop .table:not(.items-table) tr { display: table-row !important; }
html.force-desktop .table:not(.items-table) td { display: table-cell !important; }
html.force-desktop .table:not(.items-table) tbody tr {
    border: none !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 !important; background: transparent !important;
}
html.force-desktop .table:not(.items-table) tbody td::before { display: none !important; }

