:root {
    --aichat-color-button:   #2563eb;
    --aichat-color-header:   #1e293b;
    --aichat-color-user-msg: #2563eb;
    --aichat-color-bot-msg:  #f1f5f9;
    --aichat-color-send:     #2563eb;
    --aichat-bottom: 24px;
    --aichat-right:  24px;
    --aichat-top:    auto;
    --aichat-left:   auto;
    --aichat-w: 360px;
    --aichat-h: 540px;
}

#aichat-root *, #aichat-root *::before, #aichat-root *::after { box-sizing: border-box; }

#aichat-root {
    position: fixed;
    bottom: var(--aichat-bottom); right: var(--aichat-right);
    top:    var(--aichat-top);    left:  var(--aichat-left);
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px; line-height: 1.45; color: #0f172a;
}

.aichat-button {
    background: var(--aichat-color-button); color: #fff; border: 0; cursor: pointer;
    width: 56px; height: 56px; border-radius: 50%;
    box-shadow: 0 6px 24px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center;
}
.aichat-button:hover { transform: scale(1.04); }
/*
 * Bulletproof SVG sizing. The #aichat-root scoping plus min-/max-width
 * lockdown defeats common offenders:
 *   - themes that ship `img, svg { max-width: 100%; height: auto; }`
 *   - flex parents that calculate the cross-axis available size as 0
 *   - aggressive resets like `* { min-width: 0; }`
 *   - generic `svg { width: auto; }` from optimisers
 */
#aichat-root .aichat-button svg,
#aichat-root .aichat-button > svg {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    min-height: 26px !important;
    max-width: 26px !important;
    max-height: 26px !important;
    flex: 0 0 26px !important;
    display: block !important;
    fill: #ffffff !important;
    stroke: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow: visible !important;
}
#aichat-root .aichat-button svg path { fill: #ffffff !important; }

.aichat-proactive {
    position: absolute;
    bottom: 80px; right: 0;
    width: 260px;
    background: #fff; color: #0f172a;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
    font-size: 14px; line-height: 1.5;
    cursor: pointer;
    animation: aichat-proactive-pop .32s cubic-bezier(.2, .8, .2, 1);
}
.aichat-proactive .aichat-proactive-text {
    padding-right: 22px;
    word-wrap: break-word;
}
.aichat-proactive::after {
    content: ""; position: absolute;
    bottom: -7px; right: 22px;
    width: 12px; height: 12px;
    background: #fff;
    border-right: 1px solid rgba(15, 23, 42, .08);
    border-bottom: 1px solid rgba(15, 23, 42, .08);
    transform: rotate(45deg);
}
.aichat-proactive[hidden] { display: none; }
.aichat-proactive .aichat-proactive-close {
    position: absolute; top: 6px; right: 8px;
    background: transparent; border: 0; cursor: pointer;
    color: #94a3b8; font-size: 20px; line-height: 1;
    width: 24px; height: 24px; padding: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s ease, color .15s ease;
}
.aichat-proactive .aichat-proactive-close:hover {
    background: #f1f5f9; color: #0f172a;
}
@keyframes aichat-proactive-pop {
    0%   { opacity: 0; transform: translateY(12px) scale(.92); }
    100% { opacity: 1; transform: translateY(0)    scale(1);   }
}

.aichat-panel {
    position: absolute; bottom: 70px; right: 0;
    width: var(--aichat-w); height: var(--aichat-h);
    background: #fff; border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0,0,0,.18);
    display: flex; flex-direction: column; overflow: hidden;
}
.aichat-panel[hidden] { display: none; }

.aichat-header {
    background: var(--aichat-color-header); color: #fff;
    padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.aichat-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.aichat-title  { flex: 1; font-weight: 600; font-size: 14px; }
.aichat-actions { display: flex; gap: 6px; align-items: center; }
.aichat-actions button {
    background: transparent; color: #fff; border: 0; cursor: pointer;
    width: 30px; height: 30px; border-radius: 6px; padding: 0;
    font: inherit; line-height: 1;
}
.aichat-actions button:hover    { background: rgba(255,255,255,.12); }
.aichat-actions button:disabled { opacity: .4; cursor: not-allowed; }
.aichat-actions .aichat-trigger-d {
    width: auto; min-width: 0;
    padding: 0 10px; height: 30px;
    font-size: 12px; font-weight: 500;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,.35);
}
.aichat-actions .aichat-trigger-d:hover { background: rgba(255,255,255,.18); }

.aichat-consent {
    padding: 12px 14px; background: #fef9c3; border-bottom: 1px solid #fde68a;
    font-size: 13px; line-height: 1.5;
}
.aichat-consent a { color: inherit; text-decoration: underline; }
.aichat-consent .aichat-accept {
    margin-top: 8px; background: var(--aichat-color-button); color: #fff;
    border: 0; border-radius: 6px; padding: 6px 14px; cursor: pointer;
}

.aichat-messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.aichat-msg { padding: 8px 12px; border-radius: 10px; max-width: 80%; word-wrap: break-word; white-space: pre-wrap; }
.aichat-msg.--user      { background: var(--aichat-color-user-msg); color: #fff;     align-self: flex-end; }
.aichat-msg.--assistant { background: var(--aichat-color-bot-msg);  color: #0f172a;  align-self: flex-start; }
.aichat-msg.--error     { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; align-self: flex-start; }

.aichat-typing { display: inline-flex; gap: 4px; padding: 8px 12px; background: var(--aichat-color-bot-msg); border-radius: 10px; align-self: flex-start; }
.aichat-typing span { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: aichat-pulse 1.2s infinite; }
.aichat-typing span:nth-child(2) { animation-delay: .15s; }
.aichat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aichat-pulse { 0%,80%,100%{opacity:.3} 40%{opacity:1} }

.aichat-cta { display: flex; gap: 8px; flex-wrap: wrap; align-self: flex-start; }
.aichat-cta button {
    background: #fff; border: 1px solid var(--aichat-color-button); color: var(--aichat-color-button);
    border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.aichat-cta button.--primary { background: var(--aichat-color-button); color: #fff; border-color: var(--aichat-color-button); }

.aichat-form { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: #f8fafc; border-radius: 10px; align-self: stretch; }
.aichat-form input { padding: 6px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }
.aichat-form .aichat-form-actions { display: flex; gap: 6px; justify-content: flex-end; }
.aichat-form .aichat-honeypot { display: none !important; }

.aichat-input {
    border-top: 1px solid #e2e8f0; padding: 8px; display: flex; gap: 6px; align-items: end;
}
.aichat-input textarea {
    flex: 1; resize: none; max-height: 100px; min-height: 36px;
    padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit;
}
.aichat-input textarea:disabled { background: #f1f5f9; color: #94a3b8; }
.aichat-send {
    background: var(--aichat-color-send); color: #fff; border: 0; border-radius: 8px;
    padding: 0 14px; height: 36px; cursor: pointer;
}
.aichat-send:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 480px) {
    .aichat-panel { width: 100vw; height: calc(100vh - 80px); right: 0; bottom: 70px; border-radius: 0; }
    #aichat-root { right: 12px; bottom: 12px; }
}
