/* ===== Web 2FA 全局样式（响应式 + 深色模式） ===== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-secondary: #5c6470;
  --border: #d9dde3;
  --accent: #2f6fed;
  --accent-strong: #1f56c4;
  --danger: #d93025;
  --danger-strong: #a01f16;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2329;
    --text: #e8eaed;
    --text-secondary: #9aa3ad;
    --border: #33383f;
    --accent: #5b8def;
    --accent-strong: #7ba5f5;
    --danger: #f28b82;
    --danger-strong: #f7b3ac;
    --warn: #f5b544;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  min-height: 44px;              /* 移动端触控目标 ≥44px */
}

button:disabled { opacity: .6; cursor: not-allowed; }

input, textarea {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;               /* ≥16px 防 iOS 聚焦自动放大 */
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 44px;
  line-height: 1.5;
}

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

a { color: var(--accent); }

/* ===== 登录页 ===== */

.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px 20px;
}

.login-card h1 { margin: 0 0 2px; font-size: 24px; }
.subtitle { margin: 0 0 20px; color: var(--text-secondary); font-size: 14px; }

.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

.segment {
  flex: 1;
  min-height: 40px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
}

.segment.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--text-secondary); }

.primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.primary:hover { background: var(--accent-strong); }

.alert {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 8px;
  background: rgba(217, 48, 37, .08);
  border: 1px solid rgba(217, 48, 37, .35);
  color: var(--danger);
}

.alert.ban { color: var(--warn); border-color: rgba(180, 83, 9, .4); }

.footnote { margin: 16px 0 0; font-size: 12px; color: var(--text-secondary); text-align: center; }

/* ===== 顶栏 ===== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { margin: 0; font-size: 18px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.lock-timer { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.lock-timer.urgent { color: var(--danger); font-weight: 600; animation: blink 1s infinite; }

@keyframes blink { 50% { opacity: .5; } }

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  min-height: 38px;
  font-size: 14px;
}

.link-btn { font-size: 14px; padding: 8px 12px; color: var(--accent); text-decoration: none; }

/* ===== 验证码网格 ===== */

.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
}

.codes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.empty { color: var(--text-secondary); text-align: center; padding: 48px 16px; }

.code-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.card-title { display: flex; flex-direction: column; min-width: 0; }
.issuer { font-size: 12px; color: var(--text-secondary); }
.label {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 验证码环形进度（conic-gradient，--progress 由 JS 驱动；剩余 ≤5s 时 .urgent 变红） */
.code-progress {
  --progress: 1;
  --ring: var(--accent);
  flex-shrink: 0;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  padding: 5px;
  background: conic-gradient(var(--ring) calc(var(--progress) * 1turn),
                              rgba(127, 127, 127, .18) 0);
}
.code-progress.urgent { --ring: var(--danger); }

.code-progress-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 验证码大字单行（white-space: nowrap 强制不换行；点击可复制） */
.code-text {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: .08em;
  white-space: nowrap;
  cursor: pointer;
  transition: color .2s;
}
.code-text:hover { color: var(--accent); }
/* 剩余 ≤5s 变红（定义在 :hover 之后，红色优先于 hover 色）；
   urgent 悬停变暗红（深色模式反向变亮），给出可点击的视觉提示 */
.code-text.urgent { color: var(--danger); }
.code-text.urgent:hover { color: var(--danger-strong); }

.code-error { font-size: 11px; font-weight: 400; color: var(--danger); }

/* 圆环内剩余秒数（纯数字，随 tick 每秒刷新；≤5s 变红） */
.ring-seconds {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.ring-seconds.urgent { color: var(--danger); font-weight: 700; }

.card-foot { display: flex; align-items: center; justify-content: flex-end; }

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  min-height: 36px;
  font-size: 13px;
}

.copy-btn:active { background: var(--bg); }

.note {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  word-break: break-word;
  white-space: pre-wrap;         /* 备注支持换行（textContent 渲染，无 XSS 风险） */
}

/* 注释卡片（无验证码）的备注：作为卡片主体内容，字号稍大、主色显示 */
.note-only {
  font-size: 15px;
  color: var(--text);
  border-top: none;
  padding-top: 0;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ===== 锁定遮罩 ===== */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.overlay-title { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
.overlay-sub { margin: 0 0 20px; color: var(--text-secondary); font-size: 14px; }

/* ===== 复制成功小弹窗（顶部，进入/退出均有动画） ===== */

.toast {
  position: fixed;
  left: 50%;
  top: calc(56px + env(safe-area-inset-top));   /* 位于 sticky 顶栏之下 */
  transform: translateX(-50%);
  z-index: 200;                 /* 高于锁定遮罩(100) */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 14px;
  padding: 8px 18px;
  pointer-events: none;
  animation: toast-in .25s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 退出动画：JS 加 .toast-out，animationend 后置 hidden */
.toast.toast-out { animation: toast-out .25s ease-in forwards; }

@keyframes toast-out {
  from { opacity: 1; transform: translate(-50%, 0); }
  to   { opacity: 0; transform: translate(-50%, -12px); }
}

/* ===== 管理页 ===== */

.panel, .admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 18px;
}

.panel h2, .admin-section h2 { margin: 0 0 14px; font-size: 16px; }
.panel-sub { margin: 0 0 4px; font-size: 14px; color: var(--text-secondary); }

.stack { display: flex; flex-direction: column; gap: 12px; }

.stack label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.row-actions { display: flex; gap: 10px; align-items: center; }
.row-actions .primary { width: auto; }

.form-msg { margin: 2px 0 0; font-size: 13px; color: var(--text-secondary); }
.form-msg.error { color: var(--danger); }

.admin-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.admin-row-info { min-width: 0; }
.admin-row-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-row-note { font-size: 12px; color: var(--text-secondary); margin-top: 2px; word-break: break-word; white-space: pre-wrap; }
.admin-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.ghost.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-auto { background: rgba(47, 111, 237, .12); color: var(--accent); }
.badge-manual { background: rgba(217, 48, 37, .1); color: var(--danger); }
.badge-ok { background: rgba(24, 160, 88, .12); color: #1a9e5c; }
.badge-fail { background: rgba(217, 48, 37, .1); color: var(--danger); }
.badge-mode { background: rgba(127, 127, 127, .14); color: var(--text-secondary); }

/* 登录日志分页控件 */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 12px;
}
.pager-info { font-size: 13px; color: var(--text-secondary); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ===== 窄屏适配 ===== */

@media (max-width: 480px) {
  .topbar { padding: 8px 12px; }
  .content { padding: 14px 12px calc(24px + env(safe-area-inset-bottom)); }
  .code-card { padding: 14px; }
  .field-row { grid-template-columns: 1fr; }
  .admin-row { flex-direction: column; align-items: stretch; }
  .admin-row-actions { justify-content: flex-end; }
}
