/* Editor TipTap del Motor V2: figuras unificadas con tamaño continuo,
   flotado con texto alrededor, recorte y pie editable. */

.editable-note .ProseMirror {
  outline: none;
  min-height: 260px;
  white-space: pre-wrap;
  word-break: break-word;
}

.editable-note .ProseMirror::after {
  content: "";
  display: block;
  clear: both;
}

.editable-note .ProseMirror.ProseMirror-focused {
  outline: none;
}

/* ---------- Figura ---------- */

.v2-fig {
  position: relative;
  box-sizing: border-box;
  width: var(--fig-width, 60%);
  max-width: 100%;
  margin: 1.15rem auto;
}

.v2-fig[data-wrap="block"][data-align="left"] {
  margin-left: 0;
  margin-right: auto;
}

.v2-fig[data-wrap="block"][data-align="right"] {
  margin-left: auto;
  margin-right: 0;
}

.v2-fig[data-wrap="float-left"] {
  float: left;
  margin: 0.4rem 1.25rem 0.7rem 0;
}

.v2-fig[data-wrap="float-right"] {
  float: right;
  margin: 0.4rem 0 0.7rem 1.25rem;
}

.v2-fig-frame {
  position: relative;
  /* Hidden permits focus-induced scrolling, changing the visible crop. */
  overflow: clip;
  border-radius: 0;
  width: 100%;
  height: 100%;
}

.v2-fig-stage { position: relative; }
.v2-fig-surface { position: absolute; left: 50%; top: 50%; transform-origin: center; }
.v2-fig-angle { display: inline-flex; align-items: center; gap: 3px; color: #fff; }
.v2-fig-angle input { width: 60px; padding: 4px; border: 0; border-radius: 5px; background: #ffffff1a; color: #fff; font: inherit; font-size: 12px; }
.v2-fig-angle input:focus-visible { outline: 2px solid var(--ap-accent); }

.editable-note .v2-fig div { margin: 0; }

.v2-fig-img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  border-radius: 0;
}

.v2-fig-frame.cropped .v2-fig-img {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.v2-fig.missing-image .v2-fig-frame {
  min-height: 120px;
  outline: 1.5px dashed rgba(155, 28, 28, 0.55);
}

.v2-fig-caption {
  margin-top: 0.45rem;
  color: var(--ap-muted);
  font-size: 0.86em;
  line-height: 1.45;
  text-align: center;
  outline: none;
}

.v2-fig-caption:empty::before {
  content: attr(data-placeholder);
  opacity: 0.45;
}

/* Selección y arrastre */

.v2-fig.selected .v2-fig-frame,
.v2-fig.ProseMirror-selectednode .v2-fig-frame {
  outline: 2.5px solid var(--ap-accent);
  outline-offset: 2px;
}

.v2-fig.resizing .v2-fig-frame {
  outline: 2.5px dashed var(--ap-accent);
  outline-offset: 2px;
}

.ProseMirror-hideselection .v2-fig {
  caret-color: transparent;
}

/* ---------- Barra de la figura ---------- */

.v2-fig-toolbar {
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: var(--ap-radius-pill);
  background: rgba(17, 20, 27, 0.86);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  z-index: 5;
}

.v2-fig.selected .v2-fig-toolbar,
.v2-fig.ProseMirror-selectednode .v2-fig-toolbar,
.v2-fig:hover .v2-fig-toolbar {
  display: inline-flex;
}

.v2-fig.cropping .v2-fig-toolbar,
.v2-fig.resizing .v2-fig-toolbar {
  display: none;
}

.v2-fig-group {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}

.v2-fig-group + .v2-fig-group {
  margin-left: 4px;
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

.v2-fig-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--ap-radius-pill);
  background: transparent;
  color: #e8ecf4;
  font-size: var(--ap-text-meta);
  line-height: 1;
  cursor: pointer;
}

.v2-fig-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.v2-fig-btn.active {
  background: var(--ap-accent);
  color: #fff;
}

/* ---------- Asas de tamaño ---------- */

.v2-fig-handle {
  position: absolute;
  top: auto;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--ap-accent);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  cursor: nwse-resize;
  display: none;
  z-index: 6;
  touch-action: none;
  transform: translate(-50%, -50%);
}

