* {
  box-sizing: border-box;
}

:root {
  --blue-900: #0f2f57;
  --blue-800: #184a86;
  --blue-700: #245c9f;
  --blue-050: #eef4fb;
  --border: #d7dee8;
  --border-strong: #c4cfdd;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-muted: #f8fafc;
  --page-bg: #eef2f6;
  --sidebar-bg: #f8fafc;
  --text: #1f2937;
  --muted: #667085;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --radius-lg: 18px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --maxw: 1340px;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  overflow: hidden;
}

body {
  overflow: hidden;
}

.page-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 20px;
  height: 100%;
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}

.sidebar.hidden {
  display: none;
}

.sidebar-inner {
  padding: 18px 14px;
}

.sidebar-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue-800);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toc-item:hover {
  background: #fff;
  border-color: var(--border);
}

.toc-item.active {
  background: #fff;
  border-color: #bfd0e6;
}

.toc-title {
  display: block;
  text-align: left;
  justify-self: stretch;
  font-size: 12.5px;
  line-height: 1.3;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.toc-page {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 1px;
}

.toc-item[data-level="0"] .toc-title {
  font-weight: 600;
}

.toc-item[data-level="1"] .toc-title {
  font-size: 12px;
  color: #334155;
}

.toc-item[data-level="2"] .toc-title,
.toc-item[data-level="3"] .toc-title,
.toc-item[data-level="4"] .toc-title {
  font-size: 11.5px;
  color: #475569;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.7);
}

.toolbar-group {
  display: flex;
  align-items: center;
}

.toolbar-group-left {
  justify-content: flex-start;
}

.toolbar-group-center {
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.toolbar-group-right {
  justify-content: flex-end;
}

.toolbar-cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: linear-gradient(180deg, #fdfefe 0%, #f4f7fb 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.toolbar-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--blue-900);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.08s ease;
}

.toolbar-btn:hover {
  background: #fff;
  border-color: #c7d4e3;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.toolbar-btn:active {
  transform: translateY(1px);
}

.toolbar-btn:focus-visible {
  outline: none;
  border-color: var(--blue-700);
  box-shadow: 0 0 0 3px rgba(36, 92, 159, 0.16);
}

.toolbar-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
}

.toolbar-btn-panel {
  background: linear-gradient(180deg, #fdfefe 0%, #f4f7fb 100%);
  border: 1px solid var(--border);
  color: var(--blue-900);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.toolbar-btn-panel svg {
  width: 17px;
  height: 17px;
}

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 9px;
  background: linear-gradient(180deg, #fdfefe 0%, #f4f7fb 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.page-jump-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-input {
  width: 52px;
  height: 30px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

.page-input:hover {
  border-color: #9fb3c8;
}

.page-input:focus {
  border-color: var(--blue-700);
  box-shadow: 0 0 0 2px rgba(36, 92, 159, 0.15);
}

.page-input::-webkit-outer-spin-button,
.page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.page-input {
  -moz-appearance: textfield;
}

#pageIndicator {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-900);
  min-width: 42px;
  text-align: left;
}

.viewer-shell {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: linear-gradient(180deg, #edf2f8 0%, #e3eaf3 100%);
  padding: 8px 56px;
}

.pdf-stage {
  width: fit-content;
  min-width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
}

.pdf-spread {
  display: flex;
  gap: 0;
  align-items: flex-start;
  justify-content: center;
  width: fit-content;
  height: fit-content;
  padding: 8px 12px;
}

#pdfCanvasLeft,
#pdfCanvasRight {
  display: block;
  background: white;
  max-width: none;
  max-height: none;
}

#pdfCanvasLeft {
  box-shadow: -8px 18px 32px rgba(0, 0, 0, 0.10);
}

#pdfCanvasRight {
  box-shadow: 8px 18px 32px rgba(0, 0, 0, 0.10);
}

#pdfCanvasLeft.hidden,
#pdfCanvasRight.hidden {
  display: none;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(237, 242, 248, 0.96);
  z-index: 50;
}

.loading-overlay.hidden {
  display: none;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 24px;
  background: #fff;
  border: 1px solid #d7dee8;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 4px solid #d7dee8;
  border-top: 4px solid #245c9f;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  font-size: 14px;
  font-weight: 600;
  color: #0f2f57;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.side-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 74px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  background: rgba(15, 47, 87, 0.82);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 40;
  backdrop-filter: blur(2px);
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.side-nav:hover {
  background: rgba(15, 47, 87, 0.94);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
}

.side-nav:active {
  transform: translateY(-50%) scale(0.98);
}

.side-nav:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(36, 92, 159, 0.22);
}

.side-nav svg {
  width: 20px;
  height: 20px;
  display: block;
  stroke: currentColor;
}

.side-nav-left {
  left: 10px;
}

.side-nav-right {
  right: 10px;
}

.page-layer {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.link-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.pdf-link-hitbox,
.link-layer a {
  position: absolute;
  display: block;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  pointer-events: auto;
}

.pdf-link-hitbox:hover,
.link-layer a:hover {
  outline: 1px solid rgba(36, 92, 159, 0.35);
  background: rgba(36, 92, 159, 0.08);
}

.page-layer.hidden {
  display: none;
}

@media (max-width: 980px) {
  .sidebar {
    position: absolute;
    z-index: 20;
    height: 100%;
  }
}

@media (max-width: 700px) {
  .toolbar {
    padding: 6px 8px;
    gap: 6px;
  }

  .toolbar-group-center {
    gap: 6px;
  }

  .toolbar-cluster {
    padding: 2px;
    border-radius: 10px;
  }

  .toolbar-btn {
    height: 30px;
    min-width: 30px;
    padding: 0 8px;
  }

  .toolbar-btn svg {
    width: 15px;
    height: 15px;
  }

  .page-jump {
    padding: 2px 6px;
    gap: 5px;
  }

  .page-input {
    width: 46px;
    height: 28px;
  }

  .viewer-shell {
    padding: 10px 42px;
  }

  .side-nav {
    width: 32px;
    height: 58px;
  }

  .side-nav svg {
    width: 17px;
    height: 17px;
  }

  .side-nav-left {
    left: 6px;
  }

  .side-nav-right {
    right: 6px;
  }

}
