/* ==========================================================================
   Bilibili-style design system (DESIGN.md)
   White cards on light-gray page, pink #FB7299 for identity, blue #00AEEC
   for actions, 6px base radius, minimal static shadow.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f1f2f3;
  --surface-3: #e9eaec;
  --surface-hover: #f1f2f3;

  /* Borders */
  --border: #e3e5e7;
  --border-strong: #c9cdd2;

  /* Text */
  --text: #18191c;
  --text-mute: #61666d;
  --text-dim: #9499a0;
  --text-disabled: #b6bcc4;

  /* Brand */
  --pink: #fb7299;
  --pink-hover: #fc8bab;
  --pink-soft: #ffeef3;
  --primary: #00aeec;
  --primary-hover: #33c0f1;
  --primary-active: #0099d1;
  --primary-soft: #e5f6fd;
  --primary-text: #ffffff;
  --ring: rgba(0, 174, 236, 0.25);

  /* Community accents */
  --coin: #ffb027;
  --fav: #ff9f43;
  --live: #ff4d6a;

  /* Status */
  --success: #2ac864;
  --success-soft: #e6f9ec;
  --warn: #f39800;
  --warn-soft: #fef3e0;
  --danger: #f05a5a;
  --danger-soft: #feeaea;
  --info: #00aeec;
  --info-soft: #e5f6fd;

  /* Shape */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  /* Shadow: near-zero at rest, soft lift on hover */
  --shadow-sm: none;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.16);

  /* Type */
  --font-body: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

  /* Mobile bottom bar height (measured at runtime by syncMobileBarHeight) */
  --mob-bar-h: 75px;

  color-scheme: light;
}

/* ---------- Reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body, #app { margin: 0; padding: 0; width: 100%; }

body {
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--primary-soft); }

h1, h2, h3, h4, h5, h6 { margin: 0; line-height: 1.25; font-weight: 600; color: var(--text); }
p { margin: 0; }

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

img { max-width: 100%; display: block; }

.muted { color: var(--text-dim); }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.hidden { display: none !important; }
.wide { grid-column: 1 / -1; }

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ==========================================================================
   Dark mode — DESIGN.md §2.4

   Default theme. Surfaces step #111 → #1B1C1E → #26282B, borders soften to
   #333538, blue swaps to the brighter legacy #23ADE5 for contrast, pink stays.
   No shadows at rest (use surface luminance instead).
   ========================================================================== */

