:root {
    --primary-color: #2563eb; 
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-color: #0f172a;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --input-bg: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0; 
}

/* --- Layout Structure --- */
header {
    background-color: var(--surface-color);
    padding: 1rem 5%;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--primary-color);
}

main {
    max-width: 1100px; 
    margin: 2rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 80px; 
}

.hidden {
    display: none !important;
}

/* --- User Home & Welcome --- */
.welcome-box {
    text-align: center;
    padding: 2.5rem 1rem;
    background: white;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    border: 1px dashed var(--border-color);
}

.welcome-images {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.welcome-images img {
    height: 50px;
    object-fit: contain;
    opacity: 0.8;
}

/* List Item Container */
.questionnaire-list-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start; 
    transition: box-shadow 0.2s, transform 0.1s;
    gap: 1.5rem; 
}

.questionnaire-list-item:hover {
    box-shadow: var(--shadow-md);
    border-color: #94a3b8;
    transform: translateY(-1px);
}

/* Colonna Info (Sinistra) */
.questionnaire-info-col {
    display: flex;
    flex-direction: column;
    gap: 0.5rem; 
    flex: 1;
    min-width: 0; 
}

.questionnaire-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color); 
    line-height: 1.2;
    margin-bottom: 0.25rem;
}

.questionnaire-description {
    font-size: 0.95rem;
    color: var(--text-light);
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Colonna Azioni (Destra) */
.questionnaire-actions-col {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
    align-items: center;
    padding-top: 0.25rem;
    flex-wrap: wrap;
}

/* --- Questionnaire Layout --- */

.breadcrumb {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.context-info {
    background-color: #eff6ff;
    border-left: 4px solid var(--primary-color);
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: #1e3a8a;
}

.questionnaire-section {
    background-color: var(--surface-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 2rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.questionnaire-section-header {
    border-bottom: 2px solid var(--background-color);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.questionnaire-section-header h3 {
    margin: 0;
    font-size: 1.25rem; 
    font-weight: 700;   
    color: var(--primary-color);
    letter-spacing: -0.01em;
}

.questionnaire-section-header p {
    margin-top: 0.25rem;
    font-size: 0.95rem;
    color: var(--text-light);
}

/* --- QUESTIONS GRID --- */
.questions-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem; 
}

.question-form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    /* Rimuoviamo bordi e background per evitare l'effetto box-in-box */
    background: transparent;
    border: none;
    padding: 0;
}

/* --- NESTED QUESTIONS STYLING (MODERN & CLEAN) --- */

.question-form-group.has-nested-children {
    /* Mantiene pulito il contenitore padre */
    background: transparent;
    border: none;
    padding: 0;
}

.nested-questions-container {
    margin-top: 1rem;
    margin-left: 0.75rem; /* Leggero rientro */
    padding-left: 1.5rem; /* Spazio tra la linea e il contenuto */
    border-left: 3px solid #cbd5e1; /* Linea guida elegante */
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    
    /* Animazione di entrata */
    animation: slideDownFade 0.3s ease-out forwards;
    transform-origin: top;
}

@keyframes slideDownFade {
    0% { opacity: 0; transform: translateY(-10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Quando il contenitore nidificato è attivo, la linea diventa del colore primario */
.nested-questions-container:hover {
    border-left-color: var(--primary-color);
    transition: border-left-color 0.3s ease;
}

/* --- Inputs & Labels --- */
label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.5rem;
    display: block;
}

input[type="text"], 
input[type="number"], 
input[type="datetime-local"], 
select, 
textarea {
    width: 100%;
    padding: 0.6rem 0.8rem; 
    font-size: 0.95rem;
    background-color: #ffffff; /* Uniformiamo sfondo bianco */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    transition: all 0.2s;
    box-sizing: border-box;
}

input::placeholder {
    color: #94a3b8;
    font-size: 0.9em;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
    min-height: 40px; 
    height: 40px;
    resize: vertical;
    overflow-y: hidden; 
}
textarea:focus {
    min-height: 60px; 
}

/* --- CHOICES GRID --- */
.choices-group {
    display: grid;
    grid-template-columns: repeat(4, 1fr); 
    gap: 0.75rem; 
    width: 100%;
}

.choice-option {
    display: flex;
    align-items: center; 
    cursor: pointer;
    font-size: 0.95rem;
    background-color: #ffffff; 
    border: 1px solid #e2e8f0;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.choice-option:hover {
    border-color: #cbd5e1;
    background-color: #f8fafc;
}

.choice-option input[type="radio"],
.choice-option input[type="checkbox"] {
    margin: 0 0.5rem 0 0; 
    width: 1.15em;
    height: 1.15em;
    accent-color: var(--primary-color);
}

.choice-option label {
    margin-bottom: 0;
    font-weight: 400;
    cursor: pointer;
    color: var(--text-color);
}

@media (max-width: 900px) {
    .choices-group { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 500px) {
    .choices-group { grid-template-columns: 1fr; }
}

/* --- COMBINED QUESTION STYLING (The Boxes) --- */
.combined-wrapper {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.25rem;
    margin-top: 0.25rem;
    /* Aggiunge una leggera ombra per dare profondità rispetto allo sfondo */
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

/* Per i gruppi annidati, manteniamo lo stile coerente */
.nested-questions-container .combined-wrapper {
    background-color: #ffffff;
    border-color: #e2e8f0;
    /* Riduce leggermente padding se necessario, ma manteniamo coerenza */
}

.combined-secondary {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed #cbd5e1;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.combined-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0;
    white-space: nowrap;
    min-width: fit-content;
}

.combined-wrapper input[type="text"],
.combined-wrapper textarea {
     background-color: #f8fafc; /* Leggero contrasto per input testo secondari */
     border-color: #e2e8f0;
     flex-grow: 1; 
}
.combined-wrapper input[type="text"]:focus,
.combined-wrapper textarea:focus {
    background-color: #ffffff;
    border-color: var(--primary-color);
}

@media (max-width: 768px) {
    .questionnaire-section { padding: 1.25rem; }
    
    .combined-secondary {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* --- Buttons --- */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    background-color: var(--primary-color);
    color: white;
}

button:hover {
    background-color: var(--primary-hover);
}

button:active {
    transform: translateY(1px);
}

button.secondary {
    background-color: white;
    border: 1px solid #cbd5e1;
    color: var(--text-color);
}

button.secondary:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
}

/* Link Buttons inside Questionnaire */
.questionnaire-link-btn {
    background-color: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #0284c7;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}

.questionnaire-link-btn:hover {
    background-color: #e0f2fe;
}

/* --- Action Bar (Sticky Footer) --- */
.form-actions {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: flex-start;
    border-radius: var(--radius);
    box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.05);
    position: sticky;
    bottom: 20px; 
    z-index: 50;
    max-width: 1100px;
    margin: 0 auto;
}

/* --- Modal (Disclaimer) --- */
.modal-overlay {
    background-color: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay:not(.hidden) {
    display: flex;
}

.modal-content {
    background: white;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 800px; 
    max-height: 85vh; 
    overflow-y: auto; 
    display: flex;
    flex-direction: column;
}

.disclaimer-item {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.disclaimer-item:last-child {
    border-bottom: none;
}

.disclaimer-acceptance {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.modal-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

@media (max-width: 768px) {
    .questionnaire-list-item {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .questionnaire-info-col {
        width: 100%;
    }

    .questionnaire-actions-col {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        padding-top: 0;
    }
}