/* ================================================================
   chat.css — Floating AI Chat Widget
   Appears on every page via _navbar.html injection
   ================================================================ */

/* ── Floating trigger button ──────────────────────────────────── */
.chat-fab {
    position: fixed;
    bottom: 1.75rem;
    right: 1.75rem;
    width: auto;
    min-width: 64px;
    height: 64px;
    border-radius: 32px;
    background: linear-gradient(135deg, #8b5cf6, #06b6d4);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px 0 16px;
    box-shadow: 0 6px 28px rgba(139,92,246,0.55), 0 0 0 3px rgba(139,92,246,0.15);
    z-index: 8000;
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.2s ease;
    outline: none;
    animation: fab-pulse 3s ease-in-out infinite;
}
@keyframes fab-pulse {
    0%, 100% { box-shadow: 0 6px 28px rgba(139,92,246,0.55), 0 0 0 3px rgba(139,92,246,0.15); }
    50% { box-shadow: 0 6px 36px rgba(139,92,246,0.75), 0 0 0 6px rgba(139,92,246,0.1); }
}
.chat-fab:hover {
    transform: scale(1.06) translateY(-3px);
    box-shadow: 0 10px 36px rgba(139,92,246,0.7);
    animation: none;
}
.chat-fab:active { transform: scale(0.97); }
.chat-fab svg { width: 28px; height: 28px; color: #fff; flex-shrink: 0; }
.chat-fab-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
@media (max-width: 480px) {
    .chat-fab { padding: 0; width: 60px; border-radius: 50%; }
    .chat-fab-label { display: none; }
}

/* Unread badge */
.chat-fab-badge {
    position: absolute;
    top: -2px; right: -2px;
    width: 18px; height: 18px;
    background: #ef4444;
    border: 2px solid #0a0a0f;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 800;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    display: none;
}
.chat-fab-badge.show { display: flex; }

/* ── Chat window ──────────────────────────────────────────────── */
.chat-window {
    position: fixed;
    bottom: 5.5rem;
    right: 1.75rem;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 7rem);
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 8001;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(139,92,246,0.15);
    transform: scale(0.85) translateY(24px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
                opacity   0.2s ease;
    transform-origin: bottom right;
}
.chat-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ───────────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    background: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(6,182,212,0.06));
    border-bottom: 1px solid #27272a;
    flex-shrink: 0;
}
.chat-header-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #06b6d4);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: #e4e4e7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-status {
    font-size: 0.7rem;
    color: #52525b;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 1px;
}
.chat-status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #22c55e;
    animation: statusPulse 2s infinite;
}
@keyframes statusPulse {
    0%,100% { opacity: 1; }
    50%      { opacity: 0.4; }
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.chat-icon-btn {
    width: 30px; height: 30px;
    border: none;
    background: transparent;
    border-radius: 7px;
    color: #52525b;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.chat-icon-btn:hover { background: rgba(255,255,255,0.06); color: #a1a1aa; }
.chat-icon-btn svg { width: 15px; height: 15px; }

/* ── Session sidebar ──────────────────────────────────────────── */
.chat-sidebar {
    display: none;
    flex-direction: column;
    border-right: 1px solid #27272a;
    width: 100%;
    flex-shrink: 0;
    overflow: hidden;
}
.chat-sidebar.open { display: flex; }
.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #27272a;
}
.chat-sidebar-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #a1a1aa;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.btn-new-chat {
    display: flex; align-items: center; gap: 4px;
    padding: 0.3rem 0.65rem;
    background: rgba(139,92,246,0.15);
    border: 1px solid rgba(139,92,246,0.3);
    border-radius: 6px;
    color: #a78bfa;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-new-chat:hover { background: rgba(139,92,246,0.25); }
.chat-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
}
.chat-sessions-list::-webkit-scrollbar { width: 3px; }
.chat-sessions-list::-webkit-scrollbar-thumb { background: #27272a; border-radius: 2px; }
.session-item {
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.session-item:hover { background: rgba(255,255,255,0.04); }
.session-item.active { background: rgba(139,92,246,0.1); }
.session-item-title {
    font-size: 0.82rem;
    color: #e4e4e7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.session-item-time {
    font-size: 0.68rem;
    color: #52525b;
    white-space: nowrap;
    flex-shrink: 0;
}
.session-delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: opacity 0.15s;
    font-size: 0.7rem;
}
.session-item:hover .session-delete-btn { opacity: 1; }

/* ── Messages area ────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #27272a; border-radius: 2px; }

/* ── Message bubbles ──────────────────────────────────────────── */
.chat-msg {
    display: flex;
    gap: 0.6rem;
    animation: msgIn 0.2s ease;
    max-width: 100%;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    margin-top: 2px;
}
.chat-msg.assistant .msg-avatar {
    background: linear-gradient(135deg, #8b5cf6, #06b6d4);
}
.chat-msg.user .msg-avatar {
    background: rgba(139,92,246,0.2);
    border: 1px solid rgba(139,92,246,0.3);
    font-weight: 700;
    color: #a78bfa;
    font-size: 0.65rem;
}

.msg-bubble {
    max-width: calc(100% - 44px);
    padding: 0.65rem 0.9rem;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.chat-msg.assistant .msg-bubble {
    background: #1e1e24;
    border: 1px solid #27272a;
    border-top-left-radius: 4px;
    color: #d4d4d8;
}
.chat-msg.user .msg-bubble {
    background: linear-gradient(135deg, rgba(139,92,246,0.25), rgba(6,182,212,0.15));
    border: 1px solid rgba(139,92,246,0.25);
    border-top-right-radius: 4px;
    color: #e4e4e7;
}

/* Markdown rendering inside bubbles */
.msg-bubble p  { margin: 0 0 0.4em; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 0.3em 0 0.3em 1.1em; padding: 0; }
.msg-bubble li { margin-bottom: 0.2em; }
.msg-bubble code {
    background: rgba(0,0,0,0.3);
    border: 1px solid #27272a;
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.8em;
    font-family: 'DM Mono', 'Courier New', monospace;
    color: #a78bfa;
}
.msg-bubble pre {
    background: #09090b;
    border: 1px solid #27272a;
    border-radius: 8px;
    padding: 0.75rem;
    overflow-x: auto;
    margin: 0.4em 0;
}
.msg-bubble pre code {
    background: none;
    border: none;
    padding: 0;
    color: #e4e4e7;
}
.msg-bubble strong { color: #e4e4e7; font-weight: 700; }
.msg-bubble em { color: #a78bfa; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #e4e4e7;
    margin: 0.5em 0 0.2em;
}

/* ── Typing indicator ─────────────────────────────────────────── */
.chat-typing {
    display: none;
    align-items: center;
    gap: 0.6rem;
}
.chat-typing.show { display: flex; }
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.65rem 0.9rem;
    background: #1e1e24;
    border: 1px solid #27272a;
    border-radius: 14px;
    border-top-left-radius: 4px;
}
.typing-dot {
    width: 6px; height: 6px;
    background: #52525b;
    border-radius: 50%;
    animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%,60%,100% { transform: translateY(0); background: #52525b; }
    30%          { transform: translateY(-6px); background: #8b5cf6; }
}

/* ── Suggestions (empty state) ────────────────────────────────── */
.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0;
}
.chat-welcome-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.chat-welcome-title {
    font-size: 1rem;
    font-weight: 700;
    color: #e4e4e7;
    margin-bottom: 0.2rem;
}
.chat-welcome-sub {
    font-size: 0.78rem;
    color: #71717a;
    margin-bottom: 0.75rem;
    line-height: 1.45;
}
.suggestion-chip {
    padding: 0.5rem 0.8rem;
    background: #0f0f13;
    border: 1px solid #27272a;
    border-radius: 10px;
    font-size: 0.78rem;
    color: #a1a1aa;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    line-height: 1.4;
}
.suggestion-chip:hover {
    border-color: #8b5cf6;
    color: #e4e4e7;
    background: rgba(139,92,246,0.06);
}

/* ── Input area ───────────────────────────────────────────────── */
.chat-input-area {
    padding: 0.85rem 1rem;
    border-top: 1px solid #27272a;
    background: #18181b;
    flex-shrink: 0;
}
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #0f0f13;
    border: 1px solid #27272a;
    border-radius: 12px;
    padding: 0.5rem 0.5rem 0.5rem 0.85rem;
    transition: border-color 0.2s;
}
.chat-input-row:focus-within { border-color: rgba(139,92,246,0.5); }
.chat-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e4e4e7;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    font-family: inherit;
    padding: 0;
}
.chat-textarea::placeholder { color: #52525b; }
.chat-textarea::-webkit-scrollbar { width: 3px; }
.chat-textarea::-webkit-scrollbar-thumb { background: #27272a; }
.chat-send-btn {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.chat-send-btn:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(139,92,246,0.4); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.chat-send-btn svg { width: 16px; height: 16px; }
.chat-footer-note {
    font-size: 0.65rem;
    color: #3f3f46;
    text-align: center;
    margin-top: 0.5rem;
}

/* ── Setup banner (shown when no API key) ─────────────────────── */
.chat-setup-banner {
    margin: 1rem;
    padding: 1rem;
    background: rgba(245,158,11,0.08);
    border: 1px solid rgba(245,158,11,0.2);
    border-radius: 10px;
    font-size: 0.8rem;
    color: #d4d4d8;
    line-height: 1.5;
}
.chat-setup-banner strong { color: #fbbf24; }
.chat-setup-banner a { color: #a78bfa; text-decoration: underline; }

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .chat-fab  { bottom: 1.25rem; right: 1.25rem; }
    .chat-window {
        bottom: 0; right: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .chat-window.open { border-radius: 0; }
}