/* 设计令牌：后续所有页面只用这些变量，换肤只改这一段 */
:root {
  --bg: #0f1218;
  --panel: #171c26;
  --panel-hover: #1d2330;
  --border: #262e3d;
  --text: #e4e8f0;
  --muted: #8b94a7;
  --accent: #5b9dff;
  --accent-strong: #3b82f6;
  --cat-1: #38bdf8; /* 视频 */
  --cat-2: #a78bfa; /* 音频 */
  --cat-3: #34d399; /* 文档 */
  --cat-4: #fbbf24; /* 软件 */
  --cat-0: #9aa4b2; /* 其他 */
  --radius: 8px;
  font-size: 15px;
}

/* 主题预设：dark 即 :root 默认；其余经 <body> class 覆盖全套变量（前台生效，
   后台 admin_layout 无 class 恒为 dark）。变量沿 DOM 继承，body 级覆盖即全页生效。 */
body.theme-light {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-hover: #eceff4;
  --border: #d6dde6;
  --text: #1b2330;
  --muted: #5d6a7d;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  /* 浅色下分类徽章用深色变体保证对比度 */
  --cat-1: #0277bd;
  --cat-2: #7c3aed;
  --cat-3: #047857;
  --cat-4: #b45309;
  --cat-0: #64748b;
}

body.theme-midnight {
  --bg: #000000;
  --panel: #0b0b0e;
  --panel-hover: #16161c;
  --border: #2b2b36;
  --text: #f4f6fa;
  --muted: #a0a8ba;
  --accent: #86b8ff;
  --accent-strong: #5b9dff;
  --cat-1: #5cd3ff;
  --cat-2: #c4b0ff;
  --cat-3: #56e3b0;
  --cat-4: #ffd06b;
  --cat-0: #b0bac9;
}

