:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e3e8ef;
  --text: #1f2933;
  --text-soft: #6b7280;
  --primary: #2563eb;
  --primary-soft: #eaf1ff;
  --accent: #d9264f;
  --tag-math: #2563eb;
  --tag-other: #0f9d8b;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 700; }
.brand-text p { margin: 0; font-size: 12px; color: var(--text-soft); }

.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.search-box input {
  width: 240px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fbfcfe;
}
.search-box input:focus { border-color: var(--primary); background: #fff; }

.tabs { display: flex; gap: 4px; background: #eef2f7; padding: 4px; border-radius: 9px; }
.tab {
  border: none; background: transparent;
  padding: 7px 14px; border-radius: 7px;
  font-size: 14px; cursor: pointer; color: var(--text-soft);
  font-weight: 600;
}
.tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

/* ---------- 布局 ---------- */
.view { display: none; }
.view.active { display: block; }

#view-browse {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

/* ---------- 统一筛选栏（年级 + 学科）---------- */
.filter-banner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.filter-banner-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.filter-banner-text { display: flex; flex-direction: column; gap: 2px; }
.filter-banner-text strong { font-size: 15px; color: var(--text); }
.filter-banner-text span { font-size: 12px; color: var(--text-soft); }
.filter-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.filter-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  min-width: 72px;
  flex: none;
}
.grade-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.grade-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  min-width: 76px;
}
.grade-btn:hover { border-color: var(--primary); color: var(--primary); }
.grade-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .3);
}

.subject-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.subject-btn:hover { border-color: #16a34a; color: #16a34a; }
.subject-btn.active {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
  box-shadow: 0 2px 8px rgba(22, 163, 74, .3);
}

.browse-body {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 20px;
  align-items: start;
}

/* ---------- 侧栏筛选 ---------- */
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 80px;
}
.filter-block { margin-bottom: 16px; }
.filter-title {
  font-size: 12px; font-weight: 700; color: var(--text-soft);
  text-transform: none; margin-bottom: 8px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); }
.chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.clear-btn {
  width: 100%;
  border: 1px dashed var(--border);
  background: #fff;
  color: var(--text-soft);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.clear-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- 内容区 ---------- */
.content-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.result-count { font-size: 13px; color: var(--text-soft); }
.sort-select {
  padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; font-size: 13px; cursor: pointer;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.paper-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.paper-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(16,24,40,.12); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-school { font-weight: 700; font-size: 14px; }
.card-group {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: #eef2f7; color: var(--text-soft); white-space: nowrap;
}
.card-name { font-size: 13.5px; color: var(--text); line-height: 1.5; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11.5px; padding: 2px 8px; border-radius: 6px;
  background: #f1f5f9; color: var(--text-soft);
}
.tag.math { background: #eaf1ff; color: var(--tag-math); font-weight: 600; }
.tag.exam { background: #fef3e2; color: var(--warn); }
.tag.term { background: #eafaf3; color: var(--tag-other); }
.status {
  font-size: 11.5px; padding: 2px 8px; border-radius: 6px; font-weight: 600;
}
.status.待上传 { background: #fef2f2; color: var(--accent); }
.status.已上线 { background: #ecfdf3; color: var(--ok); }
.status.暂缺 { background: #f1f5f9; color: var(--text-soft); }
.card-bottom { margin-top: auto; display: flex; gap: 8px; align-items: center; }
.download-btn {
  flex: 1;
  text-align: center;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
  padding: 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.download-btn:hover { background: #1d4ed8; }
.download-btn.disabled {
  background: #eef2f7; color: var(--text-soft); cursor: not-allowed;
}
.card-note { font-size: 11.5px; color: var(--text-soft); }

/* ---------- 台账 ---------- */
.ledger-content { max-width: 960px; margin: 0 auto; padding: 20px; }
.ledger-head h2 { margin: 0 0 4px; font-size: 18px; }
.ledger-tip { margin: 0 0 12px; font-size: 12.5px; color: var(--text-soft); }
.ledger-progress {
  height: 10px; background: #e9eef5; border-radius: 20px; overflow: hidden; margin-bottom: 18px;
}
.ledger-progress > span {
  display: block; height: 100%; background: linear-gradient(90deg, #16a34a, #22c55e);
  width: 0%; transition: width .3s;
}
.ledger-group { margin-bottom: 22px; }
.ledger-group-title {
  font-size: 14px; font-weight: 700; margin-bottom: 10px;
  padding-left: 10px; border-left: 4px solid var(--primary);
}
.ledger-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px; margin-bottom: 8px;
}
.ledger-item input { width: 17px; height: 17px; cursor: pointer; flex: none; }
.ledger-item.checked .ledger-item-name { text-decoration: line-through; color: var(--text-soft); }
.ledger-item-name { flex: 1; font-size: 13.5px; }
.ledger-item-meta { font-size: 11.5px; color: var(--text-soft); white-space: nowrap; }

/* ---------- 时间轴（泳道） ---------- */
.timeline-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}
.timeline-tip {
  font-size: 12.5px;
  color: var(--text-soft);
}
.timeline-grid {
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  padding: 1px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}
.tl-corner,
.tl-head {
  background: #f8fafc;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tl-corner {
  left: 0;
  z-index: 3;
  text-align: left;
  min-width: 160px;
}
.tl-head { min-width: 170px; }
.tl-head-unknown { color: var(--text-soft); background: #f1f5f9; }

.tl-school {
  background: var(--panel);
  padding: 14px;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  position: sticky;
  left: 0;
  z-index: 1;
}
.tl-cell {
  background: var(--panel);
  padding: 10px;
  min-height: 90px;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tl-cell-unknown { background: #fbfcfe; }
.tl-empty {
  flex: 1;
  min-height: 30px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px dashed var(--border);
}
.tl-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 132px;
}
.tl-card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tl-card-name {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  min-height: calc(13px * 1.45 * 3);
  max-height: calc(13px * 1.45 * 3);
}
.tl-dl {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
}
.tl-dl:hover { background: #1d4ed8; }
.tl-dl.disabled {
  background: #eef2f7;
  color: var(--text-soft);
  cursor: not-allowed;
}

/* ---------- 管理员模式 ---------- */
.admin-area {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.admin-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-soft);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.admin-btn:hover { border-color: var(--primary); color: var(--primary); }
.admin-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.admin-btn.primary:hover { background: #1d4ed8; }
.admin-btn.ghost { background: transparent; color: var(--text-soft); }
.admin-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: var(--shadow);
}
.admin-panel input {
  width: 130px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.admin-panel input:focus { border-color: var(--primary); }
.admin-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.admin-logout {
  border: none;
  background: rgba(255, 255, 255, .25);
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.admin-logout:hover { background: rgba(255, 255, 255, .4); }
.badge-title { white-space: nowrap; }
.badge-code {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, .18);
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}
.badge-code b { letter-spacing: 1px; font-family: ui-monospace, Menlo, Consolas, monospace; }
#copyCode { margin-left: 2px; padding: 1px 7px; }

/* ---------- 拖拽标注（仅管理员模式生效） ---------- */
.tl-card.draggable { cursor: grab; }
.tl-card.draggable:hover { box-shadow: 0 0 0 2px var(--primary); }
.tl-card.dragging { opacity: .35; }
.tl-cell.drop-over {
  outline: 2px dashed var(--primary);
  outline-offset: -3px;
  background: #f0f6ff;
}
.tl-cell-unknown .tl-card.draggable {
  border-left: 3px solid var(--warn);
}

/* ---------- 头图缩略图 ---------- */
.card-cover {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  background: #f1f5f9;
  cursor: zoom-in;
}
.cover-img {
  display: block;
  width: 100%;
  height: 168px;
  object-fit: cover;
  object-position: top center;
  transition: transform .15s;
}
.card-cover:hover .cover-img { transform: scale(1.04); }

.tl-card-cover {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  background: #f1f5f9;
  cursor: zoom-in;
}
.tl-cover-img {
  display: block;
  width: 100%;
  height: 72px;
  object-fit: cover;
  object-position: top center;
}

.ledger-item-preview {
  margin-left: auto;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  border-radius: 6px;
  padding: 3px 12px;
  font-size: 12px;
  cursor: pointer;
  flex: none;
}
.ledger-item-preview:hover { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- 预览弹窗 ---------- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.preview-overlay[hidden] { display: none; }
.preview-box {
  position: relative;
  max-width: 92vw;
  max-height: 90vh;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.preview-img {
  display: block;
  max-width: 92vw;
  max-height: 78vh;
  width: auto;
  object-fit: contain;
  background: #f1f5f9;
}
.preview-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, .6);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.preview-close:hover { background: rgba(15, 23, 42, .85); }
.preview-bar { padding: 12px; text-align: center; }
.preview-bar .download-btn { display: inline-block; flex: none; padding: 8px 28px; }

/* ---------- 其它 ---------- */
.empty-hint { text-align: center; color: var(--text-soft); padding: 60px 20px; font-size: 14px; }
.footer {
  max-width: 1280px; margin: 30px auto 0; padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-soft); text-align: center;
}

@media (max-width: 860px) {
  .browse-body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .search-box input { width: 160px; }
  .filter-row { flex-direction: column; align-items: flex-start; width: 100%; }
  .filter-label { min-width: auto; }
  .grade-bar, .subject-bar { width: 100%; }
}

/* ---------- 每日下载码弹窗 ---------- */
.code-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.code-box {
  background: #fff;
  border-radius: 14px;
  padding: 26px 24px;
  width: 340px;
  max-width: 100%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.code-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-soft);
}
.code-title { font-size: 17px; margin: 0 0 6px; color: var(--text); }
.code-tip { font-size: 12.5px; color: var(--text-soft); margin: 0 0 16px; line-height: 1.5; }
.code-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.code-input:focus { border-color: var(--primary); }
.code-err { color: #dc2626; font-size: 12.5px; min-height: 18px; margin: 8px 0 0; }
.code-submit {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.code-submit:hover { background: #1d4ed8; }

/* PDF 首页图预览 */
.pdf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 18px;
}
.pdf-box {
  background: #fff;
  border-radius: 12px;
  width: min(520px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
}
.pdf-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8faff;
}
.pdf-title {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pdf-dl-btn {
  flex: 0 0 auto;
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary, #2f6df0);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.pdf-dl-btn:hover { background: #1d4ed8; }
.pdf-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-soft);
}
.pdf-frame {
  flex: 1 1 auto;
  width: 100%;
  max-height: 82vh;
  object-fit: contain;
  background: #f3f4f6;
  display: block;
}

/* ===== 生物专区：试卷 + 答案 双下载表格 ===== */
.bio-grid {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 4px 28px;
}
.bio-school {
  font-size: 18px;
  font-weight: 700;
  color: #1f3b73;
  margin: 24px 0 10px;
  padding-left: 10px;
  border-left: 4px solid var(--primary, #2f6df0);
}
.bio-table {
  border: 1px solid #e6e9f0;
  border-radius: 10px;
  overflow: hidden;
}
.bio-row {
  display: grid;
  grid-template-columns: 1fr 132px 132px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid #eef1f6;
}
.bio-row:first-child { border-top: none; }
.bio-row:nth-child(even) { background: #f8faff; }
.bio-name { font-size: 15px; color: #222; }
/* 生物专区：表格铺满宽度、行高紧凑 */
.timeline-grid.bio-grid {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}
.bio-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
  align-items: center;
  padding: 6px 4px;
}
.tl-cell.bio-cell { min-width: 92px; min-height: auto; }
.tl-head.bio-head { min-width: 92px; padding: 8px 6px; }
.tl-corner.bio-corner { min-width: 120px; padding: 8px 8px; }
.tl-school.bio-school { padding: 8px; font-size: 12px; }
.bio-dl { display: block; width: 100%; text-align: center; }
.bio-btn {
  display: inline-block;
  box-sizing: border-box;
  text-align: center;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--primary, #2f6df0);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.bio-btn:hover { background: #1d4ed8; }
.bio-missing {
  display: inline-block;
  box-sizing: border-box;
  text-align: center;
  padding: 3px 6px;
  border-radius: 6px;
  background: #f0f1f4;
  color: #9aa3b2;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
@media (max-width: 560px) {
  .bio-row { grid-template-columns: 1fr 92px 92px; padding: 9px 10px; }
  .bio-btn, .bio-missing { padding: 4px 7px; font-size: 11px; }
}
