:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #17202a;
  --muted: #667781;
  --line: #d7e0df;
  --accent: #0f8b8d;
  --accent-dark: #0a6e70;
  --green: #26805f;
  --yellow: #f2b84b;
  --red: #c74b43;
  --focus: #1d9bf0;
  --shadow: 0 12px 34px rgba(23, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

body.editor-locked {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
label {
  user-select: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand-title,
.panel-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-title {
  font-size: 19px;
  line-height: 1.15;
  font-weight: 700;
}

.app-version {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.brand p,
.panel-header p,
.status-line {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.toc-tools,
.page-controls,
.page-edit-tools,
.pdf-edit-tools,
.viewer-toolbar {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.tool-button,
.icon-button,
.drop-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.button,
.drop-action {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 700;
  text-decoration: none;
}

.button-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.button-accent {
  background: #173c45;
  color: white;
  border-color: #173c45;
}

.button:hover,
.tool-button:hover,
.icon-button:hover,
.drop-action:hover {
  border-color: var(--accent);
}

.button-primary:hover {
  background: var(--accent-dark);
}

.button-accent:hover {
  background: #0f3037;
}

button:disabled,
.button[aria-disabled="true"],
.tool-button[aria-disabled="true"],
.tool-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
label:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 32%, transparent);
  outline-offset: 2px;
}

.workspace {
  height: calc(100vh - 72px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 8px minmax(360px, var(--toc-width, 43vw));
  overflow: hidden;
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(15, 139, 141, 0.04), transparent 30%),
    var(--surface-2);
}

.drop-zone {
  display: grid;
  place-items: center;
  padding: 28px;
  overflow: auto;
}

/* Карточка-дропзона: дашед-рамка + «бумага» в линейку + весь поясняющий контент */
.drop-card {
  width: min(660px, 100%);
  box-sizing: border-box;
  padding: 30px 30px 26px;
  text-align: center;
  border: 2px dashed #a8b8b6;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.1), transparent 52%),
    repeating-linear-gradient(0deg, rgba(23, 32, 42, 0.05), rgba(23, 32, 42, 0.05) 1px, transparent 1px, transparent 26px),
    #ffffff;
  box-shadow: var(--shadow);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.drop-zone.drag-over .drop-card {
  border-color: var(--accent);
  box-shadow: 0 18px 44px rgba(15, 139, 141, 0.22);
  transform: translateY(-2px);
}

.drop-card__icon {
  display: inline-block;
  margin-bottom: 4px;
  filter: drop-shadow(0 6px 12px rgba(15, 139, 141, 0.18));
}

.drop-card__title {
  margin: 2px 0 6px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.2px;
  color: var(--ink);
}

.drop-card__subtitle {
  margin: 0 auto 16px;
  max-width: 460px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.drop-card__cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.drop-card .drop-action {
  min-width: 168px;
  min-height: 46px;
  font-size: 15px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(15, 139, 141, 0.26);
}

.drop-card .drop-action:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.drop-hint--btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  transform: rotate(-5deg);
}

.drop-hint__arrow {
  flex: 0 0 auto;
}

.drop-card__privacy {
  margin: 0 auto 16px;
  max-width: 540px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(15, 139, 141, 0.08);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
  text-align: left;
}

.drop-card__privacy b {
  color: #0c5e60;
}

/* Подсказка-плашка про демо-листалку: кликабельна (открывает флипбук), со стрелкой */
.drop-card__flip {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: 540px;
  margin: 0 auto;
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  text-align: left;
  background: linear-gradient(135deg, #6d49d9, #8b5cf6 55%, #5b7cf6);
  box-shadow: 0 8px 20px rgba(109, 73, 217, 0.3);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.drop-card__flip:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(109, 73, 217, 0.42);
}

.drop-card__flip-text {
  font-size: 13px;
  line-height: 1.35;
}

.drop-card__flip-arrow {
  flex: 0 0 auto;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  animation: flipArrowNudge 1.4s ease-in-out infinite;
}

@keyframes flipArrowNudge {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(5px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .drop-card__flip-arrow {
    animation: none;
  }
}

.viewer {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.viewer-toolbar {
  min-height: 58px;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  flex-wrap: wrap;
}

.page-controls {
  gap: 8px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.icon-button.strong {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.page-input {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.page-input input {
  width: 56px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  text-align: right;
  font-weight: 700;
}

.page-input input:focus {
  outline: none;
}

.zoom-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.zoom-control select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 8px;
}

.page-edit-tools,
.pdf-edit-tools {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-select {
  min-height: 34px;
  max-width: 148px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 8px;
  font-size: 13px;
}

.compact-select.small {
  max-width: 74px;
}

.font-select {
  max-width: 170px;
}

.number-input {
  width: 76px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 8px;
  font-size: 13px;
}

.color-input {
  width: 36px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 3px;
  cursor: pointer;
}

.tool-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.viewer-body {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(104px, var(--thumb-width, 154px)) 8px minmax(0, 1fr);
}

.thumbnail-rail {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.58);
}

.thumbnails-all {
  width: 100%;
}

.thumbnail-actions {
  display: grid;
  gap: 7px;
}

.thumbnail-actions .tool-button {
  width: 100%;
}

.thumbnail-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-right: 2px;
}

.thumbnail-button {
  position: relative;
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px;
  cursor: pointer;
  text-align: left;
}

.thumbnail-card-actions {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  z-index: 2;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.thumbnail-button:hover .thumbnail-card-actions,
.thumbnail-button.active .thumbnail-card-actions,
.thumbnail-button.selected .thumbnail-card-actions,
.thumbnail-button:focus-within .thumbnail-card-actions {
  opacity: 1;
  transform: translateY(0);
}

.thumb-action {
  min-width: 0;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.thumb-action:hover {
  border-color: var(--accent);
}

.thumb-action.danger {
  color: var(--red);
}

.thumb-action.rotate:hover {
  color: var(--accent);
}

.thumbnail-button.dragging {
  opacity: 0.46;
}

.thumbnail-button.drop-target {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--yellow) 32%, transparent);
}

.thumbnail-button:hover,
.thumbnail-button.active {
  border-color: var(--accent);
  background: #f5fbfa;
}

.thumbnail-button.selected {
  border-color: var(--focus);
  background: #f4f9ff;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 22%, transparent);
}

.thumbnail-button.active.selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent),
    inset 0 0 0 2px color-mix(in srgb, var(--focus) 36%, transparent);
}

.thumbnail-button canvas {
  display: block;
  width: 100%;
  height: auto;
  background: white;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(23, 32, 42, 0.1);
}

.thumbnail-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.canvas-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 26px;
  display: grid;
  align-content: start;
  justify-content: center;
}

.thumbnail-splitter {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: #edf3f2;
  color: var(--muted);
  cursor: col-resize;
  z-index: 3;
}

.thumbnail-splitter span {
  width: 22px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 900;
}

.page-stage {
  position: relative;
  width: max-content;
  height: max-content;
}

#pdfCanvas {
  display: block;
  background: white;
  border-radius: 3px;
  box-shadow: 0 18px 52px rgba(23, 32, 42, 0.18);
}

.annotation-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: auto;
}

.annotation-layer.tool-text,
.annotation-layer.tool-stamp {
  cursor: crosshair;
}

.annotation-layer.tool-draw {
  cursor: crosshair;
}

.annotation-item {
  position: absolute;
  min-width: 6px;
  min-height: 6px;
  border: 1px solid transparent;
  outline: 0;
  touch-action: none;
  cursor: pointer;
}

.annotation-item.selected {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 24%, transparent);
}

.annotation-text {
  display: block;
  width: 100%;
  height: 100%;
  padding: 2px 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  cursor: text;
}

.annotation-stamp {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 2px solid currentColor;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.annotation-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: auto;
}

.annotation-draw {
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border: 2px solid white;
  border-radius: 4px;
  background: var(--focus);
  cursor: nwse-resize;
  display: none;
}

.selection-box {
  position: absolute;
  border: 1px solid var(--focus);
  background: color-mix(in srgb, var(--focus) 14%, transparent);
  pointer-events: none;
}

.move-handle {
  position: absolute;
  left: -8px;
  top: -8px;
  width: 18px;
  height: 18px;
  display: none;
  place-items: center;
  border: 1px solid var(--focus);
  border-radius: 6px;
  background: white;
  color: var(--focus);
  cursor: move;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  z-index: 2;
}

.annotation-item.selected .resize-handle,
.annotation-item.selected .move-handle {
  display: block;
}

.annotation-item.selected .move-handle {
  display: grid;
}

.draw-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.workspace-splitter {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: #edf3f2;
  color: var(--muted);
  cursor: col-resize;
  z-index: 4;
}

.workspace-splitter span {
  width: 24px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 900;
}

body.resizing-workspace {
  cursor: col-resize;
  user-select: none;
}

body.resizing-thumbnails {
  cursor: col-resize;
  user-select: none;
}

.toc-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--surface);
}

.panel-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 18px;
}

