:root {
  --primary: #2f5d50;
  --primary-dark: #24493f;
  --accent: #b8860b;
  --bg: #f4f1ea;
  --card: #ffffff;
  --line: #e3ddd0;
  --text: #2b2b2b;
  --muted: #8a8578;
  --danger: #c0392b;
  --ok: #27865f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #2f5d50, #3f7a68); }
.login-card { background: var(--card); padding: 40px 36px; border-radius: 14px; width: 340px; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 24px; color: var(--primary); text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.login-card .hint { margin-top: 16px; text-align: center; color: var(--muted); font-size: 12px; }

/* 布局 */
.layout { display: flex; min-height: 100vh; align-items: flex-start; }
.sidebar {
  width: 210px;
  flex: 0 0 210px;
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;   /* 页面下滑时左侧导航不动 */
  top: 42px;               /* 让开顶部云端状态条 */
  height: calc(100vh - 42px);
  overflow-y: auto;
}
.brand { padding: 22px 18px; font-size: 17px; font-weight: bold; border-bottom: 1px solid rgba(255,255,255,.12); }
nav { flex: 1; padding: 12px 0; }
nav button { display: block; width: 100%; text-align: left; padding: 13px 20px; background: none; border: none; color: #dfe9e5; font-size: 14px; cursor: pointer; }
nav button.active, nav button:hover { background: rgba(255,255,255,.12); color: #fff; border-left: 3px solid var(--accent); }
.sidebar-foot { padding: 16px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar-foot span { display: block; margin-bottom: 10px; }
.content { flex: 1; padding: 24px; min-width: 0; }

/* 通用组件 */
.btn { padding: 9px 16px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-size: 14px; background: #eee; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.card { background: var(--card); border-radius: 12px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.card h2 { font-size: 16px; margin-bottom: 16px; color: var(--primary); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
input, select { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: normal; font-size: 13px; }
tr:hover td { background: #faf8f3; }
.muted { color: var(--muted); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.tag.ok { background: #e6f4ee; color: var(--ok); }
.tag.off { background: #fbeae8; color: var(--danger); }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: 12px; padding: 18px; }
.stat .num { font-size: 24px; font-weight: bold; color: var(--primary); margin-top: 6px; }
.stat .label { color: var(--muted); font-size: 13px; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 520px; max-width: 92vw; max-height: 86vh; overflow: auto; padding: 24px; }
.modal h3 { margin-bottom: 18px; color: var(--primary); }
.modal .field { margin-bottom: 14px; }
.modal .field label { display: block; margin-bottom: 6px; color: var(--muted); }
.modal .field input, .modal .field select { width: 100%; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* toast */
.toast { position: fixed; top: 30px; left: 50%; transform: translateX(-50%); background: var(--primary-dark); color: #fff; padding: 12px 22px; border-radius: 10px; z-index: 100; }
.toast.err { background: var(--danger); }

.search-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.search-bar input { flex: 1; max-width: 320px; }
.badge-balance { color: var(--accent); font-weight: bold; }

/* ===== 云端连接状态条 ===== */
.cloud-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: 9px 18px; font-size: 13px; }
.cloud-bar.ok { background: #1f7a55; color: #fff; }
.cloud-bar.bad { background: #b3352b; color: #fff; }
.cloud-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: #b6f7d6; box-shadow: 0 0 0 2px rgba(255,255,255,.3); }
.cloud-bar.bad .dot { background: #ffd7d2; animation: pulse 1.4s infinite; }
.cloud-bar .sep { opacity: .6; }
.cloud-bar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.55); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.login-wrap { min-height: calc(100vh - 42px); }
.layout { min-height: calc(100vh - 42px); }

/* ===== 统计卡片强调 ===== */
.stat.hl { border: 1px solid #d9ceb4; background: linear-gradient(180deg,#fffdf6,#fff); }
.stat.hl .num { color: var(--accent); font-size: 28px; }
.stat .sub { font-size: 12px; margin-top: 4px; }

/* ===== 月度柱状 ===== */
.bars { display: flex; gap: 16px; align-items: flex-end; padding: 10px 4px 0; }
.bar-item { flex: 1; text-align: center; }
.bar-wrap { height: 150px; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 44px; background: linear-gradient(180deg,#4c8f78,#2f5d50); border-radius: 6px 6px 0 0; }
.bar-val { font-size: 12px; color: var(--primary); margin-top: 6px; }
.bar-label { font-size: 12px; color: var(--muted); }

/* ===== 扣卡页 ===== */
.cs-result { min-height: 42px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.member-chip { padding: 8px 14px; border: 1px solid var(--line); border-radius: 20px; background: #fff; cursor: pointer; font-size: 13px; }
.member-chip:hover { border-color: var(--primary); color: var(--primary); }
.card-pick { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.pick-item { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; text-align: left; font-size: 13px; }
.pick-item.on { border-color: var(--primary); background: #eef5f2; box-shadow: 0 0 0 2px rgba(47,93,80,.12); }
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline label { color: var(--muted); font-size: 13px; }
.field-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
/* ===== 侧边栏图标导航 ===== */
nav button { display: flex; align-items: center; gap: 12px; }
.nav-icon { width: 24px; text-align: center; font-size: 17px; opacity: .92; }
.sidebar-foot { font-size: 12px; }

/* ===== 工作台 ===== */
.wb-top { display: grid; grid-template-columns: 1fr 280px; gap: 16px; margin-bottom: 16px; }
.wb-hero { background: var(--card); border-radius: 12px; padding: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.wb-greet { color: var(--muted); margin-bottom: 14px; font-size: 13px; }
.wb-search-row { display: flex; gap: 10px; }
.wb-search { flex: 1; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line); border-radius: 8px; }
.wb-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,93,80,.12); }
.wb-result { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; min-height: 4px; }
.wb-today { background: var(--primary-dark); color: #fff; border-radius: 12px; padding: 18px 20px; }
.wb-today-title { font-size: 13px; opacity: .75; margin-bottom: 12px; }
.wb-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,.12); }
.wb-line:last-child { border-bottom: none; }
.wb-line b { font-size: 15px; color: #f2dfae; }

.member-chip { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 22px; background: #fff; cursor: pointer; font-size: 13px; }
.member-chip:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(47,93,80,.12); }
.member-chip em { font-style: normal; color: var(--primary); font-weight: bold; }

/* ===== KPI ===== */
.wb-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--card); border-radius: 12px; padding: 16px 18px; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.kpi.hl { border: 1px solid #d9ceb4; background: linear-gradient(180deg, #fffdf6, #fff); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-num { font-size: 24px; font-weight: bold; color: var(--primary); margin-top: 8px; }
.kpi-num small { font-size: 13px; font-weight: normal; color: var(--muted); }
.kpi.hl .kpi-num { color: var(--accent); font-size: 27px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ===== 提醒卡 ===== */
.wb-alerts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.alert-card { background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.alert-head { padding: 13px 16px; border-bottom: 1px solid var(--line); }
.alert-head h3 { font-size: 14px; color: var(--primary); }
.alert-head span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.alert-body { max-height: 300px; overflow: auto; }
.alert-row { padding: 10px 16px; border-bottom: 1px solid #f2eee5; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.alert-row:hover { background: #faf8f3; }
.tag.warn { background: #fdf3e0; color: #a9700d; }
.tag.level { background: #eef5f2; color: var(--primary); }

/* ===== 常驻会员信息条 ===== */
.member-bar { display: flex; align-items: center; gap: 26px; background: var(--card); border-radius: 12px; padding: 16px 20px; margin-top: 16px; border: 1px solid var(--line); flex-wrap: wrap; }
.mb-id { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.mb-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.mb-name { font-size: 16px; font-weight: bold; }
.mb-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.mb-stats { display: flex; gap: 28px; flex: 1; }
.mb-stat span { display: block; color: var(--muted); font-size: 12px; }
.mb-stat b { font-size: 18px; color: var(--primary); display: block; margin-top: 4px; }
.mb-stat b.accent { color: var(--accent); }
.mb-actions { display: flex; gap: 8px; }

/* ===== 充值档位 / 步进器 ===== */
.preset-row { display: flex; gap: 10px; flex-wrap: wrap; }
.preset { flex: 1; min-width: 120px; padding: 12px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 13px; }
.preset:hover { border-color: var(--primary); color: var(--primary); }
.preset.on { border-color: var(--primary); background: #eef5f2; color: var(--primary); font-weight: bold; }
.pay-hint { color: var(--ok); font-size: 13px; margin-top: -4px; }
.big-num { font-size: 22px; font-weight: bold; color: var(--accent); }
.stepper { display: flex; align-items: center; }
.stepper button { width: 34px; height: 34px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 16px; }
.stepper button:first-child { border-radius: 8px 0 0 8px; }
.stepper button:last-child { border-radius: 0 8px 8px 0; }
.stepper input { width: 64px; text-align: center; border-left: none; border-right: none; border-radius: 0; height: 34px; }
.consume-form { display: flex; align-items: flex-end; gap: 18px; margin-top: 18px; flex-wrap: wrap; }
.cf-item label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.btn.big { padding: 12px 26px; font-size: 15px; }
.detail-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.detail-kpis div { background: #faf8f3; border-radius: 10px; padding: 14px; }
.detail-kpis span { color: var(--muted); font-size: 12px; display: block; }
.detail-kpis b { font-size: 20px; color: var(--primary); display: block; margin: 4px 0; }
.detail-kpis em { font-style: normal; color: var(--muted); font-size: 12px; }
tr.clickable { cursor: pointer; }
.modal.wide { width: 760px; }
.bar-right { margin-left: auto; opacity: .8; }
/* ===== 门店 LOGO ===== */
.login-logo { text-align: center; margin-bottom: 12px; }
.login-logo img { width: 100px; height: 100px; object-fit: contain; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.brand-text b { display: block; font-size: 15px; line-height: 1.2; }
.brand-text span { display: block; font-size: 11px; opacity: .72; letter-spacing: 1px; margin-top: 2px; }
/* 侧边栏底部按钮 */
.foot-btns { display: flex; gap: 8px; }
.foot-btns .btn { flex: 1; min-width: 82px; padding: 7px 8px; font-size: 12px; }
/* ---- 0.5.0 补充样式 ---- */
.cs-balance {
  margin: 8px 0 12px;
  padding: 9px 12px;
  font-size: 13px;
  color: #444;
  background: #f6f7f9;
  border: 1px solid #e8eaee;
  border-radius: 8px;
}
.cs-balance b { color: #1c7d55; font-size: 15px; }
.btn.small.danger { color: #c0392b; border-color: #e9bcb7; background: #fff; }
.btn.small.danger:hover { background: #fdeceb; border-color: #d9534f; }
td.ops { white-space: nowrap; }
td.ops .btn + .btn { margin-left: 6px; }
/* ---- 0.6.0：右下角版权 + 计费依据三段式 ---- */
.app-footer {
  position: fixed;
  right: 16px;
  bottom: 7px;
  font-size: 12px;
  color: #a8b0ba;
  letter-spacing: 0.4px;
  pointer-events: none;
  z-index: 60;
  user-select: none;
}
.content { padding-bottom: 34px; }

.bill-tabs { display: flex; gap: 8px; margin: 10px 0 14px; }
.bill-tabs .bill-tab {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid #dcdfe6;
  background: #fff;
  border-radius: 10px;
  font-size: 14px;
  color: #555;
  cursor: pointer;
  transition: all .15s;
  line-height: 1.35;
}
.bill-tabs .bill-tab:hover { border-color: #b9d6c8; }
.bill-tabs .bill-tab.on {
  border-color: #1c7d55;
  background: #effaf4;
  color: #1c7d55;
  font-weight: 600;
  box-shadow: 0 0 0 1px #1c7d55 inset;
}
.bill-tabs .t-sub { display: block; font-size: 11px; color: #98a2b3; margin-top: 2px; font-weight: 400; }
.bill-tabs .bill-tab.on .t-sub { color: #3c9b74; }
/* ---- 0.6.1：扣卡页底部一行（次数左、金额与按钮右） ---- */
#csItemRow { margin-top: 14px; }
.cs-custom { margin-top: 14px; }
.cs-custom label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.cs-custom input { max-width: 200px; }
.consume-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.consume-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
}
.amt-box { display: flex; align-items: baseline; gap: 8px; }
.amt-box span { font-size: 12px; color: var(--muted); }
body:has(#loginView:not(.hidden)) .app-footer { color: rgba(255,255,255,.72); }

/* ===== 会员价 / 原价口径 ===== */
.price-mode { display: inline-flex; gap: 6px; }
.price-mode button {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 12px; color: #556;
}
.price-mode button.on { border-color: var(--primary); background: #eef5f2; color: var(--primary); font-weight: bold; }
.price-mode button:disabled { color: #aab; cursor: not-allowed; background: #f6f7f6; }
.pick-item .price-line s { color: #9aa5a1; margin-right: 5px; }
.pick-item .price-line em { color: var(--ok); font-style: normal; font-weight: bold; }
/* ===== 服务项目卡片：等宽网格、每行每列对齐（0.6.5） ===== */
#csItemPick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  align-items: stretch;
  margin-top: 8px;
}
#csItemPick .pick-item {
  width: 100%;
  min-height: 96px;
  padding: 12px 14px;
  justify-content: space-between;
  align-items: flex-start;
}
#csItemPick .pick-item b { line-height: 1.35; }
#csItemPick .pick-item .price-line { white-space: nowrap; }
.hint-line { font-size: 12px; color: var(--muted); margin: 6px 0 8px; }
/* ===== 手机版布局（@media 820px 及以下：侧栏变顶部横滑导航） ===== */
@media (max-width: 820px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: contain; }

  /* 顶部状态条：固定 42px，手机上只显示“已连接”，不折行 */
  .cloud-bar { height: 42px; padding: 0 12px; font-size: 12px; white-space: nowrap; overflow: hidden; gap: 6px; }
  .cloud-bar .bar-where, .cloud-bar .bar-right { display: none; }
  .cloud-bar .btn.small { padding: 5px 9px; font-size: 12px; flex: 0 0 auto; }

  /* 主容器竖排；侧栏变成吸顶的横向滑条 */
  /* align-items: stretch 很关键：不然竖向排列时内容宽度会按内容撑开，把页面撑宽 */
  .layout { flex-direction: column; align-items: stretch; min-height: calc(100vh - 42px); }
  .sidebar {
    position: sticky;
    top: 42px;
    z-index: 20;
    width: 100%;
    flex: none;
    height: auto;
    overflow: visible;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    box-shadow: 0 3px 10px rgba(0,0,0,.14);
  }
  .brand { display: none; }
  nav { flex: 1; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  nav::-webkit-scrollbar { display: none; }
  nav button { flex: 0 0 auto; width: auto; white-space: nowrap; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
  nav button.active, nav button:hover { border-left: none; background: rgba(255,255,255,.2); }
  .nav-icon { width: auto; font-size: 15px; }
  .sidebar-foot { flex: 0 0 auto; padding: 0; border: none; display: flex; align-items: center; }
  .sidebar-foot span { display: none; }
  .foot-btns { gap: 6px; }
  .foot-btns .btn { flex: none; min-width: 0; padding: 7px 9px; font-size: 12px; }

  /* 内容区 */
  .content { padding: 12px; padding-bottom: 44px; min-width: 0; }
  .card { padding: 14px; margin-bottom: 14px; overflow-x: auto; }
  .card h2 { font-size: 15px; margin-bottom: 12px; }
  .card table { min-width: 560px; }
  table { font-size: 12.5px; }
  table th, table td { padding: 7px 8px; }
  .stats { gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 13px; }
  .stat .num { font-size: 20px; }
  .wb-top { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .wb-hero, .wb-today, .kpi { min-width: 0; }
  .wb-search { min-width: 0; }
  .wb-search-row { min-width: 0; }
  .bars { gap: 8px; }
  .search-bar { flex-wrap: wrap; }
  .search-bar input { max-width: none; }
  .row { gap: 8px; }

  /* 扣卡页三个页签 */
  .bill-tabs { gap: 6px; }
  .bill-tab { padding: 7px 6px; font-size: 12.5px; }
  #csItemPick { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  #csItemPick .pick-item { min-height: 86px; padding: 10px 12px; font-size: 12.5px; }
  .price-mode { flex-wrap: wrap; }
  .price-mode button { padding: 6px 9px; font-size: 12.5px; }
  .cs-result { gap: 8px; }

  /* 弹窗 */
  .modal { width: 94vw; max-width: 94vw; padding: 16px 16px 18px; max-height: 88vh; border-radius: 12px; }
  .modal.wide { width: 94vw; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; min-width: 110px; }

  /* 登录页 */
  .login-wrap { min-height: calc(100vh - 42px); padding: 16px; }
  .login-card { width: 100%; max-width: 360px; padding: 28px 22px; }

  /* 版权 */
  .app-footer { position: static; padding: 14px 0 20px; text-align: center; font-size: 12px; }
  body:has(#loginView:not(.hidden)) .app-footer { position: fixed; left: 0; right: 0; bottom: 10px; padding: 0; }

  .toast { left: 12px; right: 12px; top: 56px; transform: none; text-align: center; padding: 11px 16px; font-size: 13px; }

  /* iOS 输入框小于 16px 会自动放大页面，这里统一 16px */
  input, select, textarea { font-size: 16px !important; }
}

/* ===== 平板（821 ~ 1100px）：保留侧栏但收窄 ===== */
@media (min-width: 821px) and (max-width: 1100px) {
  .sidebar { flex: 0 0 178px; width: 178px; }
  nav button { padding: 12px 14px; font-size: 13px; }
  .content { padding: 16px; }
  .wb-top { grid-template-columns: 1fr; }
}
