.ai-chat-widget {
    position: fixed;
    left: 20px;
    bottom: 24px;
    z-index: 100000;
    color: #f8fafc;
}

.ai-chat-toggle {
    min-height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    padding: 0 16px;
    background: #1464c8;
    color: #fff;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
    transition: background-color 180ms ease, transform 180ms ease;
}

.ai-chat-toggle:hover {
    background: #0f56ad;
    transform: translateY(-1px);
}

.ai-chat-toggle:focus-visible,
.ai-chat-close:focus-visible,
.ai-chat-action:focus-visible,
.ai-chat-send:focus-visible,
.ai-chat-handoff-close:focus-visible,
.ai-chat-handoff-submit:focus-visible {
    outline: 3px solid rgba(255, 166, 46, 0.55);
    outline-offset: 2px;
}

.ai-chat-toggle-icon {
    display: inline-flex;
    line-height: 0;
}

.ai-chat-toggle-icon-svg {
    width: 19px;
    height: 19px;
}

.ai-chat-panel {
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    width: min(440px, calc(100vw - 40px));
    height: min(680px, calc(100dvh - 110px));
    min-height: 480px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    background: #07182d;
    color: #f8fafc;
    border: 1px solid rgba(148, 184, 224, 0.22);
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.ai-chat-panel[hidden] {
    display: none;
}

.ai-chat-thread {
    grid-row: 2 / -1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 16px;
    background: #0b223e;
    border-bottom: 1px solid rgba(148, 184, 224, 0.16);
}

.ai-chat-heading { min-width: 0; }

.ai-chat-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-status-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

.ai-chat-title {
    margin: 0;
    color: #fff;
    font-size: 16px;
    font-weight: 900;
    line-height: 1.5;
}

.ai-chat-subtitle {
    margin: 3px 0 0;
    color: #b8c8dc;
    font-size: 12px;
    line-height: 1.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-close,
.ai-chat-handoff-close {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    cursor: pointer;
}

.ai-chat-close:hover,
.ai-chat-handoff-close:hover { background: rgba(255, 255, 255, 0.12); }
.ai-chat-close svg,
.ai-chat-send svg { width: 19px; height: 19px; }

.ai-chat-messages {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 184, 224, 0.35) transparent;
}

.ai-chat-empty {
    margin: auto;
    max-width: 260px;
    text-align: center;
    color: #9fb2c9;
    font-size: 13px;
    line-height: 1.8;
}

.ai-chat-message {
    max-width: 86%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-chat-message.user { align-self: flex-start; }
.ai-chat-message.assistant,
.ai-chat-message.error,
.ai-chat-message.typing { align-self: flex-end; }

.ai-chat-bubble {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ai-chat-message.user .ai-chat-bubble {
    background: #1f6ed4;
    color: #fff;
    border-bottom-left-radius: 3px;
}

.ai-chat-message.assistant .ai-chat-bubble,
.ai-chat-message.typing .ai-chat-bubble {
    background: #112b49;
    color: #f5f8fc;
    border: 1px solid rgba(148, 184, 224, 0.16);
    border-bottom-right-radius: 3px;
}

.ai-chat-message.error .ai-chat-bubble {
    background: #3b1c25;
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
}

.ai-chat-meta {
    padding: 0 3px;
    color: #7f96b0;
    font-size: 10px;
    line-height: 1.5;
}

.ai-chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 12px 10px;
    background: #0b223e;
}

.ai-chat-action {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 11px;
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.ai-chat-action.primary {
    border: 1px solid #f59e0b;
    background: #f59e0b;
    color: #172033;
}

.ai-chat-action.secondary {
    border: 1px solid rgba(125, 183, 255, 0.45);
    background: #123a65;
    color: #fff;
}

.ai-chat-bubble a {
    color: #93c5fd;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ai-chat-bubble .ai-chat-product-card {
    display: grid;
    gap: 3px;
    margin: 8px 0;
    padding: 10px 11px;
    border: 1px solid rgba(147, 197, 253, 0.34);
    border-radius: 7px;
    background: #102f52;
    color: #fff;
    text-decoration: none;
    transition: border-color 160ms ease, background 160ms ease;
}

.ai-chat-bubble .ai-chat-product-card:hover,
.ai-chat-bubble .ai-chat-product-card:focus-visible {
    border-color: #60a5fa;
    background: #16406d;
}

.ai-chat-product-name { font-weight: 900; }
.ai-chat-product-meta { color: #c7d7e9; font-size: 11px; }
.ai-chat-product-cta { margin-top: 4px; color: #fbbf24; font-size: 11px; font-weight: 900; }

.ai-chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    gap: 8px;
    align-items: center;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px;
    background: #0b223e;
    border-top: 1px solid rgba(148, 184, 224, 0.16);
}

.ai-chat-input-wrap { min-width: 0; overflow: hidden; }
.ai-chat-input-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ai-chat-input {
    box-sizing: border-box;
    width: 100%;
    min-height: 46px;
    max-height: 112px;
    resize: none;
    border: 1px solid rgba(148, 184, 224, 0.24);
    border-radius: 7px;
    background: #061426;
    color: #fff;
    padding: 11px 12px;
    font: inherit;
    font-size: 13px;
    line-height: 1.7;
}

.ai-chat-input::placeholder { color: #738aa4; }
.ai-chat-input:focus {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    border-color: #60a5fa;
}

.ai-chat-send {
    min-width: 48px;
    max-width: 104px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-radius: 7px;
    padding: 0 14px;
    background: #f59e0b;
    color: #172033;
    font: inherit;
    font-size: 12px;
    font-weight: 900;
    cursor: pointer;
}

.ai-chat-send:hover { background: #fbbf24; }
.ai-chat-send:disabled,
.ai-chat-input:disabled { opacity: 0.58; cursor: not-allowed; }

.ai-chat-handoff {
    position: absolute;
    inset: 71px 0 0;
    z-index: 4;
    padding: 16px;
    overflow-y: auto;
    background: #07182d;
    color: #fff;
}

.ai-chat-handoff[hidden] { display: none; }
.ai-chat-handoff-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-chat-handoff-head strong { font-size: 15px; }
.ai-chat-handoff > p {
    margin: 8px 0 14px;
    color: #aebfd3;
    font-size: 12px;
    line-height: 1.8;
}

.ai-chat-handoff > label:not(.ai-chat-consent) {
    display: block;
    margin: 10px 0 5px;
    font-size: 12px;
    font-weight: 800;
}

.ai-chat-handoff label span { color: #aebfd3; font-weight: 500; }
.ai-chat-handoff input[type='text'],
.ai-chat-handoff input[type='tel'] {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid rgba(148, 184, 224, 0.3);
    border-radius: 7px;
    background: #f7fbff;
    color: #102a43;
    font: inherit;
}

.ai-chat-handoff input:focus {
    outline: 3px solid rgba(245, 158, 11, 0.25);
    border-color: #f59e0b;
}

.ai-chat-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 13px 0;
    font-size: 12px;
    line-height: 1.7;
    cursor: pointer;
}

.ai-chat-consent input { flex: 0 0 auto; margin-top: 4px; }
.ai-chat-handoff-submit {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-radius: 7px;
    background: #f59e0b;
    color: #172033;
    font: inherit;
    font-weight: 900;
    cursor: pointer;
}

.ai-chat-handoff-status {
    min-height: 22px;
    margin-top: 9px;
    font-size: 12px;
    line-height: 1.7;
}

.ai-chat-handoff-status.success { color: #86efac; }
.ai-chat-handoff-status.error { color: #fca5a5; }
.ai-chat-typing-dots { display: inline-flex; align-items: center; gap: 5px; }
.ai-chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9fb2c9;
    animation: ai-chat-bounce 1.2s infinite ease-in-out;
}

.ai-chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-chat-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 640px) {
    .ai-chat-widget { left: 12px; right: 12px; bottom: 12px; }
    .ai-chat-toggle { min-width: 48px; padding-inline: 13px; }
    .ai-chat-panel {
        position: fixed;
        inset: 8px;
        width: auto;
        height: calc(100dvh - 16px);
        min-height: 0;
    }
    .ai-chat-widget.is-open .ai-chat-toggle { visibility: hidden; }
    .ai-chat-header { padding: 12px; }
    .ai-chat-subtitle { max-width: 245px; }
    .ai-chat-messages { padding: 12px; }
    .ai-chat-message { max-width: 92%; }
    .ai-chat-form {
        grid-template-columns: minmax(0, 1fr) 48px;
        gap: 8px;
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        overflow: hidden;
    }
    .ai-chat-send {
        width: 48px;
        min-width: 48px;
        max-width: 48px;
        padding: 0;
        overflow: hidden;
    }
    .ai-chat-send span { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chat-toggle,
    .ai-chat-typing-dots span { transition: none; animation: none; }
}
