/* PPL NIBBIO v2 — Modal "Risposta AI"
   Stesse classi generate da quiz-ai-helper.js, stile del design system v2
   (modal 720 px, header viola, badge di stato, testo formattato). */

.ai-modal {
    position: fixed; inset: 0; z-index: 10000;
    display: none; align-items: center; justify-content: center;
    padding: 16px;
    background: rgba(10, 12, 30, 0.78);
    backdrop-filter: blur(6px);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.ai-modal.active { display: flex; }
/* sul telefono 100vh comprende anche la barra del browser: si usa l'altezza visibile (dvh), se il browser la conosce */
.ai-modal { height: 100vh; height: 100dvh; bottom: auto; }

.ai-modal-content {
    width: 100%; max-width: 760px; max-height: 92vh; max-height: 92dvh;
    display: flex; flex-direction: column;
    background: #252a45;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0,0,0,.6);
    overflow: hidden;
    animation: ai-pop .18s ease-out;
}
@keyframes ai-pop { from { transform: translateY(12px) scale(.98); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---- header ---- */
.ai-modal-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #9b59b6 0%, #6b2c87 100%);
    color: #fff;
}
.ai-modal-header h3 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: .01em; flex: 1; }
.ai-provider-toggle {
    display: flex; gap: 4px; padding: 3px;
    background: rgba(0,0,0,.28); border-radius: 999px;
}
.ai-provider-btn {
    border: 0; cursor: pointer; padding: 5px 14px; border-radius: 999px;
    background: transparent; color: rgba(255,255,255,.75);
    font: 600 .78rem/1 Inter, system-ui, sans-serif; text-transform: uppercase; letter-spacing: .06em;
    transition: all .15s;
}
.ai-provider-btn.active { background: #fff; color: #6b2c87; }
.ai-modal-close {
    border: 0; cursor: pointer; width: 34px; height: 34px; border-radius: 8px;
    background: rgba(255,255,255,.14); color: #fff; font-size: 1.3rem; line-height: 1;
    transition: background .15s;
}
.ai-modal-close:hover { background: rgba(255,255,255,.28); }

/* ---- body ---- */
.ai-modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; color: #e8e8f0;
    flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.ai-modal-body > * , .ai-modal-header, .ai-modal-footer { flex-shrink: 0; }
/* formule lunghe (KaTeX): scorrono di lato invece di uscire dalla finestra */
#aiResponseContent .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.ai-question { padding: 14px 16px; border-radius: 10px; background: #30365a; border-left: 3px solid #3498db; }
.ai-question h4 { margin: 0 0 6px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #b4b6cc; }
.ai-question p { margin: 0; font-size: .98rem; line-height: 1.5; color: #fff; }

.ai-response h4 { margin: 0 0 8px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #bb86fc; }
#aiResponseContent { font-size: .95rem; line-height: 1.65; color: #e8e8f0; }
#aiResponseContent h1, #aiResponseContent h2, #aiResponseContent h3 { color: #fff; margin: 14px 0 6px; font-weight: 700; }
#aiResponseContent h1 { font-size: 1.15rem; } #aiResponseContent h2 { font-size: 1.05rem; } #aiResponseContent h3 { font-size: .98rem; }
#aiResponseContent p { margin: 0 0 10px; }
#aiResponseContent ul, #aiResponseContent ol { margin: 0 0 10px 20px; }
#aiResponseContent li { margin: 3px 0; }
#aiResponseContent strong { color: #fff; }
#aiResponseContent code { font-family: "JetBrains Mono", monospace; font-size: .88em; background: #12142a; padding: 1px 6px; border-radius: 4px; color: #92ccff; }
#aiResponseContent hr { border: 0; border-top: 1px solid rgba(255,255,255,.12); margin: 12px 0; }

/* badge di stato in cima alla risposta */
.ai-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; margin-bottom: 12px; border-radius: 999px;
    font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.ai-badge-cache       { background: rgba(39,174,96,.18);  color: #4ae183; }
.ai-badge-new         { background: rgba(241,196,15,.18); color: #f1c40f; }
.ai-badge-regenerated { background: rgba(52,152,219,.18); color: #92ccff; }

/* caricamento / errore */
.ai-loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 28px; color: #b4b6cc; }
.ai-loading p { margin: 0; }
.ai-spinner {
    width: 40px; height: 40px; border-radius: 50%;
    border: 4px solid rgba(255,255,255,.15); border-top-color: #9b59b6;
    animation: ai-spin 1s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg) } }
.ai-error { padding: 14px 16px; border-radius: 10px; background: rgba(231,76,60,.14); border: 1px solid rgba(231,76,60,.4); color: #ffb4ab; }
.ai-error p { margin: 0; }

/* ---- footer ---- */
.ai-modal-footer {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 20px;
    background: #12142a; border-top: 1px solid rgba(255,255,255,.1);
}
.ai-footer-buttons { display: flex; gap: 8px; }
.ai-report-btn, .ai-regenerate-btn {
    cursor: pointer; padding: 7px 14px; border-radius: 8px;
    font: 600 .8rem/1 Inter, system-ui, sans-serif;
    transition: all .15s;
}
.ai-report-btn { border: 1px solid rgba(241,196,15,.45); background: rgba(241,196,15,.1); color: #f1c40f; }
.ai-report-btn:hover { background: rgba(241,196,15,.22); }
.ai-regenerate-btn { border: 1px solid rgba(52,152,219,.45); background: rgba(52,152,219,.12); color: #92ccff; }
.ai-regenerate-btn:hover { background: rgba(52,152,219,.25); }
.ai-modal-footer small { color: #b4b6cc; font-size: .75rem; }

/* ---- pulsante "AI" nelle card (lo mostra/nasconde l'helper) ---- */
.btn-ai { }

@media (max-width: 640px) {
    .ai-modal { padding: 0; align-items: flex-end; }
    .ai-modal-content { max-height: 96vh; max-height: 96dvh; border-radius: 16px 16px 0 0; }
    .ai-modal-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .ai-modal-header h3 { font-size: .95rem; }
    .ai-modal-footer { flex-direction: column; align-items: stretch; }
    .ai-footer-buttons { justify-content: space-between; }
}
