/* 进销存系统样式 v2 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #4f46e5; --primary-dark: #4338ca; --primary-light: #eef2ff;
    --bg: #f3f4f6; --card: #fff; --line: #e5e7eb; --text: #1f2937; --muted: #6b7280;
    --ok: #16a34a; --warn: #ea580c; --danger: #dc2626; --sidebar-w: 210px;
}
body { font-family: -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

/* ---------------- 顶栏 ---------------- */
.topbar {
    height: 52px; background: var(--primary); color: #fff; display: flex; align-items: center;
    padding: 0 16px; position: fixed; top: 0; left: 0; right: 0; z-index: 60; gap: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.topbar .brand { font-size: 17px; font-weight: 600; }
.topbar .top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar .logout { color: #fff; text-decoration: none; background: rgba(255,255,255,.18); padding: 5px 12px; border-radius: 6px; }
.hamburger { display: none; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }

/* ---------------- 侧栏 ---------------- */
.sidebar {
    position: fixed; top: 52px; bottom: 0; left: 0; width: var(--sidebar-w);
    background: #fff; border-right: 1px solid var(--line); overflow-y: auto; z-index: 50;
    padding: 8px 0;
}
.sidebar nav { display: flex; flex-direction: column; }
.sidebar a {
    display: block; padding: 10px 18px; color: var(--text); text-decoration: none; font-size: 15px;
    border-left: 3px solid transparent;
}
.sidebar a:hover { background: #f9fafb; }
.sidebar a.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.sidebar .group-title {
    padding: 10px 18px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none;
    display: flex; justify-content: space-between;
}
.sidebar .group-title::after { content: '▾'; font-size: 11px; transition: transform .2s; }
.sidebar .group:not(.open) .group-title::after { transform: rotate(-90deg); }
.sidebar .group-body { display: none; }
.sidebar .group.open .group-body { display: block; }
.sidebar .group-body a { padding-left: 34px; font-size: 14px; }

.content { margin-left: var(--sidebar-w); margin-top: 52px; padding: 18px; max-width: 1400px; }
.overlay { display: none; }

/* ---------------- 容器 / 标题 ---------------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
h2 { font-size: 20px; color: var(--text); }
h3 { margin: 22px 0 12px; font-size: 16px; color: var(--text); }

/* ---------------- 卡片 ---------------- */
.card { background: var(--card); border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.07); margin-bottom: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); padding: 16px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.stat-card.alert { border-left: 4px solid var(--danger); }
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-sub { color: #9ca3af; font-size: 12px; margin-top: 4px; }

/* ---------------- 表格 ---------------- */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.07); margin-bottom: 16px; }
th { background: #f8fafc; color: var(--muted); padding: 10px 12px; text-align: left; font-size: 13px; font-weight: 600; white-space: nowrap; }
td { padding: 10px 12px; border-top: 1px solid var(--line); font-size: 14px; }
tr:hover td { background: #fafafa; }
.low-stock td { color: var(--danger); }
.debt { color: var(--danger); font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }

/* ---------------- 表单 ---------------- */
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.form-row label { min-width: 78px; color: var(--text); font-weight: 500; }
input, select, textarea {
    padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 7px; font-size: 15px;
    font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-row input[type=text], .form-row input[type=number], .form-row select { min-width: 180px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.form-grid .fi { display: flex; flex-direction: column; gap: 5px; }
.form-grid .fi label { font-size: 13px; color: var(--muted); }
.form-grid .fi input, .form-grid .fi select { width: 100%; }

/* ---------------- 按钮 ---------------- */
button, .btn { padding: 8px 16px; border: none; border-radius: 7px; font-size: 14px; cursor: pointer; text-decoration: none; display: inline-block; background: #e5e7eb; color: var(--text); }
button:hover, .btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-default { background: #e5e7eb; color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
.btn-del { background: #fee2e2; color: var(--danger); }

/* ---------------- 其它 ---------------- */
.tag { padding: 2px 9px; border-radius: 20px; font-size: 12px; display: inline-block; }
.tag-ok { background: #dcfce7; color: var(--ok); }
.tag-warn { background: #ffedd5; color: var(--warn); }
.tag-info { background: #e0e7ff; color: var(--primary); }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.empty a { color: var(--primary); }
.actions { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 16px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; font-size: 14px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* 搜索结果 / 商品选择 */
.search-results { position: relative; }
.search-item { padding: 10px 14px; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.search-item:hover { background: var(--primary-light); border-color: var(--primary); }
.pill { background: var(--primary-light); color: var(--primary); padding: 2px 8px; border-radius: 12px; font-size: 12px; }

/* 商品缩略图 */
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #f3f4f6; border: 1px solid var(--line); }

/* 小票 */
.receipt { width: 80mm; margin: 0 auto; padding: 6mm; background: #fff; font-family: "Courier New", monospace; font-size: 12px; }
.receipt.w58 { width: 58mm; }
.receipt.w110 { width: 110mm; }
.receipt h2 { text-align: center; font-size: 15px; margin: 4px 0; }
.receipt table { width: 100%; box-shadow: none; margin: 0; }
.receipt th { background: #fff; color: #000; border-bottom: 1px dashed #999; padding: 3px; font-size: 11px; }
.receipt td { padding: 3px; border: none; font-size: 11px; }
.receipt .total { text-align: right; font-size: 14px; font-weight: bold; margin: 8px 0; }
.receipt .meta { font-size: 11px; color: #333; }
.receipt hr { border: none; border-top: 1px dashed #999; margin: 6px 0; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: 12px; max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 20px; }
.modal h3 { margin-top: 0; }

/* 图片上传 */
.img-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.img-box { width: 72px; height: 72px; border: 1px dashed #cbd5e1; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); font-size: 22px; overflow: hidden; position: relative; background: #fafafa; }
.img-box img { width: 100%; height: 100%; object-fit: cover; }
.img-box .rm { position: absolute; top: 0; right: 0; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* 打印时隐藏界面 */
@media print {
    .topbar, .sidebar, .overlay, .no-print { display: none !important; }
    .content { margin: 0; padding: 0; max-width: none; }
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 820px) {
    .hamburger { display: block; }
    .sidebar { transform: translateX(-100%); transition: transform .25s; box-shadow: 2px 0 10px rgba(0,0,0,.1); }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .overlay { display: block; position: fixed; inset: 52px 0 0 0; background: rgba(0,0,0,.3); z-index: 45; }
    .content { margin-left: 0; padding: 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid2 { grid-template-columns: 1fr; }
    table { font-size: 13px; }
    th, td { padding: 8px 7px; }
    .form-row input, .form-row select { min-width: 130px; }
}

/* ================= v3 视觉与移动端优化 ================= */
.topbar { background: linear-gradient(120deg, #4f46e5 0%, #7c3aed 100%); box-shadow: 0 2px 10px rgba(79,70,229,.28); }
.sidebar .group-title { font-weight: 600; }

.card { border: 1px solid #eef0f4; box-shadow: 0 2px 8px rgba(17,24,39,.05); border-radius: 12px; }
.stat-card { border: 1px solid #eef0f4; box-shadow: 0 2px 8px rgba(17,24,39,.05); border-radius: 12px; transition: .15s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(79,70,229,.12); }
.stat-value { letter-spacing: -.4px; }
th { background: #f7f8fc; }
tr:hover td { background: #f8f9ff; }

button, .btn { border-radius: 9px; transition: .15s; font-weight: 500; }
button:active, .btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(120deg,#4f46e5,#6d28d9); box-shadow: 0 2px 8px rgba(79,70,229,.3); }
.btn-primary:hover { box-shadow: 0 4px 14px rgba(79,70,229,.42); filter: none; }
.btn-voice { background: linear-gradient(120deg,#8b5cf6,#ec4899); color: #fff; box-shadow: 0 2px 8px rgba(139,92,246,.35); }
.btn-voice:hover { filter: brightness(1.05); }

/* 语音面板 */
.voice-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px; background: #faf9ff; border: 1px dashed #ddd6fe; border-radius: 14px; }
.mic { width: 78px; height: 78px; border-radius: 50%; font-size: 34px; background: linear-gradient(120deg,#8b5cf6,#ec4899); color: #fff; box-shadow: 0 6px 18px rgba(139,92,246,.35); }
.mic.rec { animation: micpulse 1.1s infinite; }
@keyframes micpulse { 0%{box-shadow:0 0 0 0 rgba(236,72,153,.55);} 70%{box-shadow:0 0 0 20px rgba(236,72,153,0);} 100%{box-shadow:0 0 0 0 rgba(236,72,153,0);} }
.voice-tip { font-size: 13px; color: #6b7280; text-align: center; }

/* 底部导航默认隐藏 */
.bottomnav { display: none; }

@media (max-width: 820px) {
    .content { padding: 12px 12px 84px; }
    .page-head h2 { font-size: 18px; }
    .page-head { gap: 8px; }
    .page-head > div { flex-wrap: wrap; }
    .page-head .btn, .page-head button { padding: 8px 12px; font-size: 13px; }
    .card { padding: 12px; }
    input, select, textarea { max-width: 100%; }
    .toolbar > *, .form-row > * { flex: 1 1 auto; }
    .toolbar input, .toolbar select { width: 100%; }
    .card, .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 500px; }
    table.receipt, .receipt table, table.narrow { min-width: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-row label { min-width: auto; width: 100%; font-size: 13px; }
    .form-row input, .form-row select, .form-grid .fi input, .form-grid .fi select { min-width: 0; width: 100%; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-value { font-size: 20px; }
    .modal { max-height: 92vh; padding: 16px; }
    .tbl-wrap { -webkit-overflow-scrolling: touch; }
    .bottomnav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
        background: #fff; border-top: 1px solid var(--line);
        padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 12px rgba(17,24,39,.07);
    }
    .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0; text-decoration: none; color: #9ca3af; font-size: 11px; }
    .bottomnav a i { font-size: 20px; font-style: normal; line-height: 1; }
    .bottomnav a.active { color: var(--primary); font-weight: 600; }
}

/* 小票不受移动端表格最小宽度影响 */
.receipt table { min-width: 0 !important; }

/* ===== 摄像头扫码 ===== */
.btn-cam{ background:#f59e0b; color:#fff; }
.btn-cam:hover{ background:#d97706; }
.cam-modal{ max-width:420px; }
.cam-box{ position:relative; width:100%; background:#000; border-radius:10px; overflow:hidden; aspect-ratio:4/3; }
.cam-box video{ width:100%; height:100%; object-fit:cover; display:block; }
.cam-center{ position:absolute; left:50%; top:50%; width:70%; height:45%; transform:translate(-50%,-50%); border:2px dashed rgba(255,255,255,.85); border-radius:12px; pointer-events:none; }