/* ===== VARIABLES CSS ===== */
:root {
    --primary-color: #2E86AB;
    --secondary-color: #A23B72;
    --accent-color: #F18F01;
    --success-color: #C73E1D;
    --background: #F5F5F5;
    --text-dark: #2C3E50;
    --text-light: #7F8C8D;
    --shadow: rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

/* ===== RESET Y BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Gluten', cursive;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-dark);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 100vw;
    padding: 20px;
    position: relative;
}

/* ===== HEADER ===== */
header {
    text-align: center;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--shadow);
    backdrop-filter: blur(10px);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

header p {
    font-size: 1.1rem;
    color: var(--text-light);
    font-weight: 300;
}

/* ===== CONTROLES ===== */
.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.controls button {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    background: var(--primary-color);
    color: white;
    font-family: 'Gluten', cursive;
    font-weight: 400;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(46, 134, 171, 0.3);
}

.controls button:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(162, 59, 114, 0.4);
}

/* ===== CONTENEDOR DEL ÁRBOL ===== */
#tree-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--shadow);
    backdrop-filter: blur(10px);
    overflow: hidden;
    height: 70vh;
    position: relative;
}

#tree-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#tree-svg:active {
    cursor: grabbing;
}

/* ===== ESTILOS DE NODOS ===== */
.node circle {
    fill: var(--primary-color);
    stroke: white;
    stroke-width: 3px;
    cursor: pointer;
    transition: var(--transition);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.node circle:hover {
    fill: var(--accent-color);
    stroke-width: 4px;
    transform: scale(1.1);
}

.node.trunk circle {
    fill: #8B4513;  /* Marrón tronco */
    stroke-width: 5px;
}

.node.roots circle {
    fill: #654321;  /* Marrón raíces */
}

.node.deep_roots circle {
    fill: #4A2C17;  /* Marrón muy oscuro para raíces profundas */
}

.node.branch circle {
    fill: #228B22;  /* Verde ramas */
}

.node.leaf circle {
    fill: #32CD32;  /* Verde hojas */
}

.node.active circle {
    fill: #FFD700;  /* Dorado activo */
    stroke: var(--primary-color);
    stroke-width: 5px;
    animation: pulse 2s infinite;
}

.node text {
    font-family: 'Gluten', cursive;
    font-size: 12px;
    font-weight: 500;
    fill: var(--text-dark);
    text-anchor: middle;
    pointer-events: none;
    dominant-baseline: central;
}

.node.has-children text {
    font-weight: 600;
}

/* ===== ENLACES ===== */
.link {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 2px;
    stroke-opacity: 0.8;
    transition: var(--transition);
}

.link:hover {
    stroke: var(--accent-color);
    stroke-width: 3px;
    stroke-opacity: 1;
}

/* ===== PANEL DE INFORMACIÓN ===== */
.info-panel {
    position: fixed;
    right: -400px;
    top: 50%;
    transform: translateY(-50%);
    width: 380px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 15px 0 0 15px;
    box-shadow: -5px 0 30px var(--shadow);
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.info-panel.active {
    right: 0;
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--primary-color);
    color: white;
    border-radius: 15px 0 0 0;
}

.info-header h3 {
    font-size: 1.3rem;
    font-weight: 500;
}

#close-panel {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#close-panel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.info-content {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

#info-description {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 20px;
    color: var(--text-dark);
}

#info-details {
    font-size: 0.9rem;
    color: var(--text-light);
    line-height: 1.5;
}

.detail-item {
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(46, 134, 171, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.detail-label {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 5px;
}

/* ===== TOOLTIPS ===== */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 2000;
    max-width: 200px;
    text-align: center;
}

.tooltip.visible {
    opacity: 1;
}

/* ===== ANIMACIONES ===== */
@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: scale(0);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.node {
    animation: nodeAppear 0.5s ease-out;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .controls {
        gap: 10px;
    }
    
    .controls button {
        padding: 10px 20px;
        font-size: 0.8rem;
    }
    
    #tree-container {
        height: 60vh;
    }
    
    .info-panel {
        width: 100%;
        right: -100%;
        top: auto;
        bottom: -100%;
        transform: none;
        border-radius: 15px 15px 0 0;
        height: 80vh;
    }
    
    .info-panel.active {
        right: auto;
        bottom: 0;
    }
    
    .info-header {
        border-radius: 15px 15px 0 0;
    }
}

