:root {
  --brand: #185FA5;
  --brand-weak: #E6F1FB;
  --brand-soft: #B5D4F4;
  --ok: #0F6E56;
  --ok-weak: #E1F5EE;
  --err: #A32D2D;
  --err-weak: #FCEBEB;
  --warn: #854F0B;
  --warn-weak: #FAEEDA;
  --text: #1c1c1a;
  --muted: #5F5E5A;
  --line: rgba(0, 0, 0, .10);
  --bg: #F4F4F1;
  --card: #fff;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .10);
  --font: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --drawer-w: 268px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
button { font-family: inherit; }

.btn {
  border: none; border-radius: 10px; cursor: pointer;
  padding: 9px 16px; font-size: 14px; font-weight: 500; min-height: 38px;
  background: var(--bg); color: var(--text); white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #14497f; }
.btn.ghost { background: var(--card); border: 1px solid var(--line); }
.btn.danger { background: var(--err); color: #fff; }
.btn.block { width: 100%; display: block; }
.btn.icon-btn { width: 38px; height: 38px; min-height: 38px; padding: 0; display: grid; place-items: center; }
.btn.sm { padding: 5px 12px; min-height: 32px; font-size: 13px; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: min(380px, 100%); background: var(--card); border-radius: var(--radius-lg);
  padding: 36px 32px; box-shadow: var(--shadow); text-align: center;
}
.login-logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 16px;
  background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 26px;
}
.login-card h1 { font-size: 22px; }
.login-sub { color: var(--muted); margin: 6px 0 22px; }
.login-card label { display: block; text-align: left; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; outline: none; color: var(--text);
}
.login-card input:focus { border-color: var(--brand); }
.login-err { color: var(--err); min-height: 20px; margin-bottom: 8px; font-size: 13px; }
.login-card .btn { height: 44px; font-size: 16px; margin-top: 4px; }

/* ---------- 骨架 ---------- */
.shell { height: 100%; display: grid; grid-template-columns: var(--sidebar-w) 1fr; }

.sidebar {
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px;
  min-height: 0;
}
.side-brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; margin-bottom: 24px; }
.side-logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 17px; flex: 0 0 auto;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  text-align: left; border: none; background: none; cursor: pointer;
  padding: 11px 14px; border-radius: 10px; font-size: 15px; color: var(--text);
  min-height: 44px;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--brand-weak); color: var(--brand); font-weight: 500; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 14px; }
.mode-tag {
  background: var(--warn-weak); color: var(--warn);
  text-align: center; padding: 6px; border-radius: 8px; font-size: 12px;
}
.mode-tag.live { background: var(--ok-weak); color: var(--ok); }

/* 抽屉遮罩（仅窄屏使用） */
.side-mask {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(20, 20, 18, .45);
}

.tophead .menu-btn { display: none; margin-right: 10px; font-size: 18px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tophead {
  height: 62px; flex: 0 0 auto; padding: 0 24px;
  border-bottom: 1px solid var(--line); background: var(--card);
  display: flex; align-items: center; gap: 4px;
}
.tophead h1 { font-size: 18px; margin-right: auto; }
.tophead-right { font-size: 13px; }

.view { flex: 1 1 auto; overflow-y: auto; padding: 20px 24px 40px; -webkit-overflow-scrolling: touch; }
.view[hidden] { display: none; }

/* ---------- 卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--card); border-radius: var(--radius-lg); padding: 18px 20px;
  border: 1px solid var(--line);
}
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 600; margin-top: 8px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.blue .value { color: var(--brand); }
.stat.green .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }

.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; }
.panel-body { padding: 16px 18px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 500; background: #FAFAF8; }
tbody tr:hover { background: #FAFAF8; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.pill.warn { background: var(--warn-weak); color: var(--warn); }
.pill.err { background: var(--err-weak); color: var(--err); }
.pill.muted { background: var(--bg); color: var(--muted); }

.row-actions { display: flex; gap: 6px; }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; outline: none; background: var(--card); color: var(--text);
  min-height: 38px; max-width: 100%;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--brand); }
.spacer { flex: 1 1 auto; }
#fKeyword { width: 240px; }
#oKeyword { width: 180px; }

/* ---------- 分页条 ---------- */
.pager {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px;
}
.pager select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; background: var(--card); color: var(--text); outline: none;
}
.pager .btn[disabled] { opacity: .4; cursor: not-allowed; }
@media (max-width: 640px) {
  .pager { gap: 6px; }
  .pager .btn { padding: 6px 8px; }
}

