* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

body {
    font-family: "Poppins", "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #fdf6ff, #f3f8ff 50%, #fdf6ff 100%);
    color: #1e1e2f;
    min-height: 100vh;
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 48px;
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    z-index: 10;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(135deg, #ff9ecb, #92b7ff);
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    font-size: 24px;
    box-shadow: 0 12px 24px rgba(120, 90, 255, 0.25);
}

.brand-text h1 {
    font-size: 32px;
}

.brand-text p {
    font-size: 18px;
    color: #5d5d7a;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.lang-switch {
    display: flex;
    gap: 8px;
}

.lang-btn {
    border: none;
    background: #f1f3ff;
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.lang-btn.active,
.lang-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(120, 90, 255, 0.2);
}

.hero {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    align-items: center;
    gap: 48px;
    padding: 80px 48px 32px;
    position: relative;
}

.hero-content h2 {
    font-size: 56px;
    margin-bottom: 16px;
}

.hero-content p {
    font-size: 22px;
    color: #4a4a68;
    margin-bottom: 24px;
    max-width: 520px;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.cta {
    border: none;
    padding: 18px 28px;
    border-radius: 20px;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 16px 24px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cta.fixed {
    background: #ffd1dc;
}

.cta.variable {
    background: #cde7ff;
}

.cta:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 20px 28px rgba(0, 0, 0, 0.2);
}

.hero-art {
    position: relative;
    min-height: 260px;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(0px);
    opacity: 0.85;
}

.orb.pink {
    width: 200px;
    height: 200px;
    background: #ffb3d9;
    top: 0;
    left: 10%;
}

.orb.blue {
    width: 160px;
    height: 160px;
    background: #9ad0ff;
    right: 10%;
    bottom: 0;
}

.orb.yellow {
    width: 120px;
    height: 120px;
    background: #ffe4a8;
    bottom: 25%;
    left: 45%;
}

.calculator {
    padding: 24px 48px 60px;
    display: grid;
    gap: 24px;
}

.loan-card {
    background: white;
    border-radius: 24px;
    box-shadow: 0 18px 40px rgba(20, 20, 60, 0.1);
    overflow: hidden;
    transition: transform 0.2s ease;
}

.loan-card.open {
    transform: translateY(-6px);
}

.card-toggle {
    width: 100%;
    border: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(120deg, #ffd1dc, #cde7ff);
}

.card-toggle.variable {
    background: linear-gradient(120deg, #cde7ff, #d5ffd6);
}

.card-sub {
    font-size: 18px;
    font-weight: 400;
    color: #4a4a68;
}

.card-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease;
    background: #fff;
}

.loan-card.open .card-body {
    max-height: 2000px;
}

.loan-form {
    padding: 24px 28px 32px;
    display: grid;
    gap: 18px;
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.advanced-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-top: 12px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 16px;
}

.form-field input,
.form-field select {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid #e2e6f5;
    background: #fbfcff;
    font-size: 16px;
}

.form-section {
    display: grid;
    gap: 12px;
    padding: 12px 0;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.btn {
    border: none;
    padding: 14px 22px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn.primary {
    background: #5d5ff5;
    color: white;
    box-shadow: 0 10px 18px rgba(93, 95, 245, 0.3);
}

.btn.ghost {
    background: #f1f3ff;
    color: #5d5ff5;
}

.btn:hover {
    transform: translateY(-2px);
}

.results {
    padding: 32px 48px 60px;
    background: #f9fbff;
    border-top: 1px solid #eef1ff;
}

.results.hidden {
    display: none;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.results-block.hidden {
    display: none;
}

.section {
    margin-top: 56px;
    margin-bottom: 40px;
    padding-top: 40px;
    border-top: 2px solid rgba(120, 90, 255, 0.15);
}

.section:first-of-type {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.section h4 {
    font-size: 1.75rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 8px;
    letter-spacing: -0.3px;
}

.section-note {
    margin: 6px 0 20px;
    color: #6b6b8b;
    font-size: 18px;
}

.kpi-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.kpi-card {
    background: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.kpi-card.kpi-highlight {
    background: rgba(52, 152, 219, 0.08);
}

.kpi-card span {
    font-size: 16px;
    color: #6b6b8b;
}

.kpi-card strong {
    display: block;
    margin-top: 6px;
    font-size: 26px;
}

.insight-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    margin-top: 12px;
}

.insight-box {
    margin-top: 12px;
    background: linear-gradient(135deg, #f8faff 0%, #eef4ff 100%);
    border: 1px solid #dfe7ff;
    border-radius: 12px;
    padding: 12px 14px;
    color: #3b4b7a;
    font-size: 15px;
    line-height: 1.45;
}

.grid-2 {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}


.chart {
    background: white;
    border-radius: 20px;
    padding: 14px;
    min-height: 470px;
    height: 470px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
    isolation: isolate;
}

.chart-full {
    width: 100%;
    min-height: 640px;
    height: 640px;
    margin-bottom: 24px;
    overflow: hidden;
}

.chart.chart-full {
    padding-bottom: 36px;
}

/* Più spazio verticale per i plot affiancati della sezione MC */
#mcPlotHeatmap,
#mcPlotEuriborBox {
    min-height: 520px;
    height: 520px;
}

/* Allinea altezza dei due grafici principali MC (traiettorie EURIBOR e rata) */
#mcPlotEuriborFan,
#mcPlotRataFan {
    min-height: 760px;
    height: 760px;
}

.chart > .js-plotly-plot,
.chart .plot-container,
.chart .svg-container,
.chart .main-svg,
.chart .modebar-container {
    border-radius: inherit;
}

.chart > .js-plotly-plot,
.chart .plot-container,
.chart .svg-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Plotly typography boost (all charts) */
.js-plotly-plot .plotly .gtitle {
    font-size: 24px !important;
    font-weight: 700 !important;
}

.js-plotly-plot .plotly .xtitle,
.js-plotly-plot .plotly .ytitle {
    font-size: 18px !important;
    font-weight: 600 !important;
}

.js-plotly-plot .plotly .xtick text,
.js-plotly-plot .plotly .ytick text {
    font-size: 15px !important;
}

.js-plotly-plot .plotly .legend text,
.js-plotly-plot .plotly .legendtext {
    font-size: 15px !important;
}

.table-wrap {
    overflow-x: auto;
    background: white;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 18px;
}

th,
td {
    padding: 14px 16px;
    text-align: right;
    border-bottom: 1px solid #eef1ff;
}

th:first-child,
td:first-child {
    text-align: left;
}

.table-actions {
    margin: 12px 0;
    display: flex;
    justify-content: flex-end;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 48px;
    background: #1f2140;
    color: white;
}

.site-footer a {
    color: white;
    text-decoration: none;
}

.buymeacoffee {
    background: #ffdd57;
    color: #1f2140;
    padding: 10px 16px;
    border-radius: 12px;
    font-weight: 600;
}

.paypal-donate {
    background: #003087;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 12px;
    font-weight: 600;
    text-decoration: none;
    margin-left: 8px;
}

.hidden {
    display: none;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: grid;
    place-items: center;
    z-index: 9999;
}

.loading-card {
    background: white;
    padding: 24px 28px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(93, 95, 245, 0.2);
    text-align: center;
    width: min(420px, 90vw);
}

.loading-title {
    font-weight: 600;
    margin-bottom: 14px;
}

.loading-sub {
    margin-top: 10px;
    color: #6b6b8b;
    font-size: 14px;
}

.loading-bar {
    background: #eef1ff;
    border-radius: 999px;
    overflow: hidden;
    height: 12px;
}

.loading-fill {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, #ffb3d9, #9ad0ff, #ffe4a8);
    animation: loadingMove 1.2s ease-in-out infinite;
    border-radius: 999px;
}

@keyframes loadingMove {
    0% {
        transform: translateX(-60%);
    }
    50% {
        transform: translateX(80%);
    }
    100% {
        transform: translateX(-60%);
    }
}

@media (max-width: 768px) {
    .site-header {
        flex-direction: column;
        gap: 16px;
        padding: 18px 20px;
    }

    /* Push hero below the taller stacked sticky header */
    .hero {
        padding: 170px 20px 24px;
    }

    .hero-content h2 {
        font-size: 38px;
    }

    .hero-content p {
        font-size: 18px;
    }

    .calculator,
    .results {
        padding: 24px 16px 40px;
    }

    /* Reduce chart heights for mobile */
    .chart {
        height: 300px;
        min-height: 300px;
    }

    .chart-full {
        height: 360px;
        min-height: 360px;
    }

    /* MC charts */
    #mcPlotHeatmap,
    #mcPlotEuriborBox {
        height: 360px;
        min-height: 360px;
    }

    #mcPlotEuriborFan,
    #mcPlotRataFan {
        height: 400px;
        min-height: 400px;
    }

    /* Stack all side-by-side chart rows into a single column */
    .charts-top-wrapper,
    .chart-row-pair {
        flex-direction: column !important;
    }

    .charts-top-wrapper > .chart,
    .chart-row-pair > .chart {
        flex: none !important;
        width: 100% !important;
    }

    /* Force all grid-2 layouts to single column */
    .grid-2 {
        grid-template-columns: 1fr !important;
        display: grid !important;
    }

    .site-footer {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
}