/* Chat Toggle Button */
.chat-toggle-btn {
    display: none;
}
.chat-toggle-btn i { width: 22px; height: 22px; }
.chat-toggle-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(99,102,241,.5); }
.chat-toggle-btn.active { background: var(--bg-card); border: 1px solid var(--border); box-shadow: var(--shadow); }

/* Chat Panel */
.chat-panel {
    width: 100%;
    max-width: 860px;
    height: calc(100vh - 80px);
    min-height: 520px;
    margin: 20px auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-panel.open {
    display: flex;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chat-header-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-header-avatar i { width: 16px; height: 16px; color: #fff; }
.chat-header-title { font-size: 14px; font-weight: 600; }
.chat-header-subtitle { font-size: 11px; color: var(--text-dim); }
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-actions button {
    width: 28px; height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .12s;
}
.chat-header-actions button i { width: 15px; height: 15px; }
.chat-header-actions button:hover { background: var(--bg-card-hover); color: var(--text); }

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Welcome State */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    padding: 20px;
}
.chat-welcome-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}
.chat-welcome-icon i { width: 24px; height: 24px; color: #fff; }
.chat-welcome h4 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.chat-welcome p { font-size: 12px; color: var(--text-dim); max-width: 280px; line-height: 1.5; }
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 16px;
    justify-content: center;
}
.chat-suggestions button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.chat-suggestions button:hover { border-color: var(--primary); color: var(--primary-hover); background: rgba(99,102,241,.06); }

/* Message Bubbles */
.chat-msg { display: flex; gap: 10px; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.user .chat-msg-content {
    background: var(--primary);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    max-width: 85%;
    word-break: break-word;
}
.chat-msg.assistant { align-items: flex-start; }
.chat-msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: rgba(99,102,241,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}
.chat-msg-avatar i { width: 14px; height: 14px; color: var(--primary-hover); }
.chat-msg-body { max-width: 85%; min-width: 0; }
.chat-msg.assistant .chat-msg-content {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px 14px 14px 14px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    word-break: break-word;
}
.chat-msg.assistant .chat-msg-content h2,
.chat-msg.assistant .chat-msg-content h3,
.chat-msg.assistant .chat-msg-content h4 {
    font-size: 13px;
    font-weight: 600;
    margin: 8px 0 4px;
}
.chat-msg.assistant .chat-msg-content h2:first-child,
.chat-msg.assistant .chat-msg-content h3:first-child,
.chat-msg.assistant .chat-msg-content h4:first-child { margin-top: 0; }
.chat-msg.assistant .chat-msg-content ul { padding-left: 16px; margin: 4px 0; }
.chat-msg.assistant .chat-msg-content li { margin-bottom: 2px; }
.chat-msg.assistant .chat-msg-content pre {
    background: rgba(0,0,0,.3);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 6px 0;
    overflow-x: auto;
    font-size: 11px;
}
.chat-msg.assistant .chat-msg-content code { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.chat-inline-code {
    background: rgba(99,102,241,.12);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}
.chat-msg.assistant .chat-msg-content strong { color: #fff; }

/* Tool badges */
.chat-tools-used {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-tool-results {
    margin-top: 10px;
    border-top: 1px solid rgba(148,163,184,.16);
    padding-top: 10px;
}

.chat-tool-result {
    background: rgba(15,17,23,.55);
    border: 1px solid rgba(148,163,184,.14);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
}

.chat-tool-result summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    background: rgba(99,102,241,.10);
    border-bottom: 1px solid rgba(148,163,184,.12);
}

.chat-tool-result summary::-webkit-details-marker {
    display: none;
}

.chat-tool-result summary i {
    width: 16px;
    height: 16px;
    color: var(--primary-hover);
}

.chat-tool-result-body {
    padding: 10px;
    max-height: 520px;
    overflow: auto;
}

.chat-tool-result-body .result-table {
    font-size: 12px;
}

.chat-tool-json {
    white-space: pre;
    overflow: auto;
    max-height: 420px;
    background: rgba(0,0,0,.2);
    border: 1px solid rgba(148,163,184,.12);
    border-radius: 10px;
    padding: 10px;
}

.chat-tool-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(99,102,241,.1);
    border: 1px solid rgba(99,102,241,.2);
    color: var(--primary-hover);
    font-size: 10px;
    font-weight: 500;
}
.chat-tool-badge i { width: 10px; height: 10px; }

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px 14px 14px 14px;
}
.chat-typing span {
    width: 7px; height: 7px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: chatBounce .6s infinite alternate;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatBounce {
    from { opacity: .3; transform: translateY(0); }
    to { opacity: 1; transform: translateY(-4px); }
}

/* Input Area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-input-area input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color .15s;
}
.chat-input-area input::placeholder { color: var(--text-dim); }
.chat-input-area input:focus { border-color: var(--border-focus); }
.chat-send-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all .15s;
}
.chat-send-btn i { width: 16px; height: 16px; }
.chat-send-btn:hover { background: var(--primary-hover); }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Responsive */
@media (max-width: 480px) {
    .chat-panel {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 180px);
        min-height: 420px;
        margin: 12px auto;
        border-radius: 12px;
    }
    .chat-toggle-btn { display: none; }
}
