/* =============================================
   AI Assistant — Chat UI Styles
   ============================================= */

/* ── Google Fonts (self-contained) ─────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&family=Source+Sans+3:wght@400;600&display=swap');

/* ── FAB (Floating Action Button) ──────────────── */

.ai-fab {
    position: fixed;
    bottom: 32px;
    right: 28px;
    z-index: 1047;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: #e15200;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(225, 82, 0, 0.35);
    transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
    font-size: 20px;
}

.ai-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(225, 82, 0, 0.45);
}

.ai-fab.open {
    display: none;
}

/* ── AI Slide Overlay ───────────────────────────── */

.ai-slide-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1048;
    background: rgba(0, 0, 0, 0.3);
}

.ai-slide-overlay.show {
    display: block;
}

/* ── AI Slide Panel ─────────────────────────────── */

.ai-slide-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 420px;
    height: 100vh;
    z-index: 1049;
    background: #f8f9fa;
    border-left: 1px solid #e3e6ea;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    transition: right 0.35s ease;
    display: flex;
    flex-direction: column;
}

.ai-slide-panel.open {
    right: 0;
}

.ai-slide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #e3e6ea;
    flex-shrink: 0;
    background: #fff;
    font-family: Inter, sans-serif;
}

.ai-slide-header .ai-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #e15200;
    font-size: 15px;
}

.ai-slide-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-close-btn,
.ai-expand-btn,
.ai-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 32px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid #e3e6ea;
    background: transparent;
    color: #6c757d;
    cursor: pointer;
    font-size: 13px;
    font-family: Inter, sans-serif;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ai-close-btn:hover {
    background: #dc3545;
    color: #fff;
    border-color: #dc3545;
}

.ai-expand-btn:hover,
.ai-new-chat-btn:hover {
    background: rgba(74, 48, 36, 0.07);
    color: #e15200;
    border-color: #e15200;
}

.ai-slide-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-slide-panel .cse-ai__reset {
    display: none;
}

/* ── Page wrapper (full-page view) ─────────────── */

.ai-page-wrapper {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

.ai-page-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 24px 0 20px;
    border-bottom: 1px solid #e3e6ea;
    font-family: Inter, sans-serif;
}

.ai-page-header .ai-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #e15200;
    font-size: 18px;
}

.ai-page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-page-subtitle {
    flex-basis: 100%;
    margin: 0;
    font-size: 14px;
    color: #6c757d;
    font-family: "Source Sans 3", sans-serif;
}

.ai-page-chat {
    height: calc(100vh - 220px);
    min-height: 400px;
    display: flex;
    flex-direction: column;
    border: 1px solid #e3e6ea;
    border-top: none;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

/* ── .cse-ai — isolated messaging area ─────────── */

.cse-ai {
    /* own design tokens — no theme/Bootstrap vars */
    --bg:         #f8f9fa;
    --card:       #ffffff;
    --accent:     #e15200;
    --accent-dark:#c74800;
    --txt:        #212529;
    --muted:      #6c757d;
    --border:     #e3e6ea;
    --code-bg:    #f4f5f7;

    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14.5px;
    color: var(--txt);
    box-sizing: border-box;
}

.cse-ai *,
.cse-ai *::before,
.cse-ai *::after {
    box-sizing: border-box;
}

/* Header */

.cse-ai__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.cse-ai__titles h1 {
    font-family: Inter, sans-serif;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--txt);
    line-height: 1.3;
}

.cse-ai__sub {
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 3px;
}

