/* Design System & Variables */
:root {
    --bg-color: #0f172a;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --success: #10b981;
    --danger: #ef4444;
    --font-family: 'Outfit', sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Styles */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-family); background: var(--bg-gradient); color: var(--text-primary); min-height: 100vh; overflow-x: hidden; }
h1, h2, h3 { font-weight: 600; }
.text-accent { color: var(--accent-color); }
.text-success-bg { background: var(--success) !important; }

/* Layout */
.app-container { display: flex; height: 100vh; }
.main-content { flex: 1; padding: 2rem; overflow-y: auto; display: flex; flex-direction: column; gap: 2rem; }

/* Components */
.glass-panel {
    background: var(--panel-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border); border-radius: 16px; box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: var(--accent-color); color: #fff; border: none; padding: 0.6rem 1.2rem;
    border-radius: 8px; font-family: var(--font-family); font-weight: 600; cursor: pointer; transition: var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-2px); }
.btn-icon { background: none; border: none; color: var(--text-secondary); cursor: pointer; transition: var(--transition); padding: 5px;}
.btn-icon:hover { color: var(--danger); }

/* Sidebar */
.sidebar { width: 260px; padding: 2rem 1.5rem; display: flex; flex-direction: column; gap: 3rem; border-radius: 0; border-left: none; border-top: none; border-bottom: none; }
.logo { display: flex; align-items: center; gap: 1rem; font-size: 1.5rem; color: var(--accent-color); }
.nav-links { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.nav-links li { padding: 1rem 1.5rem; border-radius: 12px; cursor: pointer; transition: var(--transition); display: flex; align-items: center; gap: 1rem; color: var(--text-secondary); font-weight: 500; }
.nav-links li:hover, .nav-links li.active { background: rgba(56, 189, 248, 0.1); color: var(--accent-color); }

/* Header & Sections */
.top-bar { display: flex; justify-content: space-between; align-items: center; }
.user-profile { font-size: 0.9rem; color: var(--text-secondary); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-section { display: none; animation: fadeIn 0.4s ease-out forwards; }
.page-section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Dashboard Grid */
.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.stat-card { padding: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.stat-card h3 { font-size: 1rem; color: var(--text-secondary); }
.stat-value { font-size: 2rem; font-weight: 800; }
.stat-sub { font-size: 1rem; font-weight: 400; color: var(--text-secondary); }
.progress-bar { width: 100%; height: 6px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; margin-top: 0.5rem; overflow: hidden; }
.progress { height: 100%; background: var(--accent-color); border-radius: 3px; transition: width 0.5s ease; }
.main-widget { grid-column: span 3; padding: 1.5rem; }
.concept-preview { margin-top: 1rem; width: 100%; height: 350px; border-radius: 12px; overflow: hidden; position: relative; }
.concept-preview img { width: 100%; height: 100%; object-fit: cover; transition: var(--transition); }
.concept-preview:hover img { transform: scale(1.02); }
.concept-overlay { position: absolute; bottom: 0; left: 0; right: 0; padding: 2rem 1.5rem 1.5rem; background: linear-gradient(transparent, rgba(0,0,0,0.8)); font-weight: 600; }

/* Budget */
.card { padding: 2rem; }
.budget-table { width: 100%; border-collapse: collapse; }
.budget-table th, .budget-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--panel-border); }
.budget-table th { color: var(--text-secondary); font-weight: 500; }
.budget-table tfoot th { font-size: 1.2rem; border-top: 2px solid var(--panel-border); border-bottom: none; padding-top: 1.5rem; }

/* Timeline / Roadmap */
.timeline { display: flex; flex-direction: column; gap: 1rem; }
.timeline-item { display: flex; align-items: center; gap: 1.5rem; padding: 1rem; border-radius: 12px; background: rgba(255,255,255,0.02); border: 1px solid transparent; transition: var(--transition); cursor: pointer; }
.timeline-item:hover { border-color: var(--panel-border); background: rgba(255,255,255,0.05); }
.timeline-item.completed .timeline-icon { background: var(--success); color: white; }
.timeline-item.completed .timeline-content h3 { text-decoration: line-through; color: var(--text-secondary); }
.timeline-icon { width: 40px; height: 40px; border-radius: 50%; background: rgba(56, 189, 248, 0.1); color: var(--accent-color); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; transition: var(--transition); }
.timeline-content { flex: 1; }
.timeline-content h3 { margin-bottom: 0.25rem; transition: var(--transition); }
.timeline-content p { color: var(--text-secondary); font-size: 0.9rem; }
.checkbox-container { width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--panel-border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: var(--transition); }
.timeline-item.completed .checkbox-container { background: var(--success); border-color: var(--success); }
.timeline-item.completed .checkbox-container::after { content: '✓'; color: white; font-weight: bold; }

/* Gallery Grid */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }
.gallery-item { border-radius: 12px; overflow: hidden; position: relative; aspect-ratio: 16/9; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: var(--transition); }
.gallery-item:hover img { transform: scale(1.05); }
.delete-img { position: absolute; top: 10px; right: 10px; background: rgba(239, 68, 68, 0.8); color: white; border: none; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; display: none; align-items: center; justify-content: center; z-index: 10; }
.gallery-item:hover .delete-img { display: flex; }

