/* ==========================================
   VARIABLES Y RESETEO (Diseño UI/UX)
   ========================================== */
:root {
    --primary: #2271b1;      /* Azul principal que ya venimos usando */
    --primary-hover: #135e96;
    --bg-color: #f4f6f8;     /* Gris súper claro para contrastar las tarjetas */
    --text-dark: #2d3748;
    --text-muted: #718096;
    --card-bg: #ffffff;
    --radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==========================================
   CABECERA Y MENSAJES
   ========================================== */

header {
    text-align: center;
    padding: 60px 20px 40px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 10px;
    color: var(--primary);
}

header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 500px;
    margin: 0 auto;
}

/* ==========================================
   MENÚ GLOBAL DE ECOSISTEMA PULGUITA
   ========================================== */
.global-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.global-nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 20px;
    background: #e2e8f0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.global-nav a:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(34, 113, 177, 0.2);
}

/* Resalta el sitio en el que el usuario está actualmente */
.global-nav a.active {
    background: #ebf4ff;
    color: var(--primary);
    border: 1px solid rgba(34, 113, 177, 0.3);
}

.global-nav a.active:hover {
    background: var(--primary);
    color: white;
}
/* ==========================================
   CONTENEDOR DE TARJETAS (Los dos caminos)
   ========================================== */
.main-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    max-width: 800px;
    width: 100%;
}

/* Diseño de los componentes interactivos */
.option-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 30px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 10px 15px rgba(0, 0, 0, 0.025);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.option-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 25px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    background: #ebf4ff;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.option-card h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.option-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* ==========================================
   PIE DE PÁGINA (Privacidad)
   ========================================== */
footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer strong {
    color: #38a169; /* Verde para dar seguridad */
}
/* ==========================================
   ESTILOS DEL WORKSPACE Y DROPZONE
   ========================================== */
.workspace {
    width: 100%;
    max-width: 800px;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.workspace-header {
    text-align: center;
    margin-bottom: 30px;
}

.workspace-header h2 {
    font-size: 1.8rem;
    color: var(--primary);
    margin: 10px 0;
}

/* Botón de Volver */
/* Botón de Volver (Mejorado) */
.btn-back {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: var(--text-dark);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 20px; /* Forma de píldora */
    transition: all 0.3s ease;
    position: absolute;
    top: 20px;
    left: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05); /* Sombra para que flote */
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
}

.btn-back:hover {
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.15);
    transform: translateX(-4px); /* Animación suave hacia la izquierda */
}

/* El Dropzone (Zona de arrastre) */
.dropzone {
    background-color: var(--card-bg);
    border: 2px dashed #cbd5e0;
    border-radius: var(--radius);
    padding: 50px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background-color: #ebf4ff;
}

.dropzone-content .drop-icon {
    font-size: 3.5rem;
    margin-bottom: 15px;
}

