html, body {
    margin: 0;
    height: 100%;
}

/* Shown until Blazor finishes booting and replaces #app's content (spec §14.3). */
.lexira-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-family: Charter, Georgia, serif;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
    color: #1B2A4A;
}

/* ---------- Auth screens (Login/Register/AcceptInvite/ForgotPassword/ResetPassword) ---------- */
/* Split hero + form layout, matching the design mockup (spec §14.12). */

.lexira-auth-screen {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    min-height: 100vh;
}

.lexira-auth-hero {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.lexira-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: Charter, Georgia, serif;
    font-weight: 700;
    font-size: 1.3rem;
}

.lexira-brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--mud-palette-tertiary);
    color: #1E1707;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.lexira-auth-hero-title {
    font-family: Charter, Georgia, serif;
    font-weight: 700;
    max-width: 20ch;
    text-wrap: balance;
    margin-bottom: 0.9rem !important;
}

.lexira-auth-hero-copy {
    max-width: 34ch;
    opacity: 0.8;
}

.lexira-auth-hero-foot {
    letter-spacing: 0.1em;
    opacity: 0.55;
}

.lexira-auth-form-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
}

.lexira-auth-form {
    width: 100%;
    max-width: 360px;
    background: transparent !important;
}

.lexira-auth-form-foot {
    margin-top: 1.8rem;
    padding-top: 1.4rem;
    border-top: 1px solid var(--mud-palette-lines-default);
    font-size: 0.88rem;
    color: var(--mud-palette-text-secondary);
}

@media (max-width: 900px) {
    .lexira-auth-screen {
        grid-template-columns: 1fr;
    }

    .lexira-auth-hero {
        padding: 2rem;
    }
}

/* Simple centered card for the lighter-weight auth screens (forgot/reset password). */
.lexira-auth-standalone {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-background);
    padding: 2rem;
}

.lexira-auth-standalone .lexira-auth-form {
    background: var(--mud-palette-surface) !important;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    padding: 2.25rem;
}

/* ---------- Legal assistant chat (spec §17.2) ---------- */
/* Modelled on the web chat interfaces people know: a centred reading column, the user's messages in a bubble on
   the right, the assistant's answers as plain formatted text beside an avatar, a rounded composer at the bottom.
   Colours come from the MudBlazor palette, so light and dark themes both follow. */

.lexira-chat {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 230px);
    min-height: 480px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 16px;
    overflow: hidden;
}

.lexira-chat-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1.5rem 1rem 0.5rem;
}

.lexira-chat-column {
    width: 100%;
    max-width: 768px;
    margin: 0 auto;
    box-sizing: border-box;
}

.lexira-chat-conversation {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    padding: 0.4rem 0.5rem 0.4rem 0.75rem;
    margin-bottom: 2px;
    border-radius: 8px;
    cursor: pointer;
}

.lexira-chat-conversation:hover { background: var(--mud-palette-action-default-hover); }
.lexira-chat-conversation.active { background: var(--mud-palette-action-selected); }

.lexira-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 3rem 0 1rem;
}

.lexira-chat-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    width: 100%;
}

.lexira-chat-suggestion {
    font: inherit;
    font-size: 0.875rem;
    text-align: left;
    color: var(--mud-palette-text-primary);
    background: transparent;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.lexira-chat-suggestion:hover { background: var(--mud-palette-action-default-hover); }

.lexira-chat-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.lexira-chat-row.user { justify-content: flex-end; }

.lexira-chat-bubble {
    max-width: 80%;
    padding: 0.65rem 1rem;
    border-radius: 18px 18px 4px 18px;
    background: var(--mud-palette-background-gray, var(--mud-palette-background-grey));
    color: var(--mud-palette-text-primary);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.lexira-chat-avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.lexira-chat-avatar.large { width: 56px; height: 56px; }

.lexira-chat-answer {
    flex: 1 1 auto;
    min-width: 0;
    padding-top: 0.2rem;
}

.lexira-chat-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.25rem;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.lexira-chat-row:hover .lexira-chat-actions { opacity: 1; }

.lexira-chat-sources {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 12px;
    overflow: hidden;
}

.lexira-chat-source { margin-bottom: 0.75rem; }

.lexira-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 32px;
}

.lexira-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mud-palette-text-secondary);
    animation: lexira-chat-typing 1.2s infinite ease-in-out;
}