/* Modals */
.modal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(5px); align-items: center; justify-content: center; }
.modal.show { display: flex; animation: fadeIn 0.2s ease-out forwards; }
.modal-content { width: 100%; max-width: 500px; padding: 2rem; position: relative; }
.close-modal { color: var(--text-secondary); float: right; font-size: 28px; font-weight: bold; cursor: pointer; position: absolute; right: 1.5rem; top: 1.5rem; }
.close-modal:hover { color: #fff; }

/* Forms */
form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-size: 0.9rem; color: var(--text-secondary); }
.form-group input { padding: 0.8rem; border-radius: 8px; border: 1px solid var(--panel-border); background: rgba(0,0,0,0.2); color: #fff; font-family: var(--font-family); }
.form-group input:focus { outline: none; border-color: var(--accent-color); }

/* Blueprint / Planimetria 2D */
.blueprint-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 0;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    margin-top: 1.5rem;
}

.blueprint-wrapper {
    position: relative;
    width: 400px;
    height: 400px;
}

/* Container Inferiore (Orizzontale) */
.container-bottom {
    position: absolute;
    top: 160px; /* (400 - 80) / 2 */
    left: 0;
    width: 400px; /* 12 metri in scala */
    height: 80px;  /* 2.4 metri in scala */
    background: rgba(148, 163, 184, 0.2); /* Grigio scuro/vetro */
    border: 3px solid #94a3b8;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Container Superiore (Verticale spostato a destra) */
.container-top {
    position: absolute;
    top: 0;
    left: 260px; /* Spostato a destra per lasciare tutto il terrazzo a sinistra */
    width: 80px;  /* 2.4 metri in scala */
    height: 400px; /* 12 metri in scala */
    background: rgba(245, 158, 11, 0.2); /* Legno/vetro */
    border: 3px solid #f59e0b;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* Stanze e Aree */
.stairwell {
    width: 100%;
    height: 80px; /* Quadrato centrale 2.4x2.4 */
    border-top: 2px dashed #f59e0b;
    border-bottom: 2px dashed #f59e0b;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
}

.room {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.top-room {
    border-bottom: 2px solid #f59e0b;
}

.bottom-room {
    border-top: 2px solid #f59e0b;
}

/* Labels */
.room-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    transform: rotate(0deg); /* Se serve ruotare il testo */
}

.container-top .room-label {
    transform: rotate(-90deg); /* Ruota il testo per farlo leggere in verticale */
    white-space: nowrap;
}

.bottom-terrace-left { margin-left: 20px; }
.bottom-terrace-right { margin-right: 20px; }

/* ========== Compact 3D Controls ========== */
.ui-controls-compact {
    margin-top: 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: rgba(15, 23, 42, 0.5);
    overflow: hidden;
}

/* Toggle header button */
.controls-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.85rem;
    background: rgba(15, 23, 42, 0.6);
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--transition);
}
.controls-toggle-btn:hover { color: var(--accent-color); }
.controls-toggle-btn .toggle-arrow { margin-left: auto; transition: transform 0.3s ease; }
.controls-toggle-btn.collapsed .toggle-arrow { transform: rotate(180deg); }

/* Collapsible body */
.controls-body {
    display: grid;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem 0.7rem;
    max-height: 300px;
    transition: max-height 0.35s ease, padding 0.35s ease, opacity 0.25s ease;
    opacity: 1;
}
.controls-body.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    overflow: hidden;
}

/* Selectors grid - auto-fill for density */
.selectors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.4rem;
}

.ctrl-select {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.ctrl-select label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding-left: 0.15rem;
}

.ctrl-select select {
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    font-family: var(--font-family);
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-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='%2394a3b8' 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 0.4rem center;
    background-size: 0.8em;
    padding-right: 1.6rem;
}
.ctrl-select select:hover,
.ctrl-select select:focus {
    border-color: var(--accent-color);
    outline: none;
}

