﻿:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #eef3fb;
    --surface-3: #e2ebf8;
    --text: #172033;
    --muted: #647089;
    --border: #d8e1f0;
    --primary: #3554d1;
    --primary-contrast: #ffffff;
    --success: #15803d;
    --danger: #c62828;
    --warning: #f59e0b;
    --shadow: 0 10px 24px rgba(14, 24, 43, .08);
    --radius: 18px;
}

:root[data-theme=dark] {
    --bg: #0d1424;
    --surface: #141d31;
    --surface-2: #1b2740;
    --surface-3: #243350;
    --text: #edf2ff;
    --muted: #9daccc;
    --border: #2a3859;
    --primary: #7ea2ff;
    --primary-contrast: #0f1830;
    --success: #4ade80;
    --danger: #ff8f8f;
    --warning: #fbbf24;
    --shadow: 0 12px 28px rgba(0, 0, 0, .24);
    --radius: 18px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
}

body {
    font-family: Segoe UI, Arial, sans-serif;
    background: linear-gradient(180deg, var(--surface-2) 0, var(--bg) 160px);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img,
table,
iframe,
video,
embed,
object {
    max-width: 100%;
    height: auto;
}

/* testo lungo: solo sugli elementi testuali veri */
h1, h2, h3, h4, p, td, th {
    overflow-wrap: break-word;
}

/* elementi che NON devono rompersi */
a,
span,
.btn,
.sidebar-link,
.badge,
.pill,
.meta-label,
.meta-value,
.kpi-label,
.kpi-value {
    overflow-wrap: normal;
    word-break: normal;
}

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding-left: 16px;
    padding-right: 16px;
}

/* =========================
   HEADER
========================= */

.site-header {
    position: static;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 14px rgba(14, 24, 43, .04);
}

:root[data-theme=dark] .site-header {
    background: rgba(20, 29, 49, .96);
}

.site-header .container {
    padding-left: 16px;
    padding-right: 16px;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 0;
    min-width: 0;
}

.header-inner > div {
    min-width: 0;
}

.brand {
    display: inline-block;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: .2px;
    color: var(--text);
}

.brand:hover {
    text-decoration: none;
}

.brand-subtitle {
    color: var(--muted);
    font-size: .95rem;
    margin-top: 4px;
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: none;
    min-width: 132px;
    white-space: nowrap;
    flex-shrink: 0;
}

.theme-toggle:hover {
    text-decoration: none;
    background: var(--surface-2);
}

/* =========================
   LAYOUT PRINCIPALE
========================= */

.page-shell {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 22px 0 40px;
    min-width: 0;
}

.page-shell > * {
    min-width: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* =========================
   MENU ORIZZONTALE
========================= */

.sidebar {
    padding: 16px 18px;
    align-self: stretch;
    position: static;
    min-width: 0;
    width: 100%;
    border-radius: 18px;
    background: var(--surface);
    overflow: visible;
}

.sidebar-title {
    font-size: .88rem;
    font-weight: 800;
    margin: 0 0 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: row;
    gap: 10px;
    min-width: 0;
    flex-wrap: wrap;
    align-items: center;
}

.sidebar-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    min-height: 44px;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-weight: 700;
    border: 1px solid var(--border);
    white-space: nowrap;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
    flex-shrink: 0;
}

.sidebar-link:hover {
    text-decoration: none;
    border-color: var(--primary);
    background: var(--surface-2);
    color: var(--primary);
}

.sidebar-link.active {
    background: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}

.sidebar-link.disabled {
    opacity: .7;
    cursor: default;
}

.sidebar-meta {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.sidebar-meta-row {
    margin-bottom: 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    min-width: 220px;
    flex: 1 1 240px;
}

.meta-label {
    display: block;
    color: var(--muted);
    font-size: .84rem;
    margin-bottom: 4px;
}

.meta-value {
    display: block;
    font-weight: 700;
    margin-top: 0;
}

/* =========================
   CONTENUTO
========================= */

.content-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    min-width: 0;
}

.content {
    min-width: 0;
    width: 100%;
}

.page-ad-sidebar {
    min-width: 0;
}

.page-ad-box {
    padding: 18px;
    position: static;
}

.page-ad-box .ad-box-label {
    margin-bottom: 12px;
}

