:root {
  --bg: #f2f5f6;
  --panel: #ffffff;
  --ink: #14232b;
  --ink-2: #3d525c;
  --muted: #78889a;
  --line: #e2e9ec;
  --brand: #0e7c72;
  --brand-deep: #0b4f52;
  --brand-soft: #e6f3f1;
  --warn: #c2410c;
  --ok: #0f7a4d;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 45, 55, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* 登录页 */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(14, 124, 114, 0.16), transparent 55%),
    radial-gradient(circle at 85% 80%, rgba(11, 79, 82, 0.14), transparent 50%),
    #f2f5f6;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 32px 30px 26px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--brand), var(--brand-deep));
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
  flex: 0 0 auto;
}

.brand h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: 0.5px; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); }

.login-card form { margin-top: 26px; display: grid; gap: 16px; }

label { display: grid; gap: 8px; font-size: 13px; color: var(--ink-2); }

input, select {
  height: 42px;
  padding: 0 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 124, 114, 0.12);
}

.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(140deg, var(--brand), var(--brand-deep)); color: #fff; }
.btn-primary:hover { opacity: 0.94; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; height: 46px; font-size: 15px; letter-spacing: 2px; }
.btn-danger { color: var(--warn); border-color: rgba(194, 65, 12, 0.3); background: rgba(194, 65, 12, 0.06); }

.login-tip { margin: 2px 0 0; min-height: 18px; font-size: 12.5px; color: var(--warn); }

/* 主界面 */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 26px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand.compact .brand-mark { width: 38px; height: 38px; font-size: 18px; border-radius: 11px; }
.brand.compact h1 { font-size: 16px; margin: 0; }
.brand.compact p { font-size: 11.5px; }

.tabs { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.tab {
  height: 36px;
  padding: 0 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.tab:hover { background: var(--brand-soft); color: var(--brand-deep); }

.tab.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 6px 16px rgba(14, 124, 114, 0.24);
}

.panel { padding: 24px 26px 60px; display: none; }
.panel.active { display: block; }

/* 指标卡 */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(15, 45, 55, 0.04);
}

