/* ============================================================
   common.css — 全局基础样式与公共组件
   （设计变量 / 重置 / 按钮 / 表单 / 图标 / Toast / 弹窗 / 滚动条）
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  --primary: #4f46e5;            /* 主色（靛蓝） */
  --primary-100: #eef2ff;
  --primary-50: #f5f7ff;
  --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --bg: #f3f5fa;                 /* 页面背景 */
  --surface: #ffffff;            /* 卡片/面板背景 */
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1f2937;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --danger: #ef4444;
  --danger-600: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 10px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .05);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, .14), 0 4px 12px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ---------- 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* 统一移除默认焦点边框，自定义 :focus-visible 保证键盘可访问性 */
input, select, button, textarea { outline: none !important; box-shadow: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ---------- 通用工具类 ---------- */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- 图标（SVG） ---------- */
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.15em; }

/* ---------- Logo 徽标（各页面通用） ---------- */
.logo-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--gradient); color: #fff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, .3);
}
.logo-badge .icon { width: 22px; height: 22px; }
/* logo 图片（透明底 / 白底版本）通用样式 */
.logo-badge img {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: inherit;
  display: block;
}
/* 浅色背景场景：白色底 logo 融入白色区域 */
.logo-badge.brand-logo-img.light { background: #fff; }
.brand-text { font-size: 18px; font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand-text span { color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; transition: all .2s var(--ease); user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn[hidden] { display: none; }
.btn-primary {
  background: var(--gradient); color: #fff;
  box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); box-shadow: 0 8px 20px rgba(99, 102, 241, .45); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 16px rgba(239, 68, 68, .3); }
.btn-danger:hover:not(:disabled) { background: var(--danger-600); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: var(--text-2);
  transition: all .18s var(--ease);
}
.icon-btn:hover { background: var(--primary-100); color: var(--primary); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }

/* ---------- 加载动画 ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}

/* ---------- 表单控件 ---------- */
.input, .select {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; background: var(--surface); font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15) !important;
}
/* 下拉框自定义箭头（跨浏览器） */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 14px;
  padding-right: 36px;
}

/* ---------- Toast 通知 ---------- */
#toast-container {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  position: relative; display: flex; align-items: center; justify-content: center;
  max-width: min(88vw, 420px);
  padding: 12px 18px; border-radius: 20px; font-size: 14px; line-height: 1.45;
  border: 1px solid rgba(0, 0, 0, .08); box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(-14px) scale(.97); cursor: pointer;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: auto; user-select: none; word-break: break-word;
  text-align: center;
}
.toast.enter { opacity: 1; transform: translateY(0) scale(1); }
.toast.exit { opacity: 0; transform: translateY(-14px) scale(.97); }
.toast-success { background: #ecfdf5; color: #047857; }
.toast-error   { background: #fef2f2; color: #b91c1c; }
.toast-warning { background: #fffbeb; color: #b45309; }
.toast-info    { background: #eff6ff; color: #1d4ed8; }
/* error 退场淡出 1s，配合 4s 自动关闭、5s 完全消失 */
.toast-error.exit { transition: opacity 1s var(--ease), transform .3s var(--ease); }
.toast .toast-text { flex: 1; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 8000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(17, 24, 39, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .22s var(--ease);
}
.modal-overlay.show { opacity: 1; }
.modal {
  width: min(92vw, 420px); background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(.96); transition: transform .25s var(--ease);
  overflow: hidden;
}
.modal-overlay.show .modal { transform: none; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-tip { font-size: 14px; color: var(--text-2); margin-bottom: 12px; line-height: 1.7; }
.modal-body .input { margin-top: 4px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg);
}

/* ---------- 滚动条（WebKit） ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: #c9ced8; border-radius: 8px; border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: #aab1bf; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 减少动态效果偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
