/* ==========================================================================
   1. VARIABLES GLOBALES (Tema Amarillo MPI)
   ========================================================================== */
:root {
    --primary-color: #f4d942;
    --primary-hover: #eaf458;
    --bg-container: #ffffff;
    --bg-body: #f4f6f9;
    --text-main: #333333;
    --text-muted: #666666;
    --border-color: #cccccc;
    --success-color: #28a745;
}

/* ==========================================================================
   2. CONTENEDORES Y MAQUETACIÓN COMPARTIDA
   ========================================================================== */
.document-upload-container,
.document-search-container,
.document-list-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    padding: 20px;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.document-list-container {
    max-width: 80%;
    margin: 40px auto;
    justify-content: flex-start;
}

/* Estructura de Formularios (Upload y Search) */
.upload-form, 
.search-form {
    background-color: var(--bg-container);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.upload-title, 
.search-title {
    font-size: 24px;
    color: var(--text-main);
    margin: 0 0 10px 0;
    text-align: center;
    font-weight: 700;
}

/* Inputs y Labels */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.document-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(244, 217, 66, 0.3);
}

/* Botones Compartidos */
.button-container { width: 100%; }

.btn-submit {
    width: 100%;
    background-color: var(--primary-color);
    color: var(--text-main);
    border: none;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn-submit:hover { background-color: var(--primary-hover); }
.btn-submit:active { transform: scale(0.98); }
.btn-submit:disabled { background-color: #e6ecbe; cursor: not-allowed; transform: none; }

/* ==========================================================================
   3. ELEMENTOS ESPECÍFICOS: UPLOAD (Cargar)
   ========================================================================== */

/* Estilo del botón en la esquina superior izquierda */
.btn-top-left {
    position: absolute;
    top: 15px;
    left: 15px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4a5568;
    background-color: #f8f9fa;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.btn-top-left:hover {
    background-color: #e2e8f0;
    color: #1a202c;
    border-color: #a0aec0;
}

.document-note {
    font-size: 13px;
    color: var(--text-muted);
    background-color: #f8f9fa;
    padding: 10px 15px;
    border-left: 4px solid var(--primary-color);
    margin: 5px 0;
    border-radius: 0 6px 6px 0;
    line-height: 1.4;
}

.document-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.file-input-wrapper {
    padding: 10px;
    background-color: #fafafa;
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
}

progress {
    width: 100%;
    height: 16px;
    appearance: none;
    -webkit-appearance: none;
    border: none;
}

progress::-webkit-progress-bar { background-color: #e9ecef; border-radius: 8px; }
progress::-webkit-progress-value { background-color: var(--success-color); border-radius: 8px; transition: width 0.2s ease-out; }

/* ==========================================================================
   4. ELEMENTOS ESPECÍFICOS: SEARCH (Consultar)
   ========================================================================== */
.form-logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
}

.form-logo {
    width: 100%;
    max-width: 80px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0px 4px 6px rgba(0, 0, 0, 0.05));
}

.certificate-result-card {
    background-color: #ffffff;
    border-left: 5px solid var(--success-color);
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 500px;
    margin-top: 25px;
    box-sizing: border-box;
    animation: fadeIn 0.4s ease-in-out;
}

.certificate-result-card h3 {
    margin-top: 0;
    color: #2c3e50;
    font-size: 18px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.result-details p { margin: 10px 0; font-size: 15px; color: var(--text-main); }
.result-actions { margin-top: 20px; }

.btn-view-pdf {
    display: inline-block;
    text-align: center;
    width: 100%;
    background-color: var(--success-color);
    color: white;
    text-decoration: none;
    padding: 12px;
    font-weight: 600;
    border-radius: 6px;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

.btn-view-pdf:hover { background-color: #218838; }

/* ==========================================================================
   5. ELEMENTOS ESPECÍFICOS: LIST (Historial y Tabla)
   ========================================================================== */
.module-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 30px;
    gap: 20px;
}

.header-text { display: flex; flex-direction: column; }
.list-title { font-size: 26px; color: var(--text-main); margin: 0; font-weight: 700; }
.module-subtitle { font-size: 14px; color: var(--text-muted); margin: 5px 0 0 0; }

.btn-primary-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--primary-color);
    color: var(--text-main);
    text-decoration: none;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    transition: all 0.25s ease;
    white-space: nowrap;
}

.btn-primary-action:hover { background-color: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12); }

.table-wrapper {
    width: 100%;
    background-color: var(--bg-container);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    border: 1px solid #eef2f5;
}