/* ===== MEJORAS VISUALES ===== */
.node circle.pulsing {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 134, 171, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(46, 134, 171, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(46, 134, 171, 0);
    }
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-size: 1.2rem;
    color: var(--text-light);
}

.fade-in {
    animation: fadeIn 0.8s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== SECCIÓN DE EDICIÓN ===== */
.edit-section {
    margin-top: 20px;
    padding: 20px;
    background: rgba(46, 134, 171, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(46, 134, 171, 0.2);
}

.edit-section h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.edit-section label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-dark);
}

.edit-section input,
.edit-section textarea,
.edit-section select {
    width: 100%;
    padding: 10px;
    border: 2px solid rgba(46, 134, 171, 0.2);
    border-radius: 6px;
    font-family: 'Gluten', cursive;
    font-size: 0.9rem;
    transition: border-color 0.3s;
}

.edit-section input:focus,
.edit-section textarea:focus,
.edit-section select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.edit-section textarea {
    min-height: 80px;
    resize: vertical;
}

.edit-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.edit-buttons button {
    flex: 1;
    min-width: 100px;
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    font-family: 'Gluten', cursive;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

#save-node {
    background: #28a745;
    color: white;
}

#save-node:hover {
    background: #218838;
}

#cancel-edit {
    background: #6c757d;
    color: white;
}

#cancel-edit:hover {
    background: #5a6268;
}

#delete-node {
    background: #dc3545;
    color: white;
}

#delete-node:hover {
    background: #c82333;
}

/* ===== MODO EDICIÓN ACTIVO ===== */
body.edit-mode .node circle {
    stroke: #FFD700;
    stroke-width: 2px;
    stroke-dasharray: 5,5;
    animation: dash 1s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -10;
    }
}

body.edit-mode .node:hover circle {
    stroke-width: 4px;
    stroke: #FF6B6B;
}

/* ===== INDICADORES VISUALES ===== */
.tree-legend {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    font-size: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
}

