/* ============================================================
   Bellina — Portale San Bellino AI
   Palette istituzionale + AGID WCAG 2.1 AA
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Titillium+Web:wght@300;400;600;700&display=swap');

/* -------- Custom properties -------- */
:root {
    --c-arancione:     #D94D1A;
    --c-arancione-d:   #B83810;
    --c-arancione-l:   #E86B3D;
    --c-blu:           #2E4D9E;
    --c-blu-d:         #1F3A7A;
    --c-blu-l:         #4169E1;
    --c-oro:           #FDB913;

    --c-bg:            #F5F6FA;
    --c-surface:       #FFFFFF;
    --c-border:        #D8DCE6;
    --c-text:          #1A1A2E;
    --c-text-light:    #5A5F7A;
    --c-text-muted:    #8A8FA8;

    --c-success:       #1D7A4F;
    --c-success-bg:    #E8F5EE;
    --c-warning:       #7A5C00;
    --c-warning-bg:    #FFF8E1;
    --c-error:         #A01F2E;
    --c-error-bg:      #FDECEA;
    --c-info:          #1A4A7A;
    --c-info-bg:       #E8F0FC;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
    --shadow-md:  0 4px 12px rgba(0,0,0,.10);
    --shadow-lg:  0 8px 24px rgba(0,0,0,.12);
    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --radius-xl:  24px;
}

/* -------- Reset & base -------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; height: 100%; }

body {
    margin: 0;
    font-family: 'Titillium Web', 'Roboto', sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--c-text);
    background-color: var(--c-bg);
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

/* Skip link AGID 2.4.1 */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--c-arancione);
    color: #fff;
    padding: .5rem 1rem;
    font-weight: 600;
    z-index: 9999;
    border-radius: 0 0 var(--radius-sm) 0;
    transition: top .2s;
}
.skip-link:focus { top: 0; }

/* -------- Navbar -------- */
.bellina-navbar {
    background: var(--c-arancione);
    box-shadow: var(--shadow-md);
    padding: .75rem 0;
}

.bellina-navbar .navbar-brand {
    color: #fff !important;
    font-weight: 700;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    text-decoration: none;
}

.bellina-navbar .brand-icon {
    background: rgba(255,255,255,.2);
    border-radius: var(--radius-sm);
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .9rem;
}

.bellina-navbar .navbar-toggler {
    border-color: rgba(255,255,255,.5);
    color: #fff;
}
.bellina-navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(255,255,255,0.9)' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