.certificates-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.certificates-table th { background-color: #f8f9fa; color: #495057; padding: 16px; border-bottom: 2px solid #dee2e6; font-weight: 600; text-align: left; }
.certificates-table td { padding: 16px; border-bottom: 1px solid #eee; color: var(--text-main); vertical-align: middle; }
.certificates-table tbody tr:hover { background-color: #fdfdfd; }
.text-center { text-align: center; }
.filename-cell { color: #495057; font-family: monospace; font-size: 14px; }
.file-type-icon { margin-right: 6px; }

.btn-table-view {
    display: inline-block;
    background-color: #f8f9fa;
    color: #858585;
    border: 1px solid #858585;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-table-view:hover { background-color: #858585; color: white; }

/* Botón de Eliminar fila a fila */
.btn-table-delete {
    display: inline-block;
    background-color: #fff5f5;
    color: #c53030;
    border: 1px solid #feb2b2;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s ease;
}

.btn-table-delete:hover {
    background-color: #fed7d7;
    color: #9b2c2c;
    border-color: #fca5a5;
}

/* Formulario inline de eliminación con código secreto */
.delete-form {
    display: none;
    margin-top: 10px;
    width: 100%;
    box-sizing: border-box;
}

/* El input reutiliza las base de .form-control y solo sobreescribe el tamaño */
.form-control-small {
    max-width: 200px;
    padding: 8px 10px;
    font-size: 14px;
}

.btn-confirm-delete,
.btn-cancel-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 8px;
}

.btn-confirm-delete {
    background-color: #c53030;
    color: #fff;
}

.btn-confirm-delete:hover {
    background-color: #a32222;
    transform: translateY(-1px);
}

.btn-cancel-delete {
    background-color: #f8f9fa;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-cancel-delete:hover {
    background-color: #eef2f5;
    color: #1a202c;
    border-color: #a0aec0;
}

.no-results { padding: 40px; text-align: center; color: var(--text-muted); }
.btn-upload-first { display: inline-block; margin-top: 15px; background-color: var(--primary-color); color: var(--text-main); text-decoration: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; }

/* Paginación */
.pagination-container { display: flex; justify-content: center; align-items: center; margin-top: 30px; width: 100%; }
.pagination-nav { display: flex; align-items: center; gap: 10px; background-color: var(--bg-container); padding: 8px 16px; border-radius: 30px; border: 1px solid #eef2f5; }
.btn-pagination-arrow { padding: 8px 16px; font-size: 14px; font-weight: 600; color: var(--text-main); text-decoration: none; border-radius: 20px; transition: background-color 0.2s ease; }
.btn-pagination-arrow:not(.disabled):hover { background-color: #f0f4f8; }
.btn-pagination-arrow.disabled { color: #b5bfc9; cursor: not-allowed; }
.pagination-numbers { display: flex; align-items: center; gap: 4px; }
.page-number { display: flex; justify-content: center; align-items: center; min-width: 36px; height: 36px; font-size: 14px; font-weight: 600; color: var(--text-main); text-decoration: none; border-radius: 50%; transition: all 0.2s ease; }
.page-number:not(.active):not(.ellipsis):hover { background-color: #eef2f5; color: #000; }
.page-number.active { background-color: var(--primary-color); color: var(--text-main); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1); }
.page-number.ellipsis { color: var(--text-muted); cursor: default; }

/* ==========================================================================
   6. MENSAJES FLASH (Alertas globales)
   ========================================================================== */
.flashes { list-style: none; padding: 0; margin: 20px 0 0 0; width: 100%; max-width: 500px; }
.flashes li { padding: 12px 20px; border-radius: 6px; margin-bottom: 10px; font-size: 14px; text-align: center; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.flash-success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-danger { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.flash-warning { background-color: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* ==========================================================================
   7. RESPONSIVIDAD (Móviles y Tablets)
   ========================================================================== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media screen and (max-width: 768px) {
    .module-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .header-actions, .btn-primary-action { width: 100%; justify-content: center; }
    
    .certificates-table, .certificates-table thead, .certificates-table tbody, 
    .certificates-table th, .certificates-table td, .certificates-table tr { display: block; }
    .certificates-table thead tr { position: absolute; top: -9999px; left: -9999px; }
    .certificates-table tr { border: 1px solid #eef2f5; margin-bottom: 15px; border-radius: 8px; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
    .certificates-table td { border: none; border-bottom: 1px solid #f1f1f1; position: relative; padding-left: 50%; text-align: right; }
    .certificates-table td:last-child { border-bottom: 0; }
    .certificates-table td:before { content: attr(data-label); position: absolute; left: 15px; width: 45%; text-align: left; font-weight: 600; color: var(--text-muted); font-size: 13px; }
    .actions-cell { text-align: right !important; }
    .btn-table-view { width: 100%; box-sizing: border-box; }
    .btn-table-delete { margin-left: 0; margin-top: 8px; }
    .delete-form { display: block; margin-top: 10px; }
    .form-control-small { max-width: 100%; }
    .btn-confirm-delete,
    .btn-cancel-delete { display: block; margin: 10px 0 0 0; }
}

@media (max-width: 480px) {
    .upload-form, .search-form { padding: 24px 16px; box-shadow: none; }
    .upload-title, .search-title { font-size: 20px; }
    
    .pagination-nav { width: 100%; justify-content: space-between; padding: 8px; }
    .pagination-numbers { display: none; }
    .btn-pagination-arrow { flex: 1; text-align: center; background-color: #f8f9fa; border: 1px solid #eef2f5; }
}


/* ==========================================================================
   FILTRO DE FECHAS (DISEÑO COMPACTO Y MODERNO)
   ========================================================================== */
.filter-container {
    background-color: var(--bg-container);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); /* Sombra más suave y moderna */
    border: 1px solid #eef2f5;
    padding: 12px 20px; /* Padding reducido para hacerlo compacto */
    margin-bottom: 25px;
    width: 100%;
    box-sizing: border-box;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center; /* Centra todo verticalmente */
    gap: 16px;
}

/* Alineamos el label y el input en la misma línea */
.filter-group {
    display: flex;
    align-items: center; 
    gap: 10px;
}

.filter-group .document-label {
    margin: 0;
    font-size: 13px; /* Fuente ligeramente más pequeña */
    color: var(--text-muted); /* Gris sutil para no robar atención */
    white-space: nowrap; /* Evita que el texto se parta en dos líneas */
}

/* Ajustamos los inputs para que sean más delgados (compactos) */
.filter-group .form-control {
    padding: 6px 12px;
    font-size: 14px;
    height: 36px; /* Altura fija para que coincida exacto con los botones */
    width: auto;
    min-width: 140px;
}

.filter-actions {
    display: flex;
    gap: 10px;
    margin-left: auto; /* ¡Este es el truco! Empuja los botones a la derecha */
}

/* Estilos de botones unificados y compactos */
.btn-filter, .btn-clear {
    height: 36px; /* Misma altura que los inputs */
    padding: 0 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    text-decoration: none;
    border: none;
}

/* Botón Amarillo */
.btn-filter {
    background-color: var(--primary-color);
    color: var(--text-main);
}

.btn-filter:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(244, 217, 66, 0.2); /* Sombra amarilla sutil */
}

/* Botón Limpiar (Transparente con borde) */
.btn-clear {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.btn-clear:hover {
    background-color: #f8f9fa;
    color: var(--text-main);
    border-color: #a0aec0;
}

/* ==========================================================================
   RESPONSIVIDAD (Móviles)
   ========================================================================== */
@media (max-width: 768px) {
    .filter-form {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .filter-group {
        flex-direction: column; /* En móviles volvemos a apilar label arriba e input abajo */
        align-items: flex-start;
        gap: 4px;
    }
    
    .filter-group .form-control {
        width: 100%; /* Ocupan todo el ancho disponible */
    }
    
    .filter-actions {
        margin-left: 0;
        margin-top: 5px;
    }
    
    .btn-filter, .btn-clear {
        flex: 1; /* Los botones se reparten el 50% del espacio cada uno */
    }
}

/* ==========================================================================
   8. MÓDULO VISITORS (Ingresos al área)
   ========================================================================== */
.visitor-container { justify-content: flex-start; padding-top: 80px; }

.visitor-form {
    max-width: 900px;
    width: 100%;
}

.visitor-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    width: 100%;
}

.visitor-form-grid .input-group:last-child {
    grid-column: 1 / -1;
}

@media (max-width: 640px) {
    .visitor-form-grid { grid-template-columns: 1fr; }
}

/* Firma dibujada (canvas) */
.signature-pad {
    position: relative;
    width: 100%;
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    background-color: #fafafa;
    cursor: crosshair;
    overflow: hidden;
    box-sizing: border-box;
}

.signature-pad canvas {
    display: block;
    width: 100%;
    height: 150px;
    touch-action: none;
}

.signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a0aec0;
    font-size: 14px;
    pointer-events: none;
    user-select: none;
}

#signatureData {
    display: none;
}

.visitor-form .btn-clear {
    align-self: flex-start;
    width: auto;
}

/* Tabla de visitantes */
.visitors-table {
    min-width: 1000px;
}

.exit-form {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.exit-form .form-control-small {
    width: 110px;
    height: 34px;
    box-sizing: border-box;
}

.exit-time-set {
    color: var(--success-color);
    font-weight: 600;
}

.exit-time-pending {
    color: #b7791f;
    font-weight: 600;
}

.signature-link {
    color: #2b6cb0;
    text-decoration: underline;
    font-size: 13px;
    font-weight: 600;
}

.visitors-table td small {
    color: var(--text-muted);
}

.text-muted { color: var(--text-muted); }