/* ============================================================
   拾光相册 · 设计令牌与基础组件
   8 点栅格 · 深色优先 · WCAG AA 对比度
   ============================================================ */

/* ---------- 1. 令牌 ---------- */
:root {
  /* 间距（4px 基准） */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px; --sp-20: 80px;

  /* 字号 */
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-base: 15px;
  --fs-lg: 17px; --fs-xl: 20px; --fs-2xl: 24px; --fs-3xl: 30px; --fs-4xl: 38px;

  --lh-tight: 1.25; --lh-snug: 1.4; --lh-normal: 1.6;

  /* 圆角 */
  --r-xs: 6px; --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  /* 动效 */
  --ease: cubic-bezier(.2, .8, .25, 1);
  --t-fast: 140ms var(--ease);
  --t-base: 220ms var(--ease);
  --t-slow: 380ms var(--ease);

  /* 层级 */
  --z-sticky: 100; --z-overlay: 500; --z-modal: 600; --z-lightbox: 700; --z-toast: 900;

  /* 布局 */
  --topbar-h: 64px;
  --container: 1360px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* 字体 */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ---------- 2. 主题：深色（默认） ---------- */
:root,
[data-theme="dark"] {
  --bg: #0B0D12;
  --bg-soft: #0F1218;
  --surface: #12151D;
  --surface-2: #171B25;
  --surface-3: #1E232F;
  --line: #242A38;
  --line-soft: #1A1F2A;

  --text: #E8EBF1;
  --text-2: #99A2B4;
  --text-3: #6B7488;

  --accent: #7C8CFF;
  --accent-hover: #8F9DFF;
  --accent-soft: rgba(124, 140, 255, .14);
  --accent-line: rgba(124, 140, 255, .34);
  --accent-ink: #0A0C11;

  --gold: #E0B96B;
  --danger: #FF6B7A;
  --danger-soft: rgba(255, 107, 122, .14);
  --ok: #4ADE80;
  --warn: #F0B95C;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, .38);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
  --scrim: rgba(6, 8, 12, .72);
  --glass: rgba(18, 21, 29, .72);
  color-scheme: dark;
}

/* ---------- 3. 主题：浅色 ---------- */
[data-theme="light"] {
  --bg: #F6F7FA;
  --bg-soft: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F2F4F8;
  --surface-3: #E9ECF3;
  --line: #E3E7EF;
  --line-soft: #EDF0F6;

  --text: #12151D;
  --text-2: #5B6478;
  --text-3: #8A93A6;

  --accent: #4C5BE0;
  --accent-hover: #3F4ED0;
  --accent-soft: rgba(76, 91, 224, .10);
  --accent-line: rgba(76, 91, 224, .28);
  --accent-ink: #FFFFFF;

  --gold: #A9812F;
  --danger: #DC3545;
  --danger-soft: rgba(220, 53, 69, .10);
  --ok: #16A34A;
  --warn: #B45309;

  --shadow-sm: 0 1px 2px rgba(16, 20, 32, .06);
  --shadow-md: 0 6px 20px rgba(16, 20, 32, .10);
  --shadow-lg: 0 20px 50px rgba(16, 20, 32, .16);
  --scrim: rgba(12, 16, 24, .5);
  --glass: rgba(255, 255, 255, .78);
  color-scheme: light;
}

/* ---------- 4. 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
}

img, svg, video { display: block; max-width: 100%; }
img { border: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: var(--lh-tight); }
p { margin: 0 0 var(--sp-4); }

::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: var(--r-full);
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- 5. 布局工具 ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}
@media (max-width: 767px) {
  .container { padding: 0 var(--sp-4); }
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- 6. 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--surface-3); border-color: var(--line); }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .5; cursor: not-allowed; pointer-events: none;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--outline { background: transparent; border-color: var(--line); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.08); }

.btn--danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-soft); }

.btn--sm { min-height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn--lg { min-height: 48px; padding: 0 var(--sp-6); font-size: var(--fs-lg); border-radius: var(--r-md); }

.btn--icon {
  width: 40px; min-height: 40px; padding: 0;
  border-radius: var(--r-sm);
  background: transparent; border-color: transparent;
  color: var(--text-2);
}
.btn--icon:hover { background: var(--surface-2); color: var(--text); }
.btn--icon svg { width: 20px; height: 20px; }

.btn--block { width: 100%; }

/* ---------- 7. 表单 ---------- */
.field { display: block; margin-bottom: var(--sp-4); }
.field__label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-2);
}
.field__hint { margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); }
.field__error { margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--danger); }

