:root {
    --neon: #00f2ff;
    --bg: #492c1f;
    --card: #11141d;
    --border: #0097c5;
    --text: #e5e7eb;
    --accent: #7c3aed;
}

body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    background: radial-gradient(circle at center, #5a5a5a 0%, #000000 100%);
    color: var(--text);
    margin: 0;
    overflow-x: hidden;
    height: 100vh;
    width: 100vw;
}

body.is-dragging * {
    cursor: grabbing !important;
    user-select: none;
}

/* Barre de contrôle */
.panel {
    background: rgba(10, 15, 25, 0.9);
    backdrop-filter: blur(12px);
    padding: 15px 25px;
    border-radius: 0 0 20px 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: fit-content;
    min-width: 600px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    align-items: center;
}

.zoom-controls {
    display: flex;
    gap: 10px;
    border-left: 1px solid var(--border);
    padding-left: 20px;
}

button {
    background: #1f2937;
    border: 1px solid var(--neon);
    color: var(--neon);
    padding: 5px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    min-width: 40px;
    min-height: 30px;
}

button:hover {
    background: var(--neon);
    color: black;
    box-shadow: 0 0 10px var(--neon);
}

label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--neon);
}

select, input {
    background: #111827;
    border: 1px solid var(--border);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
}

/* --- Search Input --- */
.search-container {
    position: relative;
}

#itemSearchInput {
    width: 180px;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #111827;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 1001;
    max-height: 300px;
    overflow-y: auto;
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-result-item:hover {
    background: var(--accent);
    color: white;
}

/* Viewport et Container */
#viewport {
    width: 100%;
    height: calc(100vh - 120px);
    margin-top: 60px;
    cursor: grab;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
}

#zoom-container {
    transform-origin: 0 0;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: absolute;
    padding: 500px;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    will-change: transform;
    backface-visibility: hidden;
    touch-action: none;
}

#svg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

#output {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 130px;
    position: relative;
    z-index: -2;
    background-color: #05080c;
    --grid-line-width: 1px;
    background-image: linear-gradient(rgba(255, 255, 255, 0.08) var(--grid-line-width), transparent var(--grid-line-width)), linear-gradient(90deg, rgba(255, 255, 255, 0.08) var(--grid-line-width), transparent var(--grid-line-width));
    background-size: var(--grid-size, 32px) var(--grid-size, 32px);
}

.tier {
    display: flex;
    justify-content: flex-start;
    gap: inherit;
    width: fit-content;
    min-width: 100%;
}

/* Noeuds */
.node {
    background: var(--card);
    border: 2px solid var(--border);
    padding: 2px;
    border-radius: 4px;
    text-align: center;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    position: relative;
    z-index: 5;
    cursor: pointer;
    overflow: hidden;
}

.node:active {
    transform: scale(0.98);
}

.node:hover {
    border-color: var(--neon);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
    transform: translateY(-5px);
}

.node.is-final {
    border: 2px solid var(--neon);
    background: #0c111a;
}

/* Icône en filigrane (arrière-plan) */
.icon-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    height: 55%;
    object-fit: contain;
    opacity: 0.8;
    pointer-events: none;
    z-index: 1;
    filter: drop-shadow(0 0 10px rgba(0,0,0,0.5));
}

/* Gestion du LOD (Level of Detail) */
#output.lod-medium .m-info {
    display: none;
}

#output.lod-low .m-info,
#output.lod-low .qty {
    display: none;
}

#output.lod-low .icon-bg {
    opacity: 0.4;
    width: 90%;
    height: 90%;
}

.node-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 22%;
    background: rgba(10, 15, 25, 0.85);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

h4 {
    margin: 0;
    font-size: 0.65rem;
    color: #fff;
    width: 100%;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    padding: 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid;
    backdrop-filter: blur(2px);
    font-size: 0.9rem;
    font-weight: 800;
    font-family: monospace;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.node-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 18%;
    background: rgba(10, 15, 25, 0.85);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.m-info {
    padding: 0 4px;
    color: #fbbf24;
    font-size: 0.55rem;
    font-weight: bold;
    width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Flèches animées */
.flow-path {
    stroke-dasharray: 8, 12;
    animation: flow 2s linear infinite;
    stroke-width: 3px;
    opacity: 0.3;
    fill: none;
    transition: opacity 0.3s, stroke-width 0.3s;
}

@keyframes flow {
    from {
        stroke-dashoffset: 100;
    }
    to {
        stroke-dashoffset: 0;
    }
}

.flow-path.highlight {
    opacity: 1 !important;
    stroke-width: 5px;
    filter: drop-shadow(0 0 5px currentColor);
}

/* Panneaux latéraux */
.summary-panel {
    background: rgba(10, 15, 25, 0.9);
    backdrop-filter: blur(12px);
    padding: 15px;
    border-radius: 0 20px 20px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: fixed;
    z-index: 1000;
    width: 220px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    top: 100px;
    left: 0;
    margin-left: 10px;
    margin-top: 10px;
    transition: transform 0.3s ease;
}

.summary-panel.hidden {
    transform: translateX(-100%);
}

.summary-panel h3 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--neon);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#machine-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.machine-entry-vertical {
    background: var(--card);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.machine-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 5px;
}

.machine-name {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
}

.machine-total {
    font-weight: 800;
    color: var(--neon);
    font-size: 1rem;
    font-family: monospace;
}

.machine-products {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.product-badge {
    background: rgba(0, 0, 0, 0.4);
    padding: 4px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.product-badge:hover {
    transform: scale(1.1);
    border-color: var(--neon);
}

.product-badge img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.search-result-item img {
    width: 20px;
    height: 20px;
}

.total-bar {
    border-left: 4px solid #fbbf24 !important;
    background: rgba(251, 191, 36, 0.1);
    margin-top: 10px;
}

.total-bar .machine-total {
    color: #fbbf24;
}

/* Panneau plein écran 3D */
.fullscreen-schema-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
}

.fullscreen-schema-panel.hidden {
    display: none;
}

.fullscreen-schema-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.fullscreen-schema-header h2 {
    color: var(--neon);
    font-size: 1.2rem;
    margin: 0;
}

#threejs-container {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    position: relative;
    background: #0a0a12;
}

.fullscreen-schema-controls {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* Responsive */
@media (max-width: 768px) {
    .panel {
        min-width: 95vw;
        padding: 10px;
        flex-direction: column;
    }

    .controls-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    .zoom-controls {
        border-left: none;
        padding-left: 0;
        margin-top: 10px;
        width: 100%;
        justify-content: center;
    }

    #viewport {
        height: calc(100vh - 160px);
        margin-top: 100px;
    }

    #zoom-container {
        padding: 200px 50px;
    }

    .tier {
        gap: 80px !important;
    }

    .node {
        width: 140px;
        padding: 12px;
    }

    .icon-main {
        width: 36px;
        height: 36px;
    }

    h4 {
        font-size: 0.75rem;
    }

    .qty {
        font-size: 1rem;
    }

    .m-info {
        font-size: 0.6rem;
        padding: 3px;
    }

    .summary-panel {
        width: 90vw;
        max-width: 250px;
        top: 110px;
        left: 5px;
    }

    button {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    select, input {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .flow-path {
        animation: none;
        stroke-dasharray: none;
    }
}
