/* ─────────────────────────────────────────────
   MiaoE1 授权文件分发 · 样式

   设计原则：清爽简洁。
   - 浅色为默认，深色跟随系统（prefers-color-scheme），两套主题各自独立取值
   - 全部走语义令牌，页面里不出现硬编码颜色
   - 靠留白和字重建立层级，不靠渐变、发光和大阴影
   - 只有一个强调色，其余都是中性灰
   ───────────────────────────────────────────── */

:root {
  color-scheme: light;

  /* 表面 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;

  /* 描边 */
  --border: #e5e8ed;
  --border-strong: #d3d8e0;

  /* 文字（对比度实测：正文 17.7:1，次要 7.6:1，弱化 4.9:1，均过 WCAG AA） */
  --text: #111827;
  --text-2: #4b5563;
  --muted: #5f6b7f;

  /* 强调色：只有一个 */
  --accent: #2f6bd8;
  --accent-fg: #ffffff;
  --accent-hover: #2557b3;
  --accent-soft: #f4f8ff;
  --accent-ring: rgba(47, 107, 216, .28);

  /* 状态色 */
  --ok: #0b7d5b;
  --ok-soft: #e9f7f1;
  --warn: #a25a06;
  --warn-soft: #fdf5e7;
  --danger: #c3271c;
  --danger-soft: #fdeeed;

  /* 形状 */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", "Microsoft YaHei Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0b0d11;
    --surface: #13161b;
    --surface-2: #191d24;

    --border: #242a33;
    --border-strong: #333b47;

    --text: #e8ecf2;
    --text-2: #b3bccb;
    --muted: #8d97a7;

    --accent: #7aa2ff;
    --accent-fg: #0b0d11;
    --accent-hover: #94b4ff;
    --accent-soft: rgba(122, 162, 255, .12);
    --accent-ring: rgba(122, 162, 255, .3);

    --ok: #4fd1a5;
    --ok-soft: rgba(79, 209, 165, .12);
    --warn: #e0a458;
    --warn-soft: rgba(224, 164, 88, .12);
    --danger: #ff8078;
    --danger-soft: rgba(255, 128, 120, .12);

    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* `hidden` 属性必须真的生效。
   UA 样式表的 [hidden]{display:none} 会被任何作者样式里的 display 覆盖
   （典型受害者：.login-wrap{display:grid} 让已登录的登录框依然显示）。
   这里用 !important 把它钉死，比给每个元素单独写覆盖规则更不容易漏。 */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 2px;
}

a:hover { text-decoration: underline; }

code, .mono {
  font-family: var(--mono);
  font-size: .94em;
  letter-spacing: .01em;
}

/* 焦点环：键盘用户可见，鼠标点击不刺眼 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 布局 ── */
.wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: 56px 20px 72px;
}

.wrap--wide { max-width: 1120px; }

/* ── 品牌头 ── */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 26px;
}

.brand__mark {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.brand__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.35;
}

.brand__sub {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* ── 卡片 ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

.card--tight { padding: 20px; }

.card h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.015em;
  margin: 0 0 6px;
  line-height: 1.4;
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0 0 14px;
}

.card__hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 24px;
}

/* ── 表单 ── */
.field { margin-bottom: 16px; }

.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 7px;
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-family: var(--mono);
  letter-spacing: .06em;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input::placeholder {
  color: var(--muted);
  letter-spacing: 0;
  font-family: inherit;
}

.input:hover { border-color: var(--muted); }

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* 文本类输入用系统字体，只有码类输入用等宽 */
.input--text {
  font-family: inherit;
  letter-spacing: normal;
}

select.input { cursor: pointer; }

/* ── 按钮 ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 14.5px;
  font-weight: 550;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}

.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(.5px); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
}

.btn:disabled:active { transform: none; }

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

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

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

.btn--sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 7px;
}

.btn--danger {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--danger);
}

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

/* ── 提示条 ── */
.msg {
  display: none;
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.55;
  border: 1px solid transparent;
}

.msg.is-shown { display: block; }

.msg--error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.msg--ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.msg--warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

/* ── 顶部悬浮提示（toast） ── */
.toast-layer {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 15px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(16, 24, 40, .16), 0 1px 3px rgba(16, 24, 40, .1);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
  pointer-events: auto;
  cursor: pointer;
  max-width: 520px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease;
}

/* 深色主题下阴影看不见，改用更亮的描边把浮层从背景里摘出来 */
@media (prefers-color-scheme: dark) {
  .toast {
    box-shadow: none;
    border-color: var(--border-strong);
    background: var(--surface-2);
  }
}

.toast.is-shown {
  opacity: 1;
  transform: translateY(0);
}

.toast__mark {
  flex: none;
  width: 17px;
  height: 17px;
  margin-top: 1px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--surface);
  background: var(--ok);
}

.toast--warn .toast__mark { background: var(--warn); }
.toast--error .toast__mark { background: var(--danger); }

.toast--ok { border-color: var(--ok); }
.toast--warn { border-color: var(--warn); }
.toast--error { border-color: var(--danger); }

.toast__text { word-break: break-word; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; transform: none; }
}

