/* ===== KeideaCMS Live Chat AI Widget ====================================== */
.kecms-chat * { box-sizing: border-box; }

/* Forza il rispetto dell'attributo HTML hidden anche su elementi con display:flex */
.kecms-chat [hidden],
.kecms-chat-panel[hidden],
.kecms-chat-lead-form[hidden],
#kecms-chat-badge[hidden] { display: none !important; }

.kecms-chat {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #1f2937;
}

/* ---- Bubble di apertura -------------------------------------------------- */
.kecms-chat-bubble {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px 12px 14px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35), 0 2px 6px rgba(0,0,0,0.1);
    transition: transform .15s ease, box-shadow .15s ease;
    position: relative;
}
.kecms-chat-bubble:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(37, 99, 235, 0.45); }
.kecms-chat-bubble:focus-visible { outline: 3px solid #c7d2fe; outline-offset: 2px; }
.kecms-chat-bubble svg { flex: 0 0 auto; }

.kecms-chat-badge {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 20px; height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Quando il pannello è aperto, nascondiamo la bubble */
.kecms-chat.is-open .kecms-chat-bubble { display: none; }

/* ---- Pannello chat ------------------------------------------------------- */
.kecms-chat-panel {
    width: 360px;
    max-width: calc(100vw - 30px);
    height: 540px;
    max-height: calc(100vh - 40px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.25), 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: kecms-chat-in .18s ease-out;
}
@keyframes kecms-chat-in {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.kecms-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    color: #fff;
}
.kecms-chat-header-info { display: flex; align-items: center; gap: 12px; }
.kecms-chat-avatar {
    width: 38px; height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .5px;
}
.kecms-chat-title { font-weight: 700; font-size: 14px; }
.kecms-chat-subtitle {
    font-size: 12px;
    opacity: .9;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.kecms-chat-dot {
    width: 8px; height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}
.kecms-chat-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 6px;
}
.kecms-chat-close:hover { background: rgba(255,255,255,0.15); }

/* ---- Messaggi ------------------------------------------------------------ */
.kecms-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.kecms-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.kecms-chat-msg.assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}
.kecms-chat-msg.user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.kecms-chat-msg.system {
    align-self: center;
    background: #fef3c7;
    color: #92400e;
    font-size: 12px;
    border-radius: 10px;
}
.kecms-chat-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
    padding: 10px 14px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.kecms-chat-typing span {
    display: inline-block;
    width: 7px; height: 7px;
    margin: 0 1px;
    background: #9ca3af;
    border-radius: 50%;
    animation: kecms-chat-blink 1.2s infinite ease-in-out;
}
.kecms-chat-typing span:nth-child(2) { animation-delay: .15s; }
.kecms-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes kecms-chat-blink {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40%           { opacity: 1; transform: translateY(-3px); }
}

/* ---- Form input messaggio ----------------------------------------------- */
.kecms-chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}
.kecms-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 120px;
    outline: none;
}
.kecms-chat-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.kecms-chat-send {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    border: 0;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.kecms-chat-send:hover { background: #1d4ed8; }
.kecms-chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Footer -------------------------------------------------------------- */
.kecms-chat-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px 10px;
    font-size: 11px;
    color: #6b7280;
    background: #fff;
}
.kecms-chat-link {
    background: transparent;
    border: 0;
    color: #2563eb;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}
.kecms-chat-powered { opacity: .7; }

/* ---- Form lead ----------------------------------------------------------- */
.kecms-chat-lead-form {
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.kecms-chat-lead-title { font-weight: 700; font-size: 14px; color: #1f2937; }
.kecms-chat-lead-sub { font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.kecms-chat-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #374151; }
.kecms-chat-field input {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    outline: none;
}
.kecms-chat-field input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.kecms-chat-lead-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.kecms-chat-btn-primary {
    background: #2563eb;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 8px 14px;
    font-weight: 600;
    cursor: pointer;
}
.kecms-chat-btn-primary:hover { background: #1d4ed8; }
.kecms-chat-btn-ghost {
    background: transparent;
    color: #6b7280;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}
.kecms-chat-btn-ghost:hover { background: #e5e7eb; color: #1f2937; }

/* ---- Mobile -------------------------------------------------------------- */
@media (max-width: 480px) {
    .kecms-chat { right: 12px; bottom: 12px; }
    .kecms-chat-panel { width: calc(100vw - 24px); height: calc(100vh - 40px); }
    .kecms-chat-bubble-label { display: none; }
    .kecms-chat-bubble { padding: 14px; }
}
