/* AI Agent Sidebar Styles */

/* Toggle button - floating circle in bottom-right */
#agent-sidebar-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--admin-interface-header-background-color, #417690);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    z-index: 10000;
    transition: transform 0.2s, background 0.2s;
}
#agent-sidebar-toggle:hover {
    transform: scale(1.08);
    background: var(--admin-interface-header-link-hover-color, #205067);
}
#agent-sidebar-toggle.agent-hidden {
    display: none;
}

/* Sidebar panel */
#agent-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    background: #fff;
    box-shadow: -2px 0 16px rgba(0,0,0,0.15);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}
#agent-sidebar.agent-sidebar-closed {
    transform: translateX(100%);
}
#agent-sidebar.agent-sidebar-open {
    transform: translateX(0);
}

/* Header */
.agent-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--admin-interface-header-background-color, #417690);
    color: #fff;
    min-height: 48px;
    flex-shrink: 0;
}
.agent-sidebar-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.agent-sidebar-header-actions {
    display: flex;
    gap: 4px;
}
.agent-header-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    opacity: 0.8;
}
.agent-header-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* History panel — separate panel to the LEFT of the sidebar */
.agent-history-panel {
    position: fixed;
    top: 0;
    right: 420px;
    width: 280px;
    height: 100vh;
    background: #f9fafb;
    box-shadow: -2px 0 12px rgba(0,0,0,0.1);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, opacity 0.25s ease;
}
.agent-history-panel.agent-history-closed {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
}
.agent-history-panel.agent-history-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}
.agent-history-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--admin-interface-header-background-color, #417690);
    color: #fff;
    min-height: 48px;
    flex-shrink: 0;
}
.agent-history-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.agent-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}
.agent-history-item {
    display: flex;
    flex-direction: column;
    padding: 10px 16px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: 13px;
    color: #374151;
    transition: background 0.1s;
    gap: 3px;
    border-bottom: 1px solid #e5e7eb;
}
.agent-history-item:hover {
    background: #e5e7eb;
}
.agent-history-item.agent-history-active {
    background: #dbeafe;
    color: var(--admin-interface-header-background-color, #417690);
    font-weight: 600;
}
.agent-history-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-history-item-meta {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
}
.agent-history-active .agent-history-item-meta {
    color: #6b7280;
}
.agent-history-empty {
    padding: 24px 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    font-style: italic;
}
.agent-header-btn.agent-header-btn-active {
    background: rgba(255,255,255,0.25);
    opacity: 1;
}

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

/* Message bubbles */
.agent-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.agent-msg-user {
    align-self: flex-end;
    background: var(--admin-interface-header-background-color, #417690);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.agent-msg-assistant {
    align-self: flex-start;
    background: #f1f3f5;
    color: #333;
    border-bottom-left-radius: 4px;
}
.agent-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}
.agent-msg-system {
    align-self: center;
    color: #6b7280;
    font-size: 12px;
    font-style: italic;
    text-align: center;
    padding: 4px 8px;
}

/* Tool use indicator (active — with spinner) */
.agent-msg-tool {
    align-self: flex-start;
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
    border-radius: 8px;
    font-size: 12px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.agent-tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #fde68a;
    border-top-color: #92400e;
    border-radius: 50%;
    animation: agent-spin 0.8s linear infinite;
}
@keyframes agent-spin {
    to { transform: rotate(360deg); }
}

/* Tool use indicator (completed — static checkmark) */
.agent-msg-tool-done {
    align-self: flex-start;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 12px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.agent-tool-check {
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
}

/* Result set link -- high specificity to override admin-interface theme */
#agent-sidebar .agent-msg a.agent-msg-result-link,
#agent-sidebar .agent-msg a.agent-msg-result-link:link,
#agent-sidebar .agent-msg a.agent-msg-result-link:visited {
    display: inline-block;
    margin-top: 6px;
    padding: 6px 14px;
    background: #2563eb;
    color: #fff !important;
    border-radius: 4px;
    text-decoration: none !important;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}
#agent-sidebar .agent-msg a.agent-msg-result-link:hover,
#agent-sidebar .agent-msg a.agent-msg-result-link:active {
    background: #1d4ed8;
    color: #fff !important;
}

/* Typing indicator */
.agent-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 16px 4px;
    flex-shrink: 0;
}
.agent-typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: agent-bounce 1.2s ease-in-out infinite;
}
.agent-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.agent-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes agent-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input area */
.agent-input-area {
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    flex-shrink: 0;
    background: #fafafa;
}
.agent-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.agent-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s;
}
.agent-input:focus {
    border-color: var(--admin-interface-header-background-color, #417690);
}
.agent-send {
    background: var(--admin-interface-header-background-color, #417690);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.agent-send:hover {
    opacity: 0.85;
}
.agent-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Assistant message content formatting */
.agent-msg-assistant code {
    background: #e5e7eb;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}
.agent-msg-assistant pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}
.agent-msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.agent-msg-assistant strong { font-weight: 600; }
.agent-msg-assistant em { font-style: italic; }

/* Empty state */
.agent-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    text-align: center;
    padding: 32px;
    gap: 12px;
}
.agent-empty-state svg {
    opacity: 0.4;
}
.agent-empty-state p {
    font-size: 13px;
    line-height: 1.5;
    max-width: 240px;
}

/* Responsive: full-width on small screens */
@media (max-width: 700px) {
    #agent-sidebar {
        width: 100vw;
    }
    .agent-history-panel {
        right: 0;
        width: 100vw;
        z-index: 10002;
    }
}
