/* CLEAN RESET WITH RESPONSIVE IMPROVEMENTS */

:root {
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #222222;
    --muted: #777777;
    --brand: #3b6aff;
    --divider: #e5e8f0;
    --shadow: 0 4px 18px rgba(0,0,0,0.05);
    --space: clamp(16px, 3vw, 30px);
    --radius: 12px;
    --chip-bg: rgba(59,106,255,0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --card: #171a21;
        --text: #e6e6e6;
        --muted: #a2a7b0;
        --brand: #6da3ff;
        --divider: #2a2f3a;
        --shadow: none;
    }
}

[data-theme="light"] {
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #222222;
    --muted: #777777;
    --brand: #3b6aff;
    --divider: #e5e8f0;
    --shadow: 0 4px 18px rgba(0,0,0,0.05);
}

[data-theme="dark"] {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e6e6e6;
    --muted: #a2a7b0;
    --brand: #6da3ff;
    --divider: #2a2f3a;
    --shadow: none;
    --chip-bg: rgba(109,163,255,0.16);
}

body {
    margin: 0;
    font-family: "Inter", sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    display: flex;
    max-width: 1200px;
    margin: auto;
    padding: var(--space);
    gap: var(--space);
    flex: 1;
}

.sidebar {
    width: clamp(260px, 28%, 340px);
    background: var(--card);
    padding: var(--space);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.content {
    flex: 1;
    background: var(--card);
    padding: var(--space);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 0;
}

#name {
    font-size: clamp(28px, 6vw, 40px);
    font-weight: 700;
    margin: 0 0 clamp(12px, 2vw, 20px) 0;
    line-height: 1.1;
    word-break: break-word;
}

.section h2 {
    margin: 0 0 8px 0; /* riduci spazio sotto il titolo */
    font-size: 20px;
    color: var(--brand);
    border-bottom: 2px solid var(--divider);
    padding-bottom: 3px; /* più compatto */
}
/* evita margine extra subito dopo il titolo */
.section h2 + p { margin-top: 0; }
.section h2 + ul { margin-top: 0; }

.section ul { padding-left: 18px; }
.section ul li { margin-bottom: 6px; }
.job, .edu { margin-bottom: 25px; }
.job h3, .edu h3 { margin: 0; }
.date { font-size: 14px; color: var(--muted); }

/* Riduci lo spazio tra data e descrizione nelle esperienze */
.job .date { display: block; margin: 2px 0 0; }
.job .date + ul { margin-top: 4px; }

/* Applica la stessa compattezza a educazione e skills */
.edu .date { display: block; margin: 2px 0 0; }
.edu .date + p { margin-top: 4px; }
.section h3 { margin: 0; }
.section h3 + p,
.section h3 + ul { margin-top: 4px; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

#avatar {
    width: 75%;
    height: auto;        /* mantiene l’aspect ratio */
    border-radius: 50%;
    object-fit: cover;

    display: block;
    margin: 1rem auto;
    
    border: 2px solid var(--divider);
    box-shadow: var(--shadow);
    transition: filter .3s ease;
}
#avatar:hover { filter: brightness(1.05); }

/* Nascondi sezioni vuote */
.section:empty { display: none; }

/* Skills chips */
.skill-group { margin-bottom: 18px; }
.skills-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px; /* spazio tra titolo e chips */
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--divider);
    background: var(--chip-bg);
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
    transition: border-color .2s ease, transform .15s ease;
}
/* .chip:hover { border-color: var(--brand); transform: translateY(-1px); } */
.chip-icon { font-size: 14px; line-height: 1; }

/* Toggle tema */
.sidebar-top {
    display:flex;
    justify-content:flex-end;
    margin-bottom:8px;
}
#theme-toggle {
    position:fixed;
    bottom:32px;
    right:32px;
    z-index:1000;
    border-radius:50%;
    width:clamp(48px, 5vw, 64px);
    height:clamp(48px, 5vw, 64px);
    display:flex;
    align-items:center;
    justify-content:center;
    backdrop-filter:blur(6px);
    background:rgba(0,0,0,0.15);
    font-size:clamp(16px, 2vw, 32px);
    line-height:1;
}
[data-theme="dark"] #theme-toggle { background:rgba(255,255,255,0.12); }
#theme-toggle:hover { border-color: var(--brand); }

/* Responsive layout */

@media (max-width: 900px) {
    .container { 
        flex-direction: column; 
        padding-inline: clamp(14px, 4vw, 24px); /* evita che i bordi tocchino lo schermo */
    }
    .content {
        order: 1;
        text-align: justify;
    }
    .sidebar { 
        order: 2; 
        width: 100%; 
        padding: clamp(10px, 2.5vw, 16px); 
        margin-left: auto; 
        margin-right: auto; 
        box-sizing: border-box; 
    }
    /* Avatar più piccolo su schermi molto piccoli */
    #avatar { width: clamp(72px, 28vw, 110px); height: clamp(72px, 28vw, 110px); }
    .container { padding-right: calc(clamp(12px, 4vw, 20px) + env(safe-area-inset-right)); }
}

footer {
    order: 3;
    text-align: center;
    padding: 16px;
    flex-shrink: 0;
    margin-top: auto;
    color: var(--muted);
    font-size: 14px;
}
footer p { margin: 0; }

/* Stampa */
@media print {
    body { background: #ffffff; color: #000; }
    /* Single-column layout for print */
    .container { display: block; padding: 0; margin: 0; gap: 0; }
    .sidebar, .content { box-shadow: none; border-radius: 0; width: 100%; padding: 0; margin: 0; }
    /* Put avatar at the very top with tight spacing */
    #avatar { width: 120px; height: 120px; margin: 0 0 8pt 0; border: 1px solid #000; box-shadow: none; }
    /* Hide interactive/ui-only elements */
    #theme-toggle,
    #visitor-badge,
    .loading-overlay { display: none !important; }
    /* Links: print as plain text */
    a { color: #000; text-decoration: none; }
    /* Name larger for print */
    #name { font-size: 28pt; margin: 0 0 8pt 0; }
    .section h2 { font-size: 12pt; border-bottom: 1px solid #000; padding-bottom: 2pt; }
    .section h3 { font-size: 11pt; }
    .date { font-size: 9pt; color: #333; }
    .chip { border-color: #000; }
    /* Page break rules to avoid orphaned headers */
    .section { page-break-inside: avoid; }
    .job, .edu { page-break-inside: avoid; }
    /* Reduce margins for tighter print */
    .job, .edu { margin: 0 0 10pt 0; }
    .section { margin: 0 0 12pt 0; }
}

/* Languages section */
.lang { margin-bottom: 16px; }
.lang h3 { display:flex; align-items:center; gap:8px; margin:0 0 6px 0; }
.lang .badge { 
    display:inline-block; 
    padding: 2px 8px; 
    border-radius: 999px; 
    font-size: 12px; 
    background: var(--chip-bg); 
    border: 1px solid var(--divider);
}
.lang .note { display:block; color: var(--muted); font-size: 14px; }
.lang-meter { 
    height: 8px; 
    background: var(--divider); 
    border-radius: 999px; 
    overflow: hidden; 
}
.lang-meter-fill { height: 100%; background: var(--brand); }

/* Contact icons spacing */
#contacts i { 
    margin-right: 6px; 
    color: var(--muted); 
}