/* ============================================================
   auth.css — 登录 / 注册页共享样式
   设计原则：
   1. CSS 变量集中管理主题色、间距、圆角、阴影
   2. 输入框图标、浮动 label、状态反馈
   3. 按钮加载态、禁用态
   4. 完全响应式（桌面 / 平板 / 移动）
   5. 减少动画（尊重 prefers-reduced-motion）
   ============================================================ */

:root {
  /* 主题色 */
  --auth-primary:        #5b6cff;
  --auth-primary-hover:  #4a5be8;
  --auth-primary-soft:   rgba(91, 108, 255, 0.08);
  --auth-primary-ring:   rgba(91, 108, 255, 0.18);
  --auth-danger:         #ff4d4f;
  --auth-danger-soft:    rgba(255, 77, 79, 0.10);
  --auth-success:        #16a34a;
  --auth-success-soft:   rgba(22, 163, 74, 0.10);
  --auth-warning:        #f59e0b;

  /* 中性色 */
  --auth-text:           #1f2937;
  --auth-text-soft:      #6b7280;
  --auth-text-mute:      #9ca3af;
  --auth-border:         #e5e7eb;
  --auth-border-strong:  #d1d5db;
  --auth-bg:             #f4f6fb;
  --auth-bg-card:        #ffffff;
  --auth-bg-input:       #f9fafb;

  /* 尺寸 */
  --auth-radius:         14px;
  --auth-radius-sm:      8px;
  --auth-radius-pill:    999px;
  --auth-gap:            18px;
  --auth-shadow-card:    0 10px 40px -10px rgba(31, 41, 55, 0.15),
                         0 4px 12px -4px rgba(31, 41, 55, 0.06);
  --auth-shadow-focus:   0 0 0 4px var(--auth-primary-ring);
}

/* ============================================================
   页面容器
   ============================================================ */
.auth-page {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(91, 108, 255, 0.10), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, rgba(22, 163, 74, 0.06), transparent 60%),
    var(--auth-bg);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--auth-bg-card);
  border-radius: var(--auth-radius);
  box-shadow: var(--auth-shadow-card);
  padding: 40px 36px 32px;
  position: relative;
  overflow: hidden;
}

/* 顶部装饰条 */
.auth-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--auth-primary), #8b5cf6, var(--auth-success));
}

/* ============================================================
   头部（图标 + 标题 + 副标题）
   ============================================================ */
.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--auth-radius-pill);
  background: linear-gradient(135deg, var(--auth-primary), #8b5cf6);
  color: #fff;
  box-shadow: 0 8px 24px -8px var(--auth-primary-ring);
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--auth-text);
  margin: 0 0 6px;
  letter-spacing: 0.5px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--auth-text-soft);
  margin: 0;
}

/* ============================================================
   标签切换
   ============================================================ */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--auth-bg-input);
  border-radius: var(--auth-radius);
  padding: 4px;
  margin-bottom: 24px;
  position: relative;
}

.auth-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  border-radius: calc(var(--auth-radius) - 4px);
  font-size: 14px;
  font-weight: 600;
  color: var(--auth-text-soft);
  cursor: pointer;
  transition: all .2s ease;
  user-select: none;
}

.auth-tab:hover {
  color: var(--auth-text);
}

.auth-tab.is-active {
  background: var(--auth-bg-card);
  color: var(--auth-primary);
  box-shadow: 0 2px 8px rgba(31, 41, 55, 0.08);
}

.auth-panel[hidden] { display: none !important; }
.auth-panel.is-active { display: block; animation: fade-in .25s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   字段（form-group）
   ============================================================ */
.field {
  margin-bottom: var(--auth-gap);
}

.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--auth-text);
  margin-bottom: 6px;
}

.label-optional {
  color: var(--auth-text-mute);
  font-weight: 400;
  font-size: 12px;
}

/* ============================================================
   输入框（含图标）
   ============================================================ */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--auth-text-mute);
  transition: color .2s;
}

.input-wrap input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 44px;
  font-size: 15px;
  font-family: inherit;
  color: var(--auth-text);
  background: var(--auth-bg-input);
  border: 1.5px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
  -webkit-appearance: none;
  appearance: none;
}

