        :root {
            --rojo: #E73747;
            --sandia: #FC6A6D;
            --rosa-claro: #FED2D2;
            --casi-blanco: #FFFAFA;
            --blanco: #FFFFFF;
            --gris-oscuro: #353535;
            --azul: #2A439E;
            --celeste: #6095E2;
            --amarillo: #FFCF00;
            --azul-marino: #061C4F;
            --rojo-hover: #FC6A6D;
            --rojo-oscuro: #b22230;
            --rojo-claro: #FED2D2;
            --amarillo-hover: #FFCF00;
            --amarillo-claro: #FFE04A;
            --gris-claro: #FFFAFA;
            --gris-medio: #e2e5ea;
            --verde: #22c55e;
            --verde-claro: #dcfce7;
            --naranja: #f59e0b;
            --naranja-claro: #fef3c7;
            --rojo-fondo: #FED2D2;
            --sombra-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
            --sombra-md: 0 4px 20px rgba(0, 0, 0, 0.12);
            --sombra-lg: 0 12px 48px rgba(0, 0, 0, 0.18);
            --sombra-xl: 0 20px 60px rgba(0, 0, 0, 0.22);
            --radio-sm: 8px;
            --radio-md: 12px;
            --radio-lg: 20px;
            --radio-xl: 24px;
            --transicion: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Avenir', 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: #f3f4f6;
            color: var(--gris-oscuro);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
            overflow-x: hidden;
            padding-bottom: 120px;
            /* Space for bulk actions bar */
        }

        .dashboard-container,
        footer {
            position: relative;
            z-index: 1;
        }

        /* ====== HEADER ====== */
        .admin-header {
            text-align: left;
            padding: 0.75rem 2rem;
            color: white;
            width: 100%;
            max-width: none;
            animation: slideDown 0.6s ease-out;
            display: flex;
            align-items: center;
            gap: 1rem;
            background: var(--rojo);
            margin-top: 0;
            position: relative;
        }

        /* Header Stats */
        .header-stats {
            display: flex;
            gap: 0.5rem;
            margin-left: auto;
            background: rgba(0, 0, 0, 0.15);
            padding: 0.4rem 0.75rem;
            border-radius: 6px;
        }

        .header-stat {
            font-size: 0.8rem;
            color: rgba(255, 255, 255, 0.85);
            display: flex;
            align-items: center;
            gap: 0.25rem;
            padding: 0 0.5rem;
            border-right: 1px solid rgba(255, 255, 255, 0.2);
        }

        .header-stat:last-child {
            border-right: none;
            padding-right: 0;
        }

        .header-stat:first-child {
            padding-left: 0;
        }

        .header-stat strong {
            font-size: 0.85rem;
            font-weight: 700;
            color: white;
        }

        .admin-brand {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            min-width: 160px;
        }

        .admin-logo {
            max-width: 90px;
            height: auto;
            margin-bottom: 0;
            filter: brightness(0) invert(1);
        }

        .admin-logo-fallback {
            display: none;
            align-items: center;
            justify-content: flex-start;
            gap: 0.6rem;
            margin-bottom: 0;
        }

        .admin-logo-fallback .logo-icon {
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(10px);
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: var(--radio-sm);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: 800;
            font-size: 0.85rem;
        }

        .admin-logo-fallback .logo-text {
            font-size: 1.25rem;
            font-weight: 700;
            letter-spacing: -0.5px;
        }

        .admin-title {
            display: flex;
            flex-direction: column;
            gap: 0.35rem;
        }

        .admin-header h1 {
            font-size: 1.1rem;
            font-weight: 700;
            margin: 0;
            letter-spacing: -0.3px;
            line-height: 1.2;
        }

        .admin-header p {
            font-size: 0.8rem;
            opacity: 0.85;
            font-weight: 500;
            letter-spacing: 0.4px;
            text-transform: uppercase;
            margin: 0;
        }

        /* User Bar - part of header flex */
        .user-bar {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            color: white;
            font-size: 0.75rem;
            margin-left: 1rem;
        }

        .user-bar>span {
            opacity: 0.9;
            font-weight: 500;
        }

        .user-settings {
            width: 28px;
            height: 28px;
            border-radius: 6px;
            background: rgba(255, 255, 255, 0.12);
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.25);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all var(--transicion);
        }

        .user-settings:hover {
            background: rgba(255, 255, 255, 0.22);
            border-color: rgba(255, 255, 255, 0.4);
        }

        .user-settings svg {
            width: 14px;
            height: 14px;
        }

        .btn-logout {
            background: rgba(255, 255, 255, 0.12);
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.25);
            color: white;
            padding: 0.35rem 0.75rem;
            border-radius: 6px;
            cursor: pointer;
            font-family: inherit;
            font-size: 0.8rem;
            font-weight: 600;
            transition: all var(--transicion);
            display: flex;
            align-items: center;
            gap: 0.3rem;
        }

        .btn-logout:hover {
            background: rgba(255, 255, 255, 0.22);
            border-color: rgba(255, 255, 255, 0.4);
        }

        .btn-logout svg {
            width: 14px;
            height: 14px;
        }

        /* ====== LAYOUT ====== */
        .dashboard-container {
            width: 100%;
            max-width: 1000px;
            padding: 1.5rem 1rem 1.5rem;
            display: flex;
            flex-direction: column;
            gap: 0;
            animation: slideUp 0.5s ease-out;
        }

        /* ====== NAV TABS ====== */
        .nav-tabs {
            display: flex;
            gap: 0;
            background: transparent;
        }

        .nav-tab {
            background: #e5e7eb;
            color: #6b7280;
            padding: 0.6rem 1.25rem;
            border-radius: var(--radio-sm) var(--radio-sm) 0 0;
            cursor: pointer;
            font-weight: 500;
            font-size: 0.8rem;
            transition: all var(--transicion);
            border: 1px solid #d1d5db;
            border-bottom: none;
            display: flex;
            align-items: center;
            gap: 0.4rem;
            margin-bottom: -1px;
        }

        .nav-tab:hover {
            background: #f3f4f6;
            color: var(--gris-oscuro);
        }

        .nav-tab.active {
            background: white;
            color: var(--gris-oscuro);
            font-weight: 600;
            border-color: #d1d5db;
            z-index: 1;
        }

        .nav-tab svg {
            width: 16px;
            height: 16px;
            flex-shrink: 0;
        }

        /* ====== CONTENT CARD ====== */
        .content-card {
            background: white;
            border-radius: 0 var(--radio-lg) var(--radio-lg) var(--radio-lg);
            box-shadow: var(--sombra-md);
            padding: 1.5rem;
            min-height: 300px;
            position: relative;
            border: 1px solid #d1d5db;
        }

        .field {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
        }

        .field label {
            font-size: 0.8rem;
            font-weight: 600;
            color: var(--gris-oscuro);
        }

        .field input {
            border: 1px solid var(--gris-medio);
            border-radius: var(--radio-sm);
            padding: 0.5rem 0.75rem;
            font-size: 0.875rem;
            font-family: inherit;
            outline: none;
            transition: border var(--transicion), box-shadow var(--transicion);
        }

        .field input:focus {
            border-color: var(--rojo);
            box-shadow: 0 0 0 3px rgba(231, 55, 71, 0.2);
        }

        /* Select elements */
        select {
            outline: none;
        }

        select:focus {
            border-color: var(--rojo);
            box-shadow: 0 0 0 3px rgba(231, 55, 71, 0.15);
        }

        textarea {
            outline: none;
        }

        textarea:focus {
            border-color: var(--rojo);
        }

        .config-card {
            background: #f9fafb;
            border: 1px solid var(--gris-medio);
            border-radius: var(--radio-md);
            padding: 0.875rem 1rem;
        }

        .config-card+.config-card {
            margin-top: 0.75rem;
        }

        .config-card h3 {
            margin-bottom: 0.2rem;
            color: var(--gris-oscuro);
            font-size: 0.9rem;
            font-weight: 600;
        }

        .config-card p {
            margin-bottom: 0.5rem;
            color: #6b7280;
            font-size: 0.8rem;
        }

        .config-grid {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 0.75rem;
        }

        .config-actions {
            margin-top: 0.75rem;
            display: flex;
            justify-content: flex-end;
        }

        /* Form Card (Plantilla section) */
        .form-card {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: var(--radio-md);
            padding: 1.25rem;
        }

        .form-card h3 {
            margin-bottom: 0.35rem;
            color: var(--gris-oscuro);
            font-size: 0.95rem;
            font-weight: 600;
        }

        .form-card p {
            margin-bottom: 0.5rem;
            color: #6b7280;
            font-size: 0.85rem;
        }

        .form-card code {
            background: #e5e7eb;
            padding: 0.15rem 0.4rem;
            border-radius: 4px;
            font-size: 0.8rem;
            color: var(--gris-oscuro);
        }

        .auth-overlay {
            position: fixed;
            inset: 0;
            background: var(--rojo);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
            opacity: 0;
            pointer-events: none;
            transition: opacity var(--transicion);
            z-index: 999;
        }

        .auth-overlay.active {
            opacity: 1;
            pointer-events: auto;
        }

        .auth-card {
            background: white;
            padding: 2.5rem 2rem;
            border-radius: var(--radio-xl);
            width: 100%;
            max-width: 340px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.75rem;
            animation: slideUp 0.4s ease-out;
        }

        .auth-icon {
            margin-bottom: 0.5rem;
        }

        .auth-icon svg {
            width: 48px;
            height: 48px;
            color: var(--rojo);
        }

        .auth-card h2 {
            color: var(--gris-oscuro);
            font-size: 1.5rem;
            font-weight: 700;
            margin: 0;
        }

        .auth-card p {
            color: var(--gris-oscuro);
            opacity: 0.7;
            font-size: 0.875rem;
            margin-bottom: 0.5rem;
        }

        .auth-field {
            width: 100%;
        }

        .auth-field input {
            width: 100%;
            padding: 0.875rem 1rem;
            border: 2px solid var(--gris-medio);
            border-radius: var(--radio-md);
            font-size: 1rem;
            font-family: inherit;
            text-align: center;
            outline: none;
            transition: all var(--transicion);
        }

        .auth-field input:focus {
            border-color: var(--rojo);
            box-shadow: 0 0 0 4px rgba(231, 55, 71, 0.15);
        }

        .auth-field input::placeholder {
            color: var(--gris-oscuro);
            opacity: 0.5;
        }

        .auth-error {
            color: #ef4444;
            font-size: 0.8rem;
            min-height: 1.25rem;
            text-align: center;
            font-weight: 500;
        }

        .auth-btn {
            width: 100%;
            padding: 1.125rem 1.5rem;
            font-size: 1.1rem;
            font-weight: 700;
            justify-content: center;
            gap: 0.5rem;
            border-radius: var(--radio-md);
            background: var(--amarillo) !important;
            color: var(--gris-oscuro) !important;
            box-shadow: 0 4px 12px rgba(255, 207, 0, 0.4) !important;
            min-height: 52px;
        }

        .auth-btn svg {
            width: 22px;
            height: 22px;
        }

        .auth-btn:hover:not(:disabled) {
            background: var(--amarillo-claro) !important;
            box-shadow: 0 4px 16px rgba(255, 207, 0, 0.45) !important;
        }

        .auth-back-link {
            display: inline-flex;
            align-items: center;
            gap: 0.25rem;
            margin-top: 0.75rem;
            padding: 0.5rem 1rem;
            color: var(--gris-oscuro);
            text-decoration: none;
            font-size: 0.8rem;
            border-radius: var(--radio-sm);
            transition: all var(--transicion);
        }

        .auth-back-link:hover {
            color: var(--rojo);
            background: rgba(231, 55, 71, 0.08);
        }

        /* Lucide Icons */
        .lucide {
            width: 1.25rem;
            height: 1.25rem;
            stroke-width: 2px;
        }

        .action-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            padding: 0;
            border: none;
            background: transparent;
            color: #6b7280;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .action-btn:hover {
            background: #f3f4f6;
            color: var(--azul-marino);
        }

        .preview-overlay {
            position: fixed;
            inset: 0;
            background: #f1f5f9;
            display: flex;
            flex-direction: column;
            opacity: 0;
            pointer-events: none;
            transition: opacity var(--transicion);
            z-index: 998;
            overflow: hidden;
        }

        .preview-overlay.active {
            opacity: 1;
            pointer-events: auto;
        }

        .preview-card {
            background: transparent;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .preview-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 1rem;
            padding: 1rem 2rem;
            background: white;
            border-bottom: 1px solid #e5e7eb;
            flex-shrink: 0;
        }

        .preview-header h2 {
            margin: 0;
            color: var(--azul-marino);
            font-size: 1.25rem;
        }

        .preview-header p {
            margin: 0.25rem 0 0;
            color: #6b7280;
            font-size: 0.85rem;
        }

        .preview-close {
            border: none;
            background: #f3f4f6;
            color: #6b7280;
            border-radius: 999px;
            width: 40px;
            height: 40px;
            font-size: 1.5rem;
            line-height: 1;
            cursor: pointer;
            transition: all var(--transicion);
        }

        .preview-close:hover {
            background: #fee2e2;
            color: var(--rojo-oscuro);
        }

        .preview-actions {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            gap: 0.75rem;
        }

        .preview-body {
            flex: 1;
            padding: 2rem;
            overflow-y: auto;
            overflow-x: hidden;
            background-color: #e2e8f0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        #previewContent {
            background: white;
            width: 100%;
            max-width: 800px;
            min-height: 1100px;
            /* Simula hoja carta */
            padding: 4rem 5rem;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
            border: 1px solid #cbd5e1;
            border-radius: 4px;
            color: #1e293b;
            line-height: 1.6;
            font-size: 0.95rem;
            position: relative;
            margin: 1rem 0 2rem;
            box-sizing: border-box;
            overflow: visible;
            /* Justificación por defecto como en documentos formales */
            text-align: justify;
        }

        /* Párrafos con espaciado y preservar saltos de línea */
        #previewContent p {
            margin-bottom: 0.75rem;
            min-height: 1em;
            /* Para párrafos vacíos que actúan como saltos */
        }

        /* Párrafos vacíos = saltos de línea */
        #previewContent p:empty {
            min-height: 1.2em;
        }

        /* Saltos de línea explícitos */
        #previewContent br {
            display: block;
            content: "";
            margin-top: 0.5em;
        }

        #previewContent strong,
        #previewContent b,
        #previewContent h1,
        #previewContent h2,
        #previewContent h3,
        #previewContent h4,
        #previewContent h5,
        #previewContent h6 {
            font-weight: 700 !important;
            color: #1a202c;
        }

        #previewContent img {
            height: auto !important;
            display: block;
            margin: 1rem 0;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }

        #previewContent .preview-qr {
            position: absolute !important;
            bottom: 1.27cm;
            right: 2.54cm;
            max-width: var(--qr-preview-width, 85px) !important;
            margin: 0 !important;
            padding: 8px;
            background: white;
            border: 1px solid #eee;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
            z-index: 10;
        }

        #previewContent .preview-signature {
            max-width: 200px !important;
            margin-left: auto;
            margin-right: auto;
        }

        /* Elementos centrados detectados del documento */
        #previewContent .doc-centered {
            text-align: center !important;
        }

        #previewContent .doc-title,
        #previewContent h1.doc-heading {
            text-align: center !important;
            margin-bottom: 1.5rem;
        }

        #previewContent .doc-subtitle {
            text-align: center !important;
            margin-bottom: 1rem;
            color: #4a5568;
        }

        #previewContent .signature-block {
            text-align: center !important;
            margin-top: 0.25rem;
            margin-bottom: 0.25rem;
        }

        #previewContent .signature-block img {
            margin-left: auto;
            margin-right: auto;
        }

        .preview-body table {
            width: 100%;
            border-collapse: collapse;
            margin: 1.5rem 0;
        }

        .preview-body td,
        .preview-body th {
            border: 1px solid #e5e7eb;
            padding: 0.35rem 0.5rem;
        }

        .preview-loading {
            text-align: center;
            color: #6b7280;
            padding: 2rem 0;
        }

        .card-header-internal {
            border-bottom: 1px solid var(--gris-medio);
            padding-bottom: 0.75rem;
            margin-bottom: 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .card-title {
            color: var(--gris-oscuro);
            font-size: 1.1rem;
            font-weight: 700;
            letter-spacing: -0.3px;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .card-title svg {
            width: 22px;
            height: 22px;
            color: var(--rojo-oscuro);
        }

        .card-subtitle {
            font-size: 0.85rem;
            color: #6b7280;
            font-weight: 400;
        }

        /* ====== TABS ====== */
        .input-tabs {
            display: flex;
            gap: 0;
            border-bottom: 1px solid var(--gris-medio);
            margin-bottom: 0.75rem;
        }

        .tab-btn {
            padding: 0.5rem 1rem;
            border: none;
            background: none;
            font-family: inherit;
            font-size: 0.9rem;
            color: #9ca3af;
            cursor: pointer;
            font-weight: 500;
            position: relative;
            transition: all var(--transicion);
            display: flex;
            align-items: center;
            gap: 0.4rem;
        }

        .tab-btn:hover {
            color: var(--gris-oscuro);
        }

        .tab-btn.active {
            color: var(--gris-oscuro);
            font-weight: 600;
        }

        .tab-btn.active::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            right: 0;
            height: 2px;
            background: var(--rojo);
            border-radius: 2px 2px 0 0;
        }

        .tab-btn svg {
            width: 16px;
            height: 16px;
        }

        /* ====== UPLOAD AREA ====== */
        .upload-area {
            border: 2px dashed var(--gris-medio);
            border-radius: var(--radio-md);
            padding: 2.5rem 2rem;
            text-align: center;
            transition: all var(--transicion);
            cursor: pointer;
            background: var(--gris-claro);
        }

        .upload-area:hover,
        .upload-area.dragover {
            border-color: var(--rojo);
            background: var(--rojo-fondo);
        }

        .upload-area.has-file {
            border-color: var(--verde);
            background: var(--verde-claro);
        }

        .upload-icon {
            width: 52px;
            height: 52px;
            border-radius: 50%;
            background: white;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 1rem;
            box-shadow: var(--sombra-sm);
            color: var(--rojo-oscuro);
        }

        .upload-icon svg {
            width: 26px;
            height: 26px;
        }

        .upload-area.has-file .upload-icon {
            color: var(--verde);
        }

        .upload-title {
            font-size: 1.05rem;
            font-weight: 600;
            margin-bottom: 0.35rem;
            color: var(--gris-oscuro);
        }

        .upload-subtitle {
            font-size: 0.85rem;
            color: #9ca3af;
        }

        /* ====== TIP BOX ====== */
        .tip-box {
            background: var(--naranja-claro);
            padding: 0.5rem 0.75rem;
            border-radius: var(--radio-sm);
            margin-bottom: 0.75rem;
            font-size: 0.8rem;
            color: #92400e;
            display: flex;
            align-items: flex-start;
            gap: 0.5rem;
            border-left: 3px solid var(--naranja);
        }

        .tip-box svg {
            width: 18px;
            height: 18px;
            flex-shrink: 0;
            margin-top: 1px;
            color: var(--naranja);
        }

        /* ====== MAPPING SECTION ====== */
        .mapping-section {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: var(--radio-sm);
            padding: 0.75rem 1rem;
            margin-top: 1rem;
            margin-bottom: 1rem;
            font-size: 0.82rem;
        }

        .mapping-header {
            display: flex;
            align-items: center;
            gap: 0.4rem;
            color: var(--gris-oscuro);
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        .mapping-list {
            display: flex;
            flex-wrap: wrap;
            gap: 0.4rem;
        }

        .mapping-item {
            display: inline-flex;
            align-items: center;
            gap: 0.3rem;
            padding: 0.25rem 0.6rem;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 500;
        }

        .mapping-item.mapped {
            background: var(--verde-claro);
            color: #166534;
        }

        .mapping-item.unmapped {
            background: var(--naranja-claro);
            color: #92400e;
        }

        .mapping-item svg {
            width: 12px;
            height: 12px;
        }

        .mapping-warning {
            display: flex;
            align-items: center;
            gap: 0.4rem;
            margin-top: 0.5rem;
            padding-top: 0.5rem;
            border-top: 1px solid #e5e7eb;
            color: #92400e;
            font-size: 0.75rem;
        }

        /* ====== PASTE TEXTAREA ====== */
        .paste-textarea {
            width: 100%;
            height: 140px;
            padding: 0.75rem;
            border: 1px solid var(--gris-medio);
            border-radius: var(--radio-sm);
            font-family: 'Courier New', monospace;
            font-size: 0.82rem;
            resize: vertical;
            transition: all var(--transicion);
            background: var(--gris-claro);
            color: var(--gris-oscuro);
        }

        .paste-textarea:focus {
            outline: none;
            border-color: var(--rojo);
            background: white;
            box-shadow: 0 0 0 4px rgba(231, 55, 71, 0.08);
        }

        .paste-textarea::placeholder {
            color: #b0b7c3;
        }

        /* ====== PREVIEW ====== */
        .preview-section {
            margin-top: 1rem;
            overflow-x: auto;
            display: none;
        }

        .preview-section h4 {
            font-size: 0.9rem;
            color: var(--gris-oscuro);
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.4rem;
        }

        .preview-count {
            background: var(--azul-marino);
            color: white;
            font-size: 0.8rem;
            padding: 0.15rem 0.5rem;
            border-radius: 20px;
            font-weight: 700;
        }

        /* ====== BUTTONS ====== */
        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: var(--radio-sm);
            font-family: inherit;
            font-size: 0.8rem;
            font-weight: 700;
            cursor: pointer;
            transition: all var(--transicion);
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
        }

        .btn:hover:not(:disabled) {
            transform: translateY(-1px);
        }

        .btn:active:not(:disabled) {
            transform: translateY(0);
        }

        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
        }

        .btn-primary {
            background: var(--rojo);
            color: white;
            box-shadow: 0 2px 8px rgba(231, 55, 71, 0.25);
        }

        .btn-primary:hover:not(:disabled) {
            background: var(--rojo-oscuro);
            box-shadow: 0 4px 16px rgba(231, 55, 71, 0.35);
        }

        /* SECCIÓN PLANTILLA WEB */
        #section-template .card-header i {
            color: var(--rojo-oscuro);
        }

        #editor-container {
            border: 1px solid #ccc;
            background: white;
            font-family: 'Times New Roman', Times, serif;
            /* Simulate print feel */
            font-size: 14px;
        }

        /* Variables in editor */
        .editor-variable {
            background-color: #fff3cd;
            color: #856404;
            padding: 2px 5px;
            border-radius: 3px;
            border: 1px solid #ffeeba;
            font-weight: bold;
            display: inline-block;
        }

        .variable-toolbar {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
            align-items: center;
        }

        .btn-outline {
            background: white;
            border: 1px solid var(--azul-marino);
            color: var(--azul-marino);
            padding: 0.25rem 0.75rem;
            border-radius: 20px;
            font-size: 0.8rem;
            cursor: pointer;
            transition: all 0.2s;
        }

        .btn-outline:hover {
            background: var(--azul-marino);
            color: white;
        }

        .btn-secondary {
            background: var(--gris-claro);
            color: #6b7280;
            border: 1px solid var(--gris-medio);
        }

        .btn-secondary:hover:not(:disabled) {
            background: var(--gris-medio);
            color: var(--gris-oscuro);
        }

        .btn-success {
            background: linear-gradient(135deg, var(--verde) 0%, #16a34a 100%);
            color: white;
            box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
        }

        .btn-success:hover:not(:disabled) {
            box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
        }

        .btn svg {
            width: 18px;
            height: 18px;
            flex-shrink: 0;
        }

        .actions-row {
            margin-top: 1rem;
            display: flex;
            justify-content: flex-end;
            gap: 0.5rem;
        }

        /* ====== SEARCH INPUT ====== */
        .search-wrapper {
            position: relative;
            display: flex;
            align-items: center;
            gap: 0.6rem;
        }

        .search-wrapper input {
            padding: 0.55rem 1rem 0.55rem 2.4rem;
            border: 2px solid var(--gris-medio);
            border-radius: 30px;
            font-family: inherit;
            font-size: 0.85rem;
            background: var(--gris-claro);
            transition: all var(--transicion);
            width: 240px;
            color: var(--gris-oscuro);
        }

        .search-wrapper input:focus {
            outline: none;
            border-color: var(--rojo);
            background: white;
            box-shadow: 0 0 0 4px rgba(231, 55, 71, 0.08);
        }

        .search-wrapper svg {
            position: absolute;
            left: 0.75rem;
            top: 50%;
            transform: translateY(-50%);
            width: 16px;
            height: 16px;
            color: #9ca3af;
            pointer-events: none;
        }

        .search-clear {
            border: 1px solid var(--gris-medio);
            background: var(--gris-claro);
            color: var(--gris-oscuro);
            border-radius: 999px;
            padding: 0.45rem 0.85rem;
            font-size: 0.75rem;
            font-weight: 600;
            letter-spacing: 0.01em;
            cursor: pointer;
            transition: all var(--transicion);
        }

        .search-clear:hover:not(:disabled) {
            background: white;
            border-color: var(--rojo);
            color: var(--rojo-oscuro);
            box-shadow: 0 6px 14px rgba(231, 55, 71, 0.14);
        }

        .search-clear:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        /* ====== TABLE ====== */
        .table-container {
            overflow-x: auto;
            border-radius: var(--radio-md);
            border: 1px solid var(--gris-claro);
        }

        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.88rem;
        }

        th {
            background: #f9fafb;
            color: var(--gris-oscuro);
            font-weight: 600;
            text-transform: uppercase;
            font-size: 0.7rem;
            padding: 0.6rem 0.75rem;
            text-align: left;
            border-bottom: 2px solid #e5e7eb;
            letter-spacing: 0.5px;
            white-space: nowrap;
        }

        tr:last-child td {
            border-bottom: none;
        }

        tbody tr {
            transition: background var(--transicion);
            cursor: pointer;
        }

        tbody tr:nth-child(even) {
            background: #f3f4f6;
        }

        tbody tr:hover {
            background: #fef3c7;
        }

        td {
            padding: 0.5rem 0.75rem;
        }

        td code {
            font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
            background: transparent;
            padding: 0;
            font-size: 0.75rem;
            font-weight: 500;
            color: #6b7280;
            letter-spacing: 0.5px;
        }

        .badge {
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-size: 0.7rem;
            font-weight: 600;
            letter-spacing: 0.2px;
            display: inline-block;
            text-transform: lowercase;
        }

        .badge-activo,
        .badge-vigente {
            background: var(--verde-claro);
            color: #15803d;
        }

        .badge-inactivo,
        .badge-revocado {
            background: var(--rojo-fondo);
            color: #991b1b;
        }

        .link-ver {
            color: #9ca3af;
            text-decoration: none;
            transition: color var(--transicion);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 28px;
            height: 28px;
            border-radius: 4px;
        }

        .link-ver:hover {
            color: var(--azul);
            background: rgba(42, 67, 158, 0.1);
        }

        .link-ver svg {
            width: 16px;
            height: 16px;
        }

        /* ====== ACTIONS DROPDOWN ====== */
        .actions-cell {
            position: relative;
            width: 100px;
            text-align: center;
        }

        .actions-dropdown {
            position: relative;
            display: inline-block;
        }

        .btn-action-menu {
            background: none;
            border: none;
            cursor: pointer;
            padding: 0.25rem;
            border-radius: 4px;
            color: #6b7280;
            transition: all var(--transicion);
        }

        .btn-action-menu:hover {
            background: var(--gris-claro);
            color: var(--gris-oscuro);
        }

        .actions-menu {
            display: none;
            position: absolute;
            right: 0;
            top: 100%;
            background: white;
            border: 1px solid var(--gris-medio);
            border-radius: var(--radio-sm);
            box-shadow: var(--sombra-lg);
            min-width: 160px;
            z-index: 100;
            padding: 0.25rem 0;
        }

        .actions-menu.show {
            display: block;
        }

        .actions-menu button {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            width: 100%;
            padding: 0.5rem 0.75rem;
            border: none;
            background: none;
            font-family: inherit;
            font-size: 0.8rem;
            color: var(--gris-oscuro);
            cursor: pointer;
            text-align: left;
            transition: background var(--transicion);
        }

        .actions-menu button:hover:not(:disabled) {
            background: var(--gris-claro);
        }

        .actions-menu button:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        .actions-menu button.btn-danger {
            color: var(--rojo-oscuro);
        }

        .actions-menu button.btn-danger:hover:not(:disabled) {
            background: var(--rosa-claro);
        }

        .actions-divider {
            height: 1px;
            background: var(--gris-medio);
            margin: 0.25rem 0;
        }

        .badge-suspendido {
            background: var(--naranja-claro);
            color: #92400e;
        }

        .badge-vencido {
            background: #fef3c7;
            color: #92400e;
        }

        /* ====== MODALS ====== */
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }

        .modal-overlay.show {
            display: flex;
        }

        .modal-card {
            background: white;
            border-radius: var(--radio-lg);
            box-shadow: var(--sombra-xl);
            width: 100%;
            max-width: 480px;
            max-height: 90vh;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }

        .modal-card.modal-lg {
            max-width: 600px;
        }

        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 1.25rem;
            border-bottom: 1px solid var(--gris-medio);
        }

        .modal-header h3 {
            font-size: 1.1rem;
            font-weight: 700;
            color: var(--azul-marino);
            margin: 0;
        }

        .modal-close {
            background: none;
            border: none;
            font-size: 1.5rem;
            color: #9ca3af;
            cursor: pointer;
            padding: 0;
            line-height: 1;
        }

        .modal-close:hover {
            color: var(--gris-oscuro);
        }

        .modal-body {
            padding: 1.25rem;
            overflow-y: auto;
        }

        .modal-footer {
            display: flex;
            justify-content: flex-end;
            gap: 0.5rem;
            padding: 1rem 1.25rem;
            border-top: 1px solid var(--gris-medio);
        }

        /* Historial info */
        .historial-info {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.5rem;
            margin-bottom: 1rem;
            padding: 0.75rem;
            background: var(--gris-claro);
            border-radius: var(--radio-sm);
        }

        .historial-info-item {
            display: flex;
            flex-direction: column;
        }

        .historial-info-label {
            font-size: 0.8rem;
            text-transform: uppercase;
            color: #9ca3af;
            letter-spacing: 0.3px;
        }

        .historial-info-value {
            font-size: 0.85rem;
            font-weight: 600;
            color: var(--gris-oscuro);
        }

        /* COLORES DE ESTADO (OVERRIDE) */
        .etiqueta-verde {
            background: #dcfce7;
            color: #166534;
        }

        .etiqueta-roja {
            background: #ffe4e6;
            /* Rose 100 */
            color: #be123c;
            /* Rose 700 */
        }

        .etiqueta-amarilla {
            background: #fef3c7;
            /* Amber 100 */
            color: #b45309;
            /* Amber 700 */
        }

        .etiqueta-naranja {
            background: #ffedd5;
            color: #c2410c;
        }

        .etiqueta-gris {
            background: #f3f4f6;
            color: #374151;
        }

        /* Ajuste ancho RUT */
        .rut-cell {
            white-space: nowrap !important;
        }

        /* Timeline */
        .timeline {
            position: relative;
            padding-left: 1.5rem;
        }

        .timeline::before {
            content: '';
            position: absolute;
            left: 0.35rem;
            top: 0;
            bottom: 0;
            width: 2px;
            background: var(--gris-medio);
        }

        .timeline-item {
            position: relative;
            padding-bottom: 1.25rem;
        }

        .timeline-item:last-child {
            padding-bottom: 0;
        }

        .timeline-dot {
            position: absolute;
            left: -1.25rem;
            top: 0.25rem;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: var(--celeste);
            border: 2px solid white;
            box-shadow: 0 0 0 2px var(--celeste);
        }

        .timeline-item.emitido .timeline-dot {
            background: var(--verde);
            box-shadow: 0 0 0 2px var(--verde);
        }

        .timeline-item.revocado .timeline-dot,
        .timeline-item.eliminado .timeline-dot {
            background: var(--rojo);
            box-shadow: 0 0 0 2px var(--rojo);
        }

        .timeline-item.suspendido .timeline-dot {
            background: var(--naranja);
            box-shadow: 0 0 0 2px var(--naranja);
        }

        .timeline-date {
            font-size: 0.8rem;
            color: #9ca3af;
            margin-bottom: 0.15rem;
        }

        .timeline-evento {
            font-weight: 600;
            font-size: 0.85rem;
            color: var(--gris-oscuro);
            margin-bottom: 0.15rem;
        }

        .timeline-detalle {
            font-size: 0.8rem;
            color: #6b7280;
            line-height: 1.4;
        }

        .timeline-loading {
            text-align: center;
            color: #9ca3af;
            padding: 1rem 0;
        }

        /* ====== PROGRESS ====== */
        .progress-container {
            margin-top: 1.5rem;
            background: var(--gris-claro);
            border-radius: 30px;
            height: 8px;
            overflow: hidden;
            display: none;
        }

        .progress-container.active {
            display: block;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--rojo) 0%, var(--sandia) 100%);
            width: 0%;
            transition: width 0.4s ease-out;
            border-radius: 30px;
        }

        .progress-text {
            text-align: center;
            margin-top: 0.5rem;
            font-size: 0.85rem;
            color: #6b7280;
            display: none;
            font-weight: 500;
        }

        /* ====== RESULTS SECTION ====== */
        .results-section {
            display: none;
            margin-top: 2rem;
            border-top: 2px solid var(--gris-claro);
            padding-top: 1.5rem;
            animation: fadeSlideIn 0.4s ease-out;
        }

        .results-title {
            margin-bottom: 1rem;
            color: var(--gris-oscuro);
            font-size: 1.05rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .results-title svg {
            width: 20px;
            height: 20px;
            color: var(--verde);
        }

        .results-stats {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.75rem;
            margin-bottom: 1.25rem;
        }

        .result-stat {
            background: var(--gris-claro);
            padding: 1rem;
            border-radius: var(--radio-sm);
            text-align: center;
            border: 1px solid var(--gris-medio);
        }

        .result-stat .stat-number {
            font-size: 1.5rem;
        }

        .result-stat small {
            color: #6b7280;
            font-weight: 600;
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }

        /* ====== TEMPLATE SECTION ====== */
        .template-grid {
            display: flex;
            gap: 2rem;
            align-items: flex-start;
        }

        .template-current {
            flex: 1;
            background: var(--gris-claro);
            padding: 1.5rem;
            border-radius: var(--radio-md);
            border: 1px solid var(--gris-medio);
        }

        .template-current h3 {
            font-size: 0.95rem;
            font-weight: 700;
            color: var(--gris-oscuro);
            margin-bottom: 0.75rem;
            display: flex;
            align-items: center;
            gap: 0.4rem;
        }

        .template-current h3 svg {
            width: 18px;
            height: 18px;
            color: var(--rojo);
        }

        .template-name {
            font-weight: 600;
            color: var(--azul-marino);
            margin-bottom: 0.25rem;
        }

        .template-date {
            font-size: 0.82rem;
            color: #9ca3af;
        }

        .template-upload {
            flex: 1;
        }

        .template-upload h3 {
            font-size: 0.95rem;
            font-weight: 700;
            color: var(--gris-oscuro);
            margin-bottom: 0.75rem;
        }

        .template-upload .upload-area {
            padding: 1.5rem;
        }

        .template-upload .upload-icon {
            width: 42px;
            height: 42px;
        }

        .template-upload .upload-icon svg {
            width: 20px;
            height: 20px;
        }

        /* ====== SECTIONS VISIBILITY ====== */
        .section {
            display: none;
        }

        .section.active {
            display: block;
            animation: fadeSlideIn 0.35s ease-out;
        }

        /* ====== ANIMATIONS ====== */
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes fadeSlideIn {
            from {
                opacity: 0;
                transform: translateY(12px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* ====== FOOTER ====== */
        footer {
            margin-top: auto;
            padding: 2rem 1rem;
            color: #6b7280;
            font-size: 0.82rem;
            text-align: center;
        }

        footer a {
            color: var(--rojo);
            text-decoration: none;
            font-weight: 600;
            transition: color var(--transicion);
        }

        footer a:hover {
            color: var(--rojo-oscuro);
            text-decoration: underline;
        }

        /* ====== RESPONSIVE ====== */
        @media (max-width: 768px) {
            .admin-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 0.75rem;
            }

            .admin-brand {
                min-width: unset;
            }

            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }

            .admin-header h1 {
                font-size: 1.3rem;
            }

            .admin-header p {
                font-size: 0.8rem;
            }

            .content-card {
                padding: 1.5rem;
                border-radius: var(--radio-lg);
            }

            .card-header-internal {
                flex-direction: column;
                gap: 0.75rem;
                align-items: flex-start;
            }

            .search-wrapper input {
                width: 100%;
            }

            .template-grid {
                flex-direction: column;
            }

            .results-stats {
                grid-template-columns: 1fr;
            }

            .config-grid {
                grid-template-columns: 1fr;
            }

            .user-bar {
                position: relative;
                top: 0;
                right: 0;
                justify-content: flex-end;
                padding: 0.5rem 1rem;
            }

            .actions-row {
                flex-direction: column;
            }

            .actions-row .btn {
                justify-content: center;
            }
        }

        @media (max-width: 480px) {
            .auth-card {
                padding: 1.75rem 1.25rem;
                gap: 0.5rem;
                max-width: 320px;
            }

            .auth-icon {
                margin-bottom: 0.25rem;
            }

            .auth-icon svg {
                width: 44px;
                height: 44px;
            }

            .auth-card h2 {
                font-size: 1.35rem;
            }

            .auth-card p {
                font-size: 0.9rem;
                margin-bottom: 0.25rem;
            }

            .auth-field input {
                padding: 0.75rem 1rem;
            }

            .auth-btn {
                padding: 0.75rem 1.25rem;
            }

            .auth-back-link {
                margin-top: 0.5rem;
                font-size: 0.85rem;
            }

            .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 0.5rem;
            }

            .stat-card {
                padding: 1rem 0.5rem;
            }

            .stat-number {
                font-size: 1.4rem;
            }

            .stat-label {
                font-size: 0.75rem;
            }

            .nav-pill {
                padding: 0.55rem 0.9rem;
                font-size: 0.8rem;
            }

            .nav-pill svg {
                display: none;
            }
        }

        /* Spreadsheet Preview Style */
        .spreadsheet-table {
            border-collapse: collapse;
            width: 100%;
            font-family: 'Inter', sans-serif;
            font-size: 0.85rem;
        }

        .spreadsheet-table th,
        .spreadsheet-table td {
            border: 1px solid #ddd;
            padding: 0.35rem 0.5rem;
            white-space: nowrap;
            font-size: 0.8rem;
        }

        .spreadsheet-table thead th {
            background: #f9fafb;
            text-align: center;
            padding: 0.35rem 0.5rem;
            min-width: 100px;
            font-size: 0.75rem;
            font-weight: 600;
            color: var(--gris-oscuro);
            border-color: #e5e7eb;
        }

        .spreadsheet-table tbody tr:nth-child(even) {
            background: #f9f9f9;
        }

        .spreadsheet-table tbody tr:hover {
            background: #e3f2fd;
        }

        .column-selector {
            width: 100%;
            padding: 0.25rem;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 0.8rem;
            margin-bottom: 0.25rem;
            background: white;
        }

        /* Bulk Actions Toolbar */
        .bulk-actions-bar {
            position: fixed;
            bottom: 40px;
            left: 50%;
            transform: translateX(-50%) translateY(150px);
            /* Hidden by default */
            background: #ffffff;
            padding: 0.75rem 1.5rem;
            border-radius: 50px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            display: flex;
            align-items: center;
            gap: 2rem;
            z-index: 9999;
            transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
            border: 1px solid rgba(0, 0, 0, 0.08);
            min-width: 420px;
            justify-content: space-between;
            backdrop-filter: blur(10px);
        }

        .bulk-actions-bar.active {
            transform: translateX(-50%) translateY(0);
        }

        .bulk-info {
            font-size: 1rem;
            color: #374151;
            font-weight: 500;
        }

        .bulk-count {
            background: var(--azul-marino);
            color: white;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 0.85rem;
            font-weight: 600;
        }

        .bulk-buttons {
            display: flex;
            gap: 0.75rem;
            align-items: center;
        }

        .bulk-close {
            background: none;
            border: none;
            font-size: 1.5rem;
            color: #9ca3af;
            cursor: pointer;
            margin-left: 1rem;
            line-height: 1;
        }

        .bulk-close:hover {
            color: #ef4444;
        }

        /* Checkboxes in table */
        .checkbox-cell {
            text-align: center;
        }

        input[type="checkbox"] {
            width: 16px;
            height: 16px;
            cursor: pointer;
            accent-color: var(--azul-marino);
        }