body.theme-forest {
  --bg: #0d1512;
  --panel: #14201a;
  --panel-hover: #1a2821;
  --border: #27392f;
  --text: #e4ede7;
  --muted: #8ea698;
  --accent: #4ade80;
  --accent-strong: #22c55e;
  --cat-1: #38bdf8;
  --cat-2: #a78bfa;
  --cat-3: #4ade80;
  --cat-4: #fbbf24;
  --cat-0: #9db3a7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

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

.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- 头部 ---------- */
.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.logo span { color: var(--accent); }
.logo:hover { text-decoration: none; }

.search {
  display: flex;
  flex: 1;
  max-width: 560px;
}

.search input {
  flex: 1;
  padding: 8px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  outline: none;
}
.search input:focus { border-color: var(--accent-strong); }

.search button {
  padding: 8px 18px;
  color: #fff;
  background: var(--accent-strong);
  border: 1px solid var(--accent-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
}
.search button:hover { filter: brightness(1.1); }

.site-nav {
  display: flex;
  gap: 4px;
  padding-bottom: 10px;
  overflow-x: auto;
}
.site-nav a {
  padding: 4px 12px;
  color: var(--muted);
  border-radius: 999px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.site-nav a:hover {
  color: var(--text);
  background: var(--panel-hover);
  text-decoration: none;
}

/* ---------- 内容 ---------- */
.page-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 20px 0 12px;
}
.page-head h1 { margin: 0; font-size: 1.15rem; }

.torrent-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
/* border-radius 对 table 不生效的兼容 */
.torrent-table { border-style: hidden; box-shadow: 0 0 0 1px var(--border); }

.torrent-table th {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.torrent-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.torrent-table tbody tr:last-child td { border-bottom: none; }
.torrent-table tbody tr:hover { background: var(--panel-hover); }

.col-name { min-width: 0; }
.col-name .name {
  display: block;
  max-width: 52ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.col-name .hash {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.col-size, .col-files { width: 1%; }
.col-time { width: 1%; color: var(--muted); font-size: 0.85rem; }
.col-time time { color: var(--muted); }
.col-cat { width: 1%; }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.badge.cat-1 { color: var(--cat-1); background: color-mix(in srgb, var(--cat-1) 14%, transparent); }
.badge.cat-2 { color: var(--cat-2); background: color-mix(in srgb, var(--cat-2) 14%, transparent); }
.badge.cat-3 { color: var(--cat-3); background: color-mix(in srgb, var(--cat-3) 14%, transparent); }
.badge.cat-4 { color: var(--cat-4); background: color-mix(in srgb, var(--cat-4) 14%, transparent); }
.badge.cat-0, .badge { color: var(--cat-0); background: color-mix(in srgb, var(--cat-0) 14%, transparent); }

.empty {
  padding: 48px 0;
  text-align: center;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty p { margin: 4px 0; }

/* ---------- 页脚 ---------- */
.site-footer {
  margin-top: 32px;
  border-top: 1px solid var(--border);
  padding: 16px 0 28px;
  font-size: 0.82rem;
  color: var(--muted);
}
.site-footer .wrap { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

/* ---------- 窄屏（≤720px，前台移动端；管理后台是桌面工具，不在此适配） ---------- */
@media (max-width: 720px) {
  /* 头部：logo 与搜索框分两行，搜索框/按钮加大触控高度（≥44px） */
  .header-inner { flex-wrap: wrap; gap: 10px; padding-top: 10px; padding-bottom: 10px; }
  .search { flex-basis: 100%; max-width: none; order: 2; }
  .search input, .search button { min-height: 44px; padding: 10px 14px; font-size: 1rem; }

  /* 分类导航横向可滚动，触控目标加大 */
  .site-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
  .site-nav a { padding: 8px 14px; font-size: 0.95rem; }

  /* 列表转卡片：每行一张块级卡片（名称最多两行截断，meta 第二行小字横排，
     隐藏 hash 副行；表头隐藏）。只作用于前台 list-table，后台表格不动。 */
  .list-table { background: transparent; border: none; box-shadow: none; }
  .list-table thead { display: none; }
  .list-table, .list-table tbody, .list-table tr { display: block; }
  .list-table tbody tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 10px 12px;
  }
  .list-table tbody tr:hover { background: var(--panel); }
  .list-table td { display: inline; padding: 0; border: none; font-size: 0.8rem; color: var(--muted); }
  .list-table td + td { margin-left: 12px; }
  .list-table td.col-name { display: block; margin: 0 0 6px; }
  .list-table td[data-th]::before { content: attr(data-th) "\00a0"; }
  .list-table .col-name .name {
    max-width: none;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.95rem;
  }
  .list-table .col-name .hash { display: none; }
  /* 广告行保持整行块级 */
  .list-table tr.ad-row { background: transparent; border: none; padding: 4px 0; }
  .list-table tr.ad-row td { display: block; margin: 0; }

  /* 分页：页码/按钮触控区加大、间距拉开 */
  .pagination { gap: 10px; flex-wrap: wrap; }
  .pagination a, .pagination .page-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 14px;
  }

  /* 详情页：meta 单列；文件路径允许换行 */
  .meta-list { grid-template-columns: 1fr; gap: 2px 0; }
  .meta-list dt { margin-top: 8px; }
  .meta-list dd { margin-bottom: 4px; }
  .file-table .path { white-space: normal; word-break: break-all; }
}

/* ---------- 分页 ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px 0;
}
.pagination a {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pagination a:hover {
  background: var(--panel-hover);
  text-decoration: none;
}

/* ---------- 详情页 ---------- */
.detail-name {
  font-size: 1.3rem;
  word-break: break-all;
  margin: 20px 0 12px;
}

.detail h2 {
  font-size: 1rem;
  margin: 24px 0 10px;
}

.meta-list {
  display: grid;
  grid-template-columns: 6em 1fr;
  gap: 6px 16px;
  margin: 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; word-break: break-all; }

.hash-full {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  user-select: all;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-style: hidden;
  box-shadow: 0 0 0 1px var(--border);
  border-radius: var(--radius);
}
.file-table th {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.file-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.file-table tbody tr:last-child td { border-bottom: none; }
.file-table .path { word-break: break-all; font-size: 0.9rem; }

.risk {
  display: inline-block;
  margin-left: 8px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  color: #f87171;
  background: color-mix(in srgb, #f87171 14%, transparent);
}

/* ---------- 详情页操作区 ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 14px 0 4px;
}

.magnet-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 280px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.magnet-uri {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-hover); text-decoration: none; }
.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); background: var(--accent-strong); }

/* ---------- 图片网格 ---------- */
.image-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.image-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--bg);
}
.image-pending {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--bg);
}
.image-caption {
  padding: 7px 10px;
  font-size: 0.8rem;
}
.image-caption .path {
  display: block;
  word-break: break-all;
}
.col-seed { width: 1%; color: var(--muted); }

/* ---------- 管理后台 ---------- */
.admin-nav {
  margin-left: auto;
  padding-bottom: 0;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form { display: inline; }

.admin-form {
  display: grid;
  gap: 12px;
  max-width: 480px;
  margin: 16px 0;
}
.admin-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}
.admin-form input,
.admin-form select,
.admin-form textarea {
  padding: 8px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus { border-color: var(--accent-strong); outline: none; }
.admin-form button { justify-self: start; }

.admin-search { max-width: 560px; margin: 12px 0 16px; }

.ops { white-space: nowrap; }
.ops form { display: inline; }
.ops .btn { padding: 3px 10px; font-size: 0.8rem; }

/* 条目页批量操作栏与勾选列 */
.batch-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.batch-bar select {
  padding: 6px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.88rem;
}
.col-check { width: 1%; }
.col-check input { width: 16px; height: 16px; vertical-align: middle; }

.detail-cell { word-break: break-all; max-width: 32ch; font-size: 0.88rem; }

.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0 24px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 240px;
}
.stat-card h2 { margin: 0 0 8px; font-size: 0.95rem; }
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table td { padding: 3px 8px 3px 0; }
.mini-table td.num { text-align: right; }

h2 { font-size: 1rem; }

.pagination .page-num, .pagination .page-current {
  display: inline-block;
  min-width: 2em;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.pagination .page-num:hover { background: var(--panel-hover); text-decoration: none; }
.pagination .page-current {
  background: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}

/* ---------- 条目管理：状态标签与筛选 ---------- */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 12px 0 4px;
}
.tabs .tab {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.tabs .tab:hover { color: var(--text); background: var(--panel-hover); text-decoration: none; }
.tabs .tab.active {
  color: var(--text);
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}
.tabs .tab .num { font-size: 0.78rem; opacity: 0.8; }

.admin-search select {
  padding: 8px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: none;
}
.admin-search input { border-radius: var(--radius) 0 0 var(--radius); }

.notice {
  padding: 8px 14px;
  border: 1px solid var(--cat-3);
  border-radius: var(--radius);
  color: var(--cat-3);
  background: color-mix(in srgb, var(--cat-3) 10%, transparent);
  display: inline-block;
}

.settings-cats {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: grid;
  gap: 8px;
}
.settings-cats legend { color: var(--muted); font-size: 0.85rem; padding: 0 6px; }
.settings-cats .check { display: flex; align-items: center; gap: 8px; color: var(--text); }

/* ---------- 广告位 ---------- */
.ad { margin-top: 8px; margin-bottom: 8px; }
.ad-header { padding-top: 8px; }
.ad-footer { margin-bottom: 12px; }
.ad-inline { padding: 4px 0; }
.ad-row td { background: var(--bg); }

/* ---------- 分类/广告管理表格内嵌输入 ---------- */
.cell-input {
  width: 100%;
  padding: 4px 8px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85rem;
}
.cell-num { width: 5.5em; }
.admin-cat-form { max-width: 480px; }

/* ---------- 合规静态页 ---------- */
.static-page { max-width: 760px; margin: 20px auto 0; }
.static-page h1 { font-size: 1.3rem; margin: 0 0 4px; }
.static-page h2 { font-size: 1.02rem; margin: 22px 0 8px; }
.static-page p { margin: 8px 0; }
.static-page ul, .static-page ol { margin: 8px 0; padding-left: 22px; }
.static-page li { margin: 4px 0; }

/* ---------- 语言切换器 ---------- */
.lang-switch {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- 广告位 ---------- */
.ad-slot { margin: 12px 0; }

/* 演示广告样式（真实广告可在后台直接用这些 class 或自行扩展） */
.ad-demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, #1d2b4f, #2b4a7f);
  border: 1px solid var(--border);
}
.ad-demo-banner .ad-title { font-size: 1.05rem; font-weight: 700; color: #fff; }
.ad-demo-banner .ad-sub { font-size: 0.85rem; color: #b8c6e0; margin-top: 2px; }
.ad-demo-banner .ad-cta {
  padding: 8px 20px;
  border-radius: 6px;
  background: var(--accent-strong);
  color: #fff;
  font-size: 0.9rem;
  white-space: nowrap;
}
.ad-demo-banner .ad-cta:hover { text-decoration: none; filter: brightness(1.15); }

.ad-demo-inline {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
}
.ad-demo-inline .ad-tag {
  flex: none;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
}
.ad-demo-inline .ad-text { font-size: 0.92rem; color: var(--text); }
.ad-demo-inline .ad-link { font-size: 0.88rem; white-space: nowrap; }

.ad-demo-footer {
  text-align: center;
  padding: 12px;
  font-size: 0.88rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- 分类多语言字段 / 静态页管理 ---------- */
.i18n-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.i18n-grid label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; }
.i18n-cell { min-width: 220px; }
.i18n-cell .cell-input { margin: 1px 0; width: 9em; }
.page-select { display: flex; gap: 16px; }
.page-select label { display: grid; gap: 4px; color: var(--muted); font-size: 0.9rem; }

/* ---------- 站点 Logo / 首页副标题 ---------- */
.logo-img { height: 28px; width: auto; display: block; }
.logo-preview { background: var(--bg); padding: 4px; border: 1px solid var(--border); border-radius: 4px; }
.slogan { font-size: 0.9rem; }
.ad-detail { margin: 14px 0 4px; }

/* ---------- 首页精选区块 ---------- */
.featured { margin-bottom: 20px; }
.featured-title { font-size: 1rem; margin: 0 0 8px; }

/* ---------- 监控页 ---------- */
.stat-num { margin: 0; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card.alert-red { border-color: #f87171; }
.stat-card.alert-red .stat-num, .stat-card.alert-red h2 { color: #f87171; }
.stat-card.alert-yellow { border-color: var(--cat-4); }
.stat-card.alert-yellow .stat-num, .stat-card.alert-yellow h2 { color: var(--cat-4); }
.worker-fold { margin: 8px 0; }
.worker-fold summary { cursor: pointer; color: var(--muted); padding: 6px 2px; }
.worker-fold summary:hover { color: var(--text); }
.badge-red { color: #f87171; background: color-mix(in srgb, #f87171 14%, transparent); }
.cursor-kv {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin: 1px 2px 1px 0;
}
.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chart .bar {
  flex: 1;
  min-height: 2px;
  background: var(--accent-strong);
  border-radius: 2px 2px 0 0;
}
.chart .bar:hover { filter: brightness(1.25); }

/* ---------- 语言过滤提示条 ---------- */
.lang-notice {
  margin: 0 0 10px;
  padding: 8px 14px;
  font-size: 0.88rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
