:root {
    --ai-agent-width: 380px;
}

.ai-agent-toggle {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1045;
    width: 36px;
    height: 72px;
    border: 1px solid #dee2e6;
    border-right: none;
    border-radius: 8px 0 0 8px;
    background: #fff;
    color: #495057;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: right 0.25s ease, background 0.15s, color 0.15s, border-color 0.15s;
}

.ai-agent-toggle:hover {
    background: #f8f9fa;
    color: #007bff;
}

.ai-agent-toggle.active {
    right: var(--ai-agent-width);
    color: #007bff;
    border-color: #007bff;
    background: #f0f7ff;
}

.ai-agent-panel {
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: var(--ai-agent-width);
    z-index: 1040;
    background: #fff;
    border-left: 1px solid #dee2e6;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

body.ai-agent-open {
    margin-right: var(--ai-agent-width);
    transition: margin-right 0.25s ease;
}

body.ai-agent-open .ai-agent-panel {
    transform: translateX(0);
}

.ai-agent-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    flex-shrink: 0;
}

.ai-agent-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #495057;
    font-size: 0.95rem;
}

.ai-agent-title i {
    color: #007bff;
}

.ai-agent-close {
    color: #6c757d;
    padding: 2px 6px;
}

.ai-agent-close:hover {
    color: #495057;
}

.ai-agent-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #fff;
    min-height: 0;
}

.ai-agent-message {
    display: flex;
    margin-bottom: 16px;
}

.ai-agent-message-user {
    justify-content: flex-end;
}

.ai-agent-message-content {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-agent-message-user .ai-agent-message-content {
    background: #007bff;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-agent-message-assistant .ai-agent-message-content {
    background: #f1f3f4;
    color: #333;
    border-bottom-left-radius: 4px;
}

.ai-agent-message-content p {
    margin: 0 0 8px;
}

.ai-agent-message-content p:last-child {
    margin-bottom: 0;
}

.ai-agent-message-content pre {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.82rem;
}

.ai-agent-message-content code {
    background: #f1f3f4;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.82rem;
}

.ai-agent-message-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.ai-agent-action-btn {
    background: #28a745;
    color: #fff;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.ai-agent-action-btn:hover {
    background: #218838;
}

.ai-agent-action-btn.copy {
    background: #007bff;
}

.ai-agent-action-btn.copy:hover {
    background: #0056b3;
}

.ai-agent-input-area {
    padding: 12px;
    border-top: 1px solid #dee2e6;
    background: #f8f9fa;
    flex-shrink: 0;
}

.ai-agent-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-agent-model-select {
    width: 110px;
    flex-shrink: 0;
    font-size: 0.8rem;
}

.ai-agent-textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    font-size: 0.9rem;
}

.ai-agent-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-agent-loading {
    text-align: center;
    padding: 12px;
}

.ai-agent-error {
    background: #f8d7da;
    color: #721c24;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.85rem;
}

@media (max-width: 767.98px) {
    :root {
        --ai-agent-width: 100vw;
    }

    body.ai-agent-open {
        margin-right: 0;
        overflow: hidden;
    }

    .ai-agent-panel {
        top: 0;
        z-index: 1050;
    }

    .ai-agent-toggle.active {
        right: 0;
        opacity: 0;
        pointer-events: none;
    }
}
