/* ============================================================================
   Chat Agent — Peak Value AI Assistant
   ============================================================================ */

/* Floating Action Button */
#chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
    z-index: 9999;
    transition: transform 0.2s, box-shadow 0.2s;
}

#chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}

/* Panel — Modal flotante */
#chat-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 420px;
    height: 650px;
    max-height: 80vh;
    background: #ffffff;
    border: none;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}

.chat-panel-closed {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

.chat-panel-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-icon {
    font-size: 1.2rem;
}

.chat-header-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #0f172a;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-btn-icon {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: background 0.15s, color 0.15s;
}

.chat-btn-icon:hover {
    background: #e2e8f0;
    color: #0f172a;
}

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

/* Welcome */
.chat-welcome {
    text-align: center;
    padding: 40px 20px;
}

.chat-welcome-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.chat-welcome-text {
    color: #64748b;
    font-size: 0.95rem;
    margin-bottom: 20px;
}

/* Suggestions */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.chat-suggestion-btn {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}

.chat-suggestion-btn:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

/* Message bubbles */
.chat-msg {
    display: flex;
}

.chat-msg-user {
    justify-content: flex-end;
}

.chat-msg-assistant {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble-user {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}

.chat-bubble-assistant strong {
    color: #0f172a;
}

.chat-bubble-assistant code {
    background: #e2e8f0;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.85em;
}

.chat-bubble-assistant pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-bubble-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Tables in chat */
.chat-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.82rem;
}

.chat-table th,
.chat-table td {
    border: 1px solid #e2e8f0;
    padding: 6px 10px;
    text-align: left;
}

.chat-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #0f172a;
}

.chat-table tr:nth-child(even) {
    background: #f8fafc;
}

/* Copy button */
.chat-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 3px 5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    color: #64748b;
    font-size: 0.75rem;
}

.chat-bubble-assistant:hover .chat-copy-btn {
    opacity: 1;
}

.chat-copy-btn:hover {
    background: white;
    color: #0f172a;
}

/* Thinking animation */
.chat-thinking {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.chat-thinking span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: chatBounce 1.4s infinite ease-in-out both;
}

.chat-thinking span:nth-child(1) { animation-delay: -0.32s; }
.chat-thinking span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: #2563eb;
}

#chat-input::placeholder {
    color: #94a3b8;
}

#chat-send-btn {
    background: #2563eb;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

#chat-send-btn:hover {
    background: #1e40af;
}

#chat-send-btn:disabled {
    cursor: not-allowed;
}

/* Tool Use Indicator */
.chat-tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1e40af;
    font-size: 0.85rem;
    font-weight: 500;
    margin: 4px 0;
}

.chat-tool-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2563eb;
    animation: chatToolPulse 1.2s infinite ease-in-out;
}

@keyframes chatToolPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* ============================================================================
   RESPONSIVE — Mobile
   ============================================================================ */
@media (max-width: 768px) {
    #chat-panel {
        width: 100vw;
    }

    #chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }

    .chat-bubble {
        max-width: 90%;
    }
}

/* Blinking cursor while streaming */
.chat-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #2563eb;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: chatCursorBlink 0.8s infinite;
}

@keyframes chatCursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Resize handle */
.chat-resize-handle {
    display: none;
}

/* Chart in chat */
.chat-chart-container {
    width: 100%;
    height: 220px;
    margin: 8px 0;
    padding: 8px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.chat-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Powered by Claude */
.chat-powered {
    text-align: center;
    padding: 4px 0;
    font-size: 0.7rem;
    color: #94a3b8;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

/* Slow notice */
.chat-slow-notice {
    text-align: center;
    padding: 8px 16px;
    font-size: 0.82rem;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.08);
    border-radius: 8px;
    margin: 8px 16px;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