.toc-tools {
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.tool-button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 700;
}

.tool-button.danger {
  color: var(--red);
}

.file-tool {
  display: inline-flex;
  align-items: center;
}

.toc-table {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toc-head,
.toc-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 70px 66px 208px;
  gap: 8px;
  align-items: center;
}

.toc-head {
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.toc-body {
  overflow: auto;
  padding: 10px 10px 12px;
}

.toc-row {
  min-height: 48px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}

.toc-row + .toc-row {
  margin-top: 4px;
}

.toc-row:hover,
.toc-row.selected {
  background: #f5fbfa;
  border-color: #cfe1df;
}

.toc-row.dragging {
  opacity: 0.52;
}

.title-cell {
  min-width: 0;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding-left: calc((var(--level) - 1) * 18px);
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  text-align: center;
  font-size: 18px;
}

.toc-row input,
.toc-row select {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 8px;
}

.toc-row input[type="number"] {
  text-align: right;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(6, 30px);
  gap: 5px;
  justify-content: end;
}

.row-actions .icon-button {
  width: 30px;
  height: 30px;
  font-size: 16px;
}

.row-actions .delete {
  color: var(--red);
}

.row-actions .child {
  color: var(--green);
}

.empty-toc {
  display: none;
  padding: 18px;
  border-top: 1px solid var(--line);
}

.empty-toc.visible {
  display: block;
}

.status-line {
  min-height: 38px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: #fbfcfc;
}

/* --- Рекламные блоки (Яндекс РСЯ) --- */
.ad-slot {
  display: none;
  position: relative;
}

/* Закрытие действует только до перезагрузки страницы */
.ad-slot.is-closed {
  display: none !important;
}

.ad-close {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.ad-close:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.ad-frame {
  width: 100%;
}

/* Маркировка рекламы (требование закона «О рекламе») */
.ad-label {
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
  margin-bottom: 6px;
}

/* Зона 1: горизонтальный баннер под листом PDF (десктоп) */
.ad-horizontal {
  display: grid;
  place-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
}

.ad-horizontal .ad-frame {
  max-width: 728px;
  min-height: 90px;
}

/* Колонка с таблицей TOC + вертикальной рекламой справа */
.toc-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.toc-main-content {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

/* Зона 2: вертикальный баннер в панели оглавления (десктоп) */
.ad-vertical {
  display: grid;
  align-content: start;
  justify-items: center;
  padding: 14px 12px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.5);
}

.ad-vertical .ad-frame {
  width: 240px;
  max-width: 100%;
  min-height: 400px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 42, 0.45);
}

.modal-card {
  position: relative;
  width: min(1060px, 94vw);
  max-height: min(840px, 90vh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(23, 32, 42, 0.26);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2,
.modal-header p {
  margin: 0;
}

.modal-header h2 {
  font-size: 18px;
}

.modal-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.modal-card-compact {
  grid-template-rows: auto minmax(0, auto);
  width: min(560px, 94vw);
  max-height: min(700px, 90vh);
}

.split-input {
  margin-top: 8px;
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

.pn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pn-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.pn-field .compact-select,
.pn-field .split-input {
  margin-top: 0;
  width: 100%;
  font-weight: 400;
}

.pn-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.pn-actions {
  margin-top: 12px;
}

/* Попап листалки albom.io: модал почти во весь экран + iframe на демо-страницу.
   Real3D рендерит сама демо-страница albom.io ВНУТРИ iframe (его контент = albom.io),
   поэтому даём полный размер — иначе движок неверно считает габариты страниц. */
#flipbookModal {
  padding: 2vmin;
}

.modal-card-flipbook {
  width: 96vw;
  max-width: none;
  height: 96vh;
  max-height: none;
}

.flipbook-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #14141a;
}

/* CTA в шапке попапа: «зарегистрируйтесь на albom.io» рядом с крестиком-закрытием */
.flipbook-cta {
  max-width: 320px;
  font-size: 12.5px;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  text-decoration: none;
}

@media (max-width: 760px) {
  .flipbook-cta {
    display: none; /* узкий экран — прячем длинный CTA, крестик остаётся */
  }
}

/* Кнопка «Превратить в Флипбук» под рекламой — стилизована под листающую книжку */
.flipbook-cta-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 45px;
  box-sizing: border-box;
  margin: 12px 0 0;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  color: #fff;
  background: linear-gradient(135deg, #6d49d9 0%, #8b5cf6 52%, #5b7cf6 100%);
  box-shadow:
    0 8px 22px rgba(109, 73, 217, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    filter 0.18s ease;
}

.flipbook-cta-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 30px rgba(109, 73, 217, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  filter: saturate(1.05);
}

.flipbook-cta-btn:active {
  transform: translateY(0);
}

.flipbook-cta-btn:focus-visible {
  outline: 3px solid rgba(139, 92, 246, 0.55);
  outline-offset: 2px;
}

.flipbook-cta-btn__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.flipbook-cta-btn__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.flipbook-cta-btn__hint {
  font-size: 11px;
  opacity: 0.85;
}

/* мини-книжка: две страницы + листающаяся поверх */
.flipbook-cta-btn__book {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 32px;
  perspective: 220px;
}

.fb-pg {
  position: absolute;
  top: 2px;
  width: 20px;
  height: 28px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(23, 16, 54, 0.25);
}

.fb-pg--left {
  left: 1px;
  border-radius: 3px 1px 1px 3px;
  background-image: repeating-linear-gradient(#fff 0 4px, #d9ccf7 4px 5px);
}

.fb-pg--right {
  right: 1px;
  border-radius: 1px 3px 3px 1px;
  background-image: repeating-linear-gradient(#fff 0 4px, #d9ccf7 4px 5px);
}

.fb-pg--flip {
  left: 22px;
  border-radius: 1px 3px 3px 1px;
  transform-origin: left center;
  background: linear-gradient(90deg, #efe9ff, #fff);
  animation: fbFlip 2.6s ease-in-out infinite;
}

@keyframes fbFlip {
  0%,
  14% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-168deg);
  }
  86%,
  100% {
    transform: rotateY(0deg);
  }
}

.flipbook-cta-btn:hover .fb-pg--flip {
  animation-duration: 1.1s;
}

@media (prefers-reduced-motion: reduce) {
  .fb-pg--flip {
    animation: none;
  }
}

.markdown-options {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--surface-2);
}

.md-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.md-option-body {
  min-width: 0;
}

.md-option h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.md-option p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.md-option .md-warn {
  color: var(--red);
}

.md-option .button {
  flex: none;
  white-space: nowrap;
}

#markdownProgress {
  margin: 2px;
  min-height: 18px;
}

.all-thumbnail-grid {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
  padding: 18px;
  background: var(--surface-2);
}

.hidden {
  display: none;
}

.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;
}

@media (max-width: 980px) {
  body.editor-locked {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .workspace-splitter {
    display: none;
  }

  .viewer-panel,
  .toc-panel {
    min-height: auto;
    height: auto;
  }

  .viewer-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .canvas-wrap {
    max-height: 68vh;
  }

  .toc-panel {
    min-height: 520px;
  }

  /* На планшете/телефоне — только один текстовый блок вместо баннеров */
  .ad-horizontal,
  .ad-vertical {
    display: none;
  }

  .toc-main {
    grid-template-columns: 1fr;
  }

  .ad-text {
    display: grid;
    place-items: center;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .ad-text .ad-frame {
    max-width: 600px;
    min-height: 90px;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions .button {
    flex: 1 1 110px;
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-edit-tools {
    justify-content: flex-start;
  }

  .pdf-edit-tools {
    justify-content: flex-start;
  }

  .viewer-body {
    grid-template-columns: minmax(96px, var(--thumb-width, 112px)) 8px minmax(0, 1fr);
  }

  .thumbnail-rail {
    padding: 10px 8px;
  }

  .canvas-wrap {
    padding: 16px;
  }

  .toc-head {
    display: none;
  }

  .toc-row {
    grid-template-columns: 1fr 66px 60px;
    align-items: start;
  }

  .title-cell {
    grid-column: 1 / -1;
  }

  .row-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(6, 34px);
    justify-content: start;
  }

  .row-actions .icon-button {
    width: 34px;
    height: 34px;
  }
}

/* --- Баннеры albom.io (заменяют РСЯ) --- */
.albom-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: #fff;
  border-radius: 12px;
  padding: 14px 18px;
  font-family: inherit;
  background: linear-gradient(120deg, #6d49d9 0%, #8b5cf6 46%, #5b7cf6 100%);
  box-shadow: 0 10px 26px rgba(91, 73, 180, 0.28);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.albom-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 80% at 100% 0%, rgba(255, 255, 255, 0.2), transparent 60%);
}

.albom-banner:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(91, 73, 180, 0.38);
  filter: saturate(1.05);
}

.albom-banner:active {
  transform: translateY(0);
}

.albom-banner:focus-visible {
  outline: 3px solid color-mix(in srgb, #6d49d9 45%, white);
  outline-offset: 2px;
}

.albom-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
}

.albom-icon--lg {
  width: auto;
  height: auto;
  background: transparent;
}

.albom-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.albom-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.15;
}

.albom-sub {
  font-size: 12.5px;
  line-height: 1.3;
  opacity: 0.92;
}

.albom-cta {
  flex: none;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  color: #5b3fc7;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}

.albom-cta--block {
  margin-left: 0;
}

.albom-brand {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  opacity: 0.72;
}

.albom-brand--lg {
  position: static;
  opacity: 0.9;
  font-size: 13px;
  margin-top: 2px;
}

.albom-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: #ffd76a;
  color: #5b3fc7;
}

.albom-banner--wide {
  min-height: 84px;
}

.albom-banner--tall {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  width: 240px;
  max-width: 100%;
  min-height: 400px;
  padding: 26px 18px 18px;
}

.albom-banner--tall .albom-title {
  font-size: 19px;
}

.albom-banner--tall .albom-sub {
  font-size: 13px;
}

@media (max-width: 560px) {
  .albom-banner--wide .albom-sub {
    display: none;
  }
  .albom-banner--wide .albom-icon {
    width: 44px;
    height: 44px;
  }
  .albom-banner--wide .albom-title {
    font-size: 14px;
  }
}

/* --- Листалка (встроенный canvas page-flip) --- */
.flipbook-card {
  /* Размер 90% экрана. ВАЖНО: перебиваем max-height:min(840px,90vh) из .modal-card,
     иначе высота режется до 840px (≈50% на больших экранах). */
  width: 90vw;
  height: 90vh;
  max-width: none;
  max-height: 92vh;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* Анимированная подсказка про QR-пульт рядом с кнопкой ▦ */
.flipbook-qr-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  color: #6d49d9;
  background: color-mix(in srgb, #6d49d9 12%, white);
  border: 1px solid color-mix(in srgb, #6d49d9 35%, transparent);
  animation: qrhint-pulse 1.7s ease-in-out infinite;
}

.flipbook-qr-hint .qrhint-arrow {
  display: inline-block;
  animation: qrhint-arrow 1.1s ease-in-out infinite;
}

.flipbook-qr-hint.hidden {
  display: none;
}

@keyframes qrhint-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(109, 73, 217, 0.45); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 7px rgba(109, 73, 217, 0); }
}

@keyframes qrhint-arrow {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

@media (max-width: 640px) {
  .flipbook-qr-hint { display: none; }
}

.flipbook-by {
  font-size: 13px;
  font-weight: 700;
  color: #6d49d9;
}

.flipbook-body {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 18px;
  overflow: auto;
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(109, 73, 217, 0.1), transparent 70%),
    var(--surface-2);
}

.flipbook-empty {
  display: grid;
  gap: 14px;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

.flipbook-empty p {
  margin: 0;
  max-width: 360px;
}

/* После базовых display, чтобы .hidden срабатывал поверх grid/flex. */
.flipbook-empty.hidden,
.flipbook-stage.hidden,
.flipbook-hint.hidden {
  display: none;
}

.flipbook-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 0;
}

.flipbook-book {
  position: relative;
  flex: none;
  width: min(560px, 72vw);
  perspective: 2200px;
  background: #fff;
  border-radius: 4px;
  filter: drop-shadow(0 18px 30px rgba(23, 32, 42, 0.28));
}

.flipbook-book img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

.flipbook-static {
  position: relative;
  z-index: 1;
}

.flipbook-leaf {
  position: absolute;
  inset: 0;
  z-index: 3;
  transform-origin: left center;
  backface-visibility: hidden;
  will-change: transform;
  transition: transform 0.62s cubic-bezier(0.2, 0.7, 0.25, 1);
}

.flipbook-leaf img {
  backface-visibility: hidden;
}

.flipbook-leaf::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.25s ease;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0) 38%);
}

