/* --- ESTILOS PARA LA LISTA DE CASOS PRINCIPALES --- */
.karyo-case-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

.karyo-case-item {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.07);
    text-decoration: none;
    color: #333;
    display: flex;
    flex-direction: column;
    border: 1px solid #e2e8f0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.karyo-case-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.karyo-case-item h3 {
    padding: 20px 20px 0 20px;
    margin: 0 0 10px 0;
    font-size: 1.25em;
    color: #1a202c;
}

.karyo-card-desc {
    padding: 0 20px;
    font-size: 0.9em;
    color: #4a5568;
    margin: 0 0 15px 0;
    line-height: 1.5;
    flex-grow: 1;
}

.karyo-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 15px 20px;
}

.karyo-card-tags .tag {
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
}

.karyo-card-tags .tag.difficulty {
    background-color: #e6fffa;
    color: #2c7a7b;
}

.karyo-card-tags .tag.diagnosis {
    background-color: #f0f4f8;
    color: #4a5568;
}

.karyo-card-button {
    display: block;
    background-color: #2d3748;
    color: white;
    text-align: center;
    padding: 15px;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    font-weight: bold;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.karyo-card-button:hover {
    background-color: #1a202c;
}

/* --- ESTILOS PARA LA GRILLA DE SUBCASOS --- */
.karyo-subcase-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.karyo-subcase-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.karyo-subcase-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.karyo-subcase-item h4 {
    margin: 0;
    font-size: 1.1em;
    color: #2d3748;
}

.karyo-subcase-item .status-icon {
    font-size: 1.5em;
    color: #38a169;
}

.karyo-subcase-item.completed {
    background-color: #f0fff4;
    border-color: #9ae6b4;
}

.karyo-subcase-item.completed h4 {
    color: #2f855a;
}

/* --- ESTILOS PARA LA HERRAMIENTA DE ARMADO --- */

.cariotipo-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f4f8;
    padding: 20px;
    border-radius: 12px;
    max-width: 1400px; /* <-- LO HE CAMBIADO DE 1200px a 1400px */
    margin: 20px auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.karyo-top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 10px 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.karyo-top-nav .nav-arrow {
    font-size: 28px;
    font-weight: bold;
    color: #4299e1;
    text-decoration: none;
    padding: 0 10px;
    flex-shrink: 0;
}

.karyo-top-nav .nav-arrow.disabled {
    color: #a0aec0;
    pointer-events: none;
}

.karyo-nav-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-grow: 1;
}

.title-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.subcase-title {
    margin: 0;
    font-size: 1.5em;
    color: #334e6f;
    font-weight: 600;
    line-height: 1.2;
}

#completion-status-badge {
    display: none;
    background-color: #28a745;
    color: white;
    padding: 3px 8px;
    font-size: 0.7em;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
}

#completion-status-badge.completed {
    display: inline-block;
}

.karyo-top-nav #case-counter {
    font-size: 0.9em;
    font-weight: 500;
    color: #718096;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: stretch;
}

.cromosomas-wrapper,
.cariotipo-wrapper {
    background-color: #ffffff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.cariotipo-subtitle {
    margin-top: 0;
    color: #334e6f;
    padding-bottom: 10px;
    margin-bottom: 0;
    flex-shrink: 0;
    font-size: 1.3em;
}

.cromosomas-pool {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* <-- CAMBIO: 4 columnas */
    gap: 10px;
    padding: 10px; /* Padding añadido */

    /* CAMBIO: Se eliminan max-height y overflow-y */
    background-color: #f8fafc; 
    border: 1px solid #e2e8f0; 
    border-radius: 6px;
}

.cromo-slot {
    min-height: 60px;
    border: 1px dashed #e2e8f0;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cromosoma {
    position: relative;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 2px;
    background-color: #f8fafc;
    cursor: grab;
    width: 100%;
    height: 60px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cromosoma.selected {
    border-color: #4299e1;
    box-shadow: 0 0 8px rgba(66, 153, 225, 0.5);
}

.cromosoma-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.remove-cromo-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background-color: #dc3545;
    color: white;
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone .cromosoma:hover .remove-cromo-btn {
    opacity: 1;
}

.cariotipo-grid-by-rows {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cariotipo-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    justify-content: space-between;
}

.cromosoma-group {
    display: flex;
    gap: 10px;
}

/* --- NUEVA REGLA PARA LA FILA 2 --- */
.cariotipo-row .cromosoma-group:only-child {
    width: 100%;
    justify-content: space-between;
}

.cariotipo-spacer {
    flex-grow: 1;
}

.cariotipo-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-grow: 0;
}

.drop-zone {
    border: 2px dashed #a0aec0;
    border-radius: 8px;
    min-height: 100px;
    width: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background-color: #f7fafc;
}

.drop-zone .cromosoma {
    width: 28px;
    height: 95%;
}

.drop-zone.is-trisomy {
    width: 125px;
}

.drop-zone > span {
    display: none;
}

.cariotipo-label {
    font-size: 0.9em;
    font-weight: bold;
    color: #334e6f;
}

.drop-zone.drag-over {
    background-color: #e2e8f0;
    border-color: #4299e1;
}

