/* Página genérica de herramientas (www/tool.html + tool.js + editor.js) */
.tl-app{max-width:980px;margin:0 auto}
.tl-hidden{display:none !important}
.tl-drop{position:relative}
.tl-drop .tl-actions{display:flex;gap:10px;justify-content:center;flex-wrap:wrap;margin-top:16px}
.tl-drop .file-btn{margin-top:0}
.tl-sub{color:var(--text-muted);font-size:.82rem;margin-top:10px}
.tl-or{display:flex;align-items:center;gap:12px;color:var(--text-muted);font-size:.8rem;margin:18px 0 14px}
.tl-or::before,.tl-or::after{content:'';flex:1;border-top:1px solid var(--border)}
.tl-url{display:flex;gap:8px}
.tl-url input{flex:1;min-width:0}

.tl-files{display:flex;flex-direction:column;gap:8px;margin-bottom:18px}
.tl-file{display:flex;align-items:center;gap:12px;background:var(--surface-2);border:1px solid var(--border);border-radius:10px;padding:10px 12px}
.tl-file .tl-thumb{width:42px;height:42px;border-radius:6px;object-fit:cover;background:var(--surface);flex-shrink:0;display:flex;align-items:center;justify-content:center;color:var(--tc,var(--accent))}
.tl-file .tl-thumb svg{width:22px;height:22px}
.tl-file .tl-name{flex:1;min-width:0;font-size:.88rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tl-file .tl-size{color:var(--text-muted);font-size:.76rem;white-space:nowrap}
.tl-file .tl-handle{cursor:grab;color:var(--text-muted);padding:4px;touch-action:none}
.tl-iconbtn{background:none;border:1px solid transparent;color:var(--text-muted);border-radius:8px;width:32px;height:32px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;transition:.15s;flex-shrink:0}
.tl-iconbtn:hover{color:var(--text);background:var(--surface);border-color:var(--border)}
.tl-iconbtn svg{width:16px;height:16px}

.tl-opts{display:grid;gap:16px;margin-bottom:20px}
.tl-opt>label.tl-label{display:block;font-size:.78rem;font-weight:700;color:var(--text-muted);text-transform:uppercase;letter-spacing:.06em;margin-bottom:8px}
.tl-choices{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px}
.tl-choice{background:var(--surface-2);border:2px solid var(--border);border-radius:12px;padding:12px 14px;cursor:pointer;transition:.15s;text-align:left;color:var(--text);font:inherit}
.tl-choice:hover{border-color:color-mix(in srgb,var(--tc,var(--accent)) 50%,transparent)}
.tl-choice[aria-pressed="true"]{border-color:var(--tc,var(--accent));background:color-mix(in srgb,var(--tc,var(--accent)) 12%,var(--surface-2))}
.tl-choice b{display:block;font-size:.9rem;margin-bottom:2px}
.tl-choice small{color:var(--text-muted);font-size:.76rem;line-height:1.35}
.tl-opt input[type=text],.tl-opt input[type=url],.tl-opt input[type=password],.tl-opt input[type=number],.tl-opt select,.tl-opt textarea{width:100%;background:var(--surface-2);border:1px solid var(--border);border-radius:9px;padding:11px 13px;color:var(--text);font:inherit;font-size:.92rem}
.tl-opt textarea{min-height:96px;resize:vertical}
.tl-opt input:focus,.tl-opt select:focus,.tl-opt textarea:focus{outline:2px solid color-mix(in srgb,var(--tc,var(--accent)) 60%,transparent);outline-offset:1px}
.tl-check{display:flex;align-items:center;gap:10px;font-size:.9rem;cursor:pointer}
.tl-check input{width:18px;height:18px;accent-color:var(--tc,var(--accent))}
.tl-chips{display:flex;flex-wrap:wrap;gap:8px}
.tl-chip{border:1px solid var(--border);background:var(--surface-2);color:var(--text);border-radius:99px;padding:7px 13px;font:inherit;font-size:.84rem;cursor:pointer}
.tl-chip[aria-pressed="true"]{background:var(--tc,var(--accent));border-color:var(--tc,var(--accent));color:#fff}
.tl-pos{display:grid;grid-template-columns:repeat(3,44px);gap:6px}
.tl-pos button{height:34px;border-radius:8px;border:1px solid var(--border);background:var(--surface-2);cursor:pointer;position:relative}
.tl-pos button::after{content:'';position:absolute;width:10px;height:4px;border-radius:2px;background:var(--text-muted);left:50%;top:50%;transform:translate(-50%,-50%)}
.tl-pos button[aria-pressed="true"]{border-color:var(--tc,var(--accent));background:color-mix(in srgb,var(--tc,var(--accent)) 18%,var(--surface-2))}
.tl-pos button[aria-pressed="true"]::after{background:var(--tc,var(--accent))}
.tl-pos .tl-pos-mid{grid-column:1/-1;height:26px;border:1px dashed var(--border);border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:.7rem;color:var(--text-muted)}
.tl-err{color:#f87171;font-size:.8rem;margin-top:6px}

.tl-bar{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.tl-bar .btn-primary{background:var(--tc,var(--accent))}
.tl-note{font-size:.84rem;color:var(--text-muted);margin:0 0 14px;line-height:1.5}
.tl-sticky{position:sticky;bottom:12px;z-index:5;background:color-mix(in srgb,var(--surface) 92%,transparent);backdrop-filter:blur(8px);border:1px solid var(--border);border-radius:14px;padding:12px;margin-top:16px;box-shadow:0 10px 30px rgba(0,0,0,.25)}
@media (max-width:768px){.tl-sticky{bottom:86px}}

/* ── Miniaturas de páginas ── */
.tl-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:14px;margin:6px 0 4px}
.tl-page{position:relative;background:var(--surface-2);border:2px solid var(--border);border-radius:12px;padding:8px 8px 6px;text-align:center;cursor:pointer;user-select:none;transition:border-color .15s,transform .15s}
.tl-page:hover{border-color:color-mix(in srgb,var(--tc,var(--accent)) 50%,transparent)}
.tl-page .tl-canvas{height:150px;display:flex;align-items:center;justify-content:center;overflow:hidden}
.tl-page canvas{max-width:100%;max-height:150px;box-shadow:0 2px 8px rgba(0,0,0,.25);background:#fff;transition:transform .25s}
.tl-page .tl-num{font-size:.74rem;color:var(--text-muted);margin-top:6px;display:block}
.tl-page .tl-tools{position:absolute;top:6px;right:6px;display:flex;gap:4px;opacity:0;transition:.15s}
.tl-page:hover .tl-tools,.tl-page:focus-within .tl-tools{opacity:1}
@media (hover:none){.tl-page .tl-tools{opacity:1}}
.tl-page .tl-tools button{width:28px;height:28px;border-radius:7px;border:none;background:rgba(0,0,0,.65);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center}
.tl-page .tl-tools svg{width:15px;height:15px}
.tl-page.is-selected{border-color:var(--tc,var(--accent));background:color-mix(in srgb,var(--tc,var(--accent)) 14%,var(--surface-2))}
.tl-page.is-selected::before{content:'✓';position:absolute;top:6px;left:6px;width:22px;height:22px;border-radius:50%;background:var(--tc,var(--accent));color:#fff;font-size:.78rem;font-weight:800;display:flex;align-items:center;justify-content:center;z-index:2}
.tl-page.is-deleted{border-color:#ef4444}
.tl-page.is-deleted canvas{opacity:.3;filter:grayscale(1)}
.tl-page.is-deleted::after{content:'';position:absolute;inset:8px 8px 26px;background:linear-gradient(45deg,transparent 47%,#ef4444 47%,#ef4444 53%,transparent 53%),linear-gradient(-45deg,transparent 47%,#ef4444 47%,#ef4444 53%,transparent 53%);pointer-events:none}
.tl-page.sortable-ghost{opacity:.35}
.tl-page.sortable-chosen{transform:scale(1.03)}
.tl-pages-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:14px}
.tl-pages-bar input{flex:1;min-width:160px;background:var(--surface-2);border:1px solid var(--border);border-radius:9px;padding:9px 12px;color:var(--text);font:inherit;font-size:.88rem}
.tl-loading{color:var(--text-muted);font-size:.86rem;padding:30px;text-align:center}

/* ── Resultado ── */
.tl-result{text-align:center}
.tl-result .tl-ok{width:64px;height:64px;border-radius:50%;margin:0 auto 14px;background:color-mix(in srgb,var(--tc,var(--accent)) 16%,transparent);color:var(--tc,var(--accent));display:flex;align-items:center;justify-content:center}
.tl-result .tl-ok svg{width:32px;height:32px}
.tl-result h3{font-family:var(--font-display);font-size:1.35rem;margin-bottom:8px}
.tl-result p.tl-msg{color:var(--text-muted);margin-bottom:18px}
.tl-result .result-btns{justify-content:center}
.tl-result .btn-primary{background:var(--tc,var(--accent))}
.tl-preview{text-align:left;background:var(--surface-2);border:1px solid var(--border);border-radius:12px;padding:16px 18px;margin:18px 0 6px;max-height:420px;overflow:auto;font-size:.9rem;line-height:1.6}
.tl-preview pre{white-space:pre-wrap;font-family:ui-monospace,Consolas,monospace;font-size:.82rem;margin:0}
.tl-preview h2,.tl-preview h3{font-family:var(--font-display);font-size:1.05rem;margin:12px 0 6px}
.tl-preview ul,.tl-preview ol{padding-left:20px;margin:6px 0}
.tl-preview table{border-collapse:collapse;margin:8px 0}
.tl-preview td,.tl-preview th{border:1px solid var(--border);padding:4px 8px}
.tl-stats{display:flex;justify-content:center;gap:12px;margin:4px 0 16px;flex-wrap:wrap}
.tl-stat{background:var(--surface-2);border:1px solid var(--border);border-radius:12px;padding:10px 16px;min-width:110px}
.tl-stat b{display:block;font-family:var(--font-display);font-size:1.2rem}
.tl-stat span{font-size:.74rem;color:var(--text-muted)}
.tl-change{display:flex;gap:10px;align-items:flex-start;padding:8px 0;border-bottom:1px solid var(--border);font-size:.86rem}
.tl-change em{font-style:normal;font-size:.7rem;font-weight:800;padding:2px 7px;border-radius:99px;white-space:nowrap}
.tl-change .add{background:rgba(34,197,94,.18);color:#22c55e}
.tl-change .del{background:rgba(239,68,68,.18);color:#ef4444}
.tl-next{margin-top:22px}
.tl-next p{font-size:.8rem;color:var(--text-muted);margin-bottom:10px}
.tl-next nav{display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.tl-next a{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--border);border-radius:99px;padding:7px 12px;font-size:.82rem;color:var(--text);text-decoration:none;background:var(--surface-2)}
.tl-next a svg{width:15px;height:15px}

/* ── Comparar ── */
.tl-two{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:16px}
@media (max-width:640px){.tl-two{grid-template-columns:1fr}}
.tl-two .drop-zone{padding:28px 16px;margin:0}
.tl-two .drop-zone h3{font-size:1rem}
.tl-two .is-set{border-style:solid;border-color:var(--tc,var(--accent))}

/* ── Formularios ── */
.tl-doc{display:flex;flex-direction:column;gap:18px;align-items:center;margin:8px 0}
.tl-sheet{position:relative;box-shadow:0 4px 20px rgba(0,0,0,.3);background:#fff;max-width:100%}
.tl-sheet canvas{display:block;width:100%;height:auto}
.tl-field{position:absolute;box-sizing:border-box;background:rgba(219,234,254,.55);border:1px solid rgba(37,99,235,.55);border-radius:3px;color:#111;font:13px/1.2 Helvetica,Arial,sans-serif;padding:1px 4px}
.tl-field:focus{outline:2px solid #2563eb;background:rgba(219,234,254,.9)}
input.tl-field[type=checkbox],input.tl-field[type=radio]{margin:0;accent-color:#2563eb}
textarea.tl-field{resize:none}

/* ── Escanear ── */
.tl-scan-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:12px;margin-bottom:16px}
.tl-shot{position:relative;border-radius:10px;overflow:hidden;border:1px solid var(--border);background:var(--surface-2);aspect-ratio:3/4}
.tl-shot img{width:100%;height:100%;object-fit:cover;display:block}
.tl-shot .tl-tools{position:absolute;top:6px;right:6px;display:flex;gap:4px}
.tl-shot .tl-tools button{width:28px;height:28px;border-radius:7px;border:none;background:rgba(0,0,0,.65);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center}
.tl-shot .tl-tools svg{width:15px;height:15px}
.tl-shot .tl-n{position:absolute;left:6px;bottom:6px;background:rgba(0,0,0,.65);color:#fff;font-size:.72rem;padding:2px 7px;border-radius:99px}

/* ── Editor ── */
.ed-toolbar{position:sticky;top:72px;z-index:6;display:flex;flex-wrap:wrap;gap:6px;align-items:center;background:color-mix(in srgb,var(--surface) 94%,transparent);backdrop-filter:blur(8px);border:1px solid var(--border);border-radius:14px;padding:8px;margin-bottom:14px}
.ed-tool{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--border);background:var(--surface-2);color:var(--text);border-radius:9px;padding:7px 10px;font:inherit;font-size:.82rem;cursor:pointer}
.ed-tool svg{width:16px;height:16px}
.ed-tool[aria-pressed="true"]{background:var(--tc,var(--accent));border-color:var(--tc,var(--accent));color:#fff}
.ed-sep{width:1px;align-self:stretch;background:var(--border);margin:0 2px}
.ed-props{display:flex;gap:6px;align-items:center;flex-wrap:wrap;font-size:.8rem;color:var(--text-muted)}
.ed-props input[type=color]{width:30px;height:30px;border:1px solid var(--border);border-radius:7px;padding:2px;background:var(--surface-2)}
.ed-props select{background:var(--surface-2);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 6px;font:inherit;font-size:.8rem}
.ed-pages{display:flex;flex-direction:column;gap:22px;align-items:center}
.ed-page{position:relative;box-shadow:0 4px 22px rgba(0,0,0,.35);background:#fff;max-width:100%;touch-action:pan-y}
.ed-page.ed-drawing{touch-action:none;cursor:crosshair}
.ed-page canvas{display:block;width:100%;height:auto}
.ed-label{position:absolute;top:-20px;left:0;font-size:.72rem;color:var(--text-muted)}
.ed-layer{position:absolute;inset:0}
.ed-el{position:absolute;box-sizing:border-box;cursor:move;touch-action:none}
.ed-el.sel{outline:2px dashed var(--tc,var(--accent));outline-offset:2px}
.ed-el .ed-h{position:absolute;right:-7px;bottom:-7px;width:14px;height:14px;border-radius:50%;background:var(--tc,var(--accent));border:2px solid #fff;cursor:nwse-resize;display:none}
.ed-el.sel .ed-h{display:block}
.ed-el .ed-x{position:absolute;right:-10px;top:-10px;width:22px;height:22px;border-radius:50%;background:#ef4444;color:#fff;border:2px solid #fff;font-size:12px;line-height:16px;text-align:center;cursor:pointer;display:none;padding:0}
.ed-el.sel .ed-x{display:block}
.ed-text{white-space:pre;line-height:1.2;outline:none;min-width:20px;cursor:text}
.ed-text:focus{outline:1px solid #2563eb}
.ed-el img{width:100%;height:100%;display:block;pointer-events:none}
.ed-hl{mix-blend-mode:multiply}
.ed-redact{background:#000}
.ed-hint{font-size:.8rem;color:var(--text-muted);margin:-6px 0 12px}
.ed-ink{position:absolute;inset:0;pointer-events:none;overflow:visible}

/* Modal de firma */
.sg-back{position:fixed;inset:0;background:rgba(0,0,0,.7);z-index:10002;display:flex;align-items:center;justify-content:center;padding:16px}
.sg-box{background:var(--surface);border:1px solid var(--border);border-radius:18px;padding:22px;width:100%;max-width:560px}
.sg-box h3{font-family:var(--font-display);font-size:1.2rem;margin-bottom:12px}
.sg-tabs{display:flex;gap:6px;margin-bottom:12px}
.sg-pad{background:#fff;border:1px dashed #94a3b8;border-radius:12px;width:100%;height:200px;touch-action:none;cursor:crosshair;display:block}
.sg-typed{background:#fff;border-radius:12px;height:200px;display:flex;align-items:center;justify-content:center;color:#1d4ed8;font-size:46px;overflow:hidden;padding:0 12px;text-align:center}
.sg-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
.sg-row input[type=text]{flex:1;min-width:0;background:var(--surface-2);border:1px solid var(--border);border-radius:9px;padding:10px 12px;color:var(--text);font:inherit}
.sg-colors{display:inline-flex;gap:6px}.sg-colors button{width:26px;height:26px;border-radius:50%;border:2px solid var(--border);box-shadow:0 0 0 1px rgba(255,255,255,.25);cursor:pointer}
.sg-colors button[aria-pressed="true"]{border-color:var(--text)}

html[data-theme="light"] .tl-page .tl-tools button,html[data-theme="light"] .tl-shot .tl-tools button{background:rgba(15,23,42,.72)}
