/* style.css */
:root {
    --bg-gradient: linear-gradient(135deg, #e0f2fe 0%, #fbcfe8 50%, #e0e7ff 100%);
    --glass-bg: rgba(255, 255, 255, 0.42);
    --glass-border: rgba(255, 255, 255, 0.55);
    --glass-shadow: 0 10px 40px 0 rgba(15, 23, 42, 0.03);
    --glass-blur: blur(24px);
    --inner-card-bg: rgba(255, 255, 255, 0.25);
    --inner-card-border: rgba(255, 255, 255, 0.45);
    --chat-received-bg: rgba(255, 255, 255, 0.65);
    --chat-sent-bg: rgba(2, 132, 199, 0.1);
    --chat-sent-border: rgba(2, 132, 199, 0.2);
    --accent-blue: #0284c7;
    --accent-blue-hover: #0369a1;
    --accent-red: #ef4444;
    --accent-red-glow: rgba(239, 68, 68, 0.2);
    --accent-green: #22c55e;
    --text-main: #0f172a;
    --text-muted: #475569;
    --text-light: #64748b;
    --radius-premium: 24px;
    --radius-inner: 16px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --island-gap: 16px;
}

/* --- RESET UTENTE --- */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    -webkit-font-smoothing: antialiased; 
}
body, html { 
    height: 100%; 
    font-family: var(--font-family); 
    background: var(--bg-gradient); 
    color: var(--text-main); 
    overflow: hidden; 
    position: relative; 
}

/* --- SFERE DI SFONDO --- */
.blur-sphere { 
    position: absolute; 
    border-radius: 50%; 
    filter: blur(100px); 
    z-index: 0; 
    pointer-events: none; 
    opacity: 0.55; 
}
.sphere-1 { top: 15%; left: 5%; width: 380px; height: 380px; background: rgba(239, 68, 68, 0.28); }
.sphere-2 { bottom: 10%; right: 10%; width: 450px; height: 450px; background: rgba(56, 189, 248, 0.32); }

/* --- STRUTTURA GENERALE CONTAINER --- */
.app-container { 
    position: relative; 
    z-index: 1; 
    height: 100vh; 
    padding: var(--island-gap); 
    display: flex; 
    flex-direction: column; 
    gap: var(--island-gap); 
}
.app-header-island, .app-sidebar-island, .app-content-island, .app-footer-island { 
    background: var(--glass-bg); 
    backdrop-filter: var(--glass-blur); 
    border: 1px solid var(--glass-border); 
    border-radius: var(--radius-premium); 
    box-shadow: var(--glass-shadow); 
}

/* --- HEADER ISLAND --- */
.app-header-island { 
    height: 75px; 
    min-height: 75px; 
    display: flex; 
    align-items: center; 
    padding: 0 32px; 
}
.header-left-side { 
    display: flex; 
    align-items: center; 
    gap: 20px; 
    width: 100%; 
} 
.logo-title { 
    font-size: 1.4rem; 
    font-weight: 300; 
    letter-spacing: 2px; 
    color: var(--text-main); 
    white-space: nowrap; 
}
.logo-title span { 
    color: var(--accent-red); 
    font-weight: 700; 
}

.ethereal-search-icon { 
    width: 24px; 
    height: 24px; 
    min-width: 24px; 
    min-height: 24px; 
    border: 2px solid var(--accent-blue); 
    border-radius: 50%; 
    position: relative; 
    transform: rotate(-45deg); 
    opacity: 0.85; 
    display: inline-block; 
    box-sizing: border-box; 
}
.ethereal-search-icon::after { 
    content: ''; 
    position: absolute; 
    width: 2px; 
    height: 11px; 
    background-color: var(--accent-red); 
    bottom: -10px; 
    left: 9px; 
    border-radius: 2px; 
}

/* CHIP RIEPILOGO */
.header-summary { 
    display: flex; 
    gap: 8px; 
    align-items: center; 
    overflow-x: auto; 
    padding-left: 20px; 
    border-left: 1px solid rgba(0,0,0,0.08); 
    width: 100%; 
    height: 40px; 
}
.header-summary::-webkit-scrollbar { height: 0px; } 

