:root {
    --primary: #1677ff;
    --primary-weak: #eaf2ff;
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #1f2329;
    --muted: #8a919f;
    --line: #eef0f3;
    --danger: #e5484d;
    --green: #18a058;
    --orange: #f59e0b;
    --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
input, select, textarea, button { font-family: inherit; }

.app {
    max-width: 680px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    overflow-x: hidden;
}

/* 顶栏 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 52px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 6px;
}
.topbar-side { width: 48px; display: flex; align-items: center; }
.topbar-side.right { justify-content: flex-end; }
.topbar-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }
.icon-btn {
    width: 40px; height: 40px; border: 0; background: transparent; color: var(--text);
    font-size: 28px; line-height: 1; display: flex; align-items: center; justify-content: center;
    cursor: pointer; border-radius: 10px;
}
.icon-btn:active { background: #f2f3f5; }
.brand { font-size: 12px; color: var(--primary); font-weight: 600; padding-left: 8px; }

.page { padding: 12px 12px 90px; }
.page.no-tab { padding-bottom: 110px; }

/* 卡片 */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
}
.card.tight { padding: 4px 14px; }

.section-title {
    display: flex; align-items: center; justify-content: space-between;
    margin: 18px 4px 8px; font-size: 15px; font-weight: 600;
}
.section-title .link { font-size: 13px; font-weight: 400; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.danger { color: var(--danger); }
.green { color: var(--green); }
.center { text-align: center; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }

/* 首页 */
.hello { padding: 8px 4px 4px; }
.hello h1 { font-size: 21px; margin: 0 0 4px; }
.hello p { margin: 0; color: var(--muted); font-size: 13px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 14px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -0.5px; }
.stat-value small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }

.qgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qitem {
    background: #fff; border-radius: 12px; padding: 14px 4px 10px;
    text-align: center; color: var(--text); display: block;
}
.qitem:active { background: #f7f8fa; }
.qicon {
    width: 36px; height: 36px; margin: 0 auto 7px; border-radius: 10px;
    background: var(--primary-weak); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
}
.qicon svg { width: 20px; height: 20px; }
.qtext { font-size: 12px; }

/* 列表 */
.list-item {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px;
}
.list-item:last-child { border-bottom: 0; }
.item-main { min-width: 0; flex: 1; }
.item-title { font-size: 15px; font-weight: 600; line-height: 1.4; word-break: break-all; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.6; }
.item-side { text-align: right; flex-shrink: 0; }
.item-amount { font-size: 15px; font-weight: 600; }

.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; line-height: 18px; background: #f0f2f5; color: var(--muted);
}
.badge.blue { background: #eaf2ff; color: var(--primary); }
.badge.green { background: #e8f7ee; color: var(--green); }
.badge.orange { background: #fff5e6; color: var(--orange); }
.badge.red { background: #fdecec; color: var(--danger); }
.badge.gray { background: #f0f2f5; color: var(--muted); }

/* 搜索 */
.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input {
    flex: 1; height: 40px; border: 0; border-radius: 20px; padding: 0 16px;
    background: #fff; font-size: 14px; outline: none;
}
.searchbar button {
    height: 40px; padding: 0 18px; border: 0; border-radius: 20px;
    background: var(--primary); color: #fff; font-size: 14px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex-shrink: 0; padding: 6px 13px; border-radius: 16px; background: #fff;
    color: #5c6370; font-size: 13px; border: 1px solid transparent;
}
.chip.active { background: var(--primary); color: #fff; }

/* 按钮 */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 44px; padding: 0 18px; border-radius: 10px; border: 0;
    background: var(--primary); color: #fff; font-size: 15px; font-weight: 500;
    cursor: pointer;
}
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn.ghost {
    background: #fff; color: var(--text); border: 1px solid #e3e6eb;
}
.btn.danger { background: #fdecec; color: var(--danger); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }

.fab {
    position: fixed; z-index: 30;
    right: max(16px, calc(50% - 324px));
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 54px; height: 54px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 26px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(22, 119, 255, .4);
    text-decoration: none;
}
.fab:active { transform: scale(.96); }

/* 表单 */
.form-card { background: #fff; border-radius: var(--radius); padding: 16px 14px 6px; }
.form-group { margin-bottom: 14px; }
.form-group > label {
    display: block; font-size: 13px; color: #5c6370; margin-bottom: 6px;
}
.required::after { content: " *"; color: var(--danger); }
.form-control, .form-group input[type=text], .form-group input[type=number],
.form-group input[type=password], .form-group input[type=tel], .form-group input[type=date],
.form-group select, .form-group textarea {
    width: 100%; height: 44px; border: 1px solid #e3e6eb; border-radius: 10px;
    padding: 0 12px; font-size: 15px; background: #fafbfc; color: var(--text);
    outline: none; appearance: none;
}
.form-group textarea { height: 88px; padding: 10px 12px; line-height: 1.6; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--primary); background: #fff;
}
.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a919f' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 32px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-tip { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }
.input-with-btn .btn { flex-shrink: 0; height: 44px; }
.form-actions {
    position: sticky; bottom: 0; background: var(--bg);
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin-top: 4px;
}
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-item {
    display: flex; align-items: center; gap: 8px; padding: 9px 10px;
    border: 1px solid #e3e6eb; border-radius: 9px; background: #fafbfc; font-size: 14px;
}
.check-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.check-item.checked { border-color: var(--primary); background: var(--primary-weak); }

/* 分页 */
.pager { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 4px; }
.pager span { font-size: 12px; color: var(--muted); }
.pager button {
    height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid #e3e6eb;
    background: #fff; color: var(--text); font-size: 13px;
}
.pager button:disabled { opacity: .4; }

/* 底部导航 */
.tabbar {
    position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
    bottom: 0; width: 100%; max-width: 680px; background: #fff;
    border-top: 1px solid var(--line);
    display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tab {
    flex: 1; height: 56px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); font-size: 11px;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--primary); }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 32px 26px; }
.login-logo {
    width: 62px; height: 62px; border-radius: 18px; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 700; margin: 0 auto 16px;
    box-shadow: 0 10px 24px rgba(22, 119, 255, .3);
}
.login-title { text-align: center; font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 26px; }
.login-form { background: #fff; border-radius: 16px; padding: 20px 16px 16px; }
.login-tip { text-align: center; color: #b0b6c0; font-size: 12px; margin-top: 22px; line-height: 1.7; }

/* 空状态 */
.empty { text-align: center; color: var(--muted); padding: 46px 0; font-size: 14px; }
.empty svg { width: 42px; height: 42px; color: #d3d8e0; display: block; margin: 0 auto 10px; }

/* 提示 */
.toast {
    position: fixed; left: 50%; top: 64px; transform: translateX(-50%);
    background: rgba(20, 22, 26, .88); color: #fff; font-size: 14px;
    padding: 10px 18px; border-radius: 8px; z-index: 999; max-width: 80%;
    opacity: 0; pointer-events: none; transition: opacity .18s;
    text-align: center; line-height: 1.5;
}
.toast.show { opacity: 1; }

/* 扫码 */
.scan-overlay {
    position: fixed; inset: 0; background: #000; z-index: 1000;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.scan-overlay video { width: 100%; max-height: 70vh; object-fit: cover; }
.scan-frame {
    position: absolute; width: 70%; max-width: 300px; height: 120px;
    border: 2px solid #fff; border-radius: 10px; box-shadow: 0 0 0 2000px rgba(0,0,0,.45);
}
.scan-hint { position: absolute; bottom: 90px; color: #fff; font-size: 14px; }
.scan-cancel { position: absolute; bottom: 32px; }

/* 详情标签 */
.kv { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 500; text-align: right; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.row-actions a, .row-actions button {
    font-size: 12px; padding: 5px 10px; border-radius: 7px; border: 1px solid #e3e6eb;
    background: #fff; color: var(--text);
}
.row-actions .del { color: var(--danger); border-color: #f7d4d5; background: #fff8f8; }

/* 单据明细 */
.doc-line {
    border: 1px solid var(--line); border-radius: 10px; padding: 10px;
    margin-bottom: 9px; background: #fafbfc;
}
.doc-line .line-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; font-size: 13px; font-weight: 600; color: #5c6370;
}
.doc-line .line-head .remove { border: 0; background: none; color: var(--danger); font-size: 12px; padding: 2px 4px; }
.doc-line .line-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.doc-line .line-fields label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.doc-line input, .doc-line select {
    width: 100%; height: 38px; border: 1px solid #e3e6eb; border-radius: 8px;
    padding: 0 9px; font-size: 14px; background: #fff; color: var(--text); outline: none;
}
.doc-line input[readonly] { background: #f2f3f5; color: var(--muted); }
.doc-line .line-full { grid-column: 1 / -1; }
.doc-line .serial-block { margin-top: 8px; }
.doc-line .serial-block label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.doc-line .serial-block textarea {
    width: 100%; height: 76px; border: 1px solid #e3e6eb; border-radius: 8px;
    padding: 8px 9px; font-size: 14px; background: #fff; color: var(--text);
    outline: none; line-height: 1.5; resize: vertical;
}
.doc-line .serial-chips { margin-top: 6px; }
.doc-line .line-product { font-size: 14px; font-weight: 600; }
.doc-line .line-product small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.doc-total { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; font-size: 15px; font-weight: 600; }
.doc-total .money { color: var(--danger); font-size: 19px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .mini-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.mini-table th { color: var(--muted); font-weight: 400; font-size: 12px; }
.mini-table td.num, .mini-table th.num { text-align: right; }
.mini-table tr:last-child td { border-bottom: 0; }
.doc-actions { display: flex; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; }
.doc-actions .btn { flex: 1; min-width: 96px; }
.notice-box {
    background: #fff8e6; color: #8a6100; border-radius: 10px; padding: 10px 12px;
    font-size: 12px; line-height: 1.6; margin-bottom: 10px;
}