.lexira-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.lexira-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes lexira-chat-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
    .lexira-chat-typing span { animation: none; opacity: 0.6; }
}

.lexira-chat > .lexira-chat-column { padding: 0.5rem 1rem 0.75rem; }

.lexira-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 24px;
    background: var(--mud-palette-surface);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.lexira-chat-composer:focus-within { border-color: var(--mud-palette-primary); }

.lexira-chat-composer textarea {
    flex: 1 1 auto;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 200px;
    padding: 0.4rem 0;
}

.lexira-chat-composer textarea::placeholder { color: var(--mud-palette-text-secondary); }

.lexira-chat-send {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    transition: opacity 0.15s;
}

.lexira-chat-send:disabled { opacity: 0.35; cursor: default; }

.lexira-chat-hint {
    display: block;
    text-align: center;
    margin-top: 0.4rem;
}

/* Markdown answers (SafeMarkdown) */

.lexira-markdown {
    color: var(--mud-palette-text-primary);
    font-size: 1rem;
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.lexira-markdown > :first-child { margin-top: 0; }
.lexira-markdown > :last-child { margin-bottom: 0; }

.lexira-markdown p { margin: 0 0 0.9em; }

.lexira-markdown h1,
.lexira-markdown h2,
.lexira-markdown h3,
.lexira-markdown h4 {
    font-weight: 600;
    line-height: 1.3;
    margin: 1.3em 0 0.5em;
}

.lexira-markdown h1 { font-size: 1.4rem; }
.lexira-markdown h2 { font-size: 1.25rem; }
.lexira-markdown h3 { font-size: 1.1rem; }
.lexira-markdown h4 { font-size: 1rem; }

.lexira-markdown ul,
.lexira-markdown ol {
    margin: 0 0 0.9em;
    padding-left: 1.5em;
}

.lexira-markdown li { margin: 0.3em 0; }
.lexira-markdown li > p { margin: 0 0 0.4em; }
.lexira-markdown li::marker { color: var(--mud-palette-text-secondary); }

.lexira-markdown strong { font-weight: 600; }

.lexira-markdown a {
    color: var(--mud-palette-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.lexira-markdown blockquote {
    margin: 0 0 0.9em;
    padding: 0.1em 1em;
    border-left: 3px solid var(--mud-palette-tertiary);
    color: var(--mud-palette-text-secondary);
}

.lexira-markdown code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.875em;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--mud-palette-action-default-hover);
}

.lexira-markdown pre {
    margin: 0 0 0.9em;
    padding: 0.85em 1em;
    border-radius: 8px;
    overflow-x: auto;
    background: var(--mud-palette-action-default-hover);
}

.lexira-markdown pre code { padding: 0; background: none; }

.lexira-markdown hr {
    border: none;
    border-top: 1px solid var(--mud-palette-lines-default);
    margin: 1.2em 0;
}

.lexira-markdown table {
    display: block;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 0 0 0.9em;
    font-size: 0.925rem;
}

.lexira-markdown th,
.lexira-markdown td {
    border: 1px solid var(--mud-palette-lines-default);
    padding: 0.4em 0.75em;
    text-align: left;
}

.lexira-markdown th { background: var(--mud-palette-action-default-hover); font-weight: 600; }

/* A generated document (spec §17.7): read like a letter, not like a chat reply. */
.lexira-document {
    font-family: Charter, Georgia, serif;
    font-size: 1.02rem;
    line-height: 1.7;
}

.lexira-document hr { margin: 1.5em 0; }

@media (max-width: 600px) {
    .lexira-chat { height: calc(100vh - 180px); border-radius: 12px; }
    .lexira-chat-scroll { padding: 1rem 0.75rem 0.5rem; }
    .lexira-chat > .lexira-chat-column { padding: 0.5rem 0.5rem 0.75rem; }
    .lexira-chat-bubble { max-width: 88%; }
    .lexira-chat-row { gap: 0.5rem; }
}


#blazor-error-ui {
    background: #b32121;
    color: white;
    bottom: 0;
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.8rem 1.2rem 0.8rem 3rem;
    position: fixed;
    width: 100%;
    /* Above every MudBlazor layer (drawer, app bar, dialogs, snackbars, tooltips — all in the low thousands):
       the Blazor template's 1000 left the bar behind the navigation drawer. */
    z-index: 10000;
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: 0.5rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
