:root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --text: #16233a;
    --muted: #6b7791;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #ea580c;
    --info: #0e7490;
    --sales: #7c3aed;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

/* 顶栏 */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    height: 62px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 16px;
}
.nav { display: flex; align-items: center; gap: 4px; height: 100%; }
.nav a {
    padding: 8px 16px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav a:hover { background: #f1f5f9; color: var(--text); }
.nav a.active { background: #eff6ff; color: var(--primary); }

/* 容器 */
.container { max-width: 1440px; margin: 0 auto; padding: 28px 24px 60px; }
.footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    text-align: center;
    padding: 20px;
    font-size: 12px;
    background: var(--card);
}

/* 标题区 */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.page-head h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.4px; }
.sub { color: var(--muted); margin: 0; font-size: 14px; }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* 提示 */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: 13px; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* 面板 */
.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-note { color: var(--muted); font-size: 12px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* 记账录入 */
.date-jump { display: flex; align-items: center; gap: 10px; }
.date-jump label { color: var(--muted); font-size: 13px; }
input[type="date"], .text-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    font-family: inherit;
}
input:focus, .text-input:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.entry-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field-list { padding: 8px 20px 18px; }
.field-list.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding-top: 18px; }
.field-row { padding: 11px 0; border-bottom: 1px dashed #edf1f7; }
.field-row:last-child { border-bottom: none; }
.field-row label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field-row label small { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }
.input-wrap { position: relative; max-width: 260px; }
.currency {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}
.money-input {
    width: 100%;
    padding: 8px 12px 8px 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    font-family: inherit;
    color: var(--text);
}
.money-input:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
    vertical-align: 1px;
}
.tag-today { background: #eff6ff; color: #1d4ed8; }
.tag-yesterday { background: #f1f5f9; color: #475569; }
.tag-minus { background: #fef2f2; color: #b91c1c; }
.tag-income { background: #ecfdf5; color: #047857; }
.tag-end { background: #f5f3ff; color: #6d28d9; }
.tag-required { background: #fff7ed; color: #c2410c; }

/* 汇总卡片 */
.summary-panel { background: linear-gradient(180deg, #fbfdff 0%, #fff 100%); }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 20px; }
.stat-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    background: #fff;
}
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.stat-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
#diffCard.status-short { border-color: #fecaca; background: #fef2f2; }
#diffCard.status-short .stat-value, #diffCard.status-short .stat-hint { color: var(--danger); }
#diffCard.status-over { border-color: #fed7aa; background: #fff7ed; }
#diffCard.status-over .stat-value, #diffCard.status-over .stat-hint { color: var(--warning); }
#diffCard.status-balanced { border-color: #bbf7d0; background: #f0fdf4; }
#diffCard.status-balanced .stat-value, #diffCard.status-balanced .stat-hint { color: var(--success); }
.formula-line {
    padding: 0 20px 18px;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}
.form-actions { padding: 0 20px 20px; display: flex; gap: 10px; justify-content: center; }

/* 总览 */
.hero-card {
    background: linear-gradient(120deg, #1e3a8a 0%, #2563eb 100%);
    color: #fff;
    border-radius: 14px;
    padding: 26px 30px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    flex-wrap: wrap;
    box-shadow: 0 8px 24px rgba(37, 99, 235, .18);
}
.hero-empty { background: linear-gradient(120deg, #334155 0%, #475569 100%); }
.hero-empty h2 { margin: 0 0 6px; font-size: 20px; }
.hero-empty p { margin: 0; opacity: .85; }
.hero-label { opacity: .8; font-size: 13px; }
.hero-status { font-size: 38px; font-weight: 800; line-height: 1.3; }
.hero-status.status-short { color: #fecaca; }
.hero-status.status-over { color: #fed7aa; }
.hero-status.status-balanced { color: #bbf7d0; }
.hero-diff { opacity: .9; font-size: 13px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-diff .vs { opacity: .5; font-size: 11px; }
.mini-stat-sales { background: linear-gradient(135deg, #eff6ff, #f5f3ff); border-color: #dbeafe; }
.hero-right { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.hero-metric { display: flex; flex-direction: column; gap: 2px; }
.hero-metric span { opacity: .8; font-size: 12px; }
.hero-metric strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.hero-card .btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.3); }

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.mini-stat {
    flex: 1 1 150px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mini-stat span { color: var(--muted); font-size: 12px; }
.mini-stat strong { font-size: 19px; font-variant-numeric: tabular-nums; }

/* 表格 */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid #edf1f7; white-space: nowrap; }
.table th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; }
.table tbody tr:hover { background: #fafcff; }
.table tfoot td { background: #f8fafc; font-weight: 700; border-top: 2px solid var(--border); }
.num-strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.text-short { color: var(--danger) !important; }
.text-over { color: var(--warning) !important; }
.text-balanced { color: var(--success) !important; }
.text-sales { color: var(--sales) !important; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-short { background: #fee2e2; color: #b91c1c; }
.badge-over { background: #ffedd5; color: #c2410c; }
.badge-balanced { background: #dcfce7; color: #15803d; }

.link { color: var(--primary); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--danger); background: none; border: none; padding: 0; cursor: pointer; font-size: inherit; font-family: inherit; font-weight: 600; }
.inline-form { display: inline; margin-left: 10px; }

/* 筛选 */
.filter-panel { padding: 0; }
.filter-form { display: flex; align-items: flex-end; gap: 16px; padding: 18px 20px 12px; flex-wrap: wrap; }
.filter-item { display: flex; flex-direction: column; gap: 5px; }
.filter-item label { font-size: 12px; color: var(--muted); }
.filter-actions { display: flex; gap: 8px; }
.quick-ranges { padding: 0 20px 16px; display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.quick-ranges a { color: var(--primary); text-decoration: none; }

/* 统计 */
.period-tabs { display: flex; gap: 2px; padding: 14px 18px 0; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.period-tab {
    padding: 8px 16px;
    border-radius: 8px 8px 0 0;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
}
.period-tab:hover { background: #f8fafc; color: var(--text); }
.period-tab.active { background: #eff6ff; color: var(--primary); }
.stats-filter { padding-top: 16px; }
.range-note { margin-left: auto; align-self: center; color: var(--muted); font-size: 12px; }

.chart { padding: 18px 20px 6px; }
.chart-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.chart-label { width: 110px; flex-shrink: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.chart-bar-wrap { flex: 1; background: #f1f5f9; border-radius: 6px; height: 26px; position: relative; overflow: hidden; }
.chart-bar { height: 100%; background: linear-gradient(90deg, #8b5cf6, #6d28d9); border-radius: 6px; }
.chart-value { position: absolute; right: 10px; top: 3px; font-size: 12px; font-weight: 700; color: var(--text); }
.chart-meta { width: 170px; flex-shrink: 0; font-size: 12px; color: var(--muted); text-align: right; }

/* 响应式 */
@media (max-width: 960px) {
    .entry-grid { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: 1fr 1fr; }
    .field-list.two-col { grid-template-columns: 1fr; }
    .topbar-inner { padding: 0 14px; }
    .container { padding: 20px 14px 50px; }
    .nav a { padding: 8px 10px; font-size: 13px; }
    .brand span:last-child { display: none; }
    .chart-label { width: 80px; }
    .chart-meta { display: none; }
}
@media (max-width: 600px) {
    .summary-grid { grid-template-columns: 1fr; }
    .hero-right { gap: 16px; }
    .stat-value { font-size: 20px; }
}

/* ===== 用户与权限 ===== */
.user-area { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.user-badge { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 20px; background: #f8fafc; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.user-name { font-size: 13px; font-weight: 600; }
.role-pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.role-admin { background: #dbeafe; color: #1d4ed8; }
.role-user { background: #f1f5f9; color: #475569; }
.logout-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.logout-link:hover { color: var(--danger); }

.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.tag-locked { background: #f1f5f9; color: #64748b; }
.money-input-locked { background: #f8fafc; color: var(--muted); cursor: not-allowed; }
.money-input-locked:focus { outline: none; border-color: var(--border); }

.badge-admin { background: #dbeafe; color: #1d4ed8; }
.badge-user { background: #f1f5f9; color: #475569; }

.select-input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); }

.permission-box { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 20px; }
.permission-col h3 { margin: 0 0 8px; font-size: 15px; }
.permission-col p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.permission-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.inline-details { display: inline; }
.inline-details summary { list-style: none; cursor: pointer; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-edit-form { position: absolute; z-index: 10; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px; box-shadow: 0 8px 24px rgba(16,24,40,.12); display: flex; flex-direction: column; gap: 10px; min-width: 230px; }
.table td { position: relative; }

/* 登录页 */
.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #eff6ff 0%, #f4f6fa 50%, #faf5ff 100%); padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 36px; box-shadow: 0 20px 50px rgba(16,24,40,.1); border: 1px solid var(--border); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .brand-mark { width: 40px; height: 40px; font-size: 20px; }
.login-brand h1 { font-size: 19px; margin: 0; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form input[type="text"], .login-form input[type="password"] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; }
.captcha-row { display: flex; align-items: stretch; gap: 8px; }
.captcha-row input[type="text"] { flex: 1; min-width: 0; width: auto; }
.captcha-img { flex: 0 0 124px; width: 124px; height: 42px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: #f8fafc; }
.captcha-img:active { opacity: .75; }
.login-btn { width: 100%; padding: 11px; margin-top: 4px; }
.login-hint { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); line-height: 1.9; }
.login-hint code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; color: var(--primary); }

@media (max-width: 960px) {
    .user-name { display: none; }
    .permission-box { grid-template-columns: 1fr; }
}

/* 危险操作区 */
.danger-zone { border-color: #fecaca; }
.danger-zone .panel-head { background: #fef2f2; }
.danger-zone .panel-head h2 { color: #b91c1c; }
.danger-zone-body { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; flex-wrap: wrap; }
.danger-zone-body p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* ===================================================================
   移动端适配
   桌面端导航图标与短标签默认隐藏；窄屏时导航移到底部固定标签栏
   =================================================================== */
.nav-icon, .nav-label-short { display: none; }

@media (max-width: 1024px) {
    .topbar-inner { padding: 0 16px; gap: 14px; }
    .container { padding: 22px 16px 50px; }
    .nav a { padding: 8px 11px; }
}

@media (max-width: 720px) {
    html { -webkit-text-size-adjust: 100%; }
    body {
        padding-bottom: 64px;
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }

    /* 顶栏只保留品牌与用户，导航下移 */
    .topbar-inner { height: 54px; padding: 0 14px; gap: 10px; }
    .brand { font-size: 15px; gap: 7px; }
    .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
    .brand .brand-name { display: inline; font-size: 14px; }
    .user-area { gap: 8px; }
    .user-badge { padding: 2px; background: transparent; }
    .user-avatar { width: 28px; height: 28px; }
    .role-pill { display: none; }
    .logout-link { font-size: 12px; white-space: nowrap; }

    /* 底部固定标签栏 */
    .nav {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: 60px;
        height: calc(60px + env(safe-area-inset-bottom, 0px));
        padding: 0 4px 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        align-items: stretch;
        gap: 0;
        background: var(--card);
        border-top: 1px solid var(--border);
        box-shadow: 0 -3px 16px rgba(16, 24, 40, .08);
        z-index: 40;
    }
    .nav a {
        flex: 1 1 0;
        min-width: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 4px 0;
        border-radius: 0;
        font-size: 11px;
        line-height: 1.2;
    }
    .nav a:hover, .nav a.active { background: transparent; color: var(--muted); }
    .nav a.active { color: var(--primary); }
    .nav-icon { display: block; width: 22px; height: 22px; }
    .nav-icon svg { width: 100%; height: 100%; display: block; }
    .nav-label-full { display: none; }
    .nav-label-short { display: block; white-space: nowrap; }

    /* 页面骨架 */
    .container { padding: 16px 12px 28px; }
    .page-head { margin-bottom: 16px; gap: 12px; }
    .page-head h1 { font-size: 23px; }
    .sub { font-size: 12px; line-height: 1.5; }
    .page-head > a.btn, .page-head > .btn, .page-head > .date-jump { width: 100%; }
    .page-head .date-jump { justify-content: space-between; }
    .date-jump input[type="date"] { flex: 1; min-width: 0; }

    /* 面板与表单：输入框 16px 防止 iOS Safari 自动缩放 */
    .panel { margin-bottom: 14px; }
    .panel-head { padding: 13px 14px; gap: 8px; }
    .panel-head h2 { font-size: 15px; }
    .panel-note { font-size: 11px; }
    .field-list { padding: 6px 14px 14px; }
    .field-row { padding: 10px 0; }
    .field-row label { font-size: 13px; }
    .field-row label small { display: block; margin: 2px 0 0; font-size: 11px; }
    .input-wrap { max-width: 100%; }
    .money-input { font-size: 16px; padding: 10px 12px 10px 30px; }
    input[type="date"], .text-input, .select-input {
        font-size: 16px; padding: 9px 10px; max-width: 100%;
    }
    .tag { font-size: 10px; }
    .alert { padding: 10px 12px; font-size: 12px; }

    /* 汇总卡片两列 */
    .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; }
    .stat-card { padding: 12px; }
    .stat-label { font-size: 12px; }
    .stat-value { font-size: 18px; letter-spacing: -.4px; }
    .stat-hint { font-size: 11px; }
    .formula-line { padding: 0 14px 14px; font-size: 11px; }
    .form-actions { padding: 0 14px 16px; flex-direction: column; }
    .form-actions .btn { width: 100%; }
    .btn { min-height: 40px; padding: 9px 14px; }
    .btn-sm { min-height: 36px; padding: 6px 10px; }

    /* 总览：hero 卡片上下分区，对齐更整齐 */
    .hero-card { padding: 22px 20px; gap: 20px; border-radius: 14px; flex-direction: column; align-items: stretch; }
    .hero-left { width: 100%; }
    .hero-label { font-size: 12px; }
    .hero-status { font-size: 36px; line-height: 1.25; }
    .hero-diff { font-size: 12px; gap: 6px; margin-top: 4px; }
    .hero-diff .vs { font-size: 10px; }
    .hero-right {
        width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
        align-items: stretch; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.2);
    }
    .hero-metric { background: rgba(255,255,255,.1); border-radius: 10px; padding: 12px; }
    .hero-metric span { font-size: 11px; }
    .hero-metric strong { font-size: 19px; }
    .hero-right .btn { grid-column: 1 / -1; width: 100%; }
    .hero-empty { align-items: flex-start; }
    .hero-empty .btn { width: 100%; }

    /* 统计卡片：本月销额独占一行，其余 2×2 对齐 */
    .stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .mini-stat { padding: 13px 14px; }
    .mini-stat-sales { grid-column: 1 / -1; }
    .mini-stat-sales strong { font-size: 24px; }
    .mini-stat strong { font-size: 20px; }

    /* 表格：保留横向滚动 */
    .table-scroll { -webkit-overflow-scrolling: touch; }
    .table th, .table td { padding: 9px 10px; }
    .badge { font-size: 11px; padding: 3px 8px; }

    /* 筛选区 */
    .filter-form { padding: 14px 14px 8px; gap: 10px; }
    .filter-item { flex: 1 1 130px; min-width: 0; }
    .filter-item input { width: 100%; }
    .filter-actions { width: 100%; }
    .filter-actions .btn { flex: 1; }
    .quick-ranges { padding: 0 14px 14px; gap: 10px; }

    /* 统计页 */
    .period-tabs { padding: 10px 8px 0; }
    .period-tab { flex: 1 1 auto; text-align: center; padding: 8px 6px; font-size: 12px; }
    .range-note { width: 100%; margin-left: 0; align-self: flex-start; }
    .chart { padding: 14px 12px 4px; }
    .chart-row { gap: 8px; }
    .chart-label { width: 58px; font-size: 11px; }
    .chart-bar-wrap { height: 24px; }
    .chart-value { font-size: 11px; right: 6px; }

    /* 登录页：进一步收紧账号、密码与登录按钮的纵向间距 */
    .login-body { padding: 14px; min-height: 100vh; min-height: 100dvh; }
    .login-card { padding: 18px 20px; }
    .login-brand { margin-bottom: 2px; }
    .login-brand .brand-mark { width: 36px; height: 36px; font-size: 18px; }
    .login-brand h1 { font-size: 18px; }
    .login-sub { margin-bottom: 10px; }
    .login-form { gap: 6px; }
    .login-form .filter-item { gap: 2px; }
    .login-form input[type="text"], .login-form input[type="password"] { padding: 8px 10px; }
    .captcha-img { flex-basis: 112px; width: 112px; height: 38px; }
    .login-btn { margin-top: 0; padding: 10px; }
    .login-hint { margin-top: 12px; padding-top: 10px; font-size: 11px; line-height: 1.6; }

    /* 用户管理：编辑面板改为底部弹层 */
    .table td { position: static; }
    .inline-edit-form {
        position: fixed;
        left: 12px; right: 12px;
        bottom: 72px;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        min-width: 0;
        z-index: 50;
    }
    .permission-box { padding: 14px; gap: 14px; }

    /* 危险操作区 */
    .danger-zone-body { padding: 14px; }
    .danger-zone-body form { width: 100%; }
    .danger-zone-body .btn { width: 100%; }
}

@media (max-width: 360px) {
    .brand .brand-name { display: none; }
    .summary-grid { grid-template-columns: 1fr; }
    .nav-label-short { font-size: 10px; }
    .user-name { display: none; }
}

/* ===== 多店铺 ===== */
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.shop-switcher {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc;
}
.shop-switcher-icon { display: inline-flex; width: 16px; height: 16px; color: var(--primary); }
.shop-switcher-icon svg { width: 100%; height: 100%; }
.shop-switcher select {
    border: none; background: transparent; font-size: 13px; font-weight: 600;
    color: var(--text); font-family: inherit; cursor: pointer; max-width: 160px; padding: 2px 0;
}
.shop-switcher select:focus { outline: none; }
.text-muted { color: var(--muted); font-size: 12px; }
.shop-assign { flex: 1 1 240px; }
.shop-checks {
    display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
    max-height: 140px; overflow-y: auto;
}
.shop-check {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 9px; border-radius: 6px; background: #f8fafc;
    font-size: 12px; cursor: pointer; white-space: nowrap;
}
.shop-check input { accent-color: var(--primary); margin: 0; }

@media (max-width: 720px) {
    .topbar-inner { gap: 8px; }
    .topbar-right { gap: 8px; }
    .shop-switcher { padding: 3px 6px; max-width: 44vw; }
    .shop-switcher select { font-size: 12px; max-width: 34vw; }
    .shop-switcher-icon { width: 14px; height: 14px; }
    .user-badge { padding: 2px; }
    .logout-link { font-size: 12px; }
    .shop-checks { max-height: 110px; }
}
@media (max-width: 400px) {
    .shop-switcher-icon { display: none; }
    .shop-switcher select { max-width: 30vw; }
}

/* 店铺重命名：行内编辑，避免弹层被表格滚动区裁剪 */
.rename-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rename-form input[type="text"] {
    flex: 1 1 150px; min-width: 110px; max-width: 260px;
    padding: 5px 9px; border: 1px solid var(--primary); border-radius: 7px;
    font-size: 14px; font-family: inherit; color: var(--text); background: #fff;
}
.rename-form input[type="text"]:focus { outline: 2px solid rgba(59,130,246,.25); }
@media (max-width: 720px) {
    .rename-form input[type="text"] { font-size: 16px; flex-basis: 100%; max-width: none; }
}

/* 用户编辑面板：表格外独立区块，避免被表格滚动区裁剪 */
.edit-user-panel { border-color: var(--primary); }
.edit-user-panel .panel-head { background: #eff6ff; }
.edit-user-panel .panel-head h2 { color: var(--primary); }

/* ===== 账单打印 / 导出 ===== */
.print-actions { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.print-sheet { background: #fff; padding: 28px 32px; border-radius: 12px; border: 1px solid var(--border); }
.print-sheet h1 { font-size: 22px; margin: 0 0 6px; }
.print-sheet .meta { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.print-sheet .meta span { margin-right: 18px; }
.print-sheet .summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.print-sheet .summary div { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 130px; }
.print-sheet .summary span { display: block; color: var(--muted); font-size: 11px; }
.print-sheet .summary strong { font-size: 16px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-table th, .print-table td { border: 1px solid var(--border); padding: 6px 6px; text-align: right; white-space: nowrap; }
.print-table th { background: #f3f4f6; text-align: center; }
.print-table td.l, .print-table th.l { text-align: left; }
.print-table td.c { text-align: center; }
.print-table tr:nth-child(even) td { background: #fafafa; }
.print-table .tfoot td { background: #e5e7eb !important; font-weight: 700; }
.print-table .short { color: #dc2626; }
.print-table .over { color: #d97706; }
.print-sheet .note { margin-top: 12px; color: var(--muted); font-size: 11px; }
.print-sheet .empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 720px) {
    .print-sheet { padding: 16px 12px; }
    .print-sheet .summary div { min-width: calc(50% - 4px); }
    .print-sheet .meta span { display: block; margin-right: 0; margin-bottom: 2px; }
}

.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 720px) { .page-head-actions .btn { flex: 1 1 auto; text-align: center; } }

/* ===== 账单打印页：布局切换 + 单日账单 ===== */
.layout-switch { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.layout-switch .hint { color: var(--muted); font-size: 12px; }
.print-sheet .cover { text-align: center; margin-bottom: 18px; }
.print-sheet .cover h1 { font-size: 22px; margin: 0 0 6px; }
.print-sheet .cover p { color: var(--muted); font-size: 12px; margin: 0; }

/* 单日账单：每天一张，左右两栏用表格实现（PDF 中稳定并排） */
.print-sheet .day-block { border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 18px; }
.print-sheet .day-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #374151; padding-bottom: 8px; margin-bottom: 14px; }
.print-sheet .day-head h2 { font-size: 18px; margin: 0; }
.print-sheet .day-head span { font-size: 12px; color: var(--muted); }
.print-sheet .cols { width: 100%; border-collapse: separate; border-spacing: 12px 0; table-layout: fixed; }
.print-sheet .cols > tbody > tr > td { vertical-align: top; width: 50%; padding: 0; }
.print-sheet .side h3 { font-size: 13px; margin: 0 0 8px; padding: 7px; text-align: center; border-radius: 6px; }
.print-sheet .side-left h3 { background: #dbeafe; color: #1e3a8a; }
.print-sheet .side-right h3 { background: #dcfce7; color: #14532d; }
.print-sheet .side table.detail { width: 100%; border-collapse: collapse; }
.print-sheet .side table.detail th, .print-sheet .side table.detail td { border: 1px solid var(--border); padding: 6px 8px; font-size: 12px; }
.print-sheet .side td.lbl { text-align: left; background: #f9fafb; }
.print-sheet .side td.num { text-align: right; }
.print-sheet .side tr.total td { background: #f3f4f6 !important; font-weight: 700; }
.print-sheet .result-box { width: 100%; border-collapse: separate; border-spacing: 8px 0; margin-top: 14px; table-layout: fixed; }
.print-sheet .result-box td { border: 1px solid var(--border); border-radius: 8px; padding: 8px 6px; text-align: center; }
.print-sheet .result-box span { display: block; color: var(--muted); font-size: 11px; }
.print-sheet .result-box strong { font-size: 15px; }
.print-sheet .result-box .short { color: #dc2626; }
.print-sheet .result-box .over { color: #d97706; }
.print-sheet .result-box .balanced { color: #16a34a; }
.print-sheet .day-sum { margin-top: 10px; padding: 8px 10px; background: #f3f4f6; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; line-height: 1.7; }

@media (max-width: 720px) {
    /* 筛选区：每项占满一行，日期/下拉不再被挤压 */
    .filter-panel .filter-item { flex: 1 1 100%; width: 100%; }
    .filter-panel .filter-item input,
    .filter-panel .filter-item select { width: 100%; font-size: 16px; }
    .print-actions { flex-direction: column; }
    .print-actions .btn { width: 100%; }

    .print-sheet .cover h1 { font-size: 19px; }
    .print-sheet .cover p { font-size: 11px; line-height: 1.7; }
    .print-sheet .day-block { padding: 14px 12px; border-radius: 8px; }
    .print-sheet .day-head h2 { font-size: 16px; }
    .print-sheet .cols, .print-sheet .cols > tbody, .print-sheet .cols > tbody > tr { display: block; }
    .print-sheet .cols > tbody > tr > td { display: block; width: 100%; }
    .print-sheet .cols > tbody > tr > td + td { margin-top: 14px; }
    .print-sheet .side table.detail { font-size: 12px; }
    .print-sheet .side table.detail td { padding: 7px 8px; }

    /* 结果区：5 列在窄屏会挤成一团，改为两列自动换行 */
    .print-sheet .result-box { display: block; border-spacing: 0; margin-top: 12px; }
    .print-sheet .result-box tbody { display: flex; flex-wrap: wrap; gap: 8px; }
    .print-sheet .result-box tr { display: contents; }
    .print-sheet .result-box td {
        box-sizing: border-box; display: block; width: calc(50% - 4px);
        padding: 8px 6px; margin: 0;
    }
    .print-sheet .result-box strong { font-size: 14px; }
    .print-sheet .result-box span { font-size: 10px; }
    .print-sheet .day-sum { font-size: 11px; }
    .print-sheet .note { font-size: 10px; line-height: 1.7; }
    .print-sheet .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .print-sheet .print-table { min-width: 640px; }
}

@media print {
    body { background: #fff !important; }
    .topbar, .bottom-nav, .no-print, .alert, .btn { display: none !important; }
    .main, .container, main { padding: 0 !important; margin: 0 !important; max-width: none !important; }
    .print-sheet { border: none !important; padding: 0 !important; border-radius: 0 !important; }
    .print-table { font-size: 9pt; }
    .print-table th, .print-table td { padding: 3px 4px !important; }
    .print-sheet .summary div { min-width: 0; }
    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }
    .day-block { page-break-after: always; break-after: page; }
    .day-block:last-of-type { page-break-after: auto; break-after: auto; }
    /* 打印时还原结果区为一行表格，忽略手机端的两列布局 */
    .print-sheet .result-box tbody { display: table-row-group; }
    .print-sheet .result-box tr { display: table-row; }
    .print-sheet .result-box td { display: table-cell; }
}

.stats-locked-range { padding: 0 20px 14px; margin: 0; }
@media (max-width: 720px) { .stats-locked-range { padding: 0 14px 12px; font-size: 11px; } }
