/* --- RESET Y BASES --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

header { margin: 20px 0; text-align: center; }
header h1 { color: #1a202c; font-weight: 800; letter-spacing: -1px; }

/* --- TABS --- */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: #e2e8f0;
    padding: 5px;
    border-radius: 12px;
}
.tab-btn {
    background: transparent;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 600;
    color: #4a5568;
    border-radius: 8px;
    transition: 0.2s;
}
.tab-btn.active {
    background: white;
    color: #3182ce;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.tab-btn:hover:not(.active) { background: rgba(255,255,255,0.5); }

/* --- LAYOUT --- */
.main-layout {
    display: flex;
    gap: 20px;
    width: 95%;
    max-width: 1200px;
    align-items: flex-start;
    margin-bottom: 40px;
}
.visualization-area {
    flex: 2;
    background: white;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 600px;
    position: relative;
}

/* --- CONTROLES --- */
.controls-panel {
    display: flex;
    background-color: #f7fafc;
    padding: 10px 20px;
    border-radius: 12px;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 15px;
    border: 1px solid #e2e8f0;
}
.control-group { display: flex; align-items: center; gap: 8px; }
.separator { width: 1px; height: 30px; background: #cbd5e0; }
.input-number { width: 50px; padding: 5px; text-align: center; border-radius: 6px; border: 1px solid #cbd5e0; }

button {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    background-color: #edf2f7;
    color: #4a5568;
    transition: all 0.2s;
}
button:hover { background-color: #e2e8f0; transform: translateY(-1px); }
button:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }

.primary-btn { background-color: #3182ce; color: white; }
.primary-btn:hover { background-color: #2b6cb0; }
.pause-btn { background-color: #ed8936; color: white; width: 40px; display: flex; justify-content: center;}
.pause-btn.paused { background-color: #48bb78; }
.stop-btn { background-color: #e53e3e; color: white; }
.stop-btn:hover { background-color: #c53030; }
.code-btn { background-color: #805ad5; color: white; }
.code-btn:hover { background-color: #6b46c1; }

/* --- NODOS --- */
.array-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    width: 100%;
    gap: 10px;
    margin-top: 10px;
}
.node {
    width: 55px;
    height: 55px;
    background-color: white;
    border: 2px solid #4299e1;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Roboto Mono', monospace;
    font-size: 1.2rem;
    font-weight: 700;
    color: #2b6cb0;
    transition: all 0.4s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    z-index: 2;
    position: relative;
}
.array-container .node::after {
    content: attr(data-index);
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: #a0aec0;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    pointer-events: none;
}

/* Estados Visuales */
.node.dimmed { opacity: 0.2; border-color: #4c5660; color: #0e1823; transform: scale(0.9); }
.node.in-partition { opacity: 1; border-color: #2b6cb0; box-shadow: 0 0 10px rgba(43, 108, 176, 0.2); background-color: #ebf8ff;}
.node.active { background-color: #fc8181; border-color: #c53030; color: white; transform: translateY(-10px); }
.node.sorted { background-color: #68d391; border-color: #2f855a; color: white; }
.node.pivot { background-color: #f6e05e; border-color: #d69e2e; color: #744210; transform: scale(1.1); z-index: 10; }
.node.jump-highlight { background-color: #9f7aea; border-color: #553c9a; color: white; transform: scale(1.1); z-index: 5;}

/* --- RADIX BUCKETS --- */
.buckets-wrapper {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px dashed #cbd5e0;
}
.buckets-wrapper.hidden { display: none; }
.bucket {
    width: 60px;
    min-height: 80px;
    border: 2px solid #cbd5e0;
    background: #f7fafc;
    border-radius: 0 0 8px 8px;
    border-top: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 5px;
    position: relative;
}
.bucket-label {
    position: absolute;
    top: -25px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #718096;
}
.bucket .node { width: 40px; height: 40px; font-size: 0.9rem; margin-top: 5px; transform: none; }

/* --- BITACORA --- */
.log-panel {
    flex: 1;
    background: #2d3748;
    color: #e2e8f0;
    padding: 20px;
    border-radius: 16px;
    height: 600px;
    display: flex;
    flex-direction: column;
}
.log-content {
    flex: 1;
    overflow-y: auto;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.log-content::-webkit-scrollbar { width: 6px; }
.log-content::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 3px; }
.log-entry { padding: 8px; border-radius: 4px; border-left: 3px solid #4299e1; background: rgba(255,255,255,0.05); }
.log-entry.highlight { border-left-color: #f6e05e; background: rgba(246, 224, 94, 0.1); }
.log-entry.swap { border-left-color: #fc8181; background: rgba(252, 129, 129, 0.1); }
.log-entry.success { border-left-color: #68d391; }

/* --- MODAL --- */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 100;
    display: flex; justify-content: center; align-items: center;
}
.modal.hidden { display: none; }
.modal-content {
    background: white; width: 600px; max-height: 80vh;
    border-radius: 12px; padding: 20px; display: flex; flex-direction: column;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.close-btn { background: none; font-size: 1.5rem; cursor: pointer; color: #e53e3e; }
.language-tabs { display: flex; gap: 10px; margin-bottom: 10px; }
.lang-btn { background: #e2e8f0; padding: 5px 15px; border-radius: 5px; cursor: pointer; }
.lang-btn.active { background: #3182ce; color: white; }
pre { background: #2d3748; color: #e7ebf1; padding: 15px; border-radius: 8px; overflow: auto; font-family: 'Roboto Mono'; flex: 1; }

.pointers-container { display: flex; justify-content: center; gap: 10px; margin-top: 5px; height: 30px; }
.pointer-slot { width: 55px; text-align: center; font-weight: bold; font-family: 'Roboto Mono'; }

/* --- LEYENDA (FIXED) --- */
.legend { 
    display: flex; 
    gap: 15px; 
    margin-bottom: 10px; 
    font-size: 0.8rem; 
    flex-wrap: wrap; 
    justify-content: center;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.box { 
    display: inline-block; /* NECESARIO para que se vea el tamaño */
    width: 16px; 
    height: 16px; 
    border-radius: 4px; 
    border: 1px solid rgba(0,0,0,0.2); 
    flex-shrink: 0;
}
/* Colores Leyenda */
.box.active { background: #fc8181; } 
.box.sorted { background: #68d391; } 
.box.pivot { background: #f6e05e; } 
.box.jump { background: #9f7aea; }