html.dark {
  --bg: #111111;
  --surface: #1b1c1e;
  --surface-2: #26282b;
  --surface-3: #2e3033;
  --surface-hover: #26282b;

  --border: #333538;
  --border-strong: #4a4d52;

  --text: #f1f2f3;
  --text-mute: #a2a6ad;
  --text-dim: #6e7378;
  --text-disabled: #54575c;

  --pink: #fb7299;
  --pink-hover: #fc8bab;
  --pink-soft: rgba(251, 114, 153, 0.16);

  --primary: #23ade5;
  --primary-hover: #4dc2ec;
  --primary-active: #1a96c7;
  --primary-soft: rgba(35, 173, 229, 0.16);
  --ring: rgba(35, 173, 229, 0.32);

  --success: #3dd97a;
  --success-soft: rgba(61, 217, 122, 0.16);
  --warn: #f5a623;
  --warn-soft: rgba(245, 166, 35, 0.16);
  --danger: #f4717a;
  --danger-soft: rgba(244, 113, 122, 0.18);
  --info: #23ade5;
  --info-soft: rgba(35, 173, 229, 0.16);

  --shadow-sm: none;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

html.dark body { background: var(--bg); color: var(--text); }

/* Secondary/ghost buttons become filled surfaces instead of white */
html.dark button.secondary, html.dark .secondary {
  background: var(--surface-2);
  color: var(--text-mute);
  border-color: var(--border);
}
html.dark button.secondary:hover, html.dark .secondary:hover { background: var(--surface-3); color: var(--text); }
html.dark button.secondary.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

html.dark button.ghost, html.dark .ghost { background: transparent; border-color: var(--border); color: var(--text-mute); }
html.dark button.ghost:hover { background: var(--surface-2); }

html.dark button.danger, html.dark .danger { background: transparent; color: var(--danger); border-color: var(--danger); }
html.dark button.danger:hover, html.dark .danger:hover { background: var(--danger-soft); }

html.dark .addon-btn { background: transparent; color: var(--primary); border-color: var(--primary); }
html.dark .addon-btn:hover { background: var(--primary-soft); }

/* Inputs on dark fill */
html.dark input:where(#app *:not(.geetest-box, .geetest-box *)),
html.dark select:where(#app *:not(.geetest-box, .geetest-box *)),
html.dark textarea:where(#app *:not(.geetest-box, .geetest-box *)) {
  background: var(--surface-2);
  color: var(--text);
}
html.dark input:hover, html.dark select:hover, html.dark textarea:hover { background: var(--surface-3); }
html.dark input:focus, html.dark select:focus, html.dark textarea:focus {
  background: var(--surface-2);
  border-color: var(--primary);
}
html.dark input[readonly] { background: var(--surface-2); color: var(--text-mute); }

/* Topnav / surfaces */
html.dark .topnav { background: var(--surface); border-color: var(--border); }
html.dark .view-toggle { background: var(--surface-2); }
html.dark .view-toggle-btn.active { background: var(--surface-3) !important; color: var(--primary); box-shadow: none; }
html.dark .topnav-user { background: var(--surface-2); }
html.dark .balance-chip { background: var(--pink-soft); }
html.dark .balance-chip:hover { background: rgba(251, 114, 153, 0.24) !important; }
html.dark .bottombar { background: var(--surface); border-top-color: var(--border); }

/* Panels / tables */
html.dark .panel, html.dark .dash-stat, html.dark .plan,
html.dark .subscription-command, html.dark .aside-card,
html.dark .group-buy-invite, html.dark .group-buy-dashboard,
html.dark .group-buy-offers, html.dark .group-buy-board,
html.dark .group-buy-empty, html.dark .group-buy-guide,
html.dark .group-buy-share-card, html.dark .group-buy-share,
html.dark .gb-admin-create, html.dark .gb-admin-card,
html.dark .sr-card, html.dark .balance-hero,
html.dark .provisioning-endpoint-card, html.dark .auth-box,
html.dark .tutorial-card, html.dark .panel.tutorial-card {
  background: var(--surface);
  border-color: var(--border);
}

html.dark th { background: var(--surface-2); color: var(--text-dim); }
html.dark tbody tr:hover { background: var(--surface-2); }
html.dark .table-wrap { background: var(--surface); border-color: var(--border); }
html.dark .utable-sort-btn:hover { background: var(--surface-3) !important; }

html.dark .metric { background: var(--surface-2); border-color: var(--border); }
html.dark .command-metrics { background: var(--surface-2); }
html.dark .traffic-meter, html.dark .group-buy-progress, html.dark .utd-traffic-meter { background: var(--surface-3); }
html.dark .subscription-qr, html.dark .qr-placeholder { background: var(--surface-2); }

/* QR needs a light tile to scan reliably */
html.dark .subscription-qr svg, html.dark .group-buy-qr svg { background: #fff; border-radius: var(--radius); }

html.dark .plan-pay-box, html.dark .group-pay-box { background: var(--surface-2); border-color: var(--border); }
html.dark .group-buy-member { border-color: var(--border); }
html.dark .group-buy-member.empty { color: var(--text-dim); }
html.dark .group-tier-pill { background: var(--surface-2); }
html.dark .plan-picker-item { border-color: var(--border); background: var(--surface-2); }
html.dark .plan-picker-item.active, html.dark .plan-picker-item:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); }
html.dark .gb-admin-card.is-disabled { background: var(--surface-2); }
html.dark .gb-admin-card .group-tier-pills { background: var(--surface-2); }
html.dark .gb-admin-card.is-disabled .group-tier-pills { background: var(--surface-3); }
html.dark .preset-chip { background: var(--surface-2) !important; border-color: var(--border) !important; }
html.dark .preset-chip:hover { background: var(--primary-soft) !important; border-color: var(--primary) !important; }

html.dark .badge { background: var(--surface-2); color: var(--text-mute); }

html.dark .provisioning-check-card, html.dark .tutorial-block-row, html.dark .group-tier-card { border-color: var(--border); }
html.dark .group-tier-card.active { background: var(--pink-soft); border-color: var(--pink); }

html.dark .impersonate-banner { background: var(--warn-soft); border-color: rgba(245, 166, 35, 0.4); color: var(--warn); }

html.dark .drawer { background: var(--surface); border-color: var(--border); }
html.dark .drawer-backdrop { background: rgba(0, 0, 0, 0.6); }

html.dark .state-toggle { background: var(--surface-2) !important; border-color: var(--border) !important; }

/* Drawer / sidebar mobile: matches surface */
@media (max-width: 820px) {
  html.dark .bottombar { background: var(--surface); border-top-color: var(--border); }
}

/* Toast (#notice-region is injected by JS with inline light styles) */
html.dark #notice-region .notice-toast {
  background: rgba(27, 28, 30, 0.97) !important;
  color: #c8f5d9 !important;
  border-color: rgba(61, 217, 122, 0.35) !important;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5) !important;
}
html.dark #notice-region .notice-toast.error {
  background: rgba(27, 28, 30, 0.97) !important;
  color: #ffd6d9 !important;
  border-color: rgba(244, 113, 122, 0.4) !important;
}

/* Theme toggle button */
.theme-toggle {
  background: var(--surface-2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-mute) !important;
  width: 32px;
  height: 32px;
  min-height: 32px !important;
  padding: 0 !important;
  border-radius: var(--radius) !important;
  display: inline-grid !important;
  place-items: center;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--primary) !important; border-color: var(--primary) !important; background: var(--primary-soft) !important; }
.theme-toggle svg { width: 18px; height: 18px; fill: currentColor; grid-area: 1 / 1; }
.theme-toggle .icon-moon { display: none; }
html.dark .theme-toggle .icon-sun { display: none; }
html.dark .theme-toggle .icon-moon { display: block; }

/* Floating variant for the auth page */
.theme-toggle-floating {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
}

/* ---------- Buttons ---------- */

button:where(#app *:not(.geetest-box, .geetest-box *)) {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: 0;
  border-radius: var(--radius);
  min-height: 32px;
  padding: 6px 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  background: var(--primary);
  color: #fff;
  transition: background .15s ease, transform .1s ease;
}

