:root {
  --brand: #074f96;
  --brand-dark: #043362;
  --ink: #17212b;
  --muted: #66717d;
  --line: #d4dce2;
  --surface: #ffffff;
  --stage: #e8ecef;
  --accent: #d8a531;
  --danger: #a62f29;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  min-width: 280px;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--stage);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  z-index: 100;
  left: 12px;
  top: -60px;
  padding: 9px 14px;
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line);
}
.skip-link:focus { top: 10px; }

.viewer-header {
  z-index: 4;
  width: 100%;
  min-width: 0;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.viewer-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  width: fit-content;
  color: #536170;
  font-size: 12px;
  font-weight: 700;
}
.viewer-brand img { width: 108px; height: 30px; object-fit: contain; }
.viewer-brand span { padding-left: 14px; border-left: 1px solid var(--line); white-space: nowrap; }
.document-heading { min-width: 230px; text-align: center; }
.document-heading strong, .document-heading span { display: block; }
.document-heading strong { font-size: 15px; line-height: 1.3; }
.document-heading span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.language-toggle {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: #5c6872;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.language-toggle:hover { border-color: var(--brand); color: var(--brand); }
.language-toggle [data-language-option].is-current { color: var(--brand); }
.language-divider { color: #aeb7bf; font-weight: 400; }
.download-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--brand);
  border-radius: 3px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.download-button:hover { background: #0862b7; }
.download-button svg { width: 16px; height: 16px; }

.viewer-toolbar {
  z-index: 3;
  width: 100%;
  min-width: 0;
  min-height: 54px;
  overflow-x: auto;
  border-bottom: 1px solid #c8d0d7;
  background: #f8f9fa;
  box-shadow: 0 2px 7px rgba(28, 43, 56, .07);
  scrollbar-width: thin;
}
.toolbar-inner {
  min-width: max-content;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 7px 16px;
}
.control-group { display: flex; align-items: center; gap: 6px; }
.tool-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.tool-button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.tool-button:disabled { color: #a8b0b7; background: #f0f2f3; cursor: default; }
.tool-button svg { width: 18px; height: 18px; }
.page-jump {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}
.page-jump:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(7, 79, 150, .09); }
.page-jump input {
  width: 48px;
  height: 30px;
  padding: 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  font-weight: 800;
  appearance: textfield;
}
.page-jump input::-webkit-inner-spin-button { appearance: none; }
.zoom-value { width: 50px; color: #4c5964; text-align: center; font-size: 12px; font-weight: 800; }
.toolbar-divider { width: 1px; height: 26px; background: var(--line); }

.catalog-stage {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--stage);
  scrollbar-color: #9ca8b1 transparent;
}
.page-stage-inner {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: start center;
  padding: 28px 32px 36px;
}
.page-sheet {
  width: 922px;
  margin: 0;
  overflow: hidden;
  border: 1px solid #cbd3d9;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(35, 48, 59, .14);
  transition: opacity .15s ease;
}
.page-sheet img {
  width: 100%;
  height: auto;
  aspect-ratio: 603.78 / 824.882;
  display: block;
  background: #fff;
}
.page-sheet figcaption {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  font-size: 11px;
}
.catalog-stage.is-loading .page-sheet { opacity: .42; }
.loading-state {
  position: fixed;
  z-index: 2;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: rgba(255, 255, 255, .94);
  color: #45525d;
  box-shadow: 0 8px 20px rgba(32, 43, 52, .1);
  font-size: 12px;
  font-weight: 700;
}
.catalog-stage.is-loading .loading-state { display: flex; }
.loading-spinner {
  width: 17px;
  height: 17px;
  border: 2px solid #c9d4dd;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-state {
  position: fixed;
  z-index: 3;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  width: min(330px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid #d8c2bf;
  border-top: 3px solid var(--danger);
  border-radius: 4px;
  background: #fff;
  text-align: center;
  box-shadow: 0 14px 34px rgba(32, 43, 52, .16);
}
.error-state[hidden] { display: none; }
.error-state svg { width: 28px; height: 28px; color: var(--danger); }
.error-state strong { display: block; margin: 8px 0 16px; font-size: 14px; }
.error-state button {
  min-height: 38px;
  padding: 0 18px;
  border: 1px solid var(--brand);
  border-radius: 3px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 820px) {
  .viewer-header { grid-template-columns: 1fr auto; gap: 12px; padding: 9px 16px; }
  .document-heading { display: none; }
  .viewer-brand span { display: none; }
  .page-stage-inner { padding: 20px 20px 28px; }
}

@media (max-width: 520px) {
  .viewer-header { min-height: 58px; padding: 8px 10px; }
  .viewer-brand img { width: 96px; height: 27px; }
  .header-actions { gap: 6px; }
  .language-toggle { height: 36px; padding: 0 8px; }
  .download-button { width: 38px; height: 38px; min-height: 38px; padding: 0; }
  .download-button span { display: none; }
  .toolbar-inner { justify-content: flex-start; gap: 6px; padding: 7px 10px; }
  .control-group { gap: 4px; }
  .tool-button { width: 36px; height: 36px; flex-basis: 36px; }
  .page-jump { height: 36px; gap: 4px; padding: 0 7px; }
  .page-jump input { width: 42px; }
  .zoom-value { width: 40px; }
  .page-stage-inner { padding: 12px 12px 22px; }
  .page-sheet figcaption { min-height: 31px; }
  .loading-state, .error-state { top: 56%; }
}

@media (prefers-reduced-motion: reduce) {
  .page-sheet { transition: none; }
  .loading-spinner { animation-duration: 1.4s; }
}