.dropzone-content h3 {
    font-size: 1.3rem;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.dropzone-content p {
    color: var(--text-muted);
    margin-bottom: 10px;
}

.file-limits {
    font-size: 0.8rem;
    color: #a0aec0;
    background: #edf2f7;
    padding: 4px 10px;
    border-radius: 20px;
}

/* Botones de Acción (Replicando el estilo que charlamos antes) */
.action-panel {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 30px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(34, 113, 177, 0.3);
    transition: all 0.3s;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.btn-outline-danger {
    background: #f0f0f1;
    color: #d63638;
    border: 2px solid #d63638;
    padding: 12px 28px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-outline-danger:hover {
    background: #d63638;
    color: white;
    transform: scale(1.05);
}

/* ==========================================
   GRILLA VISUAL DE ARCHIVOS (Crear PDF)
   ========================================== */
.visual-file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.thumb-card {
    background: white;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    position: relative;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    user-select: none;
}

.thumb-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}

.thumb-card:active {
    cursor: grabbing;
}

.thumb-card.sortable-ghost {
    opacity: 0.4;
    background-color: #ebf4ff;
    border: 2px dashed var(--primary);
}

.thumb-preview {
    width: 100%;
    height: 150px;
    object-fit: cover; /* Recorta la imagen para que llene el cuadrado */
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
}

.thumb-pdf-canvas {
    width: 100%;
    height: 150px;
    object-fit: contain; /* Para que la hoja PDF entera entre en el cuadrado */
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: white;
}

.thumb-name {
    font-size: 0.75rem;
    color: var(--text-dark);
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
    font-weight: 600;
}

.btn-remove-thumb {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #e53e3e;
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(229, 62, 62, 0.3);
    z-index: 10;
    transition: transform 0.2s;
}

.btn-remove-thumb:hover {
    transform: scale(1.15);
    background: #c53030;
}

.thumb-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 0.65rem;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: bold;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
}

/* ==========================================
   ESTILOS PARA REORDENAMIENTO (Sortable)

   ========================================== */
.drag-handle {
    cursor: grab;
    color: #a0aec0;
    margin-right: 10px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    padding: 5px;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Estilo para la tarjeta mientras la estás arrastrando */
.sortable-ghost {
    opacity: 0.4;
    background-color: #ebf4ff;
    border: 2px dashed var(--primary);
}

/* Modificamos un poco file-info para que acomode el nuevo ícono */
.file-info {
    display: flex;
    align-items: center;
    gap: 10px; /* Reduje el gap un poquito */
    overflow: hidden;
}
/* ==========================================
   ESTILOS PARA WORKSPACE 2 (Herramientas)
   ========================================== */
.split-actions {
    margin-top: 40px;
    animation: fadeIn 0.4s ease;
}

.action-cards-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.btn-action-tool {
    background: var(--card-bg);
    border: 2px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 20px;
    width: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-action-tool:hover {
    border-color: var(--primary);
    box-shadow: 0 10px 15px rgba(34, 113, 177, 0.1);
    transform: translateY(-5px);
}

.tool-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.tool-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.tool-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.3;
}
/* ==========================================
   ESTILOS DEL EDITOR VISUAL DE PÁGINAS
   ========================================== */
.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px 20px;
    border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    margin-top: 20px;
}

.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
    padding-bottom: 80px; /* Espacio para la barra flotante */
}

/* La Tarjeta de cada Hoja */
.page-card {
    background: white;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    user-select: none;
    border: 3px solid transparent;
}

/* Efecto Hover para invitar al clic */
.page-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.15);
}

.page-card canvas {
    width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    display: block;
}

.page-number-badge {
    background: var(--text-dark);
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 12px;
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Resaltar la hoja que se está visualizando/editando */
.page-card.preview-active {
    border-color: #dd6b20 !important;
    box-shadow: 0 0 0 4px rgba(221, 107, 32, 0.3) !important;
    transform: scale(1.02);
    z-index: 2;
}

/* ====== ESTADO: ELIMINADA (La Magia) ====== */
.page-card.discarded {
    opacity: 0.6;
    transform: scale(0.95); /* Se achica un poquito */
    border-color: #fc8181;
    box-shadow: none;
}

.page-card.discarded canvas {
    filter: grayscale(100%) contrast(0.8); /* Se pone en blanco y negro */
}

.page-card.discarded::after {
    content: '❌';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    opacity: 0.8;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.page-card.discarded .page-number-badge {
    background: #e53e3e; /* El número se pone rojo */
    text-decoration: line-through;
}

/* Barra Flotante Inferior */
.floating-action-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    border-radius: 40px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    z-index: 100;
    border: 1px solid #e2e8f0;
}

/* ==========================================
   ESTILOS DEL MODO DIVIDIR
   ========================================== */
.editor-mode-switch {
    display: flex;
    background: #edf2f7;
    border-radius: 8px;
    padding: 4px;
}

.mode-btn {
    background: transparent;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s;
}

.mode-btn.active {
    background: white;
    color: var(--text-dark);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Espacio extra para que el cartel de corte no tape otras hojas */
.page-card {
    margin-bottom: 25px; 
}

/* Indicador visual de Corte */
.page-card.cut-point {
    border-color: #d63638;
    box-shadow: 0 8px 15px rgba(214,54,56,0.2);
}

.page-card.cut-point::before {
    content: '✂️ Corte hasta aquí';
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #d63638;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 12px;
    white-space: nowrap;
    z-index: 10;
}
/* ==========================================
   ESTILOS PARA BANNER PUBLICITARIO (RESPONSIVO)
   ========================================== */
.ad-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 20px;
    margin-bottom: 20px;
}

.ad-placeholder {
    width: 100%;
    max-width: 728px; /* Ancho máximo para PC */
    height: 90px;     /* Alto para PC */
    background-color: #e2e8f0;
    border: 2px dashed #a0aec0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: all 0.3s ease; /* Transición suave al redimensionar */
}

.ad-label {
    color: #718096;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    text-align: center;
}

/* MAGIA RESPONSIVA: Adaptación automática para Celulares */
@media (max-width: 600px) {
    .ad-container {
        padding: 0 10px; /* Menos margen lateral en celus */
    }
    .ad-placeholder {
        max-width: 320px; /* Estándar Google AdSense para Móviles */
        height: 50px;     /* Estándar Google AdSense para Móviles */
    }
    .ad-label {
        font-size: 0.7rem; /* Achicamos la letra para que entre bien */
    }
}
/* ==========================================
   WIDGET DE INSTALACIÓN PWA (FLOTANTE)
   ========================================== */
.pwa-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    flex-direction: column;
}

