/* ── AI Chat Panel ───────────────────────────────────────────────── */
#chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2F5496 0%, #1a3a6e 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(47,84,150,0.4);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.2s, box-shadow 0.2s;
}
#chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(47,84,150,0.5);
}
#chat-toggle.open {
    background: #666;
}

#chat-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 420px;
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
#chat-panel.open {
    right: 0;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #2F5496 0%, #1a3a6e 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.chat-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.chat-header-actions button {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-header-actions button:hover {
    background: rgba(255,255,255,0.3);
}

/* Conversation list sidebar */
.chat-sidebar {
    position: absolute;
    top: 60px;
    left: 0;
    width: 280px;
    height: calc(100vh - 60px);
    background: #f8f9fb;
    border-right: 1px solid #e0e4ea;
    z-index: 10;
    display: none;
    flex-direction: column;
    overflow-y: auto;
}
.chat-sidebar.open {
    display: flex;
}
.chat-sidebar-header {
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #2F5496;
    border-bottom: 1px solid #e0e4ea;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-sidebar-header button {
    background: #2F5496;
    color: #fff;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.conv-item {
    padding: 10px 16px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-item:hover {
    background: #eef2f7;
}
.conv-item.active {
    background: #dce4f0;
    font-weight: 600;
}
.conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-delete {
    color: #999;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    flex-shrink: 0;
}
.conv-delete:hover {
    color: #e74c3c;
}
.conv-time {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

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

.chat-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.chat-msg.user {
    align-self: flex-end;
    background: #2F5496;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
    align-self: flex-start;
    background: #f0f4f8;
    color: #333;
    border-bottom-left-radius: 4px;
}
.chat-msg.error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    font-size: 13px;
}
.chat-msg.tool-status {
    align-self: center;
    background: #f0f9ff;
    color: #0369a1;
    font-size: 12px;
    padding: 6px 12px;
    border: 1px solid #bae6fd;
}

/* Markdown in assistant messages */
.chat-msg.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    width: 100%;
}
.chat-msg.assistant th, .chat-msg.assistant td {
    border: 1px solid #d0d5dd;
    padding: 4px 8px;
    text-align: left;
}
.chat-msg.assistant th {
    background: #e8ecf0;
    font-weight: 600;
}
.chat-msg.assistant code {
    background: #e8ecf0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
}
.chat-msg.assistant pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 12px;
    margin: 6px 0;
}
.chat-msg.assistant pre code {
    background: none;
    color: inherit;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #adb5bd;
    border-radius: 50%;
    animation: typing 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input area */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e0e4ea;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #fff;
}
.chat-input-area textarea {
    flex: 1;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
}
.chat-input-area textarea:focus {
    border-color: #2F5496;
    box-shadow: 0 0 0 2px rgba(47,84,150,0.15);
}
.chat-input-area button {
    background: #2F5496;
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-input-area button:hover {
    background: #1a3a6e;
}
.chat-input-area button:disabled {
    background: #adb5bd;
    cursor: not-allowed;
}

/* Usage footer */
.chat-usage {
    font-size: 11px;
    color: #999;
    text-align: center;
    padding: 4px 0 8px;
    flex-shrink: 0;
}

/* Disabled state */
.chat-disabled-msg {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
    line-height: 1.6;
}

/* Navigate link */
.chat-navigate-link {
    display: inline-block;
    background: #f0f4ff;
    color: #2F5496;
    padding: 4px 10px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    margin-top: 4px;
    border: 1px solid #d0d8e8;
}
.chat-navigate-link:hover {
    background: #e0e8f5;
}

/* Responsive */
@media (max-width: 500px) {
    #chat-panel {
        width: 100vw;
        right: -100vw;
    }
    .chat-sidebar {
        width: 100%;
    }
}
