:root {
  --brand: #2563eb;
  --brand-dark: #0e2a47;
  --brand-2: #17588f;
  --bg: #f2f6fb;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(15, 42, 71, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ============ 登录 ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #0e2a47 0%, #123a63 55%, #17588f 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px 32px;
  box-shadow: 0 20px 60px rgba(4, 20, 38, 0.35);
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(140deg, #2563eb, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin: 0 auto 18px;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  text-align: center;
}
.login-card p.sub {
  margin: 0 0 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.login-card .field { margin-bottom: 16px; }
.login-tip {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}

/* ============ 表单 ============ */
.field { display: flex; flex-direction: column; }
.field label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='tel'],
select,
textarea {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  background: #fff;
}
input:disabled { color: var(--muted); background: #f1f5f9; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
/* 只读字段：像输入框但不可编辑，用于展示登录账号等不可改项 */
.field .readonly {
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f1f5f9;
  font-size: 14px;
  color: var(--muted);
  font-family: 'SFMono-Regular', Consolas, monospace;
}
.form-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 4px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  background: #eef2f7;
  color: var(--text);
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; height: 44px; font-size: 15px; }
.btn-link {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  padding: 0 6px;
  font-size: 13px;
  font-family: inherit;
}
.btn-link.danger { color: var(--danger); }

/* ============ 布局 ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0e2a47 0%, #123a63 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  padding: 0 8px 20px;
}
.sidebar .brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, #2563eb, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.menu { display: flex; flex-direction: column; gap: 4px; flex: 1; }
/* 「系统设置」副本：电脑端显示在菜单底部、用户信息（超级管理员）上方；手机端移到用户名右侧。
   注意它带 .menu 类（flex:1）会与主菜单平分剩余空间，这里显式改为不伸缩，使其贴底 */
.menu-settings { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.menu-settings .label-m { display: none; }
/* 主菜单里的「系统设置」由副本代替，两端都隐藏 */
#menu .menu-item[data-view='settings'] { display: none; }
.menu-item {
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.menu-item.active { background: rgba(56, 189, 248, 0.18); color: #fff; font-weight: 600; }
.sidebar-user {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 16px;
  font-size: 13px;
}
.sidebar-user .name { font-weight: 600; margin-bottom: 2px; }
.sidebar-user .role { color: rgba(255, 255, 255, 0.6); font-size: 12px; }
.sidebar-user .ops { margin-top: 12px; display: flex; gap: 8px; }
.sidebar-user .ops button {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-user .ops button:hover { background: rgba(255, 255, 255, 0.14); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.range-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-bar .preset {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.range-bar .preset.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.range-bar input[type='date'] { width: 148px; height: 32px; font-size: 13px; }
.range-bar select {
  height: 32px;
  max-width: 170px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}

.content { padding: 24px 28px 48px; }

/* ============ 卡片 ============ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .desc { font-size: 12px; color: var(--muted); margin-top: 3px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--brand);
}
.stat.green { border-left-color: var(--ok); }
.stat.orange { border-left-color: var(--warn); }
.stat.purple { border-left-color: #7c3aed; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -0.5px; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  background: #f8fafc;
  position: sticky;
  top: 0;
}
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.amount { font-weight: 600; color: var(--ok); }
.amount-plain { font-weight: 600; }
.amount-danger { font-weight: 600; color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #dbeafe;
  color: var(--brand);
}
.badge.super { background: #ede9fe; color: #6d28d9; }
.badge.agent { background: #dbeafe; color: var(--brand); }
.badge.shop { background: #dcfce7; color: #15803d; }
.badge.off { background: #f1f5f9; color: var(--muted); }
.badge.warn { background: #fef3c7; color: #b45309; }

/* ============ 趋势条 ============ */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.chart .bar-wrap {
  flex: 1;
  min-width: 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  height: 100%;
}
.chart .bar {
  width: 100%;
  max-width: 40px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #38bdf8, #2563eb);
  min-height: 3px;
  transition: height 0.3s;
}
.chart .bar.income { background: linear-gradient(180deg, #34d399, #059669); }
.chart .day { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* ============ 二维码 ============ */
.qr-box { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.qr-img {
  width: 260px;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: #fff;
}
.qr-meta { flex: 1; min-width: 240px; font-size: 13px; line-height: 2; }
.qr-meta .k { color: var(--muted); display: inline-block; width: 92px; }
.qr-token {
  margin-top: 10px;
  background: #f8fafc;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  word-break: break-all;
  color: var(--muted);
  max-height: 90px;
  overflow: auto;
}

/* ============ 模态框 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(4, 20, 38, 0.3);
}
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head .close { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============ 提示 ============ */
#toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }
#toast.error { background: var(--danger); }
#toast.ok { background: var(--ok); }

.notice {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.8;
  margin-bottom: 16px;
}
.notice.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

@media (max-width: 860px) {
  /* 手机：侧栏移到顶部——品牌与「修改密码/退出」一行，菜单横向排列（一行不够自动换行） */
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 14px 12px;
  }
  .sidebar .brand { order: 1; padding: 0; font-size: 15px; }
  .sidebar .brand-icon { width: 26px; height: 26px; font-size: 14px; border-radius: 8px; }
  /* 手机端：「设置」放在第一行、用户名（超级管理员）左边——把用户信息区拆开参与排序。
     注意 #menu-settings 同时带 .menu 类，会被下方 .menu{order:5;flex:1 1 100%} 覆盖，
     故用 .sidebar 前缀提高优先级并显式重置 flex */
  .sidebar-user {
    display: contents; /* name/ops 直接参与侧栏排列，便于把「设置」插到用户名左边 */
  }
  .sidebar-user .role { display: none; }
  .sidebar .menu-settings { order: 2; margin-left: auto; margin-top: 0; flex: 0 1 auto; }
  .sidebar .menu-settings .label-pc { display: none; }
  .sidebar .menu-settings .label-m { display: inline; }
  .sidebar .menu-settings .menu-item { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .sidebar-user .name { order: 3; margin: 0; font-size: 12px; white-space: nowrap; }
  .sidebar-user .ops { order: 4; margin-top: 0; gap: 6px; }
  .sidebar-user .ops button { font-size: 11px; padding: 0 8px; flex: none; }
  .menu {
    order: 5;
    flex: 1 1 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
  }
  .menu-item { padding: 7px 12px; font-size: 13px; white-space: nowrap; text-align: center; }
  /* 手机端：各页面卡片头部的操作按钮（新增/搜索/下拉等）整体放到标题下方的第二行 */
  .card-head { flex-direction: column; align-items: stretch; }
  .card-head > div { width: 100%; }
  .card-head > div[style] { flex-wrap: wrap; }
  .card-head input[type='text'],
  .card-head select { flex: 1; min-width: 0; width: auto; }
  /* 手机端：表格改流式布局——隐藏表头，每条记录的数据项自然排列，
     「操作」列（查看店家/编辑/删除/登记付款等）强制整行放到该记录的下一行 */
  .table-wrap { overflow-x: visible; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }
  .table-wrap tbody td {
    display: block;
    border-bottom: 0;
    padding: 2px 0;
    white-space: nowrap;
  }
  /* 手机端：每项数据前显示对应列标题（来自 td 的 data-label） */
  .table-wrap tbody td:not(.ops)::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    margin-right: 8px;
  }
  .table-wrap tbody td.ops {
    flex-basis: 100%;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
  }
  .table-wrap tfoot tr { display: flex; flex-wrap: wrap; gap: 2px 14px; padding: 12px 0; }
  .table-wrap tfoot td { display: block; border-bottom: 0; padding: 2px 0; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