.cse-ai__reset {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #fff;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13.5px;
    font-family: inherit;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.cse-ai__reset:hover {
    background: var(--accent);
    color: #fff;
}

/* Message feed */

.cse-ai__chat {
    flex: 1;
    overflow-y: auto;
    padding: 26px 24px;
    background: var(--bg);
}

.cse-ai__chat::-webkit-scrollbar { width: 10px; }
.cse-ai__chat::-webkit-scrollbar-thumb { background: #d7dade; border-radius: 6px; }

.cse-ai__inner {
    max-width: 860px;
    margin: 0 auto;
}

/* Bubbles */

.cse-ai .msg {
    margin: 16px 0;
    display: flex;
}

.cse-ai .msg:first-child {
    margin-top: 0;
}

.cse-ai .msg.user {
    justify-content: flex-end;
}

.cse-ai .bubble {
    max-width: 82%;
    padding: 13px 17px;
    border-radius: 14px;
    line-height: 1.55;
    font-size: 14.5px;
    overflow-wrap: anywhere;
}

.cse-ai .user .bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.cse-ai .bot .bubble {
    background: var(--card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    color: var(--txt);
}

/* Markdown inside bot bubble */

.cse-ai .bot .bubble pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 12px 13px;
    border-radius: 9px;
    overflow-x: auto;
    font-size: 12.7px;
    margin: 8px 0;
}

.cse-ai .bot .bubble code {
    font-family: SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.cse-ai .bot .bubble :not(pre) > code {
    background: var(--code-bg);
    padding: 1.5px 5px;
    border-radius: 4px;
    font-size: 12.7px;
    color: var(--accent-dark);
}

.cse-ai .bot .bubble table {
    border-collapse: collapse;
    margin: 9px 0;
    font-size: 13.5px;
    width: 100%;
}

.cse-ai .bot .bubble th,
.cse-ai .bot .bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.cse-ai .bot .bubble th {
    background: var(--code-bg);
}

.cse-ai .bot .bubble h1,
.cse-ai .bot .bubble h2,
.cse-ai .bot .bubble h3 {
    font-family: Inter, sans-serif;
    color: var(--accent);
    font-size: 15px;
    margin: 12px 0 6px;
    font-weight: 600;
}

.cse-ai .bot .bubble a {
    color: var(--accent-dark);
}

.cse-ai .bot .bubble p:first-child { margin-top: 0; }
.cse-ai .bot .bubble p:last-child  { margin-bottom: 0; }

/* Sources block */

.cse-ai .sources {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 9px;
    border-top: 1px dashed var(--border);
    padding-top: 7px;
}

/* Typing indicator */

.cse-ai .typing {
    color: var(--muted);
    font-style: italic;
    font-size: 13.5px;
}

/* Footer / input area */

.cse-ai__footer {
    padding: 16px 24px;
    background: var(--card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.cse-ai__inputrow {
    display: flex;
    gap: 11px;
    max-width: 860px;
    margin: 0 auto;
    align-items: flex-end;
}

.cse-ai__input {
    flex: 1;
    resize: none;
    background: #fff;
    color: var(--txt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 15px;
    font-size: 14.5px;
    font-family: inherit;
    height: 48px;
    min-height: 48px;
    max-height: 170px;
    overflow-y: hidden;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cse-ai__input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225, 82, 0, 0.12);
}

.cse-ai__input::placeholder {
    color: var(--muted);
}

.cse-ai__send {
    height: 48px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0 24px;
    font-size: 14.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.cse-ai__send:hover {
    background: var(--accent-dark);
}

.cse-ai__send:disabled {
    opacity: 0.5;
    cursor: default;
}

.cse-ai__hint {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin-top: 9px;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 1399.98px) {
    .ai-slide-panel {
        width: 100vw;
        right: -100vw;
    }
}

@media (max-width: 767.98px) {
    .ai-fab {
        bottom: 20px;
        right: 16px;
    }

    .ai-page-wrapper {
        padding: 0;
        margin-right: -5px;
        margin-left: -5px;
    }

    .ai-page-header {
        padding: 10px 0 8px;
        gap: 4px;
        border-bottom-color: #e3e6ea;
    }

    .ai-page-header .ai-title {
        font-size: 14px;
        gap: 6px;
    }

    .ai-page-header .ai-title .bi-stars {
        font-size: 15px;
    }

    .ai-page-subtitle {
        font-size: 12px;
        color: #8a929a;
    }

    .ai-page-chat {
        height: calc(100dvh - 140px);
        height: calc(100vh - 140px);
        min-height: 300px;
    }

    .cse-ai__header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .cse-ai__titles h1 {
        font-size: 13px;
    }

    .cse-ai__sub {
        font-size: 11px;
        margin-top: 2px;
    }

    .cse-ai__chat {
        padding: 10px 12px;
    }

    .cse-ai__footer {
        padding: 8px 12px;
    }

    .cse-ai__inputrow {
        gap: 6px;
        flex-direction: column;
        align-items: stretch;
    }

    .cse-ai__input {
        font-size: 13px;
        padding: 10px 12px;
        height: 42px;
        min-height: 42px;
    }

    .cse-ai__send {
        width: 100%;
        height: 42px;
        padding: 0 14px;
        font-size: 13.5px;
    }

    .cse-ai .bubble {
        max-width: 96%;
        font-size: 13px;
        padding: 10px 12px;
    }

    .cse-ai__reset {
        padding: 5px 8px;
        font-size: 12px;
    }

    .cse-ai__hint {
        display: none;
    }
}

/* =============================================
   AI Assistant — Dark Theme
   ============================================= */

[data-bs-theme="dark"] .ai-slide-panel {
    background: #1a1d21;
    border-left-color: #3a3f44;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="dark"] .ai-slide-header {
    background: #23272b;
    border-bottom-color: #3a3f44;
}

[data-bs-theme="dark"] .ai-close-btn,
[data-bs-theme="dark"] .ai-expand-btn,
[data-bs-theme="dark"] .ai-new-chat-btn {
    border-color: #3a3f44;
    color: #9aa0a6;
}

[data-bs-theme="dark"] .ai-close-btn:hover {
    background: #dc3545;
    color: #fff;
    border-color: #dc3545;
}

[data-bs-theme="dark"] .ai-expand-btn:hover,
[data-bs-theme="dark"] .ai-new-chat-btn:hover {
    background: rgba(225, 82, 0, 0.15);
    color: #e15200;
    border-color: #e15200;
}

[data-bs-theme="dark"] .ai-page-header {
    border-bottom-color: #3a3f44;
}

[data-bs-theme="dark"] .ai-page-subtitle {
    color: #9aa0a6;
}

[data-bs-theme="dark"] .ai-page-chat {
    border-color: #3a3f44;
}

[data-bs-theme="dark"] .cse-ai {
    --bg:       #1a1d21;
    --card:     #23272b;
    --txt:      #e4e6eb;
    --muted:    #9aa0a6;
    --border:   #3a3f44;
    --code-bg:  #2b2f33;
}

[data-bs-theme="dark"] .cse-ai__input {
    background: #2b2f33;
    color: #e4e6eb;
}

[data-bs-theme="dark"] .cse-ai__reset {
    background: transparent;
}

[data-bs-theme="dark"] .cse-ai__reset:hover {
    background: #e15200;
    color: #fff;
}

[data-bs-theme="dark"] .cse-ai__chat::-webkit-scrollbar-thumb {
    background: #3a3f44;
}

[data-bs-theme="dark"] .cse-ai .bot .bubble {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
