/* PSC.Blazor.Components.Sage — chat UI */

.sage-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color, #dee2e6);
    box-shadow: 0 10px 40px rgba(0,0,0,0.12);
}

.sage-panel.sage-compact { font-size: 0.92rem; }

.sage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
}

.sage-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.sage-title i { font-size: 1.25rem; }

.sage-close {
    background: rgba(255,255,255,0.15);
    border: none; color: #fff; width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.sage-close:hover { background: rgba(255,255,255,0.3); }

.sage-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.sage-empty {
    text-align: center; color: var(--bs-secondary-color, #6c757d);
    padding: 32px 16px;
}
.sage-empty i { font-size: 2.5rem; opacity: 0.4; }
.sage-empty p { margin: 12px 0 16px; }

.sage-suggestions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.sage-suggestion {
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px; padding: 8px 12px; text-align: left; cursor: pointer;
    color: var(--bs-body-color, #212529);
    transition: border-color 0.15s, background 0.15s;
}
.sage-suggestion:hover { border-color: #6366f1; background: rgba(99,102,241,0.05); }

.sage-msg { display: flex; flex-direction: column; max-width: 85%; }
.sage-msg-user { align-self: flex-end; align-items: flex-end; }
.sage-msg-assistant { align-self: flex-start; align-items: flex-start; }

.sage-bubble {
    padding: 10px 14px; border-radius: 14px; line-height: 1.5;
    word-wrap: break-word; overflow-wrap: anywhere;
}
.sage-msg-user .sage-bubble {
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
    border-bottom-right-radius: 4px;
}
.sage-msg-assistant .sage-bubble {
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-bottom-left-radius: 4px;
}

.sage-bubble code {
    background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 3px;
    font-size: 0.9em;
}
.sage-msg-user .sage-bubble code { background: rgba(255,255,255,0.18); }

.sage-bubble a { color: inherit; text-decoration: underline; }

.sage-citations {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px;
}
.sage-cite {
    font-size: 0.78rem; padding: 3px 8px; border-radius: 999px;
    background: rgba(99,102,241,0.1); color: #6366f1;
    text-decoration: none; border: 1px solid rgba(99,102,241,0.2);
}
.sage-cite:hover { background: rgba(99,102,241,0.18); }

.sage-feedback {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    margin-top: 6px; font-size: 0.8rem;
}
.sage-feedback-label { color: var(--bs-secondary-color, #6c757d); }
.sage-feedback-given { color: var(--bs-secondary-color, #6c757d); font-style: italic; }
.sage-fb-btn {
    background: transparent; border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px; padding: 2px 8px; cursor: pointer;
    color: var(--bs-secondary-color, #6c757d);
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.sage-fb-btn:hover { border-color: #6366f1; color: #6366f1; background: rgba(99,102,241,0.05); }
.sage-feedback-comment { width: 100%; }

.sage-typing { display: inline-flex; gap: 4px; padding: 14px 18px; }
.sage-typing span {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--bs-secondary-color, #6c757d); opacity: 0.4;
    animation: sage-bounce 1.2s infinite ease-in-out;
}
.sage-typing span:nth-child(2) { animation-delay: 0.15s; }
.sage-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sage-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.sage-input {
    display: flex; gap: 8px; padding: 12px;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    background: var(--bs-body-bg, #fff);
}
.sage-input input {
    flex: 1; padding: 10px 14px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 999px; font-size: 0.95rem;
    background: var(--bs-body-bg, #fff); color: var(--bs-body-color, #212529);
}
.sage-input input:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.sage-input button {
    width: 42px; height: 42px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.sage-input button:disabled { opacity: 0.5; cursor: not-allowed; }

.sage-error {
    padding: 8px 12px; background: #fef2f2; color: #b91c1c;
    border-top: 1px solid #fecaca; font-size: 0.85rem;
}

/* ─── Floating widget ───────────────────────────────────────── */

.sage-widget {
    position: fixed; bottom: 24px; right: 24px; z-index: 1050;
    display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}

.sage-widget-button {
    width: 56px; height: 56px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
    box-shadow: 0 4px 14px rgba(99,102,241,0.4); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.15s, box-shadow 0.15s;
}
.sage-widget-button:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(99,102,241,0.5); }
.sage-widget-button.sage-open { background: #475569; box-shadow: 0 4px 14px rgba(0,0,0,0.2); }

.sage-widget-panel {
    width: 380px; height: 560px; max-height: calc(100vh - 120px);
    animation: sage-slide-up 0.2s ease-out;
}

@keyframes sage-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 480px) {
    .sage-widget { bottom: 12px; right: 12px; left: 12px; align-items: stretch; }
    .sage-widget-button { align-self: flex-end; }
    .sage-widget-panel { width: 100%; height: calc(100vh - 100px); }
}

/* ─── Admin dashboard ───────────────────────────────────────── */

.sage-admin { max-width: 100%; overflow-x: hidden; }
.sage-admin .card { overflow: hidden; }
.sage-admin-trunc { min-width: 0; overflow: hidden; }
.sage-admin-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Dark mode */
[data-bs-theme="dark"] .sage-bubble code { background: rgba(255,255,255,0.08); }
[data-bs-theme="dark"] .sage-error { background: #422; color: #fca5a5; border-color: #5a1f1f; }
