:root { 
    --bg: #0f172a; --panel: #1e293b; --accent: #38bdf8; 
    --text: #f1f5f9; --ok: #22c55e; --warn: #eab308; 
    --err: #ef4444; --border: #334155; 
}

body { 
    background: var(--bg); color: var(--text); 
    font-family: 'Segoe UI', sans-serif; margin: 0; height: 100vh; 
    display: flex; flex-direction: column; overflow: hidden; user-select: none; 
}

.nav { background: var(--panel); padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; z-index: 100; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 5px; background: #0f172a; padding: 3px; border-radius: 8px; }
.tab-btn { background: transparent; border: none; color: #64748b; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; transition:0.2s; }
.tab-btn.active { background: var(--panel); color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.btn-icon { background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; }

.view-area { flex-grow: 1; position: relative; overflow: hidden; }
.hidden { display: none !important; }

/* LIST ACCORDION */
#view-list { padding: 20px; overflow-y: auto; height: 100%; box-sizing: border-box; }
.search-bar-wrap { display:flex; gap:10px; margin-bottom:15px; }
.search-bar-wrap input {
    width: 100%; padding: 12px; background: #0f172a; 
    border: 1px solid #334155; color: #fff; border-radius: 6px; 
    box-sizing: border-box;
}
.accordion-header {
    background: #334155; color: var(--accent); padding: 10px; margin-top: 15px; 
    border-radius: 6px; cursor: pointer; font-weight: bold; display: flex; justify-content: space-between;
}
.accordion-content { display: none; margin-top: 5px; }
.accordion-content.open { display: block; }

.inv-item { 
    background: var(--panel); padding: 12px; border-radius: 6px; 
    margin-bottom: 5px; display: flex; justify-content: space-between; 
    align-items: center; border-left: 3px solid var(--border); cursor: pointer;
}
.inv-item:hover { background: #2a3649; }
.btn-mini-action {
    background: var(--panel); border: 1px solid var(--border); color: var(--accent);
    width: 45px; border-radius: 6px; cursor: pointer; font-size: 1.2rem; flex-shrink:0;
}

/* 3D ENGINE */
#view-3d { background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%); width: 100%; height: 100%; position: relative; }
.scene-container { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; perspective: 2500px; }
.rack-3d { position: relative; transform-style: preserve-3d; transform: rotateX(60deg) rotateZ(-45deg); transition: transform 0.4s ease-out; }

.shelf {
    position: absolute; background: rgba(30, 41, 59, 0.9); border: 2px solid #64748b; 
    transform: translateZ(var(--z)); transform-style: preserve-3d;
    box-shadow: 0 0 20px rgba(0,0,0,0.5); 
    display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr);
}
.shelf:hover { border-color: var(--accent); cursor: pointer; background: rgba(56, 189, 248, 0.3); }

.item-3d { 
    grid-column: span var(--gw); grid-row: span var(--gd); 
    position: relative; transform-style: preserve-3d; margin: 0; 
}
.cube-top { 
    position: absolute; inset: 1px; background: var(--c-top); 
    border: 1px solid rgba(255,255,255,0.2); transform: translateZ(var(--h)); 
    box-shadow: inset 0 0 5px rgba(0,0,0,0.3); 
}
.cube-front { 
    position: absolute; bottom: 0; left: 1px; width: calc(100% - 2px); height: var(--h); 
    background: var(--c-side); transform-origin: bottom; transform: rotateX(-90deg); filter: brightness(0.7); 
}
.cube-side { 
    position: absolute; top: 1px; right: 0; height: calc(100% - 2px); width: var(--h); 
    background: var(--c-side); transform-origin: right; transform: rotateY(-90deg); filter: brightness(0.5); 
}

.ext-label {
    position: absolute; bottom: -60px; left: 50%; 
    transform: translateX(-50%) rotateZ(45deg); 
    background: var(--c-top); color: #fff; padding: 3px 8px; border-radius: 4px;
    font-size: 0.7rem; font-weight: bold; white-space: nowrap;
    border: 1px solid #fff; pointer-events: none; z-index: 200;
}
.ext-label::before {
    content:''; position: absolute; bottom: 100%; left: 50%; height: 40px; width: 2px; background: rgba(255,255,255,0.4);
}

.cat-Colori { --c-top: #3b82f6; --c-side: #1d4ed8; }
.cat-Chimici { --c-top: #10b981; --c-side: #059669; }
.cat-Strumenti { --c-top: #f59e0b; --c-side: #d97706; }
.cat-Generico { --c-top: #94a3b8; --c-side: #475569; }

.rack-nav { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; align-items: center; z-index: 50; background: rgba(0,0,0,0.8); padding: 15px 30px; border-radius: 40px; backdrop-filter: blur(5px); }
.rn-btn { background: none; border: none; color: #fff; font-size: 1.8rem; cursor: pointer; }
.rn-title { font-weight: bold; color: var(--accent); min-width: 120px; text-align: center; }
.btn-top-right { position: absolute; top: 15px; right: 15px; z-index: 60; background: rgba(56, 189, 248, 0.2); border: 1px solid var(--accent); color: var(--accent); padding: 8px 12px; border-radius: 6px; font-size: 0.8rem; cursor: pointer; backdrop-filter: blur(4px); }
.fab { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: #000; border: none; font-size: 1.5rem; cursor: pointer; box-shadow: 0 5px 15px rgba(0,0,0,0.5); z-index: 90; display:flex; justify-content:center; align-items:center; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.95); z-index: 200; display: flex; flex-direction: column; }
.editor-header { padding: 15px; background: var(--panel); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.editor-controls { background: var(--panel); padding: 15px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; gap: 10px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
label { font-size: 0.75rem; color: #94a3b8; }
.form-input { background: #0f172a; border: 1px solid #444; color: #fff; padding: 10px; border-radius: 6px; width: 100%; box-sizing: border-box; font-size: 1rem; }
.btn-act { padding: 15px; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; flex: 1; font-size: 1rem; }
.btn-save { background: var(--accent); color: #000; }
.btn-del { background: var(--err); color: #fff; }
.btn-move { background: var(--warn); color: #000; }

.grid-viewport { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 10px; overflow: hidden; background: #000; touch-action: none; }
.interactive-grid { display: grid; gap: 1px; background: #334155; touch-action: none; }
.g-cell { background: #1e293b; position: relative; }
.g-cell.occupied { background: #475569; opacity: 0.8; border: 1px solid #64748b; }
.g-cell.drawing { background: var(--accent); opacity: 0.6; } 
.g-cell.selected { background: var(--ok); opacity: 0.8; border: 2px solid #fff; z-index: 10; }