/* ══════════════════════════════════════════════════════════════════════
   MangaFlow 授权服务控制台
   ──────────────────────────────────────────────────────────────────────
   皮肤令牌与基础组件（--bg/--fg/--accent、.card/.btn/.badge/.field/.input/
   .toast/.empty-state/.segmented…）**全部来自 ../css/design-system.css**，
   那份是构建时从 src/MangaFlow.Web/src/styles/ 同步过来的镜像（见 csproj 的
   SyncDesignSystem）。这个文件只写「控制台自己的东西」：
   外壳布局、数据表、KPI 卡、抽屉、以及**手机端的响应式口径**。

   手机端口径（用户明确要求「手机也要能正常看」）：
   · ≥881px：左侧固定栏 + 右侧内容（桌面）
   · ≤880px：左栏变抽屉（汉堡键开合、点遮罩关），数据表**横排转卡片**
     （每个 td 用 data-label 当字段名），弹层改成底部抽屉（bottom sheet），
     所有可点元素 ≥ 40px 高（--tap），输入框 16px 字号（iOS 上小于 16px 会自动放大页面）。
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --tap: 40px;              /* 触控目标最小高度 */
  --side-w: 236px;          /* 桌面侧栏宽度 */
  --shell-pad: 20px;        /* 内容区留白 */
}

html, body { height: 100%; }
body { background: var(--bg); }

/* ── 外壳 ──────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }

.side {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--surface-2); border-right: 1px solid var(--border-soft);
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}

.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px var(--space-3); border-bottom: 1px solid var(--border-soft); }
.side-brand .mark {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: var(--radius-xl); display: grid; place-items: center;
  background: var(--grad-logo); color: var(--on-accent);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 45%, transparent);
}
.side-brand b { display: block; font-size: var(--text-h4); color: var(--fg); }
.side-brand span { display: block; font-size: var(--text-xs); color: var(--muted-2); }

.side-group { display: flex; flex-direction: column; gap: 2px; }
.side-group > p { margin: 0 0 4px; padding: 0 10px; font-size: var(--text-xs); letter-spacing: .1em; color: var(--muted-2); }

.nav-item {
  display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px;
  border-radius: var(--radius-lg); color: var(--muted); font-size: var(--text-body); font-weight: 500;
  border: 1px solid transparent; text-align: left; width: 100%; background: none;
  transition: color var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.nav-item:hover { color: var(--fg); background: var(--surface-3); }
.nav-item.active { color: var(--fg); background: color-mix(in oklab, var(--accent) 14%, var(--surface-3)); border-color: color-mix(in oklab, var(--accent) 42%, transparent); }
.nav-item .nav-num { margin-left: auto; font-size: var(--text-xs); color: var(--muted-2); }
.nav-item.active .nav-num { color: var(--accent); }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--border-soft); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.side-user .who { min-width: 0; }
.side-user b { display: block; font-size: var(--text-caption); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user span { display: block; font-size: var(--text-xs); color: var(--muted-2); }

/* ── 主区 ──────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--space-3);
  min-height: 56px; padding: 0 var(--shell-pad);
  background: color-mix(in oklab, var(--bg) 84%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-size: var(--text-h2); color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: var(--text-caption); color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.hamburger { display: none; }

.content { padding: var(--shell-pad); display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.page-head h2 { font-size: var(--text-h1); color: var(--fg); }
.page-head p { font-size: var(--text-caption); color: var(--muted); margin-top: 2px; }

/* ── KPI ───────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: var(--space-3); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-2xl); padding: var(--space-4); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi .kpi-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: var(--text-caption); }
.kpi .kpi-top i { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-lg); background: var(--surface-3); color: var(--accent); flex: 0 0 auto; }
.kpi b { font-size: 22px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.kpi small { font-size: var(--text-xs); color: var(--muted-2); }

/* ── 工具条 ────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.toolbar .grow { flex: 1 1 200px; min-width: 0; }
.toolbar .search-box { flex: 1 1 200px; }

/* ── 数据表 ────────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-2xl); overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-body); }
.table th {
  text-align: left; font-size: var(--text-caption); font-weight: 600; color: var(--muted);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border-soft); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); color: var(--fg-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: color-mix(in oklab, var(--surface-3) 60%, transparent); }
.table .num { font-variant-numeric: tabular-nums; }
.table .mono { font-family: var(--font-mono); letter-spacing: .02em; color: var(--fg); }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.table .muted { color: var(--muted-2); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 10px 14px; background: var(--surface-2); border-top: 1px solid var(--border-soft); flex-wrap: wrap; }
.table-foot span { font-size: var(--text-caption); color: var(--muted); }

/* ── 行内小件 ──────────────────────────────────────────────────────── */
.code-chip {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: var(--text-body);
  padding: 3px 8px; border-radius: var(--radius-lg); background: var(--surface-3); border: 1px solid var(--border-soft); color: var(--fg);
}
.code-chip button { display: grid; place-items: center; width: 22px; height: 22px; border-radius: var(--radius-md); border: none; background: none; color: var(--muted); }
.code-chip button:hover { color: var(--fg); background: var(--border-soft); }
.money { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg); }
.money.pos { color: var(--green); }
.money.neg { color: var(--red); }
.when { color: var(--muted-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--muted); }
.empty .empty-icon { width: 56px; height: 56px; margin: 0 auto var(--space-3); border-radius: var(--radius-4xl); background: var(--surface-2); border: 1px dashed var(--border-hover); display: grid; place-items: center; color: var(--muted-2); }
.empty b { display: block; color: var(--fg-2); font-size: var(--text-h4); margin-bottom: 4px; }

