/* 设计变量、reset、页面布局。组件样式见 ui.css。 */

:root {
  color-scheme: light dark;

  /* 层级：页面底 < 卡片 < 浮层 */
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #eaeaec;
  --overlay: #ffffff;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #808089;

  /* 主色：支付宝蓝。实心按钮用略深的蓝，保证白字对比度 */
  --primary: #1677ff;
  --primary-solid: #0f66e6;
  --primary-solid-hover: #0d5bd0;
  --primary-solid-active: #0b4fb6;
  --primary-soft: #eaf2ff;
  --primary-text: #0f62d9;

  --success: #16803c;
  --success-soft: #e7f6ec;
  --warning: #a95a06;
  --warning-soft: #fdf3e1;
  --danger: #d92d20;
  --danger-solid: #d92d20;
  --danger-solid-hover: #c0261b;
  --danger-solid-active: #a32017;
  --danger-soft: #fdeceb;
  --info: #0b6ba8;
  --info-soft: #e6f2fa;

  --focus-ring: 0 0 0 3px rgba(22, 119, 255, 0.35);
  --danger-ring: 0 0 0 3px rgba(217, 45, 32, 0.25);
  --shadow-sm: 0 1px 2px rgba(16, 16, 20, 0.05);
  --shadow-pop: 0 0 0 1px rgba(16, 16, 20, 0.04), 0 12px 32px rgba(16, 16, 20, 0.12), 0 2px 8px rgba(16, 16, 20, 0.06);
  --scrim: rgba(15, 15, 20, 0.36);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 260ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --shift: 6px;
  --scale-in: 0.97;
  --press: 0.97;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;

  --control-h: 36px;
  --sidebar-w: 224px;
  --rail-w: 64px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --surface: #16161a;
    --surface-2: #1e1e23;
    --surface-3: #27272d;
    --overlay: #202026;
    --border: #2a2a31;
    --border-strong: #3a3a43;
    --text: #ececef;
    --text-2: #a9a9b3;
    --text-3: #75757f;

    --primary: #4c94ff;
    --primary-solid: #1f6fe5;
    --primary-solid-hover: #3580f0;
    --primary-solid-active: #1a62cc;
    --primary-soft: rgba(76, 148, 255, 0.16);
    --primary-text: #74abff;

    --success: #4cc97c;
    --success-soft: rgba(76, 201, 124, 0.14);
    --warning: #eeb35c;
    --warning-soft: rgba(238, 179, 92, 0.14);
    --danger: #ff7b70;
    --danger-solid: #d0362b;
    --danger-solid-hover: #e04236;
    --danger-solid-active: #b82e24;
    --danger-soft: rgba(255, 123, 112, 0.14);
    --info: #63b9ee;
    --info-soft: rgba(99, 185, 238, 0.14);

    --focus-ring: 0 0 0 3px rgba(76, 148, 255, 0.45);
    --danger-ring: 0 0 0 3px rgba(255, 123, 112, 0.3);
    /* 深色下阴影看不见，浮层靠细边框勾勒 */
    --shadow-sm: none;
    --shadow-pop: 0 0 0 1px var(--border-strong), 0 16px 40px rgba(0, 0, 0, 0.55);
    --scrim: rgba(0, 0, 0, 0.55);
  }
}

/* 减少动态效果：去掉位移和缩放，只保留淡入淡出 */
@media (prefers-reduced-motion: reduce) {
  :root {
    --shift: 0px;
    --scale-in: 1;
    --press: 1;
  }
}

/* ---------- reset ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, ul, ol, dl, dd, figure {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

a {
  color: var(--primary-text);
  text-decoration: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
}

a, button, input, textarea, [tabindex] {
  -webkit-tap-highlight-color: transparent;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

svg {
  display: block;
  flex-shrink: 0;
}

[hidden] {
  display: none !important;
}

input::-webkit-search-cancel-button,
input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
  caret-color: var(--text);
  transition: background-color 600000s 0s;
}

::selection {
  background: rgba(22, 119, 255, 0.22);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: 10px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- 后台布局：侧栏 + 顶栏 + 内容区 ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-height: 0;
  padding: var(--sp-3);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-3);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--primary-solid);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur-1), color var(--dur-1), transform var(--dur-1) var(--ease-out);
}

.nav-item[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary-text);
}

@media (hover: hover) {
  .nav-item:hover:not([aria-current="page"]) {
    background: var(--surface-2);
    color: var(--text);
  }
}

.nav-item:active {
  transform: scale(var(--press));
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
  padding: var(--sp-2) var(--sp-3);
}

.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.sidebar-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.sidebar-user-text .muted {
  font-size: var(--fs-xs);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-lg);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-6);
  padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
}

.topbar .menu-button {
  display: none;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2);
}

/* 平板 / 窄窗口：侧栏收成图标栏 */
@media (max-width: 1023px) and (min-width: 640px) {
  .app {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .sidebar {
    align-items: center;
    padding: var(--sp-3) var(--sp-2);
  }

  .brand {
    justify-content: center;
    padding: 0;
  }

  .brand-name,
  .sidebar-user-text {
    display: none;
  }

  .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .nav-item {
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .sidebar-foot {
    align-items: center;
  }

  .sidebar-user {
    padding: var(--sp-2) 0;
  }
}

/* 手机：单列，导航放进抽屉 */
@media (max-width: 639px) {
  :root {
    --control-h: 40px;
  }

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(280px, 84vw);
    padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
    border-right: 0;
    box-shadow: var(--shadow-pop);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--dur-3) var(--ease-out), visibility 0s linear var(--dur-3);
  }

  .app.nav-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform var(--dur-3) var(--ease-out), visibility 0s;
  }

  .app.nav-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .nav-item {
    height: 44px;
  }

  .topbar .menu-button {
    display: inline-flex;
    margin-left: calc(var(--sp-2) * -1);
  }

  .topbar {
    height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--sp-3) 0;
  }

  .content {
    padding: var(--sp-3);
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  }

  .hide-sm {
    display: none;
  }
}

@media (max-width: 639px) and (prefers-reduced-motion: reduce) {
  .sidebar,
  .app.nav-open .sidebar {
    transform: none;
  }

  .sidebar {
    opacity: 0;
    transition: opacity var(--dur-2), visibility 0s linear var(--dur-2);
  }

  .app.nav-open .sidebar {
    opacity: 1;
    transition: opacity var(--dur-2), visibility 0s;
  }
}

/* ---------- 单卡片页面：登录、支付跳转、提示 ---------- */

.auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--sp-6) var(--sp-4);
  padding-top: calc(var(--sp-6) + env(safe-area-inset-top));
  padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  width: min(380px, 100%);
}

.auth-card.center {
  align-items: center;
  text-align: center;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
}

.auth-heading {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.auth-title {
  font-size: var(--fs-xl);
  font-weight: 600;
  line-height: 1.35;
}

.auth-sub {
  color: var(--text-2);
}

.status-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
}

.status-icon.success {
  background: var(--success-soft);
  color: var(--success);
}

.status-icon.primary {
  background: var(--primary-soft);
  color: var(--primary-text);
}
