/* ── Chat Widget ────────────────────────────────────────────── */

#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: inherit;
}

/* Floating bubble */
#chat-bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

/* Panel */
.chat-panel-hidden {
    display: none !important;
}

#chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 420px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease, height 0.25s ease;
}
#chat-panel.chat-expanded {
    width: min(800px, calc(100vw - 48px));
    height: calc(100vh - 48px);
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    flex-shrink: 0;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
#chat-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-client-badge {
    font-size: 0.75rem;
    background: #dbeafe;
    color: #1d4ed8;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}
.chat-client-badge:empty {
    display: none;
}
.chat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.chat-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #64748b;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}
.chat-icon-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Client selector */
#chat-client-selector {
    padding: 8px 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.chat-select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #fff;
}

/* Messages area */
#chat-messages-view {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Welcome screen */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    color: #94a3b8;
    gap: 12px;
    padding: 32px;
}
.chat-welcome p {
    font-size: 0.9rem;
    line-height: 1.5;
    max-width: 280px;
}
.chat-welcome-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}
.chat-welcome-prompt {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chat-welcome-prompt:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #1e293b;
}
.chat-welcome-hint {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 12px;
}
.chat-welcome-hint strong {
    color: #64748b;
}

/* Message bubbles */
.chat-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.55;
    word-wrap: break-word;
}
.chat-msg-user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg-assistant {
    align-self: flex-start;
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.chat-msg-assistant a {
    color: #2563eb;
    text-decoration: underline;
}
.chat-msg-assistant code {
    background: #e2e8f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.85em;
}

/* Streaming indicator */
.chat-streaming-cursor::after {
    content: "▌";
    animation: blink 0.7s infinite;
    color: #94a3b8;
}
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Loading dots */
.chat-loading {
    align-self: flex-start;
    padding: 12px 16px;
}
.chat-loading-dots {
    display: flex;
    gap: 4px;
}
.chat-loading-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: loading-bounce 1.2s infinite;
}
.chat-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes loading-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Sources */
.chat-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
}
.chat-sources-label {
    color: #64748b;
    font-weight: 600;
    margin-bottom: 4px;
}
.chat-source-link {
    display: block;
    color: #2563eb;
    text-decoration: none;
    padding: 2px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-source-link:hover {
    text-decoration: underline;
}

/* Feedback buttons */
.chat-feedback {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-top: 4px;
}
.chat-feedback-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: color 0.15s, background 0.15s;
}
.chat-feedback-btn:hover {
    background: #e2e8f0;
    color: #475569;
}
.chat-feedback-btn.active {
    color: #2563eb;
    background: #dbeafe;
}

/* Input area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}
#chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
}
#chat-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
#chat-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
#chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
#chat-send-btn:not(:disabled):hover {
    background: #1d4ed8;
}
#chat-stop-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #dc2626;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: background 0.15s;
}
#chat-stop-btn:hover {
    background: #b91c1c;
}

/* History list */
.chat-history-list {
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}
.chat-history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-history-item:hover {
    background: #f1f5f9;
}
.chat-history-item-title {
    font-size: 0.88rem;
    font-weight: 500;
    color: #1e293b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-history-item-meta {
    font-size: 0.75rem;
    color: #94a3b8;
}
.chat-history-empty {
    text-align: center;
    color: #94a3b8;
    padding: 32px 16px;
    font-size: 0.9rem;
}
