/* The review workbench keeps all existing controls and data hooks. This last,
   page-scoped layer calms the source surface without changing theme authority. */
.target-document-shell.stitch-viewer-shell {
  background: var(--k-bg);
  color: var(--k-text);
}

.target-document-shell .review-header.stitch-topbar.viewer-topbar {
  min-height: 64px !important;
  padding-inline: clamp(12px, 2vw, 28px) !important;
  border-bottom: 1px solid var(--k-line);
  background: var(--k-surface) !important;
}

.target-document-shell .viewer-document-text strong {
  font-size: clamp(15px, 1.3vw, 18px);
  font-weight: 700;
}

.target-document-shell .document-workspace[data-stitch-reader-desk="true"] {
  background: var(--k-bg) !important;
}

.target-document-shell .document-workspace[data-stitch-reader-desk="true"] .page-thumbnail-rail {
  background: var(--k-surface) !important;
  border-right-color: var(--k-line) !important;
}

.target-document-shell .document-canvas-pane[data-stitch-reader-document="true"] {
  min-width: 0;
  background: var(--k-bg) !important;
  border-right-color: var(--k-line) !important;
}

.target-document-shell .document-canvas-pane[data-stitch-reader-document="true"] .toolbar {
  min-height: 56px;
  padding-inline: clamp(10px, 1.4vw, 20px) !important;
  background: var(--k-surface) !important;
  border-bottom-color: var(--k-line) !important;
}

.target-document-shell .page-stage {
  border-color: var(--k-line);
  border-radius: 10px;
  background: var(--k-surface-2);
}

.target-document-shell .viewer-workbench-toolbar[data-stitch-viewer-workbench-toolbar="true"] {
  border-bottom: 1px solid var(--k-line);
  background: var(--k-surface);
}

.target-document-shell .viewer-nav-cluster[data-stitch-viewer-nav-cluster="true"] {
  border-color: var(--k-line);
  border-radius: 8px;
  background: var(--k-surface);
}

/* DESIGN-116: Alle Werkzeuggruppen sind auf jeder Breite gleich hoch:
   44-px-Knöpfe plus Haarlinie ergeben 46 px für Navigation, Einpassen,
   Lesemodus und Zoom. */
.target-document-shell .viewer-workbench-toolbar .chrome-icon-button {
  width: 44px !important;
  min-width: 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  border-radius: 6px;
}

.target-document-shell .viewer-workbench-toolbar .page-controls .page-jump-label,
.target-document-shell .viewer-workbench-toolbar .page-controls .page-count {
  height: 44px !important;
  min-height: 44px !important;
}

.target-document-shell .viewer-workbench-toolbar .viewer-zoom-strip[data-stitch-viewer-zoom-strip="true"] {
  height: 46px !important;
  min-height: 46px !important;
  padding: 0 !important;
  align-items: stretch !important;
}

.target-document-shell .viewer-workbench-toolbar .chrome-icon-button:focus-visible,
.target-document-shell .viewer-workbench-toolbar .tool-button:focus-visible {
  outline: 2px solid var(--k-info);
  outline-offset: 2px;
}

.target-document-shell .viewer-workbench-toolbar .tool-button {
  min-height: 44px !important;
  padding-inline: 12px !important;
}

.target-document-shell .viewer-workbench-toolbar .viewer-fit-controls .tool-button {
  min-width: 44px !important;
}

.target-document-shell .viewer-quick-actions[data-stitch-viewer-quick-actions="true"] {
  flex-wrap: wrap;
}

.target-document-shell .viewer-theme-control {
  /* DESIGN-116: Der Schalter steht ohne grauen Rahmenkasten in der Kopfzeile,
     wie die übrigen Schalter. */
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
}

.target-document-shell .viewer-theme-control .theme-switch {
  min-height: 44px;
  gap: 8px;
  font-size: 12px;
}

.target-document-shell .viewer-theme-control .theme-switch-label {
  color: var(--k-muted);
  font-size: 12px;
}

.target-document-shell .viewer-theme-control .theme-switch input {
  flex-basis: 44px;
  width: 44px;
  height: 26px;
}

/* DESIGN-116: Nur der Dunkel-Zustand bekommt die helle Spur. Angehakt (Hell)
   gilt die Akzentspur aus theme-switch.css; vorher lag dort ein weißer Daumen
   auf weißer Spur und der Zustand war unsichtbar. */
.target-document-shell .viewer-theme-control .theme-switch input:not(:checked) {
  border-color: var(--k-line);
  background: var(--k-surface) !important;
}

.target-document-shell .viewer-theme-control .theme-switch input::before {
  width: 18px;
  height: 18px;
}

.target-document-shell .viewer-theme-control .theme-switch input:checked::before {
  transform: translateX(18px);
}