.input, .textarea, .select {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: var(--sp-3) var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}
.textarea { min-height: 88px; resize: vertical; line-height: var(--lh-normal); }
.select { appearance: none; background-image: none; padding-right: var(--sp-8); cursor: pointer; }

.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; }
.input-wrap__action {
  position: absolute; top: 50%; right: 4px;
  transform: translateY(-50%);
  width: 36px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--text-3); cursor: pointer;
}
.input-wrap__action:hover { color: var(--text); background: var(--surface-3); }

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  position: relative;
  width: 44px; height: 26px; flex: 0 0 44px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--t-fast), background var(--t-fast);
}
.switch input:checked + .switch__track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch__text { font-size: var(--fs-md); }

/* 复选 */
.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.checkbox input {
  appearance: none;
  width: 18px; height: 18px; flex: 0 0 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-xs);
  background: var(--surface-2);
  cursor: pointer;
  position: relative;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.checkbox input:checked { background: var(--accent); border-color: var(--accent); }
.checkbox input:checked::after {
  content: "";
  position: absolute; left: 5px; top: 1.5px;
  width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------- 8. 徽标 / 标签 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge--accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.badge--ok { color: var(--ok); border-color: rgba(74, 222, 128, .3); background: rgba(74, 222, 128, .1); }
.badge--warn { color: var(--warn); border-color: rgba(240, 185, 92, .3); background: rgba(240, 185, 92, .1); }
.badge--danger { color: var(--danger); border-color: rgba(255, 107, 122, .3); background: var(--danger-soft); }
.badge--muted { color: var(--text-3); }

/* ---------- 9. 卡片 / 面板 ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--line-soft);
}
.panel__title { font-size: var(--fs-lg); font-weight: 600; }
.panel__body { padding: var(--sp-6); }

/* ---------- 10. 模态框 ---------- */
.overlay {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  background: var(--scrim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--t-base) both;
}
.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--t-base) both;
}
.modal--wide { max-width: 620px; }
.modal__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-6) var(--sp-3);
}
.modal__title { font-size: var(--fs-xl); font-weight: 600; }
.modal__sub { margin-top: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); }
.modal__body { padding: 0 var(--sp-6) var(--sp-4); }
.modal__foot {
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6) var(--sp-6);
}
@media (max-width: 560px) {
  .modal__foot { flex-direction: column-reverse; }
  .modal__foot .btn { width: 100%; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.shake { animation: shake 500ms both; }

/* ---------- 11. 提示条 ---------- */
.toast-root {
  position: fixed;
  left: 50%; bottom: calc(var(--sp-8) + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-md);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--t-base) both;
  pointer-events: auto;
}
.toast--ok { border-color: rgba(74, 222, 128, .4); }
.toast--err { border-color: rgba(255, 107, 122, .45); }
.toast--info { border-color: var(--accent-line); }
.toast__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: 0 0 8px; }
.toast--ok .toast__dot { background: var(--ok); }
.toast--err .toast__dot { background: var(--danger); }
.toast--info .toast__dot { background: var(--accent); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 12. 骨架屏 / 空态 / 加载 ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-md);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-20) var(--sp-6);
  text-align: center;
  color: var(--text-2);
}
.empty__icon { color: var(--text-3); opacity: .8; }
.empty__title { font-size: var(--fs-lg); font-weight: 600; color: var(--text); }
.empty__text { font-size: var(--fs-md); max-width: 380px; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading .spinner { display: block; }

/* ---------- 13. 进度条 ---------- */
.progress {
  height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width var(--t-base);
}

/* ---------- 14. 无障碍：减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