button:hover { background: var(--primary-hover); }
button:active { background: var(--primary-active); }
button:disabled { background: var(--surface-2); color: var(--text-disabled); cursor: not-allowed; }

button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

button.secondary, .secondary {
  background: #fff;
  color: var(--text-mute);
  border: 1px solid var(--border);
}
button.secondary:hover, .secondary:hover { background: var(--surface-2); color: var(--text); }
button.secondary.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

button.ghost, .ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mute);
}
button.ghost:hover { background: var(--surface-2); }

button.danger, .danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid var(--danger);
}
button.danger:hover, .danger:hover { background: var(--danger-soft); }

button.primary, .primary { background: var(--pink); color: #fff; }
button.primary:hover, .primary:hover { background: var(--pink-hover); }

button.small, .small { min-height: 28px; padding: 4px 12px; font-size: 13px; }

button.block, .block { display: flex; width: 100%; }

.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: btn-spin .8s linear infinite;
}
.secondary .btn-spinner, .ghost .btn-spinner, .danger .btn-spinner {
  border-color: var(--border); border-top-color: var(--primary);
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

.btn-result { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.btn-result.ok { color: var(--success); }
.btn-result.bad { color: var(--danger); }

/* ---------- Inputs ---------- */

input:where(#app *:not(.geetest-box, .geetest-box *)),
select:where(#app *:not(.geetest-box, .geetest-box *)),
textarea:where(#app *:not(.geetest-box, .geetest-box *)) {
  font: inherit;
  width: 100%;
  padding: 8px 12px;
  min-height: 32px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: 0;
  transition: background .15s ease, border-color .15s ease;
}

input:hover, select:hover, textarea:hover { background: var(--surface-3); }

input:focus, select:focus, textarea:focus {
  background: #fff;
  border-color: var(--primary);
}

input::placeholder, textarea::placeholder { color: var(--text-dim); }

input[readonly] { background: var(--surface-2); color: var(--text-mute); }

input[type="checkbox"], input[type="radio"] {
  width: 16px !important;
  height: 16px;
  min-height: 0 !important;
  padding: 0;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

textarea { resize: vertical; line-height: 1.5; }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

label { display: grid; gap: 6px; font-size: 13px; color: var(--text-mute); }

label.check, .check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

label.check small, .check small { display: block; color: var(--text-dim); font-size: 12px; }

.form { display: grid; gap: 14px; }
.form-title { font-size: 16px; font-weight: 600; }

.input-addon { display: flex; gap: 8px; }
.input-addon input { flex: 1; min-width: 0; }
.addon-btn {
  flex-shrink: 0;
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 0 14px;
  font-size: 13px;
  min-height: 32px;
}
.addon-btn:hover { background: var(--primary-soft); }
.addon-btn:disabled { color: var(--text-disabled); border-color: var(--border); background: var(--surface-2); }

.input-suffix { display: flex; gap: 8px; }
.input-suffix input { flex: 1; min-width: 0; }
.input-suffix select { width: auto; flex-shrink: 0; }

.password-field { position: relative; display: flex; }
.password-field input { padding-right: 40px; }
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent !important;
  border: 0 !important;
  color: var(--text-dim);
  min-height: 28px;
  padding: 4px 8px;
}
.password-toggle:hover { color: var(--primary); }
.password-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.password-toggle.is-visible { color: var(--primary); }

.field-hint { font-size: 12px; color: var(--text-dim); }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-mute);
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- Layout shell: 64px topnav + centered page + mobile bottom bar ---------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== Top navigation bar (B 站顶栏) ===== */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 64px;
}

.brand-home {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: var(--text);
}
.brand-home:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--pink-soft);
  overflow: hidden;
  flex-shrink: 0;
}
.brand-mark img { width: 24px; height: 24px; }
.brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* Nav links: horizontal, blue underline when active */
.topnav-nav {
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: 100%;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.topnav-nav::-webkit-scrollbar { display: none; }
.topnav-nav button {
  background: transparent !important;
  border: 0 !important;
  color: var(--text-mute);
  font-size: 14px;
  font-weight: 400;
  padding: 0 12px;
  height: 100%;
  min-height: 0 !important;
  border-radius: 0 !important;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: none !important;
}
.topnav-nav button:hover { color: var(--primary); background: transparent !important; }
.topnav-nav button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}
.nav-icon { display: inline-flex; width: 18px; height: 18px; flex-shrink: 0; }
.nav-icon svg { width: 18px; height: 18px; fill: currentColor; }

