/* ========== Chat Widget ========== */
.chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Floating Button */
.chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color, #2563eb);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}

.chat-toggle.active {
    background: #64748b;
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.95);
    transition: opacity 0.25s, visibility 0.25s, transform 0.25s;
}

.chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--primary-color, #2563eb);
    color: white;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-header-left span {
    font-size: 1.25rem;
}

.chat-header-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: #f8fafc;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

/* Message Bubble */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: chatFadeIn 0.3s ease;
}

@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message-content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.user .chat-message-content {
    background: var(--primary-color, #2563eb);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-message-content {
    background: white;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.chat-message.assistant .chat-message-content code {
    background: #f1f5f9;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'Monaco', 'Consolas', monospace;
}

.chat-message.assistant .chat-message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
    font-size: 0.85em;
}

.chat-message.assistant .chat-message-content pre code {
    background: none;
    padding: 0;
}

/* Typing Indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: chatFadeIn 0.3s ease;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: chatTypingBounce 1.2s infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Empty State */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    text-align: center;
    padding: 2rem;
    gap: 0.5rem;
}

.chat-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.chat-empty-text {
    font-size: 0.9rem;
}

.chat-empty-hint {
    font-size: 0.8rem;
    color: #cbd5e1;
}

/* Input Area */
.chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: white;
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--primary-color, #2563eb);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--primary-color, #2563eb);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: var(--primary-hover, #1d4ed8);
}

.chat-send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* Settings Panel */
.chat-settings {
    display: none;
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}

.chat-settings.show {
    display: block;
}

.chat-settings-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 0.5rem;
    display: block;
}

.chat-settings-input {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-family: 'Monaco', 'Consolas', monospace;
    outline: none;
    transition: border-color 0.2s;
}

.chat-settings-input:focus {
    border-color: var(--primary-color, #2563eb);
}

.chat-settings-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.chat-settings-save {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    background: var(--primary-color, #2563eb);
    color: white;
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
}

.chat-settings-save:hover {
    background: var(--primary-hover, #1d4ed8);
}

.chat-settings-cancel {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    background: #e2e8f0;
    color: #475569;
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }

    .chat-window {
        width: calc(100vw - 2rem);
        height: calc(100vh - 120px);
        bottom: 64px;
        right: 0;
        border-radius: 12px;
    }

    .chat-toggle {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
}
