:root {
  --bg: #eef2f8;
  --card: #ffffff;
  --ink: #1e2a3a;
  --muted: #76829a;
  --line: #e4e9f2;
  --brand: #2f6bff;
  --brand-d: #1f54e0;
  --brand-soft: #eaf1ff;
  --brand-ink: #ffffff;
  --ok: #18a058;
  --warn: #e8830c;
  --err: #e5484d;
  --shadow: 0 2px 10px rgba(31, 55, 95, .08);
  --shadow-lg: 0 8px 28px rgba(31, 55, 95, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  padding: 13px 18px; background: linear-gradient(120deg, var(--brand) 0%, #4f7dff 100%); color: var(--brand-ink);
  position: sticky; top: 0; z-index: 10; box-shadow: 0 2px 12px rgba(31, 55, 95, .18);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .5px; }
.store-pick { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.store-pick select { font-size: 14px; padding: 5px 8px; border-radius: 6px; border: none; color: var(--ink); }

.tabs {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 54px; z-index: 9;
}
.tabs button {
  flex: 1 1 auto; min-width: 60px; padding: 9px 6px; border: none; background: transparent; color: var(--muted);
  font-size: 14px; border-radius: 999px; cursor: pointer; font-weight: 600; transition: .15s;
}
.tabs button:hover { background: var(--brand-soft); color: var(--brand-d); }
.tabs button.active { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(47, 107, 255, .35); }

main { padding: 16px; max-width: 980px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 0 12px; gap: 10px; }
.sec-head h2 { font-size: 16px; margin: 0; color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); }

.card {
  background: var(--card); border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
  display: grid; gap: 13px; border: 1px solid var(--line);
}
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card > .hint { grid-column: 1 / -1; padding: 8px 10px; background: var(--brand-soft); border-radius: 8px; color: var(--brand-d); font-weight: 600; }
.card input, .card select {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; background: #fff; color: var(--ink);
  transition: .15s; outline: none;
}
.card input:focus, .card select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.card button {
  padding: 12px; border: none; border-radius: 9px; background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer; transition: .15s;
}
.card button:hover { background: var(--brand-d); }
.card button:active { transform: translateY(1px); }

/* 报表时间筛选条 */
.rep-filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.rep-filter label { flex: 0 0 auto; }
.rep-filter .rep-quick { display: flex; gap: 6px; }
.rep-filter .mini-btn {
  padding: 10px 12px; font-size: 13px; font-weight: 600;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; cursor: pointer;
}
.rep-filter .mini-btn:hover { border-color: var(--brand); color: var(--brand-d); background: var(--brand-soft); }
.rep-filter button[type="submit"] {
  padding: 10px 20px; font-size: 14px; font-weight: 700; border-radius: 9px;
  background: var(--brand); color: #fff; border: none; cursor: pointer;
}
.rep-filter button[type="submit"]:hover { background: var(--brand-d); }
#repRangeHint { margin-left: auto; align-self: center; }
#repMonth, #inbStoreDate { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; color: var(--ink); }
@media (max-width: 640px) {
  .rep-filter { flex-direction: column; align-items: stretch; }
  .rep-filter .rep-quick { flex-wrap: wrap; }
  #repRangeHint { margin-left: 0; }
}

.table-wrap { overflow-x: auto; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #f7f9fd; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7f9fd; }
tr.warn td { color: var(--warn); font-weight: 600; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #e6f6ee; color: var(--ok); }
.badge.warn { background: #fdf0e2; color: var(--warn); }
.badge.pending { background: #fff3e0; color: #c77700; }
.badge.confirmed { background: #e6f6ee; color: var(--ok); }
.badge.cancelled { background: #eef1f6; color: var(--muted); }

.mini-btn { padding: 6px 12px; border: 1px solid var(--line); background: #fff; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--ink); transition: .15s; }
.mini-btn:hover { border-color: var(--brand); color: var(--brand-d); }
.mini-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.mini-btn.primary:hover { background: var(--brand-d); color: #fff; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: rgba(30, 42, 58, .94); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: rgba(229, 72, 77, .96); }

@media (min-width: 600px) {
  .card { grid-template-columns: 1fr 1fr; }
  .card button { grid-column: 1 / -1; }
}

.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-left: auto; }
.user-box { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.store-fixed { font-size: 13px; background: rgba(255, 255, 255, .2); padding: 5px 10px; border-radius: 6px; }

.login-overlay {
  position: fixed; inset: 0; background: rgba(30, 42, 58, .5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.login-card {
  background: var(--card); width: 100%; max-width: 340px; border-radius: 16px; padding: 26px;
  box-shadow: var(--shadow-lg); display: grid; gap: 14px; border: 1px solid var(--line);
}
.login-card h1 { font-size: 20px; margin: 0; text-align: center; color: var(--brand-d); }
.login-sub { font-size: 13px; color: var(--muted); text-align: center; margin: -6px 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; background: #fff; color: var(--ink); outline: none; transition: .15s; }
.login-card input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-card button {
  padding: 12px; border: none; border-radius: 9px; background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer; transition: .15s;
}
.login-card button:hover { background: var(--brand-d); }
.login-err { color: var(--err); font-size: 13px; text-align: center; min-height: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 6px 2px 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.legend-item i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.bars { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px 16px; margin-bottom: 6px; }
.bar-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: 13px; }
.bar-label { width: 100px; flex: none; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: #eef1f6; border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 6px; }
.bar-val { width: 100px; flex: none; text-align: right; color: var(--muted); }

/* 报表关联跳转 */
.jump { color: var(--brand-d); cursor: pointer; border-bottom: 1px dashed rgba(47, 107, 255, .45); }
.jump:hover { color: var(--brand); background: rgba(47, 107, 255, .07); }
.bar-row.clickable, .legend-item.clickable { cursor: pointer; }
.bar-row.clickable:hover, .legend-item.clickable:hover { background: rgba(47, 107, 255, .06); border-radius: 8px; }

/* 启用/关闭开关 */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: relative; width: 40px; height: 22px; border-radius: 999px; background: #cdd5e2; transition: background .18s ease; flex: none; }
.switch .slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .18s ease; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: .55; }
.switch .switch-txt { font-size: 13px; color: var(--muted); white-space: nowrap; }
.switch input:checked ~ .switch-txt { color: var(--ok); font-weight: 600; }

/* ---------- 明细弹窗 ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 32, 50, .45);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
  z-index: 120; padding: 16px;
}
.modal-card {
  background: var(--card); width: 100%; max-width: 900px; max-height: 86vh;
  border-radius: 14px; border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fbfcfe;
}
.modal-titles h3 { margin: 0 0 4px; font-size: 16px; color: var(--ink); }
.modal-titles .hint { margin: 0; }
.modal-x {
  border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted);
  cursor: pointer; padding: 0 6px; border-radius: 6px; flex: none;
}
.modal-x:hover { background: var(--brand-soft); color: var(--brand); }
.modal-body { overflow: auto; flex: 1; }
.modal-body .table-wrap { border: none; border-radius: 0; }
.modal-body table th { position: sticky; top: 0; z-index: 1; }
.modal-body .modal-block-title {
  padding: 10px 16px; background: var(--brand-soft); color: var(--brand-d);
  font-size: 13px; font-weight: 600; border-top: 1px solid var(--line);
}
.modal-body .modal-block-title:first-child { border-top: none; }
.modal-foot {
  padding: 10px 16px; border-top: 1px solid var(--line); background: #fbfcfe;
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
}
@media (max-width: 640px) {
  .modal-card { max-height: 92vh; border-radius: 12px; }
  .modal-head { padding: 12px; }
  .modal-body { font-size: 13px; }
}

/* ---------- 表格工具（打印/导出） ---------- */
.tbl-tools { display: inline-flex; gap: 6px; margin-left: auto; flex: none; }
.tbl-tools .mini-btn { padding: 4px 10px; font-size: 12px; }
.mini-btn.danger { background: var(--err); color: #fff; border-color: var(--err); }
.mini-btn.danger:hover { background: #c93b40; color: #fff; border-color: #c93b40; }
.mini-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 数据维护页 ---------- */
.data-card { grid-template-columns: auto auto 1fr; align-items: center; }
.data-card > .hint { margin: 0; }
@media (max-width: 640px) {
  .data-card { grid-template-columns: 1fr; }
  .tbl-tools { width: 100%; justify-content: flex-end; }
}
.modal-card.modal-sm { max-width: 460px; }
.modal-body .confirm-msg { padding: 16px; font-size: 14px; line-height: 1.75; color: var(--ink); }
.modal-body .confirm-msg ul { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; }
.modal-body .confirm-msg b { color: var(--err); }

/* ---------- 打印 ---------- */
.print-area { display: none; }
@media print {
  body { background: #fff !important; }
  body.printing > *:not(.print-area) { display: none !important; }
  body.printing .print-area { display: block !important; }
  .print-area { padding: 0; color: #000; }
  .print-area h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
  .print-area .print-meta { font-size: 12px; color: #444; text-align: center; margin: 0 0 14px; }
  .print-area table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .print-area th, .print-area td { border: 1px solid #999; padding: 5px 7px; text-align: left; color: #000 !important; }
  .print-area thead th { background: #f0f0f0 !important; }
  .print-area tfoot td { font-weight: 700; background: #f8f8f8 !important; }
  .print-area .badge { border: 1px solid #999; background: #fff !important; color: #000 !important; padding: 1px 6px; }
  .print-area .jump { color: #000 !important; border-bottom: none !important; }
  @page { margin: 12mm; }
}

/* ==================== 移动端布局优化（仅屏幕，不影响打印） ==================== */
@media screen and (max-width: 640px) {
  /* ---- 顶栏：不再吸顶（省高度），标题 + 门店行紧凑两行 ---- */
  .topbar {
    position: static; display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; column-gap: 10px; row-gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }
  .topbar h1 {
    grid-column: 1; grid-row: 1; font-size: 15px; letter-spacing: .3px;
    min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-right { grid-column: 1 / -1; grid-row: 2; margin-left: 0; flex-wrap: nowrap; justify-content: flex-start; }
  .store-pick { flex: 1 1 auto; min-width: 0; font-size: 12px; white-space: nowrap; gap: 8px; }
  .store-pick select { flex: 1 1 auto; min-width: 0; font-size: 15px; padding: 7px 8px; }
  .store-fixed { font-size: 12px; padding: 5px 10px; }
  .user-box { grid-column: 2; grid-row: 1; justify-self: end; font-size: 12px; min-width: 0; }
  #userName { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-box .mini-btn { padding: 6px 10px; }

  /* ---- 菜单：单行横向滑动 + 吸顶 ---- */
  .tabs-wrap {
    position: sticky; top: 0; z-index: 9; background: var(--card); overflow: hidden;
    box-shadow: 0 2px 8px rgba(31, 55, 95, .06);
  }
  .tabs-wrap::after {
    content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 30px;
    background: linear-gradient(to right, rgba(255, 255, 255, 0), var(--card));
    pointer-events: none; opacity: 0; transition: opacity .18s;
  }
  .tabs-wrap.scrollable::after { opacity: 1; }
  .tabs-wrap.at-end::after { opacity: 0; }
  .tabs {
    position: static; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    padding: 8px 10px; gap: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    background: transparent; box-shadow: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: 0 0 auto; min-width: 0; min-height: 36px; padding: 0 15px; font-size: 13px; white-space: nowrap;
    display: inline-flex; align-items: center; justify-content: center;
  }

  main { padding: 12px 12px calc(18px + env(safe-area-inset-bottom)); }

  /* ---- 区块标题：标题独占一行，说明 / 控件 / 工具在下一行 ---- */
  .sec-head {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    column-gap: 10px; row-gap: 6px; margin: 4px 0 10px;
  }
  .sec-head h2 { grid-column: 1 / -1; font-size: 15px; }
  .sec-head .hint { grid-column: 1; min-width: 0; line-height: 1.55; }
  .sec-head label.hint { display: inline-flex; align-items: center; gap: 6px; }
  .sec-head .tbl-tools { grid-column: 2; grid-row: 2; justify-self: end; margin-left: 0; }
  #repScope { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; background: #fff; color: var(--ink); }
  #repMonth, #inbStoreDate { font-size: 15px; }
  .tab > h2, .tab > div > h2 { font-size: 15px; margin: 4px 0 8px; }
  .tab > .hint { font-size: 12px; line-height: 1.6; margin: 0 0 10px; }

  /* ---- 表单 ---- */
  .card { padding: 14px; gap: 11px; border-radius: 12px; }
  .card input, .card select, .login-card input { font-size: 16px; padding: 11px 12px; }
  .card button, .login-card button { font-size: 16px; padding: 13px; }
  .card label { font-size: 12px; }
  .form-actions { gap: 8px; }
  .form-actions button { flex: 1 1 100%; }
  .form-actions .mini-btn { padding: 11px 14px; font-size: 14px; }

  /* 报表筛选：日期两列 + 快捷按钮一行五等分 */
  .card.rep-filter { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: stretch; }
  .rep-filter .rep-quick { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: 6px; }
  .rep-filter .rep-quick .mini-btn { padding: 9px 2px; font-size: 12px; text-align: center; white-space: nowrap; }
  .card input, .card select { min-width: 0; }
  .rep-filter button[type="submit"] { grid-column: 1 / -1; padding: 12px; }
  #repRangeHint { grid-column: 1 / -1; margin: 0; }

  /* ---- 条形图 ---- */
  .bars { padding: 10px 12px; border-radius: 12px; }
  .bar-row { gap: 8px; margin: 8px 0; font-size: 12px; }
  .bar-label { width: 62px; }
  .bar-val { width: 74px; font-size: 11px; }
  .legend { gap: 6px 12px; max-height: 92px; overflow-y: auto; }
  .legend-item { font-size: 12px; }
  .bars { max-height: 340px; overflow-y: auto; }

  /* ---- 表格 → 卡片（每行一张卡，左侧列名右侧值） ---- */
  .table-wrap { overflow: visible; background: transparent; border: none; box-shadow: none; border-radius: 0; }
  table { display: block; min-width: 0; font-size: 13px; }
  thead { display: none; }
  tbody, tfoot { display: block; }
  tbody tr, tfoot tr {
    display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden;
  }
  tbody tr:hover { background: var(--card); }
  tbody td, tfoot td {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    padding: 8px 12px; border-bottom: 1px dashed var(--line); white-space: normal;
    text-align: right; color: var(--ink); font-size: 13px;
  }
  tbody tr td:last-child, tfoot tr td:last-child { border-bottom: none; }
  tbody td::before, tfoot td::before {
    content: attr(data-label); flex: none; color: var(--muted);
    font-size: 12px; font-weight: 600; text-align: left;
  }
  tbody td:first-child {
    background: #f7f9fd; border-bottom: 1px solid var(--line);
    font-weight: 700; font-size: 14px; padding: 10px 12px;
  }
  tbody td[colspan] { justify-content: center; color: var(--muted); }
  tbody td[colspan]::before { display: none; }
  tbody td:empty, tfoot td:empty { display: none; }
  tfoot tr td:first-child { justify-content: flex-start; font-weight: 700; color: var(--brand-d); }
  tfoot tr td:first-child::before { display: none; }
  tfoot tr { border-color: rgba(47, 107, 255, .35); background: #f7f9fd; }
  tfoot td { font-weight: 700; }
  tr.warn { border-color: rgba(232, 131, 12, .55); }
  tr.warn td { color: var(--warn); font-weight: 600; }
  tbody td .switch { margin-left: auto; }
  tbody td .mini-btn { padding: 7px 12px; font-size: 13px; }

  /* ---- 表格工具按钮 ---- */
  .tbl-tools { gap: 8px; }
  .tbl-tools .mini-btn { padding: 8px 14px; font-size: 13px; }

  /* ---- 弹窗：底部抽屉 ---- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-card, .modal-card.modal-sm {
    max-width: 100%; width: 100%; max-height: 92dvh;
    border-radius: 16px 16px 0 0; border-bottom: none;
  }
  .modal-head { padding: 12px 14px; }
  .modal-titles h3 { font-size: 15px; }
  .modal-body { font-size: 13px; }
  .modal-body > .table-wrap { margin: 10px 12px; }
  .modal-body .modal-block-title { padding: 9px 14px; }
  .modal-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .modal-foot .mini-btn { flex: 1 1 0; padding: 11px; font-size: 15px; }
  .modal-body .confirm-msg { padding: 14px; font-size: 13px; }
  .modal-body .confirm-msg ul { font-size: 12px; }

  /* ---- 数据页 ---- */
  .data-card { grid-template-columns: 1fr; }
  .data-card .mini-btn { width: 100%; padding: 12px; font-size: 15px; }

  /* ---- 登录 ---- */
  .login-overlay { padding: 16px; }
  .login-card { padding: 22px 18px; border-radius: 14px; max-width: 360px; }
  .login-card h1 { font-size: 18px; }

  .toast { bottom: calc(24px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); font-size: 13px; padding: 10px 14px; }
}

/* 超窄屏（iPhone SE 一代等 320px 设备）：日期改单列，避免输入框撑破卡片 */
@media screen and (max-width: 360px) {
  .card.rep-filter { grid-template-columns: 1fr; }
  .sec-head { grid-template-columns: minmax(0, 1fr) auto; }
  .sec-head select { max-width: 100%; }
  .topbar h1 { font-size: 14px; }
  #userName { max-width: 30vw; }
}