/* ── 下载结果 ── */
.result {
  display: none;
  margin-top: 18px;
  padding: 18px;
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  border: 1px solid var(--ok);
}

.result.is-shown { display: block; }

.result__title {
  font-weight: 600;
  font-size: 14px;
  color: var(--ok);
  margin-bottom: 5px;
}

/* 批量生成 500 个码时这一块会撑满整屏，所以限高 + 内部滚动，
   并给一个「收起」按钮，默认展开但用户随时能压回去 */
.result__file {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-2);
  word-break: break-all;
  line-height: 1.7;
  max-height: 148px;
  overflow-y: auto;
  padding-right: 4px;
}

.result__bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.result__hint {
  color: var(--text-2);
  font-size: 12.5px;
  margin: 12px 0 0;
}

.result__action { margin-top: 10px; }

/* ── 三步说明 ── */
.steps {
  list-style: none;
  counter-reset: step;
  margin: 26px 0 0;
  padding: 22px 0 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 28px;
  margin-bottom: 10px;
}

.steps li:last-child { margin-bottom: 0; }

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

.steps strong {
  color: var(--text);
  font-weight: 550;
}

.foot {
  margin-top: 26px;
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

/* ══════════ 管理后台 ══════════ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 11px;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar .brand__mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 14px;
}

.topbar .brand__title { font-size: 14.5px; }

.who {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* 「更新于 HH:MM:SS」：只是给人一个「数据是新的」的信号，弱化处理 */
.refresh-note {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

/* 概览数字：无卡片，靠分隔线 */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.stat {
  background: var(--surface);
  padding: 15px 16px;
}

.stat__label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  white-space: nowrap;
}

.stat__value {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

/* ── 标签页 ── */
.tabs {
  display: flex;
  gap: 22px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab {
  padding: 9px 0 11px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s ease, border-color .15s ease;
}

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

.tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.panel { display: none; }
.panel.is-active { display: block; }

/* ── 工具条 ── */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.toolbar .field { margin-bottom: 0; }

/* 工具条里的按钮要和输入框一样高，否则一排控件参差不齐 */
.toolbar .btn {
  min-height: 40px;
  font-size: 14px;
  padding: 0 15px;
}

.toolbar .input {
  width: auto;
  min-width: 128px;
  max-width: 220px;
  font-family: inherit;
  letter-spacing: normal;
  font-size: 14px;
  min-height: 40px;
  padding: 9px 12px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 14px;
  align-items: end;
}

.grid-form .field { margin-bottom: 0; }

.grid-form .input {
  font-family: inherit;
  letter-spacing: normal;
  font-size: 14px;
  min-height: 40px;
  padding: 9px 12px;
}

.grid-form .btn { min-height: 40px; }

/* ── 表格 ── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

th, td {
  padding: 11px 14px;
  /* 表头表体一律居中：一列里文字忽左忽中看着乱，居中后纵向对齐更整齐 */
  text-align: center;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 550;
  font-size: 12px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: inset 0 -1px 0 var(--border);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* 复选框列：固定窄宽，表头和表体都居中 */
.col-check { width: 40px; }

.row-check,
#codes-check-all {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
  vertical-align: middle;
}

/* ── 批量操作条 ── */
.bulk-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}

.bulk-bar[hidden] { display: none; }

.bulk-bar__count {
  font-size: 13px;
  color: var(--text-2);
  margin-right: 4px;
}

.bulk-bar__count strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }

/* ── 状态徽标 ── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 550;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--active {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: var(--ok);
}

.badge--disabled {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border-strong);
}

.badge--exhausted {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: var(--warn);
}

.badge--unused {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── 分页 ── */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
  flex-wrap: wrap;
}

.pager__btns { display: flex; gap: 8px; }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

/* 间距工具类：只用于几个固定层级，不鼓励随手加 */
.mt-lg { margin-top: 22px; }

/* ── 登录 ── */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-card .brand { margin-bottom: 24px; }

/* ── 弹层 ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  backdrop-filter: blur(2px);
  z-index: 50;
  padding: 24px;
  overflow: auto;
}

.modal.is-shown { display: grid; place-items: center; }

.modal__box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 720px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.modal__box h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}

.modal__meta {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.6;
}

.hex {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.85;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  max-height: 220px;
  overflow: auto;
  color: var(--text-2);
}

.modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}

.modal__box--sm { max-width: 400px; }

.modal__text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-2);
  white-space: pre-line;
}

.modal__box--sm .field { margin: 16px 0 0; }

/* ── Turnstile 人机校验容器 ── */
/* 组件用 size:'flexible' 自适应宽度，这里只负责留位，避免懒加载时按钮跳一下。 */
.turnstile-slot {
  margin-top: 16px;
  min-height: 65px;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.turnstile-slot:empty { min-height: 0; margin-top: 0; }

.turnstile-hint {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
}

/* ── 响应式 ── */
@media (max-width: 620px) {
  .wrap { padding: 32px 16px 56px; }
  .card { padding: 22px 18px; }
  .hide-sm { display: none; }
  .toolbar .input { max-width: none; }
  .modal { padding: 16px; }
  .modal__box { padding: 18px; }
}

/* ── 尊重系统的减少动效偏好 ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .btn:active { transform: none; }
}