.page-ad-box .ad-box-content {
    min-height: 280px;
}

.hero {
    padding: 30px;
    margin-bottom: 24px;
    min-width: 0;
    border-radius: 22px;
    background: var(--surface);
}

.hero h1 {
    margin: 0 0 10px;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    line-height: 1.15;
}

.hero p {
    margin: 0;
    color: var(--muted);
    max-width: 820px;
    font-size: 1.02rem;
}

.hero.hero-wide-media p,
.hero .hero-lead {
    max-width: none;
    padding: 5px 0;
}

.materia-image-box,
.home-image-box {
    margin-top: 22px;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.materia-cover {
    display: block;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: cover;
}

.home-cover {
    display: block;
    width: 100%;
    height: auto;
    max-height: 420px;
    object-fit: cover;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
    min-width: 0;
}

.tile,
.panel {
    padding: 22px;
    min-width: 0;
    border-radius: 20px;
}

.tile h2,
.panel h2,
.section-title {
    margin: 0 0 10px;
    font-size: 1.2rem;
}

.tile p,
.panel p {
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
    min-width: 0;
    align-items: center;
}

.btn,
button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 11px 16px;
    font-weight: 800;
    cursor: pointer;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
    max-width: 100%;
    min-height: 44px;
    width: auto;
    min-width: max-content;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: center;
}

.btn:hover,
button.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-contrast);
    box-shadow: none;
}

.btn-primary:hover {
    filter: brightness(.98);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

/* =========================
   LISTE
========================= */

.list {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 18px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    min-width: 0;
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

.list-item:hover {
    border-color: var(--border);
    box-shadow: var(--shadow);
}

.list-item > div {
    min-width: 0;
}

.list-item h3 {
    margin: 0 0 6px;
    font-size: 1.05rem;
}

.list-item p {
    margin: 0;
    color: var(--muted);
}

/* =========================
   KPI
========================= */

.kpis {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
    min-width: 0;
}

.kpi {
    min-width: 140px;
    padding: 16px 18px;
    border-radius: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.kpi-label {
    color: var(--muted);
    font-size: .86rem;
    white-space: nowrap;
}

.kpi-value {
    font-size: 1.2rem;
    font-weight: 800;
    margin-top: 4px;
    white-space: nowrap;
}

/* =========================
   QUIZ
========================= */

.quiz-header {
    padding: 20px 24px;
    margin-bottom: 18px;
    position: static;
    min-width: 0;
    border-radius: 20px;
    overflow: visible;
}

.quiz-header-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: start;
    min-width: 0;
}

.quiz-header-top > div {
    min-width: 0;
}

.progress-block {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-2);
    min-width: 0;
}

.progress-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    margin-bottom: 10px;
    min-width: 0;
    flex-wrap: wrap;
}

.progress-label-row > :first-child {
    min-width: 0;
    flex: 1 1 auto;
}

.progress-label-row > :last-child {
    flex: 0 0 auto;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
}

.progress-label-row span,
.progress-label-row strong,
.progress-label-row .badge,
.progress-label-row .progress-count {
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
    display: inline-block;
}

.progress-bar-track {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--success) 100%);
    transition: width .18s ease;
}

.question-card {
    padding: 22px;
    margin-bottom: 16px;
    min-width: 0;
    border-radius: 20px;
}

.question-topline {
    margin-bottom: 12px;
}

.question-title {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 16px;
}

.answers {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.answer-option {
    position: relative;
    display: block;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
    min-width: 0;
}

.answer-option:hover {
    border-color: var(--primary);
}

.answer-option input[type=radio] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.answer-text {
    display: block;
    padding: 14px 16px;
}

.answer-option input[type=radio]:checked + .answer-text {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: inset 0 0 0 2px var(--primary);
    font-weight: 700;
}

.result-ok {
    color: var(--success);
    font-weight: 800;
}

.result-ko {
    color: var(--danger);
    font-weight: 800;
}

.muted {
    color: var(--muted);
}

/* badge protetti da compressione */
.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: .82rem;
    font-weight: 800;
    background: var(--surface-2);
    border: 1px solid var(--border);
    max-width: 100%;
    white-space: nowrap;
}

/* =========================
   TABELLE
========================= */

.table-like {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 12px;
}

