/* =========================================================
   BASE & RESET
   ========================================================= */
html {
    font-size: 14px;
    scroll-behavior: smooth;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-text-size-adjust: 100%;
}

/* Focus ring coerente */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 .1rem #fff, 0 0 0 .25rem #258cfb;
}

/* Nascondi summary validi */
.validation-summary-valid {
    display: none;
}

/* Tap target più comodi */
.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
}

/* Spazi/typo mobile */
@media (max-width:575.98px) {
    h1 {
        font-size: clamp(1.25rem,4.5vw,1.6rem);
    }

    h2 {
        font-size: clamp(1.1rem,4vw,1.4rem);
    }

    h3 {
        font-size: clamp(1rem,3.8vw,1.2rem);
    }

    .container, .container-fluid {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* Riduzione motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* =========================================================
   TOKENS / VARIABILI
   ========================================================= */
:root {
    --pad: 16px;
    --radius: 14px;
    --shadow: 0 6px 16px rgba(0,0,0,.06);
    --sticky-h: 58px;
    /* Cookie banner */
    --cc-bg: #165e72;
    --cc-bg-contrast: #0e4857;
    --cc-text: #fff;
    --cc-link: #bde9f4;
    --cc-shadow: 0 12px 30px rgba(0,0,0,.22);
    /* Tema energetico */
    --en-A4: #0bb34b;
    --en-A3: #39c05a;
    --en-A2: #66cc69;
    --en-A1: #93d978;
    --en-B: #b7e07e;
    --en-C: #ffd85a;
    --en-D: #ffb33b;
    --en-E: #ff9030;
    --en-F: #ff6a29;
    --en-G: #e53935;
    --en-soft: #f7faf2;
    --en-text: #102016;
    --en-gradient: linear-gradient(90deg,#0bb34b 0%,#66cc69 25%,#ffd85a 50%,#ff9030 75%,#e53935 100%);
}

/* =========================================================
   COOKIE BANNER (CARD)
   ========================================================= */
#cookie-banner {
    background: linear-gradient(0deg,var(--cc-bg),var(--cc-bg-contrast));
}

    #cookie-banner.cc-card {
        position: fixed;
        right: 50%;
        transform: translateX(50%);
        bottom: 60px;
        z-index: 9999;
        max-width: 680px;
        width: min(680px,calc(100vw - 40px));
        color: var(--cc-text);
        border-radius: 14px;
        box-shadow: var(--cc-shadow);
        border: 1px solid rgba(255,255,255,.12);
    }

    #cookie-banner .cc-card__inner {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 14px;
        padding: 16px 18px;
    }

    #cookie-banner .cc-card__text {
        line-height: 1.45;
        font-size: .95rem;
    }

    #cookie-banner .cc-link {
        color: var(--cc-link);
        text-decoration: underline;
    }

    #cookie-banner .cc-card__actions {
        display: flex;
        gap: 8px;
        align-items: center;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    #cookie-banner .cc-btn {
        appearance: none;
        border: 0;
        border-radius: 10px;
        padding: 8px 12px;
        font-size: .9rem;
        cursor: pointer;
        transition: transform .05s, opacity .2s;
    }

        #cookie-banner .cc-btn:active {
            transform: translateY(1px);
        }

    #cookie-banner .cc-btn--primary {
        background: #fff;
        color: #0d3b46;
    }

    #cookie-banner .cc-btn--outline {
        background: transparent;
        color: #fff;
        border: 1px solid rgba(255,255,255,.6);
    }

    #cookie-banner .cc-btn--ghost {
        background: transparent;
        color: #fff;
        opacity: .85;
    }

@media (max-width:520px) {
    #cookie-banner .cc-card__inner {
        grid-template-columns: 1fr;
    }

    #cookie-banner .cc-card__actions {
        justify-content: stretch;
    }

    #cookie-banner .cc-btn {
        flex: 1 1 auto;
        text-align: center;
    }
}

/* =========================================================
   LAYOUT / SEZIONI / SIDE-NAV
   ========================================================= */