.topnav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Admin mode toggle */
.view-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.view-toggle-btn {
  flex: 1;
  background: transparent !important;
  color: var(--text-mute);
  border: 0 !important;
  min-height: 26px;
  padding: 3px 12px !important;
  font-size: 12.5px;
  border-radius: var(--radius-sm) !important;
}
.view-toggle-btn.active {
  background: #fff !important;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Balance chip (pink, B 站会员色) */
.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--pink-soft);
  border: 0 !important;
  min-height: 30px !important;
  cursor: pointer;
  transition: background .15s;
}
.balance-chip:hover { background: #ffe3ec !important; }
.balance-label { font-size: 12px; color: var(--text-mute); }
.balance-amount { font-size: 13px; font-weight: 600; color: var(--pink); font-variant-numeric: tabular-nums; }

/* User chip */
.topnav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  min-width: 0;
}
.avatar, .user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.topnav-user-info { display: grid; gap: 0; min-width: 0; }
.topnav-user-info .email {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.topnav-user-info .role { font-size: 10.5px; color: var(--text-dim); line-height: 1.2; }

/* Logout: icon button */
.logout-btn {
  width: 32px; height: 32px;
  min-height: 32px !important;
  padding: 0 !important;
  display: inline-grid !important;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mute);
  border-radius: var(--radius) !important;
}
.logout-btn:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.logout-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ===== Page container ===== */
.page {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Topnav inner shares the same centered column for visual rhythm */
.topnav-inner {
  height: 64px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 4px;
}
.page-head h1 { font-size: 20px; line-height: 28px; font-weight: 600; }
.page-head-site { font-size: 12.5px; color: var(--text-dim); }
.eyebrow {
  font-size: 11px;
  letter-spacing: .12em;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
}

.impersonate-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--warn-soft);
  border: 1px solid #f5d9ac;
  border-radius: var(--radius);
  font-size: 13px;
  color: #8a5a00;
}
.impersonate-exit {
  min-height: 26px !important;
  padding: 3px 12px !important;
  font-size: 12.5px !important;
}

/* ===== Mobile bottom tab bar (B 站移动端) ===== */
.bottombar { display: none; }

/* ---------- Panels & cards ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}
.panel:hover { border-color: var(--border); }
.panel + .panel { margin-top: 16px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}
.panel-head strong { font-size: 15px; font-weight: 600; }

.section-head { margin-bottom: 14px; }
.section-head h2 { font-size: 16px; font-weight: 600; }
.section-head p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.empty-state { padding: 32px; text-align: center; color: var(--text-dim); }

/* ---------- Tables ---------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 14px; }
th {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td .row, th { white-space: nowrap; }
td input, td select { padding: 5px 10px; font-size: 13px; min-height: 28px; }
td .check { margin-top: 4px; font-size: 12px; }

/* Sortable headers */
.utable-th-sort { padding: 0 !important; }
.utable-sort-btn {
  display: flex !important;
  width: 100%;
  justify-content: flex-start;
  gap: 4px;
  background: transparent !important;
  border: 0 !important;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  min-height: 0 !important;
  padding: 10px 14px !important;
  border-radius: 0;
}
.utable-sort-btn:hover { background: var(--surface-3) !important; color: var(--text); }
.utable-th-sort.is-sorted .utable-sort-btn { color: var(--primary); }
.utable-sort-text { display: inline-flex; flex-direction: column; align-items: flex-start; }
.utable-th-sub { font-size: 11px; font-weight: 400; color: var(--text-disabled); }
.utable-sort-icon { display: inline-grid; width: 12px; height: 14px; }
.utable-sort-icon svg { width: 12px; height: 7px; fill: currentColor; opacity: .3; }
.utable-th-sort.is-sorted[aria-sort="ascending"] .s-asc { opacity: 1; color: var(--primary); }
.utable-th-sort.is-sorted[aria-sort="descending"] .s-desc { opacity: 1; color: var(--primary); }

.utable-empty { text-align: center; padding: 32px !important; }
.utable-lead { font-size: 13px; margin-bottom: 12px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 0 0; }
.page-info { font-size: 13px; color: var(--text-dim); }

/* ---------- Auth page ---------- */

.auth {
  display: grid;
  min-height: 100vh;
  background: var(--bg);
}
.auth-wrap {
  width: 100%;
  max-width: 880px;
  margin: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 48px;
  padding: 32px;
}
.auth-hero-copy { display: flex; align-items: center; gap: 16px; }
.auth-hero-copy .logo-mark, .logo-mark {
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: var(--pink-soft);
  overflow: hidden;
}
.logo-mark img { width: 40px; height: 40px; }
.auth-kicker { font-size: 12px; color: var(--pink); font-weight: 600; letter-spacing: .08em; }
.auth-hero-copy h1 { font-size: 24px; font-weight: 600; margin-top: 2px; }

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.auth-box .auth-head { display: grid; gap: 4px; margin-bottom: 16px; }
.auth-box .auth-head h2 { font-size: 20px; font-weight: 600; }
.auth-box .auth-head p { font-size: 13px; color: var(--text-dim); }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  padding: 0;
  background: transparent;
}
.tabs .tab {
  background: transparent !important;
  border: 0 !important;
  color: var(--text-mute);
  font-size: 14px;
  padding: 8px 16px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}
.tabs .tab:hover { color: var(--text); background: transparent !important; }
.tabs .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.auth-foot { margin-top: 12px; font-size: 13px; text-align: center; }
.auth-foot a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  margin: -6px -14px;
  font-weight: 500;
}

.step-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12.5px;
  margin-bottom: 14px;
}
.target-email { font-weight: 600; color: var(--text); margin-bottom: 14px; }

.geetest-box { margin: 4px 0; }
.geetest-status { font-size: 12px; color: var(--text-dim); }

/* ---------- Dashboard ---------- */

.dash-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: grid;
  gap: 4px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.dash-stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.dash-stat-label { font-size: 12.5px; color: var(--text-dim); }