/* Botón Minimizado (Efecto Pulso) */
.pwa-mini-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(34, 113, 177, 0.4);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

.pwa-mini-btn:hover {
    transform: scale(1.1);
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 113, 177, 0.5); }
    70% { box-shadow: 0 0 0 15px rgba(34, 113, 177, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 113, 177, 0); }
}

/* Banner Expandido */
.install-banner {
    background: white;
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 10px 25px rgba(34, 113, 177, 0.2);
    width: max-content;
    max-width: calc(100vw - 40px); /* Evitar que se salga de la pantalla en celulares chicos */
    animation: popIn 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: bottom right;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.8) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Ajustes internos del banner */
.install-info { display: flex; align-items: center; gap: 10px; }
.install-icon { font-size: 1.8rem; }
.install-text { display: flex; flex-direction: column; }
.install-text strong { color: var(--text-dark); font-size: 0.95rem; }
.install-text span { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap;}
.install-actions { display: flex; align-items: center; gap: 10px; margin-left: 10px; }

/* Botón cerrar minimizado */
.btn-close {
    background: #f4f6f8; border: none; color: #a0aec0;
    width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-close:hover { background: #e2e8f0; color: var(--text-dark); }

/* Adaptación para pantallas muy pequeñas */
@media (max-width: 450px) {
    .install-banner {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .install-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}

/* ==========================================
   ESTILOS PARA FIRMAR Y SELLAR
   ========================================== */
.sign-tool-btn {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px;
    border-radius: 8px; border: none; font-weight: 600;
    cursor: pointer; transition: all 0.2s; color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.sign-tool-btn:hover {
    transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* El contenedor arrastrable */
.draggable-signature {
    position: absolute; 
    cursor: grab; user-select: none;
    border: 2px dashed transparent; transition: border 0.2s;
}
.draggable-signature:hover { border: 2px dashed var(--primary); }
.draggable-signature:active { cursor: grabbing; }

/* El botón de achicar/agrandar (Tamaño PC) */
.draggable-signature .resize-handle {
    position: absolute; bottom: -8px; right: -8px;
    width: 16px; height: 16px; background: var(--primary);
    border-radius: 50%; cursor: se-resize; display: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* El botón de eliminar (Tamaño PC) */
.draggable-signature .delete-handle {
    position: absolute; top: -10px; right: -10px;
    width: 20px; height: 20px; background: #e53e3e; color: white;
    border-radius: 50%; cursor: pointer; display: none;
    align-items: center; justify-content: center;
    font-size: 10px; font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Mostrar controles en PC al pasar el mouse */
.draggable-signature:hover .resize-handle { display: block; }
.draggable-signature:hover .delete-handle { display: flex; }

/* ==========================================
   MAGIA PARA CELULARES (Touch Screens)
   ========================================== */
@media (hover: none) and (pointer: coarse) {
    .draggable-signature {
        border: 2px dashed rgba(34, 113, 177, 0.5); /* Siempre el borde a la vista */
    }
    
    /* Botón de achicar gigante para los dedos */
    .draggable-signature .resize-handle { 
        display: block; /* Siempre visible */
        width: 32px; height: 32px; 
        bottom: -16px; right: -16px;
    }
    
    /* Botón de borrar gigante para los dedos */
    .draggable-signature .delete-handle { 
        display: flex; /* Siempre visible */
        width: 32px; height: 32px; 
        top: -16px; right: -16px;
        font-size: 14px;
    }
}
