:root {
  --page-bg: #12131d;
  --surface: rgba(28, 31, 46, 0.9);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-primary: #f2f4f8;
  --text-secondary: #bfc6d8;
  --text-muted: #9097a7;
  --control-bg: rgba(30, 33, 49, 0.9);
  --control-active-bg: rgba(139, 92, 246, 0.18);
  --button-primary-bg: linear-gradient(135deg, #8b5cf6, #a78bfa);
  --button-primary-text: #fff;
  --accent: #8b5cf6;
}

.pdf-page {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.pdf-header {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  min-height: 4.5rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(18, 19, 29, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.pdf-header__back,
.pdf-header__download,
.pdf-control {
  min-height: 2.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.9rem;
  background: var(--control-bg);
  color: var(--text-primary);
  font-weight: 700;
}

.pdf-header__back,
.pdf-header__download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 0.85rem;
}

.pdf-header__download {
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
}

.pdf-header__title {
  min-width: 0;
  text-align: center;
}

.pdf-header__title strong,
.pdf-header__title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-header__title span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.pdf-header__title span span {
  display: inline;
}

.pdf-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: calc(100dvh - 4.5rem - env(safe-area-inset-top));
}

.pdf-toolbar {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.7rem max(0.7rem, env(safe-area-inset-right)) 0.7rem max(0.7rem, env(safe-area-inset-left));
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  scrollbar-width: thin;
}

.pdf-toolbar__group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
}

.pdf-language-switch {
  padding-right: 0.75rem;
  border-right: 1px solid var(--border);
}

.pdf-control {
  min-width: 2.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 1.05rem;
}

.pdf-control--text,
.pdf-control--language {
  min-width: auto;
  font-size: 0.86rem;
}

.pdf-control--language.is-active {
  border-color: var(--accent);
  background: var(--control-active-bg);
}

.pdf-control:hover:not(:disabled),
.pdf-control:focus-visible,
.pdf-header__back:hover,
.pdf-header__download:hover {
  border-color: var(--accent);
  background-color: var(--control-active-bg);
}

.pdf-control:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.pdf-page-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.pdf-page-field input {
  width: 3.4rem;
  min-height: 2.75rem;
  padding: 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.75rem;
  background: var(--control-bg);
  color: var(--text-primary);
  text-align: center;
}

.pdf-zoom-value {
  min-width: 3.2rem;
  color: var(--text-secondary);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pdf-document {
  position: relative;
  display: grid;
  place-items: start center;
  min-height: 0;
  padding: 1.5rem;
  overflow: auto;
  overscroll-behavior: contain;
  background: #262936;
}

.pdf-canvas {
  flex: none;
  max-width: none;
  border-radius: 0.25rem;
  background: #fff;
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.36);
}

.pdf-message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.85rem;
  padding: 1.5rem;
  background: rgba(38, 41, 54, 0.94);
  color: var(--text-secondary);
  text-align: center;
}

.pdf-message--error a {
  padding: 0.7rem 1rem;
  border-radius: 0.85rem;
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  font-weight: 700;
}

.pdf-spinner {
  width: 2.4rem;
  height: 2.4rem;
  border: 0.25rem solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pdf-spin 700ms linear infinite;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

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

@media (max-width: 640px) {
  .pdf-header {
    gap: 0.45rem;
    padding-inline: max(0.6rem, env(safe-area-inset-left));
  }

  .pdf-header__back span:last-child,
  .pdf-header__title > span,
  .pdf-header__download {
    font-size: 0.78rem;
  }

  .pdf-header__back span:last-child {
    display: none;
  }

  .pdf-header__title strong {
    font-size: 0.9rem;
  }

  .pdf-toolbar {
    justify-content: flex-start;
  }

  .pdf-document {
    padding: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pdf-spinner {
    animation-duration: 1.4s;
  }
}
