/* Agent Panel Styles */

/* Panel Content Container */
#agent-panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Chat Messages Area */
.agent-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #18181b;
}

.agent-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.agent-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.agent-chat-messages::-webkit-scrollbar-thumb {
    background: #3f3f46;
    border-radius: 2px;
}

/* Empty State */
.agent-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #52525b;
    gap: 16px;
}

.agent-chat-empty svg {
    width: 40px;
    height: 40px;
}

.agent-chat-empty span {
    font-size: 13px;
}

.agent-reload-btn {
    margin-top: 8px;
    padding: 10px 20px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.agent-reload-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.agent-reload-btn:active {
    transform: translateY(0);
}

.agent-reload-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Message Container */
.agent-message {
    display: flex;
    width: 100%;
    margin-bottom: 20px;
}

.agent-message.user {
    justify-content: flex-end;
}

.agent-message.assistant {
    justify-content: flex-start;
}

/* Message Bubble */
.agent-message-content {
    max-width: 100%;
    padding: 8px 14px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.agent-message.user .agent-message-content {
    border-radius: 12px;
    background: #27272a;
    color: #ededed;
    border: 1px solid #3f3f46;
}

.agent-message.assistant .agent-message-content {
    border-radius: 4px;
    background: transparent;
    color: #ededed;
}

/* Message Metadata */
.agent-message-meta {
    margin-top: 6px;
    font-size: 10px;
    color: #71717a;
    display: flex;
    align-items: center;
    gap: 6px;
}

.agent-message.user .agent-message-meta {
    justify-content: flex-end;
}

.agent-message.assistant .agent-message-meta {
    justify-content: flex-start;
}

/* Status Icons */
.agent-status-sending {
    color: #71717a;
}

.agent-status-processing {
    color: #fbbf24;
}

.agent-status-error {
    color: #ef4444;
}

/* Input Area */
.agent-chat-input-area {
    padding: 16px;
    background-color: #18181b;
    border-top: 1px solid #27272a;
    flex-shrink: 0;
}

.agent-input-wrapper {
    background: #202023;
    border: 1px solid #3f3f46;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all 0.2s ease;
}

.agent-input-wrapper.drag-active {
    border-color: #4ade80;
    background-color: #27272a;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.1);
}

/* File List */
.agent-file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.agent-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #3f3f46;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #e4e4e7;
    max-width: 100%;
}

.agent-file-badge.has-preview {
    padding: 4px;
    gap: 8px;
}

.agent-file-preview {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #52525b;
    flex-shrink: 0;
}

.agent-file-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.agent-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.agent-file-size {
    color: #a1a1aa;
    font-size: 10px;
}

.agent-file-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-weight: bold;
    padding: 0 4px;
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
    transition: all 0.2s;
}

.agent-file-remove:hover {
    color: #dc2626;
    transform: scale(1.2);
}

/* Textarea */
.agent-chat-textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: #ededed;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    height: 40px;
    min-height: 40px;
}

.agent-chat-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Input Controls */
.agent-input-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.agent-input-actions {
    display: flex;
    gap: 4px;
}

/* Buttons */
.agent-btn {
    background: transparent;
    border: none;
    color: #a1a1aa;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-btn:hover {
    color: #ededed;
    background: #27272a;
}

.agent-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.agent-send-btn {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: #ededed;
    color: #18181b;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Code Block Wrapper for Run Bash Button */
.agent-code-block-wrapper {
    position: relative;
    margin: 8px 0;
}

.agent-run-bash-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #3b82f6;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
}

.agent-run-bash-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.agent-run-bash-btn:active {
    transform: translateY(0);
}

/* Mermaid Diagrams */
.agent-mermaid {
    margin: 16px 0;
    background-color: var(--code-block-bg, #161b22);
    border-radius: 6px;
    overflow: hidden;
    min-height: 100px;
    position: relative;
}

.agent-mermaid-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.agent-mermaid-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: #a1a1aa;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s ease;
}

.agent-mermaid-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ededed;
}

.agent-mermaid-btn:active {
    transform: scale(0.95);
}

.agent-mermaid-diagram {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
}

.agent-mermaid-diagram svg {
    max-width: 100%;
    height: auto;
}

