/**
 * Huffman Algorithm Visualization - Styles
 * 
 * @author Valentin Barral
 * @license CC BY 4.0
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* ===== COLORES GENERALES DE LA APLICACIÓN - TEMA CLARO ===== */
    --primary-color: #4f46e5;
    --secondary-color: #7c3aed;
    --accent-color: #db2777;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #475569;
    --border-color: #cbd5e1;
    --success-color: #059669;
    --warning-color: #d97706;
    
    /* ===== COLORES DEL ÁRBOL DE HUFFMAN - TEMA CLARO ===== */
    /* Colores optimizados para máxima legibilidad en fondo claro */
    
    /* Nodos - Más oscuros para mejor contraste con texto blanco */
    --node-leaf-color: #7c3aed;           /* Púrpura oscuro para nodos hoja */
    --node-internal-color: #475569;       /* Gris oscuro para nodos internos */
    --node-highlight-color: #8b5cf6;      /* Púrpura brillante para resaltado */
    --node-highlight-border: #f59e0b;     /* Naranja/amarillo para borde resaltado */
    --node-highlight-shadow: #f59e0b;     /* Sombra naranja */
    --node-border-color: #1e293b;         /* Borde muy oscuro para definición */
    
    /* Aristas */
    --edge-left-color: #3b82f6;           /* Azul fuerte para aristas 0 */
    --edge-right-color: #ec4899;          /* Rosa fuerte para aristas 1 */
    --edge-label-color: #059669;          /* Verde oscuro para etiquetas */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text-color);
    min-height: 100vh;
    padding: 0;
}

.container {
    width: 100%;
    margin: 0;
}

header {
    text-align: center;
    margin-bottom: 0;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 0;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
    color: white;
    position: relative;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

header h1 {
    font-size: 2rem;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    color: white;
}

/* Language Selector */
.language-selector {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 30px;
}

.language-selector select {
    padding: 10px 35px 10px 15px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
    min-width: 150px;
}

.language-selector select:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.language-selector select:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.language-selector select option {
    background: var(--primary-color);
    color: white;
    padding: 10px;
}

@media (max-width: 768px) {
    header {
        padding: 20px 15px 30px 15px;
        display: flex;
        flex-direction: column;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .language-selector {
        position: static;
        order: -1;
        margin: 0 auto 20px auto;
        display: flex;
        justify-content: center;
    }
    
    .language-selector select {
        width: auto;
        min-width: 180px;
    }
    
    .header-content {
        order: 0;
    }
}

.main-content {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 20px;
    margin-bottom: 0;
    padding: 20px;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

.control-panel,
.visualization-panel {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
}

.input-section {
    margin-bottom: 30px;
}

.order-note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-style: italic;
}

h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.examples {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #cbd5e1;
    transform: translateY(-2px);
}

.btn-nav {
    background: var(--primary-color);
    color: white;
    padding: 10px 18px;
    font-size: 0.9rem;
}

.btn-nav:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

.btn-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.custom-input {
    margin-top: 15px;
}

.custom-input label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

textarea {
    width: 100%;
    padding: 12px;
    background: #f8fafc;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    resize: vertical;
    transition: border-color 0.3s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead {
    background: var(--primary-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: white;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
    background: rgba(99, 102, 241, 0.1);
}

.symbol-cell {
    font-weight: bold;
    color: var(--accent-color);
    font-size: 1.1rem;
}

.code-cell {
    font-family: 'Courier New', monospace;
    color: var(--success-color);
    font-weight: bold;
}

.canvas-container {
    background: #f8fafc;  /* Fondo claro para el canvas */
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    overflow: auto;  /* Permitir scroll tanto horizontal como vertical */
    max-height: 700px;  /* Altura máxima del contenedor */
    border: 2px solid var(--border-color);
    width: 100%;
}

#treeCanvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
}

.navigation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.step-indicator {
    background: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1.1rem;
    border: 2px solid var(--primary-color);
    min-width: 120px;
    text-align: center;
}

#currentStep {
    color: var(--accent-color);
    font-size: 1.3rem;
}

.step-description {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
    transition: all 0.3s ease;
}

.step-description.step-mark {
    border-left-color: #f59e0b;
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.1) 0%, white 100%);
}

.step-description.step-combine {
    border-left-color: #ec4899;
    background: linear-gradient(90deg, rgba(236, 72, 153, 0.1) 0%, white 100%);
}

.step-description.step-insert {
    border-left-color: #059669;
    background: linear-gradient(90deg, rgba(5, 150, 105, 0.1) 0%, white 100%);
}

.step-description.step-final {
    border-left-color: #f59e0b;
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.1) 0%, white 100%);
}

.step-description p {
    line-height: 1.6;
    color: var(--text-secondary);
    font-size: 1rem;
}

.statistics {
    margin-top: 20px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
}

.statistics div {
    margin: 8px 0;
    display: flex;
    justify-content: space-between;
}

.statistics strong {
    color: var(--primary-color);
}

.highlight-row {
    background: rgba(236, 72, 153, 0.2) !important;
    animation: pulse 1s ease-in-out;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.node-active {
    stroke: var(--accent-color);
    stroke-width: 3;
    filter: drop-shadow(0 0 10px var(--accent-color));
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Animaciones suaves */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 20px;
}

footer p {
    margin: 0;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

