/**
 * Agentic Admin-Bar Chat Overlay
 *
 * Fixed-position overlay panel that slides in from the bottom-right
 * when an agent is selected from the admin-bar "AI Agents" menu.
 *
 * Theme-aware via --aco-* CSS variables set on .agentic-overlay.
 */

/* ------------------------------------------------------------------ */
/*  Theme variables (defaults = light)                                 */
/* ------------------------------------------------------------------ */
.agentic-overlay {
    --aco-bg: #fff;
    --aco-text: #1d2327;
    --aco-text-muted: #646970;
    --aco-primary: #2271b1;
    --aco-primary-hover: #135e96;
    --aco-border: #dcdcde;
    --aco-user-bg: #2271b1;
    --aco-user-text: #fff;
    --aco-agent-bg: #f0f0f1;
    --aco-agent-text: #1d2327;
    --aco-code-bg: rgba(0, 0, 0, 0.08);
    --aco-pre-bg: #1d2327;
    --aco-pre-text: #f0f0f1;
}

/* ------------------------------------------------------------------ */
/*  Overlay wrapper & backdrop                                         */
/* ------------------------------------------------------------------ */
.agentic-overlay {
    position: fixed;
    inset: 0;
    z-index: 100100; /* Above WP admin bar (100000) */
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.agentic-overlay.agentic-overlay-visible {
    opacity: 1;
    pointer-events: auto;
}

.agentic-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------------ */
/*  Panel                                                              */
/* ------------------------------------------------------------------ */
.agentic-overlay-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: min(600px, calc(100vh - 80px));
    background: var(--aco-bg);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(30px);
    transition: transform 0.25s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.agentic-overlay-visible .agentic-overlay-panel {
    transform: translateY(0);
}

/* ------------------------------------------------------------------ */
/*  Header                                                             */
/* ------------------------------------------------------------------ */
.agentic-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--aco-primary);
    color: #fff;
    flex-shrink: 0;
}

.agentic-overlay-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agentic-overlay-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.agentic-overlay-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.agentic-overlay-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

/* ------------------------------------------------------------------ */
/*  Messages                                                           */
/* ------------------------------------------------------------------ */
.agentic-overlay-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--aco-bg);
}

.agentic-overlay-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.agentic-overlay-msg-user {
    align-self: flex-end;
    background: var(--aco-user-bg);
    color: var(--aco-user-text);
    border-bottom-right-radius: 4px;
}

.agentic-overlay-msg-agent {
    align-self: flex-start;
    background: var(--aco-agent-bg);
    color: var(--aco-agent-text);
    border-bottom-left-radius: 4px;
}

.agentic-overlay-msg-body code {
    background: var(--aco-code-bg);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 13px;
}

.agentic-overlay-msg-body pre {
    background: var(--aco-pre-bg);
    color: var(--aco-pre-text);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 13px;
}

.agentic-overlay-msg-body pre code {
    background: none;
    padding: 0;
}

/* Strong / em / headers inside messages */
.agentic-overlay-msg-body h1,
.agentic-overlay-msg-body h2,
.agentic-overlay-msg-body h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 8px 0 4px;
}

.agentic-overlay-msg-body ul {
    margin: 4px 0;
    padding-left: 18px;
}

.agentic-overlay-msg-body p {
    margin: 0 0 6px;
}

.agentic-overlay-msg-body p:last-child {
    margin-bottom: 0;
}

/* Meta */
.agentic-overlay-msg-meta {
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.6;
    display: flex;
    gap: 8px;
}

/* Tool tags */
.agentic-overlay-tools {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.agentic-overlay-tool-tag {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--aco-code-bg);
    border-radius: 4px;
    color: var(--aco-text-muted);
}

/* Quick action buttons */
.agentic-overlay-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.agentic-overlay-quick-btn {
    padding: 7px 14px;
    border: 1px solid var(--aco-primary);
    border-radius: 18px;
    background: var(--aco-bg);
    color: var(--aco-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    line-height: 1.3;
}

.agentic-overlay-quick-btn:hover {
    background: var(--aco-primary);
    color: #fff;
}

/* Chat image */
.agentic-overlay-chat-img {
    max-width: 220px;
    max-height: 160px;
    border-radius: 6px;
    margin-bottom: 4px;
    object-fit: cover;
    display: block;
}

/* ------------------------------------------------------------------ */
/*  Typing indicator                                                   */
/* ------------------------------------------------------------------ */
.agentic-overlay-typing {
    padding: 6px 16px;
    display: flex;
    gap: 4px;
}

.agentic-overlay-typing span {
    width: 7px;
    height: 7px;
    background: var(--aco-text-muted);
    border-radius: 50%;
    animation: agenticOverlayTyping 1.4s infinite ease-in-out;
}

.agentic-overlay-typing span:nth-child(2) { animation-delay: 0.2s; }
.agentic-overlay-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes agenticOverlayTyping {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1;   }
}

/* ------------------------------------------------------------------ */
/*  Image preview                                                      */
/* ------------------------------------------------------------------ */
.agentic-overlay-image-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--aco-agent-bg);
    border-top: 1px solid var(--aco-border);
}

.agentic-overlay-image-preview img {
    max-height: 60px;
    max-width: 100px;
    border-radius: 6px;
    object-fit: cover;
}

.agentic-overlay-remove-img {
    background: var(--aco-code-bg);
    border: none;
    color: var(--aco-text);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.agentic-overlay-remove-img:hover {
    background: rgba(214, 54, 56, 0.2);
    color: #d63638;
}

/* ------------------------------------------------------------------ */
/*  Input form                                                         */
/* ------------------------------------------------------------------ */
.agentic-overlay-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--aco-border);
    flex-shrink: 0;
    background: var(--aco-bg);
}

.agentic-overlay-attach {
    background: none;
    border: 1px solid var(--aco-border);
    border-radius: 6px;
    padding: 6px;
    color: var(--aco-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s, border-color 0.15s;
}

.agentic-overlay-attach:hover {
    color: var(--aco-primary);
    border-color: var(--aco-primary);
}

.agentic-overlay-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--aco-border);
    border-radius: 18px;
    resize: none;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: var(--aco-bg);
    color: var(--aco-text);
}

.agentic-overlay-input:focus {
    border-color: var(--aco-primary);
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

.agentic-overlay-send {
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--aco-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.agentic-overlay-send:hover {
    background: var(--aco-primary-hover);
}

.agentic-overlay-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Footer branding */
.agentic-overlay-footer {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--aco-text-muted);
    text-align: center;
    border-top: 1px solid var(--aco-border);
    opacity: 0.5;
}

/* ------------------------------------------------------------------ */
/*  Responsive                                                         */
/* ------------------------------------------------------------------ */
@media (max-width: 480px) {
    .agentic-overlay-panel {
        width: calc(100% - 16px);
        right: 8px;
        bottom: 8px;
        height: calc(100vh - 60px);
        border-radius: 10px;
    }
}

/* Quota / credit limit error highlight */
.agentic-quota-error .agentic-message-content {
    border-left: 3px solid #f59e0b;
    padding-left: 0.75rem;
}
.agentic-quota-error .agentic-message-content a {
    color: #f59e0b;
    font-weight: 600;
    text-decoration: none;
}
.agentic-quota-error .agentic-message-content a:hover {
    text-decoration: underline;
}