/* --- .bottom-bar y .action-buttons-left/right ELIMINADOS --- */
/* Las reglas para .bottom-bar, .action-buttons-left y .action-buttons-right han sido removidas */


/* --- Estilos para los botones ahora dentro de .action-buttons-container --- */
.action-buttons-container button {
    display: flex;
    align-items: center;
    justify-content: center; /* Centrar span */
    gap: 8px;
    padding: 12px 18px; /* Aumentar padding vertical */
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    width: 100%; /* Hacer que los botones ocupen el ancho de su contenedor de grid */
}

.btn-guardar { background-color: #3182ce; color: white; }
.btn-verificar { background-color: #28a745; color: white; }
.btn-reiniciar { background-color: #dc3545; color: white; }

.bottom-bar button:disabled,
.reference-container button:disabled,
.action-buttons-container button:disabled { /* Añadida la nueva regla de disabled */
    background-color: #e2e8f0;
    color: #a0aec0;
    cursor: not-allowed;
}

.diagnosis-wrapper {
    margin-top: 20px; /* --- CAMBIO: Quitado 'auto' y puesto un margen fijo */
}

#diagnosis-input {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    font-size: 1em;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

#diagnosis-input.correcto {
    border-color: #38a169;
    background-color: #f0fff4;
}

#diagnosis-input.incorrecto {
    border-color: #e53e3e;
    background-color: #fff5f5;
}

/* --- NUEVOS ESTILOS PARA EL CONTENEDOR DE BOTONES --- */
.action-buttons-container {
    display: grid;
    grid-template-columns: 1fr; /* Una columna */
    gap: 12px;
    margin-top: auto; /* <-- ESTO ES LO MÁS IMPORTANTE. Empuja los botones al fondo */
    padding-top: 20px; /* Espacio de seguridad por si el diagnóstico crece */
}

.action-buttons-container .action-buttons-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
/* --- FIN DE NUEVOS ESTILOS --- */


.reference-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-metafase {
    width: 85%;
    margin: 5px auto 0 auto;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    background-color: #6c757d;
    color: white;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-header .cariotipo-subtitle {
    margin-bottom: 0;
}

.zoom-controls {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    z-index: 10;
    display: flex;
    flex-direction: column; /* Apila los botones verticalmente */
    gap: 8px; /* Espacio entre botones */
    background-color: rgba(255, 255, 255, 0.7);
    padding: 8px 5px; /* Ajuste de padding para formato vertical */
    border-radius: 20px;
    opacity: 0.6;
    transition: opacity 0.2s ease-in-out;
}

.reference-image-wrapper:hover .zoom-controls {
    opacity: 1;
}

.zoom-controls button {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid transparent;
    background-color: #fff;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    color: #4a5568;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.zoom-controls button:hover {
    background-color: #2d3748;
    color: #fff;
}


.reference-image-wrapper {
    position: relative;
    width: 85%;
    height: 200px; /* <-- CAMBIO: Reducido de 250px a 200px */
    margin: 0 auto;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
    background-color: #f8fafc;
    /* Evitar selección de texto con doble clic */
    -webkit-user-select: none; /* Safari */
    -ms-user-select: none; /* IE 10+ */
    user-select: none; /* Estándar */
}

.reference-image-wrapper.is-zoomed {
    cursor: grab;
}

.reference-image-wrapper.is-panning {
    cursor: grabbing;
}

.reference-image {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    transition: transform 0.2s ease;
    pointer-events: none; /* Evita que la imagen interfiera con los eventos del mouse del wrapper */
}

.drop-zone.correcto { border: 2px solid #38a169; background-color: #f0fff4; }
.drop-zone.incorrecto { border: 2px solid #e53e3e; background-color: #fff5f5; }

/* --- ESTILOS PARA EL POP-UP DE RESULTADO --- */
.result-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.result-popup {
    background-color: white;
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.popup-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 20px auto;
}
.popup-icon.correct { background-color: #28a745; }
.popup-icon.incorrect { background-color: #dc3545; }

.result-popup h2 {
    font-size: 1.8em;
    margin: 0 0 10px 0;
    color: #1a202c;
}

.result-popup p {
    margin: 0 0 25px 0;
    color: #718096;
}

.popup-precision {
    background-color: #f7fafc;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
}

.popup-precision span {
    display: block;
    font-size: 2.5em;
    font-weight: bold;
    color: #2d3748;
}

.popup-precision small {
    color: #a0aec0;
    font-size: 0.9em;
}

.popup-actions {
    display: flex;
    gap: 15px;
}

.popup-actions button, .popup-actions a {
    flex-grow: 1;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
    font-size: 1em;
    border: 1px solid transparent;
}

#popup-retry-btn-correct, #popup-close-btn-incorrect {
    background-color: #fff;
    color: #2d3748;
    border: 1px solid #cbd5e1;
}

#popup-next-btn {
    background-color: #2d3748;
    color: white;
}

/* --- ESTILOS PARA POP-UP DE METAFASE --- */
.metafase-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001; /* Higher than result popup */
}

.metafase-popup {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.metafase-popup-close {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 35px;
    height: 35px;
    background-color: #2d3748;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    line-height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.metafase-popup img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-sizing: border-box;
    min-height: 0; /* Corrige el desbordamiento de la imagen en contenedores flex */
}