/* ===== AI CHAT WIDGET ===== */

/* ── Container ──────────────────────────── */
#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Toggle Button ──────────────────────── */
.cw-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2B7CE9 0%, #1a5fb4 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    box-shadow: 0 4px 20px rgba(43, 124, 233, 0.4), 0 2px 8px rgba(0,0,0,0.3);
    transition: transform 200ms ease, box-shadow 200ms ease;
    position: relative;
}
.cw-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(43, 124, 233, 0.5), 0 3px 12px rgba(0,0,0,0.4);
}
.cw-toggle:active { transform: scale(0.96); }
.cw-open .cw-toggle { opacity: 0; pointer-events: none; transform: scale(0.8); }

.cw-icon { width: 24px; height: 24px; }
.cw-label { font-size: 9px; font-weight: 700; letter-spacing: 0.5px; line-height: 1; }

/* ── Popup Window ───────────────────────── */
.cw-popup {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 420px;
    height: 560px;
    max-height: calc(100vh - 48px);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    /* Glassmorphism */
    background: rgba(22, 27, 34, 0.85);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 80px rgba(0,0,0,0.5), 0 8px 32px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);

    /* Animation */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 250ms cubic-bezier(0.16, 1, 0.3, 1),
                transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
.cw-popup.cw-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ─────────────────────────────── */
.cw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: rgba(255,255,255,0.03);
    flex-shrink: 0;
}
.cw-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #E6EDF3;
}
.cw-header-icon { width: 20px; height: 20px; color: #2B7CE9; }
.cw-header-right { display: flex; gap: 6px; }
.cw-clear-btn, .cw-close-btn {
    background: none;
    border: none;
    color: #8B949E;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms, color 150ms;
}
.cw-clear-btn:hover, .cw-close-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #E6EDF3;
}

/* ── Messages Area ──────────────────────── */
.cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.cw-messages::-webkit-scrollbar { width: 4px; }
.cw-messages::-webkit-scrollbar-track { background: transparent; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Welcome Screen ─────────────────────── */
.cw-welcome {
    text-align: center;
    padding: 24px 8px;
    color: #8B949E;
    font-size: 13px;
    line-height: 1.6;
}
.cw-welcome strong { color: #E6EDF3; font-size: 15px; }
.cw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}
.cw-suggestion {
    background: rgba(43, 124, 233, 0.1);
    border: 1px solid rgba(43, 124, 233, 0.25);
    color: #62A0EA;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 150ms;
    font-family: inherit;
}
.cw-suggestion:hover {
    background: rgba(43, 124, 233, 0.2);
    border-color: rgba(43, 124, 233, 0.4);
    color: #fff;
}

/* ── Message Bubbles ────────────────────── */
.cw-msg {
    display: flex;
    gap: 10px;
    animation: cwFadeIn 200ms ease;
}
@keyframes cwFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.cw-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}
.cw-msg-user .cw-msg-avatar {
    background: rgba(43, 124, 233, 0.2);
    color: #62A0EA;
}
.cw-msg-assistant .cw-msg-avatar {
    background: rgba(45, 164, 78, 0.2);
    color: #56d364;
}

.cw-msg-content {
    flex: 1;
    font-size: 13px;
    line-height: 1.6;
    color: #E6EDF3;
    overflow-wrap: break-word;
    min-width: 0;
}
.cw-msg-user .cw-msg-content {
    background: rgba(43, 124, 233, 0.1);
    border-radius: 12px 12px 2px 12px;
    padding: 10px 14px;
}
.cw-msg-assistant .cw-msg-content {
    padding: 4px 0;
}

/* Content styling */
.cw-msg-content code {
    background: rgba(255,255,255,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}
.cw-msg-content pre {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid rgba(255,255,255,0.06);
}
.cw-msg-content pre code {
    background: none;
    padding: 0;
    font-size: 12px;
}
.cw-msg-content h2, .cw-msg-content h3, .cw-msg-content h4 {
    color: #E6EDF3;
    margin: 8px 0 4px;
}
.cw-msg-content h2 { font-size: 15px; }
.cw-msg-content h3 { font-size: 14px; }
.cw-msg-content h4 { font-size: 13px; }
.cw-msg-content ul { padding-left: 18px; margin: 4px 0; }
.cw-msg-content li { margin: 2px 0; }
.cw-msg-content strong { color: #E6EDF3; }

/* ── Typing Indicator ───────────────────── */
.cw-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}
.cw-typing::before, .cw-typing::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8B949E;
    animation: cwBounce 1.2s infinite;
}
.cw-typing::before { animation-delay: 0s; }
.cw-typing::after { animation-delay: 0.2s; }
/* middle dot via box-shadow trick */
.cw-typing {
    position: relative;
}
.cw-typing::before { animation-delay: 0s; }
.cw-typing::after { animation-delay: 0.4s; }

@keyframes cwBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Error ──────────────────────────────── */
.cw-error {
    color: #f85149;
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    margin: 4px 0;
}

/* ── Input Area ─────────────────────────── */
.cw-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(255,255,255,0.02);
    flex-shrink: 0;
}
.cw-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 10px 14px;
    color: #E6EDF3;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    transition: border-color 150ms;
    line-height: 1.4;
}
.cw-input::placeholder { color: #484F58; }
.cw-input:focus { border-color: rgba(43, 124, 233, 0.5); }

.cw-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #2B7CE9;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 150ms, transform 150ms;
}
.cw-send-btn:hover:not(:disabled) { background: #62A0EA; transform: scale(1.05); }
.cw-send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.cw-send-btn svg { width: 18px; height: 18px; }

/* ── Responsive ─────────────────────────── */
@media (max-width: 480px) {
    #chat-widget { bottom: 16px; right: 16px; }
    .cw-popup {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        border-radius: 12px;
    }
}

/* ===== Full-page assistant mode (AssistantPage docks the popup) ===== */
.cw-popup.cw-fullpage {
    position: static;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: none;
    pointer-events: auto;
}
.cw-popup.cw-fullpage .cw-messages {
    flex: 1 1 auto;
    max-height: none;
    padding: 28px clamp(20px, 8vw, 120px);
}
.cw-popup.cw-fullpage .cw-input-area {
    padding: 16px clamp(20px, 8vw, 120px) 22px;
    border-top: 1px solid var(--border, #30363D);
}
.cw-popup.cw-fullpage .cw-header { border-radius: 0; }

/* The floating bubble is NOT the landing entry point anymore — the header CTA is. */
body.landing-header #chat-widget { display: none !important; }