.flipbook-leaf.is-turning::after {
  opacity: 1;
}

.flipbook-nav {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(23, 32, 42, 0.12);
}

.flipbook-nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.flipbook-nav:disabled {
  opacity: 0.4;
  cursor: default;
}

.flipbook-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.flipbook-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.flipbook-page-label {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.albom-footer-cta {
  background: linear-gradient(120deg, #6d49d9, #5b7cf6);
  border-color: #6d49d9;
  color: #fff;
}

.albom-footer-cta:hover {
  filter: brightness(1.06);
}

/* Real3D FlipBook — инлайн внутри попапа */
.flipbook-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Real3D заполняет тело попапа абсолютом (проверенный паттерн демо albomio —
   в сетке-центрировании Real3D не рассчитывал размеры и не рисовал страницы). */
.flipbook-real3d {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #fff;
  overflow: hidden;
}

.flipbook-real3d.hidden {
  display: none;
}

.flipbook-real3d > div,
.flipbook-real3d .flipbook-container,
.flipbook-real3d .flipbook-main-container {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* Пульт ДУ: QR-панель поверх листалки */
.flipbook-qr {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  width: min(290px, 80vw);
  padding: 16px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 44px rgba(23, 32, 42, 0.3);
  text-align: center;
}

.flipbook-qr.hidden {
  display: none;
}

.flipbook-qr-close {
  position: absolute;
  right: 8px;
  top: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.flipbook-qr-close:hover {
  color: var(--ink);
}

.flipbook-qr-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.flipbook-qr-code {
  width: 240px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
}

.flipbook-qr-code img,
.flipbook-qr-code canvas {
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
}

.flipbook-qr-cap {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.flipbook-qr-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
  min-height: 16px;
}
