/* =====================================================
   Satoru — Quantum Automation AI Assistant.
   Built on the suite's tokens (css/tokens.css) and MudTheme (CasTheme.cs).
   House rules followed here: gradients are for chrome only, surfaces are
   white on a slate canvas, and status colours are never decoration.
   ===================================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
}

main {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

.askme-page {
    /* Exactly the viewport, never taller: the page itself must not scroll —
       the messages pane is the only scroll region. */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--cas-canvas);
    color: var(--cas-body);
    font-family: var(--cas-font);
}

/* ---- Header: the only gradient on the page ---- */
.askme-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    height: 64px;
    background: var(--cas-gradient-hero);
    color: #fff;
    box-shadow: var(--cas-shadow-card);
}

.askme-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

/* The QAI mark is its own rounded bubble on a transparent canvas, so it needs no plate
   behind it — a soft shadow is enough to lift it off the dark gradient. */
.askme-mark {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.askme-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
}

.askme-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.askme-title {
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.3;
}

.askme-tagline {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.68);
    line-height: 1.3;
}

.askme-disclaimer {
    font-size: 0.75rem;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.55);
    text-align: right;
    max-width: 66ch; /* wraps the long advisory to 3 lines inside the 64px header */
}

/* ---- Layout: one conversation per tab, so the chat panel is the whole body ---- */
.askme-content {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 24px 24px;
    display: flex;
}

/* ---- Chat panel ---- */
.askme-chat {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--cas-surface);
    border: 1px solid var(--cas-line);
    border-radius: var(--cas-radius-card);
    box-shadow: var(--cas-shadow-card);
}

/* Status colour, paired with an icon + label — never decorative. */
.askme-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 16px 20px 0;
    padding: 11px 14px;
    border-radius: var(--cas-radius-card);
    background: var(--cas-warning-soft);
    color: var(--cas-warning-deep);
    border: 1px solid rgba(237, 108, 2, 0.22);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.askme-alert code {
    font-family: var(--cas-font-mono);
    font-size: 0.78em;
    background: rgba(154, 74, 0, 0.10);
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

/* ---- Messages ---- */
.askme-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--cas-line) transparent;
}

.askme-messages::-webkit-scrollbar {
    width: 6px;
}

.askme-messages::-webkit-scrollbar-thumb {
    background: var(--cas-line);
    border-radius: 3px;
}

.askme-msg {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.askme-msg--bot {
    flex-direction: row;
}

.askme-msg--user {
    flex-direction: row-reverse;
}

/* Only the greeting animates in; replies would jitter the scroll anchor. Driven purely by CSS so the
   greeting is still visible if the Blazor circuit never connects — its resting state is opacity 1. */
.askme-messages > .askme-msg:first-child {
    animation: askmeFadeIn 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes askmeFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* Same mark as the header, at message scale. No circle crop: the bubble's tail and
   rounded corners are part of the logo. */
.askme-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.askme-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.askme-bubble {
    max-width: min(68%, 720px);
    padding: 12px 16px;
    border-radius: var(--cas-radius-card);
    font-size: 0.875rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.askme-bubble--bot {
    background: var(--cas-navy-tint);
    color: var(--cas-ink);
    border-top-left-radius: var(--cas-radius-control);
}

.askme-bubble--user {
    background: var(--cas-navy-700);
    color: #fff;
    border-top-right-radius: var(--cas-radius-control);
}

/* ---- Typing indicator ---- */
.askme-typing {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    padding: 3px 0;
}

.askme-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cas-teal-500);
    animation: askmeDot 1.2s infinite;
}

.askme-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.askme-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes askmeDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ---- Composer ---- */
.askme-input {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 18px 16px;
    border-top: 1px solid var(--cas-line-soft);
    background: var(--cas-surface);
}

.askme-input-field {
    width: 100%;
    margin: 0;
}

/* MudBlazor reserves space for helper text we never use. */
.askme-input-field .mud-input-helper-text,
.askme-input-field .mud-input-helper-container {
    display: none;
}

.askme-input-field .mud-input-adornment {
    cursor: pointer;
}

/* ---- Markdown inside bot answers ---- */
.askme-bubble--bot > :first-child {
    margin-top: 0;
}

.askme-bubble--bot > :last-child {
    margin-bottom: 0;
}

.askme-bubble--bot p {
    margin: 0.4rem 0;
}

.askme-bubble--bot h1,
.askme-bubble--bot h2,
.askme-bubble--bot h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--cas-navy-800);
    margin: 0.8rem 0 0.35rem;
}

