/* AI Analyst — slide-over chat panel (BYOK) */
/* Menu-header launch button (sits beside the tier/copier badges). auth.js toggles
   style.display between 'none' and '' — the '' state falls back to this class. */
/* Sidebar AI Analyst section — robot + name + purple "Open" pill, sitting in
   its own block between the user header and Dashboard. Whole row is
   clickable (matters in collapsed mode, where the pill is hidden and only
   the icon remains). */
.ai-analyst-row { display: flex; align-items: center; }
.ai-analyst-icon { color: #8b5cf6; }
.ai-analyst-open-btn {
    margin-left: auto;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff; border: none; cursor: pointer;
    padding: 4px 16px; border-radius: 14px;
    font-size: 0.75em; font-weight: 600; white-space: nowrap;
    font-family: inherit;
}
.ai-analyst-open-btn:hover { filter: brightness(1.15); }
.side-menu.collapsed .ai-analyst-open-btn { display: none; }
.ai-analyst-beta {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border: 1px solid #8b5cf6;
    border-radius: 10px;
    color: #a78bfa;
    font-size: 0.62em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    vertical-align: 1px;
}

.ai-analyst-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(480px, 100vw);
    /* Solid color, NOT var(--bg-card) — that var is rgba with 0.5 alpha in dark
       theme and the dashboard would bleed through the slide-over. */
    background: #1e293b;
    border-left: 1px solid var(--border-color, #2a2e3a);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
    display: flex; flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease, width 0.25s ease;
    z-index: 10500;
}
body.light-theme .ai-analyst-panel { background: #ffffff; }
.ai-analyst-panel.open { transform: translateX(0); }
/* Fullscreen spans the CONTENT area, keeping the accounts sidebar visible:
   the panel is right-anchored, so subtracting the sidebar width (280px, or
   80px when body.menu-collapsed) leaves the menu usable on the left. On
   mobile the sidebar is an overlay, so fullscreen stays edge-to-edge. */
.ai-analyst-panel.fullscreen { width: calc(100vw - 280px); }
body.menu-collapsed .ai-analyst-panel.fullscreen { width: calc(100vw - 80px); }
@media (max-width: 768px) {
    .ai-analyst-panel.fullscreen { width: 100vw; }
}
/* In fullscreen, keep the conversation a readable centered column */
.ai-analyst-panel.fullscreen .ai-analyst-messages,
.ai-analyst-panel.fullscreen .ai-analyst-input-area,
.ai-analyst-panel.fullscreen .ai-analyst-context {
    width: 100%; max-width: 900px; margin-left: auto; margin-right: auto;
}

.ai-analyst-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #6d28d9, #8b5cf6);
    color: #fff;
}
.ai-analyst-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.ai-analyst-header select {
    background: rgba(255, 255, 255, 0.15); color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 6px;
    font-size: 12px; padding: 3px 6px; margin-left: 8px;
}
.ai-analyst-header select option { color: #111; }
.ai-analyst-close, .ai-analyst-expand {
    background: none; border: none; color: #fff; cursor: pointer;
    padding: 4px; display: flex; align-items: center;
}
.ai-analyst-context {
    padding: 6px 16px; font-size: 12px;
    color: var(--text-secondary, #9aa1b1);
    border-bottom: 1px solid var(--border-color, #2a2e3a);
    background: var(--bg-secondary, #12141a);
}
.ai-analyst-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.ai-msg { max-width: 92%; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; word-wrap: break-word; }
.ai-msg-user { align-self: flex-end; background: #6d28d9; color: #fff; border-bottom-right-radius: 4px; }
.ai-msg-assistant { align-self: flex-start; background: var(--bg-secondary, #12141a); color: var(--text-primary, #e8eaf0); border: 1px solid var(--border-color, #2a2e3a); border-bottom-left-radius: 4px; }
.ai-msg-system { align-self: center; background: none; color: var(--text-secondary, #9aa1b1); font-size: 12px; text-align: center; }
.ai-msg-error { align-self: center; background: rgba(231, 76, 60, 0.12); color: #e74c3c; font-size: 12.5px; }
/* Turn discarded from the model's message history (exhaustion/abort/network-error/failure
   truncated state.messages) but left in the DOM since the user already read it — dim, don't delete. */
.ai-msg-discarded { opacity: 0.45; }
.ai-msg code { background: rgba(139, 92, 246, 0.12); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.ai-msg-h { font-weight: 600; margin: 10px 0 4px; font-size: 14px; }
.ai-msg-table-wrap { overflow-x: auto; margin: 8px 0; }
.ai-msg table { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
.ai-msg th, .ai-msg td { border: 1px solid var(--border-color, #2a2e3a); padding: 5px 9px; text-align: left; }
.ai-msg th { background: rgba(139, 92, 246, 0.14); font-weight: 600; white-space: nowrap; }
.ai-analyst-input-area {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border-color, #2a2e3a);
}
.ai-analyst-input-area textarea {
    flex: 1; resize: none; max-height: 120px;
    background: var(--bg-secondary, #12141a);
    color: var(--text-primary, #e8eaf0);
    border: 1px solid var(--border-color, #2a2e3a);
    border-radius: 8px; padding: 9px 10px; font-size: 13.5px; font-family: inherit;
}
.ai-analyst-send {
    background: #6d28d9; border: none; border-radius: 8px; color: #fff;
    width: 40px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.ai-analyst-send:disabled { opacity: 0.45; cursor: default; }
.ai-analyst-send svg { width: 18px; height: 18px; fill: currentColor; }
.ai-analyst-disclaimer {
    padding: 6px 16px 10px; font-size: 11px; text-align: center;
    color: var(--text-secondary, #9aa1b1);
}
@media (max-width: 560px) { .ai-analyst-panel { width: 100vw; } }
