/* Website chat widget: FAQ bot with live-agent hand-off */

.iai-chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color, #2563eb);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.35);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
}

.iai-chat-launcher:hover { transform: scale(1.06); background: var(--primary-dark, #1d4ed8); }
.iai-chat-launcher:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }

.iai-chat-launcher .iai-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--secondary-color, #10b981);
    border: 2px solid #fff;
}

.iai-chat-window {
    position: fixed;
    right: 20px;
    bottom: 92px;
    width: 370px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(17, 24, 39, 0.25);
    z-index: 9001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-primary, #1f2937);
}

.iai-chat-window.open { display: flex; animation: iai-pop 0.18s ease-out; }

@keyframes iai-pop {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.iai-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--primary-color, #2563eb);
    color: #fff;
}

.iai-chat-header .iai-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.iai-chat-header .iai-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.iai-chat-header .iai-status { font-size: 12px; opacity: 0.85; }
.iai-chat-header .iai-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    margin-right: 6px;
    vertical-align: 1px;
}

.iai-chat-header .iai-close {
    margin-left: auto;
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    opacity: 0.85;
}

.iai-chat-header .iai-close:hover { opacity: 1; }

.iai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-secondary, #f8fafc);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.iai-msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.iai-msg a { color: inherit; text-decoration: underline; }
.iai-msg.bot, .iai-msg.agent { align-self: flex-start; background: #fff; border: 1px solid var(--border-color, #e5e7eb); border-bottom-left-radius: 4px; }
.iai-msg.agent { border-color: #a7f3d0; background: #ecfdf5; }
.iai-msg.user { align-self: flex-end; background: var(--primary-color, #2563eb); color: #fff; border-bottom-right-radius: 4px; }
.iai-msg.system { align-self: center; background: none; color: var(--text-secondary, #6b7280); font-size: 12px; text-align: center; padding: 2px 8px; }
.iai-msg .iai-sender { display: block; font-size: 11px; font-weight: 600; color: #047857; margin-bottom: 2px; }

.iai-typing { display: inline-flex; gap: 4px; }
.iai-typing span { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; animation: iai-blink 1.2s infinite; }
.iai-typing span:nth-child(2) { animation-delay: 0.2s; }
.iai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes iai-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

.iai-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
}

.iai-quick button {
    border: 1px solid var(--primary-color, #2563eb);
    background: #fff;
    color: var(--primary-color, #2563eb);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

.iai-quick button:hover { background: var(--primary-color, #2563eb); color: #fff; }

.iai-form {
    align-self: stretch;
    background: #fff;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.iai-form h4 { margin: 0 0 2px; font-size: 14px; }
.iai-form p { margin: 0; font-size: 12px; color: var(--text-secondary, #6b7280); }

.iai-form input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 14px;
    font-family: inherit;
}

.iai-form input:focus { outline: none; border-color: var(--primary-color, #2563eb); }

.iai-form .iai-row { display: flex; gap: 8px; }
.iai-form .iai-row button { flex: 1; }
.iai-form .iai-error { color: #dc2626; font-size: 12px; min-height: 0; }

.iai-btn {
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
}

.iai-btn-primary { background: var(--primary-color, #2563eb); color: #fff; }
.iai-btn-primary:hover { background: var(--primary-dark, #1d4ed8); }
.iai-btn-green { background: var(--secondary-color, #10b981); color: #fff; }
.iai-btn-green:hover { background: #059669; }
.iai-btn-ghost { background: #fff; color: var(--text-secondary, #6b7280); border: 1px solid var(--border-color, #e5e7eb); }
.iai-btn:disabled { opacity: 0.6; cursor: default; }

.iai-escalate {
    padding: 8px 12px;
    background: #fff;
    border-top: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    gap: 8px;
}

.iai-escalate .iai-btn { flex: 1; padding: 8px 10px; }

.iai-chat-footer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.iai-chat-footer textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 14px;
    font-family: inherit;
    max-height: 90px;
    line-height: 1.4;
}

.iai-chat-footer textarea:focus { outline: none; border-color: var(--primary-color, #2563eb); }

.iai-chat-footer .iai-send {
    width: 42px;
    border: none;
    border-radius: 10px;
    background: var(--primary-color, #2563eb);
    color: #fff;
    cursor: pointer;
    font-size: 16px;
}

.iai-chat-footer .iai-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 480px) {
    .iai-chat-window {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .iai-chat-launcher { right: 16px; bottom: 16px; }
    body.iai-chat-open .iai-chat-launcher { display: none; }
}