.dash-stat-value { font-size: 24px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.dash-columns { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.dash-side { display: grid; gap: 16px; }
.dash-shortcuts { display: grid; gap: 8px; }
.dash-feed { display: grid; gap: 0; }
.dash-feed-body { display: grid; gap: 12px; }
.dash-feed-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.dash-feed-meta { font-size: 12px; color: var(--text-dim); }
.dash-feed-empty { padding: 16px; text-align: center; }

/* ---------- Account / subscription workbench ---------- */

.subscription-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.subscription-command {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: grid;
  gap: 18px;
}

.command-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.command-copy h2 { font-size: 20px; font-weight: 600; }
.command-copy p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.traffic-block { display: grid; gap: 8px; }
.traffic-block-top { display: flex; align-items: baseline; gap: 10px; font-size: 13px; color: var(--text-mute); }
.traffic-block-top b { font-size: 15px; color: var(--text); }
.traffic-block-top em { margin-left: auto; font-style: normal; font-size: 18px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.traffic-meter {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.traffic-meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  border-radius: 999px;
  transition: width .3s ease;
}
.is-exhausted .traffic-meter span { background: var(--danger); }
.is-exhausted .traffic-block-top em { color: var(--danger); }

.command-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.command-metrics span { display: grid; gap: 2px; }
.command-metrics em { font-style: normal; font-size: 12px; color: var(--text-dim); }
.command-metrics strong { font-size: 14px; color: var(--text); }

.command-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.subscription-aside { display: grid; gap: 16px; }
.aside-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
}
.aside-card-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
}
.aside-card-head b { font-size: 14px; }
.aside-card p { font-size: 12.5px; color: var(--text-dim); }
.subscription-renewal strong { font-size: 15px; }

.subscription-qr, .qr-placeholder {
  width: 180px;
  height: 180px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
}
.subscription-qr svg { width: 100%; height: 100%; }
.copy-subscription-qr { cursor: pointer; }
.qr-placeholder span { font-size: 13px; color: var(--text-dim); }

/* ---------- Buy plans ---------- */

.purchase-hero { margin-bottom: 16px; }
.purchase-hero h2 { font-size: 20px; font-weight: 600; }
.purchase-hero p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.purchase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.plan {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: grid;
  gap: 10px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.plan:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.plan strong { font-size: 16px; }
.plan .price { font-size: 22px; font-weight: 700; color: var(--pink); }
.plan .price small { font-size: 12px; font-weight: 400; color: var(--text-dim); }
.plan .meta { font-size: 12.5px; color: var(--text-dim); }
.plan-desc { font-size: 12.5px; color: var(--text-mute); }

.discount-row { display: grid; gap: 6px; font-size: 13px; color: var(--text-mute); }
.discount-row input, .discount-row select { max-width: none; }

.plan-pay-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  background: var(--surface-2);
}
.plan-pay-box.is-disabled { opacity: .6; }
.plan-pay-summary { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-mute); }
.plan-pay-summary b { color: var(--pink); }

/* ---------- Settings ---------- */

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.settings-tabs button {
  background: transparent !important;
  border: 0 !important;
  color: var(--text-mute);
  font-size: 13.5px;
  padding: 10px 14px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}
.settings-tabs button:hover { color: var(--text); background: transparent !important; }
.settings-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.settings-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.save-indicator { font-size: 12.5px; color: var(--text-dim); }
.save-indicator.ok { color: var(--success); }

.info-field { display: grid; gap: 4px; font-size: 13.5px; }
.info-label { font-size: 12.5px; color: var(--text-dim); }

.balance-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--pink-soft);
  border-radius: var(--radius);
}
.balance-strip-label { font-size: 12.5px; color: var(--text-mute); }
.balance-strip-value { font-size: 18px; font-weight: 700; color: var(--pink); }

.profile-logout-panel { display: flex; justify-content: center; }
.profile-logout-btn { width: auto; padding: 8px 24px; }

/* ---------- Balance ---------- */

.balance-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: grid;
  gap: 16px;
}
.balance-hero-card { display: grid; gap: 4px; }
.balance-hero-label { font-size: 13px; color: var(--text-dim); }
.balance-hero-amount { font-size: 32px; font-weight: 700; color: var(--pink); font-variant-numeric: tabular-nums; }
.balance-hero-sub { font-size: 12.5px; color: var(--text-dim); }
.balance-recharge-form { display: grid; gap: 12px; }
.balance-recharge-row { display: flex; gap: 10px; flex-wrap: wrap; }
.balance-presets { display: flex; gap: 8px; flex-wrap: wrap; }
.preset-chip {
  background: #fff !important;
  border: 1px solid var(--border) !important;
  color: var(--text-mute) !important;
  border-radius: var(--radius-pill) !important;
  min-height: 30px !important;
  padding: 4px 14px !important;
  font-size: 13px !important;
}
.preset-chip:hover { border-color: var(--primary) !important; color: var(--primary) !important; background: var(--primary-soft) !important; }