.table-like td,
.table-like th {
    text-align: left;
    vertical-align: top;
    padding: 14px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.table-like td:first-child,
.table-like th:first-child {
    border-left: 1px solid var(--border);
    border-radius: 14px 0 0 14px;
}

.table-like td:last-child,
.table-like th:last-child {
    border-right: 1px solid var(--border);
    border-radius: 0 14px 14px 0;
}

/* =========================
   FOOTER
========================= */

.site-footer {
    border-top: 1px solid var(--border);
    margin-top: 36px;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    padding-top: 20px;
    overflow: visible;
}

.site-footer .container {
    padding-left: 16px;
    padding-right: 16px;
}

.footer-inner {
    gap: 24px;
    padding-top: 0;
    padding-bottom: 24px;
    color: var(--muted);
    min-width: 0;
}

.footer-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
    min-width: 0;
    gap: 24px;
    align-items: start;
}

.footer-grid > div,
.footer-col {
    min-width: 0;
}

.footer-col > * {
    max-width: 100%;
}

.footer-col h3 {
    margin: 0 0 10px;
    color: var(--text);
}

.footer-col h4 {
    margin: 16px 0 8px;
    color: var(--text);
}

.footer-col p {
    margin: 0;
}

.footer-col hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.footer-links {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}

.footer-links li {
    margin: 0 0 8px;
}

.footer-note {
    color: var(--muted);
}

.footer-ad-box {
    margin-top: 18px;
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: none;
    min-width: 0;
}

.footer-ad-box .ad-box-label {
    font-size: .84rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 10px;
}

.footer-ad-box .ad-box-content {
    color: var(--text);
    font-size: .95rem;
    line-height: 1.5;
    min-width: 0;
    max-width: 100%;
}

.footer-ad-image,
.footer-ad-box img,
.footer-ad-box iframe,
.footer-ad-box ins,
.footer-ad-box .adsbygoogle {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
    border-radius: 12px;
}

/* =========================
   EXTRA
========================= */

.ad-box {
    margin-top: 18px;
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    background: var(--surface-2);
    min-width: 0;
}

.ad-box-label {
    font-size: .84rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 8px;
}

.ad-box-content {
    color: var(--text);
    font-size: .95rem;
    min-width: 0;
    max-width: 100%;
}

.adsbygoogle {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    min-width: 0;
}

.quiz-type-panel {
    margin-top: 20px;
}

.quiz-type-normal {
    border-top: 4px solid rgba(59,130,246,.35);
}

.quiz-type-advanced {
    border-top: 4px solid rgba(168,85,247,.35);
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: .875rem;
    font-weight: 700;
    border: 1px solid transparent;
    max-width: 100%;
    white-space: nowrap;
    flex-shrink: 0;
}

.pill-normal {
    background: rgba(59,130,246,.12);
    border-color: rgba(59,130,246,.28);
    color: #1d4ed8;
}

.pill-advanced {
    background: rgba(168,85,247,.12);
    border-color: rgba(168,85,247,.28);
    color: #7e22ce;
}

.header-side-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
}

.compact-kpis {
    margin-top: 16px;
}

.question-image-box,
.result-image-box {
    margin: 16px 0;
}