.summary-chip { 
    padding: 6px 14px; 
    border-radius: 100px; 
    font-size: 0.68rem; 
    font-weight: 600; 
    letter-spacing: 0.8px; 
    white-space: nowrap; 
    animation: fadeInBubble 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; 
}
.blue-chip { background: rgba(2, 132, 199, 0.07); color: var(--accent-blue); border: 1px solid rgba(2, 132, 199, 0.16); }
.red-chip { background: rgba(239, 68, 68, 0.05); color: var(--accent-red); border: 1px solid rgba(239, 68, 68, 0.12); }

/* --- CORPO AFFIANCAMENTO --- */
.app-body-row { 
    flex: 1; 
    display: flex; 
    gap: var(--island-gap); 
    overflow: hidden; 
}

/* --- CHAT SIDEBAR --- */
.chat-sidebar { 
    width: 350px; 
    min-width: 350px; 
    padding: 24px 20px; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
}
.chat-sidebar-header { 
    padding-bottom: 16px; 
    margin-bottom: 16px; 
    border-bottom: 1px solid rgba(255, 255, 255, 0.2); 
}
.active-chat-user { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}
.active-chat-status { 
    display: flex; 
    flex-direction: column; 
}
.chat-name { 
    font-weight: 600; 
    font-size: 1rem; 
    color: var(--text-main); 
}
.status-indicator { 
    font-size: 0.75rem; 
    color: var(--accent-green); 
    font-weight: 500; 
    margin-top: 2px; 
}
.status-indicator.writing { color: var(--accent-blue); }

.chat-avatar { 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 600; 
    font-size: 0.9rem; 
}
.chat-avatar.red-avatar { 
    background: rgba(239, 68, 68, 0.1); 
    color: var(--accent-red); 
    border: 1px solid rgba(239, 68, 68, 0.15); 
}

.chat-messages-container { 
    flex: 1; 
    overflow-y: auto; 
    padding-right: 4px; 
    display: flex; 
    flex-direction: column; 
    gap: 14px; 
    margin-bottom: 12px; 
}
.chat-messages-container::-webkit-scrollbar { width: 4px; }
.chat-messages-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.04); border-radius: 10px; }

.msg-row { 
    display: flex; 
    width: 100%; 
    animation: fadeInBubble 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; 
}
.msg-received { justify-content: flex-start; }
.msg-sent { justify-content: flex-end; }

.msg-bubble { 
    max-width: 85%; 
    padding: 12px 14px; 
    position: relative; 
}
.msg-received .msg-bubble { 
    background: var(--chat-received-bg); 
    border: 1px solid rgba(255, 255, 255, 0.4); 
    border-radius: 4px 16px 16px 16px; 
    color: var(--text-main); 
}
.msg-sent .msg-bubble { 
    background: var(--chat-sent-bg); 
    border: 1px solid var(--chat-sent-border); 
    border-radius: 16px 4px 16px 16px; 
    color: var(--text-main); 
}
.msg-time { 
    display: block; 
    font-size: 0.7rem; 
    color: var(--text-light); 
    text-align: right; 
    margin-top: 4px; 
}

