/* --- STYLE GLOBAL --- */
body {
    margin: 0;
    padding: 0;
    background-color: #1e1e24; /* Fond sombre */
    color: #ffffff;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

#chart-container {
    width: 100vw;
    height: 100vh;
}

/* --- STYLES SVG D3.js --- */

/* Liens */
.link {
    fill: none;
    stroke: #555560;
    stroke-width: 1.5px;
    transition: all 0.5s ease;
}

/* Noeuds */
.node rect {
    fill: #2d2d35;
    stroke: #4a4a55;
    stroke-width: 1px;
    rx: 6;
    ry: 6;
    cursor: pointer;
    transition: all 0.3s;
}

.node rect:hover {
    stroke: #6c7ae0;
    fill: #363640;
}

/* Noeud sélectionné */
.node.selected rect {
    stroke: #ff9f43;
    stroke-width: 2px;
    fill: #363640;
}

/* Noeud Racine */
.node--root rect {
    fill: #4a4a55;
    stroke: #6c7ae0;
    stroke-width: 2px;
}

/* Texte */
.node text {
    font-size: 12px;
    fill: #e0e0e0;
    pointer-events: none;
}

/* Expander (Cercle) */
.node circle.expander {
    stroke: #6c7ae0;
    stroke-width: 1.5px;
    fill: #1e1e24;
    cursor: pointer;
}

/* --- INTERFACE UTILISATEUR --- */
.controls {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(45, 45, 53, 0.95);
    padding: 15px;
    padding-top: 45px; /* Space for the button */
    border-radius: 8px;
    border: 1px solid #4a4a55;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
    max-width: 300px;
    width: 300px; 
    /* Transition on width, height/max-height, and padding */
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    
    overflow: hidden;
    max-height: 800px;
    min-height: 48px; /* Ensure it never fully disappears */
}

/* Collapsed State */
.controls.collapsed {
    padding: 0;
    width: 48px;
    height: 48px; /* Explicit height */
    max-height: 48px;
    border-radius: 8px; 
    background: rgba(45, 45, 53, 0.8);
    border-color: transparent;
    cursor: pointer;
    /* Center the button within the circle */
    align-items: center;
    justify-content: center;
}

.controls.collapsed:hover {
    background: rgba(60, 60, 70, 0.9);
    transform: scale(1.05);
}

/* Toggle Button */
.toggle-menu {
    position: absolute;
    top: 10px;
    left: 10px; /* Moved to Left */
    right: auto;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0; /* Remove padding to be precise */
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 101;
}

.toggle-menu svg {
    width: 24px;
    height: 24px;
}

.toggle-menu:hover {
    color: #aeaeae;
}

/* Button position when collapsed */
.controls.collapsed .toggle-menu {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Reset other positions */
    right: auto;
    bottom: auto;
}

.controls-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 1;
    transform: translateY(0);
}

.controls.collapsed .controls-content {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    position: absolute; /* Take out of flow to allow shrinking */
}

.controls h1 {
    font-size: 16px;
    margin: 0 0 5px 0;
    color: #fff;
    font-weight: 600;
}

.btn-group {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.btn {
    background-color: #4a4a55;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s;
    flex: 1 0 auto; /* Boutons flexibles */
    text-align: center;
}

.btn:hover {
    background-color: #5a5a65;
}

.btn.primary {
    background-color: #6c7ae0;
}

.btn.primary:hover {
    background-color: #5a6ad0;
}

.btn.danger {
    background-color: #e55039;
}

.btn.danger:hover {
    background-color: #c0392b;
}

.legend {
    margin-top: 5px;
    font-size: 11px;
    color: #aaa;
    line-height: 1.4;
}

/* Édition de texte (ForeignObject input) */
.node-input-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node-input {
    background: #2d2d35;
    color: #fff;
    border: 1px solid #6c7ae0;
    border-radius: 4px;
    padding: 4px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    outline: none;
    text-align: left;
    box-sizing: border-box; /* Important for padding */
    line-height: normal;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px; /* Espace minimal bords */
    box-sizing: border-box;
}

.modal {
    background: #2d2d35;
    border: 1px solid #4a4a55;
    border-radius: 8px;
    padding: 20px;
    width: 500px;
    max-width: 100%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal h2 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

.modal p {
    font-size: 13px;
    color: #ccc;
    margin: 0;
}

.modal textarea {
    width: 100%;
    background: #1e1e24;
    border: 1px solid #4a4a55;
    color: #fff;
    font-family: monospace;
    padding: 10px;
    resize: vertical;
    border-radius: 4px;
    box-sizing: border-box;
    min-height: 150px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 5px;
}

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 768px) {
    .controls {
        top: 10px;
        left: 10px;
        right: 10px; /* Prend toute la largeur moins marges */
        max-width: none;
        padding: 10px;
    }

    .btn {
        padding: 10px; /* Zones tactiles plus grandes */
        font-size: 14px; 
    }

    .legend {
        display: none; /* Masquer légende sur mobile pour gagner place */
    }

    .node rect {
        height: 40px; /* Noeuds plus hauts pour le tactile */
        y: -20;
    }
    
    .node text {
         font-size: 14px; /* Texte plus lisible */
    }
}

/* --- TOASTS --- */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: #333;
    color: #fff;
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 14px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    min-width: 250px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    border-left: 4px solid #6c7ae0;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-left-color: #e55039;
    background: #2c1e1e;
}

.toast.success {
    border-left-color: #2ecc71;
    background: #1e2c1e;
}
