:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1f2733;
  --ink-soft: #63708a;
  --line: #e3e8f0;
  --brand: #c8342b;
  --brand-soft: #fdeceb;
  --accent: #1f6feb;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(23, 33, 54, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: linear-gradient(120deg, #ffffff 0%, #f7f9ff 100%);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  letter-spacing: 1px;
}

.topbar h1 { margin: 0; font-size: 18px; }
.sub { margin: 2px 0 0; color: var(--ink-soft); font-size: 12px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }

.apikey {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.apikey input {
  width: 220px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-family: Consolas, "Courier New", monospace;
  outline: none;
}

.apikey input:focus { border-color: var(--accent); }
.apikey .btn { height: 30px; padding: 0 12px; font-size: 12px; }

.keydot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #d0d7e2;
  flex: none;
}

.keydot.ok { background: #1f7a43; box-shadow: 0 0 0 3px rgba(31, 122, 67, .15); }
.keydot.bad { background: var(--brand); box-shadow: 0 0 0 3px rgba(200, 52, 43, .15); }

.authwarn {
  max-width: 1360px;
  margin: 14px auto -6px;
  padding: 10px 16px;
  border: 1px solid #f3d6a8;
  background: #fff8ec;
  color: #8a5a12;
  border-radius: var(--radius);
  font-size: 13px;
}

.authwarn[hidden] { display: none; }

.stat {
  min-width: 118px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat b { display: block; font-size: 16px; }
.stat span { color: var(--ink-soft); font-size: 12px; }

main {
  max-width: 1360px;
  margin: 20px auto 48px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.tab {
  appearance: none;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--ink-soft);
  padding: 8px 16px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 14px;
}

.tab:hover { color: var(--brand); background: var(--brand-soft); }

.tab.active {
  color: var(--brand);
  font-weight: 700;
  background: var(--panel);
  border-color: var(--line);
  box-shadow: inset 0 -2px 0 var(--brand);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  background: #fbfcfe;
  border-bottom: 1px solid var(--line);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1 1 320px; }

.field label { font-size: 12px; color: var(--ink-soft); }

.field input,
.field select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  outline: none;
}

.field input:focus,
.field select:focus { border-color: var(--accent); }

.actions { display: flex; gap: 8px; }

.btn {
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s ease;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #ad2a22; border-color: #ad2a22; color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.resultbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

.resultbar.bottom { border-top: 1px solid var(--line); }
.summary { color: var(--ink-soft); font-size: 13px; }

.pager { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.pager button {
  min-width: 34px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}

.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button.current { background: var(--brand); border-color: var(--brand); color: #fff; cursor: default; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.pager .gap { color: var(--ink-soft); padding: 0 2px; }

.tablewrap { position: relative; overflow-x: auto; }

.grid { width: 100%; border-collapse: collapse; min-width: 1080px; }

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fd;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 12px;
  text-align: left;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.grid tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid #f0f3f8;
  vertical-align: top;
  font-size: 13px;
}

.grid tbody tr:hover { background: #fafcff; }
.col-title { width: 40%; }
.col-type { width: 88px; }
.col-date { width: 104px; }
.col-org { width: 130px; }
.col-researcher { width: 120px; }
.col-pages { width: 64px; }
.col-updated { width: 148px; }
.col-action { width: 96px; }

.title {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  border-bottom: none;
}

.title:hover { color: var(--accent); text-decoration: none; }

a { text-decoration: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  background: #eef3ff;
  color: #2b57b7;
  white-space: nowrap;
}

.badge.stock { background: var(--brand-soft); color: var(--brand); }
.badge.industry { background: #eaf7ef; color: #1f7a43; }
.badge.macro { background: #f2eefc; color: #5b3fbf; }

.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }

.empty, .loading {
  padding: 40px 16px;
  text-align: center;
  color: var(--ink-soft);
}

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 22, 36, .55); }

.modal-body {
  position: relative;
  width: min(1100px, 94vw);
  height: min(90vh, 1000px);
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(10, 18, 35, .35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.modal-title { min-width: 0; display: flex; flex-direction: column; }
.modal-title strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 52vw; }
.modal-title .meta { color: var(--ink-soft); font-size: 12px; }

.modal-tools { display: flex; align-items: center; gap: 8px; }
.modal-tools label { color: var(--ink-soft); font-size: 12px; }

.modal-tools select {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
}

.modal-stage {
  flex: 1;
  overflow: auto;
  background: #eef1f6;
  padding: 16px 16px 24px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
}

.page {
  position: relative;
  width: 100%;
  flex: none;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 18px rgba(20, 30, 50, .18);
  overflow: hidden;
  scroll-margin-top: 12px;
}

.page.ph {
  background: #e9edf4;
  box-shadow: none;
  border-radius: 4px;
  flex: none;
}

.page.ph::before { content: none; }

.page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  opacity: 0;
  transition: opacity .18s ease;
}

.page.loaded img { opacity: 1; }

.page .badge-no {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(24, 33, 51, .62);
  color: #fff;
  font-size: 12px;
  pointer-events: none;
}

.page .skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  background: linear-gradient(100deg, #f4f6fa 30%, #eaeef6 50%, #f4f6fa 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #cdd6e4;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s infinite linear;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.page.loaded .skeleton { display: none; }
.page.failed .skeleton { animation: none; background: #fdf1f0; color: var(--brand); cursor: pointer; }

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -80% 0; }
}

.sentinel { height: 2px; }

.stage-status {
  padding: 12px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}

.stage-status[hidden] { display: none; }

.sentinel-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 0 4px;
  color: var(--ink-soft);
  font-size: 13px;
}

.sentinel-hint[hidden] { display: none; }
.sentinel-hint .btn[hidden] { display: none; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.pageinfo { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 13px; }
.pageinfo input {
  width: 68px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  text-align: center;
}
.hint { margin-left: auto; color: var(--ink-soft); font-size: 12px; }

.filterbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
}

.filterbar .btn { flex: none; }
.filterbar .count { color: var(--ink-soft); font-size: 12px; }
.filterbar .count:empty { display: none; }

.apikey.locked { padding: 6px 12px; cursor: pointer; }
.apikey.editing { cursor: default; }

.apikey.locked::after {
  content: "API Key 已就绪";
  font-size: 12px;
  color: #1f7a43;
  white-space: nowrap;
}

.apikey.locked.bad::after { content: "API Key 无效，点此修改"; color: var(--brand); }

.apikey [hidden] { display: none !important; }

.tabbar {
  display: none;
  position: sticky;
  bottom: 0;
  z-index: 5;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.tabbar .pos { color: var(--ink-soft); font-size: 12px; }
.tabbar .jump { display: flex; align-items: center; gap: 6px; }
.tabbar .jump input {
  width: 62px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 6px;
  text-align: center;
}

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }

  .topbar { gap: 10px; }
  .stats { gap: 8px; }
  .stat { min-width: 96px; padding: 6px 10px; }
  .stat b { font-size: 15px; }
}

@media (max-width: 1000px) {
  main { padding: 0 12px; }

  .topbar { align-items: flex-start; }

  .stats {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 1 0 auto; min-width: 104px; }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: none; }

  .filterbar { display: flex; }

  .filters { display: none; }
  .filters.open { display: flex; }

  .filters .field { flex: 1 1 calc(50% - 6px); }
  .filters .field.grow { flex: 1 1 100%; }
  .filters .actions { flex: 1 1 100%; }

  .apikey { flex: none; margin-left: auto; }
  .field label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 720px) {
  body { -webkit-text-size-adjust: 100%; }

  main { padding: 0 10px; margin: 12px auto 96px; }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
    align-items: flex-start;
  }

  .brand { gap: 10px; min-width: 0; }
  .logo { width: 36px; height: 36px; border-radius: 10px; font-size: 13px; }
  .topbar h1 { font-size: 15px; }
  .sub { font-size: 11px; }

  .stats { display: none; }

  .apikey {
    margin-left: auto;
    padding: 4px 10px;
    min-height: 36px;
  }

  .apikey input {
    width: 100%;
    min-width: 0;
    height: 36px;
    font-size: 16px;
  }

  .apikey .btn { height: 36px; padding: 0 12px; }

  .apikey.editing {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
  }

  .apikey.editing input { width: 100%; }

  .authwarn { margin: 0 0 10px; padding: 10px 12px; font-size: 12.5px; }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 8px 10px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 14px; white-space: nowrap; font-size: 13.5px; }

  .filterbar { display: flex; }

  .filters {
    display: none;
    padding: 12px 10px;
    gap: 10px;
  }

  .filters.open { display: flex; }

  .field, .field.grow { flex: 1 1 100%; }

  /* 两个日期控件在窄屏挤在一行会显示不全，各占整行 */
  .field.date { flex: 1 1 100%; }
  .field.date input { width: 100%; }

  .field input,
  .field select {
    height: 40px;
    font-size: 16px;
  }

  .field label { white-space: normal; }

  .actions { width: 100%; }
  .actions .btn { flex: 1; height: 40px; font-size: 14px; }

  .btn { height: 36px; padding: 0 14px; }

  .resultbar { padding: 12px; flex-direction: column; align-items: stretch; gap: 6px; }
  .resultbar .pager { display: none; }
  .summary { font-size: 12px; color: var(--ink-soft); }

  .authwarn { font-size: 12.5px; }

  .tablewrap { overflow-x: visible; }

  .grid { min-width: 0; display: block; }
  .grid thead { display: none; }
  .grid tbody { display: block; }

  .grid tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 3px 10px;
    margin: 0 8px 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  .grid tbody tr:hover { background: #fff; }

  .grid tbody td {
    width: auto;
    min-width: 0;
    max-width: none;
    padding: 0;
    border: none;
    font-size: 13px;
  }

  .grid tbody td.col-title {
    grid-column: 1 / -1;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
    margin-bottom: 4px;
  }

  .grid tbody td:empty { display: none; }

  .grid tbody td.col-researcher,
  .grid tbody td.col-updated { display: none; }

  .grid tbody td.col-type { grid-area: 2 / 1 / 3 / 2; }
  .grid tbody td.col-org { grid-area: 2 / 2 / 3 / 3; justify-self: end; text-align: right; }

  .grid tbody td.col-date {
    grid-area: 3 / 1 / 4 / 2;
    align-self: center;
    color: var(--ink-soft);
    font-size: 12.5px;
    margin-top: 6px;
  }

  .grid tbody td.col-pages {
    grid-area: 3 / 2 / 4 / 3;
    align-self: center;
    justify-self: end;
    color: var(--ink-soft);
    font-size: 12.5px;
    margin-top: 6px;
  }

  .grid tbody td.col-pages::after { content: " 页"; }

  .grid tbody td.col-action { grid-area: 4 / 1 / 5 / 3; margin-top: 10px; }

  .grid tbody td.col-action .btn {
    width: 100%;
    height: 40px;
    font-size: 14px;
    color: var(--brand);
    border-color: #f0d3d0;
    background: #fdf6f5;
  }

  .grid tbody td.col-date::before,
  .grid tbody td.col-pages::before { content: ""; }

  .empty, .loading { padding: 32px 12px; }

  .pager button { min-width: 40px; height: 38px; }

  .modal-body {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-head { padding: 10px 12px; }
  .modal-title strong { max-width: 100%; font-size: 13.5px; }
  .modal-tools { width: 100%; justify-content: space-between; }
  .modal-tools label { display: none; }
  .modal-tools select { height: 36px; }
  .modal-tools .btn { padding: 0 12px; }
  .modal-tools .btn#openRaw,
  .modal-tools .btn#printPage { display: none; }

  .modal-stage { padding: 8px 8px 4px; }
  .pages { gap: 10px; }

  .modal-foot {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    position: relative;
  }

  .modal-foot .hint { display: none; }
  .modal-foot .btn { height: 38px; }
  .modal-foot #prevPage,
  .modal-foot #nextPage { flex: 1; }
  .modal-foot #jumpPage { display: none; }
  .pageinfo input { width: 58px; height: 38px; font-size: 16px; }

  .tabbar { display: flex; }
}

@media (max-width: 380px) {
  .brand .sub { display: none; }
  .grid tbody tr { margin: 0 6px 8px; padding: 10px; }
}

@media (max-width: 720px) {
  .tabbar .btn {
    white-space: nowrap;
    padding: 0 10px;
    font-size: 13px;
  }

  .tabbar .jump input { width: 56px; }
  .tabbar .pos { white-space: nowrap; }
}

@media (min-width: 721px) and (max-width: 1000px) {
  .grid { min-width: 0; }
  .col-researcher,
  .col-pages,
  .col-updated { display: none; }

  .grid tbody td,
  .grid thead th { padding: 9px 8px; font-size: 12.5px; }

  .col-title { width: auto; }
  .col-type { width: 80px; }
  .col-date { width: 96px; }
  .col-org { width: 118px; }
  .col-action { width: 84px; }
}