.typing-bubble { 
    padding: 14px 20px !important; 
    display: flex; 
    align-items: center; 
    min-width: 65px; 
}
.typing-dots { 
    display: flex; 
    align-items: center; 
    gap: 5px; 
}
.typing-dots span { 
    width: 7px; 
    height: 7px; 
    background-color: var(--text-muted); 
    border-radius: 50%; 
    display: inline-block; 
    animation: bounceDots 1.4s infinite ease-in-out both; 
    opacity: 0.5; 
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounceDots { 
    0%, 80%, 100% { transform: scale(0); } 
    40% { transform: scale(1.0); } 
}
.hidden { display: none !important; }

.chat-external-action-container { 
    display: flex; 
    justify-content: flex-start; 
    padding-left: 8px; 
    margin-top: 2px; 
    flex-wrap: wrap;
}
.choice-gap { gap: 10px; }

.btn-chat-action { 
    background: var(--accent-blue); 
    color: white; 
    border: none; 
    padding: 11px 24px; 
    border-radius: 100px; 
    font-family: var(--font-family); 
    font-size: 0.85rem; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.2s ease; 
}
.btn-chat-action:hover { 
    background: var(--accent-blue-hover); 
    transform: translateY(-1px); 
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.2); 
}
.btn-choice-no { 
    background: rgba(239, 68, 68, 0.06); 
    border: 1px solid rgba(239, 68, 68, 0.2); 
    color: var(--accent-red); 
}
.btn-choice-no:hover { 
    background: var(--accent-red); 
    color: white; 
    border-color: var(--accent-red); 
    box-shadow: 0 4px 12px var(--accent-red-glow); 
}

/* WRAPPER COMPONENTE INPUT */
.input-container, .chat-input-wrapper { 
    display: flex; 
    gap: 8px; 
    align-items: center; 
    background: rgba(255, 255, 255, 0.4); 
    border: 1px solid rgba(255, 255, 255, 0.5); 
    padding: 6px 6px 6px 14px; 
    border-radius: 100px; 
}
.chat-input-field { 
    flex: 1; 
    background: transparent; 
    border: none; 
    outline: none; 
    font-family: var(--font-family); 
    font-size: 0.9rem; 
    color: var(--text-main); 
}

.chat-input-field::-webkit-outer-spin-button, 
.chat-input-field::-webkit-inner-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
.chat-input-field[type=number] { 
    -moz-appearance: textfield; 
}

/* PULSANTE INVIO */
.chat-send-btn { 
    width: 34px; 
    height: 34px; 
    min-width: 34px;
    min-height: 34px;
    border-radius: 50%; 
    background: var(--accent-blue); 
    color: white; 
    border: none; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    transition: transform 0.2s;
}
.chat-send-btn:hover { transform: scale(1.05); }
.chat-send-btn svg { display: block; width: 16px; height: 16px; color: white; fill: currentColor; }

/* GRUPPO BOTTONI FINALI SIDEBAR */
.chat-final-buttons-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding: 4px 8px;
    animation: fadeInBubble 0.4s ease forwards;
}
.btn-chat-action-full {
    width: 100%;
    border: none;
    padding: 13px 20px;
    border-radius: 14px;
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}
.btn-action-primary { background: var(--accent-blue); color: white; }
.btn-action-primary:hover { background: var(--accent-blue-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(2, 132, 199, 0.15); }
.btn-action-secondary { background: rgba(255, 255, 255, 0.65); border: 1px solid rgba(0,0,0,0.06); color: var(--text-muted); }
.btn-action-secondary:hover { background: white; color: var(--text-main); border-color: rgba(0,0,0,0.12); transform: translateY(-1px); }

/* --- CONTENUTO ISLAND --- */
.app-content-island { 
    flex: 1; 
    padding: 40px; 
    overflow: hidden; 
}
.scrollable-content { 
    height: 100%; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
}
.content-title { 
    font-size: 1.5rem; 
    font-weight: 300; 
    letter-spacing: 1px; 
    color: var(--text-main); 
    margin-bottom: 24px; 
    flex-shrink: 0; 
}
.card-full { 
    padding: 36px; 
    background: var(--inner-card-bg); 
    border: 1px solid var(--inner-card-border); 
    border-radius: var(--radius-inner); 
}
.card-p { 
    font-size: 0.95rem; 
    color: var(--text-muted); 
    line-height: 1.65; 
    font-weight: 400; 
}

/* MASTER-DETAIL SYSTEM (RISULTATI BANDI) */
.split-bonus-layout { 
    display: flex; 
    gap: 20px; 
    flex: 1; 
    overflow: hidden; 
    height: calc(100% - 60px); 
}
.bonus-master-column { 
    width: 320px; 
    min-width: 320px; 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto; 
    padding-right: 6px; 
}
.bonus-master-column::-webkit-scrollbar { width: 4px; }
.bonus-master-column::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.05); border-radius: 10px; }