/* 浮动 label 效果：用 placeholder=" " 占位 */
.input-wrap input::placeholder { color: transparent; }
.input-wrap input:focus::placeholder { color: var(--auth-text-mute); }

.input-wrap input:hover:not(:focus):not(:disabled) {
  border-color: var(--auth-border-strong);
}

.input-wrap input:focus {
  border-color: var(--auth-primary);
  background: var(--auth-bg-card);
  box-shadow: var(--auth-shadow-focus);
}

.input-wrap input:focus ~ .input-icon,
.input-wrap input:focus + .input-icon {
  color: var(--auth-primary);
}

/* 字段状态 */
.field.has-success .input-wrap input { border-color: var(--auth-success); }
.field.has-success .input-icon       { color: var(--auth-success); }

.field.has-error .input-wrap input {
  border-color: var(--auth-danger);
  background: var(--auth-danger-soft);
}
.field.has-error .input-icon { color: var(--auth-danger); }

/* 错误抖动 */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
.field.has-error .input-wrap { animation: shake .35s ease; }

/* ============================================================
   密码显隐切换按钮
   ============================================================ */
.pwd-toggle {
  position: absolute;
  right: 10px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--auth-text-mute);
  cursor: pointer;
  border-radius: 6px;
  transition: background .2s, color .2s;
}

.pwd-toggle:hover {
  color: var(--auth-text);
  background: rgba(31, 41, 55, 0.05);
}

.pwd-toggle:focus-visible {
  outline: 2px solid var(--auth-primary);
  outline-offset: 1px;
}

/* ============================================================
   行布局：输入框 + 按钮
   ============================================================ */
.row-input-btn {
  display: flex;
  gap: 10px;
}

.row-input-btn .input-wrap { flex: 1; min-width: 0; }
.row-input-btn .btn { flex-shrink: 0; }

/* ============================================================
   字段消息
   ============================================================ */
.field-msg {
  font-size: 12px;
  line-height: 1.5;
  min-height: 18px;
  margin-top: 6px;
  color: var(--auth-text-mute);
  transition: color .2s;
}

.field-msg.success { color: var(--auth-success); }
.field-msg.error   { color: var(--auth-danger); }

/* ============================================================
   图形验证码
   ============================================================ */
.captcha-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.captcha-row .input-wrap { flex: 1; min-width: 0; }

.captcha-img {
  height: 48px;
  width: 110px;
  flex-shrink: 0;
  border: 1.5px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  cursor: pointer;
  background: var(--auth-bg-input);
  object-fit: contain;
  transition: border-color .2s, transform .2s;
}

.captcha-img:hover {
  border-color: var(--auth-primary);
  transform: scale(1.02);
}

.captcha-img:focus-visible {
  outline: 2px solid var(--auth-primary);
  outline-offset: 2px;
}

/* ============================================================
   记住我 / 复选框
   ============================================================ */
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.hint {
  font-size: 12px;
  color: var(--auth-text-mute);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--auth-text);
  cursor: pointer;
  user-select: none;
}

.checkbox input { position: absolute; opacity: 0; pointer-events: none; }

.checkbox-mark {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--auth-border-strong);
  border-radius: 4px;
  background: var(--auth-bg-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
}

.checkbox input:checked + .checkbox-mark {
  background: var(--auth-primary);
  border-color: var(--auth-primary);
}

.checkbox input:checked + .checkbox-mark::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.checkbox input:focus-visible + .checkbox-mark {
  box-shadow: 0 0 0 3px var(--auth-primary-ring);
}

/* ============================================================
   按钮
   ============================================================ */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 48px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  border-radius: var(--auth-radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  outline: 2px solid var(--auth-primary);
  outline-offset: 2px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--auth-primary), #4a5be8);
  color: #fff;
  box-shadow: 0 4px 14px -4px var(--auth-primary-ring);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--auth-primary-hover), #3d4ed4);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px -6px var(--auth-primary-ring);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px -2px var(--auth-primary-ring);
}

