/* Catálogo de templates de contrato */
.tpl-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.tpl-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .tpl-layout { grid-template-columns: 1fr; }
}

.tpl-sidebar {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.7) 0%, rgba(15, 23, 42, 0.5) 100%);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.tpl-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.tpl-sidebar-head h3 {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin: 0;
    font-weight: 700;
}

.tpl-folders {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tpl-folder {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.08s ease;
    color: #94a3b8;
    font-size: 0.88rem;
    position: relative;
    border: 1px solid transparent;
}
.tpl-folder:hover {
    background: rgba(148, 163, 184, 0.1);
    color: #e2e8f0;
    transform: translateX(2px);
}
.tpl-folder.is-active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.18) 0%, rgba(99, 102, 241, 0.12) 100%);
    color: #93c5fd;
    font-weight: 600;
    border-color: rgba(59, 130, 246, 0.25);
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.15);
}

.tpl-folder-icon { flex-shrink: 0; }
.tpl-folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-folder-count {
    font-size: 0.72rem;
    color: #64748b;
    background: rgba(148, 163, 184, 0.1);
    padding: 1px 7px;
    border-radius: 10px;
}

.tpl-folder-del {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.06s;
}
.tpl-folder:hover .tpl-folder-del { opacity: 1; }
.tpl-folder-del:hover { color: #ef4444; }

.tpl-content {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.7) 0%, rgba(15, 23, 42, 0.5) 100%);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: blur(12px);
    min-height: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.tpl-content-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.tpl-content-head h2 {
    font-size: 1.4rem;
    margin: 0;
    color: #f1f5f9;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.tpl-actions { display: flex; gap: 8px; }

.tpl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    border-radius: 9px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.08s;
    text-decoration: none;
    background: none;
    font-family: inherit;
    position: relative;
    z-index: 1;
}
.tpl-btn:hover {
    text-decoration: none;
}
.tpl-btn--primary {
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.3);
    border-color: rgba(99, 102, 241, 0.4);
}
.tpl-btn--primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5), 0 0 0 1px rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}
.tpl-btn--ghost {
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.12) 0%, rgba(148, 163, 184, 0.06) 100%);
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.25);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.tpl-btn--ghost:hover {
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.2) 0%, rgba(148, 163, 184, 0.1) 100%);
    color: #f8fafc;
    border-color: rgba(148, 163, 184, 0.4);
    box-shadow: 0 4px 12px rgba(148, 163, 184, 0.15), 0 0 0 1px rgba(148, 163, 184, 0.1);
    transform: translateY(-1px);
}
.tpl-btn--ghost-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.12) 0%, rgba(239, 68, 68, 0.06) 100%);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.tpl-btn--ghost-danger:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.22) 0%, rgba(239, 68, 68, 0.12) 100%);
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.25), 0 0 0 1px rgba(239, 68, 68, 0.15);
    transform: translateY(-1px);
}

.tpl-loading, .tpl-empty {
    text-align: center;
    padding: 60px 20px;
    color: #64748b;
}
.tpl-empty p { margin: 4px 0; }
.tpl-empty p:first-child {
    color: #e2e8f0;
    font-size: 1.15rem;
    font-weight: 500;
}
.tpl-empty-sub {
    font-size: 0.9rem;
    color: #64748b;
}
.tpl-empty .big-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.tpl-card {
    background: linear-gradient(145deg, rgba(6, 13, 26, 0.6) 0%, rgba(6, 13, 26, 0.4) 100%);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.tpl-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.1s;
}
.tpl-card:hover {
    border-color: rgba(99, 102, 241, 0.4);
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.1);
}
.tpl-card:hover::before {
    opacity: 1;
}

.tpl-card-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    transition: transform 0.1s;
}
.tpl-card:hover .tpl-card-icon {
    transform: scale(1.05);
}
.tpl-card-body { flex: 1; }
.tpl-card-name {
    font-size: 1rem;
    margin: 0 0 4px;
    color: #e2e8f0;
    word-break: break-word;
}
.tpl-card-meta {
    font-size: 0.78rem;
    color: #64748b;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.tpl-card-contratos-link {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.08s;
    cursor: pointer;
}
.tpl-card-contratos-link:hover {
    color: #93c5fd;
    text-decoration: underline;
}
.tpl-card-contratos-link[data-contratos="0"] {
    color: #64748b;
    pointer-events: none;
    cursor: default;
    text-decoration: none;
}
.tpl-card-actions {
    display: flex;
    gap: 6px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
    padding-top: 10px;
    position: relative;
    z-index: 10;
}
.tpl-card-actions > * {
    flex: 1;
    cursor: pointer;
    position: relative;
    z-index: 11;
}

.tpl-card--locked {
    border-color: rgba(245, 158, 11, 0.25);
}
.tpl-card--locked:hover {
    border-color: rgba(245, 158, 11, 0.45);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(245, 158, 11, 0.1);
}
.tpl-btn--secondary {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(245, 158, 11, 0.08) 100%);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.tpl-btn--secondary:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.25) 0%, rgba(245, 158, 11, 0.14) 100%);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.55);
    transform: translateY(-1px);
}
.tpl-btn--secondary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Modal */
.tpl-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.tpl-modal[hidden] { display: none; }
.tpl-modal-content {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    padding: 28px;
    width: 420px;
    max-width: 92vw;
    color: #e2e8f0;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    animation: modal-in 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
.tpl-modal-content h3 {
    margin: 0 0 16px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #f1f5f9;
}
.tpl-modal-content input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 9px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(6, 13, 26, 0.6);
    color: #e2e8f0;
    font-size: 0.9rem;
    box-sizing: border-box;
}
.tpl-modal-content input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
}
.tpl-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.tpl-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: tpl-spin 0.5s linear infinite;
    margin: 16px auto 0;
}
@keyframes tpl-spin { to { transform: rotate(360deg); } }

