/**
 * Modulo di profilazione AI — stile frontend (mobile-first).
 * Eredita le CSS var del widget (--chatbot-widget-primary, ecc.).
 * Tutto scoped sotto .cbq- per non interferire col widget esistente.
 *
 * @package AIChatbot
 * @since   2.1.0
 */

/* ──────────────────────────────────────────
   BLINDATURA CONTRO OVERRIDE DEL TEMA
   I temi con `button { ... }` o `a { ... }` aggressivi possono rendere
   illeggibili i pulsanti del questionario. Selettore con #ai-chatbot-widget
   (specificità ID) + !important sui valori critici + reset appearance.
   Questi pulsanti sono dentro #chatbot-window (parte di #ai-chatbot-widget).
   ────────────────────────────────────────── */
#ai-chatbot-widget .cbq-opt,
#ai-chatbot-widget .cbq-btn,
#ai-chatbot-widget .cbq-invite-start,
#ai-chatbot-widget .cbq-invite-dismiss,
#ai-chatbot-widget .cbq-close,
#ai-chatbot-widget .cbq-result-link,
.cbq-opt, .cbq-btn, .cbq-invite-start, .cbq-result-link {
    appearance: none !important;
    -webkit-appearance: none !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    text-shadow: none !important;
    text-decoration: none !important;
    line-height: 1.35 !important;
    min-height: 0 !important;
    box-shadow: none !important;
    margin: 0;
    font-family: var(--chatbot-widget-font, inherit) !important;
    /* Il tema può forzare `white-space:nowrap` sui <button>: il testo lungo
       uscirebbe dal pulsante. Forziamo il ritorno a capo. */
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    height: auto !important;
    max-width: 100% !important;
}
/* Colori forzati: vincono su `button{background:...}` del tema */
#ai-chatbot-widget .cbq-opt,
.cbq-opt {
    background: #fff !important;
    color: var(--chatbot-widget-primary, #0073aa) !important;
    border: 1.5px solid var(--chatbot-widget-primary, #0073aa) !important;
}
#ai-chatbot-widget .cbq-opt.cbq-selected,
.cbq-opt.cbq-selected,
#ai-chatbot-widget .cbq-opt:hover,
.cbq-opt:hover {
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
#ai-chatbot-widget .cbq-btn-primary,
.cbq-btn-primary,
#ai-chatbot-widget .cbq-invite-start,
.cbq-invite-start {
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
#ai-chatbot-widget .cbq-invite-start,
.cbq-invite-start {
    /* invito ha sfondo brand → testo bianco su fondo brand */
    background: #fff !important;
    color: var(--chatbot-widget-primary, #0073aa) !important;
}
#ai-chatbot-widget .cbq-btn-ghost,
.cbq-btn-ghost {
    background: #f1f1f1 !important;
    color: #555 !important;
}
#ai-chatbot-widget .cbq-result-link,
.cbq-result-link {
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
#ai-chatbot-widget .cbq-text-input,
.cbq-text-input {
    background: #fff !important;
    color: #222 !important;
}

/* ---- Card invito (in cima all'area conversazione) ---- */
.cbq-invite {
    margin: 10px 12px 4px;
    padding: 14px 14px 14px 14px;
    border-radius: 14px;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.cbq-invite-title {
    font-size: 14px;
    font-weight: 700;
    margin: 0 22px 4px 0;
    line-height: 1.3;
}
.cbq-invite-desc {
    font-size: 12.5px;
    opacity: 0.92;
    margin: 0 0 12px;
    line-height: 1.4;
}
.cbq-invite-start {
    display: inline-block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    background: #fff;
    color: var(--chatbot-widget-primary, #0073aa);
    border: none;
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.cbq-invite-start:hover { opacity: 0.93; }
.cbq-invite-dismiss {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    min-width: 24px;
    border: none;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cbq-invite-dismiss:hover { background: rgba(255, 255, 255, 0.30); }

/* ---- Popup interno (overlay dentro #chatbot-window) ---- */
.cbq-overlay {
    position: absolute;
    inset: 0;
    background: var(--chatbot-quiz-popup-bg, #ffffff);
    z-index: 30;
    display: flex;
    flex-direction: column;
    animation: cbqIn 0.18s ease;
}
@keyframes cbqIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.cbq-head {
    flex-shrink: 0;
    background: var(--chatbot-widget-primary, #0073aa);
    color: var(--chatbot-widget-header-text, #fff);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.cbq-head-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    min-width: 0;
    color: var(--chatbot-widget-header-text, #fff);
}
.cbq-close {
    flex-shrink: 0;
    border: none;
    padding: 7px 12px;
    margin: 0;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.18);
    color: var(--chatbot-widget-header-text, #fff) !important;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.cbq-close:hover { background: rgba(255, 255, 255, 0.28); }
.cbq-close:hover { background: rgba(255, 255, 255, 0.28); }

/* Progress bar */
.cbq-progress {
    flex-shrink: 0;
    height: 4px;
    background: #ececec;
}
.cbq-progress-bar {
    height: 100%;
    width: 0;
    background: var(--chatbot-widget-primary, #0073aa);
    transition: width 0.3s ease;
}

.cbq-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 18px;
    color: var(--chatbot-quiz-text, #222);
}

.cbq-step-count {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--chatbot-widget-primary, #0073aa);
    background: rgba(0, 115, 170, 0.10);
    padding: 4px 10px;
    border-radius: 999px;
    margin: 0 0 12px;
    letter-spacing: 0.2px;
}
.cbq-q-text {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0 0 6px;
}
.cbq-q-desc {
    font-size: 13.5px;
    color: #666;
    margin: 0 0 18px;
    line-height: 1.45;
}

/* Pulsanti risposta — grandi, mobile-first */
.cbq-opt {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    background: #fff;
    color: var(--chatbot-widget-primary, #0073aa);
    border: 1.5px solid var(--chatbot-widget-primary, #0073aa);
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 500;
    margin: 0 0 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.cbq-opt:hover { background: rgba(0, 0, 0, 0.03); }
.cbq-opt:active { transform: scale(0.99); }
.cbq-opt.cbq-selected {
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
}

/* Spaziatura tra i pulsanti risposta (vince sul reset ID del tema) +
   leggero respiro interno. */
#ai-chatbot-widget .cbq-opt,
.cbq-opt {
    margin: 0 0 12px !important;
    padding: 15px 18px !important;
}
#ai-chatbot-widget .cbq-opt:last-child,
.cbq-opt:last-child { margin-bottom: 4px !important; }

/* Scelta multipla: quadratino da spuntare a sinistra del testo */
#ai-chatbot-widget .cbq-opt-multi,
.cbq-opt-multi {
    display: flex !important;
    align-items: center;
    gap: 12px;
    text-align: left;
}
.cbq-opt-multi .cbq-opt-label { flex: 1; min-width: 0; }
.cbq-opt-multi .cbq-check {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    box-sizing: border-box;
    border: 2px solid currentColor;
    border-radius: 5px;
    position: relative;
    display: inline-block;
    background: transparent;
}
/* Spunta quando selezionato */
.cbq-opt-multi.cbq-selected .cbq-check::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Scala 1-10 — griglia ordinata 5×2, tappabile */
#ai-chatbot-widget .cbq-scale,
.cbq-scale {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin: 4px 0 14px;
}
#ai-chatbot-widget .cbq-scale-btn,
.cbq-scale-btn {
    appearance: none !important;
    -webkit-appearance: none !important;
    width: 100%;
    min-height: 46px;
    box-sizing: border-box;
    cursor: pointer;
    background: #fff !important;
    color: var(--chatbot-widget-primary, #0073aa) !important;
    border: 1.5px solid var(--chatbot-widget-primary, #0073aa) !important;
    border-radius: 10px;
    padding: 0 !important;
    font-size: 15px;
    font-weight: 700;
    line-height: 1 !important;
    text-align: center;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background .15s, color .15s, transform .1s;
}
#ai-chatbot-widget .cbq-scale-btn:hover,
.cbq-scale-btn:hover { background: rgba(0, 0, 0, 0.04) !important; }
#ai-chatbot-widget .cbq-scale-btn:active,
.cbq-scale-btn:active { transform: scale(0.96); }
#ai-chatbot-widget .cbq-scale-btn.cbq-selected,
.cbq-scale-btn.cbq-selected {
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
/* Etichette estremi (opzionali, aggiunte via JS se presenti) */
.cbq-scale-ends {
    display: flex;
    justify-content: space-between;
    font-size: 11.5px;
    color: #888;
    margin: -8px 0 14px;
}

.cbq-text-input {
    width: 100%;
    box-sizing: border-box;
    border: 1.5px solid #ccc;
    border-radius: 10px;
    padding: 13px 14px;
    font-size: 15px;
    margin-bottom: 14px;
    outline: none;
}
.cbq-text-input:focus { border-color: var(--chatbot-widget-primary, #0073aa); }

/* Menu a tendina */
#ai-chatbot-widget .cbq-select,
.cbq-select {
    width: 100%;
    box-sizing: border-box;
    border: 1.5px solid #ccc !important;
    border-radius: 10px;
    padding: 13px 14px !important;
    font-size: 15px;
    margin-bottom: 14px;
    background: #fff !important;
    color: #222 !important;
    outline: none;
    appearance: auto;
    -webkit-appearance: auto;
}
#ai-chatbot-widget .cbq-select:focus,
.cbq-select:focus { border-color: var(--chatbot-widget-primary, #0073aa) !important; }

/* Valutazione a stelle */
#ai-chatbot-widget .cbq-stars,
.cbq-stars {
    display: flex !important;
    gap: 6px;
    flex-wrap: wrap;
    margin: 4px 0 14px;
}
#ai-chatbot-widget .cbq-star,
.cbq-star {
    appearance: none !important;
    -webkit-appearance: none !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 2px !important;
    margin: 0 !important;
    font-size: 32px;
    line-height: 1 !important;
    cursor: pointer;
    color: #d4d4d4 !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: color .12s, transform .1s;
}
#ai-chatbot-widget .cbq-star:hover,
.cbq-star:hover { transform: scale(1.12); }
#ai-chatbot-widget .cbq-star.cbq-on,
.cbq-star.cbq-on { color: var(--chatbot-widget-primary, #f5b301) !important; }

/* Footer azioni */
.cbq-foot {
    flex-shrink: 0;
    border-top: 1px solid #eee;
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    background: #fff;
}
.cbq-btn {
    flex: 1;
    border: none;
    border-radius: 10px;
    padding: 13px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.cbq-btn-primary {
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
}
.cbq-btn-ghost {
    background: #f1f1f1;
    color: #555;
    flex: 0 0 auto;
    padding: 13px 18px;
}
.cbq-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Schermata finale (M3: profilo base + completion) */
.cbq-result-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--chatbot-widget-primary, #0073aa);
}
.cbq-result-text { font-size: 14px; line-height: 1.5; color: #444; margin: 0 0 16px; }
.cbq-result-link {
    display: block;
    box-sizing: border-box;
    text-align: center;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff !important;
    text-decoration: none;
    border-radius: 10px;
    padding: 12px 14px;
    font-weight: 600;
    margin: 0 0 8px;
}

/* Card prodotto WooCommerce (immagine + nome + pulsante) */
#ai-chatbot-widget .cbq-product-card,
.cbq-product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    width: 100%;
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    padding: 10px;
    margin: 0 0 10px;
    background: #fff;
}
#ai-chatbot-widget .cbq-product-img,
.cbq-product-img {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #eee;
    background: #f5f5f5;
}
#ai-chatbot-widget .cbq-product-info,
.cbq-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#ai-chatbot-widget .cbq-product-name,
.cbq-product-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    color: #222;
    overflow-wrap: anywhere;
}
#ai-chatbot-widget .cbq-product-btn,
.cbq-product-btn {
    appearance: none !important;
    -webkit-appearance: none !important;
    align-self: flex-start;
    display: inline-block;
    box-sizing: border-box;
    text-decoration: none !important;
    text-align: center;
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 8px;
    padding: 9px 14px !important;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.2 !important;
    cursor: pointer;
    white-space: normal !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
}
#ai-chatbot-widget .cbq-product-btn:hover,
.cbq-product-btn:hover { opacity: 0.92; }

.cbq-loading {
    text-align: center;
    color: #999;
    padding: 30px 0;
    font-size: 14px;
}

/* ─────────────────────────────────────────────────────────────
   Modulo di contatto finale (step virtuale del questionario)
   ───────────────────────────────────────────────────────────── */
.cbq-contact {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 6px 0 10px;
}
.cbq-cf-label {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    margin: 0 !important;
}
#ai-chatbot-widget .cbq-cf-label-row,
.cbq-cf-label-row {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    line-height: 1.2;
}
#ai-chatbot-widget .cbq-cf-label-text,
.cbq-cf-label-text {
    display: inline-block !important;
    color: #111 !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    letter-spacing: .1px;
}
#ai-chatbot-widget .cbq-cf-req,
.cbq-cf-req {
    display: inline-block !important;
    color: #dc2626 !important;
    font-weight: 700;
    margin-left: 2px;
    background: none !important;
    padding: 0 !important;
    line-height: 1;
}
#ai-chatbot-widget .cbq-cf-label input,
.cbq-cf-label input {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 11px 12px !important;
    font-size: 15px !important;
    line-height: 1.3 !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    background: #fff !important;
    color: #111 !important;
    margin: 0 !important;
    transition: border-color .15s ease, box-shadow .15s ease;
    -webkit-appearance: none;
            appearance: none;
}
#ai-chatbot-widget .cbq-cf-label input:focus,
.cbq-cf-label input:focus {
    outline: none !important;
    border-color: var(--cb-primary, #4f46e5) !important;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12) !important;
}
#ai-chatbot-widget .cbq-cf-label input.cbq-cf-err,
.cbq-cf-label input.cbq-cf-err {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .12) !important;
}
.cbq-cf-consent {
    display: flex !important;
    gap: 10px;
    align-items: flex-start;
    font-size: 12.5px;
    color: #555;
    line-height: 1.45;
    margin: 4px 0 6px !important;
    cursor: pointer;
}
.cbq-cf-consent input[type="checkbox"] {
    flex: 0 0 auto;
    margin-top: 3px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.cbq-cf-consent a {
    color: var(--cb-primary, #4f46e5);
    text-decoration: underline;
}

/* Desktop: leggermente più arioso */
@media (min-width: 480px) {
    .cbq-body { padding: 24px 22px; }
    .cbq-q-text { font-size: 18px; }
    .cbq-contact { gap: 14px; }
}