/* ACCORDION STRUTTURA */
.bonus-accordion-item {
    background: rgba(239, 68, 68, 0.015); 
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-inner);
    overflow: hidden;
    margin-bottom: 12px;
    transition: all 0.3s ease;
}

.bonus-accordion-summary {
    background: rgba(255, 255, 255, 0.9);
    color: var(--accent-red); 
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.8px;
    padding: 15px 20px;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    outline: none;
    user-select: none;
    border-bottom: 1px solid transparent;
}
.bonus-accordion-summary::-webkit-details-marker { display: none; }

.bonus-accordion-summary::after {
    content: '➔';
    font-size: 0.75rem;
    color: var(--text-light);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.bonus-accordion-item[open] {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(255, 255, 255, 0.55);
}
.bonus-accordion-item[open] .bonus-accordion-summary {
    border-bottom: 1px solid rgba(239, 68, 68, 0.1);
    color: var(--text-main);
}
.bonus-accordion-item[open] .bonus-accordion-summary::after {
    transform: rotate(90deg);
    color: var(--accent-red);
}

.bonus-accordion-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;    
    overflow-y: auto;     
    background: rgba(255, 255, 255, 0.25);
    animation: fadeInBubble 0.25s ease;
}

.bonus-accordion-content::-webkit-scrollbar { width: 4px; }
.bonus-accordion-content::-webkit-scrollbar-thumb { background: rgba(239, 68, 68, 0.2); border-radius: 10px; }

.bonus-accordion-content .bonus-list-item {
    padding: 12px 16px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.04);
}
.bonus-accordion-content .bonus-list-item:hover {
    background: white;
    border-color: rgba(239, 68, 68, 0.25);
    transform: translateX(2px);
}
.bonus-accordion-content .bonus-list-item.active {
    background: var(--chat-sent-bg);
    border-color: var(--accent-blue);
    box-shadow: none;
}
.bonus-accordion-content .item-title {
    font-size: 0.88rem;
    font-weight: 500;
}

.item-title-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    gap: 10px; 
}
.item-chevron { 
    font-size: 0.8rem; 
    color: var(--text-light); 
    transition: transform 0.2s ease; 
}
.bonus-list-item.active .item-chevron { 
    color: var(--accent-blue); 
    transform: translateX(3px); 
}

.bonus-detail-column { 
    flex: 1; 
    background: rgba(255, 255, 255, 0.45); 
    border: 1px solid rgba(255, 255, 255, 0.6); 
    border-radius: var(--radius-premium); 
    overflow-y: auto; 
    padding: 32px; 
    transition: opacity 0.2s ease; 
}
.bonus-detail-column::-webkit-scrollbar { width: 4px; }
.bonus-detail-column::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.05); border-radius: 10px; }

.detail-empty-state { 
    height: 100%; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    text-align: center; 
    padding: 0 40px; 
    color: var(--text-light); 
}
.empty-state-sparkle { 
    font-size: 2rem; 
    margin-bottom: 16px; 
    opacity: 0.6; 
}
.detail-empty-state p { 
    font-size: 0.95rem; 
    line-height: 1.6; 
    max-width: 400px; 
}

.detail-card-premium { 
    display: flex; 
    flex-direction: column; 
    gap: 28px; 
    animation: fadeInBubble 0.35s cubic-bezier(0.16, 1, 0.3, 1); 
}
.detail-main-header { 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
    border-bottom: 1px solid rgba(0,0,0,0.05); 
    padding-bottom: 20px; 
}
.detail-badge-ente { 
    font-size: 0.72rem; 
    font-weight: 700; 
    color: var(--accent-blue); 
    text-transform: uppercase; 
    letter-spacing: 1px; 
    background: rgba(2, 132, 199, 0.06); 
    padding: 4px 10px; 
    border-radius: 4px; 
    width: fit-content; 
}
.detail-title { 
    font-size: 1.4rem; 
    font-weight: 700; 
    color: var(--text-main); 
    letter-spacing: -0.3px; 
}