.ape-section {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid #e9edf2;
    padding: var(--pad);
    margin-bottom: 12px;
    text-align: center;
    padding-bottom: 4rem;
    /* >>> manteniamo la tua logica di altezza <<< */
    min-height: 100vh;
}

    .ape-section:last-of-type {
        min-height: calc(100vh - 200px);
    }

    .ape-section > h2 {
        position: relative;
        display: inline-block;
        padding-bottom: .25rem;
    }

        .ape-section > h2::after {
            content: "";
            display: block;
            height: 4px;
            border-radius: 999px;
            margin-top: .4rem;
            background: var(--en-gradient);
        }

/* Sticky bottom CTA */
.ape-stickybar {
    position: sticky;
    bottom: 0;
    z-index: 1030;
    padding: .5rem var(--pad);
    background: rgba(255,255,255,.86);
    backdrop-filter: blur(6px);
    box-shadow: 0 -4px 14px rgba(0,0,0,.06);
    padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
}

    .ape-stickybar .total {
        font-weight: 700;
        font-size: 1.05rem;
    }

/* ====== Side nav Dati Immobiliari (versione unica) ====== */
.ape-side-nav {
    position: sticky;
    top: 12px;
    align-self: flex-start;
    background: #165e72;
    color: #fff;
    border-radius: 12px;
    padding: 16px 14px;
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
}

    .ape-side-nav ol {
        list-style: none;
        margin: 0;
        padding: 0;
        counter-reset: step;
    }

    .ape-side-nav li {
        margin: 6px 0;
    }

    .ape-side-nav a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 12px;
        border-radius: 8px;
        text-decoration: none;
        color: #e9f6fb;
        opacity: .9;
        transition: background .2s, opacity .2s;
    }

        .ape-side-nav a:hover {
            opacity: 1;
            background: rgba(255,255,255,.06);
            color: white;
        }

        .ape-side-nav a.active {
            background: #fff;
            color: #0f4c64;
            font-weight: 700;
            opacity: 1;
            box-shadow: 0 2px 10px rgba(0,0,0,.06);
        }
    /* badge errori */
    .ape-side-nav .badge-error {
        display: inline-block;
        min-width: 22px;
        height: 22px;
        border-radius: 999px;
        padding: 0 6px;
        line-height: 22px;
        font-size: .75rem;
        font-weight: 700;
        background: #e03131;
        color: #fff;
    }

@media (max-width: 991.98px) {
    #ape-side-nav {
        display: none;
    }

    .ape-accordion {
        display: block;
        margin-bottom: .75rem;
    }
}

/* =========================================================
   COMPONENTI: CARDS / TOGGLE / VISURA / ERRORI
   ========================================================= */
/* Card di scelta */
.ape-card {
    height: 160px;
    width: 100%;
    border: 1px solid #dfe5ea;
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: box-shadow .2s, border-color .2s, transform .05s;
}

#grid-sopralluogo .ape-card, #grid-planimetria .ape-card {
    height: auto;
}

.ape-card:hover, .visura-price:hover {
    box-shadow: 0 6px 18px rgba(0,0,0,.06);
}

.ape-card:active {
    transform: scale(.98);
}

.ape-card-thumb {
    width: 72px;
    height: 56px;
    margin: 2px auto 8px;
    background: #f1f5f8 center no-repeat;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #4b5b66;
}

    .ape-card-thumb svg {
        width: 34px;
        height: 34px;
    }

.ape-card-title {
    font-size: .95rem;
    font-weight: 600;
    color: #123;
}

.ape-card-sub {
    font-size: .8rem;
    opacity: .7;
    margin-top: 2px;
}

