/* ==========================================================================
   Editor con página tipo Word: diseño de página, encabezado, cuerpo, pie
   e imágenes (1 mm = 3.7795 px en pantalla)
   ========================================================================== */
.page-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 4px 0 8px; }
.page-bar-sep { width: 1px; height: 24px; background: var(--line-2); }
.page-bar-hint { margin-left: auto; font-size: 13px; color: var(--muted); }
.page-bar-hint b { color: var(--accent-ink); }
.editor-tips { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; }
.editor-tips .ico { color: var(--warn); width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-2); user-select: none; position: relative; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 38px; height: 22px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .25s; flex-shrink: 0; }
.switch-ui::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .3s var(--spring); }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

.toolbar-slot { position: sticky; top: 0; z-index: 15; }
.toolbar-slot .ql-toolbar.ql-snow { border: 1px solid var(--line); border-radius: 12px 12px 0 0; background: #fff; box-shadow: var(--shadow-sm); display: flex; align-items: center; flex-wrap: wrap; row-gap: 4px; }
.toolbar-slot .ql-toolbar[hidden] { display: none !important; }
.tb-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #fff; background: var(--accent); border-radius: 6px; padding: 2px 8px; margin-right: 10px; }

/* Cinta de diseño de página */
.ribbon {
    display: flex; flex-wrap: wrap; align-items: stretch; margin: 14px 0 10px; background: #fff;
    border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.rb-group { display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; border-right: 1px solid var(--line); justify-content: center; }
.rb-group:last-child { border-right: 0; }
.rb-end { margin-left: auto; flex-direction: row; align-items: center; gap: 10px; }
.rb-title { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.rb-row { display: flex; gap: 6px; align-items: center; }
.ribbon select { padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff; font-size: 13px; max-width: 190px; outline: none; }
.ribbon select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
.ribbon .rb-narrow { width: 74px; }
.rb-mini { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 2px; }
.seg button { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.seg-page { width: 10px; height: 13px; border: 1.5px solid currentColor; border-radius: 2px; }
.seg-page.land { width: 13px; height: 10px; }
.rb-pages { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--ok); background: var(--ok-soft); padding: 6px 10px; border-radius: 9px; transition: all .3s; white-space: nowrap; }
.rb-pages .ico { width: 15px; height: 15px; }
.rb-pages.many { color: #b91c1c; background: #fef2f2; }
.margin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; margin-top: 6px; }
.margin-form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.margin-form input { padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 10px; font: inherit; }
.margin-form .full { grid-column: 1 / -1; }

/* Hoja */
.editor-paper { background: #e9ebf2; border-radius: 0 0 16px 16px; padding: 24px 16px 40px; overflow-x: auto; }
.page {
    --pw: 816px; --ph: 1056px; --mt: 83px; --mb: 83px; --ml: 75.6px; --mr: 75.6px; --hd: 37.8px; --fd: 18.9px;
    --ff: 'Arial'; --fs: 11pt; --lh: 1.323; --sb: 0pt; --sa: 6pt;
    position: relative; width: var(--pw); min-height: var(--ph); margin: 0 auto; background: #fff; flex-shrink: 0;
    box-shadow: 0 8px 30px rgba(21, 26, 45, .14); display: flex; flex-direction: column;
    font-family: var(--ff), Arial, sans-serif; font-size: var(--fs); line-height: var(--lh); color: #1f2430;
    text-align: left;
}
.page .ql-container.ql-snow { border: 0; font: inherit; }
.page .ql-editor { padding: 0; line-height: inherit; overflow: visible; font: inherit; }
.page .ql-editor p, .page .doc-html p { margin: var(--sb) 0 var(--sa); }
.page .ql-editor h1, .page .doc-html h1 { font-size: 20pt; margin: 0 0 10pt; line-height: 1.2; }
.page .ql-editor h2, .page .doc-html h2 { font-size: 15pt; margin: 8pt 0; line-height: 1.2; }
.page .ql-editor h3, .page .doc-html h3 { font-size: 12.5pt; margin: 6pt 0; line-height: 1.2; }
.page .ql-editor table, .page .doc-html table { border-collapse: collapse; width: 100%; }
.page .ql-editor td, .page .doc-html td { border: 1px solid #c9ced8; padding: 5px 8px; }
.page .ql-editor.ql-blank::before { left: 0; right: 0; font-style: normal; color: #a3a9bd; }
.page .doc-html .ql-align-center { text-align: center; }
.page .doc-html .ql-align-right { text-align: right; }
.page .doc-html .ql-align-justify { text-align: justify; }
.page .ql-editor .ql-indent-1, .page .doc-html .ql-indent-1 { padding-left: 48px; }
.page .ql-editor .ql-indent-2, .page .doc-html .ql-indent-2 { padding-left: 96px; }
.page .ql-editor .ql-indent-3, .page .doc-html .ql-indent-3 { padding-left: 144px; }
.page .ql-editor .ql-indent-4, .page .doc-html .ql-indent-4 { padding-left: 192px; }
.page .ql-editor .ql-indent-5, .page .doc-html .ql-indent-5 { padding-left: 240px; }
.page .ql-editor .ql-indent-6, .page .doc-html .ql-indent-6 { padding-left: 288px; }
.page img { max-width: 100%; }
.page hr.page-break { border: 0; border-top: 2px dashed #f59e0b; margin: 10px 0; height: 0; position: relative; overflow: visible; }
.page.editing hr.page-break::after {
    content: var(--l-pagebreak); position: absolute; left: 50%; top: -10px; transform: translateX(-50%);
    background: #fff7e6; color: #b45309; font: 600 10.5px 'Inter', sans-serif; padding: 1px 8px; border-radius: 6px;
}
.page:not(.editing) hr.page-break { border-top-color: transparent; }

/* Zonas: el encabezado ocupa el margen superior y el pie el inferior (como en Word) */
.zone { position: relative; flex-shrink: 0; transition: background .2s; }
.zone-header { height: var(--mt); border-bottom: 1.5px dashed transparent; }
.zone-footer { height: var(--mb); margin-top: auto; border-top: 1.5px dashed transparent; }
.page.editing .zone-header { border-bottom-color: #e3e5ef; }
.page.editing .zone-footer { border-top-color: #e3e5ef; }
.page.editing:not(.no-header) .zone-header { border-bottom-color: #c7cbff; }
.page.editing:not(.no-footer) .zone-footer { border-top-color: #c7cbff; }
.page.editing .zone.active { background: rgba(79, 70, 229, .04); }
.zone-text { position: absolute; left: var(--ml); right: var(--mr); z-index: 2; }
.zone-header .zone-text { top: var(--hd); }
.zone-footer .zone-text { top: var(--fd); }
.zone-text .ql-editor p, .zone-text .doc-html p { margin: 0; line-height: 1.25; }
.zone-text .ql-editor { min-height: 20px; }
.page.no-header .zone-header .zone-text, .page.no-header .zone-header .float-layer, .page.no-header .zone-header .zone-tag,
.page.no-footer .zone-footer .zone-text, .page.no-footer .zone-footer .float-layer, .page.no-footer .zone-footer .zone-tag { display: none; }
.zone-tag {
    position: absolute; left: 8px; z-index: 4; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--accent); background: #eef0ff; padding: 1px 8px; opacity: 0; transition: opacity .2s; pointer-events: none; font-family: 'Inter', sans-serif;
}
.zone-header .zone-tag { bottom: -19px; border-radius: 0 0 6px 6px; }
.zone-footer .zone-tag { top: -19px; border-radius: 6px 6px 0 0; }
.page.editing .zone:hover .zone-tag, .page.editing .zone.active .zone-tag { opacity: 1; }
.zone-resize { position: absolute; left: 0; right: 0; height: 12px; cursor: ns-resize; z-index: 6; display: none; }
.zone-header .zone-resize { bottom: -7px; }
.zone-footer .zone-resize { top: -7px; }
.page.editing .zone-resize { display: block; }
.zone-resize::after { content: ''; position: absolute; left: 50%; top: 4px; width: 48px; height: 4px; margin-left: -24px; border-radius: 4px; background: var(--accent); opacity: 0; transition: opacity .2s; }
.zone:hover .zone-resize::after, .zone-resize.dragging::after { opacity: .6; }
.zone-body { flex: 1; padding: 0 var(--mr) 0 var(--ml); position: relative; z-index: 1; }
.page.editing .zone-body .ql-editor { min-height: 200px; }

/* Guías de fin de página */
.page-guides { position: absolute; left: 0; right: 0; top: 0; height: 0; pointer-events: none; z-index: 5; }
.page-guide { position: absolute; left: 0; right: 0; border-top: 1.5px dashed #ef4444; }
.page-guide span {
    position: absolute; right: 8px; top: -10px; background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
    font: 600 10.5px 'Inter', sans-serif; padding: 0 8px; border-radius: 6px; white-space: nowrap; line-height: 18px;
}
.page-guide.manual { border-top-color: transparent; }
.page-guide.manual span { background: #fff7e6; color: #b45309; border-color: #fde4b8; }

/* Imágenes flotantes (encabezado / pie) */
/* La capa no crea contexto propio: cada imagen decide si va delante (z 3) o detrás (z 0) del texto */
.float-layer { position: absolute; inset: 0; pointer-events: none; }
.page-layer { top: 0; left: 0; right: 0; bottom: auto; height: 0; overflow: visible; }
.float-img { position: absolute; pointer-events: auto; cursor: move; touch-action: none; user-select: none; z-index: 3; }
.float-img.behind { z-index: 0; }
.float-img.lifted { z-index: 7; opacity: .7; }
.fi-grip {
    position: absolute; z-index: 8; width: 22px; height: 22px; margin: -8px 0 0 -8px; border-radius: 50%;
    background: var(--accent); color: #fff; display: grid; place-items: center; pointer-events: auto; cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, .45); border: 2px solid #fff;
}
.fi-grip .ico { width: 12px; height: 12px; }
.page:not(.editing) .fi-grip { display: none; }
.float-tools {
    position: absolute; z-index: 20; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 10px;
    background: var(--ink); box-shadow: var(--shadow-lg); white-space: nowrap; animation: popIn .25s var(--spring); font-family: 'Inter', sans-serif;
}
.float-tools button, .img-tools-bar button { display: inline-flex !important; align-items: center; gap: 5px; }
.float-tools button { border: 0; background: transparent; color: #fff; border-radius: 7px; padding: 5px 8px; cursor: pointer; font-size: 12px; font-weight: 600; }
.float-tools button:hover { background: rgba(255, 255, 255, .15); }
.float-tools .ico { width: 15px; height: 15px; }
.float-tools .sep { width: 1px; height: 18px; background: rgba(255, 255, 255, .2); margin: 0 3px; }
.wrap-menu {
    position: absolute; z-index: 30; width: 280px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow-lg); font-family: 'Inter', sans-serif; animation: popIn .2s var(--spring);
}
.wm-title { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 4px 8px 6px; }
.wrap-menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; cursor: pointer; text-align: left; color: var(--ink); }
.wrap-menu button:hover { background: var(--surface-2); }
.wrap-menu button.on { background: var(--accent-soft); color: var(--accent-ink); }
.wrap-menu .ico { width: 22px; height: 22px; flex-shrink: 0; color: var(--accent); }
.wrap-menu b { display: block; font-size: 13px; font-weight: 650; }
.wrap-menu small { display: block; font-size: 11.5px; color: var(--muted); }

/* Ajuste del texto de las imágenes dentro del texto */
.page .ql-editor img[data-wrap="square-left"], .page .doc-html img[data-wrap="square-left"] { float: left; margin: 2px 12px 6px 0; }
.page .ql-editor img[data-wrap="square-right"], .page .doc-html img[data-wrap="square-right"] { float: right; margin: 2px 0 6px 12px; }
.page .ql-editor p, .page .doc-html p { overflow-wrap: break-word; }
.page .ql-editor::after, .page .doc-html::after { content: ''; display: block; clear: both; }

/* Ventana de recorte */
.crop-help { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-2); }
.crop-ratios { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.crop-ratios button { border: 1px solid var(--line-2); background: #fff; border-radius: 8px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.crop-ratios button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.crop-stage { position: relative; margin: 0 auto; overflow: hidden; user-select: none; background: repeating-conic-gradient(#eef0f5 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 6px; }
.crop-stage img { width: 100%; height: 100%; display: block; pointer-events: none; }
.crop-box { position: absolute; cursor: move; box-shadow: 0 0 0 9999px rgba(15, 18, 32, .55); outline: 2px solid #fff; touch-action: none; }
.crop-grid { position: absolute; inset: 0; pointer-events: none; background:
    linear-gradient(to right, transparent 33.2%, rgba(255,255,255,.5) 33.3%, rgba(255,255,255,.5) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.5) 66.6%, rgba(255,255,255,.5) 66.8%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.2%, rgba(255,255,255,.5) 33.3%, rgba(255,255,255,.5) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.5) 66.6%, rgba(255,255,255,.5) 66.8%, transparent 66.9%); }
.ch { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; z-index: 2; }
.ch-nw { left: 0; top: 0; cursor: nwse-resize; } .ch-ne { right: 0; top: 0; cursor: nesw-resize; }
.ch-sw { left: 0; bottom: 0; cursor: nesw-resize; } .ch-se { right: 0; bottom: 0; cursor: nwse-resize; }
.ch-n { left: 50%; top: 0; margin-left: -7px; cursor: ns-resize; } .ch-s { left: 50%; bottom: 0; margin-left: -7px; cursor: ns-resize; }
.ch-w { top: 50%; left: 0; margin-top: -7px; cursor: ew-resize; } .ch-e { top: 50%; right: 0; margin-top: -7px; cursor: ew-resize; }
.crop-info { margin-top: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.float-img img { width: 100%; height: 100%; display: block; pointer-events: none; max-width: none; }
.page:not(.editing) .float-img { cursor: default; pointer-events: none; }
.float-img:hover { outline: 1px dashed var(--accent); }
.float-img.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.fi-handle, .img-handle {
    position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 4px; background: #fff;
    border: 2px solid var(--accent); cursor: nwse-resize; display: none; pointer-events: auto; touch-action: none;
}
.float-img.selected .fi-handle { display: block; }
.fi-del {
    position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0;
    background: var(--danger); color: #fff; cursor: pointer; display: none; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.fi-del .ico { width: 12px; height: 12px; stroke-width: 3; }
.float-img.selected .fi-del { display: grid; place-items: center; }
.fi-pos { position: absolute; left: 0; top: -22px; font-size: 11px; background: var(--ink); color: #fff; padding: 1px 6px; border-radius: 4px; white-space: nowrap; display: none; font-family: 'Inter', sans-serif; }
.float-img.dragging .fi-pos { display: block; }

/* Herramientas para imágenes dentro del texto */
.page.editing .ql-editor img { cursor: grab; -webkit-user-drag: none; user-select: none; touch-action: none; }
.img-tools { position: absolute; z-index: 12; pointer-events: none; outline: 2px solid var(--accent); outline-offset: 1px; }
.img-tools .img-handle { display: block; }
.img-tools-bar {
    position: absolute; left: 0; top: -46px; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 10px;
    background: var(--ink); box-shadow: var(--shadow-lg); pointer-events: auto; white-space: nowrap; animation: popIn .25s var(--spring);
    font-family: 'Inter', sans-serif;
}
.img-tools-bar button { border: 0; background: transparent; color: #fff; border-radius: 7px; padding: 5px 7px; cursor: pointer; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.img-tools-bar button:hover { background: rgba(255, 255, 255, .15); }
.img-tools-bar button .ico { width: 15px; height: 15px; }
.img-tools-bar .sep { width: 1px; height: 18px; background: rgba(255, 255, 255, .2); margin: 0 3px; }
.img-size { position: absolute; right: 0; bottom: -24px; font-size: 11px; background: var(--ink); color: #fff; padding: 1px 6px; border-radius: 4px; pointer-events: none; font-family: 'Inter', sans-serif; }
.drop-caret { position: absolute; width: 2px; background: var(--accent); z-index: 13; pointer-events: none; animation: blink .8s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Menús de fuente, tamaño e interlineado en la barra de formato */
.ql-snow .ql-picker.ql-font { width: 118px; }
.ql-snow .ql-picker.ql-size { width: auto; min-width: 72px; }
.ql-snow .ql-picker.ql-size .ql-picker-label { padding-right: 22px; white-space: nowrap; }
.ql-snow .ql-picker.ql-lineheight { width: 70px; }
.ql-snow .ql-picker.ql-font .ql-picker-label::before, .ql-snow .ql-picker.ql-font .ql-picker-item::before { content: attr(data-value); }
.ql-snow .ql-picker.ql-font .ql-picker-label:not([data-value])::before, .ql-snow .ql-picker.ql-font .ql-picker-item:not([data-value])::before { content: var(--l-font); }
.ql-snow .ql-picker.ql-size .ql-picker-label::before, .ql-snow .ql-picker.ql-size .ql-picker-item::before { content: attr(data-value) !important; }
.ql-snow .ql-picker.ql-size .ql-picker-label:not([data-value])::before, .ql-snow .ql-picker.ql-size .ql-picker-item:not([data-value])::before { content: var(--l-size) !important; }
.ql-snow .ql-picker.ql-size .ql-picker-item { font-size: 13px !important; }
.ql-snow .ql-picker.ql-lineheight .ql-picker-label::before { content: '\2195 ' attr(data-label); }
.ql-snow .ql-picker.ql-lineheight .ql-picker-item::before { content: attr(data-label); }
.ql-snow .ql-picker.ql-lineheight .ql-picker-label:not([data-value])::before { content: '\2195  Doc.'; }
.ql-snow .ql-picker.ql-lineheight .ql-picker-item:not([data-value])::before { content: var(--l-doc-full); }
.ql-snow .ql-picker-options { max-height: 300px; overflow-y: auto; }
.ql-snow .ql-pagebreak svg { width: 18px; height: 18px; }

/* Vista previa y miniaturas con el mismo diseño de página */
.preview-doc .page { margin: 0 auto 18px; }
.tpl-thumb .page { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; box-shadow: none; }
.tpl-thumb .page .var { font-size: 12px; }

/* Deshacer / rehacer */
.undo-group { display: inline-flex; gap: 4px; }
.undo-group .icon-btn { width: 34px; height: 34px; }
.undo-group .icon-btn .ico { width: 17px; height: 17px; }

/* Textos de las listas y del cuadro de enlaces de Quill, traducibles.
   page-editor.js los rellena con t(); aquí queda el español por defecto. */
:root {
    --l-pagebreak: 'Salto de página'; --l-font: 'Fuente'; --l-size: 'Tamaño'; --l-doc-full: 'Del documento';
    --l-normal: 'Normal'; --l-h1: 'Título 1'; --l-h2: 'Título 2'; --l-h3: 'Título 3';
    --l-visit: 'Visitar enlace:'; --l-edit: 'Editar'; --l-remove: 'Quitar'; --l-save: 'Guardar'; --l-enter-link: 'Escribe el enlace:';
}
.ql-snow .ql-picker.ql-header .ql-picker-label::before, .ql-snow .ql-picker.ql-header .ql-picker-item::before { content: var(--l-normal); }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before { content: var(--l-h1); }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before { content: var(--l-h2); }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before { content: var(--l-h3); }
.ql-snow .ql-tooltip::before { content: var(--l-visit); }
.ql-snow .ql-tooltip[data-mode=link]::before { content: var(--l-enter-link); }
.ql-snow .ql-tooltip a.ql-action::after { content: var(--l-edit); }
.ql-snow .ql-tooltip.ql-editing a.ql-action::after { content: var(--l-save); }
.ql-snow .ql-tooltip a.ql-remove::before { content: var(--l-remove); }