.detail-body-content { 
    display: flex; 
    flex-direction: column; 
    gap: 24px; 
}
.detail-meta-row { 
    display: flex; 
    gap: 32px; 
    background: rgba(255,255,255,0.3); 
    padding: 16px 20px; 
    border-radius: var(--radius-inner); 
    border: 1px solid rgba(255,255,255,0.4); 
}
.meta-block { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
}
.meta-block strong { 
    font-size: 0.68rem; 
    font-weight: 600; 
    color: var(--text-light); 
    letter-spacing: 0.8px; 
}

.badge-contributo-premium { 
    background: white; 
    color: var(--accent-blue); 
    padding: 4px 12px; 
    border-radius: 6px; 
    font-weight: 700; 
    font-size: 0.88rem; 
    border: 1px solid rgba(2, 132, 199, 0.15); 
    width: fit-content; 
}
.detail-date-badge { 
    font-weight: 600; 
    font-size: 0.9rem; 
    color: var(--text-main); 
}

.detail-section { 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}
.detail-section h4 { 
    font-size: 0.95rem; 
    font-weight: 600; 
    color: var(--text-main); 
    letter-spacing: 0.2px; 
}
.detail-section p { 
    font-size: 0.93rem; 
    color: var(--text-muted); 
    line-height: 1.65; 
}

/* FOOTER ISLAND */
.app-footer-island { 
    height: 50px; 
    min-height: 50px; 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 0 32px; 
    font-size: 0.78rem; 
    color: var(--text-light); 
    font-weight: 500; 
}
.app-footer-island a { color: var(--accent-blue); text-decoration: none; font-weight: 600; }

@keyframes fadeInBubble { 
    from { opacity: 0; transform: translateY(6px); } 
    to { opacity: 1; transform: translateY(0); } 
}


/* ==========================================================================
   🟢 SEZIONE RESPONSIVITÀ PER TABLET E MOBILE (MEDIA QUERIES)
   ========================================================================= */

/* 💻 1. OTTIMIZZAZIONE PER TABLET (Sotto i 1024px) */
@media (max-width: 1024px) {
    body, html {
        overflow-y: auto; /* Abilita lo scroll principale se lo spazio verticale non basta */
    }
    .app-container {
        height: auto;
        min-height: 100vh;
    }
    .app-body-row {
        flex-direction: column; /* Chat sopra, Contenuto dei Bonus sotto */
        overflow: visible;
    }
    .chat-sidebar {
        width: 100%;
        min-width: 100%;
        height: 480px; /* Altezza fissa per la chat su tablet */
    }
    .app-content-island {
        padding: 24px;
        height: auto;
    }
    .header-summary {
        padding-left: 10px;
    }
}

/* 📱 2. OTTIMIZZAZIONE COMPLETA PER MOBILE (Sotto i 768px) */
@media (max-width: 767px) {
    .app-container {
        padding: 8px;
        gap: 8px;
    }
    .app-header-island {
        padding: 0 16px;
        height: auto;
        padding-top: 12px;
        padding-bottom: 12px;
    }
    .header-left-side {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .header-summary {
        border-left: none;
        padding-left: 0;
        height: auto;
        flex-wrap: wrap; /* Avvolge i chip dell'ISEE se sono troppi */
    }
    .logo-title {
        font-size: 1.1rem;
    }
    .chat-sidebar {
        height: 420px;
        padding: 16px 12px;
    }
    
    /* Disposizione verticale dei risultati dei bonus */
    .split-bonus-layout {
        flex-direction: column;
        gap: 16px;
    }
    .bonus-master-column {
        width: 100%;
    }
    .bonus-detail-column {
        width: 100%;
        padding: 16px;
    }
    
    .app-footer-island {
        flex-direction: column;
        height: auto;
        padding: 16px;
        gap: 8px;
        text-align: center;
    }
    .card-full {
        padding: 20px;
    }
}