/* CSS Minimalista - Generador de Tarjetas de Visitante */
:root {
    --primary-color: #2563eb;
    --secondary-color: #1e40af;
    --accent-color: #3b82f6;
    --light-color: #f8fafc;
    --dark-color: #1e293b;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --success-color: #059669;
    --warning-color: #dc2626;
    /* Dimensiones estándar para tarjeta de identificación (formato ISO/IEC 7810 ID-1) */
    --card-width: 340px;
    --card-height: 215px;
    --border-radius: 12px;
    --shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 16px -4px rgba(0, 0, 0, 0.15), 0 4px 8px -2px rgba(0, 0, 0, 0.08);
}

/* Reset básico y tipografía */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: 'Poppins', sans-serif;
    line-height: 1.6;
    padding: 20px;
    min-height: 100vh;
    background: var(--gray-100);
    color: var(--dark-color);
}

/* Contenedor principal */
.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

header.main-header .header-brand h1 {
    font-size: 1.8rem;
    color: var(--dark-color);
    font-weight: 600;
}

header.main-header .header-brand .subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-top: 4px;
}

/* Botones */
.btn {
 box-shadow: var(--shadow-md);
  transition: background 0.2s, transform 0.15s;
}

.btn:hover {
    transform: translateY(-1px);
}

.form-section,
.preview-section {
  background: #fafafa;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: 2px solid rgba(37,99,235,0.3);
}

.btn.btn-outline {
    background: white;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.btn.btn-block {
    width: 100%;
}

/* Formulario y vista previa */
.app-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.form-section, .preview-section {
    background: white;
    box-shadow: var(--shadow);
    border-radius: var(--border-radius);
    padding: 30px;
    border: 1px solid var(--gray-200);
}

.form-section h2, .preview-section h2 {
    font-size: 1.5rem;
    color: var(--dark-color);
    margin-bottom: 20px;
    font-weight: 600;
}

/* Inputs y selects */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    transition: border-color 0.2s ease;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Botones de acción dentro de secciones */
.btn-group {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

/* Plantillas y colores */
.template-selector, .color-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.template, .color-option {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    cursor: pointer;
    border: 2px solid var(--gray-300);
    transition: all 0.2s ease;
}

.template.selected, .color-option.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Vista previa de tarjeta - MEJORADA */
.card-container {
    width: var(--card-width);
    height: var(--card-height);
    background: white;
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
    border: 1px solid var(--gray-200);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    /* Proporción estándar de tarjeta de identificación */
    aspect-ratio: 340/215;
}

.card-container:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.15), 0 6px 12px -4px rgba(0, 0, 0, 0.1);
}

/* Header del carné - MEJORADO */
.card-header {
    position: relative;
    padding: 12px 15px;
    background: var(--primary-color);
    color: white;
    text-align: center;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.card-header h2 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.card-header span {
    font-size: 0.7rem;
    opacity: 0.9;
    font-weight: 400;
}

.card-header .card-logo {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    max-height: 35px;
    max-width: 60px;
    width: auto;
    object-fit: contain;
    display: block;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px;
    border-radius: 4px;
}

/* Cuerpo del carné - MEJORADO */
.card-body {
     display: flex;
  align-items: flex-start;
  gap: 20px; 
}

.card-qr {
  margin-left: auto;  /* empuja el QR al extremo derecho */
  flex-shrink: 0;     /* no se comprima */
  padding-top: 10px;
}

.card-qr img,
#qr-code {
  width: 100px;       /* o el tamaño que necesites */
  height: 100px;
  object-fit: contain;
}

/* Foto del visitante - MEJORADA */
.card-photo .photo-placeholder {
    width: 75px;
    height: 95px;
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-200) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--gray-300);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.card-photo .photo-placeholder i {
    font-size: 1.8rem;
    color: var(--gray-400);
}

.card-photo .photo-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Detalles de texto - MEJORADOS */
.card-details {
    flex: 1;
    font-size: 0.75rem;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 95px;
}

.card-details .name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 3px;
    color: var(--dark-color);
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.card-details .company {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary-color);
    font-size: 0.8rem;
    text-transform: capitalize;
}

.card-details p {
    margin-bottom: 2px;
    color: var(--gray-600);
    font-size: 0.7rem;
}

.card-details strong {
    color: var(--dark-color);
    font-weight: 600;
}

/* Footer del carné con QR - COMPLETAMENTE REDISEÑADO */
.card-footer {
    padding: 8px 15px;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.7rem;
    color: var(--gray-500);
    border-top: 1px solid var(--gray-200);
    min-height: 50px;
    position: relative;
}

/* Contenedor del QR - SIEMPRE VISIBLE */
#qr-container {
  position: absolute;
  bottom: 32px;            /* justo encima de la firma */
  left: 16px;              /* alinear con padding interior */
  width: 48px;
  height: 48px;
  display: flex !important;
  justify-content: center;
  align-items: center;
  background: white;       /* destacarlo */
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  z-index: 2;              /* encima de footer */
  animation: qrAppear 0.4s ease-out;
}

#qr-code {
    width: 84px !important;
    height: 84px !important;
    max-width: 84px !important;
    max-height: 84px !important;
    opacity: 1 !important;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: white;
    padding: 2px;
    display: block !important; /* Siempre visible */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Placeholder del QR cuando no está generado */