.legend-color.trunk { background: #8B4513; }
.legend-color.roots { background: #654321; }
.legend-color.deep_roots { background: #4A2C17; }
.legend-color.branch { background: #228B22; }
.legend-color.leaf { background: #32CD32; }

/* ===== SECCIÓN DE CREACIÓN ===== */
.create-section, .generate-section {
    margin-top: 20px;
    padding: 20px;
    background: rgba(40, 167, 69, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(40, 167, 69, 0.2);
}

.create-section h4, .generate-section h4 {
    color: #28a745;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.create-buttons, .generate-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.create-buttons button, .generate-buttons button {
    flex: 1;
    min-width: 100px;
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    font-family: 'Gluten', cursive;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

#create-node, #generate-ideas {
    background: #28a745;
    color: white;
}

#create-node:hover, #generate-ideas:hover {
    background: #218838;
}

#cancel-create, #cancel-generate {
    background: #6c757d;
    color: white;
}

#cancel-create:hover, #cancel-generate:hover {
    background: #5a6268;
}

/* ===== IDEAS GENERADAS ===== */
.generated-ideas {
    margin-top: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.idea-item {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.idea-item:hover {
    background: rgba(40, 167, 69, 0.1);
    border-color: #28a745;
}

.idea-item.selected {
    background: rgba(40, 167, 69, 0.2);
    border-color: #28a745;
    border-width: 2px;
}

.idea-title {
    font-weight: 600;
    color: #28a745;
    margin-bottom: 5px;
}

.idea-description {
    font-size: 0.9rem;
    color: var(--text-dark);
    line-height: 1.4;
}

.ideas-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.ideas-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-family: 'Gluten', cursive;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

#add-selected-ideas {
    background: #28a745;
    color: white;
}

#add-selected-ideas:hover {
    background: #218838;
}

#regenerate-ideas {
    background: #17a2b8;
    color: white;
}

#regenerate-ideas:hover {
    background: #138496;
}

/* ===== ZONAS DE COLOR DEL ÁRBOL ===== */
.zona-verde {
    background: linear-gradient(to bottom, rgba(76, 175, 80, 0.15), rgba(76, 175, 80, 0.05));
}

.zona-azul {
    background: linear-gradient(to bottom, rgba(33, 150, 243, 0.15), rgba(33, 150, 243, 0.05));
}

.zona-amarilla {
    background: linear-gradient(to bottom, rgba(255, 235, 59, 0.15), rgba(255, 235, 59, 0.05));
}

/* ===== CONEXIONES ORGÁNICAS ===== */
.root-connection {
    filter: drop-shadow(0 2px 4px rgba(141, 110, 99, 0.3));
    stroke-linecap: round;
}

.branch-connection {
    filter: drop-shadow(0 2px 4px rgba(76, 175, 80, 0.3));
    stroke-linecap: round;
}

.deep-root-connection,
.leaf-connection {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
    stroke-linecap: round;
}

/* ===== TRONCO MEJORADO - FORMA VERTICAL ===== */
.trunk-group ellipse {
    fill: #8B4513;
    stroke: #654321;
    stroke-width: 4px;
    filter: drop-shadow(0 8px 16px rgba(139, 69, 19, 0.5));
    /* Agregamos textura visual con gradiente */
    fill: url(#trunkGradient);
}

/* Gradientes para dar textura de corteza */
.trunk-texture {
    fill: none;
    stroke: #4A2C17;
    stroke-width: 1.5;
    opacity: 0.6;
    stroke-dasharray: 2, 1;
}

/* ===== ESTILOS MEJORADOS PARA FORMA ORGÁNICA ===== */
.node.trunk text {
    fill: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* ===== EFECTOS HOVER MEJORADOS ===== */
.node:hover .edit-indicator {
    stroke: #FF6B6B;
    stroke-width: 3px;
    opacity: 1;
}

/* ===== NOTIFICACIONES ===== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    font-family: 'Gluten', cursive;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.notification.success { background: #28a745; }
.notification.warning { background: #ffc107; color: #212529; }
.notification.error { background: #dc3545; }
.notification.info { background: #17a2b8; }

/* ===== NODOS ORGÁNICOS ===== */
.roots-main circle {
    filter: drop-shadow(0 4px 8px rgba(101, 67, 33, 0.4));
}

.roots-deep circle {
    filter: drop-shadow(0 3px 6px rgba(74, 44, 23, 0.4));
}

.branches-main circle {
    filter: drop-shadow(0 4px 8px rgba(34, 139, 34, 0.4));
}

.branches-leaf circle {
    filter: drop-shadow(0 3px 6px rgba(50, 205, 50, 0.4));
}

.trunk-group circle {
    filter: drop-shadow(0 6px 12px rgba(139, 69, 19, 0.5));
}

/* ===== INDICADORES VISUALES DE CREACIÓN ===== */
.node.can-add-child circle {
    stroke: #28a745;
    stroke-width: 3px;
    stroke-dasharray: 3, 3;
    animation: dashGreen 1s linear infinite;
}

@keyframes dashGreen {
    to {
        stroke-dashoffset: -6;
    }
}

.create-hint {
    position: absolute;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
}

.create-hint.visible {
    opacity: 1;
}

/* ===== INDICADORES DE CREACIÓN ===== */
.creation-indicator {
    animation: creationPulse 1.5s ease-in-out infinite;
}

@keyframes creationPulse {
    0% { opacity: 0.5; stroke-width: 2px; }
    50% { opacity: 1; stroke-width: 3px; }
    100% { opacity: 0.5; stroke-width: 2px; }
}

.node.selected-parent circle {
    stroke: #28a745;
    stroke-width: 4px;
    filter: drop-shadow(0 0 10px rgba(40, 167, 69, 0.6));
}

/* ===== MEJORAS EN IDEAS GENERADAS ===== */
.generated-ideas {
    border-top: 2px solid rgba(40, 167, 69, 0.2);
    padding-top: 15px;
}

.idea-item {
    transition: all 0.3s ease;
    position: relative;
}

.idea-item::before {
    content: '○';
    position: absolute;
    left: -20px;
    top: 12px;
    color: #28a745;
    font-weight: bold;
    transition: all 0.3s ease;
}

.idea-item.selected::before {
    content: '●';
    color: #28a745;
    transform: scale(1.2);
}

.idea-item.selected {
    background: rgba(40, 167, 69, 0.15);
    border-color: #28a745;
    border-width: 2px;
    transform: translateX(5px);
}

.ideas-actions {
    border-top: 1px solid rgba(40, 167, 69, 0.2);
    padding-top: 15px;
}

/* ===== ESTADO DE CARGA ===== */
.loading-ideas {
    text-align: center;
    padding: 20px;
    color: #17a2b8;
}

.loading-ideas::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '⏳'; }
    40% { content: '⏳.'; }
    60% { content: '⏳..'; }
    80%, 100% { content: '⏳...'; }
}

/* ===== INDICADORES DE GUARDADO ===== */
.save-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 9999;
}

