/* ==========================================================================
   资料库管理后台样式
   纯 CSS，无依赖。配色跟随系统浅色主题。
   ========================================================================== */

:root {
  --brand: #2b6cff;
  --brand-dark: #1a52d6;
  --brand-soft: #eef3ff;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;

  --text: #1c1f26;
  --text-2: #5a6068;
  --text-3: #8a8f99;

  --ok: #22a06b;
  --ok-soft: #e8f8f1;
  --warn: #b26a00;
  --warn-soft: #fff5e0;
  --danger: #e8453c;
  --danger-soft: #fdeceb;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 1px 2px rgba(20, 30, 60, 0.04);
  --shadow-lg: 0 10px 30px rgba(20, 30, 60, 0.14);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.35; }

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

code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: 'SFMono-Regular', Consolas, monospace;
}

.muted { color: var(--text-3); }

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

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef3ff 0%, #f5f6f8 55%, #eaf6f1 100%);
  padding: 24px;
}

.login-wrap { width: 100%; max-width: 420px; }

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 28px;
}

.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }

.login-logo {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #4a9dff);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand h1 { font-size: 19px; }
.login-brand p { margin: 2px 0 0; font-size: 13px; color: var(--text-3); }

.login-foot {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
}

/* ============================ 表单 ============================ */

.field { display: block; margin-bottom: 18px; }

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

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='url'],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { resize: vertical; min-height: 90px; line-height: 1.65; }

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 108, 255, 0.13);
}

input::placeholder,
textarea::placeholder { color: #b0b5bd; }

.field-row { display: flex; gap: 16px; }
.field-row > .field { flex: 1; }

/* ============================ 按钮 ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

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

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #cf3a32; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ============================ 布局 ============================ */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #4a9dff);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-spacer { flex: 1; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-2);
}

.container { max-width: 1240px; margin: 0 auto; padding: 24px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-spacer { flex: 1; }

.search-box { position: relative; width: 260px; }
.search-box input { padding-left: 34px; }
.search-box::before {
  content: '⌕';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--text-3);
  pointer-events: none;
}

/* ============================ 卡片 / 表格 ============================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-head h2 { font-size: 15px; }
.card-head-spacer { flex: 1; }
.card-body { padding: 22px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.cell-title { font-weight: 500; max-width: 320px; }
.cell-title .sub {
  display: block;
  font-weight: 400;
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions .btn + .btn { margin-left: 6px; }

/* 卡密列表里的卡密列：等宽字体，便于逐字符核对 */
.cell-code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  font-weight: 500;
  max-width: 260px;
  word-break: break-all;
  color: #1c1f26;
}

/* ============================ 顶部导航 ============================ */

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
}

.nav-link {
  padding: 6px 14px;
  font-size: 13.5px;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 500;
}

/* ============================ 标签 ============================ */

.tag {
  display: inline-block;
  padding: 2px 9px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.tag-brand { background: var(--brand-soft); color: var(--brand); border-color: #d6e2ff; }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: #cdeee1; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: #ffe4b3; }
.tag-danger { background: var(--danger-soft); color: var(--danger); border-color: #fbd5d2; }

/* ============================ 状态提示 ============================ */

.form-error,
.form-ok {
  margin-top: 14px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}
.form-error { background: var(--danger-soft); color: #a32b24; border: 1px solid #f8cdc9; }
.form-ok { background: var(--ok-soft); color: #16794f; border: 1px solid #bfe8d6; }

.empty-state { padding: 70px 24px; text-align: center; color: var(--text-3); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state .title { font-size: 15px; color: var(--text-2); margin-bottom: 6px; }

.loading-state { padding: 50px; text-align: center; color: var(--text-3); font-size: 13.5px; }

/* ============================ 弹窗 ============================ */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 40, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  z-index: 100;
}

/* 关键：hidden 属性必须压过上面的 display:flex，
   否则"隐藏"的弹窗仍然铺满全屏、挡住底下所有点击 */
.modal-mask[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  margin: auto;
  animation: modalIn 0.16s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.modal-head h2 { font-size: 16px; flex: 1; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 24px; }
.modal-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #fafbfc;
  border-radius: 0 0 12px 12px;
}

/* ============================ 上传控件 ============================ */

.upload-box {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 18px;
  background: #fafbfc;
  transition: border-color 0.15s, background 0.15s;
}
.upload-box:hover { border-color: var(--brand); background: var(--brand-soft); }

.upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.upload-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.upload-file-info .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cover-preview {
  margin-top: 12px;
  max-width: 180px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

/* 进度条 */
.progress {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar {
  height: 100%;
  background: var(--brand);
  width: 0;
  transition: width 0.2s;
}

/* ============================ 分页 ============================ */

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  padding: 18px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}

/* ============================ 提示条 ============================ */

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 18px;
}
.notice-warn { background: var(--warn-soft); border: 1px solid #ffe4b3; color: #8a5200; }
.notice-info { background: var(--brand-soft); border: 1px solid #d6e2ff; color: #1a4bb8; }

/* 隐藏文件输入，用按钮触发 */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .container { padding: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-box { width: 100%; }
  .field-row { flex-direction: column; gap: 0; }
  .topbar-inner { padding: 0 16px; }
  .topbar-title { display: none; }
}

/* ============================ 全局设置页 ============================ */

/* 危险提示条：免费模式开启时常驻，用红色确保不会被忽略 */
.notice-danger {
  background: var(--danger-soft);
  border: 1px solid #f8cdc9;
  color: #a32b24;
  align-items: flex-start;
}
.notice-danger strong { white-space: nowrap; }

/* 设置行：左侧说明 + 右侧开关 */
.setting-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 4px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.setting-main { flex: 1; min-width: 0; }
.setting-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}
.setting-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
}

/* ---- 开关（纯 CSS，无第三方依赖）---- */
.switch {
  flex: none;
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  display: block;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #cfd4dc;
  transition: background 0.18s;
  position: relative;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 30, 60, 0.28);
  transition: transform 0.18s;
}
/* 开启态用红色而不是绿色：这是个"需要尽快关掉"的开关，
   视觉上要和普通的"启用"区分开，减少忘记关闭的概率 */
.switch input:checked + .switch-track { background: var(--danger); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(22px); }
.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px rgba(43, 108, 255, 0.2);
}

/* 用途说明块 */
.usage-hint {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.usage-hint-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
}
.usage-hint ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.85;
}
.usage-hint li + li { margin-top: 6px; }

/* ---- 广告位配置步骤条 ---- */
.adstep {
  display: flex;
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}
.adstep:last-child { border-bottom: none; padding-bottom: 0; }
.adstep-num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.adstep-body { flex: 1; min-width: 0; }
.adstep-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
}
.adstep-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.75;
}

.codeblock {
  margin: 10px 0 0;
  padding: 14px 16px;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: #1c1f26;
  overflow-x: auto;
  white-space: pre;
}