.v2-fig-handle.nw { left: 0; top: 0; }
.v2-fig-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.v2-fig-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.v2-fig-handle.se { left: 100%; top: 100%; }
.v2-fig-handle::before { content: ""; position: absolute; inset: -8px; }
.v2-fig-rotate { position: absolute; top: -34px; left: 50%; transform: translateX(-50%); display: none; width: 26px; height: 26px; padding: 5px; border: 0; border-radius: 50%; background: var(--ap-accent); color: #fff; touch-action: none; cursor: grab; }
.v2-fig-rotate::before { content: ""; position: absolute; width: 1px; height: 10px; top: 100%; left: 50%; background: var(--ap-accent); }
.v2-fig-rotate svg { width: 100%; height: 100%; }
.v2-fig.selected .v2-fig-rotate, .v2-fig.ProseMirror-selectednode .v2-fig-rotate { display: block; }
.v2-fig.cropping .v2-fig-rotate { display: none; }
.v2-fig.rotating .v2-fig-toolbar { display: none; }
.v2-fig-handle:focus-visible, .v2-fig-rotate:focus-visible { outline: 2px solid var(--ap-ink); outline-offset: 3px; }

/* La barra se coloca sobre el espacio de giro, sin tapar el tirador. */
.v2-fig-toolbar { top: -78px; }
@media (max-width: 760px) {
  .v2-fig-toolbar { max-width: calc(100vw - 32px); flex-wrap: wrap; justify-content: center; border-radius: 12px; white-space: normal; }
}
@media print { .v2-fig-rotate { display: none !important; } }

.v2-fig.selected .v2-fig-handle,
.v2-fig.ProseMirror-selectednode .v2-fig-handle,
.v2-fig:hover .v2-fig-handle {
  display: block;
}

.v2-fig.cropping .v2-fig-handle {
  display: none;
}

.v2-fig-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: var(--ap-radius-pill);
  background: rgba(17, 20, 27, 0.82);
  color: #e8ecf4;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: none;
  z-index: 5;
  pointer-events: none;
}

.v2-fig.resizing .v2-fig-badge,
.v2-fig.selected .v2-fig-badge {
  display: inline-block;
}

.v2-fig.cropping .v2-fig-badge {
  display: none;
}

/* ---------- Recorte ---------- */

.v2-fig-crop {
  position: absolute;
  inset: 0;
  z-index: 8;
  touch-action: none;
}

.v2-fig-crop-shade {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 18, 0.55);
  pointer-events: none;
}

.v2-fig-crop-rect {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  cursor: move;
}

.v2-fig-crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--ap-accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.v2-fig-crop-handle.nw { top: -8px; left: -8px; cursor: nwse-resize; }
.v2-fig-crop-handle.ne { top: -8px; right: -8px; cursor: nesw-resize; }
.v2-fig-crop-handle.sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.v2-fig-crop-handle.se { bottom: -8px; right: -8px; cursor: nwse-resize; }

.v2-fig-crop-bar {
  position: absolute;
  width: max-content;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 5px 7px;
  border-radius: var(--ap-radius-pill);
  background: rgba(17, 20, 27, 0.9);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  z-index: 9;
}

.v2-fig[data-wrap="float-left"] .v2-fig-toolbar,
.v2-fig[data-wrap="float-left"] .v2-fig-crop-bar,
.v2-fig[data-align="left"][data-wrap="block"] .v2-fig-toolbar,
.v2-fig[data-align="left"][data-wrap="block"] .v2-fig-crop-bar {
  left: 0;
  transform: none;
}

.v2-fig[data-wrap="float-right"] .v2-fig-toolbar,
.v2-fig[data-wrap="float-right"] .v2-fig-crop-bar,
.v2-fig[data-align="right"][data-wrap="block"] .v2-fig-toolbar,
.v2-fig[data-align="right"][data-wrap="block"] .v2-fig-crop-bar {
  left: auto;
  right: 0;
  transform: none;
}

.v2-fig-crop-bar button {
  flex-shrink: 0;
  white-space: nowrap;
  border: 0;
  border-radius: var(--ap-radius-pill);
  padding: 5px 11px;
  font-size: var(--ap-text-label);
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  color: #e8ecf4;
}

.v2-fig-crop-bar .v2-fig-crop-apply {
  background: var(--ap-accent);
  color: #fff;
}

.v2-fig-crop-bar button:hover {
  filter: brightness(1.15);
}

/* ---------- Formatos enriquecidos (barra Docx) ---------- */

.editable-note .ProseMirror ul,
.editable-note .ProseMirror ol {
  margin: 0.35em 0 0.6em;
  padding-left: 1.7em;
}

.editable-note .ProseMirror ul { list-style: disc; }
.editable-note .ProseMirror ul ul { list-style: circle; }
.editable-note .ProseMirror ul ul ul { list-style: square; }
.editable-note .ProseMirror ol { list-style: decimal; }
.editable-note .ProseMirror ol[data-kind="lower-alpha"] { list-style-type: lower-alpha; }
.editable-note .ProseMirror ol[data-kind="upper-alpha"] { list-style-type: upper-alpha; }
.editable-note .ProseMirror ol[data-kind="lower-roman"] { list-style-type: lower-roman; }
.editable-note .ProseMirror ol[data-kind="upper-roman"] { list-style-type: upper-roman; }

.editable-note .ProseMirror li { margin: 0.12em 0; }
.editable-note .ProseMirror li > p { margin: 0; }
.editable-note .ProseMirror li > ul,
.editable-note .ProseMirror li > ol { margin: 0.1em 0 0.2em; }

.editable-note .ProseMirror code {
  padding: 0.05em 0.3em;
  border-radius: 4px;
  background: rgba(31, 41, 55, 0.07);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
}

[data-theme="dark"] .editable-note .ProseMirror code { background: rgba(255, 255, 255, 0.1); }

