/* 顾客管理系统 · 云端版样式 —— 现代浅色主题，零外链（字体/图标全部系统栈 + emoji） */

:root {
  --primary: #1f6feb;
  --primary-dark: #1558c0;
  --primary-soft: #e8f1ff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #1a2233;
  --text-dim: #5b6b85;
  --muted: #8794a8;
  --border: #e3e8f0;
  --border-strong: #cfd8e6;
  --ok: #1a7f4b;
  --ok-soft: #e6f6ee;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b26a00;
  --warn-soft: #fff5e0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 56, .04), 0 8px 24px rgba(20, 32, 56, .07);
  --shadow-sm: 0 1px 2px rgba(20, 32, 56, .06);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC",
          "Hiragino Sans GB", "Noto Sans SC", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .01em; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-dim); font-weight: 700; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1 1 160px; min-width: 120px; }

/* 金额：右对齐 + 等宽数字 */
.money, .num, td.num, .stat-value.money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-family: var(--mono);
  letter-spacing: -.01em;
}
.num, td.num, th.num { text-align: right; }

/* ---------- 顶部横幅（未配置 API 地址） ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid #f0dcb4;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 40;
}
.banner-text { flex: 1; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; line-height: 1; }
.brand-text h1 { line-height: 1.2; }
.brand-sub { margin: 0; font-size: 12px; color: var(--muted); }

.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 88px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.stat-value { font-size: 15px; font-weight: 700; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(31, 111, 235, .28); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(31, 111, 235, .22); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93326; border-color: #a93326; color: #fff; }
.icon-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-size: 16px; line-height: 1; color: var(--muted); padding: 6px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 输入 ---------- */
.input {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 235, .15); }
.input::placeholder { color: #a8b3c4; }
.select-narrow { width: auto; min-width: 104px; }
.date-input { width: auto; min-width: 140px; }

/* ---------- 主布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 18px 24px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.customers-panel { display: flex; flex-direction: column; max-height: calc(100vh - 132px); position: sticky; top: 118px; }
.panel-head { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border); }
.panel-head-row { display: flex; gap: 8px; align-items: center; }

/* ---------- 顾客列表 ---------- */
.list { overflow-y: auto; padding: 6px; flex: 1 1 auto; min-height: 120px; }
.list-loading { padding: 18px 12px; color: var(--muted); text-align: center; }
.customer-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.customer-item + .customer-item { margin-top: 2px; }
.customer-item:hover { background: var(--surface-2); }
.customer-item.active { background: var(--primary-soft); border-color: rgba(31, 111, 235, .35); }
.ci-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ci-name { font-weight: 700; font-size: 14px; }
.ci-balance { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 700; color: var(--ok); }
.ci-bottom { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.ci-code { font-family: var(--mono); letter-spacing: .02em; }

/* ---------- 顾客详情 ---------- */
.detail { border-top: 1px solid var(--border); background: var(--surface-2); padding: 12px; overflow-y: auto; flex: 0 1 auto; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.detail-meta { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.detail-balance { text-align: right; display: flex; flex-direction: column; }
.detail-balance .money { font-size: 18px; font-weight: 700; color: var(--primary-dark); }
.detail-block { margin-top: 12px; }
.detail-block h3 { margin-bottom: 6px; }
.pkg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.pkg-item {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 5px 9px; font-size: 12px;
}
.pkg-name { font-weight: 600; }
.pkg-num { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text-dim); }
.pkg-num b { color: var(--primary-dark); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.empty-small { color: var(--muted); font-size: 12px; padding: 6px 2px; }

/* ---------- 主区 tabs ---------- */
.main-panel { min-height: 320px; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab {
  appearance: none; border: 0; background: transparent; font: inherit; font-weight: 700; font-size: 13.5px;
  color: var(--text-dim); padding: 9px 16px; border-radius: 10px 10px 0 0; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--primary-dark); background: var(--surface-2); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); background: var(--primary-soft); }
.tabs-spacer { flex: 1; }
.tabs-hint { font-size: 11.5px; color: var(--muted); padding-right: 4px; }

.view { padding: 14px; }
.section-title { margin: 4px 0 8px; }
.section-title + .table-wrap { margin-bottom: 18px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }

/* ---------- 表格 ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: auto; background: var(--surface); }
.table-wrap.compact { max-height: 180px; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: 11.5px; font-weight: 700; color: var(--text-dim);
  background: var(--surface-2); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.num { text-align: right; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:nth-child(even) { background: #fbfcfe; }
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num { text-align: right; }
.table td.time { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }
.table .amount.pos { color: var(--ok); font-weight: 700; }
.table .amount.neg { color: var(--danger); font-weight: 700; }
.table .amount.zero { color: var(--muted); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap;
}
.badge.t-充值 { background: var(--ok-soft); border-color: #bfe6d1; color: var(--ok); }
.badge.t-消费 { background: #eef2ff; border-color: #cdd8f8; color: #2c3f8f; }
.badge.t-购买套餐 { background: var(--warn-soft); border-color: #edd9ad; color: var(--warn); }
.badge.t-使用套餐 { background: #f3ecff; border-color: #ddd0f7; color: #5b3fa8; }
.table-foot { margin: 8px 2px 0; font-size: 12px; }
.cell-note { color: var(--text-dim); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 空状态 / 骨架 ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 34px 16px; color: var(--muted); text-align: center; font-size: 13px;
}
.empty-icon { font-size: 30px; opacity: .7; }
.skeleton-row {
  height: 34px; margin: 6px; border-radius: 8px;
  background: linear-gradient(90deg, #eef2f8 25%, #f7f9fc 37%, #eef2f8 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 报表卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card-label { font-size: 11.5px; color: var(--muted); letter-spacing: .06em; }
.card-value { font-size: 26px; font-weight: 800; line-height: 1.15; }
.card-turnover { background: linear-gradient(160deg, #f2f7ff, #fff); border-color: #d6e5ff; }
.card-turnover .card-value { color: var(--primary-dark); }
.card-service .card-value { color: #2c3f8f; }
.card-customers .card-value { color: #5b3fa8; }
#report-date-label { margin: 0 0 10px; font-size: 12px; }

/* ---------- 底部 tab（仅移动端显示） ---------- */
.bottom-tabs { display: none; }

/* ---------- 弹窗 ---------- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(16, 24, 40, .45);
  backdrop-filter: blur(2px);
  animation: fade .14s ease;
  margin: 0; border: 0;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); box-shadow: 0 24px 60px rgba(16, 24, 40, .3);
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.modal.modal-wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; }
.modal-body { padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .field-label { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.field .input, .field select.input { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.check-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.info-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 12.5px; color: var(--text-dim); display: flex; flex-direction: column; gap: 3px;
}
.info-box .money { color: var(--text); font-weight: 700; }
.hint { font-size: 11.5px; color: var(--muted); }
.warn-text { font-size: 12px; color: var(--warn); }
.err-text { font-size: 12px; color: var(--danger); }

/* 凭证 */
.receipt {
  margin: 0; padding: 14px; border-radius: var(--radius-sm);
  background: #fbfcfe; border: 1px dashed var(--border-strong);
  font-family: var(--mono); font-size: 12px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-height: 52vh; overflow: auto;
}

/* ---------- toast ---------- */
.toast-root { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast {
  pointer-events: auto;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: #fff; background: #2b3448; box-shadow: 0 10px 30px rgba(16, 24, 40, .28);
  animation: toast-in .18s ease; max-width: 100%;
}
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }
.toast.info { background: #2b3448; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 响应式：<900px 上下堆叠 + 底部 tab ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 12px 82px; }
  .topbar { position: static; padding: 12px; gap: 10px; }
  .customers-panel { position: static; max-height: none; }
  .list { max-height: 42vh; }
  .detail { max-height: none; }
  .actions { margin-left: 0; width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .stats { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .stat { flex: 0 0 auto; }
  .cards { grid-template-columns: 1fr; }
  .card-value { font-size: 22px; }
  .tabs { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .modal { max-width: none; max-height: calc(100vh - 24px); }
  .modal-backdrop { padding: 10px; align-items: flex-end; }
  .bottom-tabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: rgba(255, 255, 255, .96); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 14px rgba(20, 32, 56, .07);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .btab {
    flex: 1; appearance: none; border: 0; background: transparent; font: inherit; font-size: 11px;
    color: var(--muted); padding: 6px 2px; border-radius: 10px; cursor: pointer; font-weight: 700;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  .btab-icon { font-size: 18px; line-height: 1; }
  .btab.active { color: var(--primary-dark); background: var(--primary-soft); }
  .toast-root { bottom: 78px; }
  .table th, .table td { padding: 7px 8px; }
  .cell-note { max-width: 150px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --surface: #171d28;
    --surface-2: #1d2431;
    --text: #e6ecf6;
    --text-dim: #aab6c8;
    --muted: #8895aa;
    --border: #28313f;
    --border-strong: #3a4658;
    --primary-soft: #17273f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --ok: #4ade80; --ok-soft: #16301f;
    --danger-soft: #3a1c18; --warn-soft: #35290f;
  }
  .table tbody tr:nth-child(even) { background: #1a2130; }
  .table tbody tr:hover { background: #1f2b40; }
  .btn { background: var(--surface-2); }
  .btn-primary { background: var(--primary); }
  .bottom-tabs { background: rgba(23, 29, 40, .96); }
  .receipt { background: #121722; }
  .modal-backdrop { background: rgba(0, 0, 0, .6); }
  .card-turnover { background: linear-gradient(160deg, #16233a, var(--surface)); border-color: #24406b; }
}