.askme-bubble--bot strong {
    font-weight: 600;
}

.askme-bubble--bot a {
    color: var(--cas-info-deep);
    text-decoration: underline;
}

.askme-bubble--bot ul,
.askme-bubble--bot ol {
    padding-left: 1.35rem;
    margin: 0.45rem 0;
}

.askme-bubble--bot li {
    margin: 0.25rem 0;
}

.askme-bubble--bot code {
    font-family: var(--cas-font-mono);
    font-size: 0.82em;
    background: var(--cas-surface);
    border: 1px solid var(--cas-line);
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

.askme-bubble--bot pre {
    background: var(--cas-console);
    color: #E6EDF3;
    padding: 12px 14px;
    border-radius: var(--cas-radius-control);
    overflow-x: auto;
    margin: 0.6rem 0;
}

.askme-bubble--bot pre code {
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
}

.askme-bubble--bot table {
    border-collapse: collapse;
    margin: 0.6rem 0;
    font-size: 0.8125rem;
    display: block;
    overflow-x: auto;
}

.askme-bubble--bot th,
.askme-bubble--bot td {
    border: 1px solid var(--cas-line);
    padding: 6px 10px;
    text-align: left;
}

.askme-bubble--bot th {
    background: var(--cas-surface);
    font-weight: 600;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .askme-content {
        padding: 12px;
    }

    .askme-disclaimer {
        display: none;
    }
}

@media (max-width: 600px) {
    .askme-header {
        padding: 0 14px;
    }

    .askme-bubble {
        max-width: 84%;
    }

    .askme-messages {
        padding: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    /* Resting state is already visible, so dropping the animation is enough. */
    .askme-messages > .askme-msg:first-child {
        animation: none;
    }

    .askme-typing span {
        animation: none;
    }
}

/* ---- Error page ---- */
.askme-error {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--cas-canvas);
    font-family: var(--cas-font);
}

.askme-error-card {
    max-width: 520px;
    padding: 32px;
    background: var(--cas-surface);
    border: 1px solid var(--cas-line);
    border-radius: var(--cas-radius-hero);
    box-shadow: var(--cas-shadow-card);
}

.askme-error-title {
    margin: 0 0 10px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--cas-ink);
}

.askme-error-body {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--cas-body);
}

.askme-error-meta {
    margin: 16px 0 0;
    font-size: 0.75rem;
    color: var(--cas-muted);
}

.askme-error-meta code {
    font-family: var(--cas-font-mono);
    overflow-wrap: anywhere;
}

.askme-error-action {
    display: inline-block;
    margin-top: 24px;
    padding: 9px 18px;
    border-radius: var(--cas-radius-control);
    background: var(--cas-navy-700);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
}

.askme-error-action:hover {
    background: var(--cas-navy-800);
}

/* ---- Blazor's built-in error bar (was inline in MainLayout) ---- */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    padding: 0.6rem 1.25rem 0.7rem;
    background: var(--cas-warning-soft);
    color: var(--cas-warning-deep);
    box-shadow: 0 -1px 2px rgba(15, 32, 39, 0.2);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ---- Sources under an answer: knowledge-base documents (plain chips) and web results (links) ---- */
.askme-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--cas-line-soft);
}

.askme-sources-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--cas-faint);
}

.askme-source {
    display: inline-block;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 2px 10px;
    border: 1px solid var(--cas-line);
    border-radius: 999px;
    background: var(--cas-canvas);
    color: var(--cas-muted);
    font-size: 0.75rem;
    text-decoration: none;
}

.askme-source--link {
    color: var(--cas-info);
    border-color: var(--cas-info-soft);
    background: var(--cas-info-soft);
}

.askme-source--link:hover {
    text-decoration: underline;
}