.editable-note .ProseMirror a {
  color: var(--ap-accent);
  text-decoration: underline;
  text-underline-offset: 0.12em;
  cursor: text;
}

.editable-note .ProseMirror mark {
  padding: 0 0.08em;
  border-radius: 2px;
  color: inherit;
}

.editable-note .ProseMirror s { text-decoration-thickness: 1.5px; }

hr.v2-page-break {
  position: relative;
  height: 0;
  margin: 1.5rem 0;
  border: 0;
  border-top: 2px dashed var(--ap-line-strong);
  overflow: visible;
}

hr.v2-page-break::after {
  content: "Salto de página";
  position: absolute;
  top: -0.75em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 10px;
  background: #fff;
  color: var(--ap-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

[data-theme="dark"] hr.v2-page-break::after { background: var(--ap-bg-deep); color: var(--ap-muted); }

hr.v2-page-break.ProseMirror-selectednode {
  outline: 2px solid var(--ap-accent);
  outline-offset: 6px;
  border-radius: 2px;
}

.editor-document-scroll .paper-sheet { zoom: var(--note-zoom, 1); }

/* Barra: zoom y menús compactos */

.editor-zoom {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 1px;
}

.editor-command-bar .editor-zoom > button {
  display: inline-flex;
  min-width: 30px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 9px;
  color: var(--muted-strong);
}

.editor-command-bar .editor-zoom > button:hover { color: var(--ink); background: var(--atlas-glass-strong); }
.editor-command-bar .editor-zoom > button:disabled { opacity: 0.35; cursor: default; }
.editor-command-bar .editor-zoom > .zoom-value {
  min-width: 54px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.editor-style-menu.compact > summary {
  min-width: 0;
  gap: 6px;
  padding: 0 8px 0 9px;
}

.editor-style-menu.compact > summary:empty::before { content: ""; }
.editor-style-menu > summary .swatch-icon {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.editor-style-menu .color-swatch {
  display: block;
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.85;
  border: 0;
  transform: none;
  box-shadow: none;
}

.editor-style-menu:is([data-format-menu="color"], [data-format-menu="highlight"]) > summary { background: transparent; box-shadow: none; }
.editor-style-menu:is([data-format-menu="color"], [data-format-menu="highlight"]) > summary:hover { background: var(--surface-soft); }

/* El espectro usa gradientes para representar colores, no como decoración. */
.editor-style-panel.editor-color-panel { display: block; width: min(312px, calc(100vw - 24px)); padding: 16px; border-radius: 14px; max-height: min(520px, calc(100dvh - 180px)); overflow-y: auto; background: var(--surface, #faf9f6); color: var(--ink); }
.color-panel-header, .color-value-row, .color-favorites-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.color-panel-header { position: sticky; top: 0; z-index: 2; flex-wrap: wrap; padding-block: 4px; margin-bottom: 10px; background: inherit; }
.color-panel-header > strong, .color-panel-header > button { flex: 0 0 auto; white-space: nowrap; }
.editor-color-panel strong { font-size: 13px; font-weight: 650; }
.editor-color-panel button { display: inline-flex; grid-template-columns: none; min-height: 32px; padding: 5px 8px; gap: 4px; font: inherit; font-size: 12px; text-align: center; justify-content: center; border: 0; border-radius: 6px; }
.editor-color-panel button:focus-visible, .editor-color-panel input:focus-visible, .color-spectrum:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 3px; }
.editor-color-panel button:disabled { opacity: .55; cursor: default; }
.color-panel-header button, .color-edit-favorites { color: var(--muted-strong, var(--ink)); }
.color-spectrum { position: relative; height: 142px; border-radius: 8px; touch-action: none; cursor: crosshair; background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, var(--spectrum-hue)); }
.color-spectrum-cursor { position: absolute; width: 13px; height: 13px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 1px 4px #0009; transform: translate(-50%, -50%); pointer-events: none; }
.color-hue { display: block; width: 100%; height: 12px; margin: 18px 0; padding: 0; appearance: none; border: 0; border-radius: 6px; background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); cursor: pointer; }
.color-hue::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; border: 2px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 1px 4px #0009; }
.color-hue::-moz-range-thumb { width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 1px 4px #0009; }
.color-value-row { margin-bottom: 14px; }
.color-preview { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 7px; outline: 1px solid color-mix(in srgb, var(--ink) 15%, transparent); outline-offset: -1px; }
.color-hex-label { display: flex; gap: 6px; align-items: center; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; }
.color-hex-label > span { font-size: 10px; color: var(--muted-strong); }
.color-hex { width: 82px; min-width: 0; padding: 0; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; }
.editor-color-panel .color-apply { padding-inline: 12px; background: var(--ap-accent); color: #fff; }
.editor-color-panel .color-apply:hover { background: var(--ap-accent-deep, #b41555); }
.color-quick, .color-favorites { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.color-quick { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.editor-color-panel .color-choice { position: relative; min-height: 30px; width: 100%; padding: 0; background: var(--choice-color); border-radius: 5px; box-shadow: inset 0 0 0 1px #0002; }
.editor-color-panel .color-choice:hover { background: var(--choice-color); outline: 2px solid var(--ink); outline-offset: 2px; }
.editor-color-panel .color-choice[aria-pressed="true"] { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.color-choice svg { width: 18px; height: 18px; padding: 2px; border-radius: 50%; background: #fff; fill: none; stroke: #171923; stroke-width: 1.7; }
.color-favorites-header { margin: 12px 0 7px; }
.color-favorites-empty { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted-strong); line-height: 1.45; }
.editor-color-panel .color-save-favorite { margin-top: 12px; width: 100%; background: var(--surface-soft); color: var(--ink); min-height: 36px; }
.color-error { font-size: 12px; color: var(--danger, #b42318); margin: 0 0 12px; line-height: 1.4; }
[data-theme="dark"] .editor-style-panel.editor-color-panel { background: #262622; }

.editor-style-menu .color-swatch.empty { opacity: 0.25; }

.editor-style-panel.palette {
  grid-template-columns: repeat(4, 1fr);
  width: 212px;
}

.editor-style-panel.palette .palette-reset {
  grid-column: 1 / -1;
  display: flex;
  min-height: 36px;
  justify-content: flex-start;
  font-size: var(--type-ui);
}

.editor-style-panel.palette button:not(.palette-reset) {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.editor-style-panel .color-dot {
  display: block;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 50%;
}

.editor-style-panel.palette button[aria-checked="true"] .color-dot { box-shadow: 0 0 0 2px var(--ap-bg), 0 0 0 4px var(--ap-accent); }

.editor-style-panel.size-panel { width: 200px; }
.editor-style-panel.size-panel button,
.editor-style-panel.list-panel button,
.editor-style-panel.font-panel button { min-height: 40px; padding: 6px 11px; }
.editor-style-panel.size-panel,
.editor-style-panel.list-panel,
.editor-style-panel.font-panel { max-height: min(60vh, 420px); overflow-y: auto; }
.editor-style-panel.font-panel { width: 250px; }
.editor-style-panel.list-panel { width: 250px; }
.editor-style-panel .list-sample { font-size: var(--ap-text-meta); letter-spacing: 0.02em; white-space: nowrap; }
.editor-style-panel .style-sample .icon { width: 16px; height: 16px; }

@media screen {
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar { min-height: 0; padding: 6px 10px; align-items: start; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools { flex-wrap: wrap; row-gap: 3px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-actions { align-self: start; margin-top: 2px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-context { align-self: start; margin-top: 2px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-style-menu > summary { min-width: 0; min-height: 36px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-style-menu:not(.compact) > summary { min-width: 104px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools > button,
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools > .toolbar-file-button { min-width: 34px; min-height: 36px; padding: 0 8px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools > button[data-editor-command]:disabled { opacity: 0.35; cursor: default; }
}

/* ---------- Impresión / exportación ---------- */

@media print {
  .v2-fig-toolbar,
  .v2-fig-handle,
  .v2-fig-rotate,
  .v2-fig-badge,
  .v2-fig-crop,
  .v2-fig-crop-bar {
    display: none !important;
  }

  .v2-fig.selected .v2-fig-frame,
  .v2-fig.ProseMirror-selectednode .v2-fig-frame {
    outline: none;
  }

  .v2-fig-caption:empty {
    display: none;
  }

  /* An image is never split across two pages. */
  .v2-fig {
    break-inside: avoid;
  }

  /* Unrotated images flow normally: an absolute surface lands off its page near a break. */
  .v2-fig:not([data-rotation]) .v2-fig-stage,
  .v2-fig[data-rotation="0"] .v2-fig-stage {
    aspect-ratio: auto !important;
  }

  .v2-fig:not([data-rotation]) .v2-fig-surface,
  .v2-fig[data-rotation="0"] .v2-fig-surface {
    position: relative;
    top: auto;
    left: auto;
    width: 100% !important;
    height: auto !important;
    transform: none !important;
  }
}

/* The wrapper has no layout effect outside the screen editor. */
.editor-document-scroll { display: contents; }

@media screen {
  html:has(body:is([data-route="document"], [data-route="summary"])),
  body:is([data-route="document"], [data-route="summary"]) { height: 100%; overflow: hidden; }
  body:is([data-route="document"], [data-route="summary"]) .app-shell {
    height: 100dvh;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
  }
  body:is([data-route="document"], [data-route="summary"]) .app-body {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  /* Leave the full height to the editor; the active timer keeps running. */
  body:is([data-route="document"], [data-route="summary"]) .topbar { display: none; }
  body:is([data-route="document"], [data-route="summary"]) .main-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  body:is([data-route="document"], [data-route="summary"]) .document-page {
    flex: 1;
    min-height: 0;
    display: flex;
    padding: 16px 12px 0;
    overflow: hidden;
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-shell {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f7f7f8;
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar {
    position: relative;
    top: auto;
    flex: 0 0 auto;
    width: 100%;
    min-height: 54px;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 8px;
    margin: 0;
    padding: 6px 10px;
    border-radius: 0;
    border-bottom: 1px solid var(--line);
    background: #fff;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .editor-command-bar .editor-context > span { display: none; }
  .editor-command-bar .editor-format-tools {
    grid-column: 2;
    grid-row: 1;
    flex-wrap: nowrap;
    gap: 3px;
  }
  .editor-command-bar .editor-actions { grid-column: 3; grid-row: 1; }
  .editor-command-bar .save-state { display: none; }
  .editor-command-bar .editor-style-menu > summary { min-width: 90px; }
  .editor-format-tools > button:disabled { opacity: .35; cursor: default; }
  .editor-format-tools > button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
  .editor-format-tools > button[data-action] > span,
  .editor-format-tools > .toolbar-file-button > span { display: none; }
  .editor-document-scroll {
    display: block;
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scroll-padding-block: 24px;
  }
  .editor-document-scroll:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
  .editor-document-scroll .paper-sheet { margin-top: 0; margin-bottom: 32px; }
  .v2-fig:hover:not(.selected):not(.ProseMirror-selectednode) .v2-fig-toolbar { opacity: 0; pointer-events: none; }
  :root[data-theme="dark"] .editor-shell { background: var(--ap-bg-deep); }
  :root[data-theme="dark"] .editor-command-bar { background: var(--ap-glass-3); }
  @container (max-width: 780px) {
    .editor-shell .editor-command-bar { grid-template-columns: 38px minmax(0, 1fr); }
    .editor-command-bar .editor-actions { grid-column: 2; grid-row: 1; width: auto; justify-self: end; }
    .editor-command-bar .editor-format-tools { grid-column: 1 / -1; grid-row: 2; flex-wrap: wrap; }
  }
  @media (max-width: 760px) {
    body:is([data-route="document"], [data-route="summary"]) .document-page { padding: 10px 0 0; }
    .editor-command-bar .editor-style-menu > summary { min-width: 80px; }
    .editor-command-bar .editor-format-tools { gap: 2px; }
  }
}

/* Reproductor del fragmento de audio en el panel de revisión */
.v2-audio-player {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--ap-radius-sm);
  background: color-mix(in srgb, var(--blue) 8%, var(--surface));
}
.v2-audio-toggle,
.v2-audio-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.v2-audio-toggle { background: var(--blue); border-color: var(--blue); color: #fff; }
.v2-audio-toggle .icon,
.v2-audio-close .icon { width: 16px; height: 16px; pointer-events: none; }
.v2-audio-toggle:hover,
.v2-audio-close:hover { filter: brightness(1.08); }
.v2-audio-toggle:focus-visible,
.v2-audio-close:focus-visible,
.v2-audio-seek:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.v2-audio-time {
  min-width: 42px;
  font-variant-numeric: tabular-nums;
  font-size: var(--type-meta);
  color: var(--ink);
  text-align: center;
}
.v2-audio-range { font-size: var(--type-meta); color: var(--muted); white-space: nowrap; }
.v2-audio-seek {
  width: 100%;
  min-width: 80px;
  height: 22px;
  margin: 0;
  accent-color: var(--blue);
  cursor: pointer;
}
@media (max-width: 760px) {
  .v2-audio-player { grid-template-columns: auto auto minmax(0, 1fr) auto auto; }
  .v2-audio-range { display: none; }
}

/* Texto con color fijado que no se lee sobre la hoja del tema (lo marca el plugin
   v2ReadableColor del editor). Solo pantalla: el documento conserva su color. */
:root[data-theme="dark"] .ProseMirror .ap-unreadable-on-dark { color: var(--ap-readable-dark) !important; }
:root:not([data-theme="dark"]) .ProseMirror .ap-unreadable-on-light { color: var(--ap-readable-light) !important; }

/* Temas repartidos entre grabaciones */
.topic-upload { display: grid; gap: .4rem; margin: .75rem 0; }
.topic-continuation, .topic-summary, .topic-provisional { margin: .5rem 0; font-size: .92rem; }
.topic-provisional { color: var(--muted, #6b6b6b); }
.topic-recordings { margin: .5rem 0; font-size: .92rem; }
.topic-recordings p { margin: 0; color: var(--muted, #6b6b6b); }
.topic-recordings ol { margin: .2rem 0 0; padding-inline-start: 1.4rem; }
.topic-recordings li { overflow-wrap: anywhere; }
.topic-recordings .topic-recording-adding { margin-top: .2rem; font-style: italic; }
.topic-continues-next { display: inline-flex; gap: .5rem; align-items: center; cursor: pointer; }
/* Menú «⋯ Opciones del tema» en la cabecera del panel de Bloopy (20-10-2026). */
.topic-menu { flex: none; align-self: flex-start; }
.topic-menu.class-actions-menu .space-actions-panel { width: max-content; min-width: 240px; max-width: min(320px, calc(100vw - 48px)); }
.topic-menu .space-actions-panel button { white-space: normal; }
.topic-menu-check { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 9px; align-items: center; min-height: 38px; padding: 0 10px; border-radius: 10px; color: var(--muted-strong); font-size: var(--type-meta); cursor: pointer; }
.topic-menu-check:hover { background: var(--accent-soft); color: var(--blue); }
.topic-menu-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--blue); }
@media (pointer: coarse) { .topic-menu-check { min-height: 44px; } }
.v2-engine-panel:has(.topic-menu[open]) { overflow: visible; z-index: 6; position: relative; }
/* En móvil la cabecera se apila y el «⋯» quedaba al final: el menú se abría fuera de la pantalla. */
@media (max-width: 760px) {
  .v2-engine-panel { position: relative; }
  .v2-engine-panel > header > .topic-menu { position: absolute; z-index: 2; top: 14px; right: 14px; }
}
.topic-cut-list { max-height: 55vh; overflow-y: auto; display: grid; gap: .15rem; }
.topic-cut-sentence { margin: 0; padding: .25rem .5rem; }
.topic-cut-gap { height: .9rem; border: 0; background: transparent; cursor: pointer; border-radius: .4rem; }
.topic-cut-gap:hover, .topic-cut-gap:focus-visible { background: color-mix(in srgb, var(--accent, #3b6fd8) 18%, transparent); }
.topic-cut-divider { display: flex; gap: .5rem; align-items: center; padding: .35rem .5rem; border-top: 2px solid var(--accent, #3b6fd8); font-weight: 600; }
/* Recortar audio: lo tachado sale de los apuntes. Inicio y final marcados en la propia frase. */
.modal.topic-trim-modal { width: min(760px, calc(100vw - 32px)); }
.topic-trim-recording { display: grid; gap: .4rem; margin-block: .75rem; }
.topic-trim-recording h3 { margin: 0; font-size: .95rem; }
.topic-trim-kept { margin: 0; color: var(--muted-strong); font-size: .88rem; }
.topic-trim-list { list-style: none; margin: 0; padding: 0; max-height: 42vh; overflow-y: auto; border: 1px solid var(--line); border-radius: .6rem; }
.topic-trim-row { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.topic-trim-row:last-child { border-bottom: 0; }
.topic-trim-text p { margin: 0; overflow-wrap: anywhere; }
.topic-trim-time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.topic-trim-badge:empty { display: none; }
.topic-trim-badge { display: inline-block; margin-bottom: .15rem; padding: .05rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 600; color: #fff; background: var(--accent, #3b6fd8); }
.topic-trim-marks { display: flex; gap: .75rem; align-items: center; }
.topic-trim-marks .text-action { font-size: .8rem; white-space: nowrap; }
.topic-trim-row.is-trimmed .topic-trim-text p { text-decoration: line-through; opacity: .45; }
.topic-trim-row.is-start { box-shadow: inset 0 2px 0 var(--accent, #3b6fd8); }
.topic-trim-row.is-end { box-shadow: inset 0 -2px 0 var(--accent, #3b6fd8); }
.topic-trim-row.is-start.is-end { box-shadow: inset 0 2px 0 var(--accent, #3b6fd8), inset 0 -2px 0 var(--accent, #3b6fd8); }
@media (max-width: 560px) {
  .topic-trim-row { grid-template-columns: auto 1fr; }
  .topic-trim-marks { grid-column: 2; justify-content: flex-start; gap: .9rem; }
}

/* Continuous reading sheet: size against the editor, including sidebar changes. */
@media screen {
  body:is([data-route="document"], [data-route="summary"]) .editor-document-scroll .paper-sheet {
    box-sizing: border-box;
    width: min(var(--note-paper-width, 820px), calc(100% - 32px));
    max-width: none;
    margin: 0 auto 32px;
    padding-inline: min(var(--note-margin-inline, 72px), clamp(20px, 8cqi, 120px));
    border-radius: 3px;
  }
}

@media screen and (min-width: 981px) {
  body:is([data-route="document"], [data-route="summary"]) .app-shell:not(.sidebar-collapsed) {
    grid-template-columns: var(--sidebar-current-width, 286px) minmax(0, 1fr);
  }
}

/* Compact screen controls and page header; document content and export stay intact. */
@media screen {
  body:is([data-route="document"], [data-route="summary"]) .editor-shell .editor-command-bar {
    grid-template-columns: 36px minmax(0, 1fr) auto;
    grid-template-rows: auto;
    gap: 6px 10px;
    min-height: 56px;
    padding: 8px 12px;
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-context { grid-column: 1; grid-row: 1; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-context > span { display: none; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-actions { grid-column: 3; grid-row: 1; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools {
    grid-column: 2;
    grid-row: 1;
    flex-wrap: nowrap;
    padding-top: 0;
    border-top: 0;
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools { flex-wrap: wrap; gap: 4px 10px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-detail-tools {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding-top: 4px;
    border-top: 1px solid var(--ap-line);
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group { display: flex; align-items: center; gap: 2px; min-width: 0; }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group + .editor-tool-group { padding-left: 8px; border-left: 1px solid var(--ap-line); }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > button,
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > .toolbar-file-button {
    min-width: 30px;
    min-height: 36px;
    padding: 0 6px;
    flex-shrink: 0;
  }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > button > span,
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > .toolbar-file-button > span { display: none; }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > button:disabled { opacity: .35; cursor: default; }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > button[aria-pressed="true"] { color: var(--blue); background: color-mix(in srgb, var(--blue) 13%, transparent); }
  body:is([data-route="document"], [data-route="summary"]) .editor-tool-group > button:focus-visible { outline: 2px solid var(--ap-ink); outline-offset: 2px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-style-menu > summary { min-width: 30px; min-height: 36px; padding: 0 6px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-style-menu:not(.compact) > summary { min-width: 82px; }
  body:is([data-route="document"], [data-route="summary"]) [data-format-menu="font"] > summary > span { max-width: 116px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-style-panel { max-height: min(220px, 40vh); overflow-y: auto; }
  body:is([data-route="document"], [data-route="summary"]) .document-page { padding-top: 20px; }
  body:is([data-route="document"], [data-route="summary"]) .editor-document-scroll .paper-sheet { padding-top: 48px; }
  body:is([data-route="document"], [data-route="summary"]) .paper-sheet > .paper-rule { margin: 20px 0 32px; }
  body:is([data-route="document"], [data-route="summary"]) .paper-sheet .editable-note { padding-top: 0; }
  @container (max-width: 720px) {
    body:is([data-route="document"], [data-route="summary"]) .editor-shell .editor-command-bar { grid-template-columns: 36px minmax(0, 1fr); }
    body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-actions { grid-column: 2; }
    body:is([data-route="document"], [data-route="summary"]) .editor-command-bar .editor-format-tools { grid-column: 1 / -1; grid-row: 2; }
    body:is([data-route="document"], [data-route="summary"]) .editor-detail-tools { grid-row: 3; }
    body:is([data-route="document"], [data-route="summary"]) .editor-format-tools .editor-tool-group { flex-wrap: wrap; }
  }
}

/* ── Exportación a PDF ─────────────────────────────────────────────────────
   La hoja va sin margen de página: así el navegador no imprime su cabecera y su pie
   (fecha, título y la dirección de la app). Los márgenes los pone la propia hoja y se
   repiten en cada página. El prefijo `body` gana a las reglas de impresión antiguas de
   styles.css y liquid-glass.css, que también usan !important; para la hoja manda esto. */
@page bloopy-doc { size: A4; margin: 0; }

.pdf-brand,
.pdf-slogans,
.pdf-cta { display: none; }

@media print {
  /* Colores fijos en papel: el tema oscuro no debe cambiarlos. */
  body {
    --pdf-ink: #1f1419;
    --pdf-text: #1b1b1a;
    --pdf-accent: #c8215f;
    --pdf-side: 15mm;
  }
  /* Todo el documento en la misma página con nombre: lo vacío que queda tras la hoja
     abriría si no una última página con el margen normal y la dirección de la app. */
  body:has(.document-page .paper-sheet) { page: bloopy-doc; }
  /* El fondo ilustrado de la app es fijo: en papel acaba en una página propia. */
  body:has(.document-page .paper-sheet)::before,
  body:has(.document-page .paper-sheet)::after { content: none !important; display: none !important; }
  /* Los contenedores de la pantalla no aportan márgenes: la hoja empieza en el borde de la
     página (los eslóganes se colocan contando desde ahí, así que nada visible puede ir antes
     de la hoja) y nada sobra tras ella. */
  body:has(.document-page .paper-sheet) :is(.app-shell, .app-body, .main-content, .document-page, .editor-shell) {
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
  }
  body .document-page .paper-sheet {
    position: relative;
    zoom: 1;
    padding: 14mm var(--pdf-side) !important;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }
  body .paper-sheet .paper-kicker {
    margin: 0 0 2.5mm;
    color: var(--pdf-accent) !important;
    font-size: 7.5pt;
    font-weight: 700;
    letter-spacing: 0.14em;
  }
  body .paper-sheet h1,
  body .paper-sheet .document-title-editor {
    max-width: none;
    color: var(--pdf-ink) !important;
    font-family: var(--ap-font-display);
    font-size: 24pt !important;
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: -0.025em;
  }
  body .paper-sheet > .paper-rule {
    height: 0;
    margin: 5mm 0 6mm;
    border-top: 0.6pt solid rgba(31, 20, 25, 0.16);
    background: none;
  }
  body .paper-sheet > .paper-rule::after { display: none; }
  body .paper-sheet .editable-note {
    max-width: none;
    min-height: 0;
    padding-top: 0;
    color: var(--pdf-text) !important;
    font-size: 10.5pt !important;
    line-height: 1.55 !important;
  }
  body .paper-sheet .editable-note :is(p, li) { orphans: 3; widows: 3; }
  body .paper-sheet .editable-note p,
  body .paper-sheet .editable-note div { margin: 0 0 2.8mm; }
  body .paper-sheet .editable-note :is(ul, ol) { margin: 0 0 2.8mm; padding-left: 6mm; }
  body .paper-sheet .editable-note h2 {
    margin: 7mm 0 2.5mm;
    color: var(--pdf-ink);
    font-family: var(--ap-font-display);
    font-size: 15pt;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.015em;
    break-after: avoid;
  }
  body .paper-sheet .editable-note h3 {
    margin: 5mm 0 2mm;
    color: var(--pdf-ink);
    font-size: 12pt;
    font-weight: 650;
    line-height: 1.25;
    break-after: avoid;
  }
  body .paper-sheet .editable-note > :first-child,
  body .paper-sheet .editable-note .ProseMirror > :first-child { margin-top: 0; }
  /* Nada de margen al final: sumado al relleno de la hoja, abriría una página en blanco. */
  body .paper-sheet .editable-note .ProseMirror { min-height: 0; margin: 0; }
  body .paper-sheet .editable-note .ProseMirror > :last-child,
  body .paper-sheet .editable-note .ProseMirror > :last-child > :last-child { margin-bottom: 0; }
  body .paper-sheet .editable-note figcaption { font-size: 8.5pt; line-height: 1.35; }

  /* Con marca: cabecera con Bloop, marca de agua y un eslogan en el pie de cada página. */
  body.pdf-branded .document-page .paper-sheet { padding: 21mm var(--pdf-side) 19mm !important; }
  /* Sin caja propia: un bloque al final del documento abriría otra página con el margen normal. */
  body.pdf-branded .pdf-brand { display: contents; }
  .pdf-brand-head {
    position: fixed;
    top: 8mm;
    left: var(--pdf-side);
    right: var(--pdf-side);
    display: flex;
    align-items: center;
    gap: 2mm;
    padding-bottom: 2.4mm;
    border-bottom: 0.6pt solid rgba(200, 33, 95, 0.28);
    color: #6e6068;
    font-family: var(--ap-font);
    font-size: 8.5pt;
    line-height: 1;
  }
  /* El logo de la app: la gota y «bloopy.» con el punto rosa. */
  .pdf-brand-head img { width: 5.6mm; height: 5.6mm; }
  .pdf-brand-head .ap-wordmark { margin-left: -1mm; color: var(--pdf-ink); font-family: var(--ap-font-display); font-size: 12pt; font-weight: 800; letter-spacing: -0.045em; }
  .pdf-brand-head .ap-wordmark i { font-style: normal; color: #ff4d8b; }
  .pdf-brand-head a { margin-left: auto; color: var(--pdf-accent); font-weight: 650; text-decoration: none; }
  /* Llamada a probar Bloopy (PDF de la administración): recuadro al principio o página final. */
  body.pdf-branded .pdf-cta { display: grid; }
  .pdf-cta { gap: 1.6mm; color: var(--pdf-ink); font-family: var(--ap-font); break-inside: avoid; }
  .pdf-cta strong { font-family: var(--ap-font-display); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
  .pdf-cta p { margin: 0; line-height: 1.4; }
  .pdf-cta a { justify-self: start; color: var(--pdf-accent); font-weight: 700; text-decoration: none; }
  .pdf-cta-start {
    margin: 0 0 7mm;
    padding: 4mm 5mm;
    border: 0.8pt solid rgba(200, 33, 95, 0.45);
    border-radius: 3mm;
    background: #fff1f6;
    font-size: 10pt;
  }
  .pdf-cta-start strong { font-size: 12.5pt; }
  .pdf-cta-end {
    break-before: page;
    align-content: center;
    gap: 5mm;
    min-height: 200mm;
    padding: 0 8mm;
    font-size: 12pt;
  }
  .pdf-cta-end strong { font-size: 26pt; color: var(--pdf-accent); }
  .pdf-cta-end small { color: #6e6068; font-size: 9.5pt; }
  .pdf-cta-end a {
    margin-top: 4mm;
    padding: 3.5mm 6mm;
    border-radius: 99px;
    background: var(--pdf-accent);
    color: #fff;
    width: max-content;
  }
  .pdf-brand-watermark {
    position: fixed;
    top: 50%;
    left: 0;
    right: 0;
    z-index: 10;
    transform: translateY(-50%);
    color: rgba(255, 77, 139, 0.1);
    font-family: var(--ap-font-display);
    font-size: 82pt;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    /* Encima de todo pero multiplicando: el texto sigue negro y el blanco se tiñe de rosa. */
    mix-blend-mode: multiply;
    pointer-events: none;
  }
  /* El carril cubre la hoja hasta el final de su última página (alto redondeado a páginas
     enteras, así el pie de la última página no se corta) y recorta lo que sobra sin crear
     páginas nuevas. */
  body.pdf-branded .pdf-slogans {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(round(up, 100%, 1123px) - 1px);
    contain: strict;
    pointer-events: none;
  }
  .pdf-slogans p {
    position: absolute;
    /* Chrome pagina el A4 cada 1123 px enteros, no 297 mm (1122,5 px): con 297 mm el pie
       se iría subiendo medio píxel por página. */
    top: calc(var(--pdf-page) * 1123px + 283mm);
    left: var(--pdf-side);
    right: var(--pdf-side);
    margin: 0;
    padding: 1mm 0;
    color: var(--pdf-accent);
    font-family: var(--ap-font-display);
    font-size: 9pt;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.005em;
    text-align: center;
  }
}