.balance-tx-list { display: grid; }
.balance-tx {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.balance-tx:last-child { border-bottom: 0; }
.balance-tx-info { display: grid; gap: 2px; min-width: 0; }
.balance-tx-meta { font-size: 12px; color: var(--text-dim); }
.balance-tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.balance-tx-amount.positive { color: var(--success); }
.balance-tx-amount.negative { color: var(--text); }

/* ---------- Group buy ---------- */

.group-buy-workspace, .group-buy-main-card { display: grid; gap: 16px; }
.group-buy-hero { margin-bottom: 16px; }
.group-buy-headline h2 { font-size: 20px; font-weight: 600; }
.group-buy-headline p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.group-buy-invite, .group-buy-dashboard, .group-buy-offers, .group-buy-board,
.group-buy-empty, .group-buy-guide, .group-buy-share-card, .group-buy-share {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.group-buy-copy-row { display: flex; gap: 8px; }
.group-buy-copy-row input { flex: 1; }

.group-buy-progress-wrap { display: grid; gap: 8px; }
.group-buy-progress {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.group-buy-progress > span, .group-buy-progress-bar {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--pink-hover));
  border-radius: 999px;
}
.group-buy-progress-label { font-size: 12.5px; color: var(--text-dim); }

.group-buy-members { display: grid; gap: 10px; }
.group-buy-member-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.group-buy-member {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12.5px;
}
.group-buy-member.me { border-color: var(--pink); color: var(--pink); }
.group-buy-member.empty { color: var(--text-dim); border-style: dashed; cursor: pointer; }
.member-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--pink); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}
.member-status.paid { color: var(--success); }
.member-status.unpaid { color: var(--text-dim); }

.group-buy-timer { display: flex; gap: 12px; align-items: baseline; }
.timer-label { font-size: 12.5px; color: var(--text-dim); }
.timer-value { font-size: 20px; font-weight: 700; color: var(--danger); font-variant-numeric: tabular-nums; }

.group-tier-ladder { display: grid; gap: 8px; }
.group-tier-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.group-tier-card.active { border-color: var(--pink); background: var(--pink-soft); }
.group-tier-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.group-tier-pill {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 12px;
}
.group-tier-pill.active { background: var(--pink-soft); color: var(--pink); }
.group-tier-pill b { font-size: 13px; }
.group-tier-pill em { font-style: normal; }

.group-buy-offer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.group-buy-offer { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; }

.group-buy-mini-list { display: grid; gap: 8px; }
.group-buy-mini {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.group-buy-mini-status { font-size: 12px; }
.group-buy-mini-status.open { color: var(--primary); }
.group-buy-mini-status.full { color: var(--warn); }
.group-buy-mini-status.completed { color: var(--success); }

.group-pay-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid; gap: 8px;
  background: var(--surface-2);
}
.group-pay-box.is-muted { opacity: .7; }
.group-pay-summary { display: flex; justify-content: space-between; font-size: 12.5px; }
.group-pay-hint { font-size: 12px; color: var(--text-dim); }

.group-buy-guide-list { display: grid; gap: 10px; padding-left: 18px; font-size: 13.5px; color: var(--text-mute); }
.group-buy-side-note { font-size: 12.5px; color: var(--text-dim); }

/* Group buy admin — DESIGN.md: white cards on gray page, thin borders,
   6px radius, static-shadow-free, pink/blue only as accents. */
.gb-admin-workspace { display: grid; gap: 16px; }
.gb-admin-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.gb-admin-create { padding: 20px; }
.gb-admin-create .section-head { margin-bottom: 4px; }
.gb-admin-form { display: grid; gap: 14px; }
.gb-admin-submit { margin-top: 2px; }
.gb-admin-submit button { width: 100%; }
.gb-admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.gb-admin-cards { display: grid; gap: 16px; min-width: 0; }
.gb-admin-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.gb-admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: grid;
  gap: 12px;
  background: var(--surface);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.gb-admin-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.gb-admin-card.is-disabled { background: var(--surface-2); }
.gb-admin-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.gb-admin-card-title { display: grid; gap: 2px; min-width: 0; }
.gb-admin-card-title strong { font-size: 16px; font-weight: 600; color: var(--text); }
.gb-admin-card-scope { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-admin-card-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
.gb-admin-card .group-tier-pills { padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); }
.gb-admin-card.is-disabled .group-tier-pills { background: var(--surface-3); }
.gb-admin-actions { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.gb-admin-empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.gb-admin-card.is-removing { opacity: 0; transform: scale(.96); transition: opacity .3s ease, transform .3s ease; pointer-events: none; }

.plan-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.plan-picker-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s ease, background .15s ease;
}
.plan-picker-item:hover { border-color: var(--primary); }
.plan-picker-item:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.plan-picker-item input { flex-shrink: 0; width: 15px !important; height: 15px; }
.plan-picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.plan-picker-item code {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim);
  background: transparent;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1100px) {
  .gb-admin-layout { grid-template-columns: 1fr; }
}

/* Plan picker is also embedded in the discount-code drawer; keep it narrow */
.drawer-form .plan-picker { grid-template-columns: 1fr; }

/* ---------- Users page (admin) ---------- */