.product-thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--bg); }
.off-tag { color: var(--err); font-size: 12px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.mask { position: absolute; inset: 0; background: rgba(20, 20, 18, .45); }
.dialog {
  position: relative; z-index: 1; background: var(--card);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  width: min(640px, 100%); max-height: min(90vh, 860px); display: flex; flex-direction: column;
}
.dialog-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h3 { font-size: 16px; }
.dialog-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-row input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; outline: none; color: var(--text);
  width: 100%; min-height: 40px;
}
.form-row input[type="file"] { padding: 6px; }
.form-row input:focus { border-color: var(--brand); }
.upload-row { grid-template-columns: 110px 1fr; align-items: start; }
.pic-preview {
  width: 100px; height: 100px; border-radius: 12px; background: var(--bg);
  display: grid; place-items: center; color: var(--muted); font-size: 12px;
  background-size: cover; background-position: center;
}
.upload-ctl { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; min-width: 0; }
.upload-ctl input[type="file"] { max-width: 100%; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 16px; min-height: 40px; }
.form-err { color: var(--err); min-height: 20px; font-size: 13px; }

.order-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.order-meta div { background: var(--bg); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.order-meta span { display: block; font-size: 12px; color: var(--muted); }
.order-meta b { font-size: 16px; word-break: break-all; }

/* ---------- 在店 / 外卖 分档 ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--card); }
.seg-btn {
  border: 0; background: transparent; cursor: pointer; font: inherit; font-size: 14px;
  color: var(--muted); padding: 0 16px; min-height: 38px;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.active { background: var(--brand); color: #fff; }
.list-summary { font-size: 13px; color: var(--muted); margin: -4px 0 10px; }
.cell-sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; word-break: break-all; }

/* ---------- 外卖配送信息 ---------- */
.deliver-box {
  background: var(--warn-weak); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
}
.deliver-title { font-size: 13px; color: var(--warn); font-weight: 600; margin-bottom: 8px; }
.deliver-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; }
.deliver-row { min-width: 0; font-size: 14px; }
.deliver-row.wide { grid-column: 1 / -1; }
.deliver-row span { display: block; font-size: 12px; color: var(--muted); }
.deliver-row b { font-weight: 600; word-break: break-all; }
.lnk { margin-left: 8px; font-size: 12px; color: var(--brand); text-decoration: none; font-weight: 400; }
.fee-note { margin-top: 10px; font-size: 12px; color: var(--muted); }

/* ---------- 图表 ---------- */
.chart-tabs { display: flex; gap: 6px; }
.chart-tabs button {
  border: 1px solid var(--line); background: var(--card); cursor: pointer;
  padding: 5px 14px; border-radius: 8px; font-size: 13px; color: var(--text);
  min-height: 34px;
}
.chart-tabs button.active { background: var(--brand-weak); border-color: var(--brand); color: var(--brand); }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bar-chart { width: 100%; min-width: 460px; height: 260px; display: block; }
.bar-label { font-size: 11px; fill: var(--muted); }
.bar-value { font-size: 11px; fill: var(--text); }
.bar-rect { fill: var(--brand); }
.bar-rect:hover { fill: #14497f; }

.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.rank-no { width: 24px; height: 24px; border-radius: 7px; background: var(--brand-weak); color: var(--brand); display: grid; place-items: center; font-size: 12px; flex: 0 0 auto; }
.rank-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 20px; left: 0; right: 0; z-index: 99; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: rgba(28, 28, 26, .92); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; max-width: 90vw; text-align: center; }
.toast.good { background: var(--ok); }
.toast.bad { background: var(--err); }

/* =========================================================
   响应式：>1180 桌面宽屏 / 861~1180 桌面窄屏 / <=860 移动平板
   ========================================================= */

/* 大屏：内容限宽，避免表格被拉得过宽 */
@media (min-width: 1500px) {
  .view > .stat-grid, .view > .panel, .view > .toolbar { max-width: 1440px; margin-left: auto; margin-right: auto; }
}

