:root{
  --bg:#f3f5f9; --card:#ffffff;
  --primary:#3d6fe0; --primary-d:#2f5bc4; --primary-soft:#eaf0fd; --primary-line:#c9d9fb;
  --text:#2b3038; --muted:#8a93a2; --line:#ebedf1;
  --ok:#18a957; --ok-soft:#e7f7ee; --warn:#e08a00; --warn-soft:#fdf3e3; --bad:#e5484d; --bad-soft:#fdecec;
  --radius:14px; --shadow:0 2px 10px rgba(28,39,60,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
       background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.topbar { position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); }
header { background: linear-gradient(135deg, #3d6fe0, #5b86ef); color: #fff; padding: 15px 18px;
         box-shadow: 0 2px 14px rgba(61,111,224,.18); display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
header h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .5px; }
#who { font-size: 12.5px; opacity: .92; margin-top: 3px; flex: 1; min-width: 0; }
#who a { color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.55); padding-bottom: 1px; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.header-btn { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.3);
              border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; transition: background .15s; }
.header-btn:hover { background: rgba(255,255,255,.3); }
.header-btn:active { background: rgba(255,255,255,.12); }
.header-btn.active { background: rgba(255,255,255,.35); font-weight: 600; }
@media (max-width: 480px) {
  header { padding: 10px 12px; gap: 4px; }
  header h1 { font-size: 14px; }
  #who { flex: 1 1 100%; margin-top: 4px; font-size: 11px; }
  .header-actions { flex: 1 1 auto; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
  .header-btn { padding: 5px 7px; font-size: 11px; border-radius: 7px; }
}
.tabs { display: flex; background: var(--card); padding: 5px; gap: 4px; box-shadow: 0 1px 6px rgba(28,39,60,.05);
        overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs .tab-link { flex: 0 0 auto; border: none; background: none; padding: 11px 11px; font-size: 14.5px; white-space: nowrap;
               color: var(--muted); position: relative; font-weight: 500; border-radius: 10px; transition: all .18s; }
.tabs button.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.tabs .tab-link:hover { background: #f5f7fb; color: var(--primary-d); }
.wrap { padding: 16px; max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
        box-shadow: var(--shadow); border: 1px solid rgba(235,237,241,.8); }
.card h3 { margin: 0 0 14px; font-size: 16px; color: var(--text); font-weight: 600; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; letter-spacing: .2px; }
label .req { color: var(--bad); margin-left: 2px; }
select, input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]), textarea {
  width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #fcfdff; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input.big-input { font-size: 16px; padding: 12px; font-weight: 500; }
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(61,111,224,.12); background: #fff; }
select:disabled, input:disabled { background: #f3f4f6; color: #9aa3b0; border-color: #eceef1; }
input[type=checkbox] { accent-color: var(--primary); width: 16px; height: 16px; }
.remember { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted);
            margin: 4px 0 14px; font-weight: 500; cursor: pointer; }
.remember input { width: auto; padding: 0; }
textarea { resize: vertical; min-height: 46px; line-height: 1.5; }
.row2 { display: flex; gap: 12px; } .row2 > div { flex: 1; }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.pay-grid .online { grid-column: 1 / -1; background: var(--primary-soft); border: 1px solid var(--primary-line);
                    border-radius: 10px; padding: 10px 12px; }
.pay-grid .online label { color: var(--primary-d); font-weight: 600; margin: 0 0 6px; }
.calc { background: #f7f9fc; border-radius: 12px; padding: 14px; margin-top: 16px; border: 1px solid #eef1f6; }
.calc .line { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; color: #525a66; }
.calc .line b { font-size: 16px; color: var(--text); } .calc .arrears b { color: var(--bad); } .calc .online b { color: var(--primary); }
.hint { font-size: 12.5px; margin-top: 8px; line-height: 1.5; } .hint.ok { color: var(--ok); } .hint.err { color: var(--bad); }
.btn { width: 100%; background: var(--primary); color: #fff; border: none; border-radius: 12px; padding: 14px;
       font-size: 16px; font-weight: 600; margin-top: 18px; cursor: pointer; transition: background .15s, transform .05s;
       box-shadow: 0 4px 12px rgba(61,111,224,.22); }
.btn:active { background: var(--primary-d); transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--primary); border: 1px solid var(--primary); box-shadow: none; }
.btn.ghost:active { background: var(--primary-soft); }
.btn.done { background: #18a957; box-shadow: 0 4px 12px rgba(24,169,87,.22); }
.btn.done:active { background: #138a47; }
.btn.sm { width: auto; padding: 7px 14px; font-size: 13px; margin: 0; box-shadow: none; border-radius: 9px; }
.toast { position: fixed; left: 50%; top: 78px; transform: translateX(-50%) translateY(-8px);
         background: rgba(33,40,55,.92); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
         z-index: 99; opacity: 0; transition: opacity .25s, transform .25s; max-width: 90%; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 10px 7px; text-align: right; border-bottom: 1px solid #f1f3f6; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; background: #fafbfd; font-size: 12px; }
tbody tr:hover { background: #fafbfd; }
.table-scroll { overflow-x: auto; border-radius: 10px; border: 1px solid #f0f2f5; }
.table-scroll table { margin: 0; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.sec { margin: 4px 0 12px; font-size: 14.5px; font-weight: 600; color: var(--text); padding-left: 10px; border-left: 3px solid var(--primary); }
.filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 34px 0; font-size: 13.5px; }
.summary-top { display: flex; gap: 12px; margin-bottom: 16px; }
.kpi { flex: 1; background: var(--card); border-radius: 12px; padding: 14px 10px; text-align: center;
       box-shadow: var(--shadow); border: 1px solid rgba(235,237,241,.8); }
.kpi .v { font-size: 20px; font-weight: 700; color: var(--primary); letter-spacing: .3px; }
.kpi .v.red { color: var(--bad); } .kpi .v.warn { color: var(--warn); } .kpi .v.ok { color: var(--ok); }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { margin-top: 0; flex: 1; }
.btn-row .btn.ghost { flex: 0 0 36%; }
.plan-detail { margin-top: 10px; padding: 11px 13px; background: var(--ok-soft); border: 1px solid #bfe9cf;
               border-radius: 10px; font-size: 13px; color: #1d6b41; line-height: 1.6; display: none; }
.plan-detail b { color: #138a47; }
.plan-row.done { opacity: .5; }
.plan-row.done:hover { opacity: .72; }
.remind-top { display: flex; gap: 10px; margin-bottom: 16px; }
#gate { position: fixed; inset: 0; background: linear-gradient(160deg, #eef2fb, #f6f8fc); z-index: 100;
        display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
#gate .box { width: 100%; max-width: 340px; background: var(--card); border-radius: 18px; padding: 26px 22px;
             box-shadow: 0 10px 40px rgba(28,39,60,.10); }
#gate .box > div:first-child { font-size: 20px; font-weight: 700; color: var(--text); text-align: center; }
.tip { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.7; background: #f7f9fc; padding: 10px 12px; border-radius: 10px; }
#conn-status { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; text-align: left;
               padding: 10px 12px; background: #f3f5f9; border-radius: 10px; line-height: 1.6; }
#conn-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
                    background: #c8cdd5; margin-right: 6px; vertical-align: middle; }
#conn-status .dot.ok { background: #18a957; }
#conn-status .dot.bad { background: #e5484d; }
#conn-status.okbox { background: var(--ok-soft); color: #186f3b; }
#conn-status.badbox { background: var(--bad-soft); color: #9b2c2c; }
.conn-hint { display: block; font-size: 12px; margin-top: 6px; color: inherit; opacity: .9; line-height: 1.6; }
.err-box { display: none; background: var(--bad-soft); color: #9b2c2c; border: 1px solid #f5c2c2;
           border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.6; margin-top: 12px; }
.login-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 8px; }
.qr-card { border: 1px solid #e5e8ef; border-radius: 10px; padding: 10px; text-align: center; background: #fff; }
.qr-card .nm { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.qr-card .rl { font-size: 12px; color: #86909c; margin-bottom: 6px; }
.qr-card .qrbox { display: flex; justify-content: center; }
.qr-card .qrbox img, .qr-card .qrbox canvas { width: 120px !important; height: 120px !important; }
.qr-card .lk { font-size: 11px; color: #3d6fe0; word-break: break-all; margin-top: 6px; cursor: pointer; }
.qr-card .lk:hover { text-decoration: underline; }
/* ===== v2 进销存 ===== */
.inv-bar { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-bottom:14px; }
.inv-bar select, .inv-bar input { width:auto; flex:1 1 130px; padding:9px 10px; font-size:14px; }
.inv-in { width:70px !important; padding:6px 7px !important; font-size:14px !important; text-align:right; border-radius:7px !important; }
.inv-in.filled { border-color:var(--primary); background:#f4f8ff; font-weight:600; }
td.pos { color:var(--ok); } td.neg { color:var(--bad); font-weight:600; }
.num-b { font-weight:600; }
.statusbar { display:flex; justify-content:space-between; align-items:center; gap:10px;
             padding:11px 13px; border-radius:11px; font-size:13px; margin-bottom:14px; line-height:1.6; }
.statusbar.none { background:#f3f5f9; color:#5a6472; }
.statusbar.draft { background:var(--warn-soft); color:#8a5a00; }
.statusbar.submitted { background:var(--primary-soft); color:var(--primary-d); }
.statusbar.confirmed { background:var(--ok-soft); color:#186f3b; }
.formula { font-size:12px; color:var(--muted); background:#f7f9fc; border-radius:9px;
           padding:9px 11px; line-height:1.75; margin-top:10px; }
.formula b { color:var(--text); }
.mini-tabs { display:flex; gap:6px; margin-bottom:12px; }
.mini-tabs button { flex:1; border:1px solid var(--line); background:#fff; color:var(--muted);
                    padding:8px 4px; border-radius:9px; font-size:13.5px; font-weight:500; }
.mini-tabs button.on { background:var(--primary-soft); color:var(--primary-d);
                       border-color:var(--primary-line); font-weight:600; }
.fold-h { display:flex; justify-content:space-between; align-items:center; cursor:pointer; }
.fold-h .ar { color:var(--muted); font-size:13px; }
/* v2 进销存补充 */
.num { text-align:right; font-variant-numeric: tabular-nums; white-space:nowrap; }
.tot td { font-weight:700; background:#f3f5f9; border-top:2px solid var(--line); }
.ok { color:var(--ok); } .bad { color:var(--bad); } .warn { color:var(--warn); } .muted { color:var(--muted); }
.tag-pick { display:inline-block; font-size:11px; background:var(--primary-soft); color:var(--primary-d);
            padding:1px 6px; border-radius:6px; margin-left:4px; }
.iv-in.sm { width:100% !important; min-width:56px; }
.statusbar b { color:var(--text); }
.statusbar .hint-strong { font-weight:600; }
#iv-tbl th, #iv-log th, #iv-prog th, #iv-cost th { font-size:12px; white-space:nowrap; }
#iv-tbl td, #iv-log td, #iv-prog td, #iv-cost td { font-size:13px; }
/* 搜索下拉框（产品/赠品选择器） */
.search-select-wrap { position: relative; width: 100%; }
.search-select-wrap input { width: 100%; box-sizing:border-box; padding:12px; border:1px solid var(--line);
  border-radius:10px; font-size:16px; outline:none; transition:border-color .15s, box-shadow .15s; background:#fcfdff; color:var(--text); }
.search-select-wrap input:focus { border-color: var(--primary); box-shadow:0 0 0 3px rgba(61,111,224,.12); background:#fff; }
.search-select-dropdown { display:none; position:absolute; top:100%; left:0; right:0; max-height:220px;
  overflow-y:auto; background:#fff; border:1px solid var(--line); border-radius:10px; margin-top:4px;
  box-shadow:0 6px 20px rgba(28,39,60,.12); z-index:999; }
.search-select-dropdown.show { display:block; }
.search-select-dropdown div { padding:10px 12px; font-size:14px; cursor:pointer; white-space:nowrap; overflow:hidden;text-overflow:ellipsis; }
.search-select-dropdown div:hover, .search-select-dropdown div.active { background:var(--primary-soft); color:var(--primary); }
.search-select-dropdown div.empty { color:var(--muted); cursor:default; padding:10px 11px; font-size:12px; }

/* ===== v3 新增：桌面端响应式布局 ===== */
@media (min-width: 900px) {
  .wrap { max-width: 1200px; padding: 20px 24px; }
  .tabs { justify-content: center; }
  .tabs button, .tabs .tab-link { padding: 11px 18px; font-size: 15px; }
  .card { padding: 22px; }
  .summary-top { gap: 16px; }
  .kpi .v { font-size: 24px; }
  .kpi .l { font-size: 13px; }
  table { font-size: 13px; }
  th, td { padding: 11px 10px; }
  .pay-grid { grid-template-columns: repeat(3, 1fr); }
  .row2 { gap: 16px; }
  .btn { max-width: 420px; margin-left: auto; margin-right: auto; }
  .login-links { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* ===== v3 新增：看板图表区域 ===== */
.chart-card { margin-bottom: 16px; }
.chart-card .chart-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.chart-container { position: relative; height: 240px; }
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-container { height: 280px; }
}

/* ===== v3 新增：折叠区 ===== */
.fold-section { margin-top: 14px; }
.fold-section .fold-h { background: #f7f9fc; border-radius: 10px; padding: 12px 14px; }
.fold-body { padding-top: 6px; }

/* ===== v3 新增：移动端优化 ===== */
@media (max-width: 400px) {
  .row2 { flex-direction: column; gap: 0; }
  /* 手机端收款方式：一行 3 个（原来被强制成单列，导致十几行太长） */
  .pay-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .pay-grid label { font-size: 12px; margin: 0 0 4px; }
  .pay-grid input { padding: 9px 8px; font-size: 15px; }
  .kpi .v { font-size: 17px; }
  .kpi .l { font-size: 11px; }
  .summary-top { gap: 8px; }
  .tabs button, .tabs .tab-link { padding: 10px 8px; font-size: 13px; }
  header h1 { font-size: 15px; }
  #who { font-size: 11.5px; }
  .btn { font-size: 15px; padding: 13px; }
  .btn-row { gap: 8px; }
  .btn-row .btn.ghost { flex: 0 0 33%; }
  table { font-size: 11.5px; }
  th, td { padding: 8px 5px; }
  .card { padding: 14px; }
  .wrap { padding: 12px; }
}

@media (max-width: 380px) {
  .summary-top { flex-wrap: wrap; }
  .kpi { flex: 1 1 40%; }
}

/* iPhone safe area 适配 */
@supports (padding: env(safe-area-inset-bottom)) {
  .wrap { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .btn-row { margin-bottom: env(safe-area-inset-bottom); }
}

/* 手机端筛选区日期输入框不要占满宽度 */
@media (max-width: 480px) {
  .filter input[type=date] { width: auto; flex: 1 1 0; min-width: 0; padding: 6px; font-size: 13px; }
  .filter input[type=month] { width: auto !important; flex: 1 1 0; min-width: 0; padding: 6px; font-size: 13px; }
  .filter > span { flex: 0 0 auto; }
  .mr-bar input[type=month] { width: auto !important; flex: 0 0 auto; min-width: 0; padding: 6px; font-size: 13px; }
  .mr-bar .btn { flex: 1 1 auto; font-size: 13px; padding: 10px 8px; white-space: nowrap; }
}

/* 提交按钮区吸底（手机端） */
@media (max-width: 640px) {
  #view-entry .btn-row {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, #fff 60%, rgba(255,255,255,0));
    padding: 14px 0 calc(6px + env(safe-area-inset-bottom));
    margin-top: 14px;
    z-index: 5;
  }
}

/* 通知铃铛 + 红色未读角标 */
.bell-btn { position: relative; font-size: 15px; line-height: 1; padding: 7px 11px; }
.notif-badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px;
  padding: 0 4px; border-radius: 9px; background: #e5484d; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
  box-shadow: 0 0 0 2px #3d6fe0;
}

/* 通知面板 */
.notif-panel { background: #fff; border-radius: 14px; width: 100%; max-width: 560px;
  margin: 44px auto; box-shadow: 0 14px 44px rgba(20,28,45,.32); overflow: hidden; }
.notif-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); }
.notif-head h3 { margin: 0; font-size: 16px; }
.notif-head .btn.ghost.sm { width: auto; padding: 6px 12px; margin: 0; }
.notif-pub { padding: 14px 16px; }
.notif-pub label { margin: 12px 0 6px; }
.notif-pub label:first-child { margin-top: 0; }
.notif-divider { display: flex; align-items: center; color: var(--muted); font-size: 12px;
  margin: 4px 16px; }
.notif-divider::before, .notif-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.notif-divider span { padding: 0 10px; white-space: nowrap; }
.notif-list { padding: 4px 10px 14px; }
.notif-item { padding: 12px; border-radius: 10px; margin: 8px 6px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; transition: background .12s; }
.notif-item:active { background: #f5f7fb; }
.notif-item.unread { border-color: #f5c2c2; background: var(--bad-soft); }
.notif-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notif-title { font-size: 15px; font-weight: 600; color: var(--text); flex: 1; }
.notif-item.unread .notif-title { color: #c0272c; }
.unread-tag { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700;
  color: #fff; background: var(--bad); border-radius: 6px; padding: 1px 6px; vertical-align: middle; }
.notif-content { font-size: 13.5px; color: #4a515c; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.notif-meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.notif-del { width: auto; padding: 4px 10px; margin: 0; font-size: 12px; flex: 0 0 auto;
  background: #fff; color: var(--bad); border: 1px solid #f5c2c2; border-radius: 8px; }
.notif-del:active { background: var(--bad-soft); }