.save-indicator.visible {
    opacity: 1;
}

/* ===== MEJORAS EN FORMULARIOS ===== */
.edit-section input:invalid,
.create-section input:invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.edit-section input:valid,
.create-section input:valid {
    border-color: #28a745;
}

/* ===== VALIDACIÓN VISUAL EN TIEMPO REAL ===== */
.create-section input[style*="border-color: rgb(220, 53, 69)"],
.edit-section input[style*="border-color: rgb(220, 53, 69)"] {
    background-color: rgba(220, 53, 69, 0.05);
    animation: shake 0.5s ease-in-out;
}

.create-section input[style*="border-color: rgb(255, 193, 7)"],
.edit-section input[style*="border-color: rgb(255, 193, 7)"] {
    background-color: rgba(255, 193, 7, 0.05);
}

.create-section input[style*="border-color: rgb(40, 167, 69)"],
.edit-section input[style*="border-color: rgb(40, 167, 69)"] {
    background-color: rgba(40, 167, 69, 0.05);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===== BOTONES DESHABILITADOS ===== */
.create-buttons button:disabled,
.edit-buttons button:disabled {
    background: #6c757d !important;
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.create-buttons button:disabled:hover,
.edit-buttons button:disabled:hover {
    background: #6c757d !important;
    transform: none !important;
}

/* ===== INDICADORES DE CAMPO REQUERIDO ===== */
.create-section label[for="create-name"]::after,
.edit-section label[for="edit-name"]::after {
    content: ' *';
    color: #dc3545;
    font-weight: bold;
}

/* ===== AYUDA CONTEXTUAL ===== */
.field-help {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 2px;
    font-style: italic;
}

.field-help.error {
    color: #dc3545;
}

.field-help.warning {
    color: #ffc107;
}

.field-help.success {
    color: #28a745;
}

/* ===== ANIMACIONES DE ENTRADA ===== */
.panel-enter {
    animation: slideInRight 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===== TOOLTIPS MEJORADOS ===== */
.advanced-tooltip {
    max-width: 300px;
    background: rgba(0, 0, 0, 0.95);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip-title {
    font-weight: bold;
    margin-bottom: 5px;
    color: #FFD700;
}

.tooltip-description {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #fff;
}

.tooltip-type {
    font-size: 0.7rem;
    color: #ccc;
    margin-top: 5px;
    font-style: italic;
}