/* Agent Widget Styles (Docked Right Panel) - Light Glassmorphism Theme */
/* Scoped to .app-container so these styles do NOT affect the
   Grafana-specific fixed-position widget (which lives on document.body
   and is styled by revive_widget_grafana.css instead). */
:root {
    --ai-helper-width: 380px;
}

.app-container #agent-widget {
    grid-column: 3;
    grid-row: 2 / -1;
    height: 100%;
    width: 100%;
    position: relative;
    z-index: 100;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    pointer-events: auto;
    overflow: hidden;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-left: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.05);
}

/* Hide when closed */
.app-container:not(.ai-open) #agent-widget {
    visibility: hidden;
    pointer-events: none;
    width: 0;
}

#agent-fab {
    display: none !important;
}

.app-container #agent-window {
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.app-container.ai-open #agent-window {
    opacity: 1;
}

/* Header - matches app header style */
.agent-header {
    height: 48px;
    padding: 0 1rem;
    background: var(--bg-header, #0f0e47);
    border-bottom: 1px solid var(--border-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    color: var(--text-header);
}

.agent-header .font-semibold {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-header);
}

/* RE-VIVE mark in the widget header. border-color + box-shadow glow reflect
   live backend status (see setAgentStatus() in revive_widget.js) rather than
   a hardcoded "online" dot. */
.agent-status-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #3b82f6, #7c3aed);
    color: #fff;
    font-size: 12px;
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.agent-status-badge[data-status="ok"] {
    border-color: #4ade80;
    animation: agent-status-glow-ok 2s ease-in-out infinite;
}

.agent-status-badge[data-status="error"] {
    border-color: #f87171;
    animation: agent-status-glow-error 2s ease-in-out infinite;
}

@keyframes agent-status-glow-ok {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55); }
    50% { box-shadow: 0 0 8px 3px rgba(74, 222, 128, 0.55); }
}

@keyframes agent-status-glow-error {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55); }
    50% { box-shadow: 0 0 8px 3px rgba(248, 113, 113, 0.55); }
}

.agent-header button {
    background: transparent;
    border: none;
    color: var(--text-header);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
    opacity: 0.8;
}

.agent-header button:hover {
    background: var(--header-btn-hover);
    color: var(--text-header);
    opacity: 1;
}

/* Messages Area - Light glass style */
.agent-messages {
    flex: 1;
    padding: 1.25rem 1rem;
    overflow-y: auto;
    background: linear-gradient(180deg, #f1f5f9 0%, #e8ecf1 100%);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Message Bubbles - Premium Glass */
.agent-message {
    max-width: 90%;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.agent-message.user {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.agent-message.ai {
    background: rgba(255, 255, 255, 0.85);
    color: #1e293b;
    align-self: flex-start;
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(10px);
}

.agent-message pre {
    background: #1e293b;
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

.agent-message code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85em;
}

/* ── Markdown rendering inside AI messages ── */
.agent-message.ai h1,
.agent-message.ai h2,
.agent-message.ai h3,
.agent-message.ai h4 {
    font-weight: 700;
    margin-top: 0.85rem;
    margin-bottom: 0.3rem;
    color: #0f172a;
    line-height: 1.3;
}
.agent-message.ai h1 { font-size: 1.1rem; }
.agent-message.ai h2 { font-size: 0.98rem; border-bottom: 1px solid #e2e8f0; padding-bottom: 0.2rem; }
.agent-message.ai h3 { font-size: 0.9rem; color: #334155; }

.agent-message.ai p {
    margin-bottom: 0.5rem;
    line-height: 1.6;
    color: #1e293b;
}

.agent-message.ai ul,
.agent-message.ai ol {
    margin: 0.3rem 0 0.5rem 1.2rem;
    padding-left: 0.2rem;
}
.agent-message.ai ul { list-style-type: disc; }
.agent-message.ai ol { list-style-type: decimal; }
.agent-message.ai li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
    color: #1e293b;
}
.agent-message.ai li > ul,
.agent-message.ai li > ol {
    margin-top: 0.15rem;
    margin-bottom: 0;
}

.agent-message.ai strong,
.agent-message.ai b {
    font-weight: 700;
    color: #0f172a;
}

.agent-message.ai em,
.agent-message.ai i {
    font-style: italic;
    color: #334155;
}

.agent-message.ai code {
    background: #f1f5f9;
    color: #0369a1;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    font-size: 0.82rem;
    white-space: nowrap;
}

.agent-message.ai pre {
    background: #1e293b;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid #334155;
    margin: 0.5rem 0 0.6rem;
    padding: 0.75rem;
}
.agent-message.ai pre code {
    background: transparent;
    border: none;
    padding: 0;
    color: #86efac;
    font-size: 0.82rem;
    white-space: pre;
}

.agent-message.ai blockquote {
    border-left: 3px solid #7c3aed;
    margin: 0.4rem 0;
    padding: 0.25rem 0.65rem;
    background: #f5f3ff;
    border-radius: 0 4px 4px 0;
    color: #5b21b6;
    font-style: italic;
}

.agent-message.ai table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.4rem 0 0.6rem;
    font-size: 0.82rem;
}
.agent-message.ai th {
    background: #e2e8f0;
    color: #0f172a;
    font-weight: 600;
    padding: 0.35rem 0.5rem;
    text-align: left;
    border: 1px solid #cbd5e1;
}
.agent-message.ai td {
    padding: 0.3rem 0.5rem;
    border: 1px solid #e2e8f0;
    color: #1e293b;
}
.agent-message.ai tr:nth-child(even) td {
    background: #f8fafc;
}

.agent-message.ai hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 0.6rem 0;
}

.agent-message.ai a {
    color: #4f46e5;
    text-decoration: underline;
}
.agent-message.ai a:hover {
    color: #6366f1;
}

/* Remove excess margins at edges */
.agent-message.ai > :first-child { margin-top: 0; }
.agent-message.ai > :last-child  { margin-bottom: 0; }

/* Input Area - Glass Style */
.agent-input-area {
    padding: 0;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.revive-widget-composer #agent-input {
    font-size: 0.9rem;
}

.revive-widget-composer #agent-input::placeholder {
    color: #94a3b8;
}

.revive-widget-composer #agent-send {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: #3b82f6;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s, background 0.2s;
}

.revive-widget-composer #agent-send:hover {
    color: #2563eb;
    background: rgba(59, 130, 246, 0.1);
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: ew-resize;
    z-index: 100;
    background: transparent;
}

.resize-handle:hover {
    background: linear-gradient(180deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

/* Status indicator in header */
.agent-header .bg-green-400 {
    background-color: #4ade80;
}

/* Scrollbar styling for messages */
.agent-messages::-webkit-scrollbar {
    width: 6px;
}

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

.agent-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 3px;
}

.agent-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}
