/* PDF · estilos propios */
body { overflow: hidden; }
.shell { display: grid; height: 100dvh; grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: 48px auto minmax(0, 1fr); grid-template-areas: "top top" "bar bar" "board side"; }
.topbar { grid-area: top; }
.top-mid { margin: 0 auto; }
.topbar .top-actions { margin-left: 0; }
.bar { grid-area: bar; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.inline-f { flex-direction: row; align-items: center; gap: 6px; }
.inline-f .input { width: 180px; height: 30px; }
.board { grid-area: board; position: relative; overflow: auto; padding: 16px; }
.drop { position: absolute; inset: 16px; display: grid; place-items: center; border: 1.5px dashed var(--border-2); border-radius: 14px; }
.drop-in { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--text-2); line-height: 1.5; }
.drop-in strong { font-size: 16px; color: var(--text); }
.drop-in .btn { margin-top: 8px; }
.drop-ic { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: rgba(185, 28, 28, .1); color: #b91c1c; margin-bottom: 4px; }
.drop-ic .ic { width: 26px; height: 26px; }
body.dragging .board { box-shadow: inset 0 0 0 3px var(--accent); }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.pg { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; user-select: none; transition: border-color .12s, box-shadow .12s, opacity .12s; }
.pg:hover { border-color: var(--border-2); }
.pg.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-line); }
.pg.dragging { opacity: .35; }
.pg.before { box-shadow: -4px 0 0 var(--accent); }
.pg.after { box-shadow: 4px 0 0 var(--accent); }
.pg-img { display: grid; place-items: center; aspect-ratio: 3 / 4; border-radius: 6px; background: var(--sunken); overflow: hidden; border-top: 3px solid var(--fc); }
.pg-img img { max-width: 92%; max-height: 92%; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); background: #fff; transition: transform .2s var(--ease); }
.pg-meta { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; color: var(--text-3); min-width: 0; }
.pg-meta b { color: var(--text); font-size: 12.5px; }
.pg-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-act { position: absolute; top: 12px; right: 12px; display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-sm); opacity: 0; transition: opacity .12s; }
.pg:hover .pg-act, .pg:focus-within .pg-act { opacity: 1; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.side { grid-area: side; overflow: auto; border-left: 1px solid var(--border); }
.s-sec { display: grid; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.files { display: grid; gap: 4px; }
.file { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto 24px; align-items: center; gap: 8px; font-size: 12.5px; }
.file i { width: 8px; height: 8px; border-radius: 50%; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { color: var(--text-3); white-space: nowrap; }
.files .empty { text-align: left; padding: 0; }
.tips { margin: 0; padding-left: 16px; display: grid; gap: 6px; font-size: 12px; color: var(--text-2); line-height: 1.5; }
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px auto auto auto; grid-template-areas: "top" "bar" "board" "side"; }
  .board { min-height: 60vh; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .top-mid { display: none; } .topbar .top-actions { margin-left: auto; }
  .inline-f .input { width: 130px; }
}

/* ───────── Miniaturas editadas ───────── */
.pg-badge { position: absolute; top: 12px; left: 12px; z-index: 1; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 600; }

/* ───────── Editor de página ───────── */
body.editing { overflow: hidden; }
.ed { position: fixed; inset: 48px 0 0; z-index: 40; display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--bg); }
.ed[hidden] { display: none; }
.ed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.ed-tools { display: flex; flex-wrap: wrap; gap: 2px; }
.ed-tool { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--text-2); }
.ed-tool:hover { background: var(--hover); color: var(--text); }
.ed-tool[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ed-tool .ic { width: 18px; height: 18px; }
.ed-props { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ed-props [hidden] { display: none !important; }
.ed-colors { display: flex; align-items: center; gap: 3px; }
.sw { width: 20px; height: 20px; padding: 0; border: 2px solid var(--panel); border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px var(--border-2); cursor: pointer; }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--text); }
.sw-custom { position: relative; overflow: hidden; background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.sw-custom input { position: absolute; inset: -6px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }
.ed-sel { width: auto; height: 30px; padding: 0 8px; }
.ed-bold { width: 30px; height: 30px; }
.ed-bold[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ed-nav { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.ed-stage { overflow: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 24px 24px 14px; }
.ed-stage > * { flex: none; margin-inline: auto; }   /* centrado que no corta la hoja cuando es más ancha que la ventana */
.ed-stage > .ed-hint { margin: auto auto 0; }         /* si la hoja no llena la pantalla, la ayuda baja hasta el borde inferior */
.ed-page { position: relative; box-shadow: 0 2px 6px rgba(0, 0, 0, .12), 0 12px 40px rgba(0, 0, 0, .18); background: #fff; }
.ed-page canvas { display: block; }
.ed-hint { margin: 0; text-align: center; }
.ed-layer { position: absolute; inset: 0; touch-action: none; user-select: none; cursor: default; }
.ed-layer:not([data-tool="select"]) { cursor: crosshair; }
.ed-layer[data-tool="text"], .ed-layer[data-tool="date"] { cursor: text; }
.an-svg { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.an-svg g { pointer-events: auto; cursor: move; }
.an-hit { fill: none; stroke: transparent; pointer-events: stroke; }
.an { position: absolute; cursor: move; }
.an.on { outline: 1.5px solid var(--accent); outline-offset: 2px; }
.an-shape, .an-hl { position: absolute; inset: 0; box-sizing: border-box; }
.an-hl { opacity: .45; mix-blend-mode: multiply; }
.an-in { position: absolute; left: 50%; top: 50%; }
.an-in img { display: block; width: 100%; height: 100%; pointer-events: none; }
.an-mark { display: block; width: 100%; height: 100%; overflow: visible; }
.an-text { white-space: pre; outline: none; }
.an-text[contenteditable] { cursor: text; user-select: text; box-shadow: 0 0 0 1px var(--accent); background: color-mix(in srgb, #fff 70%, transparent); }
.an-bbox { position: absolute; border: 1.5px dashed var(--accent); border-radius: 4px; pointer-events: none; }
.hd { position: absolute; z-index: 2; width: 12px; height: 12px; border: 2px solid var(--accent); border-radius: 3px; background: #fff; transform: translate(-50%, -50%); cursor: nwse-resize; }
.hd[data-h="ne"], .hd[data-h="sw"] { cursor: nesw-resize; }
.hd[data-h="A"], .hd[data-h="B"] { border-radius: 50%; cursor: crosshair; }

/* ───────── Firma ───────── */
.sig-dlg { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: var(--overlay); }
.sig-dlg[hidden] { display: none; }
.sig-box { display: grid; gap: 12px; width: min(560px, 100%); max-height: 100%; overflow: auto; padding: 18px; border-radius: 16px; background: var(--panel); box-shadow: var(--shadow-lg); }
.sig-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sig-h b { font-size: 16px; }
.sig-draw { display: grid; gap: 6px; }
.sig-draw[hidden], .sig-type[hidden] { display: none; }
#sigPad { width: 100%; height: 200px; border: 1px solid var(--border-2); border-radius: 12px; background: #fff; touch-action: none; cursor: crosshair; }
.sig-row { display: flex; align-items: center; gap: 8px; }
.sig-inks { display: flex; gap: 4px; }
.sig-type { display: grid; gap: 8px; }
.sig-fonts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.sig-fonts button { height: 64px; padding: 0 10px; border: 1px solid var(--border-2); border-radius: 10px; background: #fff; font-size: 28px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sig-fonts button[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-line); }
.sig-saved { display: grid; gap: 6px; }
.sig-saved:empty { display: none; }
.sig-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sig-item { position: relative; }
.sig-pick { display: grid; place-items: center; width: 130px; height: 56px; padding: 6px; border: 1px solid var(--border-2); border-radius: 10px; background: #fff; }
.sig-pick:hover { border-color: var(--accent); }
.sig-pick img { max-width: 100%; max-height: 100%; }
.sig-item .icon-btn { position: absolute; top: -8px; right: -8px; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow-sm); }
.sig-f { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 760px) {
  .ed-stage { padding: 12px; }
  .ed-bar .sep { display: none; }
}
.ed-stage.loading .ed-page::after { content: ""; position: absolute; left: 50%; top: 40px; width: 28px; height: 28px; margin-left: -14px; border-radius: 50%; border: 3px solid rgba(0, 0, 0, .12); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.ed-stage.loading .ed-layer { visibility: hidden; }
.ed-zoom { display: flex; align-items: center; gap: 2px; }
.ed-zoom .icon-btn { font-size: 17px; font-weight: 500; }
#edZoomVal { min-width: 64px; justify-content: center; font-variant-numeric: tabular-nums; }
.save-info { margin: 4px 0 0; color: var(--ok); line-height: 1.45; }
.save-info.warn { color: var(--star); }
.close-doc { justify-self: start; }

/* ───────── Pantallas táctiles: acciones visibles en la página elegida ───────── */
.pg-act .mv { display: none; }
:root[data-input="touch"] .pg-act { top: auto; bottom: 34px; left: 12px; right: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; opacity: 0; pointer-events: none; }
:root[data-input="touch"] .pg.sel .pg-act { opacity: 1; pointer-events: auto; }
/* Sin elegir, solo el lápiz, siempre visible arriba a la derecha: entrar a editar es un toque */
:root[data-input="touch"] .pg:not(.sel) .pg-act { top: 12px; bottom: auto; left: auto; right: 12px; grid-template-columns: 40px; opacity: 1; pointer-events: auto; }
:root[data-input="touch"] .pg:not(.sel) .pg-act > :not([data-act="e"]) { display: none; }
:root[data-input="touch"] .pg-act .mv { display: grid; }
:root[data-input="touch"] .pg-act .icon-btn { width: auto; height: 38px; }
:root[data-input="touch"] .pg-act .icon-btn:disabled { opacity: .3; }
:root[data-input="touch"] .pg { touch-action: manipulation; }

/* ───────── Móvil ───────── */
@media (max-width: 700px) {
  .bar { gap: 6px; padding: 10px 12px; }
  .bar .sep, .bar .grow { display: none; }
  #addBtn { flex: 1; justify-content: center; }
  #rotL, #rotR, #delSel, #reverse { flex: 1 1 calc(25% - 6px); justify-content: center; padding: 0 4px; }
  #editSel { flex: 1 1 100%; justify-content: center; }
  .inline-f { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; }
  .inline-f .input { flex: 1; width: auto; }
  #splitBtn, #extractBtn { flex: 1; }
  /* «Descargar PDF», siempre a mano abajo */
  #saveBtn { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20; min-height: 48px; justify-content: center; font-size: 15px; box-shadow: var(--shadow-lg); }
  #saveBtn:disabled { display: none; }
  .shell { padding-bottom: 76px; }
  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .pages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  body:has(> .orient-hint) #saveBtn { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
/* El editor de página ocupa toda la pantalla en el móvil (se sale con «Listo») */
@media (max-width: 700px) {
  .ed { inset: 0; z-index: 60; }
  .ed-bar { padding: 8px; gap: 4px; }
}

/* ───────── Dividir en páginas con nombres ───────── */
.split-m { width: min(780px, 100%); max-height: 90dvh; display: flex; flex-direction: column; padding-bottom: 14px; }
.split-m .modal-h { align-items: flex-start; }
.sp-sub { margin: 3px 0 0; }
.sp-body { display: grid; gap: 14px; min-height: 0; overflow: auto; margin: 0 -4px; padding: 2px 4px 4px; }
.sp-ic { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--sunken); color: var(--text-2); }
.sp-ic.xl { background: color-mix(in srgb, #1d7f45 14%, var(--panel)); color: #1d7f45; }
.sp-ic.big { width: 48px; height: 48px; border-radius: 13px; }
.sp-ic.big .ic { width: 24px; height: 24px; }

/* Cómo nombrar: dos tarjetas */
.sp-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sp-card { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 12px 14px; border: 1.5px solid var(--border-2); border-radius: 12px; background: var(--panel); color: var(--text); text-align: left; font: inherit; cursor: pointer; transition: border-color .12s, box-shadow .12s, background .12s; }
.sp-card:hover { border-color: var(--text-3); }
.sp-card.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.sp-card.on .sp-ic:not(.xl) { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); color: var(--accent); }
.sp-ct { display: grid; gap: 2px; min-width: 0; }
.sp-ct b { font-size: 13.5px; }
.sp-ct small { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Datos: zona para soltar y tarjeta del archivo cargado */
.sp-data { display: grid; gap: 14px; }
.sp-drop { display: grid; justify-items: center; gap: 6px; padding: 22px 16px; border: 1.5px dashed var(--border-2); border-radius: 14px; background: var(--sunken); color: var(--text); font: inherit; text-align: center; cursor: pointer; transition: border-color .12s, background .12s; }
.sp-drop:hover, .sp-drop.over { border-color: #1d7f45; background: color-mix(in srgb, #1d7f45 7%, var(--sunken)); }
.sp-drop b { font-size: 14px; margin-top: 4px; }
.sp-file { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border-2); border-radius: 12px; background: var(--panel); }
.sp-fi { display: grid; gap: 1px; min-width: 0; flex: 1; }
.sp-fi b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-fi small { font-size: 11.5px; }
.input.sm { height: 30px; padding: 0 8px; font-size: 12.5px; width: auto; }

/* Nombre: campo con «.pdf» fijo y datos para insertar */
.sp-step { display: grid; gap: 8px; }
.sp-lbl { font-size: 12px; font-weight: 600; color: var(--text-2); }
.sp-tplw { display: flex; align-items: stretch; border: 1px solid var(--border-2); border-radius: 10px; background: var(--panel); overflow: hidden; }
.sp-tplw:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.sp-tplw .input { flex: 1; min-width: 0; height: 40px; border: 0; border-radius: 0; background: none; box-shadow: none; font-family: var(--mono); font-size: 13px; }
.sp-ext { display: grid; place-items: center; padding: 0 12px; border-left: 1px solid var(--border); background: var(--sunken); color: var(--text-3); font: 500 12.5px var(--mono); }
.sp-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sp-chips > span:last-child { display: contents; }
.chip-d { display: inline-flex; align-items: baseline; gap: 6px; height: 30px; padding: 0 11px; border: 1px solid var(--border-2); border-radius: 99px; background: var(--sunken); color: var(--text); font: 600 12px var(--sans); cursor: pointer; transition: border-color .12s, background .12s; line-height: 28px; }
.chip-d small { font-weight: 400; color: var(--text-3); max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-d:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--sunken)); }
.chip-d.n { border-style: dashed; }

/* Opciones en una fila */
.sp-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 10px 12px; border-radius: 10px; background: var(--sunken); font-size: 12.5px; }
.sp-sw { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.sp-sw input { appearance: none; -webkit-appearance: none; position: relative; width: 34px; height: 20px; margin: 0; border-radius: 99px; background: var(--border-2); cursor: pointer; transition: background .15s; flex: none; }
.sp-sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.sp-sw input:checked { background: var(--accent); }
.sp-sw input:checked::after { transform: translateX(14px); }
.sp-sw input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sp-num { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.sp-num .input { width: 64px; text-align: center; }

/* Vista previa */
.sp-prev-c { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--sunken); }
.sp-prev-h { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sp-badge { padding: 1px 9px; border-radius: 99px; background: var(--panel); border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.sp-badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.sp-badge.w { color: #b45309; border-color: color-mix(in srgb, #d97706 45%, var(--border)); }
.sp-warn:empty { display: none; }
.sp-warn { display: grid; gap: 4px; }
.sp-w { margin: 0; padding: 7px 10px; border-radius: 8px; font-size: 12.5px; }
.sp-w.w { background: color-mix(in srgb, #d97706 13%, var(--panel)); color: color-mix(in srgb, #b45309 75%, var(--text)); }
.sp-w.i { background: color-mix(in srgb, var(--accent) 9%, var(--panel)); color: var(--text-2); }
.sp-empty { margin: 4px 0; text-align: center; padding: 14px; }
.sp-prev { max-height: 300px; overflow: auto; }
.sp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; counter-reset: sp; }
.sp-list li { display: grid; grid-template-columns: 30px 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 5px 10px 5px 6px; border-radius: 9px; background: var(--panel); border: 1px solid var(--border); font-size: 13px; }
.sp-th { width: 30px; height: 40px; display: grid; place-items: center; overflow: hidden; border-radius: 4px; background: var(--sunken); box-shadow: inset 0 0 0 1px var(--border); }
.sp-th img { max-width: 100%; max-height: 100%; }
.sp-pg { justify-self: center; min-width: 26px; padding: 1px 6px; border-radius: 6px; background: var(--sunken); color: var(--text-3); font-size: 11px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sp-name i { font-style: normal; color: var(--text-3); font-weight: 400; }
.sp-tag { padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.sp-tag.w { background: color-mix(in srgb, #d97706 15%, var(--panel)); color: color-mix(in srgb, #b45309 75%, var(--text)); }
.sp-tag.i { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); color: var(--text-2); }
.sp-list li.f-nodata .sp-name, .sp-list li.f-empty .sp-name { color: var(--text-3); font-weight: 400; }
.sp-foot { align-items: center; margin-top: 14px; }
.sp-foot .grow { flex: 1; }

@media (max-width: 640px) {
  .sp-modes { grid-template-columns: 1fr; }
  .sp-card { padding: 10px 12px; }
  .sp-file { flex-wrap: wrap; }
  .sp-file .input.sm, .sp-file .btn { min-height: 38px; }
  .sp-list li { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .sp-pg { display: none; }
  .sp-list li .sp-tag { grid-column: 2 / -1; justify-self: start; }
  .sp-tplw .input, .sp-num .input, .input.sm { font-size: 16px; }
  .chip-d { height: 38px; line-height: 36px; }
  .sp-foot #spFoot { flex-basis: 100%; }
}