.target-document-shell .author-workspace-sidebar .theme-switch-form {
  display: none !important;
}

@media (max-width: 760px) {
  .target-document-shell .review-header.stitch-topbar.viewer-topbar {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-auto-rows: auto;
    height: auto !important;
    min-height: 0 !important;
    gap: 8px !important;
    padding-inline: 16px !important;
    align-items: start !important;
  }

  .target-document-shell .viewer-document-title,
  .target-document-shell .viewer-project-document-switcher,
  .target-document-shell .viewer-quick-actions {
    grid-column: 1 !important;
    width: 100%;
    max-width: 100%;
  }

  /* DESIGN-116: eine Reihe Seitenaktionen, darunter eine Reihe mit
     Theme-Schalter und Utilities, beide am 16-px-Rand. */
  .target-document-shell .viewer-topbar[data-stitch-viewer-chrome="single-row-toolbar"] .viewer-quick-actions[data-stitch-viewer-quick-actions="true"] {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center;
    justify-content: flex-start !important;
    gap: 8px !important;
    margin-left: 0;
    width: 100%;
  }

  .target-document-shell .viewer-theme-control,
  .target-document-shell .viewer-quick-actions > .author-global-utilities {
    order: 1;
    margin: 0 !important;
    max-width: 100%;
  }

  .target-document-shell .viewer-quick-actions > .author-global-utilities :is(.author-global-notifications, .author-global-feedback) {
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }

  .target-document-shell .viewer-document-text strong {
    max-width: min(52vw, 260px);
  }

  .target-document-shell .document-workspace[data-stitch-reader-desk="true"] {
    min-height: calc(100dvh - 64px);
    height: auto;
    padding-top: 0 !important;
  }

  .target-document-shell .viewer-workbench-toolbar[data-stitch-viewer-workbench-toolbar="true"] {
    position: static;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 16px;
  }

  .target-document-shell .viewer-nav-cluster[data-stitch-viewer-nav-cluster="true"] {
    max-width: 100%;
    margin: 0;
  }

  .target-document-shell .viewer-workbench-toolbar .page-controls .page-jump-label,
  .target-document-shell .viewer-workbench-toolbar .page-controls .page-count {
    padding-inline: 8px;
  }

  .target-document-shell .viewer-workbench-toolbar .page-controls input {
    width: 40px;
  }

  /* DESIGN-116: Die Werkzeuge sind direkte Glieder der Leiste. Erste Reihe:
     Navigation und Lesemodus, zweite Reihe: Einpassen und Zoom. */
  .target-document-shell .viewer-workbench-toolbar .viewer-tool-strip {
    display: contents !important;
  }

  .target-document-shell .viewer-workbench-toolbar .viewer-reader-mode-link {
    order: 1;
  }

  .target-document-shell .viewer-workbench-toolbar .viewer-fit-controls,
  .target-document-shell .viewer-workbench-toolbar .viewer-zoom-strip {
    order: 2;
    margin: 0 !important;
  }

  /* DESIGN-116: Die Kopfaktionen sind so hoch wie Glocke und
     „Problem melden“. */
  .target-document-shell .viewer-topbar[data-stitch-viewer-chrome="single-row-toolbar"] .viewer-quick-actions .viewer-topbar-action {
    min-height: 44px !important;
    padding: 0 14px !important;
    border-radius: 8px !important;
    font-size: 13px !important;
  }

  /* DESIGN-116: Die Randpfeile doppelten Vor/Zurück aus der Leiste und
     nahmen der Folie links und rechts je 48 px. */
  .target-document-shell .document-canvas-pane .page-stage-shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .target-document-shell .document-canvas-pane .stage-nav-button {
    display: none !important;
  }

  .target-document-shell .document-canvas-pane .page-stage {
    grid-column: 1 !important;
    padding: 16px 16px 24px !important;
  }

  .target-document-shell .document-canvas-pane[data-stitch-reader-document="true"] .toolbar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .target-document-shell .feedback-report-overlay {
    top: auto;
    bottom: 12px;
  }
}

/* DESIGN-116: „Lesemodus“ ist ein Werkzeugknopf wie seine Nachbarn, kein
   unterstrichener Link zwischen gerahmten Gruppen. */
.target-document-shell .viewer-workbench-toolbar[data-stitch-viewer-workbench-toolbar="true"] .viewer-reader-mode-link {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 46px !important;
  padding: 0 14px !important;
  border: 1px solid var(--k-line) !important;
  border-radius: 8px !important;
  background: var(--k-surface) !important;
  color: var(--k-text) !important;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none !important;
  white-space: nowrap;
}

.target-document-shell .viewer-workbench-toolbar[data-stitch-viewer-workbench-toolbar="true"] .viewer-reader-mode-link:hover {
  background: var(--k-surface-2) !important;
}

