/* IUM AI chat widget (spec 109 / US3). Framework-free, self-contained,
   RTL/LTR aware via [dir] on the widget root. Brand: #003244 / #0c6277 /
   #32b2d0. Keep everything namespaced under .ai-chat-*. */

.ai-chat-root {
    position: fixed;
    bottom: 96px;
    z-index: 2147483000;
    font-family: inherit;
}

.ai-chat-root[dir="rtl"] { right: 18px; }
.ai-chat-root[dir="ltr"] { left: auto; right: 18px; }

.ai-chat-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: #0c6277;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 50, 68, 0.35);
}

.ai-chat-toggle:hover { background: #003244; }

.ai-chat-toggle:focus-visible,
.ai-chat-panel button:focus-visible,
.ai-chat-input:focus-visible,
.ai-chat-sources a:focus-visible {
    outline: 3px solid #32b2d0;
    outline-offset: 2px;
}

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

.ai-chat-panel {
    position: fixed;
    bottom: 164px;
    inset-inline-end: 18px;
    width: 360px;
    max-width: calc(100vw - 36px);
    height: 480px;
    max-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #d7dee3;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 50, 68, 0.25);
    overflow: hidden;
    box-sizing: border-box;
}

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

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    background: #003244;
    color: #fff;
}

.ai-chat-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
}

.ai-chat-close {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f8fa;
}

.ai-chat-bubble {
    max-width: 85%;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    unicode-bidi: plaintext;
}

.ai-chat-bubble--user {
    align-self: flex-end;
    background: #0c6277;
    color: #fff;
    border-end-end-radius: 4px;
}

.ai-chat-bubble--assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #d7dee3;
    color: #11273d;
    border-end-start-radius: 4px;
}

.ai-chat-bubble--status {
    align-self: center;
    background: #fdf3df;
    border: 1px solid #e6a530;
    color: #11273d;
    font-size: 13px;
    text-align: center;
}

.ai-chat-typing {
    align-self: flex-start;
    color: #0c6277;
    font-size: 13px;
    padding: 2px 6px;
}

.ai-chat-sources {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #d7dee3;
    font-size: 12.5px;
}

.ai-chat-sources-title {
    display: block;
    font-weight: 700;
    color: #0c6277;
    margin-bottom: 2px;
}

.ai-chat-sources a,
.ai-chat-sources span.ai-chat-source-plain {
    display: block;
    color: #0c6277;
    text-decoration: underline;
    word-break: break-all;
}

.ai-chat-sources span.ai-chat-source-plain { text-decoration: none; color: #11273d; }

/* Clickable links inside a reply bubble (inline, wrap long URLs). */
.ai-chat-bubble a.ai-chat-link {
    color: #0c6277;
    text-decoration: underline;
    word-break: break-all;
}
.ai-chat-bubble a.ai-chat-link:hover { color: #11273d; }

.ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #d7dee3;
    background: #fff;
    box-sizing: border-box;
    flex: 0 0 auto;
}

.ai-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid #c6d2d9;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    unicode-bidi: plaintext;
    box-sizing: border-box;
}

.ai-chat-send {
    flex: 0 0 auto;
    border: 0;
    border-radius: 10px;
    background: #0c6277;
    color: #fff;
    padding: 0 16px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-chat-send:disabled,
.ai-chat-input:disabled { opacity: 0.55; cursor: not-allowed; }

@media (max-width: 480px) {
    .ai-chat-root { bottom: 84px; }
    .ai-chat-root[dir="rtl"], .ai-chat-root[dir="ltr"] { right: 10px; }
}

/* ━━ Mobile: full-screen chat layout (same pattern as the portal chat room, 015) ━━
   The panel becomes a fixed full-viewport container so the composer is ALWAYS
   pinned to the bottom like WhatsApp/Telegram, instead of a floating box with
   dead white space. height: 100dvh (dynamic viewport height) tracks the iOS
   Safari keyboard + sliding address bar natively on iOS 15.4+; the dual
   declaration (100vh first, then 100dvh) keeps older browsers working, and the
   widget JS corrects iOS < 15.4 / older Android via visualViewport.
   flex-column inside the panel: header → messages(flex:1) → form.
   font-size:16px on the input prevents iOS from auto-zooming on focus.
   Guard: max-width 767px — desktop is completely untouched. */
@media (max-width: 767px) {
    .ai-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        inset-inline-end: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .ai-chat-header { flex-shrink: 0; }

    .ai-chat-messages {
        flex: 1 1 0;
        min-height: 0;
        height: 0;
        overflow-y: auto;
    }

    .ai-chat-form {
        flex-shrink: 0;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .ai-chat-input { font-size: 16px; }

    /* the launcher would float over the full-screen panel */
    .ai-chat-root.ai-chat-open .ai-chat-toggle { display: none; }
}