/* Mermaid Toast Notification */
.agent-mermaid-toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    z-index: 100;
    animation: mermaid-toast-fade 2s ease-out forwards;
}

.agent-mermaid-toast.success {
    background: rgba(74, 222, 128, 0.9);
    color: #000;
}

.agent-mermaid-toast.error {
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
}

@keyframes mermaid-toast-fade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    85% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Mermaid Fullscreen Modal */
.agent-mermaid-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.agent-mermaid-modal.open {
    opacity: 1;
}

.agent-mermaid-modal.closing {
    opacity: 0;
}

.agent-mermaid-modal-content {
    background: #1a1a1a;
    border-radius: 12px;
    max-width: 95vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.agent-mermaid-modal.open .agent-mermaid-modal-content {
    transform: scale(1);
}

.agent-mermaid-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #252525;
    border-bottom: 1px solid #333;
    color: #ededed;
    font-weight: 600;
    font-size: 14px;
}

.agent-mermaid-modal-actions {
    display: flex;
    gap: 8px;
}

.agent-mermaid-modal-actions .agent-mermaid-btn {
    padding: 6px 12px;
}

.agent-mermaid-close {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.agent-mermaid-close:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.agent-mermaid-modal-body {
    padding: 40px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #161b22;
}

.agent-mermaid-modal-body svg {
    max-width: 100%;
    height: auto;
}

/* Mermaid error state */
.agent-mermaid-error {
    margin: 16px 0;
    padding: 16px;
    background-color: rgba(255, 59, 48, 0.1);
    border: 1px solid var(--ios-red, #ff3b30);
    border-radius: 6px;
    color: var(--ios-red, #ff3b30);
    font-family: monospace;
    font-size: 12px;
}

/* Light Theme Support */
[data-theme="light"] .agent-chat-messages {
    background-color: #FFFFFF;
}

[data-theme="light"] .agent-chat-input-area {
    background-color: #FFFFFF;
}

[data-theme="light"] .agent-input-wrapper {
    background: #F7F7F7;
    border-color: #D1D1D1;
}

[data-theme="light"] .agent-message.user .agent-message-content {
    background: #F0F0F0;
    color: #000000;
    border-color: #D1D1D1;
}

[data-theme="light"] .agent-message.assistant .agent-message-content {
    color: #000000;
}

[data-theme="light"] .agent-chat-textarea {
    color: #000000;
}

/* Spinner Animation */
@keyframes agent-spin {
    100% {
        transform: rotate(360deg);
    }
}

.agent-spinner {
    animation: agent-spin 1s linear infinite;
}

/* Error Message */
.agent-error-box {
    color: #ef4444;
    padding: 12px;
    background: #2a1515;
    border-radius: 8px;
    border: 1px solid #7f1d1d;
}

.agent-error-title {
    font-weight: 600;
    margin-bottom: 8px;
}

.agent-retry-btn {
    background: #dc2626;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    margin-top: 4px;
}

.agent-retry-btn:hover {
    background: #b91c1c;
}

/* History Pane — mounted inside #tool-panel-agent */
#tool-panel-agent { position: relative; }

.agent-history-modal-inline {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: #18181b;
    color: #ededed;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.agent-history-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.agent-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #27272a;
    font-weight: 600;
    font-size: 14px;
}

.agent-history-close {
    background: transparent;
    border: none;
    color: #a1a1aa;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.agent-history-close:hover { color: #ededed; }

.agent-history-list {
    overflow-y: auto;
    padding: 6px;
}

.agent-history-empty {
    padding: 24px;
    text-align: center;
    color: #71717a;
    font-size: 13px;
}

.agent-history-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.agent-history-row:hover { background: #27272a; }

.agent-history-row-main { flex: 1; min-width: 0; }

.agent-history-title {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-history-meta {
    display: flex;
    gap: 10px;
    margin-top: 4px;
    font-size: 11px;
    color: #71717a;
}

.agent-history-delete {
    background: transparent;
    border: none;
    color: #71717a;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
}
.agent-history-delete:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

[data-theme="light"] .agent-history-modal-inline {
    background: #ffffff;
    color: #18181b;
}
[data-theme="light"] .agent-history-header { border-bottom-color: #e5e5ea; }
[data-theme="light"] .agent-history-row:hover { background: #f2f2f7; }