.users-page { display: grid; gap: 16px; }
.utable-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.utable-search { display: flex; gap: 8px; flex: 1 1 320px; min-width: 240px; }
.utable-search input { flex: 1; min-width: 0; }
.utable-panel { padding: 12px !important; }
.utable-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.utable .utd-user { display: flex; align-items: center; gap: 10px; }
.utd-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--pink); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.utd-email { font-weight: 500; font-size: 13.5px; }
.utd-idtext, .utd-sub { font-size: 11.5px; color: var(--text-dim); }
.utd-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.utd-num { font-variant-numeric: tabular-nums; }
.utd-days { font-weight: 600; }
.utd-days-ok { color: var(--success); }
.utd-days-warn { color: var(--warn); }
.utd-days-bad { color: var(--danger); }
.utd-traffic { display: grid; gap: 4px; min-width: 120px; }
.utd-traffic-meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.utd-traffic-meter span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.utd-uuid { font-size: 11px; }
.utd-op { display: flex; gap: 6px; flex-wrap: wrap; }
.utd-op-h { min-width: 200px; }
.utr.is-open { background: var(--primary-soft); }

.user-command-stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-mute); }

.state-toggle {
  background: var(--surface-2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-mute) !important;
  min-height: 26px !important;
  padding: 3px 10px !important;
  font-size: 12px !important;
  border-radius: var(--radius-pill) !important;
}
.state-toggle.active { background: var(--success-soft) !important; color: var(--success) !important; border-color: var(--success) !important; }
.state-toggle.disable-toggle.active { background: var(--danger-soft) !important; color: var(--danger) !important; border-color: var(--danger) !important; }

/* ---------- Drawer ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 100;
  animation: dw-fade .18s ease;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 101;
  display: flex;
  flex-direction: column;
  animation: dw-slide .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes dw-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dw-slide { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-idhead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.drawer-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--pink); color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 15px;
  flex-shrink: 0;
}
.drawer-idtext { min-width: 0; display: grid; gap: 2px; }
.drawer-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-sub { font-size: 12px; color: var(--text-dim); }
.drawer-close {
  background: transparent !important;
  border: 0 !important;
  color: var(--text-dim);
  font-size: 18px;
  min-height: 32px !important;
  padding: 4px 10px !important;
}
.drawer-close:hover { color: var(--text); background: var(--surface-2) !important; }

.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; display: grid; gap: 16px; align-content: start; }
.drawer-section { display: grid; gap: 10px; }
.drawer-section-title { font-size: 13px; font-weight: 600; color: var(--text-mute); }
.drawer-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.drawer-stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.drawer-stat-grid .metric { padding: 10px 12px; }
.drawer-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; padding: 6px 0; }
.drawer-switches, .drawer-toggles { display: grid; gap: 8px; }
.drawer-form { display: grid; gap: 12px; }
.drawer-actions { display: flex; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
.drawer-actions button { flex: 1; }
.drawer-danger { border-top: 1px solid var(--border); padding-top: 12px; }

.metric {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid; gap: 2px;
  border: 1px solid var(--border);
}
.metric .label { font-size: 12px; color: var(--text-dim); }
.metric .value { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Provisioning ---------- */

.provisioning-node-list { display: grid; gap: 12px; }
.provisioning-node-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.provisioning-node-toolbar-actions { display: flex; gap: 8px; }
.provisioning-node-hint { font-size: 13px; }
.provisioning-settings-brief { font-size: 13px; color: var(--text-mute); }

.provisioning-endpoint-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.provisioning-endpoint-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
}
.provisioning-endpoint-toggle {
  display: flex !important;
  flex: 1;
  align-items: center;
  gap: 10px;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  min-height: 0 !important;
  text-align: left;
}
.provisioning-endpoint-caret { display: inline-flex; transition: transform .15s ease; }
.provisioning-endpoint-caret svg { width: 16px; height: 16px; fill: var(--text-dim); }
.provisioning-endpoint-card:not(.is-collapsed) .provisioning-endpoint-caret { transform: rotate(90deg); }
.provisioning-endpoint-summary { display: grid; gap: 2px; min-width: 0; }
.provisioning-endpoint-summary-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.provisioning-summary-flag {
  font-size: 11px; font-weight: 500;
  background: var(--surface-2); color: var(--text-dim);
  padding: 1px 6px; border-radius: var(--radius-pill);
}
.provisioning-endpoint-summary-meta { display: flex; gap: 6px; font-size: 12px; color: var(--text-dim); }
.provisioning-endpoint-actions { display: flex; align-items: center; gap: 10px; }
.provisioning-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-mute); }
.provisioning-endpoint-body { border-top: 1px solid var(--border); padding: 16px; display: grid; gap: 20px; }
.provisioning-endpoint-card.is-collapsed .provisioning-endpoint-body { display: none; }
.provisioning-endpoint-section { display: grid; gap: 12px; }
.provisioning-endpoint-section-title strong { font-size: 14px; }
.provisioning-endpoint-section-title p { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.provisioning-endpoint-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.provisioning-check-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  align-items: flex-start;
}

/* ---------- Tutorials ---------- */

