.cae-chat {
    --cae-navy-900: #0d1f3c;
    --cae-navy-800: #1b3a6b;
    --cae-navy-700: #1e4d94;
    --cae-navy-100: #e8eef8;
    --cae-slate-50: #f8f9fa;
    --cae-slate-100: #f1f3f5;
    --cae-slate-200: #e9ecef;
    --cae-slate-400: #adb5bd;
    --cae-slate-500: #6c757d;
    --cae-slate-700: #343a40;
    --cae-slate-800: #212529;
    position: fixed;
    right: max(1rem, env(safe-area-inset-right));
    bottom: max(1rem, env(safe-area-inset-bottom));
    z-index: 1200;
    width: min(390px, calc(100vw - 2rem));
    color: var(--cae-slate-800);
    font-family: inherit;
}

.cae-chat,
.cae-chat * {
    box-sizing: border-box;
}

.cae-chat__panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: min(600px, calc(100vh - 5.75rem));
    min-height: 380px;
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cae-slate-200);
    border-radius: 10px;
    box-shadow: 0 14px 40px rgba(13, 31, 60, 0.22), 0 3px 10px rgba(13, 31, 60, 0.12);
}

.cae-chat__panel[hidden] {
    display: none;
}

.cae-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    color: #fff;
    background: var(--cae-navy-900);
    border-bottom: 3px solid var(--cae-navy-700);
}

.cae-chat__eyebrow {
    margin: 0 0 0.15rem;
    color: #90b8f0;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    line-height: 1.2;
    text-transform: uppercase;
}

.cae-chat__title {
    margin: 0;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
}

.cae-chat__close,
.cae-chat__trigger,
.cae-chat__sample,
.cae-chat__submit {
    font: inherit;
    cursor: pointer;
}

.cae-chat__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    padding: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 1.35rem;
    line-height: 1;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 4px;
}

.cae-chat__close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.cae-chat__intro {
    margin: 0;
    color: var(--cae-slate-700);
    font-size: 0.84rem;
    line-height: 1.55;
}

.cae-chat__context {
    padding: 0.9rem 1rem 0.75rem;
    background: var(--cae-slate-50);
    border-bottom: 1px solid var(--cae-slate-200);
}

.cae-chat__sample {
    width: 100%;
    margin-top: 0.65rem;
    padding: 0.55rem 0.7rem;
    color: var(--cae-navy-700);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    background: #fff;
    border: 1px solid var(--cae-navy-100);
    border-radius: 5px;
}

.cae-chat__sample:hover {
    background: var(--cae-navy-100);
    border-color: #b8cceb;
}

.cae-chat__messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.7rem;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
}

.cae-chat__message {
    max-width: 88%;
    padding: 0.65rem 0.75rem;
    overflow-wrap: anywhere;
    font-size: 0.84rem;
    line-height: 1.55;
    white-space: normal;
    border: 1px solid transparent;
    border-radius: 8px;
}

.cae-chat__message--assistant {
    align-self: flex-start;
    color: var(--cae-slate-800);
    background: var(--cae-slate-50);
    border-color: var(--cae-slate-200);
}

.cae-chat__message--user {
    align-self: flex-end;
    color: #fff;
    background: var(--cae-navy-800);
}

.cae-chat__message--error {
    color: #7a271a;
    background: #fff5f2;
    border-color: #f0b8aa;
}

.cae-chat__message--loading {
    color: var(--cae-slate-500);
    font-style: italic;
}

.cae-chat__message--loading::after {
    display: inline-block;
    width: 1.25em;
    overflow: hidden;
    vertical-align: bottom;
    content: '...';
    animation: cae-chat-dots 1.2s steps(4, end) infinite;
}

.cae-chat__message a {
    color: var(--cae-navy-700);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.cae-chat__message a:hover {
    color: var(--cae-navy-900);
}

.cae-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
    padding: 0.75rem;
    background: #fff;
    border-top: 1px solid var(--cae-slate-200);
}

.cae-chat__input {
    width: 100%;
    min-height: 2.75rem;
    max-height: 7rem;
    resize: vertical;
    padding: 0.65rem 0.7rem;
    color: var(--cae-slate-800);
    font: inherit;
    font-size: 0.84rem;
    line-height: 1.4;
    background: var(--cae-slate-50);
    border: 1px solid var(--cae-slate-300, #dee2e6);
    border-radius: 5px;
}

.cae-chat__input::placeholder {
    color: var(--cae-slate-500);
}

.cae-chat__submit {
    min-height: 2.75rem;
    flex: 0 0 auto;
    padding: 0.65rem 0.8rem;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--cae-navy-700);
    border: 1px solid var(--cae-navy-700);
    border-radius: 5px;
}

