/* =========================================================
   Question AI · chat (CO-0008101)
   Loaded by the tool page (after the first Solve question-ai.js switches it
   to chat mode) and by the read-only shared-chat page. All classes .qai-*.
   ========================================================= */
.qai-app,
.qai-shared,
.qai-modal,
.qai-overlay {
    --qai-blue: #2277AB;
    --qai-blue-soft: #EFF6FF;
    --qai-top: 58px;
    --qai-bottom: 0px; /* the site's fixed footer ad, measured by question-ai.js */
}
.qai-app *,
.qai-shared *,
.qai-share-card,
.qai-share-card *,
.qai-overlay * {
    font-family: 'Inter', sans-serif;
}
.qai-app .katex, .qai-app .katex *,
.qai-shared .katex, .qai-shared .katex * { font-family: KaTeX_Main, 'Times New Roman', serif; }

.qai-panel,
.qai-thread-wrap,
.qai-drawer-backdrop,
.qai-solve-slot:empty { display: none; }
/* Chat mode hides only what the layout marks as page chrome (breadcrumb,
   title, result box, ad row, related, SEO content, footer -- class
   qai-page-chrome in calculator-page / mobile-related / footer), so any
   other overlay, toast or login element on the page stays showable. */
body.qai-chat .qai-page-chrome { display: none !important; }

/* Chat mode: the page container, row, column and tool box around the app
   stop constraining it (full width, no padding) — no 100vw tricks, which
   count the scrollbar and cause a horizontal scroll. */
body.qai-chat .qai-chat-container { max-width: 100% !important; width: 100% !important; padding: 0 !important; margin: 0 !important; }
body.qai-chat .qai-chat-container > .row { margin: 0 !important; }
body.qai-chat .qai-chat-col { flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important; padding: 0 !important; margin: 0 !important; }
body.qai-chat .page-question-ai { padding: 0 !important; margin: 0 !important; background: transparent !important; box-shadow: none !important; }
body.qai-chat { overflow-x: hidden; }

/* The chat is exactly one screen tall (between the sticky header and the
   fixed footer ad) and its messages scroll inside it. */
.qai-app--chat {
    height: calc(100vh - var(--qai-top) - var(--qai-bottom));
    height: calc(100dvh - var(--qai-top) - var(--qai-bottom));
}
.qai-app--chat .qai-thread-wrap { display: block; min-width: 0; min-height: 0; }
.qai-thread { display: flex; flex-direction: column; gap: 26px; padding-bottom: 24px; }

/* ---------- messages ---------- */
.qai-msg { scroll-margin-top: 16px; }
.qai-msg--user { display: flex; justify-content: flex-end; }
.qai-bubble {
    max-width: min(78%, 760px);
    background: #fff;
    border: 1px solid #C9DFF1;
    border-radius: 22px;
    padding: 14px 20px;
    color: #111827;
    font-size: 16px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}