.bellina-navbar .nav-link {
    color: rgba(255,255,255,.88) !important;
    font-weight: 600;
    padding: .4rem .75rem !important;
    border-radius: var(--radius-sm);
    transition: background .15s, color .15s;
}
.bellina-navbar .nav-link:hover,
.bellina-navbar .nav-link:focus { background: rgba(255,255,255,.15); color: #fff !important; }
.bellina-navbar .nav-link.active { background: rgba(255,255,255,.22); color: #fff !important; }

.user-badge {
    display: flex; align-items: center; gap: .5rem;
    color: rgba(255,255,255,.9);
    font-size: .9rem; font-weight: 600;
}
.user-badge .avatar {
    width: 32px; height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8rem; color: #fff;
}

/* -------- Ruolo badge in navbar -------- */
.ruolo-pill {
    font-size: .7rem;
    font-weight: 700;
    padding: .15rem .5rem;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.ruolo-pill.cittadino { background: rgba(255,255,255,.2); color: #fff; }
.ruolo-pill.pa        { background: var(--c-oro); color: #333; }
.ruolo-pill.admin     { background: var(--c-blu-d); color: #fff; }

/* -------- Bottoni -------- */
.btn-bellina {
    display: inline-flex; align-items: center; gap: .4rem;
    font-family: 'Titillium Web', sans-serif;
    font-weight: 600; font-size: .9rem;
    padding: .55rem 1.25rem;
    border-radius: var(--radius-xl);
    border: 2px solid transparent;
    cursor: pointer; text-decoration: none;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
    line-height: 1.4;
}
.btn-bellina:focus-visible { outline: 3px solid var(--c-oro); outline-offset: 2px; }
.btn-bellina:active { transform: translateY(1px); }

.btn-primary   { background: var(--c-arancione);   color: #fff; border-color: var(--c-arancione); }
.btn-primary:hover  { background: var(--c-arancione-d); border-color: var(--c-arancione-d); box-shadow: 0 4px 12px rgba(217,77,26,.35); color:#fff; }

.btn-secondary { background: #fff; color: var(--c-arancione); border-color: var(--c-arancione); }
.btn-secondary:hover { background: var(--c-arancione); color: #fff; }

.btn-blu       { background: var(--c-blu); color: #fff; border-color: var(--c-blu); }
.btn-blu:hover { background: var(--c-blu-d); border-color: var(--c-blu-d); color:#fff; }

.btn-danger    { background: var(--c-error-bg); color: var(--c-error); border-color: var(--c-error); }
.btn-danger:hover { background: var(--c-error); color: #fff; }

.btn-sm { font-size: .8rem; padding: .35rem .85rem; }
.btn-xs { font-size: .75rem; padding: .2rem .6rem; }
.w-100  { width: 100%; justify-content: center; }

/* -------- Cards -------- */
.bellina-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}
.bellina-card-hover { transition: box-shadow .2s, transform .2s; }
.bellina-card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* -------- Form -------- */
.form-group { margin-bottom: 1.1rem; }
.form-label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    color: var(--c-text);
    margin-bottom: .35rem;
}
.form-input,
.form-select,
.form-textarea {
    display: block; width: 100%;
    padding: .6rem .9rem;
    font-family: 'Titillium Web', sans-serif;
    font-size: 1rem; color: var(--c-text);
    background: var(--c-surface);
    border: 2px solid var(--c-border);
    border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--c-arancione);
    box-shadow: 0 0 0 3px rgba(217,77,26,.15);
    outline: none;
}
.form-input[aria-invalid="true"],
.form-select[aria-invalid="true"] { border-color: var(--c-error); }
.form-textarea { min-height: 120px; resize: vertical; }

/* -------- Alert -------- */
.bellina-alert {
    display: flex; align-items: flex-start; gap: .6rem;
    padding: .85rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .9rem; font-weight: 600;
    margin-bottom: 1rem;
}
.alert-success { background: var(--c-success-bg); color: var(--c-success); border-left: 4px solid var(--c-success); }
.alert-error   { background: var(--c-error-bg);   color: var(--c-error);   border-left: 4px solid var(--c-error); }
.alert-warning { background: var(--c-warning-bg); color: var(--c-warning); border-left: 4px solid var(--c-oro); }
.alert-info    { background: var(--c-info-bg);    color: var(--c-info);    border-left: 4px solid var(--c-blu); }

/* -------- Pagina auth (login/register) -------- */
.auth-page {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--c-arancione) 0%, var(--c-blu) 100%);
    padding: 1.5rem;
}
.auth-box {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%; max-width: 420px;
}
.auth-logo {
    display: flex; align-items: center; gap: .75rem;
    margin-bottom: 1.5rem;
}
.auth-logo .logo-icon {
    width: 48px; height: 48px;
    background: var(--c-arancione);
    color: #fff; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem;
}
.auth-logo .logo-name { font-size: 1.2rem; font-weight: 700; color: var(--c-text); }
.auth-box h1 { font-size: 1.4rem; margin-bottom: .3rem; }
.auth-box .subtitle { color: var(--c-text-light); font-size: .9rem; margin-bottom: 1.5rem; }

/* -------- Hero homepage -------- */
.bellina-hero {
    background: linear-gradient(120deg, var(--c-arancione) 0%, var(--c-arancione-d) 100%);
    color: #fff;
    padding: 3.5rem 0 3rem;
    text-align: center;
}
.bellina-hero h1 { font-size: 2rem; font-weight: 700; margin-bottom: .5rem; }
.bellina-hero p  { font-size: 1.1rem; opacity: .9; margin-bottom: 0; }

/* -------- Griglia bot -------- */
.bot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    padding: 2.5rem 0;
}
.bot-card {
    background: var(--c-surface);
    border: 2px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.5rem;
    text-decoration: none; color: var(--c-text);
    display: flex; flex-direction: column; gap: .75rem;
    transition: border-color .2s, box-shadow .2s, transform .2s;
    cursor: pointer;
}
.bot-card:hover { border-color: var(--c-arancione); box-shadow: 0 6px 20px rgba(217,77,26,.15); transform: translateY(-3px); color: var(--c-text); }
.bot-card:focus-visible { outline: 3px solid var(--c-arancione); outline-offset: 2px; }
.bot-card--disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.bot-icon {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, var(--c-arancione-l), var(--c-arancione));
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.4rem;
}
.bot-icon.blu { background: linear-gradient(135deg, var(--c-blu-l), var(--c-blu)); }
.bot-name { font-size: 1rem; font-weight: 700; margin: 0; }
.bot-desc { font-size: .88rem; color: var(--c-text-light); margin: 0; line-height: 1.5; }
.bot-badge {
    font-size: .72rem; font-weight: 700;
    padding: .2rem .6rem;
    border-radius: 99px;
    background: var(--c-info-bg); color: var(--c-blu);
    align-self: flex-start;
    text-transform: uppercase; letter-spacing: .04em;
}
.bot-badge.rag { background: #EEF2FF; color: var(--c-blu-d); }

/* -------- Tabelle -------- */
.bellina-table-wrap { overflow-x: auto; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.bellina-table {
    width: 100%; border-collapse: collapse;
    font-size: .9rem; background: var(--c-surface);
}
.bellina-table thead th {
    background: var(--c-arancione);
    color: #fff; font-weight: 700;
    padding: .75rem 1rem;
    text-align: left; white-space: nowrap;
}
.bellina-table thead th:first-child { border-radius: var(--radius-md) 0 0 0; }
.bellina-table thead th:last-child  { border-radius: 0 var(--radius-md) 0 0; }
.bellina-table tbody tr { border-bottom: 1px solid var(--c-border); }
.bellina-table tbody tr:hover { background: #FFF4F0; }
.bellina-table td { padding: .7rem 1rem; vertical-align: middle; }

/* -------- Badge permessi -------- */
.perm-badge {
    display: inline-block;
    font-size: .75rem; font-weight: 700;
    padding: .2rem .65rem; border-radius: 99px;
    text-transform: uppercase; letter-spacing: .04em;
}
.perm-1 { background: #E8F5EE; color: #1D7A4F; }        /* cittadino */
.perm-2 { background: #FFF8E1; color: #7A5C00; }        /* PA */
.perm-3 { background: #EEF2FF; color: var(--c-blu-d); } /* admin comune */
.perm-4 { background: #1F3A7A; color: #fff; }           /* admin meeple */

/* -------- Barra crediti -------- */
.crediti-bar-wrap { display: flex; flex-direction: column; gap: .15rem; }
.crediti-bar-label {
    display: flex; justify-content: space-between;
    font-size: .78rem; font-weight: 600; color: var(--c-text-light);
}
.crediti-bar {
    height: 8px; background: var(--c-border);
    border-radius: 99px; overflow: hidden;
}
.crediti-bar-fill {
    height: 100%; border-radius: 99px;
    background: var(--c-success);
    transition: width .4s ease;
}
.crediti-bar-fill.warning { background: var(--c-oro); }
.crediti-bar-fill.danger  { background: var(--c-error); }

/* -------- Page heading -------- */
.page-heading {
    display: flex; align-items: flex-start; justify-content: space-between;
    flex-wrap: wrap; gap: 1rem;
    padding: 2rem 0 1.25rem;
    border-bottom: 2px solid var(--c-border);
    margin-bottom: 1.75rem;
}
.page-heading h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-heading p  { margin: .25rem 0 0; color: var(--c-text-light); font-size: .9rem; }

/* -------- Footer -------- */
.bellina-footer {
    background: var(--c-text);
    color: rgba(255,255,255,.75);
    padding: 2rem 0;
    margin-top: 4rem;
    font-size: .85rem;
}
.bellina-footer a { color: var(--c-arancione-l); }
.bellina-footer .footer-brand { font-weight: 700; font-size: 1rem; color: #fff; margin-bottom: .25rem; }

/* -------- Back to top -------- */
#backToTop {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    width: 44px; height: 44px;
    background: var(--c-arancione); color: #fff;
    border: none; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-md);
    font-size: 1rem; z-index: 999;
    transition: opacity .2s, transform .2s;
}
#backToTop:hover { background: var(--c-arancione-d); transform: translateY(-2px); }
#backToTop:focus-visible { outline: 3px solid var(--c-oro); }

/* -------- Modali -------- */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 1050;
    align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%; max-width: 440px;
    box-shadow: var(--shadow-lg);
}
.modal-box h2 { font-size: 1.1rem; margin: 0 0 1.25rem; }

/* -------- Utility -------- */
.text-muted  { color: var(--c-text-muted) !important; }
.text-sm     { font-size: .85rem; }
.gap-sm      { gap: .5rem; }
.gap-md      { gap: 1rem; }
.d-flex      { display: flex; }
.flex-wrap   { flex-wrap: wrap; }
.align-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.mt-sm { margin-top: .5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 2rem; }
.mb-md { margin-bottom: 1rem; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); border: 0;
}

/* -------- Responsive -------- */
@media (max-width: 768px) {
    .bellina-hero h1 { font-size: 1.5rem; }
    .bot-grid { grid-template-columns: 1fr; }
    .page-heading { flex-direction: column; }
    .auth-box { padding: 2rem 1.25rem; }
    .bellina-table thead { display: none; }
    .bellina-table td { display: block; padding: .4rem 1rem; }
    .bellina-table td::before {
        content: attr(data-label) ': ';
        font-weight: 700; color: var(--c-text-light);
    }
}

/* ============================================================
   Barra sostenibilità energetica — comune a tutti i bot
   ============================================================ */
#energy-bar {
    display: none;
    align-items: center;
    gap: .5rem;
    padding: .35rem 1rem;
    background: #f0faf0;
    border-top: 1px solid #c8e6c8;
    font-size: .78rem;
    color: #2e5e2e;
    position: relative;
}
#energy-bar-text { flex: 1; font-weight: 500; }
.energy-info-btn {
    background: none;
    border: 1px solid #a5c8a5;
    border-radius: 50%;
    width: 1.2rem;
    height: 1.2rem;
    font-size: .7rem;
    cursor: pointer;
    color: #2e5e2e;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.energy-info-btn:hover { background: #e0f2e0; }
#energy-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    right: 1rem;
    min-width: 220px;
    max-width: 300px;
    background: #1a2e1a;
    color: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    padding: .75rem;
    font-size: .78rem;
    line-height: 1.6;
    z-index: 100;
}
#energy-tooltip strong { display: block; margin-bottom: .4rem; }
.energia-tip-row {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .1rem 0;
}
.energia-tip-row span:first-child { font-size: .9rem; flex-shrink: 0; }
.energia-tip-row span:nth-child(2) { flex: 1; opacity: .85; }
.energia-tip-row span:last-child { font-weight: 700; }