.cae-chat__submit:hover {
    background: var(--cae-navy-900);
    border-color: var(--cae-navy-900);
}

.cae-chat__trigger {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2.8rem;
    margin-left: auto;
    padding: 0.65rem 0.85rem;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--cae-navy-900);
    border: 1px solid var(--cae-navy-700);
    border-radius: 7px;
    box-shadow: 0 7px 20px rgba(13, 31, 60, 0.24);
}

.cae-chat__trigger:hover {
    background: var(--cae-navy-800);
}

.cae-chat__trigger-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    color: #bcd4f7;
    font-size: 0.9rem;
    border: 1px solid rgba(188, 212, 247, 0.55);
    border-radius: 50%;
}

.cae-chat button:focus-visible,
.cae-chat textarea:focus-visible,
.cae-chat a:focus-visible {
    outline: 3px solid #f6c945;
    outline-offset: 3px;
}

.cae-chat button:disabled,
.cae-chat textarea:disabled {
    cursor: wait;
    opacity: 0.62;
}

@media (prefers-color-scheme: dark) {
    .cae-chat {
        --cae-navy-900: #081326;
        --cae-navy-800: #15345f;
        --cae-navy-700: #4d8bdc;
        --cae-navy-100: #29466c;
        --cae-slate-50: #182333;
        --cae-slate-100: #202d3d;
        --cae-slate-200: #334155;
        --cae-slate-300: #475569;
        --cae-slate-400: #94a3b8;
        --cae-slate-500: #aab7c7;
        --cae-slate-700: #d4dde8;
        --cae-slate-800: #e7edf5;
    }

    .cae-chat__panel {
        background: #101b2d;
        border-color: #3b4d67;
        box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5), 0 3px 10px rgba(0, 0, 0, 0.32);
    }

    .cae-chat__header {
        background: #081326;
        border-bottom-color: #4d8bdc;
    }

    .cae-chat__context,
    .cae-chat__messages,
    .cae-chat__form {
        background: #101b2d;
        border-color: #334155;
    }

    .cae-chat__intro,
    .cae-chat__message--assistant {
        color: #d4dde8;
    }

    .cae-chat__sample {
        color: #b9d6ff;
        background: #182b48;
        border-color: #416895;
    }

    .cae-chat__sample:hover {
        color: #e1edff;
        background: #213d64;
        border-color: #78aef2;
    }

    .cae-chat__message--assistant {
        background: #1b2b40;
        border-color: #3b4d67;
    }

    .cae-chat__message--user {
        color: #fff;
        background: #15345f;
    }

    .cae-chat__message--error {
        color: #fecaca;
        background: #35191d;
        border-color: #8f4148;
    }

    .cae-chat__message--loading {
        color: #aab7c7;
    }

    .cae-chat__message a {
        color: #9bc6ff;
    }

    .cae-chat__message a:hover {
        color: #d2e5ff;
    }

    .cae-chat__input {
        color: #e7edf5;
        background: #182333;
        border-color: #51657e;
    }

    .cae-chat__input::placeholder {
        color: #9aaabd;
    }

    .cae-chat__submit {
        background: #2867b8;
        border-color: #6fa9f2;
    }

    .cae-chat__submit:hover {
        background: #3578c9;
        border-color: #8fc2ff;
    }

    .cae-chat__trigger {
        background: #081326;
        border-color: #4d8bdc;
        box-shadow: 0 7px 20px rgba(0, 0, 0, 0.42);
    }

    .cae-chat__trigger:hover {
        background: #15345f;
    }

    .cae-chat__trigger-icon {
        color: #b9d6ff;
        border-color: rgba(185, 214, 255, 0.65);
    }
}

@keyframes cae-chat-dots {
    0% { width: 0; }
    33% { width: 0.4em; }
    66% { width: 0.8em; }
    100% { width: 1.25em; }
}

@media (max-width: 600px) {
    .cae-chat {
        right: max(0.75rem, env(safe-area-inset-right));
        left: max(0.75rem, env(safe-area-inset-left));
        width: auto;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .cae-chat__panel {
        height: min(600px, calc(100vh - 5rem));
        height: min(600px, calc(100dvh - 5rem));
        min-height: 320px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cae-chat *,
    .cae-chat *::before,
    .cae-chat *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