#qr-container::before {
    content: "QR";
    display: flex;
    justify-content: center;
    align-items: center;
    width: 42px;
    height: 42px;
    background: var(--gray-100);
    border: 1px dashed var(--gray-300);
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--gray-400);
    position: absolute;
    z-index: 1;
}

/* Ocultar placeholder cuando el QR está presente */
#qr-container:has(#qr-code[style*="display: block"]) ::before,
#qr-container:has(#qr-code:not([style*="display: none"])) ::before {
    display: none;
}

/* Firma autorizada - MEJORADA */
.signature {
  bottom: 8px;   
  right: 16px;
  font-size: 0.65rem;
  color: var(--gray-500);
}


/* Descarga y acciones */
.action-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Animaciones */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.4s ease both;
}

/* Animación especial para el QR */
@keyframes qrAppear {
    from { 
        opacity: 0; 
        transform: scale(0.8); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

#qr-code {
    animation: qrAppear 0.3s ease-out;
}

/* Tabla de registros de visitantes */
.visitor-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.visitor-table th,
.visitor-table td {
    border: 1px solid var(--gray-200);
    padding: 12px;
    text-align: left;
}

.visitor-table th {
    background-color: var(--gray-50);
    color: var(--dark-color);
    font-weight: 600;
    border-bottom: 2px solid var(--gray-200);
}

.visitor-table tr:nth-child(even) {
    background-color: var(--gray-50);
}

.visitor-table tr:hover {
    background-color: var(--gray-100);
}

/* Login container */
.login-container {
    max-width: 400px;
    margin: 50px auto;
    background: white;
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--dark-color);
    font-weight: 600;
}

.error {
    background: #fee2e2;
    color: var(--warning-color);
    padding: 12px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    border: 1px solid #fecaca;
}

/* Responsive Design - MEJORADO */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 0;
    }
    
    header.main-header {
        flex-direction: column;
        text-align: center;
        gap: 20px;
        padding: 20px;
    }
    
    header.main-header .header-brand h1 {
        font-size: 1.5rem;
    }
    
    .app-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .form-section, .preview-section {
        padding: 20px;
    }
    
    /* Mantener tamaño estándar del carné en móvil */
    .card-container {
        width: 320px;
        height: 203px;
        transform: scale(0.95);
        margin: 0 auto;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .action-buttons .btn {
        width: 100%;
        max-width: 200px;
    }
    
    .template-selector, .color-options {
        justify-content: center;
    }
    
    /* Tabla responsive */
    .visitor-table {
        font-size: 0.8rem;
    }
    
    .visitor-table th,
    .visitor-table td {
        padding: 8px 4px;
    }
    
    /* Ocultar algunas columnas en móvil */
    .visitor-table th:nth-child(7),
    .visitor-table td:nth-child(7),
    .visitor-table th:nth-child(8),
    .visitor-table td:nth-child(8) {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Ajustar carné para pantallas muy pequeñas */
    .card-container {
        width: 280px;
        height: 178px;
        transform: scale(0.85);
    }
    
    .card-body {
        padding: 12px;
        gap: 10px;
    }
    
    .card-photo .photo-placeholder {
        width: 65px;
        height: 80px;
    }
    
    .card-details {
        font-size: 0.7rem;
    }
    
    .card-details .name {
        font-size: 0.85rem;
    }
    
    .card-details .company {
        font-size: 0.75rem;
    }
    
    .visitor-table {
        font-size: 0.7rem;
    }
    
    .visitor-table th,
    .visitor-table td {
        padding: 6px 2px;
    }
    
    /* Ocultar más columnas en pantallas muy pequeñas */
    .visitor-table th:nth-child(5),
    .visitor-table td:nth-child(5),
    .visitor-table th:nth-child(6),
    .visitor-table td:nth-child(6) {
        display: none;
    }
}

/* Mejoras adicionales para accesibilidad */
.btn:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Estados de carga */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Espaciado mejorado */
.form-section > *:last-child {
    margin-bottom: 0;
}

.preview-section > *:last-child {
    margin-bottom: 0;
}

.hidden { display: none !important; }
/* opcional: para animar la aparición */
.fade-in { animation: fadeIn 0.3s ease-out; }


/* Por defecto, el placeholder se ve con opacidad reducida */
#qr-code.qr-placeholder {
  display: block;         /* siempre visible hasta generar el QR real */
  width: 100px;           /* ajusta al tamaño que uses */
  height: 100px;
  opacity: 1;           /* más discreto como fondo */
  transition: opacity 0.3s ease;
}

/* Cuando tenga el QR real, quitaremos la clase .qr-placeholder */
#qr-code:not(.qr-placeholder) {
  opacity: 1;             /* imagen nítida */
}

/* Asegúrate de que no haya display:none aquí */
#qr-code {
  display: block;
}


@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Mejoras específicas para impresión */
@media print {
    .card-container {
        width: 340px !important;
        height: 215px !important;
        transform: none !important;
        box-shadow: none !important;
        border: 1px solid #000 !important;
    }
    
    #qr-code {
        display: none;
    }
}