.tutorial-hero { margin-bottom: 16px; }
.tutorial-hero h2 { font-size: 20px; font-weight: 600; }
.tutorial-hero p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.tutorial-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.tutorial-card { display: grid; gap: 10px; }
.tutorial-card + .tutorial-card { margin-top: 12px; }
.tutorial-card-head { display: flex; align-items: center; gap: 10px; }
.tutorial-card-index {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 600;
  flex-shrink: 0;
}
.tutorial-card-title { font-size: 15px; font-weight: 600; }
.tutorial-card-body { font-size: 13.5px; color: var(--text-mute); line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.tutorial-card-links { display: flex; gap: 10px; flex-wrap: wrap; }
.tutorial-qa { font-size: 13px; }
.tutorial-empty { text-align: center; padding: 40px; }
.tutorial-empty-icon { font-size: 32px; margin-bottom: 8px; }

.tutorial-block-list { display: grid; gap: 12px; }
.tutorial-block-row { display: grid; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tutorial-block-row-head { display: flex; gap: 8px; align-items: center; }
.tutorial-block-row-head input { flex: 1; }
.tutorial-block-toolbar { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- Fortune ---------- */

.fortune-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  min-height: calc(100vh - 200px);
}
.fortune-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.fortune-head strong { font-size: 15px; font-weight: 600; }
.fortune-open { font-size: 13px; }
.fortune-frame {
  flex: 1;
  width: 100%;
  min-height: 600px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

/* ---------- Shadowrocket ---------- */

.sr-list { display: grid; gap: 12px; }
.sr-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: grid; gap: 10px;
  background: var(--surface);
}
.sr-field { display: flex; align-items: center; gap: 10px; }
.sr-label { font-size: 12.5px; color: var(--text-dim); width: 90px; flex-shrink: 0; }
.sr-value { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-meta { font-size: 12px; color: var(--text-dim); }
.sr-warning {
  font-size: 13px;
  color: var(--text-mute);
  background: var(--warn-soft);
  border: 1px solid rgba(243, 152, 0, 0.25);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.sr-warning strong {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--warn);
  margin-bottom: 4px;
}
.sr-warning strong svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
.sr-warning p { margin: 0; line-height: 1.6; }
.sr-warning b { color: var(--warn); font-weight: 600; }
.sr-locked { text-align: center; padding: 40px 20px; display: grid; justify-items: center; gap: 10px; }
.sr-locked-icon svg { width: 48px; height: 48px; fill: var(--text-dim); }
.sr-locked-title { font-size: 16px; font-weight: 600; }

/* ---------- Backups ---------- */

.notice-inline { font-size: 12.5px; }
.notice-inline.ok { color: var(--success); }
.notice-inline.bad { color: var(--danger); }

/* ---------- Misc ---------- */

.pack-quota.is-capped { color: var(--danger); }
.refund-chip {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11.5px;
}
.maintenance-note { font-size: 12.5px; }
.hint { font-size: 12px; color: var(--text-dim); }
.desc { font-size: 13px; color: var(--text-mute); }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.block { margin-top: 8px; }

.balance-adjust-btn { margin-left: 6px; }
.traffic-grant-btn { margin-top: 6px; }

.buy-tab-content { display: grid; gap: 16px; }

/* ---------- Toast (in-app, see also runtime #notice-region) ---------- */

.toast-host { position: relative; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
  .dash-columns { grid-template-columns: 1fr; }
  .subscription-workbench { grid-template-columns: 1fr; }
  .subscription-aside { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}

/* Mid-width screens: hide non-essential topnav text so the nav can breathe */
@media (max-width: 1280px) {
  .topnav-user-info { display: none; }
  .topnav-user { background: transparent; padding: 0; }
  .topnav-nav button .nav-icon { display: none; }
  .topnav-nav button { padding: 0 10px; }
}

@media (max-width: 960px) {
  .settings-grid, .provisioning-endpoint-grid, .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  /* Top nav: hide the horizontal nav links and desktop-only chips */
  .topnav { height: 56px; }
  .topnav-inner { height: 56px; padding: 0 14px; gap: 10px; }
  .topnav-nav { display: none; }
  .topnav-user-info { display: none; }
  .topnav-user { background: transparent; padding: 0; }
  .topnav-right { margin-left: auto; gap: 6px; }
  .balance-chip .balance-label { display: none; }

  /* Page content reserves room for the fixed bottom bar */
  .page { padding: 14px 14px calc(var(--mob-bar-h, 60px) + 20px); }
  .page-head h1 { font-size: 17px; }

  /* Mobile bottom tab bar (B 站移动端): icon + label, horizontal scroll */
  .bottombar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
    scrollbar-width: none;
    gap: 0;
  }
  .bottombar::-webkit-scrollbar { display: none; }
  .bottombar button {
    flex: 1 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-width: 64px;
    min-height: 50px !important;
    padding: 6px 4px !important;
    font-size: 11px;
    background: transparent !important;
    border: 0 !important;
    color: var(--text-mute);
    border-radius: var(--radius) !important;
    box-shadow: none !important;
  }
  .bottombar button:hover { color: var(--text); background: transparent !important; }
  .bottombar button.active { background: transparent !important; color: var(--primary); font-weight: 500; }
  .bottombar .nav-icon, .bottombar .nav-icon svg { width: 22px; height: 22px; }

  .auth-wrap { grid-template-columns: 1fr; gap: 24px; padding: 20px; }
  .auth-hero-copy { justify-content: center; }

  .command-metrics { grid-template-columns: repeat(2, 1fr); }
  .command-actions button { flex: 1; }

  .drawer { width: 100vw; }
}

@media (max-width: 480px) {
  .panel { padding: 14px; }
  .dash-stat-value { font-size: 20px; }
  .balance-hero-amount { font-size: 26px; }
  th, td { padding: 8px 10px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