/* DESIGN-116: Ab 761px steht der Viewer-Kopf in einer Reihe. Die
   Aktionsgruppe hatte keine Mindestbreite; neben Dokument-Tabs schrumpfte sie,
   und „Schreibprüfung“ lief unter die Glocke. Die Aktionen behalten ihre
   Breite, Titel (mit Auslassung) und Tabs (scrollbar) geben nach. */
@media (min-width: 761px) {
  .target-document-shell .viewer-topbar[data-stitch-viewer-chrome="single-row-toolbar"] .viewer-quick-actions[data-stitch-viewer-quick-actions="true"] {
    min-width: max-content !important;
  }
}

/* DESIGN-117: „Neues Projekt“ steht wie auf allen Seiten vor Glocke und
   „Problem melden“. Eine Altregel aus der Zeit, als der Link direkt in der
   Aktionsleiste stand, schob ihn mit order: 1 ans Ende. */
.target-document-shell .author-global-utilities [data-global-upload-link="true"] {
  order: 0;
}

/* Die Tabs schrumpften unter ihre Textbreite und überlagerten sich; sie
   behalten ihre Breite, die Leiste scrollt. */
.target-document-shell .viewer-project-document-switcher a {
  flex: 0 0 auto;
}

/* Mit offener Seitenleiste steht der Theme-Schalter dort wie auf jeder
   anderen Seite; der Kopf zeigt keinen zweiten und gibt den Platz den Tabs. */
@media (min-width: 1181px) {
  html[data-workspace-sidebar-state="expanded"] .target-document-shell .viewer-theme-control {
    display: none !important;
  }
}

/* Bis 1180px ist der Kopf fest und einzeilig; der Titel behält Platz für
   seinen Anfang, die Tabs scrollen. */
@media (min-width: 1081px) and (max-width: 1180px) {
  .target-document-shell > .review-header.stitch-topbar.viewer-topbar[data-stitch-viewer-chrome="single-row-toolbar"] {
    grid-template-columns: 44px minmax(160px, 1fr) minmax(0, auto) auto !important;
  }
}

/* Bis 1080px steht der Kopf im Fluss: Die Dokument-Tabs bekommen eine eigene
   Reihe über die volle Breite. */
@media (min-width: 761px) and (max-width: 1080px) {
  .target-document-shell > .review-header.stitch-topbar.viewer-topbar[data-stitch-viewer-chrome="single-row-toolbar"] {
    grid-template-columns: 44px minmax(0, 1fr) auto !important;
    height: auto !important;
    row-gap: 8px !important;
    padding-block: 10px !important;
  }

  .target-document-shell > .viewer-topbar > .viewer-quick-actions {
    grid-column: 3 !important;
  }

  .target-document-shell > .viewer-topbar > .viewer-project-document-switcher {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    max-width: none !important;
  }
}

/* DESIGN-116: „Neues Projekt“ ist im Viewer bis 1080px ein ruhiges Symbol
   neben Glocke und „Problem melden“; den Namen trägt aria-label. */
@media (max-width: 1080px) {
  .target-document-shell .viewer-quick-actions .upload-shortcut[data-global-upload-link="true"] {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0 !important;
    justify-content: center;
    gap: 0 !important;
    border: 1px solid var(--k-line) !important;
    background: var(--k-surface) !important;
    color: var(--k-text) !important;
    box-shadow: none !important;
  }

  .target-document-shell .viewer-quick-actions .upload-shortcut[data-global-upload-link="true"] > span:not(.material-symbols-outlined) {
    display: none !important;
  }
}

/* DESIGN-116: Die Randpfeile neben der Folie sind ruhige Geschwister der
   Werkzeugknöpfe statt gefüllter Akzentflächen; die Akzentfarbe bleibt der
   einen Hauptaktion vorbehalten. */
.target-document-shell .document-canvas-pane .stage-nav-button {
  border: 1px solid var(--k-line) !important;
  border-radius: 8px !important;
  background: var(--k-surface) !important;
  color: var(--k-text) !important;
  box-shadow: none !important;
}

.target-document-shell .document-canvas-pane .stage-nav-button:hover {
  border-color: var(--k-line) !important;
  background: var(--k-surface-2) !important;
}

@media (max-width: 480px) {
  /* DESIGN-116: Auf dem Telefon springt das Seitenfeld zu jeder Seite; Erste
     und Letzte Seite entfallen, damit Navigation und Lesemodus eine Reihe sind. */
  .target-document-shell .viewer-workbench-toolbar #first-page,
  .target-document-shell .viewer-workbench-toolbar #last-page {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .target-document-shell *,
  .target-document-shell *::before,
  .target-document-shell *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