.note { font-size: var(--text-caption); color: var(--muted); }
.note.warn { color: var(--amber); }

/* ── 登录页 ────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-5); background:
  radial-gradient(900px 480px at 12% -10%, color-mix(in oklab, var(--accent) 16%, transparent), transparent),
  radial-gradient(700px 420px at 92% 108%, color-mix(in oklab, var(--accent-2) 14%, transparent), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-4xl); padding: var(--space-6); box-shadow: 0 18px 48px rgba(0,0,0,.45); }
.auth-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: var(--space-5); }
.auth-head .mark { width: 48px; height: 48px; border-radius: var(--radius-2xl); display: grid; place-items: center; background: var(--grad-logo); color: var(--on-accent); }
.auth-head h1 { font-size: var(--text-h1); color: var(--fg); }
.auth-head p { font-size: var(--text-caption); color: var(--muted); }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-xl); padding: 4px; margin-bottom: var(--space-5); }
.auth-tabs button { flex: 1; min-height: 34px; border: none; border-radius: var(--radius-lg); background: transparent; color: var(--muted); font-size: var(--text-caption); font-weight: 600; }
.auth-tabs button.on { background: color-mix(in oklab, var(--accent) 18%, var(--surface-3)); color: var(--fg); }
.auth-foot { margin-top: var(--space-4); font-size: var(--text-caption); color: var(--muted-2); text-align: center; line-height: 1.7; }

/* ── 弹层：桌面居中卡片 / 手机底部抽屉 ─────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(6,6,12,.62); backdrop-filter: blur(3px); display: grid; place-items: center; padding: var(--space-5); animation: fade var(--motion-fast) var(--ease); }
.modal { width: 100%; max-width: 480px; max-height: 88dvh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-4xl); padding: var(--space-5); box-shadow: 0 20px 56px rgba(0,0,0,.5); animation: rise var(--motion-base) var(--ease); }
.modal h3 { font-size: var(--text-h2); color: var(--fg); }
.modal .modal-sub { font-size: var(--text-caption); color: var(--muted); margin-top: 4px; }
.modal form { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-4); }
.modal-foot { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-5); }
.modal-foot .btn { flex: 0 0 auto; }

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(6,6,12,.55); animation: fade var(--motion-fast) var(--ease); }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }

/* ── 移动端 ────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  :root { --shell-pad: 14px; }

  .shell { grid-template-columns: minmax(0, 1fr); }

  /* 侧栏 → 抽屉。用 transform 而不是 display，滑入滑出才有方向感。 */
  .side {
    position: fixed; left: 0; top: 0; width: min(78vw, 288px); z-index: 50;
    transform: translateX(-102%); transition: transform var(--motion-base) var(--ease);
    box-shadow: 0 0 48px rgba(0,0,0,.5); padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
  .side.open { transform: none; }
  .hamburger { display: inline-grid; }

  .topbar { padding: 0 var(--shell-pad); min-height: 52px; }
  .topbar h1 { font-size: var(--text-h3); }
  .content { padding: var(--shell-pad); gap: var(--space-4); }

  /* 数据表横排转卡片：每个 td 用 data-label 显示字段名（表头在手机上没地方放） */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: var(--radius-2xl); margin: 10px; padding: 6px 4px; }
  .table td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    padding: 7px 10px; border-bottom: 1px dashed var(--border-soft); text-align: right;
  }
  .table tr td:last-child { border-bottom: none; }
  .table td::before {
    content: attr(data-label); flex: 0 0 auto; text-align: left;
    font-size: var(--text-caption); color: var(--muted-2); font-weight: 500;
  }
  .table td[data-label=""]::before { display: none; }
  .table td.span-full { justify-content: flex-start; }
  .table .actions { justify-content: flex-end; }
  .table-scroll { overflow: visible; }

  /* 弹层 → 底部抽屉（拇指够得着） */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none; max-height: 92dvh; border-radius: var(--radius-4xl) var(--radius-4xl) 0 0;
    padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom));
    animation: sheet var(--motion-base) var(--ease);
  }
  .modal-foot { position: sticky; bottom: 0; padding-top: var(--space-3); background: var(--surface); }
  .modal-foot .btn { flex: 1; }
  @keyframes sheet { from { transform: translateY(16px); opacity: .6 } to { transform: none; opacity: 1 } }

  /* 手机上「点哪儿都要够大」 */
  .btn, .input, .select, .nav-item, .auth-tabs button { min-height: var(--tap); }
  .table .btn { min-height: 34px; padding: 6px 10px; }
  .kpi b { font-size: 20px; }
  .page-head { align-items: stretch; }
  .page-head .toolbar { width: 100%; }
}

/* iOS / 移动浏览器：输入框字号 < 16px 会在聚焦时把整页放大，之后再也缩不回去 */
@media (max-width: 880px) {
  .input, .select, .textarea, input, select, textarea { font-size: 16px; }
}

@media (min-width: 1500px) {
  :root { --shell-pad: 28px; --side-w: 256px; }
}

/* 加载态的小圈。design-system 里的 .spin 是「按钮内部」用的（颜色跟着按钮文字走），
   独立占位场景需要一个中性色版本。 */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: var(--space-8); color: var(--muted); }
