:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --toolbar: #ffffff;
  --border: rgba(15, 23, 42, 0.14);
  --text: #111827;
  --muted: #667085;
  --accent: #0205d3;
  --toolbar-shadow: 0 10px 24px rgba(15, 23, 42, 0.10);
  --menu-shadow: 0 18px 34px rgba(15, 23, 42, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  position: relative;
  height: 100vh;
}

#toolbar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  background: var(--toolbar);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  box-shadow: var(--toolbar-shadow);
}

.toolbar-group {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.toolbar-group-nav {
  gap: 8px;
}

.toolbar-group-zoom {
  gap: 8px;
  position: absolute;
  left: 50%;
  transform: translateX(calc(-50% + 8px));
}

.toolbar-group-actions {
  gap: 8px;
  margin-left: auto;
}

body.hide-actions .toolbar-group-actions {
  display: none;
}

body.hide-actions .toolbar-group-mobile-actions {
  display: none;
}

body.hide-download #downloadBtn {
  display: none;
}

body.hide-print #printBtn {
  display: none;
}

body.hide-download #downloadMenuItem {
  display: none;
}

body.hide-print #printMenuItem {
  display: none;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  line-height: 1;
  min-height: 38px;
  font-weight: 600;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.btn:hover:not(:disabled):not(.is-disabled) {
  background: rgba(15, 23, 42, 0.04);
}

.btn:focus-visible,
.toolbar-menu-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(27, 103, 230, 0.18);
}

.btn:disabled,
.btn.is-disabled,
#pageNumber:disabled {
  color: var(--muted);
  cursor: default;
  pointer-events: none;
}

.btn:disabled i,
.btn.is-disabled i {
  opacity: 0.7;
}

.btn.loading {
  position: relative;
  color: transparent;
}

.btn.loading i {
  opacity: 0;
}

.btn.loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: var(--accent);
  position: absolute;
  inset: 0;
  margin: auto;
  animation: spin 0.8s linear infinite;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.toolbar-separator {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 4px;
  flex: 0 0 auto;
}

.page-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
}

.page-count-label {
  color: var(--muted);
}

.page-current-compact {
  display: none;
  align-items: center;
  height: 38px;
  font-size: 13px;
  font-weight: 600;
}

.icon-btn {
  padding: 0;
  width: 38px;
  height: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn i {
  font-size: 17px;
}

.zoom-select {
  min-width: 82px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  height: 38px;
  border-color: var(--border);
  background: #fff;
}

.zoom-pill-text {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

.menu-shell {
  position: relative;
}

.toolbar-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 164px;
  padding: 8px;
  display: grid;
  gap: 4px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  box-shadow: var(--menu-shadow);
}

.toolbar-menu[hidden] {
  display: none;
}

.toolbar-menu-zoom {
  min-width: 92px;
}

.toolbar-menu-item {
  appearance: none;
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.toolbar-menu-item:hover,
.toolbar-menu-item.selected {
  background: rgba(15, 23, 42, 0.06);
}

.toolbar-menu-item i {
  font-size: 17px;
}

.desktop-only {
  display: inline-flex;
}

.mobile-only {
  display: none;
}

#pageNumber {
  width: 62px;
  padding: 6px 12px 6px 8px;
  height: 38px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
}

#pageNumber::-webkit-outer-spin-button,
#pageNumber::-webkit-inner-spin-button {
  margin-left: 6px;
  transform: scale(1.15);
  transform-origin: center;
  opacity: 1;
}

#viewerContainer {
  position: absolute;
  top: 80px;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: auto;
  padding: 16px 12px 32px;
}

#viewerContainer.is-loading #viewer {
  opacity: 0.18;
}

.viewer-loading {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(243, 244, 246, 0.94);
}

.viewer-loading[hidden] {
  display: none;
}

.viewer-loading-panel {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 16px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 12px;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.10);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.viewer-loading-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #dbe3ef;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

#viewerContainer.has-error #viewer {
  display: none;
}

.viewer-error {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.viewer-error[hidden] {
  display: none;
}

.viewer-error-panel {
  width: min(100%, 440px);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 28px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 12px;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.10);
  text-align: center;
}

.viewer-error-icon {
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fef2f2;
  color: #b42318;
}

.viewer-error-icon i {
  font-size: 23px;
}

.viewer-error-copy {
  display: grid;
  gap: 8px;
}

.viewer-error-copy h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 600;
}

.viewer-error-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.viewer-error-action {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--border);
  background: #fff;
}

#printContainer {
  display: none;
}

.print-page {
  break-after: page;
  page-break-after: always;
}

@media print {
  body {
    background: #fff;
  }

  #toolbar,
  #viewerContainer {
    display: none !important;
  }

  #printContainer {
    display: block;
    padding: 0;
  }

  #printContainer canvas {
    width: 100%;
    height: auto;
    display: block;
  }
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 625px) {
  #toolbar {
    left: 10px;
    right: 10px;
    gap: 10px;
    padding: 10px;
  }

  .toolbar-group {
    gap: 6px;
  }

  .toolbar-group-nav {
    order: 1;
    flex: 1 1 auto;
  }

  .toolbar-group-zoom {
    order: 2;
    flex: 0 0 auto;
    position: static;
    transform: none;
    margin-left: 0;
  }

  .toolbar-group-mobile-actions {
    order: 3;
    margin-left: auto;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: inline-flex;
  }

  #pageNumber {
    width: 58px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .zoom-select {
    min-width: 80px;
    padding: 0 10px;
    height: 36px;
  }

  #pageNumber,
  .btn,
  .page-count {
    min-height: 36px;
    height: 36px;
  }

  .toolbar-separator {
    display: none;
  }

  .toolbar-menu-actions {
    top: calc(100% + 12px);
    right: 0;
    min-width: 156px;
  }

  #viewerContainer {
    top: 78px;
    padding: 12px 8px 24px;
  }
}

@media (max-width: 430px) {
  .page-indicator {
    gap: 4px;
  }

  #pageNumber {
    display: none;
  }

  .page-current-compact {
    display: inline-flex;
  }
}

@media (max-width: 400px) {
  .page-count,
  .zoom-select {
    display: none;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