.question-image,
.result-image {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.result-image {
    max-width: 240px;
    margin-top: 10px;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.panel {
    margin-bottom: 20px;
}

/* =========================
   DESKTOP GRANDE
========================= */

@media (min-width: 1100px) {
    .content-area {
        grid-template-columns: minmax(0, 1fr) 300px;
    }

    .page-ad-sidebar {
        position: sticky;
        top: 20px;
    }
}

@media (max-width: 1099px) {
    .page-ad-box .ad-box-content {
        min-height: 160px;
    }
}

@media (prefers-color-scheme: dark) {
    .pill-normal {
        background: rgba(96,165,250,.18);
        border-color: rgba(96,165,250,.35);
        color: #bfdbfe;
    }

    .pill-advanced {
        background: rgba(192,132,252,.18);
        border-color: rgba(192,132,252,.35);
        color: #e9d5ff;
    }
}

[data-theme=dark] .pill-normal {
    background: rgba(96,165,250,.18);
    border-color: rgba(96,165,250,.35);
    color: #bfdbfe;
}

[data-theme=dark] .pill-advanced {
    background: rgba(192,132,252,.18);
    border-color: rgba(192,132,252,.35);
    color: #e9d5ff;
}

/* =========================
   DESKTOP GRANDE
========================= */

@media (min-width: 921px) {
    .sidebar-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: thin;
    }

    .sidebar-link {
        flex: 0 0 auto;
    }
}

/* =========================
   TABLET
========================= */

@media (max-width: 920px) {
    .page-shell {
        gap: 16px;
        padding: 18px 0 30px;
    }

    .sidebar {
        padding: 14px 16px;
    }

    .footer-grid {
        grid-template-columns: 1fr;
    }

    .header-inner {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .theme-toggle {
        min-width: 0;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    .sidebar-link {
        padding: 10px 14px;
    }

    .sidebar-meta {
        gap: 10px;
    }

    .sidebar-meta-row {
        min-width: 180px;
        flex: 1 1 180px;
    }

    .kpis {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .quiz-header-top,
    .progress-label-row,
    .section-head,
    .header-side-info {
        flex-wrap: wrap;
    }

    .footer-ad-box {
        margin-top: 16px;
    }
}

/* =========================
   MOBILE
========================= */

@media (max-width: 640px) {
    .container,
    .site-header .container,
    .site-footer .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    .header-inner {
        padding: 14px 0;
        gap: 12px;
    }

    .brand {
        font-size: 1.35rem;
    }

    .brand-subtitle {
        font-size: .88rem;
    }

    .theme-toggle {
        width: 100%;
        padding: 12px 14px;
    }

    .page-shell {
        gap: 16px;
        padding: 16px 0 26px;
    }

    .hero,
    .tile,
    .panel,
    .question-card,
    .quiz-header {
        padding: 18px;
    }

    .quiz-header-top,
    .list-item {
        display: block;
    }

    .list-item > div,
    .quiz-header-top > div,
    .header-inner > div,
    .footer-grid > div,
    .footer-col {
        width: 100%;
        min-width: 0;
    }

    .sidebar {
        padding: 12px;
        border-radius: 14px;
    }

    .sidebar-title {
        margin-bottom: 10px;
        font-size: .8rem;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .sidebar-link,
    .sidebar-link.disabled {
        text-align: center;
        width: 100%;
        white-space: normal;
        border-radius: 12px;
        padding: 11px 10px;
        min-height: 42px;
    }

    .sidebar-meta {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .sidebar-meta-row {
        min-width: 0;
        width: 100%;
        padding: 12px;
    }

    .hero h1 {
        font-size: 1.55rem;
        line-height: 1.2;
    }

    .tile h2,
    .panel h2,
    .section-title {
        font-size: 1.08rem;
    }

    .kpis {
        grid-template-columns: 1fr;
    }

    .kpi {
        min-width: 0;
        padding: 14px 16px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions .btn,
    .actions button.btn,
    .list-item .btn {
        width: 100%;
        min-width: 0;
    }

    .list-item {
        padding: 16px;
    }

    .badge {
        margin-top: 12px;
    }

    .quiz-header {
        margin-bottom: 14px;
    }

    .progress-block {
        padding: 14px;
    }

    .question-title {
        font-size: 1rem;
        line-height: 1.35;
    }

    .answer-text {
        padding: 13px 14px;
    }

    .table-like,
    .table-like thead,
    .table-like tbody,
    .table-like tr,
    .table-like th,
    .table-like td {
        display: block;
        width: 100%;
    }

    .table-like {
        border-spacing: 0;
    }

    .table-like thead {
        display: none;
    }

    .table-like tr {
        margin-bottom: 14px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 14px;
        overflow: hidden;
    }

    .table-like td,
    .table-like th {
        border: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0 !important;
        padding: 12px 14px;
        background: transparent;
    }

    .table-like td:last-child {
        border-bottom: 0;
    }

    .result-image {
        max-width: 100%;
    }

    .materia-cover,
    .home-cover {
        max-height: 240px;
    }

    .footer-inner {
        padding-bottom: 20px;
    }

    .footer-ad-box,
    .ad-box {
        padding: 14px;
    }

    .footer-col h3 {
        font-size: 1.05rem;
    }

    .footer-col h4 {
        font-size: .95rem;
    }
}