/* FARAD Intelligence Chat Widget */

#farad-intel-widget-root {
    --fi-black: #1a1a1a;
    --fi-white: #ffffff;
    --fi-gray-light: #f5f5f5;
    --fi-gray-mid: #e0e0e0;
    --fi-gray-text: #888;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 999999;
}

/* Bubble */
.fi-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--fi-black);
    color: var(--fi-white);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 999999;
}

.fi-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

.fi-bubble svg {
    width: 28px;
    height: 28px;
    fill: var(--fi-white);
}

.fi-bubble.fi-open svg.fi-icon-chat { display: none; }
.fi-bubble.fi-open svg.fi-icon-close { display: block; }
.fi-bubble:not(.fi-open) svg.fi-icon-chat { display: block; }
.fi-bubble:not(.fi-open) svg.fi-icon-close { display: none; }

/* Chat Window */
.fi-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--fi-white);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 999998;
}

.fi-window.fi-visible {
    display: flex;
    animation: fi-slide-up 0.25s ease-out;
}

@keyframes fi-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.fi-header {
    background: var(--fi-black);
    color: var(--fi-white);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.fi-header-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.fi-header-actions {
    display: flex;
    gap: 8px;
}

.fi-header-btn {
    background: none;
    border: none;
    color: var(--fi-white);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.15s;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.fi-header-btn:hover {
    opacity: 1;
}

.fi-header-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--fi-white);
}

/* Messages Area */
.fi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.fi-messages::-webkit-scrollbar {
    width: 4px;
}

.fi-messages::-webkit-scrollbar-thumb {
    background: var(--fi-gray-mid);
    border-radius: 4px;
}

/* Message */
.fi-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
}

.fi-msg-user {
    align-self: flex-end;
    background: var(--fi-black);
    color: var(--fi-white);
    border-bottom-right-radius: 4px;
}

.fi-msg-assistant {
    align-self: flex-start;
    background: var(--fi-gray-light);
    color: var(--fi-black);
    border-bottom-left-radius: 4px;
}

.fi-msg-assistant a {
    color: var(--fi-black);
    font-weight: 600;
    text-decoration: underline;
}

.fi-msg-assistant a:hover {
    opacity: 0.7;
}

/* Typing indicator */
.fi-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 18px;
    background: var(--fi-gray-light);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.fi-typing-dot {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: fi-bounce 1.4s ease-in-out infinite;
}

.fi-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.fi-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes fi-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input Area */
.fi-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--fi-gray-mid);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--fi-white);
}

.fi-input {
    flex: 1;
    border: 1px solid var(--fi-gray-mid);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.15s;
}

.fi-input:focus {
    border-color: var(--fi-black);
}

.fi-input::placeholder {
    color: #bbb;
}

.fi-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--fi-black);
    color: var(--fi-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.fi-send-btn:hover {
    opacity: 0.85;
}

.fi-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.fi-send-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--fi-white);
}

/* Rate limit notice */
.fi-rate-notice {
    text-align: center;
    padding: 10px;
    color: #999;
    font-size: 12px;
    border-top: 1px solid var(--fi-gray-mid);
    background: var(--fi-gray-light);
}

/* Mobile */
@media (max-width: 480px) {
    .fi-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }

    .fi-bubble {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .fi-bubble.fi-open {
        bottom: 95px;
        right: 16px;
        width: 24px;
        height: 24px;
    }
}