.qai-msg--files .qai-bubble { max-width: 100%; width: 100%; }
.qai-bubble-files { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.qai-bubble-files img { width: 74px; height: 42px; object-fit: cover; border-radius: 4px; border: 1px solid #E5E7EB; background: #fff; }
.qai-bubble-omitted { display: inline-flex; align-items: center; height: 42px; padding: 0 10px; border-radius: 4px; border: 1px dashed #D1D5DB; background: #fff; color: #6B7280; font-size: 12px; }
.qai-bubble-text { white-space: pre-wrap; }
.qai-msg--chip .qai-bubble { padding: 8px 16px; font-size: 14px; color: var(--qai-blue); background: var(--qai-blue-soft); }

.qai-msg--ai { display: flex; gap: 14px; align-items: flex-start; }
.qai-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    background: #fff;
    padding: 1px;
    object-fit: contain;
}
.qai-ai-body { flex: 1; min-width: 0; }
.qai-answer { color: #111827; font-size: 15px; line-height: 1.8; overflow-x: auto; }
.qai-answer ul, .qai-answer ol { padding-left: 1.3em; margin: 4px 0; }
.qai-answer li { margin: 2px 0; }
.qai-answer pre { background: #F3F4F6; padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; }
.qai-answer .own_katex { display: inline-block; max-width: 100%; overflow-x: auto; vertical-align: middle; }
.qai-answer-error { color: #B91C1C; }
.qai-typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.qai-typing span { width: 8px; height: 8px; border-radius: 50%; background: #9CA3AF; animation: qai-blink 1.2s infinite ease-in-out; }
.qai-typing span:nth-child(2) { animation-delay: .2s; }
.qai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes qai-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.qai-ai-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.qai-chips { display: flex; gap: 12px; flex-wrap: wrap; }
.qai-chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    border-radius: 8px;
    border: 1px solid #BFDBFE;
    background: var(--qai-blue-soft);
    color: var(--qai-blue);
    font-size: 15px;
    cursor: pointer;
    transition: filter .15s;
}
.qai-chip-btn--summarize { background: #FAF5FF; border-color: #E9D5FF; color: #9333EA; }
.qai-chip-btn:hover:not(:disabled) { filter: brightness(.97); }
.qai-chip-btn:disabled { opacity: .5; cursor: not-allowed; }
.qai-acts { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.qai-act {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #6B7280;
    cursor: pointer;
}
.qai-act:hover { background: #F3F4F6; color: #111827; }
.qai-act[aria-pressed="true"] { color: var(--qai-blue); background: var(--qai-blue-soft); }
.qai-chip-btn:focus-visible,
.qai-act:focus-visible,
.qai-bm:focus-visible,
.qai-newchat:focus-visible,
.qai-more-btn:focus-visible,
.qai-panel-close:focus-visible,
.qai-share-copy:focus-visible,
.qai-share-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(34, 119, 171, .3);
}

/* In chat mode the input sits at the bottom of the screen, so the "+" and
   answer-mode menus open upwards instead of pushing the page into a scroll. */
.qai-app--chat .qai-shell .qai-menu {
    top: auto;
    bottom: calc(100% + 8px);
}
.qai-app--chat .qai-shell .qai-menu .qai-lang-list { max-height: min(200px, 40vh); }

/* ---------- panel: New Chat + Bookmarks ---------- */
.qai-newchat {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #C9DFF1;
    color: #111827;
    cursor: pointer;
}
.qai-newchat--panel { width: 100%; height: 46px; padding: 0 16px; border-radius: 8px; font-size: 16px; flex-shrink: 0; }
.qai-newchat:hover { border-color: var(--qai-blue); color: var(--qai-blue); }
.qai-bm-head { margin: 18px 0 8px; color: #6B7280; font-size: 16px; }
.qai-bm-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0 10px;
    border-left: 3px solid #E5E7EB;
    max-height: 260px;
    overflow-y: auto;
    flex-shrink: 0;
}
.qai-bm {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #111827;
    font-size: 15px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.qai-bm:hover { background: #F3F4F6; }
.qai-bm.active { background: #EEEEEE; }
.qai-panel-close { display: none; }
.qai-watermark { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 0 10px; opacity: .13; user-select: none; }
.qai-watermark img { width: 100px; height: 100px; filter: grayscale(1) brightness(1.2); }
.qai-watermark span { font-size: 30px; font-weight: 500; letter-spacing: .5px; color: #1E3A5F; white-space: nowrap; }

/* ---------- desktop chat: two columns ---------- */
@media (min-width: 992px) {
    .qai-app--chat {
        display: grid;
        grid-template-columns: 420px minmax(0, 1fr);
        border-bottom: 1px solid #EEF2F7;
    }
    .qai-app--chat .qai-panel {
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow-y: auto;
        background: #F8FAFC;
        padding: 22px 26px 22px 28px;
        border-right: 1px solid #EEF2F7;
    }
    /* the watermark only fills spare height — it shrinks away before the card would overflow */
    .qai-app--chat .qai-watermark { flex: 1 1 0; min-height: 0; overflow: hidden; justify-content: center; padding: 8px 0; }
    .qai-app--chat .qai-watermark img { width: auto; height: auto; max-width: 100px; max-height: 100%; min-height: 0; flex-shrink: 1; }
    .qai-app--chat .qai-panel-slot { flex-shrink: 0; }
    /* only the thread scrolls; the panel stays put */
    .qai-app--chat .qai-thread-wrap { position: relative; overflow-y: auto; padding: 24px 56px 24px 48px; }
    .qai-app--chat .qai-chatbar { display: none; }

    /* the card inside the panel: tabs on two rows, white input box, Solve under it */
    .qai-panel .qai-card { padding: 0; background: transparent; box-shadow: none; gap: 14px; }
    .qai-panel .qai-tabs { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; gap: 10px 8px; }
    .qai-panel .qai-tab { height: 38px; padding: 0 12px; font-size: 14px; }
    /* design order in the panel: Solve, Summarize / AI Search, Ai Writing, Translate */
    .qai-panel .qai-tab[data-tab="solve_all_homework"] { order: 0; }
    .qai-panel .qai-tab[data-tab="summarize"] { order: 1; }
    .qai-panel .qai-tab[data-tab="ai_search"] { order: 2; }
    .qai-panel .qai-tab[data-tab="ai_writing"] { order: 3; }
    .qai-panel .qai-tab[data-tab="translate"] { order: 4; }
    .qai-panel .qai-divider--top { display: none; }
    .qai-panel .qai-box { background: #fff; border-radius: 10px; padding: 16px 18px; border: 1px solid transparent; gap: 14px; }
    .qai-panel .qai-box:focus-within { border-color: var(--qai-blue); }
    .qai-panel .qai-input-area { background: #fff; padding: 0; min-height: 110px; border: none; }
    .qai-panel .qai-input-area #newInput { min-height: 80px !important; }
    .qai-panel .qai-toolbar { justify-content: flex-start; }
    .qai-panel .qai-solve-slot { margin-top: 18px; }
    .qai-panel .qai-solve-slot #convert { width: 100%; height: 48px; border-radius: 8px; }
    .qai-panel #keyboard.qai-kb { margin-top: 14px; }
}

/* ---------- mobile chat: thread + docked input + bookmarks drawer ---------- */
@media (max-width: 991px) {
    /* column: [chat bar] [thread — scrolls] [docked input] */
    .qai-app--chat { display: flex; flex-direction: column; }
    .qai-app--chat .qai-thread-wrap { flex: 1 1 auto; display: flex; flex-direction: column; }
    .qai-app--chat .qai-thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; position: relative; padding: 4px 16px 24px; }
    .qai-chatbar {
        flex: 0 0 auto;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 10px;
        padding: 10px 16px;
        background: #fff;
    }
    .qai-newchat--bar { height: 34px; padding: 0 14px; border-radius: 20px; border-color: #E5E7EB; font-size: 14px; }
    .qai-more-btn {
        width: 34px;
        height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: transparent;
        color: #374151;
        border-radius: 8px;
        cursor: pointer;
    }
    .qai-more-btn[aria-expanded="true"], .qai-more-btn:hover { background: #F3F4F6; }
    .qai-menu--more { left: auto; right: 0; min-width: 150px; }
    .qai-menu--more .qai-menu-item { font-size: 14px; }

    .qai-app--chat .qai-shell {
        flex: 0 0 auto;
        position: relative;
        z-index: 6;
        margin: 0;
        padding: 14px 16px 16px;
        background: #F5F7FA;
    }
    .qai-app--chat .qai-shell::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        height: 60px;
        background: linear-gradient(rgba(255, 255, 255, 0), #fff);
        pointer-events: none;
    }
    .qai-app--chat .qai-card { padding: 0; background: transparent; box-shadow: none; }
    .qai-app--chat .qai-divider--top { display: none; }
    .qai-app--chat .qai-box { background: #fff; border: 1px solid var(--qai-blue); border-radius: 16px; padding: 12px; gap: 12px; }
    .qai-app--chat .qai-input-area { background: #fff; padding: 0; min-height: 90px; border: none; }
    .qai-app--chat .qai-input-area #newInput { min-height: 60px !important; }
    .qai-app--chat .qai-shell.qai-kb-open::before { display: none; }
    /* the keyboard modal (question-ai.css) must win over the docked-input rules above */
    .qai-app--chat .qai-shell.qai-kb-open {
        position: fixed;
        inset: 0;
        z-index: 2147483000;
        margin: 0;
        padding: 16px;
        overflow-y: auto;
        background: rgba(0, 0, 0, .55);
    }

    .qai-bubble { max-width: 88%; font-size: 15px; padding: 12px 16px; border-radius: 18px; }
    .qai-msg--ai { gap: 10px; }
    .qai-avatar { width: 30px; height: 30px; }
    .qai-answer { line-height: 1.7; }
    .qai-ai-foot { margin-top: 16px; }
    .qai-chip-btn { height: 34px; padding: 0 12px; font-size: 14px; }
    .qai-acts { margin-left: 0; }

    /* bookmarks drawer */
    .qai-panel {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 2147482000;
        width: min(82vw, 340px);
        padding: 22px 18px;
        background: #F8FAFC;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .2s ease, visibility .2s;
        box-shadow: 4px 0 24px rgba(0, 0, 0, .15);
        overflow-y: auto;
    }
    .qai-panel.open { transform: translateX(0); visibility: visible; }
    .qai-panel .qai-newchat--panel,
    .qai-panel .qai-watermark,
    .qai-panel .qai-panel-slot { display: none; }
    .qai-panel-close {
        display: inline-flex;
        align-self: flex-end;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: none;
        border-radius: 50%;
        background: #EEF0F3;
        font-size: 14px;
        cursor: pointer;
    }
    .qai-panel .qai-bm-head { margin-top: 0; }
    .qai-panel .qai-bm-list { max-height: none; border-left: none; padding-left: 0; }
    .qai-drawer-backdrop { position: fixed; inset: 0; z-index: 2147481999; background: rgba(0, 0, 0, .45); }
    .qai-drawer-backdrop.open { display: block; }
}

/* ---------- share: overlay + link dialog ---------- */
.qai-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 24, 39, .72);
}
.qai-overlay.d-none { display: none !important; }
.qai-overlay-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; color: #fff; font-size: 26px; font-weight: 600; }
.qai-overlay-inner p { margin: 0; }
.qai-spinner { width: 76px; height: 76px; border-radius: 50%; border: 7px solid #E5E7EB; border-top-color: var(--qai-blue); border-left-color: var(--qai-blue); animation: qai-spin .9s linear infinite; }
@keyframes qai-spin { to { transform: rotate(360deg); } }

.qai-share-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .45);
}
.qai-share-modal.d-none { display: none !important; }
.qai-share-card {
    position: relative;
    width: 100%;
    max-width: 520px;
    background: #fff;
    border-radius: 12px;
    padding: 22px 20px 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}
.qai-share-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: #F3F4F6;
    font-size: 13px;
    cursor: pointer;
}
.qai-share-title { margin: 0; font-size: 20px; font-weight: 700; color: #111827; }
.qai-share-sub { margin: 4px 0 14px; padding-bottom: 14px; border-bottom: 1px solid #EEF0F3; color: #6B7280; font-size: 14px; }
.qai-share-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border: 1px solid #E5E7EB; border-radius: 10px; }
.qai-share-link-ico { color: #6B7280; flex-shrink: 0; }
.qai-share-url { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 14px; color: #374151; }
.qai-share-copy {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 14px;
    border: none;
    border-radius: 8px;
    background: var(--qai-blue);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}
.qai-share-copy:hover { filter: brightness(1.08); }
/* Pro upsell for share — same look as the bulb's "Unlock Advanced Model" modal */
.qai-modal.adv-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2147483100;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: rgb(0 0 0 / .4);
}
.qai-modal.adv-modal.d-none { display: none !important; }
.qai-modal .adv-modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    width: 500px;
    max-width: 100%;
    box-shadow: 0 5px 15px rgba(0, 0, 0, .3);
}
.qai-modal .qai-adv-close { background: none; border: none; padding: 4px; cursor: pointer; line-height: 0; border-radius: 4px; }
.qai-modal .upgrade-pro {
    display: inline-block;
    text-decoration: none;
    background: #1670a7 !important;
    color: #fff;
    padding: 9px 18px;
    font-size: 14px;
    border-radius: 8px;
}
.qai-modal .upgrade-pro:hover { filter: brightness(1.06); color: #fff; }

/* ---------- read-only shared page ---------- */
.qai-shared { max-width: 1100px; margin: 0 auto; padding: 28px 16px 40px; }
.qai-shared-missing { text-align: center; padding: 80px 16px; color: #374151; }
.qai-shared-missing h1 { font-size: 24px; margin-bottom: 8px; color: #111827; }
.qai-shared-notice { background: #fef9c3; border: 1px solid #eab308; color: #713f12; font-size: 13px; line-height: 1.5; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