/* ---------- 窄屏（<=860px）：抽屉导航 + 表格卡片化 ---------- */
@media (max-width: 860px) {
  html, body { height: auto; }
  body { min-height: 100vh; }

  .shell {
    height: 100vh;
    height: 100dvh;
    grid-template-columns: 1fr;
    overflow: hidden;
  }

  /* 侧栏变抽屉 */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
    width: var(--drawer-w); max-width: 84vw;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .18);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: none; }
  .side-nav { gap: 6px; }
  .side-foot { padding-top: 16px; }

  .tophead .menu-btn { display: grid; }

  .tophead {
    height: 56px; padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }
  .tophead h1 { font-size: 16px; }
  .tophead-right { display: none; }

  .view { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .stat { padding: 13px 14px; border-radius: var(--radius); }
  .stat .label { font-size: 12px; }
  .stat .value { font-size: 21px; margin-top: 6px; }
  .stat .sub { font-size: 11px; }

  .panel { margin-bottom: 14px; border-radius: var(--radius); }
  .panel-head { padding: 12px 14px; }
  .panel-body { padding: 12px 14px; }

  .toolbar { gap: 8px; margin-bottom: 12px; }
  .toolbar input, .toolbar select { flex: 1 1 140px; min-width: 0; font-size: 16px; }
  #fKeyword, #oKeyword { width: 100%; }
  .toolbar .btn { flex: 0 0 auto; }
  .spacer { display: none; }

  /* 表格 → 卡片列表 */
  .table-wrap { overflow-x: visible; }
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap th,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 12px 10px;
    margin: 0 0 10px;
    background: var(--card);
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap tbody tr:hover { background: var(--card); }
  .table-wrap td {
    border: none; padding: 6px 0;
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; text-align: left;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px; flex: 0 0 auto;
  }
  .table-wrap td.num { text-align: right; }
  .table-wrap td.cell-empty { justify-content: center; color: var(--muted); padding: 10px 0; }
  .table-wrap td.cell-empty::before { display: none; }
  .table-wrap td.cell-stack { flex-direction: column; align-items: flex-start; gap: 2px; }
  .table-wrap td.cell-hide-label::before { display: none; }
  .table-wrap td.cell-hide-label { justify-content: flex-start; }
  .table-wrap td[data-actions] {
    padding-top: 10px; margin-top: 6px;
    border-top: 1px dashed var(--line);
  }
  .table-wrap td[data-actions]::before { display: none; }
  .row-actions { flex-wrap: wrap; width: 100%; gap: 8px; }
  .row-actions .btn { flex: 1 1 30%; min-width: 72px; }

  /* 弹窗 → 底部抽屉 */
  .modal { place-items: end center; padding: 0; }
  .dialog {
    width: 100%; max-width: none;
    max-height: 92vh; max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .dialog-head { padding: 14px 16px; position: relative; }
  .dialog-head::before {
    content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    width: 36px; height: 4px; border-radius: 2px; background: var(--line);
  }
  .dialog-body { padding: 14px 16px; }
  .dialog-foot {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .dialog-foot .btn { flex: 1 1 0; min-height: 44px; }

  .form-row { grid-template-columns: 1fr; gap: 12px; }
  .form-row input { font-size: 16px; }
  .upload-row { grid-template-columns: 88px 1fr; }
  .pic-preview { width: 84px; height: 84px; }
  .order-meta { grid-template-columns: 1fr; gap: 8px; }
  .order-meta b { font-size: 15px; }
  .deliver-grid { grid-template-columns: 1fr; }
  .seg { width: 100%; }
  .seg-btn { flex: 1 1 0; padding: 0 8px; }

  /* 窄屏画布按 1:1 渲染（不改比例，保证坐标文字不糊），超出横向滚动 */
  .bar-chart { width: 100%; height: auto; aspect-ratio: 44 / 22; min-width: 440px; }
  .bar-label, .bar-value { font-size: 13px; }
  .chart-tabs { width: 100%; }
  .chart-tabs button { flex: 1 1 0; }
}

/* ---------- 手机（<=480px）：进一步压缩 ---------- */
@media (max-width: 480px) {
  body { font-size: 14px; }
  .login-card { padding: 28px 20px; }
  .login-card h1 { font-size: 19px; }

  .stat-grid { gap: 8px; }
  .stat .value { font-size: 19px; }
  .stat .label { font-size: 11px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select { flex: 1 1 auto; width: 100%; }
  .toolbar .btn { width: 100%; }

  .table-wrap tr { padding: 8px 10px 10px; }

  .rank-list li { gap: 8px; font-size: 13px; }
}

/* 触屏设备放大点击热区 */
@media (hover: none) and (pointer: coarse) {
  .btn.sm { min-height: 36px; padding: 7px 12px; }
  .nav-item { min-height: 46px; }
  .row-actions .btn { min-height: 38px; }
}

/* ---------- 多商户：商家管理与商户切换 ---------- */

.merchant-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.merchant-switch select {
  padding: 5px 8px;
  border: 1px solid var(--border, #d8dee9);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  max-width: 180px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.field-block {
  display: block;
  margin: 8px 0;
}

.field-block textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid var(--border, #d8dee9);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions .btn {
  padding: 4px 9px;
  font-size: 12px;
}

.pill.muted {
  background: #f1efe8;
  color: #5f5e5a;
}

@media (max-width: 640px) {
  .merchant-switch select { max-width: 120px; }
  .row-actions .btn { flex: 1 1 auto; }
}