/* Toggle pill chips - inline strip */
.toggles-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 0;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.toggle-pill input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.toggle-pill span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    border: 1px solid var(--panel-border);
    background: rgba(15, 23, 42, 0.5);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 500;
    font-family: var(--font-family);
    transition: var(--transition);
    white-space: nowrap;
}
.toggle-pill span i { font-size: 0.65rem; }

.toggle-pill:hover span {
    border-color: var(--accent-color);
    color: var(--text-primary);
}

/* Active / checked state */
.toggle-pill input:checked + span {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.4);
    color: var(--accent-color);
}

/* Accent variant (e.g. Coibentazione) */
.toggle-pill--accent input:checked + span {
    background: rgba(245, 194, 24, 0.15);
    border-color: rgba(245, 194, 24, 0.4);
    color: #f5c218;
}

/* Notebook UI */
.notes-app-container {
    display: flex;
    gap: 1.5rem;
    min-height: 500px;
    height: calc(100vh - 250px);
}

.notes-sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.notes-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-right: 5px;
}

.notes-list::-webkit-scrollbar {
    width: 4px;
}
.notes-list::-webkit-scrollbar-thumb {
    background: var(--panel-border);
    border-radius: 4px;
}

.note-item {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    transition: var(--transition);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid transparent;
}

.note-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.note-item.active {
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent-color);
    border-color: rgba(56, 189, 248, 0.3);
    font-weight: 500;
}

.notes-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--panel-border);
}

.note-title-input {
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--panel-border);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 600;
    padding: 0.5rem 0;
    margin-bottom: 1.5rem;
    font-family: var(--font-family);
    transition: var(--transition);
}

.note-title-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.note-body-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.6;
    resize: none;
}

.note-body-input:focus {
    outline: none;
}

.note-body-input::-webkit-scrollbar {
    width: 6px;
}
.note-body-input::-webkit-scrollbar-thumb {
    background: var(--panel-border);
    border-radius: 4px;
}

/* ========== RESPONSIVE MOBILE E TABLET ========== */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
    }
    
    /* Mostra il pulsante hamburger */
    #mobile-menu-toggle {
        display: block !important;
    }
    
    /* Zero padding su mobile per massimizzare l'area visibile */
    .main-content {
        padding: 0;
        gap: 1.0rem;
    }
    
    .top-bar {
        padding: 0;
        background: transparent;
        border-bottom: none;
    }
    
    /* Sidebar come menu laterale a scomparsa (off-canvas) */
    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 10000;
        background: var(--bg-color);
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
        transition: transform 0.3s ease;
        padding-top: 2rem;
    }
    
    .sidebar.mobile-open {
        transform: translateX(300px);
    }
    
    .logo {
        display: flex !important;
        margin-bottom: 2rem;
    }
    
    /* Griglie a una sola colonna */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .main-widget {
        grid-column: span 1;
    }
    
    .gallery-grid {
        grid-template-columns: 1fr;
    }
    
    /* Adatta il pannello delle note */
    .notes-app-container {
        flex-direction: column;
        height: auto;
    }
    
    .notes-sidebar {
        width: 100%;
        height: auto;
        max-height: none;
    }
    
    .notes-list {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.4rem;
        max-height: 160px;
        overflow-y: auto;
        padding-right: 0;
    }
    
    .note-item {
        white-space: normal;
        font-size: 0.8rem;
        padding: 0.5rem 0.7rem;
        flex: 0 0 auto;
        max-width: 100%;
    }
    
    /* Aggiusta la planimetria */
    .blueprint-wrapper {
        transform: scale(0.9);
        transform-origin: top center;
        margin: 0 auto;
    }

    .blueprint-container {
        padding: 1rem 0;
        overflow-x: auto; /* Permetti lo scorrimento orizzontale */
    }
    
    /* Header e controlli */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .ui-controls-compact {
        width: 100%;
    }
    
    .selectors-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .card {
        padding: 0.25rem;
    }
    
    .blueprint-wrapper {
        transform: scale(0.7);
        transform-origin: top left;
    }
    
    .blueprint-proj4 {
        align-items: flex-start !important; /* Previene il taglio a sinistra nello scrolling */
    }
}

/* Padding minimo per la sezione 3D su mobile */
@media (max-width: 1200px) {
    #modello3d .card {
        padding: 0.25rem;
    }
    
    #modello3d .section-header {
        padding: 0 0.25rem;
    }
}