/* === Editor === */
.tpl-editor-main {
    width: 100%;
    margin: 0;
    padding: 12px 16px 16px;
    position: relative;
    z-index: 1;
    height: calc(100vh - 56px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tpl-editor-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.13);
    border-radius: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
}
.tpl-editor-toolbar input,
.tpl-editor-toolbar select {
    padding: 8px 11px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(6, 13, 26, 0.5);
    color: #e2e8f0;
    font-size: 0.88rem;
    font-family: inherit;
}
.tpl-editor-toolbar input { flex: 1; min-width: 220px; }
.tpl-editor-toolbar .tpl-toolbar-spacer { flex: 1; }
.tpl-save-status {
    font-size: 0.78rem;
    color: #64748b;
}

.tpl-editor-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 16px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
@media (max-width: 1000px) {
    .tpl-editor-layout {
        grid-template-columns: 1fr;
        overflow: visible;
    }
    .tpl-editor-main { height: auto; }
}

.tpl-editor-canvas-wrap {
    overflow-y: auto;
    overflow-x: hidden;
    background: linear-gradient(180deg, #1a2233 0%, #151b2a 100%);
    border-radius: 14px;
    padding: 24px;
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tpl-editor-canvas {
    outline: none;
    width: 100%;
}

/* === Paginación visual: hojas tipo Word === */
.doc-pages {
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-items: center;
    padding: 4px 0 24px;
}
.doc-page {
    width: 816px;
    height: 1056px;
    background: #fff;
    color: #000;
    border-radius: 4px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    padding: 76px 76px 76px 113px; /* fallback — sobreescrito por inline style del doc-styles marker */
    box-sizing: border-box;
    position: relative;
    font-family: 'Times New Roman', Times, serif; /* fallback */
    font-size: 12pt;    /* fallback */
    line-height: 1.15;  /* fallback */
    page-break-after: always;
    break-after: page;
    overflow-wrap: break-word;
    overflow: hidden;
    flex-shrink: 0;
    /* Paridad con .ql-editor (que Quill fuerza a pre-wrap): sin esto un <p> vacío
       mide 16px aquí y 18px en el editor, y los espacios múltiples se colapsan.
       paginateHtml() limpia el whitespace entre bloques antes de medir. */
    white-space: pre-wrap;
}
.doc-page:last-child { page-break-after: auto; break-after: auto; }
.doc-page-content {
    height: calc(1056px - 76px - 76px);
    overflow: hidden;
}
.doc-page-footer {
    position: absolute;
    bottom: 28px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 11px;
    color: #9aa3b2;
    user-select: none;
    pointer-events: none;
}

/* Tipografía dentro de página (cubre editor y preview) */
.doc-page p { margin: 0 0 8pt; min-height: 1em; text-align: justify; }
.doc-page h1, .doc-page h2, .doc-page h3,
.doc-page h4, .doc-page h5, .doc-page h6 {
    font-family: 'Times New Roman', Times, serif;
    color: #000;
    font-weight: bold;
    margin: 6pt 0 3pt;
    line-height: 1.15;
}
.doc-page h1 { font-size: 12pt; }
.doc-page h2 { font-size: 12pt; }
.doc-page h3 { font-size: 12pt; }
.doc-page h4 { font-size: 12pt; font-style: normal; }
.doc-page h5 { font-size: 12pt; }
.doc-page h6 { font-size: 12pt; }
.doc-page .doc-title {
    font-size: 12pt;
    color: #000;
    font-weight: bold;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 4pt;
    text-align: center;
}
.doc-page .doc-subtitle { font-size: 12pt; color: #000; letter-spacing: 0; margin-bottom: 6pt; text-align: center; }
.doc-page blockquote { margin: 6pt 24pt; font-style: normal; color: #000; }
.doc-page blockquote.intense-quote { color: #000; border-left: none; padding-left: 0; font-style: normal; }
.doc-page ul, .doc-page ol { margin: 0 0 6pt; padding-left: 24pt; }
.doc-page li { margin-bottom: 2pt; }
.doc-page .list-paragraph { margin-left: 24pt; }
.doc-page .text-center  { text-align: center; }
.doc-page .text-right   { text-align: right; }
.doc-page .text-justify { text-align: justify; }
/* Marca de agua / membrete por página (detrás del texto) */
.doc-page-watermark {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 60%; height: 60%;
    object-fit: contain;
    background-repeat: no-repeat; background-position: center; background-size: contain;
    opacity: 0.45; pointer-events: none; z-index: 0;
    /* Forzar impresión del membrete (los navegadores omiten background-image por defecto) */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.doc-page-content { position: relative; z-index: 1; }
.doc-page table { border-collapse: collapse; margin: 8pt 0; max-width: 100%; }
.doc-page td, .doc-page th { border: 1px solid #999; padding: 4pt 7pt; vertical-align: top; }
.doc-page th { background: #d9e2f3; font-weight: 600; }
.doc-page img { max-width: 100%; height: auto; }
.doc-page a { color: #0563c1; text-decoration: underline; }
.doc-page cite { font-style: italic; }
.doc-page .subtle { color: #595959; font-style: italic; }
.doc-page .intense-em { color: #2e74b5; }
.doc-page hr { border: none; border-top: 1px solid #bfbfbf; margin: 12pt 0; }

/* Mobile / pantallas pequeñas: página llena de ancho */
@media (max-width: 1100px) {
    .doc-page {
        width: 100%;
        padding: 40px 32px 60px;
        min-height: 600px;
    }
    .doc-page-content { min-height: 480px; }
    .doc-page-footer { left: 0; right: 0; bottom: 28px; }
}

/* Print: hojas reales sin sombra ni gap */
@media print {
    body { background: #fff; }
    .doc-pages { display: block; gap: 0; padding: 0; }
    .doc-page {
        box-shadow: none;
        margin: 0;
        border-radius: 0;
        width: 100%;
        min-height: auto;
        padding: 0;
    }
    .doc-page-content { min-height: auto; }
    .doc-page-footer { display: none; }
}

/* Mammoth/Word output normalization */
.tpl-editor-canvas p {
    margin: 0 0 8pt;
    min-height: 1em;
    text-align: justify;
}
.tpl-editor-canvas h1, .tpl-editor-canvas h2, .tpl-editor-canvas h3,
.tpl-editor-canvas h4, .tpl-editor-canvas h5, .tpl-editor-canvas h6 {
    font-family: 'Times New Roman', Times, serif;
    color: #000;
    font-weight: bold;
    margin: 6pt 0 3pt;
    line-height: 1.15;
}
.tpl-editor-canvas h1 { font-size: 12pt; }
.tpl-editor-canvas h2 { font-size: 12pt; }
.tpl-editor-canvas h3 { font-size: 12pt; }
.tpl-editor-canvas h4 { font-size: 12pt; font-style: normal; }
.tpl-editor-canvas h5 { font-size: 12pt; }
.tpl-editor-canvas h6 { font-size: 12pt; }
.tpl-editor-canvas .doc-title {
    font-size: 12pt;
    color: #000;
    font-weight: bold;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 4pt;
    text-align: center;
}
.tpl-editor-canvas .doc-subtitle {
    font-size: 12pt;
    color: #000;
    letter-spacing: 0;
    margin-bottom: 6pt;
    text-align: center;
}

.tpl-editor-canvas blockquote {
    margin: 6pt 24pt;
    padding: 0;
    font-style: normal;
    color: #000;
}
.tpl-editor-canvas blockquote.intense-quote {
    color: #000;
    border-left: none;
    padding-left: 0;
    font-style: normal;
}

.tpl-editor-canvas ul, .tpl-editor-canvas ol {
    margin: 0 0 6pt;
    padding-left: 24pt;
}
.tpl-editor-canvas li { margin-bottom: 2pt; }
.tpl-editor-canvas .list-paragraph { margin-left: 24pt; }

.tpl-editor-canvas .text-center { text-align: center; }
.tpl-editor-canvas .text-right { text-align: right; }
.tpl-editor-canvas .text-justify { text-align: justify; }

.tpl-editor-canvas table {
    border-collapse: collapse;
    margin: 8pt 0;
    width: auto;
    max-width: 100%;
}
.tpl-editor-canvas td, .tpl-editor-canvas th {
    border: 1px solid #999;
    padding: 4pt 7pt;
    vertical-align: top;
    min-width: 40px;
}
.tpl-editor-canvas th { background: #d9e2f3; font-weight: 600; }

.tpl-editor-canvas img {
    max-width: 100%;
    height: auto;
}

.tpl-editor-canvas a { color: #0563c1; text-decoration: underline; }

.tpl-editor-canvas cite { font-style: italic; }
.tpl-editor-canvas .subtle { color: #595959; font-style: italic; }
.tpl-editor-canvas .intense-em { color: #2e74b5; }

.tpl-editor-canvas hr {
    border: none;
    border-top: 1px solid #bfbfbf;
    margin: 12pt 0;
}

/* Salto de página (visual en editor + page-break en impresión) */
.tpl-editor-canvas .page-break-before,
.cob-doc-preview .page-break-before {
    page-break-before: always;
    break-before: page;
    position: relative;
    margin-top: 48px;
    padding-top: 32px;
    border-top: 2px dashed #cbd5e1;
}
.tpl-editor-canvas .page-break-before::before,
.cob-doc-preview .page-break-before::before {
    content: "— Salto de página —";
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0 10px;
    color: #94a3b8;
    font-size: 9pt;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-family: 'Calibri', sans-serif;
}
@media print {
    .page-break-before::before { display: none; }
    .page-break-before {
        border-top: none;
        margin-top: 0;
        padding-top: 0;
    }
}

@media (max-width: 1100px) {
    .tpl-editor-canvas {
        width: 100%;
        padding: 40px 32px;
        min-height: 600px;
    }
}

/* Variable badge dentro del HTML editado */
.tpl-var {
    display: inline-block;
    background: rgba(52, 211, 153, 0.15);
    color: #059669;
    border: 1px solid rgba(52, 211, 153, 0.4);
    border-radius: 4px;
    padding: 2px 6px;
    margin: 0 1px;
    font-family: 'SF Mono', Consolas, 'Courier New', monospace;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    user-select: all;
}
.tpl-var:hover { background: rgba(52, 211, 153, 0.28); border-color: rgba(52, 211, 153, 0.55); }

.tpl-var-panel {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.8) 0%, rgba(15, 23, 42, 0.6) 100%);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 14px;
    padding: 20px;
    backdrop-filter: blur(12px);
    overflow-y: auto;
    height: 100%;
    box-sizing: border-box;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.03);
}
/* Sin padding superior: permite que el bloque flotante CONTRATO BASE se ancle
   a ras del borde del panel (sticky top:0) sin que las variables asomen. */
.tpl-var-panel { padding-top: 0; }
.tpl-var-panel-head { margin-top: 20px; }
.tpl-var-panel h3 {
    margin: 0 0 12px;
    font-size: 0.9rem;
    color: #f1f5f9;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.tpl-var-help {
    font-size: 0.78rem;
    color: #94a3b8;
    margin: 0 0 14px;
    line-height: 1.4;
}

.tpl-var-group {
    margin-bottom: 14px;
}
.tpl-var-group-name {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.78rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 4px;
    transition: color 0.06s;
}
.tpl-var-group-name:hover { color: #94a3b8; }
.tpl-var-chevron {
    transition: transform 0.1s;
    flex-shrink: 0;
}
.tpl-var-group.is-collapsed .tpl-var-chevron {
    transform: rotate(-90deg);
}
.tpl-var-group.is-collapsed .tpl-var-list {
    display: none;
}
.tpl-var-list { display: flex; flex-direction: column; gap: 4px; }
.tpl-var-item {
    position: relative;
    background: rgba(6, 13, 26, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
    text-align: left;
    padding: 9px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.92rem;
    font-family: inherit;
    transition: all 0.06s;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.tpl-var-item:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
    color: #e2e8f0;
}
.tpl-var-item-key {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.8rem;
    color: #64748b;
}
.tpl-var-item:hover .tpl-var-item-key { color: #93c5fd; }

/* Tooltip flotante de variable: explicación + ejemplo del proyecto */
.tpl-var-tooltip {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    background: #0f172a;
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    font-size: 0.78rem;
    line-height: 1.45;
}
.tpl-var-tooltip-desc { color: #cbd5e1; }
.tpl-var-tooltip-example {
    margin-top: 7px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.74rem;
    word-break: break-word;
}
.tpl-var-tooltip-example span { color: #64748b; font-family: inherit; }
.tpl-var-tooltip-note { margin-top: 5px; color: #64748b; font-size: 0.7rem; font-style: italic; }
html[data-theme="light"] .tpl-var-tooltip {
    background: #ffffff;
    border-color: rgba(59, 130, 246, 0.25);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}
html[data-theme="light"] .tpl-var-tooltip-desc { color: #334155; }
html[data-theme="light"] .tpl-var-tooltip-example { background: rgba(59, 130, 246, 0.08); color: #2563eb; }

/* === Configuracion === */
.tpl-config-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 32px;
    position: relative;
    z-index: 1;
}
.tpl-config-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.13);
    border-radius: 14px;
    padding: 24px;
    backdrop-filter: blur(10px);
}
.tpl-config-card h2 {
    margin: 0 0 6px;
    color: #e2e8f0;
}
.tpl-config-card p {
    color: #94a3b8;
    font-size: 0.88rem;
    margin: 0 0 20px;
}
.tpl-config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
@media (max-width: 600px) {
    .tpl-config-grid { grid-template-columns: 1fr; }
}
.tpl-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.tpl-field--full { grid-column: 1 / -1; }
.tpl-field label {
    font-size: 0.78rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.tpl-field input,
.tpl-field textarea {
    padding: 10px 12px;
    border-radius: 9px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(6, 13, 26, 0.5);
    color: #e2e8f0;
    font-size: 0.9rem;
    font-family: inherit;
    box-sizing: border-box;
}
.tpl-field input:focus,
.tpl-field textarea:focus {
    outline: none;
    border-color: #3b82f6;
}

.tpl-config-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}
.tpl-config-actions .tpl-save-status {
    margin-right: auto;
}

/* === Selector de template en contrato.html === */
.cob-doc-selector {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.cob-doc-selector select {
    flex: 1;
    min-width: 200px;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(6, 13, 26, 0.5);
    color: #e2e8f0;
    font-size: 0.88rem;
    font-family: inherit;
}
.cob-doc-preview {
    background: #1a2233;
    border-radius: 10px;
    padding: 16px;
    margin-top: 14px;
    max-height: 780px;
    overflow-y: auto;
    border: 1px solid rgba(148, 163, 184, 0.18);
}
.cob-doc-preview p { margin: 0 0 8pt; min-height: 1em; text-align: justify; }
.cob-doc-preview h1, .cob-doc-preview h2, .cob-doc-preview h3,
.cob-doc-preview h4, .cob-doc-preview h5, .cob-doc-preview h6 {
    font-family: 'Times New Roman', Times, serif;
    color: #000; font-weight: bold; margin: 6pt 0 3pt; line-height: 1.15;
}
.cob-doc-preview h1 { font-size: 12pt; }
.cob-doc-preview h2 { font-size: 12pt; }
.cob-doc-preview h3 { font-size: 12pt; }
.cob-doc-preview h4 { font-size: 12pt; font-style: normal; }
.cob-doc-preview .doc-title {
    font-size: 12pt; color: #000; font-weight: bold; border-bottom: none;
    padding-bottom: 0; margin-bottom: 4pt; text-align: center;
}
.cob-doc-preview .doc-subtitle { font-size: 12pt; color: #000; letter-spacing: 0; text-align: center; }
.cob-doc-preview blockquote { margin: 6pt 24pt; font-style: normal; color: #000; }
.cob-doc-preview blockquote.intense-quote {
    color: #000; border-left: none; padding-left: 0; font-style: normal;
}
.cob-doc-preview ul, .cob-doc-preview ol { margin: 0 0 6pt; padding-left: 24pt; }
.cob-doc-preview li { margin-bottom: 2pt; }
.cob-doc-preview .list-paragraph { margin-left: 24pt; }
.cob-doc-preview .text-center { text-align: center; }
.cob-doc-preview .text-right  { text-align: right; }
.cob-doc-preview .text-justify { text-align: justify; }
.cob-doc-preview table { border-collapse: collapse; margin: 8pt 0; max-width: 100%; }
.cob-doc-preview td, .cob-doc-preview th {
    border: 1px solid #999; padding: 4pt 7pt; vertical-align: top;
}
.cob-doc-preview th { background: #d9e2f3; font-weight: 600; }
.cob-doc-preview img { max-width: 100%; height: auto; }
.cob-doc-preview a { color: #0563c1; text-decoration: underline; }
.cob-doc-preview cite { font-style: italic; }
.cob-doc-preview .subtle { color: #595959; font-style: italic; }
.cob-doc-preview .intense-em { color: #2e74b5; }
.cob-doc-preview hr { border: none; border-top: 1px solid #bfbfbf; margin: 12pt 0; }

@media (max-width: 720px) {
    .cob-doc-preview { padding: 32px 24px; }
}
.cob-doc-preview .tpl-var {
    background: rgba(239, 68, 68, 0.15);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.4);
}
.cob-doc-empty {
    color: #64748b;
    font-size: 0.88rem;
    padding: 14px;
    text-align: center;
    border: 1px dashed rgba(148, 163, 184, 0.2);
    border-radius: 8px;
}
.cob-doc-history {
    margin-top: 14px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
    padding-top: 14px;
}
.cob-doc-history h4 {
    font-size: 0.78rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 8px;
}
.cob-doc-hist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(6, 13, 26, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 0.82rem;
}
.cob-doc-hist-item span { flex: 1; color: #cbd5e1; }
.cob-doc-hist-item time { color: #64748b; font-size: 0.75rem; }
.cob-doc-hist-item a {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.78rem;
}
.cob-doc-hist-item a:hover { text-decoration: underline; }

/* Print: oculta UI, muestra solo preview */
@media print {
    body > *:not(.cob-doc-print-target) { display: none !important; }
    .cob-doc-print-target {
        background: #fff;
        color: #000;
        padding: 0;
        margin: 0;
        max-height: none;
        overflow: visible;
        border: none;
    }
}

/* ============================================================
   EDITOR v2 — Topbar + Format Bar (Word-like)
   ============================================================ */

/* Input nombre dentro de la barra unificada */
.tfb-input-nombre {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(6, 13, 26, 0.6);
    color: #f1f5f9;
    font-size: 0.9rem;
    font-family: inherit;
    min-width: 200px;
    flex: 1;
    transition: all 0.08s ease;
}
.tfb-input-nombre:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.tfb-input-nombre::placeholder { color: #64748b; }

/* Carpeta dentro de la barra */
.tfb-carpeta { min-width: 100px; max-width: 150px; }

/* Nombre + carpeta cuando están en el dash-header */
.tpl-header-nombre {
    min-width: 360px;
    max-width: 800px;
    flex: 1 1 360px;
    padding: 5px 12px;
    height: 34px;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(6, 13, 26, 0.55);
    color: #f1f5f9;
    font-family: inherit;
    transition: all 0.08s ease;
}
.tpl-header-nombre:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.tpl-header-nombre::placeholder { color: #64748b; }

.tpl-header-carpeta {
    height: 34px;
    padding: 5px 10px;
    font-size: 0.85rem;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(6, 13, 26, 0.55);
    color: #cbd5e1;
    font-family: inherit;
    cursor: pointer;
    min-width: 110px;
    max-width: 160px;
    flex-shrink: 0;
}

/* Estado de guardado (dentro del widget zoom) */
.tpl-zoom-widget .tpl-save-status {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* === Widget zoom: fixed en borde izquierdo de pantalla === */
.tpl-zoom-widget {
    position: fixed;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.9) 0%, rgba(15, 23, 42, 0.75) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 10px 8px;
    z-index: 20;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    user-select: none;
}
.tzw-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(148, 163, 184, 0.1);
    color: #cbd5e1;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.08s ease;
}
.tzw-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #93c5fd;
    transform: scale(1.05);
}
.tzw-label {
    font-size: 0.75rem;
    color: #f1f5f9;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    min-width: 32px;
}
.tzw-sep {
    width: 20px;
    height: 1px;
    background: rgba(148, 163, 184, 0.25);
    flex-shrink: 0;
}
.tzw-page-info {
    font-size: 0.7rem;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    text-align: center;
    line-height: 1;
}

/* === Format Bar === */
.tpl-format-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.75) 0%, rgba(15, 23, 42, 0.55) 100%);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    padding: 10px 14px;
    flex-wrap: wrap;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    /* Estabiliza la capa de composición: dos barras fijas apiladas con
       backdrop-filter (header + esta) hacen parpadear toda la barra en Chrome.
       `will-change` la promueve a capa propia (no lo bloquea el guard de base.css
       que fuerza transform:none en elementos fijos). */
    will-change: transform;
}

/* Toolbar button */
.tfb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 10px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: rgba(148, 163, 184, 0.08);
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.82rem;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.08s ease;
}
.tfb-btn:hover {
    background: rgba(148, 163, 184, 0.15);
    border-color: rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
    transform: translateY(-1px);
}
.tfb-btn.is-active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25) 0%, rgba(99, 102, 241, 0.2) 100%);
    border-color: rgba(147, 197, 253, 0.5);
    color: #93c5fd;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.tfb-bold  { font-weight: 700; }
.tfb-italic { font-style: italic; }
.tfb-underline { text-decoration: underline; }
.tfb-strike { text-decoration: line-through; }

/* Separator */
.tfb-sep {
    width: 1px;
    height: 22px;
    background: rgba(148, 163, 184, 0.2);
    margin: 0 4px;
    flex-shrink: 0;
}

/* Selects */
.tfb-select {
    height: 30px;
    padding: 0 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    background: rgba(6, 13, 26, 0.6);
    color: #f1f5f9;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.08s ease;
}
.tfb-select:hover {
    border-color: rgba(148, 163, 184, 0.35);
}
.tfb-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.tfb-select option { background: #1e293b; color: #e2e8f0; }
.tfb-font  { min-width: 110px; max-width: 130px; }
.tfb-size  { width: 52px; }
.tfb-heading { min-width: 90px; max-width: 110px; }

/* Color button */
.tfb-color-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 2px 5px;
    min-width: 28px;
    height: 28px;
    justify-content: center;
}
.tfb-color-icon {
    font-size: 14px;
    line-height: 1;
    font-weight: 700;
    color: #cbd5e1;
}
.tfb-color-bar {
    display: block;
    width: 18px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}
.tfb-color-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}


/* === Table popup (picker de filas/cols) === */
.tfb-table-popup {
    position: fixed;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 12px;
    z-index: 9999;
    min-width: 160px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
}
.tfb-table-grid {
    display: grid;
    grid-template-columns: repeat(8, 20px);
    gap: 4px;
    margin-bottom: 8px;
}
.tfb-table-cell {
    width: 20px;
    height: 20px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 4px;
    cursor: pointer;
    background: rgba(30, 41, 59, 0.5);
    transition: all 0.05s ease;
}
.tfb-table-cell:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
}
.tfb-table-cell.is-selected {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.4) 0%, rgba(99, 102, 241, 0.35) 100%);
    border-color: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}
.tfb-table-label {
    text-align: center;
    font-size: 0.8rem;
    color: #cbd5e1;
    font-weight: 500;
}

/* === Variables panel: header + search === */
.tpl-var-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.tpl-var-panel-head h3 { margin: 0; }

/* Elementos que se ocultan al entrar en modo edición */
.tpl-var-panel-head,
.tpl-var-help {
    overflow: hidden;
    transition: max-height 0.14s cubic-bezier(0.4, 0, 0.2, 1),
                opacity    0.11s ease,
                margin     0.14s cubic-bezier(0.4, 0, 0.2, 1);
}
.tpl-var-panel-head { max-height: 60px; opacity: 1; }
.tpl-var-help       { max-height: 60px; opacity: 1; margin-bottom: 14px; }

.tpl-var-panel-head.is-hidden,
.tpl-var-help.is-hidden {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    margin-top: 0;
    pointer-events: none;
}
.tpl-vars-search {
    width: 100%;
    padding: 8px 11px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(6, 13, 26, 0.5);
    color: #e2e8f0;
    font-size: 0.85rem;
    font-family: inherit;
    margin-bottom: 12px;
    box-sizing: border-box;
}
.tpl-vars-search:focus { outline: none; border-color: #3b82f6; }
.tpl-vars-search::placeholder { color: #64748b; }

/* tpl-var-item hidden when filtered */
.tpl-var-item[data-hidden="1"] { display: none; }
.tpl-var-group[data-hidden="1"] { display: none; }

/* Variable en uso en el documento */
.tpl-var-item[data-in-use="1"] {
    border-left: 3px solid #34d399;
    background: rgba(52, 211, 153, 0.08);
    padding-right: 44px; /* espacio para contador */
}
.tpl-var-item[data-in-use="1"]::after {
    content: "✓";
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: #34d399;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Contador de usos - clickeable para navegar */
.tpl-var-counter {
    display: none;
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.08s ease;
    z-index: 10;
}
.tpl-var-item[data-in-use="1"] .tpl-var-counter {
    display: flex;
}
.tpl-var-counter:hover {
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
}
.tpl-var-counter:empty {
    display: none;
}

/* Highlight visual persistente cuando el editor pierde foco */
.tpl-fake-sel {
    background: rgba(59, 130, 246, 0.35);
    border-radius: 1px;
}

/* === Canvas zoom wrapper === */
.tpl-editor-canvas-zoom {
    transform-origin: top center;
    transition: transform 0.08s;
    display: inline-block;
    width: 100%;
}

/* === Layout principal con barra unificada === */
.tpl-editor-main {
    width: 100%;
    margin: 0;
    padding: 8px 10px 10px;
    position: relative;
    z-index: 1;
    height: calc(100vh - 56px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Tabla editable: resaltar celda activa */
.doc-page td:focus, .doc-page th:focus {
    outline: 2px solid #3b82f6;
    outline-offset: -1px;
}

/* Selección de celda de tabla al hover en editor */
.tpl-editor-canvas .doc-page td,
.tpl-editor-canvas .doc-page th {
    min-width: 40px;
    min-height: 1.4em;
}

/* Cursor de resize en bordes de tabla */
.tpl-editor-canvas table { cursor: text; }

@media (max-width: 1000px) {
    .tpl-format-bar { gap: 1px; padding: 4px 6px; }
    .tfb-font { min-width: 80px; }
    .tpl-editor-main { height: auto; padding: 8px; }
}

@media print {
    .tpl-editor-topbar,
    .tpl-format-bar,
    .tpl-var-panel { display: none !important; }
}

/* ─── Personalización de variables ─────────────────────────────────────────── */

/* Botón "Personalizar" en el header del panel */
.tpl-vars-customize-btn {
    all: unset;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(148, 163, 184, 0.06);
    cursor: pointer;
    transition: all 0.08s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.tpl-vars-customize-btn:hover {
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.1);
}
.tpl-vars-customize-btn.is-active {
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.45);
    background: rgba(99, 102, 241, 0.12);
}

/* Banner: modo personalización activo */
.tpl-vars-edit-banner {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
    font-size: 0.78rem;
    line-height: 1.3;
}
.tpl-vars-edit-banner[hidden] { display: none; }
.tpl-vars-done-btn {
    all: unset;
    margin-left: auto;
    padding: 3px 10px;
    border-radius: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(99, 102, 241, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.5);
    color: #c7d2fe;
    transition: all 0.06s;
    white-space: nowrap;
    flex-shrink: 0;
}
.tpl-vars-done-btn:hover {
    background: rgba(99, 102, 241, 0.4);
    color: #e0e7ff;
}


/* Item de variable: en modo edición muestra el ojo */
.tpl-var-item .tpl-var-eye-btn {
    display: none;
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(148, 163, 184, 0.1);
    color: #64748b;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.06s;
    z-index: 15;
    flex-shrink: 0;
    padding: 0;
}
.tpl-var-item .tpl-var-eye-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

/* En modo edición: mostrar el ojo en todos los items, ocultar el contador */
.vars-catalog--editing .tpl-var-item .tpl-var-eye-btn {
    display: inline-flex;
}
.vars-catalog--editing .tpl-var-counter {
    display: none !important;
}
.vars-catalog--editing .tpl-var-item {
    padding-right: 34px;
    cursor: default;
}
.vars-catalog--editing .tpl-var-item[data-in-use="1"]::after {
    right: 36px;
}

/* Item marcado como oculto por el usuario: se oculta completamente
   a menos que el catálogo esté en modo personalización */
.tpl-var-item[data-user-hidden="1"] {
    display: none;
}
.vars-catalog--editing .tpl-var-item[data-user-hidden="1"] {
    display: flex;
    opacity: 0.38;
    border-style: dashed;
    background: rgba(148, 163, 184, 0.04);
}
.tpl-var-item[data-user-hidden="1"] .tpl-var-eye-btn {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.35);
}
.tpl-var-item[data-user-hidden="1"] .tpl-var-eye-btn:hover {
    background: rgba(52, 211, 153, 0.15);
    border-color: rgba(52, 211, 153, 0.4);
    color: #6ee7b7;
}

/* Animación de aparición de items ocultos al entrar en modo edición */
@keyframes var-expand {
    0%   { max-height: 0;   opacity: 0;   margin-bottom: 0;    padding-top: 0;    padding-bottom: 0;    transform: translateX(18px) scaleY(0);    filter: blur(4px); }
    30%  { opacity: 0;      margin-bottom: 2px;                                                          transform: translateX(14px) scaleY(0.4);  filter: blur(4px); }
    70%  { opacity: 0.4;                                                                                  transform: translateX(8px)  scaleY(0.85); filter: blur(2px); }
    100% { max-height: 80px; opacity: 1;  margin-bottom: 4px;  padding-top: 7px;  padding-bottom: 7px;  transform: translateX(0)    scaleY(1);    filter: blur(0px); }
}
.tpl-var-item.is-expanding {
    overflow: hidden;
    transform-origin: top center;
    animation: var-expand 0.28s cubic-bezier(0.15, 0, 0.4, 1) forwards;
    pointer-events: none;
}

/* Animación de colapso al ocultar variable (al pulsar Listo) */
@keyframes var-collapse {
    0%   { max-height: 80px; opacity: 1;    margin-bottom: 4px; padding-top: 7px; padding-bottom: 7px; transform: translateX(0)   scaleY(1);    filter: blur(0px); }
    30%  { opacity: 0.4;                                                                                transform: translateX(8px)  scaleY(0.85); filter: blur(2px); }
    70%  { opacity: 0;    margin-bottom: 2px;                                                           transform: translateX(14px) scaleY(0.4);  filter: blur(4px); }
    100% { max-height: 0; opacity: 0;    margin-bottom: 0;    padding-top: 0;    padding-bottom: 0;    transform: translateX(18px) scaleY(0);    filter: blur(4px); }
}
.tpl-var-item.is-collapsing {
    overflow: hidden;
    transform-origin: top center;
    animation: var-collapse 0.28s cubic-bezier(0.4, 0, 0.15, 1) forwards;
    pointer-events: none;
}

/* Banner de edición flotante al hacer scroll */
@keyframes banner-float-in {
    0%   { opacity: 0; transform: translateY(-14px) scale(0.97); filter: blur(3px); }
    100% { opacity: 1; transform: translateY(0)    scale(1);    filter: blur(0px); }
}
.tpl-vars-edit-banner.is-floating {
    position: sticky;
    top: 8px;
    z-index: 20;
    background: rgba(30, 27, 75, 0.97);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(99, 102, 241, 0.45);
    animation: banner-float-in 0.18s cubic-bezier(0.2, 0, 0.3, 1) 0.1s both;
}

/* Header back button (Templates) */
.tpl-header-back {
    background: linear-gradient(135deg, rgba(99,102,241,0.12) 0%, rgba(59,130,246,0.08) 100%);
    color: #818cf8;
    border: 1px solid rgba(99,102,241,0.3);
}
.tpl-header-back:hover {
    background: linear-gradient(135deg, rgba(99,102,241,0.2) 0%, rgba(59,130,246,0.15) 100%);
    border-color: rgba(99,102,241,0.45);
    color: #a5b4fc;
}

/* =============================
   LIGHT THEME OVERRIDES
   ============================= */
html[data-theme="light"] .tpl-header-back {
    background: linear-gradient(135deg, rgba(59,130,246,0.08) 0%, rgba(37,99,235,0.05) 100%);
    color: #3b82f6;
    border-color: rgba(59,130,246,0.2);
}
html[data-theme="light"] .tpl-header-back:hover {
    background: linear-gradient(135deg, rgba(59,130,246,0.15) 0%, rgba(37,99,235,0.1) 100%);
    border-color: rgba(59,130,246,0.35);
    color: #2563eb;
}
html[data-theme="light"] .tpl-sidebar,
html[data-theme="light"] .tpl-content,
html[data-theme="light"] .tpl-config-card {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.03);
}

html[data-theme="light"] .tpl-content-head h2 {
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-sidebar-head h3 {
    color: #4b5563;
}

html[data-theme="light"] .tpl-folder {
    color: #4b5563;
}
html[data-theme="light"] .tpl-folder:hover {
    background: rgba(59, 130, 246, 0.06);
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-folder.is-active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(96, 165, 250, 0.07) 100%);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.08);
}
html[data-theme="light"] .tpl-folder-count {
    background: rgba(0, 0, 0, 0.05);
    color: #6b7280;
}

html[data-theme="light"] .tpl-btn--ghost {
    background: #fafafa;
    color: #1a1a1a;
    border-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
html[data-theme="light"] .tpl-btn--ghost:hover {
    background: #f5f5f5;
    color: #1a1a1a;
    border-color: rgba(59, 130, 246, 0.25);
    box-shadow: none;
}

html[data-theme="light"] .tpl-btn--ghost-danger {
    background: rgba(229, 62, 62, 0.06);
    color: #c53030;
    border-color: rgba(229, 62, 62, 0.2);
    box-shadow: none;
}
html[data-theme="light"] .tpl-btn--ghost-danger:hover {
    background: rgba(229, 62, 62, 0.1);
    color: #9b2c2c;
    border-color: rgba(229, 62, 62, 0.35);
    box-shadow: none;
}

html[data-theme="light"] .tpl-loading,
html[data-theme="light"] .tpl-empty {
    color: #4b5563;
}
html[data-theme="light"] .tpl-empty p:first-child {
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-empty-sub {
    color: #4b5563;
}
html[data-theme="light"] .tpl-empty .big-icon {
    opacity: 0.4;
    color: #6b7280;
}

html[data-theme="light"] .tpl-card {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.03);
}
html[data-theme="light"] .tpl-card:hover {
    border-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05), 0 0 0 1px rgba(59, 130, 246, 0.1);
}
html[data-theme="light"] .tpl-card-name {
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-card-meta {
    color: #6b7280;
}
html[data-theme="light"] .tpl-card--locked {
    border-color: rgba(180, 120, 0, 0.2);
}
html[data-theme="light"] .tpl-card--locked:hover {
    border-color: rgba(180, 120, 0, 0.35);
}
html[data-theme="light"] .tpl-btn--secondary {
    background: rgba(245, 158, 11, 0.1);
    color: #b45309;
    border-color: rgba(180, 120, 0, 0.3);
}
html[data-theme="light"] .tpl-btn--secondary:hover {
    background: rgba(245, 158, 11, 0.18);
    color: #92400e;
    border-color: rgba(180, 120, 0, 0.5);
}

/* Editor canvas - light theme */
html[data-theme="light"] .tpl-editor-canvas-wrap {
    background: #f8fafc !important;
}
html[data-theme="light"] .tpl-editor-canvas {
    background: #ffffff !important;
    color: #1a1a1a !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.02) !important;
}
html[data-theme="light"] .tpl-editor-layout {
    background: transparent;
}

/* Format bar - light theme */
html[data-theme="light"] .tpl-format-bar {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.06) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04) !important;
}
html[data-theme="light"] .tfb-btn {
    background: #f3f4f6 !important;
    color: #374151 !important;
    border-color: rgba(0,0,0,0.06) !important;
}
html[data-theme="light"] .tfb-btn:hover {
    background: #e5e7eb !important;
    border-color: rgba(0,0,0,0.1) !important;
    color: #111827 !important;
}
html[data-theme="light"] .tfb-btn.is-active {
    background: #dbeafe !important;
    border-color: #3b82f6 !important;
    color: #1d4ed8 !important;
}
html[data-theme="light"] .tfb-sep {
    background: rgba(0,0,0,0.08) !important;
}
html[data-theme="light"] .tfb-select {
    background: #f3f4f6 !important;
    border-color: rgba(0,0,0,0.08) !important;
    color: #374151 !important;
}
html[data-theme="light"] .tfb-select:hover {
    border-color: rgba(0,0,0,0.12) !important;
}
html[data-theme="light"] .tfb-select option {
    background: #ffffff !important;
    color: #374151 !important;
}

/* Variable panel - light theme */
html[data-theme="light"] .tpl-var-panel {
    background: #ffffff;
    border-left-color: rgba(0, 0, 0, 0.05);
    border-color: rgba(0,0,0,0.06);
}
html[data-theme="light"] .tpl-var-panel h3 {
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-var-help {
    color: #4b5563;
}
html[data-theme="light"] .tpl-vars-search {
    background: #fafafa;
    border-color: rgba(0,0,0,0.08);
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-vars-search::placeholder {
    color: #9ca3af;
}

/* Zoom widget - light theme */
html[data-theme="light"] .tpl-zoom-widget {
    background: rgba(255,255,255,0.95);
    border-color: rgba(0,0,0,0.08);
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
html[data-theme="light"] .tzw-label {
    color: #1a1a1a;
}
html[data-theme="light"] .tzw-page-info {
    color: #4b5563;
}

/* Header inputs - light theme */
html[data-theme="light"] .tpl-header-nombre {
    background: #fafafa;
    border-color: rgba(0,0,0,0.08);
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-header-nombre:focus {
    background: #ffffff;
    border-color: #3b82f6;
}
html[data-theme="light"] .tpl-header-carpeta {
    background: #fafafa;
    border-color: rgba(0,0,0,0.08);
    color: #1a1a1a;
}

html[data-theme="light"] .tpl-var-item {
    background: #fafafa;
    border-color: rgba(0, 0, 0, 0.05);
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-var-item:hover {
    background: #f5f5f5;
    border-color: rgba(59, 130, 246, 0.2);
}
html[data-theme="light"] .tpl-var-label {
    color: #4b5563;
}
html[data-theme="light"] .tpl-var-value,
html[data-theme="light"] .tpl-var-input {
    color: #1a1a1a;
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .tpl-var-input:focus {
    border-color: #3b82f6;
    background: #ffffff;
}

html[data-theme="light"] .tpl-field label {
    color: #4b5563;
}
html[data-theme="light"] .tpl-save-status {
    color: #4b5563;
}
html[data-theme="light"] .tpl-vars-customize-btn {
    background: rgba(0,0,0,0.04);
    color: #4b5563;
    border-color: rgba(0,0,0,0.06);
}
html[data-theme="light"] .tpl-vars-customize-btn:hover {
    background: rgba(59,130,246,0.08);
    color: #2563eb;
    border-color: rgba(59,130,246,0.2);
}
html[data-theme="light"] .tpl-vars-customize-btn.is-active {
    background: rgba(59,130,246,0.12);
    color: #1d4ed8;
    border-color: rgba(59,130,246,0.3);
}
html[data-theme="light"] .tpl-var-help {
    color: #4b5563;
}
html[data-theme="light"] .tpl-var-group-name {
    color: #4b5563;
}
html[data-theme="light"] .tpl-var-group-name:hover {
    color: #6b7280;
}
html[data-theme="light"] .tpl-var-item-key {
    color: #6b7280;
}
html[data-theme="light"] .tpl-var-item:hover .tpl-var-item-key {
    color: #2563eb;
}
html[data-theme="light"] .tpl-config-card h2 {
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-config-card p {
    color: #4b5563;
}
html[data-theme="light"] .tpl-vars-search::placeholder {
    color: #9ca3af;
}
html[data-theme="light"] .tpl-header-nombre::placeholder {
    color: #9ca3af;
}
html[data-theme="light"] .tfb-input-nombre::placeholder {
    color: #9ca3af;
}
html[data-theme="light"] .tzw-page-info {
    color: #4b5563;
}
html[data-theme="light"] .tfb-btn {
    color: #4b5563;
    background: rgba(0, 0, 0, 0.04);
}
html[data-theme="light"] .tfb-btn:hover {
    color: #1a1a1a;
    background: rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .tfb-btn.is-active {
    color: #ffffff;
}
html[data-theme="light"] .tpl-var-tag {
    color: #4b5563;
    border-color: rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.03);
}
html[data-theme="light"] .tpl-zoom-btn {
    color: #4b5563;
    background: rgba(0, 0, 0, 0.04);
}
html[data-theme="light"] .tpl-zoom-btn:hover {
    color: #1a1a1a;
    background: rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .tpl-field input,
html[data-theme="light"] .tpl-field textarea,
html[data-theme="light"] .tpl-field select {
    background: #fafafa;
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a1a1a;
}
html[data-theme="light"] .tpl-field input:focus,
html[data-theme="light"] .tpl-field textarea:focus,
html[data-theme="light"] .tpl-field select:focus {
    background: #ffffff;
    border-color: #3b82f6;
}

html[data-theme="light"] .tpl-vars-edit-banner {
    background: #f8fafc !important;
    border-color: rgba(59, 130, 246, 0.15) !important;
    color: #2563eb !important;
}
html[data-theme="light"] .tpl-vars-edit-banner svg {
    color: #3b82f6 !important;
}
html[data-theme="light"] .tpl-vars-done-btn {
    background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
    color: #ffffff !important;
    border-color: transparent !important;
}
html[data-theme="light"] .tpl-vars-edit-banner.is-floating {
    background: rgba(255, 255, 255, 0.97) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08), 0 0 0 1px rgba(59, 130, 246, 0.15) !important;
}

/* ═══════════════════════════════════════════════════════════
   LIGHT THEME — cob-doc-preview (contrato.html)
═══════════════════════════════════════════════════════════ */
html[data-theme="light"] .cob-doc-preview {
    background: #e8edf2;
    border-color: rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .cob-doc-selector select {
    background: #fafafa;
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a1a1a;
}
html[data-theme="light"] .cob-doc-empty {
    color: #6b7280;
}
html[data-theme="light"] .cob-doc-empty a {
    color: #2563eb;
}
