/* Chat component — the compiled app.css does not include these utilities */
.conversation-page {
    height: 100vh;
}

#chat-sidebar {
    width: 25%;
    min-width: 280px;
}

.conversation-page > section.chat-main {
    width: 75%;
}

#chat-form {
    width: 75%;
    max-width: 860px;
    margin-inline: auto;
    margin-bottom: 1rem;
}

#chat-messages {
    width: 75%;
    max-width: 860px;
    margin-inline: auto;
    padding: 20px 0;
}

/* Header (class renamed from `header` to avoid the generic .header rule in app.css) */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 1.5rem;
    border-bottom: 1px solid #E8E4DC;
}

.chat-header .header-title {
    color: #102544;
    font-size: 16px;
    font-weight: 600;
}

.chat-header .header-sub {
    color: #9CA3AF;
    font-size: 12px;
}

/* Sidebar polish */
#chat-sidebar .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: #102544;
}

#chat-sidebar .brand-mark img {
    height: 20px;
}

#chat-sidebar .brand-title {
    color: #102544;
    font-size: 14px;
}

#chat-sidebar .brand-sub {
    color: rgba(16, 37, 68, .42);
    font-size: 11px;
}

#chat-sidebar .new-con {
    padding: 8px 24px;
}

#chat-sidebar .section-label {
    color: #9CA3AF;
    font-size: 12px;
    font-weight: 600;
}

#chat-sidebar .conv-card {
    padding: 10px;
    border-radius: 10px;
}

#chat-sidebar .conv-card .icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #F4F1EB;
    color: #1A3A6B;
}

#chat-sidebar .conv-card.active .icon,
#chat-sidebar .conv-card:hover .icon {
    background: #102544;
    color: #fff;
}

#chat-sidebar .conv-card h3 {
    color: #102544;
    font-size: 14px;
    font-weight: 600;
}

#chat-sidebar .conv-card p {
    color: #9CA3AF;
    font-size: 12px;
}

#chat-sidebar .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-sidebar .conv-empty {
    color: #9CA3AF;
    font-size: 12px;
}

/* Message rows — avatar and bubble always on the same flex line */
#chat-messages .ask-ai-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
}

#chat-messages .ask-ai-msg-row:last-child {
    margin-bottom: 0;
}

#chat-messages .ask-ai-msg-row-user {
    justify-content: flex-end;
}

/* Avatars — visual anchors, aligned to the top of the bubble */
#chat-messages .ask-ai-avatar {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#chat-messages .ask-ai-avatar-bot {
    background: #102544;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .12);
    box-shadow: 0 2px 8px 0 rgba(16, 37, 68, .18);
}

#chat-messages .ask-ai-avatar-user {
    background: #0d1b2a;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 2px 8px 0 rgba(13, 27, 42, .18);
}

#chat-messages .ask-ai-avatar img {
    height: 26px;
    width: 26px;
    object-fit: contain;
}

#chat-messages .ask-ai-avatar-user img {
    height: 100%;
    width: 100%;
    object-fit: cover;
}

/* User message — right-aligned dark bubble, fits content */
#chat-messages .ai-msg {
    width: fit-content;
    max-width: 65%;
    background: #0d1b2a;
    color: #fff;
    padding: 12px 18px;
    border-radius: 18px;
    border-end-end-radius: 6px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.7;
    box-shadow: 0 2px 8px 0 rgba(16, 37, 68, .14);
}

/* Assistant message — left-aligned white bubble, mirrors user */
#chat-messages .bot-msg {
    width: fit-content;
    max-width: 65%;
    background: #fff;
    color: #1f2937;
    padding: 12px 18px;
    border-radius: 18px;
    border-end-start-radius: 6px;
    border: 1px solid #E8E4DC;
    box-shadow: 0 2px 10px 0 rgba(16, 37, 68, .06);
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.7;
    animation: chat-fade-in .25s ease-out;
}

#chat-messages .msg-empty {
    min-height: 1.5em;
}

@keyframes chat-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Empty state */
.chat-empty {
    color: #9CA3AF;
    font-size: 14px;
    padding-top: 60px;
}

/* Composer */
#chat-input {
    padding: 16px;
    padding-bottom: 44px;
    padding-inline-end: 88px;
    border-radius: 12px;
    border: 1px solid #E8E4DC;
    box-shadow: 0 1px 4px 0 rgba(16, 37, 68, .06);
    resize: none;
    background: #fff;
    max-height: 160px;
    font-size: 15px;
    line-height: 1.6;
    transition: border-color .15s ease, box-shadow .15s ease;
}

#chat-input:focus {
    outline: none;
    border-color: #102544;
    box-shadow: 0 0 0 3px rgba(16, 37, 68, .08);
}

#chat-input:read-only {
    background: #FAF8F4;
}

/* Composer action buttons. The compiled app.css lacks the livewire chat
   arbitrary classes (top-[10px], end-[10px]), so anchor them here with a
   physical `right` fallback: `inset-inline-end` alone is ignored by older
   mobile browsers, which then drops the buttons out of the input. */
.chat-composer-field {
    position: relative;
}

.composer-actions {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    top: 10px;
    right: 10px;
    inset-inline-end: 10px;
    z-index: 2;
}