.card .label { font-size: 12.5px; color: var(--muted); letter-spacing: 0.3px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -0.5px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.card.accent { background: linear-gradient(150deg, var(--brand), var(--brand-deep)); border-color: transparent; }
.card.accent .label, .card.accent .sub { color: rgba(255, 255, 255, 0.78); }
.card.accent .value { color: #fff; }

/* 区块 */
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: 0 4px 14px rgba(15, 45, 55, 0.04);
}

.box-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.box-head h2 { font-size: 15px; margin: 0; }
.hint { font-size: 12px; color: var(--muted); }

#trendChart { width: 100%; height: 220px; display: block; }

.bars { display: grid; gap: 9px; }

.bar-row { display: grid; grid-template-columns: 62px 1fr 58px; align-items: center; gap: 10px; }
.bar-name { font-size: 13px; color: var(--ink-2); }
.bar-track { height: 12px; background: #eef2f4; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.bar-value { font-size: 12.5px; color: var(--muted); text-align: right; }

.plan-sales { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.plan-sale {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: #fbfcfc;
}
.plan-sale .name { font-size: 13.5px; font-weight: 600; }
.plan-sale .num { font-size: 20px; font-weight: 700; color: var(--brand-deep); margin-top: 6px; }
.plan-sale .desc { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 工具条与表格 */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { width: 260px; }
.toolbar select { width: 160px; }
.toolbar input.wide-input { width: 340px; }

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(15, 45, 55, 0.04);
}

table { width: 100%; border-collapse: collapse; min-width: 760px; }

thead th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: #f7fafb;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid #f1f5f6; color: var(--ink-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fbfdfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 18px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.guest { background: #f1f3f5; color: #6b7a90; border-color: #e2e9ec; }
.badge.registered { background: #eef4ff; color: #2b5fa8; border-color: #dbe7fb; }
.badge.paid { background: #fff3e0; color: #b35309; border-color: #f6dcc0; }
.badge.ok { background: #e7f6ee; color: var(--ok); border-color: #cfeadd; }
.badge.warn { background: #fdf0e8; color: var(--warn); border-color: #f6d8c6; }
.badge.muted { background: #f1f3f5; color: var(--muted); border-color: #e2e9ec; }
.badge.level { background: #f7fafb; border-color: var(--line); color: var(--ink); }
.badge.app { background: #eef6f4; color: #0e7c72; border-color: #cfe5e1; }

.pager { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.pager .page-text { font-size: 12.5px; color: var(--muted); margin-right: 6px; }

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 33, 38, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 40;
}

.modal-card {
  background: #fff;
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(9, 30, 36, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; margin: 0; }

.modal-body { padding: 20px 22px 26px; overflow: auto; }

.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 22px; margin-bottom: 18px; }
.detail-item { display: grid; gap: 4px; }
.detail-item .k { font-size: 12px; color: var(--muted); }
.detail-item .v { font-size: 14px; color: var(--ink); }

.sub-title { font-size: 13.5px; font-weight: 600; margin: 20px 0 10px; color: var(--ink); }

.adjust-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.adjust-row input { width: 130px; height: 36px; }
.adjust-row input.wide { width: 200px; }

.mini-table table { min-width: 0; }
.mini-table thead th { padding: 9px 10px; }
.mini-table tbody td { padding: 9px 10px; font-size: 12.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: rgba(16, 45, 52, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 60;
  box-shadow: 0 12px 30px rgba(9, 30, 36, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }


/* ============================================================
   移动端适配（手机浏览器 / PWA）
   目标：单手持机也能完成 查会员 → 看详情 → 调贡献值 / 确认订单
   策略：桌面布局不动，≤720px 切换为「卡片化表格 + 滚动标签栏」
   ============================================================ */

html, body { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }

@media (max-width: 720px) {
  /* ---------- 顶栏：品牌一行 + 可横滑的标签栏 ---------- */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px 0;
    align-items: center;
  }
  .brand.compact { flex: 1 1 auto; min-width: 0; }
  .brand.compact .brand-mark { width: 32px; height: 32px; font-size: 16px; border-radius: 9px; }
  .brand.compact h1 {
    font-size: 14px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand.compact p { display: none; }

  #logoutBtn {
    flex: 0 0 auto;
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
  }

  .tabs {
    order: 3;
    flex: 0 0 100%;
    margin: 2px -12px 0;
    padding: 6px 12px 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    height: 38px;
    padding: 0 15px;
    font-size: 13.5px;
  }

  /* ---------- 内容区 ---------- */
  .panel { padding: 14px 12px calc(72px + env(safe-area-inset-bottom)); }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
  }
  .card { padding: 14px 14px 12px; border-radius: 12px; }
  .card .label { font-size: 11.5px; line-height: 1.4; }
  .card .value { font-size: 21px; margin-top: 6px; }
  .card .sub { font-size: 11px; margin-top: 5px; }

  .grid-2 { gap: 12px; margin-bottom: 12px; }
  .box { padding: 14px 14px 16px; border-radius: 12px; }
  .box-head { flex-wrap: wrap; gap: 4px 8px; margin-bottom: 10px; }
  .box-head h2 { font-size: 14px; }
  .hint { font-size: 11.5px; }
  #trendChart { height: 200px; }

  .plan-sales { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .plan-sale { padding: 12px 12px; }
  .plan-sale .num { font-size: 18px; }

  .bar-row { grid-template-columns: 54px 1fr 52px; gap: 8px; }

  /* ---------- 表单控件：16px 防止 iOS 聚焦自动放大 ---------- */
  input, select {
    width: 100%;
    height: 44px;
    font-size: 16px;
    border-radius: 10px;
  }
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }
  .toolbar input, .toolbar select, .toolbar input.wide-input { width: 100%; min-width: 0; }
  .toolbar input:first-child,
  .toolbar .wide-input,
  .toolbar .btn,
  .toolbar .hint { grid-column: 1 / -1; }
  .toolbar .btn { height: 44px; }
  .toolbar .hint { font-size: 12px; }

  /* ---------- 表格 → 卡片 ---------- */
  .table-wrap {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }
  table { min-width: 0 !important; width: 100%; display: block; }
  thead { display: none; }
  tbody { display: block; }

  tbody tr {
    display: block;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px 10px;
    margin-bottom: 10px;
    box-shadow: 0 4px 14px rgba(15, 45, 55, 0.05);
  }
  tbody tr:hover td { background: transparent; }

  tbody tr.row-empty {
    text-align: center;
    padding: 22px 14px;
    color: var(--muted);
    font-size: 13px;
  }
  tbody tr.row-empty td { display: block; border: 0; padding: 0; }

  tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 5px 0;
    font-size: 13px;
    min-height: 26px;
  }
  tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.2px;
  }
  tbody td.num { text-align: right; }

  /* 名字作为卡片主标题 */
  #panel-members tbody td[data-label="姓名"] {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid #f1f5f6;
  }
  #panel-members tbody td[data-label="姓名"]::before { content: none; }

  /* 手机屏上低价值字段先收起 */
  #panel-members tbody td[data-label="邮箱"],
  #panel-members tbody td[data-label="注册时间"],
  #panel-orders tbody td[data-label="创建时间"] { display: none; }

  /* 单元格内的输入框 */
  tbody td input[type="number"],
  tbody td input[type="text"],
  tbody td input:not([type="checkbox"]) {
    width: 100% !important;
    max-width: 220px;
    height: 38px !important;
    font-size: 15px;
  }

  /* 操作按钮独占一行（只作用于含按钮的单元格） */
  tbody tr td.td-actions {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    margin-top: 8px;
    border-top: 1px solid #f1f5f6;
    justify-content: flex-end;
  }
  tbody tr td.td-actions::before { content: none; }
  tbody tr td.td-actions .btn { flex: 1 1 0; height: 40px; max-width: 180px; }

  /* 新增应用表单：每个输入独占一行 */
  #appForm input { grid-column: 1 / -1; }
  /* 贡献值调整：应用按钮与禁用按钮都拉满 */
  #expApply { grid-column: 1 / -1; }

  .pager { justify-content: space-between; margin-top: 12px; }
  .pager .page-text { order: 2; margin-left: auto; font-size: 12px; }
  .pager .btn { height: 40px; flex: 0 0 auto; }

  /* ---------- 弹窗 → 全屏抽屉 ---------- */
  .modal { padding: 0; align-items: stretch; }
  .modal-card {
    max-width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
  }
  .modal-head {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
  }
  .modal-head h2 { font-size: 15px; }
  #modalClose { height: 36px; padding: 0 14px; }
  .modal-body { padding: 14px 16px calc(28px + env(safe-area-inset-bottom)); }

  .detail-grid { grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .detail-item .k { font-size: 11.5px; }
  .detail-item .v { font-size: 13px; word-break: break-all; }
  .sub-title { font-size: 13px; margin: 16px 0 8px; }

  .adjust-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .adjust-row input, .adjust-row input.wide { width: 100%; height: 42px; }
  .adjust-row .btn { height: 42px; grid-column: span 1; }
  .adjust-row #toggleStatus { grid-column: 1 / -1; }

  .mini-table { background: #fff; }

  /* ---------- 登录页 ---------- */
  .login-view { padding: 16px; align-items: flex-start; padding-top: 12vh; }
  .login-card { padding: 24px 20px 20px; border-radius: 16px; }
  .brand h1 { font-size: 18px; }
  .login-card form { margin-top: 20px; gap: 14px; }
  .btn-block { height: 48px; font-size: 16px; }

  /* ---------- 提示条 ---------- */
  .toast {
    left: 16px;
    right: 16px;
    width: auto;
    transform: none;
    bottom: calc(18px + env(safe-area-inset-bottom));
    text-align: center;
    font-size: 13.5px;
    padding: 12px 16px;
    border-radius: 12px;
  }
  .toast.show { transform: translateY(-4px); }
}

/* 超窄屏（≤360px）再收一档 */
@media (max-width: 360px) {
  .cards { grid-template-columns: 1fr; }
  .plan-sales { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* 横屏手机（如 844×390）：顶栏压成一行，避免标题换行把可视区吃掉 */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { flex-wrap: nowrap; padding: 8px 12px; gap: 10px; }
  .brand.compact { flex: 0 0 auto; }
  .brand.compact .brand-mark { width: 30px; height: 30px; font-size: 15px; }
  .brand.compact h1 { font-size: 14px; white-space: nowrap; }
  .brand.compact p { display: none; }
  .tabs {
    order: 3;
    flex: 1 1 auto;
    margin: 0;
    padding: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; height: 34px; padding: 0 12px; font-size: 13px; }
  #logoutBtn { order: 2; flex: 0 0 auto; height: 34px; }
  .panel { padding: 12px 12px 40px; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 手机卡片里的图标略放大 */
@media (max-width: 720px) {
  tbody td[data-label="图标"] img { width: 44px; height: 44px; border-radius: 10px; }
}
