:root {
  --bg: #f2f5f7;
  --panel: #ffffff;
  --line: #e4e9ee;
  --line2: #eef2f5;
  --text: #16202b;
  --muted: #6d7b8a;
  --soft: #93a1af;
  --primary: #0e8a7d;
  --primary-d: #0b6e63;
  --primary-bg: #e6f6f3;
  --accent: #e8760c;
  --accent-bg: #fdf1e5;
  --blue: #2563eb;
  --blue-bg: #eaf0ff;
  --danger: #d92d4b;
  --danger-bg: #fdecef;
  --warn: #b7791f;
  --warn-bg: #fdf6e3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .04), 0 10px 30px -22px rgba(16, 32, 48, .35);
}

* { box-sizing: border-box; }
/* iOS Safari：禁止自动放大字号（否则小屏会显得"没适配"） */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* iOS 上只要有元素宽于屏幕，Safari 会把整页缩小显示（安卓只横滚），
     这里兜住横向溢出，避免整页被缩成桌面版 */
  overflow-x: clip;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button { font-family: inherit; font-size: 14px; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
a { color: var(--primary-d); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cfd8e0; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
[hidden] { display: none !important; }

/* ---------------- 登录 ---------------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #eef5f4 0%, #f2f5f7 45%, #e9eef5 100%); }
.login-card { width: 100%; max-width: 390px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow); }
.brand-big { display: flex; gap: 13px; align-items: center; margin-bottom: 22px; }
.brand-big h1 { font-size: 19px; }
.brand-big .muted { margin: 3px 0 0; font-size: 12px; }
.logo { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; color: #fff; background: linear-gradient(135deg, #12a596, #0b6e63); box-shadow: 0 8px 18px -10px rgba(14, 138, 125, .9); flex: none; }
.login-card label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.login-card input { width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid #d3dbe3; border-radius: 10px; background: #fbfcfd; }
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 138, 125, .12); background: #fff; }
.tip { font-size: 11.5px; color: var(--soft); margin: 14px 0 0; text-align: center; }
.muted { color: var(--muted); }

/* ---------------- 布局 ---------------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar { width: 228px; flex: 0 0 228px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 11px; align-items: center; padding: 4px 8px 18px; }
.brand-name { font-size: 16px; font-weight: 750; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 9px; border: 0; background: transparent; color: #41505f; text-align: left; font-size: 13.5px; width: 100%; }
.nav-item .ic { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: #f4f7f9; color: var(--text); }
.nav-item.on { background: var(--primary-bg); color: var(--primary-d); font-weight: 650; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.side-foot { border-top: 1px solid var(--line2); padding-top: 12px; margin-top: 10px; }
.who { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding-left: 2px; word-break: break-all; }
.main { flex: 1; min-width: 0; padding: 20px 26px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 19px; font-weight: 720; }
.top-actions { display: flex; gap: 8px; }
.view { display: flex; flex-direction: column; gap: 16px; }

/* ---------------- 卡片 ---------------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; }
.card-head .badge-soft { font-size: 11.5px; color: var(--muted); background: #f4f7f9; border-radius: 20px; padding: 3px 9px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------- 统计卡 ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .lab { font-size: 12px; color: var(--muted); }
.stat .val { font-size: 22px; font-weight: 720; margin-top: 4px; letter-spacing: -.02em; }
.stat .sub { font-size: 11.5px; color: var(--soft); margin-top: 2px; }
.stat.accent .val { color: var(--primary-d); }
.stat.warn .val { color: var(--accent); }
.stat.danger .val { color: var(--danger); }

/* ---------------- 表单 ---------------- */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
label { display: block; font-size: 12.5px; color: var(--muted); }
label input, label select, label textarea { width: 100%; margin-top: 5px; }
input, select, textarea { padding: 8px 10px; border: 1px solid #d3dbe3; border-radius: 8px; background: #fbfcfd; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 138, 125, .1); background: #fff; }
input[readonly], input:disabled, select:disabled { background: #f2f5f7; color: var(--muted); }
textarea { min-height: 72px; resize: vertical; }
.btn { border: 1px solid #d3dbe3; background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; }
.btn:hover { border-color: #bcc7d2; background: #fafcfd; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ok { background: #1f9d64; border-color: #1f9d64; color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link-btn { border: 0; background: none; color: var(--primary-d); padding: 0 4px; font-size: 12.5px; }
.link-btn.danger { color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); background: #f7fafc; border: 1px dashed #dbe3ea; border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
.hint.warn { background: var(--warn-bg); border-color: #f0dfb4; color: #8a6415; }

/* 分段选择 */
.seg { display: inline-flex; background: #f1f5f7; border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 4px; flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; padding: 7px 15px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.seg-btn.on { background: #fff; color: var(--primary-d); font-weight: 650; box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line2); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line2); white-space: nowrap; }
th { background: #f8fafb; color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdfd; }
td.num, th.num { text-align: right; }
td .sub { color: var(--soft); font-size: 11.5px; }
.empty { text-align: center; color: var(--soft); padding: 22px 0; }
.line-table input, .line-table select { margin: 0; padding: 6px 8px; }
.line-table td { padding: 5px 6px; }
.line-table .del { border: 0; background: var(--danger-bg); color: var(--danger); border-radius: 6px; padding: 5px 9px; }
.sub-title { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: #41505f; margin: 16px 0 8px; }

/* ---------------- 汇总 ---------------- */
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; background: #f8fafb; border: 1px solid var(--line2); border-radius: 10px; padding: 12px; margin: 14px 0; }
.totals > div { display: flex; flex-direction: column; gap: 2px; }
.totals span { font-size: 11.5px; color: var(--muted); }
.totals b { font-size: 16px; }
.totals .hl b { color: var(--accent); }

/* ---------------- 徽标 / 状态 ---------------- */
.pill { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: #f1f5f7; color: var(--muted); }
.pill.green { background: #e7f6ee; color: #1c7a45; }
.pill.orange { background: var(--accent-bg); color: #a85a08; }
.pill.blue { background: var(--blue-bg); color: #1d4ed8; }
.pill.red { background: var(--danger-bg); color: #b42323; }
.pill.gray { background: #f1f5f7; color: var(--muted); }

/* ---------------- 筛选条 ---------------- */
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.filterbar label { display: flex; align-items: center; gap: 6px; margin: 0; }
.filterbar input, .filterbar select { margin: 0; width: auto; }

/* ---------------- 图表 ---------------- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 6px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bar-val { font-size: 10.5px; color: var(--soft); height: 14px; white-space: nowrap; }
.bar-track { width: 100%; max-width: 42px; flex: 1; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; background: linear-gradient(180deg, #2bb3a4, #0e8a7d); border-radius: 6px 6px 3px 3px; min-height: 2px; }
.bar-lab { font-size: 10.5px; color: var(--muted); }

/* ---------------- 弹窗 / 提示 ---------------- */
.modal { position: fixed; inset: 0; background: rgba(16, 32, 48, .42); display: grid; place-items: center; padding: 20px; z-index: 60; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 720px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line2); }
.modal-head h3 { font-size: 15.5px; }
.modal-head .x { border: 0; background: none; font-size: 22px; color: var(--soft); line-height: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line2); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #16202b; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: .22s; z-index: 90; max-width: 88vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b42323; }
.toast.ok { background: #147a5a; }
.loading { padding: 40px; text-align: center; color: var(--soft); }
.empty-box { padding: 40px; text-align: center; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------------- 身份标识（总店 / 分店） ---------------- */
.identity { display: flex; align-items: center; gap: 10px; margin: 0 4px 14px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #f7fafb; }
.identity .id-badge { flex: none; font-size: 12px; font-weight: 700; color: #fff; padding: 5px 11px; border-radius: 8px; letter-spacing: .06em; }
.identity .id-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.identity .id-text b { font-size: 13.5px; font-weight: 680; }
.identity .id-shop { font-size: 11.5px; color: var(--muted); }
.identity .id-text em { font-style: normal; font-size: 11px; color: var(--soft); }
.identity.hq { background: var(--primary-bg); border-color: #c3e6e0; }
.identity.hq .id-badge { background: var(--primary); box-shadow: 0 6px 14px -8px rgba(14, 138, 125, .9); }
.identity.store { background: var(--accent-bg); border-color: #f4dcbe; }
.identity.store .id-badge { background: var(--accent); box-shadow: 0 6px 14px -8px rgba(232, 118, 12, .9); }

.id-chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 650; padding: 5px 11px; border-radius: 20px; white-space: nowrap; }
.id-chip.hq { background: var(--primary-bg); color: var(--primary-d); }
.id-chip.store { background: var(--accent-bg); color: #a85a08; }

/* 分店端整体用橙色系，和总店区分开 */
body.role-store .logo { background: linear-gradient(135deg, #f7a53b, #e8760c); box-shadow: 0 8px 18px -10px rgba(232, 118, 12, .95); }
body.role-store .nav-item.on { background: var(--accent-bg); color: #a85a08; }
body.role-store .nav-item.on .ic { opacity: 1; }
body.role-hq .nav-item.on { background: var(--primary-bg); color: var(--primary-d); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 2px 4px 8px; }
  .identity { margin: 0 0 10px; }
  .nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; overflow: visible; }
  .nav-item { width: auto; white-space: nowrap; padding: 8px 4px; justify-content: center; font-size: 12.5px; gap: 4px; }
  .nav-item .ic { width: auto; font-size: 12px; }
  .nav-badge { margin-left: 2px; }
  .side-foot { display: flex; align-items: center; gap: 10px; border: 0; padding-top: 8px; margin-top: 8px; }
  .who { margin: 0; flex: 1; }
  .side-foot .btn { width: auto; margin: 0; }
  .main {
    padding: 12px 12px 60px;
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
  }
  .topbar {
    position: sticky; top: 0; z-index: 30;
    margin: 0 -12px 12px; padding: 9px 12px;
    padding-top: calc(9px + env(safe-area-inset-top));
    background: #f2f5f7;
    border-bottom: 1px solid var(--line);
  }
  .page-title { font-size: 17px; }
  .top-actions { gap: 6px; }
}

@media (max-width: 640px) {
  body { font-size: 13.5px; }
  .login-wrap { padding: 16px; }
  .login-card { padding: 22px 18px; border-radius: 16px; }
  .card { padding: 13px; border-radius: 10px; }
  .card-head { margin-bottom: 10px; gap: 8px; }
  .card-head h3 { font-size: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 11px 12px; border-radius: 10px; }
  .stat .val { font-size: 17px; }
  .stat .sub { font-size: 11px; }
  .filterbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .filterbar label { display: block; }
  .filterbar input, .filterbar select { width: 100%; }
  .form-row { grid-template-columns: 1fr; gap: 9px; }
  .totals { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  table { font-size: 12px; }
  th, td { padding: 8px 7px; white-space: normal; }
  th { white-space: nowrap; }
  td .sub { font-size: 11px; }

  /* 数据表格 → 卡片式，一屏看全不用横滑 */
  .table-wrap.dt { border: 0; border-radius: 0; overflow: visible; }
  .table-wrap.dt table, .table-wrap.dt tbody, .table-wrap.dt tr, .table-wrap.dt td { display: block; width: 100%; }
  .table-wrap.dt thead { display: none; }
  .table-wrap.dt tr { border: 1px solid var(--line2); border-radius: 10px; margin-bottom: 9px; padding: 3px 12px; background: #fff; }
  .table-wrap.dt tr:last-child { margin-bottom: 0; }
  .table-wrap.dt td { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border: 0; font-size: 12.5px; }
  .table-wrap.dt td + td { border-top: 1px dashed var(--line2); }
  .table-wrap.dt td::before { content: attr(data-th); flex: none; width: 64px; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.55; }
  .table-wrap.dt td.num { text-align: left; }
  .table-wrap.dt td.empty { display: block; text-align: center; color: var(--soft); padding: 16px 0; }
  .table-wrap.dt td.empty::before { display: none; }
  .table-wrap.dt tr:hover td { background: transparent; }

  /* 弹窗里的明细编辑表保持横向滚动 */
  .line-table th, .line-table td { white-space: nowrap; }
  .line-table td { padding: 4px 3px; }
  .line-table input, .line-table select { padding: 6px 5px; }

  /* 销售开单的行编辑表 → 每条一张卡片，手机上不用横向拖动 */
  .table-wrap.sale-lines { border: 0; border-radius: 0; overflow: visible; }
  .sale-lines table, .sale-lines tbody, .sale-lines tr, .sale-lines td { display: block; width: 100%; }
  .sale-lines thead { display: none; }
  .sale-lines tr { border: 1px solid var(--line2); border-radius: 10px; margin-bottom: 9px; padding: 4px 12px; background: #fff; }
  .sale-lines tr:last-child { margin-bottom: 0; }
  .sale-lines td { padding: 7px 0; border: 0; white-space: normal; text-align: left; }
  .sale-lines td + td { border-top: 1px dashed var(--line2); }
  .sale-lines td::before { content: attr(data-th); display: inline-block; width: 60px; color: var(--muted); font-size: 12px; font-weight: 600; vertical-align: middle; }
  .sale-lines td > input, .sale-lines td > select { width: calc(100% - 66px); vertical-align: middle; }
  .sale-lines td .sub { margin-left: 66px; }
  .sale-lines td:last-child { padding-top: 9px; text-align: right; }
  .sale-lines td:last-child::before { display: none; }
  .sale-lines td.empty::before { display: none; }
  .sale-lines td.empty { text-align: center; padding: 16px 0; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-height: 92vh; border-radius: 16px 16px 0 0; }
  .modal-head { padding: 13px 15px; }
  .modal-body { padding: 14px 15px; }
  .modal-foot { padding: 12px 15px; }
  .modal-foot .btn { flex: 1; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .bars { height: 120px; gap: 5px; }
  .bar-val, .bar-lab { font-size: 9.5px; }
}

/* ---------------- 拍照识价 ---------------- */
.scan-summary { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 12px; font-size: 14px; }
.scan-summary b { font-size: 16px; }
.scan-summary .scan-total { color: var(--primary-d); font-size: 19px; }
.scan-summary em { font-style: normal; font-size: 12px; color: var(--muted); }
.scan-card { margin-top: 12px; }
.scan-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; flex-wrap: wrap; }
.scan-via { font-size: 11px; background: var(--primary-bg); color: var(--primary-d); border-radius: 20px; padding: 3px 9px; }
.scan-model { font-size: 16px; font-weight: 650; margin-bottom: 8px; }
.scan-model .muted { font-size: 12px; font-weight: 400; }
.scan-price-main { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 10px; }
.scan-price-num { font-size: 30px; font-weight: 750; color: var(--primary-d); }
.scan-price-sub { font-size: 12px; color: var(--muted); }
.scan-price-none { color: #a85a08; background: var(--accent-bg); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 4px 0 8px; }
.scan-tier-table { width: 100%; border-collapse: collapse; }
.scan-tier-table td { padding: 6px 0; border-bottom: 1px dashed var(--line2); font-size: 13px; }
.scan-tier-table td:last-child { text-align: right; font-weight: 600; }
.scan-tier-table tr:last-child td { border-bottom: 0; }
.scan-cands { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.scan-cand { font-size: 12px; }
.scan-label { margin-top: 10px; font-size: 11.5px; color: var(--soft); word-break: break-all; border-top: 1px dashed var(--line2); padding-top: 8px; }
.scan-body { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 6px; }
.scan-thumb { flex: none; width: 86px; height: 86px; border-radius: 10px; overflow: hidden; background: #f0f2f5; border: 1px solid var(--line2); }
.scan-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.scan-main { flex: 1; min-width: 0; }
@media (max-width: 640px) {
  .scan-thumb { width: 68px; height: 68px; }
  .scan-price-num { font-size: 26px; }
}