/* Stato selezionato (tema energetico) */
.ape-card.selected {
    border: 2px solid transparent;
    background: linear-gradient(#fff,#fff) padding-box, var(--en-gradient) border-box;
    box-shadow: 0 0 0 3px rgba(11,179,75,.18);
}

    .ape-card.selected .ape-card-thumb {
        background: #eaf8ef;
        color: var(--en-A4);
    }

/* Toggle SI/NO */
.ape-toggle {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 10px;
}

    .ape-toggle input[type="radio"] {
        display: none;
    }

    .ape-toggle label {
        min-width: 86px;
        padding: 10px 16px;
        border: 2px solid #e2e6ea;
        border-radius: 10px;
        text-align: center;
        cursor: pointer;
        color: #6c757d;
        background: #fff;
        font-weight: 600;
        user-select: none;
        transition: border-color .15s, box-shadow .15s, color .15s, background .15s;
    }
    /* fallback box-shadow + color-mix override quando supportato */
    .ape-toggle input[type="radio"]:checked + label {
        border-color: var(--en-A4);
        box-shadow: 0 0 0 3px rgba(11,179,75,.22);
        color: #0f512b;
        background: #f7fff2;
    }

@supports (color: color-mix(in oklab, white, black)) {
    .ape-toggle input[type="radio"]:checked + label {
        box-shadow: 0 0 0 3px color-mix(in oklab, var(--en-A4) 30%, transparent);
    }
}

.ape-toggle input[type="radio"][value="false"]:checked + label {
    border-color: var(--en-E);
    box-shadow: 0 0 0 3px rgba(255,144,48,.22);
    color: #6b2b10;
    background: #fff3ec;
}

@supports (color: color-mix(in oklab, white, black)) {
    .ape-toggle input[type="radio"][value="false"]:checked + label {
        box-shadow: 0 0 0 3px color-mix(in oklab, var(--en-E) 26%, transparent);
    }
}

/* Opzione Visura */
.visura-box {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: .5rem;
    transition: border-color .2s, box-shadow .2s;
}

.visura-price {
    display: inline-block;
    width: 100%;
    padding: 12px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    text-align: center;
    background: #fff;
    cursor: pointer;
    transition: all .2s ease;
}

.visura-text {
    flex: 1;
    color: #555;
}

#VisuraCatastale:checked ~ .visura-box .visura-price,
#grid-sopralluogo .ape-card.selected, #grid-planimetria .ape-card.selected {
    box-shadow: 0 0 0 3px rgba(119,195,77,.2);
    color: #2d6a1f;
    background: linear-gradient(#f7fff2,#f7fff2) padding-box, var(--en-gradient) border-box;
    font-weight: 600;
}

/* Errori form leggibili */
.field-validation-error, .input-validation-error + .invalid-feedback {
    display: block;
    font-size: .9rem;
    margin-top: .25rem;
}

.input-validation-error, .is-invalid {
    border-color: #dc3545 !important;
    box-shadow: none !important;
}

/* Evidenziatore primo errore */
.field-flash {
    box-shadow: 0 0 0 .2rem rgba(220,53,69,.25);
    animation: fieldShake .25s linear 2;
}

@keyframes fieldShake {
    0%,100% {
        transform: translateX(0)
    }

    25% {
        transform: translateX(-3px)
    }

    50% {
        transform: translateX(3px)
    }

    75% {
        transform: translateX(-3px)
    }
}

/* =========================================================
   BADGE / PROGRESS ENERGETICI
   ========================================================= */
.badge-energy {
    --_fg: var(--en-A4);
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .6rem;
    border-radius: 999px;
    font-weight: 700;
    background: var(--en-soft);
    color: var(--_fg);
    border: 1px solid color-mix(in oklab, var(--_fg) 25%, transparent);
}

    .badge-energy.B {
        --_fg: var(--en-B);
    }

    .badge-energy.C {
        --_fg: var(--en-C);
    }

    .badge-energy.D {
        --_fg: var(--en-D);
    }

    .badge-energy.E {
        --_fg: var(--en-E);
    }

    .badge-energy.F {
        --_fg: var(--en-F);
    }

    .badge-energy.G {
        --_fg: var(--en-G);
    }

.energy-bar {
    height: 10px;
    border-radius: 999px;
    background: #edf1f5;
    overflow: hidden;
}

    .energy-bar > span {
        display: block;
        height: 100%;
        width: var(--value,50%);
        background: var(--en-gradient);
    }

/* =========================================================
   HEADER PUBBLICO (navbar + offcanvas)
   ========================================================= */
.ape-navbar {
    background: #fff;
    min-height: 64px;
}

.logo-rounded {
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

.brand-text {
    font-weight: 700;
    letter-spacing: .2px;
    color: #0f4c64;
}

/* Link con underline gradiente */
.navbar .nav-link.nav-energy {
    position: relative;
    font-weight: 600;
    color: #24323a;
    padding: .5rem .75rem;
}

    .navbar .nav-link.nav-energy:hover {
        color: #0f4c64;
    }

    .navbar .nav-link.nav-energy::after {
        content: "";
        position: absolute;
        left: .5rem;
        right: .5rem;
        bottom: .25rem;
        height: 3px;
        border-radius: 3px;
        background: transparent;
        transform: scaleX(0);
        transform-origin: left;
        transition: transform .25s, background .25s;
    }

    .navbar .nav-link.nav-energy:hover::after {
        background: var(--en-gradient);
        transform: scaleX(1);
    }

    .navbar .nav-link.nav-energy.active {
        color: #0f4c64;
    }

        .navbar .nav-link.nav-energy.active::after {
            background: var(--en-gradient);
            transform: scaleX(1);
        }

/* Toggler */
.navbar .navbar-toggler {
    border-color: #e4eaef;
}

    .navbar .navbar-toggler:focus {
        box-shadow: 0 0 0 .2rem rgba(11,179,75,.25);
    }

.navbar .navbar-toggler-icon {
    width: 1.5em;
    height: 1.5em;
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='rgba(36,50,58,0.9)' stroke-width='2' stroke-linecap='round' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    background-size: 100% 100%;
}

/* Dropdown */
.user-chip {
    font-weight: 600;
}

.dropdown-menu {
    border-radius: 12px;
    border: 1px solid #e9edf2;
}

.dropdown-item:hover {
    background: #f6fbf7;
}

/* CTA header */
.btn-energy {
    --_fg: var(--en-A4);
    color: var(--_fg);
    border: 1px solid currentColor;
    background: transparent;
    font-weight: 700;
}

.btn-primary {
    background: #165e72;
    color: white;
    border-color: #0e4857;
}

    .btn-primary:hover {
        background: #165e72;
        filter: opacity(90%);
        border-color: #0e4857;
    }

    .btn-energy.filled {
        background: var(--_fg);
        color: #fff;
        border-color: var(--_fg);
    }

    .btn-energy.gradient {
        color: #103520;
        border: 0;
        background: var(--en-gradient);
        box-shadow: 0 6px 20px rgba(11,179,75,.18);
    }

        .btn-energy.gradient:focus {
            box-shadow: 0 0 0 .25rem rgba(11,179,75,.25);
        }

/* Offcanvas pubblico */
.ape-offcanvas {
    width: min(88vw,380px);
    border-left: 1px solid #e9edf2;
}

    .ape-offcanvas .offcanvas-header {
        border-bottom: 1px solid #eef1f5;
    }

    .ape-offcanvas .offcanvas-title {
        font-weight: 700;
        color: #0f4c64;
    }

    .ape-offcanvas .nav-link {
        padding: .6rem 0;
        font-weight: 600;
        color: #24323a;
    }

        .ape-offcanvas .nav-link.nav-energy.active {
            color: #0f4c64;
        }

            .ape-offcanvas .nav-link.nav-energy.active::after {
                content: "";
                display: block;
                height: 3px;
                border-radius: 3px;
                margin-top: .25rem;
                background: var(--en-gradient);
            }

@media (max-width:575.98px) {
    .offcanvas-backdrop.show {
        backdrop-filter: blur(2px);
    }
}
/* visibilità offcanvas */
.offcanvas {
    visibility: hidden;
}

    .offcanvas.show {
        visibility: visible;
    }

/* =========================================================
   HEADER ADMIN (offcanvas)
   ========================================================= */
.admin-offcanvas {
    width: min(88vw,380px);
    border-left: 1px solid #e9edf2;
}

    .admin-offcanvas .offcanvas-header {
        border-bottom: 1px solid #eef1f5;
    }

    .admin-offcanvas .nav-link {
        font-weight: 600;
        color: #24323a;
        padding: .6rem 0;
    }

        .admin-offcanvas .nav-link.active {
            color: #0f4c64;
        }

            .admin-offcanvas .nav-link.active::after {
                content: "";
                display: block;
                height: 3px;
                border-radius: 3px;
                margin-top: .25rem;
                background: linear-gradient(90deg,#0bb34b,#ffd85a,#e53935);
            }

/* --- RESET IMMAGINI / SVG --- */
img {
    max-width: 100%;
    height: auto;
}

svg {
    display: block;
}

a {
    color: #0e4857;
}

a:hover {
    color: #165e72;
}

/* Logo header: dimensione fissa */
.navbar-brand img, .logo-rounded {
    height: 44px;
    width: auto;
}

/* Hero & feature */
.hero-energy {
    background: radial-gradient(1200px 300px at 50% -50px, rgba(11,179,75,.12), transparent 60%), #fff;
    padding-top: 3rem;
    padding-bottom: 3rem;
}

.feature-ico {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0,0,0,.06);
    color: #165e72;
}

    .feature-ico svg {
        width: 30px;
        height: 30px;
    }

.bg-soft-a {
    background: #f1fbf5;
}

.step-dot {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1fbf5;
    color: #0f512b;
    font-weight: 800;
    border: 1px solid #dff1e6;
}

.energy-card .card-body, .energy-feature.card .card-body {
    padding: 1.25rem;
}

/* Container widths (ripristino bootstrap-like) */
.container {
    width: 100%;
}

@media (min-width:576px) {
    .container {
        max-width: 540px;
    }
}

@media (min-width:768px) {
    .container {
        max-width: 720px;
    }
}

@media (min-width:992px) {
    .container {
        max-width: 960px;
    }
}

@media (min-width:1200px) {
    .container {
        max-width: 1140px;
    }
}

@media (min-width:1400px) {
    .container {
        max-width: 1320px;
    }
}

/* ===== Footer a tema “classi energetiche” ===== */
.footer-energy {
    --bg1: #165e72;
    --bg2: #0e4857;
    --ring: rgba(255,255,255,.12);
    background: linear-gradient(0deg,var(--bg1),var(--bg2));
    border-top: 1px solid var(--ring);
    position: relative;
    isolation: isolate;
}

    .footer-energy::before {
        content: "";
        position: absolute;
        inset: 0 auto auto 0;
        height: 4px;
        width: 100%;
        background: linear-gradient(90deg,#0bb34b,#66cc69,#ffd85a,#ff9030,#e53935);
        opacity: .9;
    }

    .footer-energy .underline {
        text-decoration: underline;
        text-underline-offset: 2px;
    }

        .footer-energy .underline:hover {
            text-decoration-thickness: 2px;
        }

    .footer-energy .btn {
        border-radius: 12px;
        font-weight: 700;
    }

    .footer-energy .btn-outline-light {
        border-color: rgba(255,255,255,.6);
    }

    .footer-energy .ls-05 {
        letter-spacing: .5px;
    }

.footer-contacts a {
    color: #fff;
    opacity: .95;
}

    .footer-contacts a:hover {
        opacity: 1;
    }

@media (max-width:575.98px) {
    .footer-energy .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

.footer-energy a:focus, .footer-energy .btn:focus {
    outline: none;
    box-shadow: 0 0 0 .15rem #fff, 0 0 0 .35rem rgba(11,179,75,.35);
}

/* ===== Radio-card per APE digitale/cartaceo ===== */
.btn-check + label.option-card {
    border: 1px solid #e5e9ef;
    border-radius: 12px;
    padding: .95rem 1rem;
    background: #fff;
    transition: border-color .2s, box-shadow .2s, transform .03s;
    display: block;
}

    .btn-check + label.option-card:hover {
        box-shadow: 0 4px 14px rgba(0,0,0,.06);
    }

.btn-check:active + label.option-card {
    transform: scale(.99);
}
/* Stato selezionato: gradient ring */
.btn-check:checked + label.option-card {
    border-color: transparent;
    background: linear-gradient(#f7fff2,#f7fff2) padding-box, var(--en-gradient) border-box;
    border: 2px solid transparent;
    box-shadow: 0 0 0 3px rgba(11,179,75,.18);
}
/* Badge prezzo dentro alle card */
label.option-card .price-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    padding: .35rem .6rem;
    border-radius: 999px;
    background: #f7f9fc;
    border: 1px solid #e5e9ef;
    font-weight: 700;
    color: #334;
}

label.option-card .row {
    align-items: center;
}

/* Sezione spedizione: cornice leggera */
#section-sped {
    border: 1px dashed #e5e9ef;
    border-radius: 12px;
    padding: .75rem;
    background: #fcfdfd;
}

/* Griglie custom in errore: no outline layout-shift */
#grid-tecnica.is-invalid, #grid-risc.is-invalid, #grid-raff.is-invalid {
    border-radius: 12px;
    padding: 6px;
    outline: 0;
    box-shadow: inset 0 0 0 2px rgba(229,57,53,.35), 0 0 0 3px rgba(229,57,53,.08);
}
