/* AI Assistant chat page — admin-only Gemini interface backed by IVTracker MCP. */

.ai-chat-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0;
    min-height: 200px;
}

.ai-empty-hero {
    padding: 1.5rem;
    background: var(--bg-secondary);
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md, 8px);
    text-align: center;
}

.ai-suggestion-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.ai-suggestion {
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm, 4px);
    color: var(--text-primary);
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
}
.ai-suggestion:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.08);
    border-color: rgba(59, 130, 246, 0.4);
}
.ai-suggestion:disabled { opacity: 0.5; cursor: not-allowed; }

.ai-turn {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

.ai-turn-user {
    background: rgba(59, 130, 246, 0.06);
    border-left: 3px solid #3b82f6;
}

.ai-turn-assistant {
    background: var(--bg-secondary);
    border-left: 3px solid #16a34a;
}

.ai-turn-error {
    background: rgba(220, 38, 38, 0.06);
    border-left: 3px solid #dc2626;
}

.ai-turn-thinking {
    border-style: dashed;
    opacity: 0.85;
}

.ai-turn-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.4rem;
    font-size: 11px;
    color: var(--text-muted);
}

.ai-turn-role {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-turn-time {
    font-variant-numeric: tabular-nums;
}

.ai-turn-body {
    color: var(--text-primary);
    line-height: 1.55;
    font-size: var(--text-sm);
}

/* Markdown render styling — keep tight, scannable */
.ai-turn-body h1, .ai-turn-body h2, .ai-turn-body h3 {
    margin: 0.75rem 0 0.4rem 0;
    font-weight: 600;
}
.ai-turn-body h1 { font-size: 1.05rem; }
.ai-turn-body h2 { font-size: 1rem; }
.ai-turn-body h3 { font-size: 0.95rem; }
.ai-turn-body p { margin: 0.4rem 0; }
.ai-turn-body ul, .ai-turn-body ol { margin: 0.4rem 0; padding-left: 1.4rem; }
.ai-turn-body li { margin: 0.15rem 0; }
.ai-turn-body code {
    background: var(--bg-tertiary, rgba(0, 0, 0, 0.06));
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.85em;
}
.ai-turn-body pre {
    background: var(--bg-primary);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.85em;
}
.ai-turn-body table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    width: 100%;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
.ai-turn-body th, .ai-turn-body td {
    padding: 4px 8px;
    border: 1px solid var(--border-primary);
    text-align: left;
}
.ai-turn-body th {
    background: rgba(59, 130, 246, 0.06);
    font-weight: 600;
}
.ai-turn-body strong { color: var(--text-primary); }

/* Tool-call accordion */
.ai-tools {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
}
.ai-tools summary {
    cursor: pointer;
    font-size: 11px;
    color: var(--text-muted);
    user-select: none;
}
.ai-tools[open] summary { margin-bottom: 0.5rem; }

.ai-tool-trace {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.ai-tool-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11px;
}

.ai-tool-args {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    background: var(--bg-primary);
    padding: 4px 6px;
    border-radius: 3px;
    margin: 0 0 4px 0;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
}

.ai-tool-result {
    font-size: 11px;
    color: var(--text-muted);
    max-height: 300px;
    overflow-y: auto;
}

/* Input row */
.ai-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin-top: 0.5rem;
}

.ai-input {
    flex: 1;
    min-height: 60px;
    resize: vertical;
    font-family: inherit;
    font-size: var(--text-sm);
}

@media (max-width: 720px) {
    .ai-suggestion-grid { grid-template-columns: 1fr; }
    .ai-input-row { flex-direction: column; }
    .ai-input-row .qs-btn-primary { width: 100%; }
}