.btn-outline {
  background: var(--auth-bg-card);
  color: var(--auth-primary);
  border-color: var(--auth-primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--auth-primary-soft);
}

.btn-outline:disabled {
  background: var(--auth-bg-input);
  color: var(--auth-text-mute);
  border-color: var(--auth-border);
}

/* 加载 spinner */
.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.btn.is-loading .btn-spinner { display: inline-block; }
.btn.is-loading .btn-text    { opacity: .85; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   密码强度
   ============================================================ */
.strength {
  height: 4px;
  background: var(--auth-bg-input);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.strength-bar {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width .3s, background .3s;
  background: var(--auth-danger);
}

.pwd-rules {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--auth-text-mute);
}

.pwd-rules .rule {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pwd-rules .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--auth-border-strong);
  display: inline-block;
  transition: background .2s;
}

.pwd-rules .rule.valid { color: var(--auth-success); }
.pwd-rules .rule.valid .dot { background: var(--auth-success); }

/* ============================================================
   分割线 + 第三方登录
   ============================================================ */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 24px 0 16px;
  color: var(--auth-text-mute);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--auth-border);
}

.divider span {
  padding: 0 12px;
}

.oauth-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.oauth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  border: 1.5px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  background: var(--auth-bg-card);
  color: var(--auth-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all .2s;
}

.oauth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(31, 41, 55, 0.12);
}

.oauth-btn[data-provider="github"]:hover { color: #24292e; border-color: #24292e; }
.oauth-btn[data-provider="qq"]:hover     { color: #12b7f5; border-color: #12b7f5; }
.oauth-btn[data-provider="wechat"]:hover { color: #07c160; border-color: #07c160; }

/* ============================================================
   底部链接
   ============================================================ */
.auth-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--auth-text-soft);
}

.auth-footer a {
  color: var(--auth-primary);
  text-decoration: none;
  font-weight: 600;
  transition: color .2s;
}

.auth-footer a:hover {
  color: var(--auth-primary-hover);
  text-decoration: underline;
}

/* ============================================================
   Toast（全局轻提示）
   ============================================================ */
.auth-toast-host {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.auth-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--auth-radius-pill);
  background: rgba(31, 41, 55, 0.92);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px -8px rgba(31, 41, 55, 0.4);
  backdrop-filter: blur(8px);
  animation: toast-in .3s ease;
}

.auth-toast.success { background: rgba(22, 163, 74, 0.95); }
.auth-toast.error   { background: rgba(255, 77, 79, 0.95); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   响应式
   ============================================================ */

/* 平板 */
@media (max-width: 768px) {
  .auth-page  { padding: 32px 16px; }
  .auth-card  { padding: 32px 24px 24px; }
  .auth-header h1 { font-size: 22px; }
}

/* 手机 */
@media (max-width: 480px) {
  .auth-page  { padding: 24px 12px; min-height: calc(100vh - 60px); }
  .auth-card  { padding: 28px 20px 20px; border-radius: 12px; }
  .auth-header { margin-bottom: 20px; }
  .auth-icon   { width: 56px; height: 56px; margin-bottom: 12px; }
  .auth-header h1 { font-size: 20px; }
  .auth-subtitle { font-size: 13px; }

  .field       { margin-bottom: 14px; }
  .input-wrap input { height: 44px; font-size: 14px; padding: 0 14px 0 40px; }
  .input-icon  { left: 12px; }

  .btn         { height: 44px; font-size: 14px; padding: 0 14px; }
  .captcha-img { width: 100px; height: 44px; }

  .row-input-btn { flex-direction: column; gap: 8px; }
  .row-input-btn .btn { width: 100%; }

  .captcha-row { flex-direction: column; gap: 8px; }
  .captcha-row .captcha-img { width: 100%; height: 44px; }

  .oauth-row { grid-template-columns: 1fr; gap: 8px; }
  .oauth-btn { height: 42px; }

  .pwd-rules  { grid-template-columns: 1fr; }

  .auth-tab    { padding: 8px 10px; font-size: 13px; }
  .auth-tab span { display: none; }
  .auth-tab    { gap: 0; }
}

/* ============================================================
   减弱动画偏好
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