.conversation-page[dir="rtl"] .composer-actions {
    right: auto;
    left: 10px;
}

.composer-footer {
    position: absolute;
}

.composer-mic {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid #E8E4DC;
    color: #9CA3AF;
    transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}

.composer-mic:hover:not(:disabled) {
    color: #6B7280;
    background: #FAF8F4;
}

.composer-mic:disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* Recording state lives on <body> so Livewire re-renders cannot wipe it. */
body.chat-recording .composer-mic {
    color: #fff;
    background: #C1272D;
    border-color: #C1272D;
    animation: chat-mic-pulse 1.4s ease-in-out infinite;
}

body.chat-transcribing .composer-mic {
    color: #9CA3AF;
    pointer-events: none;
    opacity: .6;
}

@keyframes chat-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(193, 39, 45, .45); }
    50% { box-shadow: 0 0 0 6px rgba(193, 39, 45, 0); }
}

@media (prefers-reduced-motion: reduce) {
    body.chat-recording .composer-mic { animation: none; }
}

.composer-voice-hint {
    color: #6B7280;
    opacity: 0;
    transition: opacity .15s ease;
    text-align: end;
}

.composer-voice-hint.is-visible {
    opacity: 1;
}

body.chat-recording .composer-voice-hint {
    color: #C1272D;
}

#chat-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid #E8E4DC;
}

#chat-send:disabled {
    opacity: .5;
}

.composer-footer {
    bottom: 16px;
    inset-inline: 10px;
    width: calc(100% - 20px);
}

.composer-hint {
    color: #9CA3AF;
    font-size: 12px;
}

/* Typing indicator (CSS only) */
.ask-ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 20px;
}

.ask-ai-typing .ask-ai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 9999px;
    background: currentColor;
    opacity: .35;
    animation: ask-ai-blink 1.2s ease-in-out infinite;
}

.ask-ai-typing .ask-ai-typing-dot:nth-child(2) {
    animation-delay: .15s;
}

.ask-ai-typing .ask-ai-typing-dot:nth-child(3) {
    animation-delay: .3s;
}

@keyframes ask-ai-blink {
    0%, 60%, 100% {
        opacity: .25;
        transform: scale(.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Error bubble */
.bot-msg.bot-msg-error {
    color: #ef4444;
}

/* Responsive — bubbles shrink naturally on small screens */
@media (max-width: 768px) {
    #chat-messages .ai-msg,
    #chat-messages .bot-msg {
        max-width: 85%;
    }

    #chat-messages .ask-ai-msg-row {
        gap: 10px;
        margin-bottom: 18px;
    }

    #chat-messages .ask-ai-avatar {
        width: 36px;
        height: 36px;
    }

    #chat-messages .ask-ai-avatar img {
        height: 22px;
        width: 22px;
    }

    #chat-messages .ask-ai-avatar-user {
        font-size: 14px;
    }
}

/* Drawer backdrop — hidden on desktop, only relevant on small screens */
.chat-drawer-backdrop {
    display: none;
}

/* Mobile (< md = 768px): the conversation list becomes an off-canvas drawer,
   the chat column goes full width, and the page uses the dynamic viewport so
   the composer is never hidden behind the browser chrome/keyboard. */
@media (max-width: 767px) {
    .conversation-page {
        height: 100vh; /* fallback for browsers without dvh */
        height: 100dvh;
    }

    .conversation-page > section.chat-main,
    #chat-form,
    #chat-messages {
        width: 100%;
        max-width: 100%;
    }

    #chat-form,
    #chat-messages {
        margin-inline: 0;
    }

    #chat-messages {
        padding-left: 16px;
        padding-right: 16px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* The absolute send/mic buttons float over the textarea's right edge;
       the native scrollbar renders on that same edge and visually merges
       with the icons. Hide the UA scrollbar on mobile (scrolling itself
       still works); the padding-inline-end:88px keeps text clear. */
    #chat-input {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #chat-input::-webkit-scrollbar {
        display: none;
    }

    .chat-header {
        padding: 14px 16px;
    }

    /* The sidebar cannot sit beside a 100vw chat column on phones */
    #chat-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 70;
        width: min(320px, 86vw);
        max-width: 86vw;
        min-width: 0;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        box-shadow: 0 24px 60px -12px rgba(8, 26, 58, .35);
        transform: translateX(-105%);
        visibility: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        transition: transform .28s cubic-bezier(.25, .46, .45, .94),
            visibility 0s linear .28s;
    }

    .conversation-page[dir="rtl"] #chat-sidebar {
        left: auto;
        right: 0;
        transform: translateX(105%);
    }

    body.chat-drawer-open #chat-sidebar,
    body.chat-drawer-open .conversation-page[dir="rtl"] #chat-sidebar {
        transform: translateX(0);
        visibility: visible;
        transition-delay: 0s;
    }

    .chat-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 69;
        background: rgba(8, 26, 58, .45);
        opacity: 0;
        visibility: hidden;
        transition: opacity .28s ease, visibility .28s ease;
    }

    body.chat-drawer-open .chat-drawer-backdrop {
        opacity: 1;
        visibility: visible;
    }
}
