/* NOTE: MwChat component styles
   Prefix: mw-chat-*
   Loaded via Assets["mw-chat.css"] in App.razor
   Aesthetic: refined industrial — clean dark surfaces, subtle depth, precise spacing */

/* NOTE: Page-level layout */
.mw-chat-page {
    display: flex;
    height: calc(100vh - var(--mud-appbar-height));
    background: var(--mud-palette-background);
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════
   NOTE: Sidebar
   ═══════════════════════════════════════════════════ */
.mw-chat-sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--mud-palette-surface) 60%, transparent);
    border-right: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 50%, transparent);
}

.mw-chat-sidebar-header {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.mw-chat-sidebar-search {
    position: relative;
}

.mw-chat-sidebar-search .mud-input-outlined .mud-input-outlined-border {
    border-color: color-mix(in srgb, var(--mud-palette-lines-default) 40%, transparent) !important;
    border-radius: 10px;
}

.mw-chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.mw-chat-sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.mw-chat-sidebar-list::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--mud-palette-text-secondary) 30%, transparent);
    border-radius: 2px;
}

.mw-chat-sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 24px;
    text-align: center;
    opacity: 0.5;
}

/* NOTE: Conversation list items */
.mw-chat-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.15s ease;
    position: relative;
    margin-bottom: 2px;
    border: none;
}

.mw-chat-list-item:hover {
    background: color-mix(in srgb, var(--mud-palette-action-default-hover) 80%, transparent);
}

.mw-chat-list-item--active {
    background: color-mix(in srgb, var(--mud-palette-primary) 15%, transparent);
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
}

.mw-chat-list-item--active:hover {
    background: color-mix(in srgb, var(--mud-palette-primary) 20%, transparent);
}

.mw-chat-list-item-content {
    flex: 1;
    min-width: 0;
}

.mw-chat-list-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.mw-chat-list-item-preview {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.mw-chat-list-item-time {
    font-size: 0.65rem;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-variant-numeric: tabular-nums;
}

/* NOTE: Delete button — appears on hover */
.mw-chat-list-item-delete {
    opacity: 0;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

.mw-chat-list-item:hover .mw-chat-list-item-delete {
    opacity: 0.6;
}

.mw-chat-list-item-delete:hover {
    opacity: 1 !important;
}

/* ═══════════════════════════════════════════════════
   NOTE: Chat area
   ═══════════════════════════════════════════════════ */
.mw-chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* NOTE: Root container (legacy, kept for compatibility) */
.mw-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* NOTE: Unread attention glow (MwChat GlowOnUnread) — a soft primary ring that pulses around the
   chat when a message from someone else arrives on an always-on-screen embed. Drawn on a
   pointer-events:none ::after overlay with an INSET shadow so the embed frame's overflow:hidden
   can't clip it. Suppressed via :focus-within — focus inside the chat means the viewer is already
   here — and cleared on the first pointer-down anywhere in the chat (MwChat.ClearUnreadGlow). */
.mw-chat--unread::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 2;
    animation: mw-chat-unread-pulse 1.8s ease-in-out infinite;
}

.mw-chat--unread:focus-within::after {
    animation: none;
    box-shadow: none;
}

@keyframes mw-chat-unread-pulse {
    0%, 100% {
        box-shadow:
            inset 0 0 0 1.5px color-mix(in srgb, var(--mud-palette-primary) 30%, transparent),
            inset 0 0 14px -2px color-mix(in srgb, var(--mud-palette-primary) 30%, transparent);
    }
    50% {
        box-shadow:
            inset 0 0 0 2px color-mix(in srgb, var(--mud-palette-primary) 90%, transparent),
            inset 0 0 34px 0 color-mix(in srgb, var(--mud-palette-primary) 65%, transparent);
    }
}

/* NOTE: Reduced-motion — hold a steady ring instead of pulsing. */
@media (prefers-reduced-motion: reduce) {
    .mw-chat--unread::after {
        animation: none;
        box-shadow:
            inset 0 0 0 1.5px color-mix(in srgb, var(--mud-palette-primary) 55%, transparent),
            inset 0 0 20px 0 color-mix(in srgb, var(--mud-palette-primary) 40%, transparent);
    }
}

/* NOTE: Standard embed frame — the ONE chrome for placing an inline <MwChat/> on a content
   page (bounded height + flex column so the chat's flex: 1; min-height: 0 fills it). Add
   page-specific layout (margins, flex-shrink, grid placement) via a second host class, never
   a competing frame. Surfaces that already bring their own frame (Messages page pane,
   Artist Büro .mw-ab-panel, floating MwWindow) embed the bare component instead. */
.mw-chat-panel {
    display: flex;
    flex-direction: column;
    height: 420px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    overflow: hidden;
}

/* NOTE: Header bar */
.mw-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 50%, transparent);
    flex-shrink: 0;
    backdrop-filter: blur(12px);
    z-index: 1;
}

.mw-chat-header-title {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* NOTE: Context window indicator */
.mw-chat-ctx-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: default;
}

.mw-chat-ctx-label {
    font-size: 0.7rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* NOTE: Scrollable message area */
.mw-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mw-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.mw-chat-messages::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--mud-palette-text-secondary) 20%, transparent);
    border-radius: 3px;
}

/* ═══════════════════════════════════════════════════
   NOTE: MwChatBubble message rows (mw-chat-msg-*) — "Stil 09" from
   docs/mockups/chat-message-styles.html: meta line (name · MwChatSenderChip · mono time)
   ABOVE the bubble instead of inside it, flat 14px bubble with a 4px tail corner, and a
   surface-colored border gradient standing on the tail side + bottom edge only. Own
   messages stay fully annotated. The legacy .mw-chat-bubble* rules further down are kept
   for ChatPage.razor's bespoke AI-chat markup only, until it is assimilated onto MwChat.
   ═══════════════════════════════════════════════════ */

/* NOTE: Flex column so message rows can align-self left/right — added alongside the shared
   .mw-chat-messages scroll class (which ChatPage's bespoke list also uses, so that one
   keeps its legacy block layout). */
.mw-chat-msglist {
    display: flex;
    flex-direction: column;
}

/* NOTE: Never let the fixed-height flex column compress message rows (media bubbles would
   squash before the list starts scrolling). */
.mw-chat-msglist > * {
    flex-shrink: 0;
}

/* NOTE: Surface color categories — derived from ChatMsg.SentFromLabel's prefix by
   MwChatSenderChip.GetSurfaceClass. --mw-chat-rail drives the chip colors and, on the
   .mw-chat-msg root, the incoming bubble's edge gradient + bloom. Default: transparent
   rail (plain hairline bubble — DMs and label-less rooms). */
.mw-chat-surface--office  { --mw-chat-rail: hsl(263 90% 70%); }
.mw-chat-surface--care    { --mw-chat-rail: hsl(172 62% 55%); }
.mw-chat-surface--driver  { --mw-chat-rail: hsl(38 92% 64%); }
.mw-chat-surface--stage   { --mw-chat-rail: hsl(210 90% 66%); }
.mw-chat-surface--neutral { --mw-chat-rail: var(--mud-palette-text-secondary); }

.mw-chat-msg {
    --mw-chat-rail: transparent;
    --mw-chat-hairline: color-mix(in srgb, var(--mud-palette-lines-default) 50%, transparent);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    align-self: flex-start;
    max-width: 84%;
    margin-bottom: 12px;
    animation: mw-chat-bubble-in 0.2s ease-out;
}

/* NOTE: The surface class must re-declare the rail AFTER the root default above wins the
   cascade (both sit on the same element). */
.mw-chat-msg.mw-chat-surface--office  { --mw-chat-rail: hsl(263 90% 70%); }
.mw-chat-msg.mw-chat-surface--care    { --mw-chat-rail: hsl(172 62% 55%); }
.mw-chat-msg.mw-chat-surface--driver  { --mw-chat-rail: hsl(38 92% 64%); }
.mw-chat-msg.mw-chat-surface--neutral { --mw-chat-rail: var(--mud-palette-text-secondary); }

.mw-chat-msg--out {
    align-self: flex-end;
    align-items: flex-end;
}

.mw-chat-msg--grouped { margin-top: -8px; }

/* NOTE: Bubble row — holds the bubble and, for the viewer's own messages, the delete control
   beside it (to the left of an outgoing bubble via row-reverse). */
.mw-chat-msg-bubblerow {
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
}

.mw-chat-msg--out .mw-chat-msg-bubblerow { flex-direction: row-reverse; }

/* NOTE: Delete control — hidden until the message is hovered (pointer devices), always faintly
   present on touch devices which have no hover. Reddens on its own hover. */
.mw-chat-msg-delete {
    flex: 0 0 auto;
    opacity: 0;
    color: var(--mud-palette-text-disabled);
    transition: opacity 0.12s ease, color 0.12s ease;
}

.mw-chat-msg:hover .mw-chat-msg-delete,
.mw-chat-msg-delete:focus-visible { opacity: 0.7; }

.mw-chat-msg-delete:hover {
    opacity: 1;
    color: var(--mud-palette-error);
}

@media (hover: none) {
    .mw-chat-msg-delete { opacity: 0.5; }
}

/* NOTE: Multi-select control — a small hovering FAB in the chat's top-right corner on moderator
   surfaces (not a full row). Idle: the "Select" checklist button. Active: a compact floating pill
   with the selected count + Cancel/Delete. Anchored to .mw-chat (position: relative). */
.mw-chat-selectfab {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 5;
    background: color-mix(in srgb, var(--mud-palette-surface) 92%, transparent);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 999px;
    box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
}

.mw-chat-selectfab--active {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px 2px 6px;
}

.mw-chat-selectfab-count {
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-primary);
}

/* NOTE: In select mode the whole message is a click target. An invisible overlay
   (mw-chat-msg-selectoverlay) is stacked over the bubble's own interactive controls (open
   image, play voice) so a select tap toggles selection instead of triggering them — no need
   to disable those controls manually. */
.mw-chat-msg--selectable { position: relative; cursor: pointer; }

.mw-chat-msg-selectoverlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    cursor: pointer;
}

.mw-chat-msg-select-mark { color: var(--mud-palette-text-secondary); }

.mw-chat-msg--selected .mw-chat-msg-select-mark { color: var(--mud-palette-primary); }

.mw-chat-msg--selected .mw-chat-msg-bubble {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
    border-radius: 12px;
}

.mw-chat-msg--system {
    align-self: center;
    align-items: center;
    max-width: 85%;
}

/* NOTE: Meta line — name · chip · time above the bubble (row-reversed for own messages),
   hidden on grouped continuations; their time moves below the bubble instead. */
.mw-chat-msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.mw-chat-msg--out .mw-chat-msg-meta { flex-direction: row-reverse; }

.mw-chat-msg-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--mud-palette-text-primary) 85%, transparent);
}

.mw-chat-msg-time,
.mw-chat-msg-grouptime {
    font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
    font-size: 0.6rem;
    color: var(--mud-palette-text-disabled);
    font-variant-numeric: tabular-nums;
}

.mw-chat-msg-grouptime {
    font-size: 0.55rem;
    margin-top: 3px;
    padding: 0 4px;
}

/* NOTE: The bubble. Edge glow anchored at the LOWER tail corner: a radial gradient whose
   reach is sized so it climbs the tail side and runs along the bottom edge, but is fully
   faded before the top — the top border stays plain hairline. (A diagonal linear gradient
   can't do this on a wide flat bubble: its axis is dominated by the width, so the top edge
   keeps catching color.) Double background: fill on padding-box, gradient + hairline on
   border-box behind the transparent border. */
.mw-chat-msg-bubble {
    position: relative;
    overflow: hidden;
    width: fit-content;
    max-width: 100%;
    border-radius: 14px;
    border-top-left-radius: 4px;
    border: 1.5px solid transparent;
    background:
        linear-gradient(var(--mud-palette-surface), var(--mud-palette-surface)) padding-box,
        radial-gradient(135% 125% at 0% 100%,
            color-mix(in srgb, var(--mw-chat-rail) 80%, transparent) 0%,
            color-mix(in srgb, var(--mw-chat-rail) 45%, transparent) 40%,
            transparent 72%) border-box,
        linear-gradient(var(--mw-chat-hairline), var(--mw-chat-hairline)) border-box;
    box-shadow: -3px 2px 9px -8px color-mix(in srgb, var(--mw-chat-rail) 65%, transparent);
}

/* NOTE: Own messages — tail corner mirrored to the right, quiet primary wash (~7%) over the
   surface fill, edge gradient + bloom always in the primary color (the chip still shows the
   actual surface). Keep the bloom faint. */
.mw-chat-msg--out .mw-chat-msg-bubble {
    border-radius: 14px;
    border-top-right-radius: 4px;
    background:
        linear-gradient(
            color-mix(in srgb, var(--mud-palette-primary) 7%, transparent),
            color-mix(in srgb, var(--mud-palette-primary) 7%, transparent)) padding-box,
        linear-gradient(var(--mud-palette-surface), var(--mud-palette-surface)) padding-box,
        radial-gradient(135% 125% at 100% 100%,
            color-mix(in srgb, var(--mud-palette-primary) 75%, transparent) 0%,
            color-mix(in srgb, var(--mud-palette-primary) 42%, transparent) 40%,
            transparent 72%) border-box,
        linear-gradient(var(--mw-chat-hairline), var(--mw-chat-hairline)) border-box;
    box-shadow: 3px 2px 9px -8px color-mix(in srgb, var(--mud-palette-primary) 65%, transparent);
}

.mw-chat-msg--system .mw-chat-msg-bubble {
    border: 0;
    background: transparent;
    box-shadow: none;
    color: var(--mud-palette-text-secondary);
    font-style: italic;
}

/* NOTE: Content inside the bubble */
.mw-chat-msg-content {
    padding: 9px 13px;
    font-size: 0.875rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.mw-chat-msg-content .mud-typography {
    font-size: inherit;
    line-height: inherit;
}

.mw-chat-msg-content--media { padding: 4px; }

/* NOTE: Sender-surface chip (MwChatSenderChip) — mono micro-pill in the surface color;
   rendered only for messages with a SentFromLabel (purpose-bound rooms). */
.mw-chat-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 2px 7px;
    border-radius: 999px;
    white-space: nowrap;
    color: var(--mw-chat-rail, var(--mud-palette-text-secondary));
    background: color-mix(in srgb, var(--mw-chat-rail, var(--mud-palette-text-secondary)) 13%, transparent);
    border: 1px solid color-mix(in srgb, var(--mw-chat-rail, var(--mud-palette-text-secondary)) 35%, transparent);
}

.mw-chat-chip-dot {
    flex-shrink: 0;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--mw-chat-rail, var(--mud-palette-text-secondary));
}

/* NOTE: Individual bubble wrapper (LEGACY — ChatPage.razor's bespoke AI markup only; MwChatBubble
   renders mw-chat-msg-* above) */
.mw-chat-bubble {
    display: flex;
    flex-direction: column;
    max-width: 72%;
    margin-bottom: 2px;
    animation: mw-chat-bubble-in 0.2s ease-out;
}

@keyframes mw-chat-bubble-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mw-chat-bubble--incoming {
    align-self: flex-start;
}

.mw-chat-bubble--outgoing {
    align-self: flex-end;
}

.mw-chat-bubble--system {
    align-self: center;
    max-width: 85%;
}

/* NOTE: Bubble content area */
.mw-chat-bubble-content {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
    font-size: 0.9rem;
}

.mw-chat-bubble--incoming .mw-chat-bubble-content {
    background: var(--mud-palette-surface);
    border-bottom-left-radius: 4px;
}

.mw-chat-bubble--outgoing .mw-chat-bubble-content {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-bottom-right-radius: 4px;
}

.mw-chat-bubble--system .mw-chat-bubble-content {
    background: transparent;
    color: var(--mud-palette-text-secondary);
    font-style: italic;
    text-align: center;
    padding: 4px 8px;
    font-size: 0.8rem;
}

/* NOTE: Sanitized Markdown rendered inside chat bubbles */
.mw-chat-markdown {
    white-space: normal;
}

.mw-chat-markdown > :first-child {
    margin-top: 0;
}

.mw-chat-markdown > :last-child {
    margin-bottom: 0;
}

.mw-chat-markdown h1,
.mw-chat-markdown h2,
.mw-chat-markdown h3,
.mw-chat-markdown h4,
.mw-chat-markdown h5,
.mw-chat-markdown h6 {
    margin: 0.65rem 0 0.35rem;
    font-size: 0.95rem;
    line-height: 1.3;
    font-weight: 700;
}

.mw-chat-markdown p {
    margin: 0.35rem 0;
}

.mw-chat-markdown ul,
.mw-chat-markdown ol {
    margin: 0.35rem 0;
    padding-left: 1.25rem;
}

.mw-chat-markdown li {
    margin: 0.2rem 0;
}

.mw-chat-markdown a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.mw-chat-markdown code {
    font-size: 0.85em;
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
    background: color-mix(in srgb, currentColor 10%, transparent);
}

.mw-chat-markdown pre {
    overflow-x: auto;
    padding: 0.6rem;
    border-radius: 8px;
    background: color-mix(in srgb, currentColor 8%, transparent);
}

/* NOTE: Wiki RAG source excerpts */
.mw-chat-wiki-sources {
    margin-top: 0.7rem;
}

.mw-chat-wiki-sources .mud-expand-panel {
    background: color-mix(in srgb, currentColor 5%, transparent);
    border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    border-radius: 8px;
    box-shadow: none;
    overflow: hidden;
}

.mw-chat-wiki-sources .mud-expand-panel-header {
    min-height: 36px;
    padding: 0.35rem 0.55rem;
}

.mw-chat-wiki-source-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    font-size: 0.78rem;
    font-weight: 600;
}

.mw-chat-wiki-source-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mw-chat-wiki-source-body {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0 0.65rem 0.65rem;
}

.mw-chat-wiki-source-excerpt {
    max-height: 220px;
    overflow-y: auto;
    padding: 0.65rem;
    border-radius: 6px;
    background: color-mix(in srgb, currentColor 6%, transparent);
    white-space: pre-wrap;
    font-size: 0.78rem;
    line-height: 1.45;
}

.mw-chat-wiki-source-excerpt--rendered {
    max-height: 320px;
    border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    background: transparent;
    white-space: normal;
}

.mw-chat-wiki-source-excerpt--rendered .mw-content {
    font-size: 0.84rem;
    line-height: 1.5;
}

.mw-chat-wiki-source-excerpt--rendered .mw-content > :first-child {
    margin-top: 0;
}

.mw-chat-wiki-source-excerpt--rendered .mw-content > :last-child {
    margin-bottom: 0;
}

.mw-chat-wiki-source-link {
    align-self: flex-start;
    border-radius: 8px;
    text-transform: none;
}

/* NOTE: Timestamp + status line */
.mw-chat-bubble-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px 0;
    opacity: 0.6;
}

.mw-chat-bubble--incoming .mw-chat-bubble-meta {
    justify-content: flex-start;
}

.mw-chat-bubble--outgoing .mw-chat-bubble-meta {
    justify-content: flex-end;
}

/* NOTE: Reasoning/thinking toggle */
.mw-chat-reasoning {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px 2px;
    cursor: pointer;
}

.mw-chat-reasoning:hover {
    opacity: 0.8;
}

.mw-chat-reasoning-content {
    padding: 4px 14px 8px;
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 30%, transparent);
    margin-bottom: 2px;
    max-height: 300px;
    overflow-y: auto;
}

/* NOTE: Live reasoning in the reusable MwChat message bubble */
.mw-chat-msg-reasoning {
    padding: 8px 12px;
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 30%, transparent);
    color: var(--mud-palette-text-secondary);
}

.mw-chat-msg-reasoning-header {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--mud-palette-primary);
    font-size: 0.75rem;
    font-weight: 600;
}

.mw-chat-msg-reasoning-content {
    max-height: 200px;
    margin-top: 6px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 0.78rem;
    line-height: 1.4;
    opacity: 0.7;
}

/* NOTE: Mic recording pulse animation */
.mw-chat-mic-recording {
    animation: mw-chat-mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mw-chat-mic-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* NOTE: Failed/stale message indicator */
.mw-chat-bubble-failed {
    padding: 8px 14px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    background: color-mix(in srgb, var(--mud-palette-error) 10%, var(--mud-palette-surface));
    border: 1px solid color-mix(in srgb, var(--mud-palette-error) 25%, transparent);
    font-size: 0.82rem;
    color: var(--mud-palette-text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* NOTE: Action proposal card */
.mw-chat-action {
    border: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 60%, transparent);
    border-radius: 14px;
    padding: 16px;
    min-width: 280px;
    background: color-mix(in srgb, var(--mud-palette-surface) 80%, transparent);
    backdrop-filter: blur(8px);
}

.mw-chat-action-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.mw-chat-action-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--mud-palette-background) 50%, transparent);
    border-radius: 8px;
}

.mw-chat-action-param {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: baseline;
}

.mw-chat-action-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* NOTE: Text input area (sticky bottom) */
.mw-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 24px 16px;
    border-top: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 40%, transparent);
    flex-shrink: 0;
    background: color-mix(in srgb, var(--mud-palette-surface) 30%, transparent);
    backdrop-filter: blur(12px);
}

.mw-chat-input > *:first-child {
    flex: 1;
}

.mw-chat-input .mud-input-outlined .mud-input-outlined-border {
    border-radius: 14px;
    border-color: color-mix(in srgb, var(--mud-palette-lines-default) 40%, transparent) !important;
}

.mw-chat-input .mud-input-outlined:focus-within .mud-input-outlined-border {
    border-color: var(--mud-palette-primary) !important;
}

/* NOTE: Composer variant of the input row — one shared bar ("+" menu · borderless field ·
   mic · send) fills the row; the generic .mw-chat-input > *:first-child { flex: 1 } rule
   (kept for ChatPage) conveniently stretches it. */

.mw-chat-input--composer .mw-chat-attach {
    margin-top: 0;
    align-self: flex-end;
}

/* NOTE: Pending-attachment strip above the composer (uploaded, not yet sent) */
.mw-chat-pending {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 24px;
    border-top: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 40%, transparent);
    background: color-mix(in srgb, var(--mud-palette-surface) 30%, transparent);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.mw-chat-pending-item {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 10px;
    overflow: hidden;
    background: color-mix(in srgb, var(--mud-palette-surface) 80%, transparent);
    border: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 50%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mw-chat-pending-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mw-chat-pending-remove {
    position: absolute !important;
    top: 0;
    right: 0;
    padding: 2px !important;
    background: color-mix(in srgb, var(--mud-palette-background) 70%, transparent) !important;
    border-radius: 0 0 0 8px !important;
}

/* NOTE: Drag-over highlight while an image drag hovers over the chat (mw-chat-paste module) */
.mw-chat--dragover {
    outline: 2px dashed var(--mud-palette-primary);
    outline-offset: -6px;
    border-radius: 12px;
}

/* NOTE: Media (image) message bubbles */
.mw-chat-bubble-content--media {
    padding: 4px;
    overflow: hidden;
}

.mw-chat-media {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.mw-chat-media--grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
}

.mw-chat-media-img {
    display: block;
    width: 100%;
    max-width: 360px;
    max-height: 320px;
    object-fit: cover;
    border-radius: 12px;
    cursor: zoom-in;
    transition: filter 0.15s ease;
}

.mw-chat-media-img:hover {
    filter: brightness(1.08);
}

.mw-chat-media--grid .mw-chat-media-img {
    aspect-ratio: 1;
    max-height: 180px;
}

/* NOTE: Odd image count — first image spans the full grid width */
.mw-chat-media--grid .mw-chat-media-img:first-child:nth-last-child(odd) {
    grid-column: 1 / -1;
    aspect-ratio: auto;
}

.mw-chat-media-caption {
    padding: 6px 10px 4px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

/* NOTE: Voice message bubbles — play/pause button, seekable progress track, time label.
   The mw-voice JS module drives --mw-voice-progress and the label text during playback. */
.mw-chat-voice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
    padding: 2px 4px;
}

.mw-chat-voice-track {
    position: relative;
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--mud-palette-lines-default) 55%, transparent);
    cursor: pointer;
}

.mw-chat-voice-track-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--mw-voice-progress, 0%);
    border-radius: 3px;
    background: var(--mud-palette-primary);
    transition: width 0.2s linear;
}

.mw-chat-voice-time {
    font-size: 0.78rem;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
    min-width: 34px;
    text-align: right;
}

/* NOTE: Recording strip filling the composer bar while a voice message records
   (discard ghost · pulsing dot · elapsed time · decorative waveform · send). */
.mw-chat-input--composer .mw-chat-voice-recording {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 0 6px;
}

.mw-chat-voice-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--mud-palette-error);
    box-shadow: 0 0 10px color-mix(in srgb, var(--mud-palette-error) 55%, transparent);
    animation: mw-chat-voice-pulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

.mw-chat-voice-recording-time {
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

/* NOTE: Decorative level bars (no real metering) — takes the leftover strip width */
.mw-chat-voice-recording-wave {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2.5px;
    overflow: hidden;
}

.mw-chat-voice-recording-wave i {
    width: 2px;
    border-radius: 1px;
    background: color-mix(in srgb, var(--mud-palette-error) 65%, transparent);
    animation: mw-chat-voice-wave 1s ease-in-out infinite;
    flex-shrink: 0;
}

.mw-chat-voice-recording-wave i:nth-child(1) { height: 6px; animation-delay: 0s; }
.mw-chat-voice-recording-wave i:nth-child(2) { height: 12px; animation-delay: 0.12s; }
.mw-chat-voice-recording-wave i:nth-child(3) { height: 8px; animation-delay: 0.24s; }
.mw-chat-voice-recording-wave i:nth-child(4) { height: 14px; animation-delay: 0.36s; }
.mw-chat-voice-recording-wave i:nth-child(5) { height: 5px; animation-delay: 0.48s; }
.mw-chat-voice-recording-wave i:nth-child(6) { height: 10px; animation-delay: 0.6s; }
.mw-chat-voice-recording-wave i:nth-child(7) { height: 7px; animation-delay: 0.72s; }

@keyframes mw-chat-voice-wave {
    0%, 100% { transform: scaleY(0.55); }
    50% { transform: scaleY(1.25); }
}

@keyframes mw-chat-voice-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* NOTE: Composer rework — "+" menu · text field · send. Tighter than the generic
   .mw-chat-input chrome (which ChatPage still uses), and width-aware via container
   queries so narrow embeds degrade by shrinking padding instead of wrapping. */
.mw-chat {
    container-type: inline-size;
}

.mw-chat-input--composer {
    padding: 8px 14px;
    gap: 6px;
    /* NOTE: Center the "+" and send buttons against the (now compact) field instead of
       bottom-aligning them — the row only grows once the field wraps to multiple lines. */
    align-items: center;
}

/* NOTE: The shared bar — plus, field, mic and send live in ONE bordered container
   (mockup "Composer C2 — Eine Leiste"); the field itself is borderless inside it. */
.mw-chat-composer-bar {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    padding: 5px 6px 5px 5px;
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 55%, transparent);
    background: color-mix(in srgb, var(--mud-palette-surface) 55%, transparent);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* NOTE: Focus = light from below — the bottom edge glows while the hairline stays;
   never a full border swap, and the top edge never catches light. */
.mw-chat-composer-bar:focus-within {
    border-bottom-color: color-mix(in srgb, var(--mud-palette-primary) 45%, var(--mud-palette-lines-default));
    box-shadow:
        0 6px 18px -11px color-mix(in srgb, var(--mud-palette-primary) 85%, transparent),
        0 10px 26px -18px color-mix(in srgb, var(--mud-palette-primary) 70%, transparent);
}

/* NOTE: Bar controls are PLAIN <button>/<textarea> elements — the mockup's mask 1:1,
   with zero MudBlazor input/button chrome to fight. Shared button reset first. */
.mw-chat-composer-ghost,
.mw-chat-composer-send {
    appearance: none;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 11px;
    background: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.mw-chat-composer-ghost .mud-icon-root,
.mw-chat-composer-send .mud-icon-root {
    font-size: 1.25rem;
    width: 20px;
    height: 20px;
}

/* NOTE: Ghost buttons ("+", mic, recording discard) — quiet squircles that only show
   chrome on hover */
.mw-chat-composer-ghost {
    color: var(--mud-palette-text-secondary);
    transition: background-color 0.13s ease, color 0.13s ease;
}

.mw-chat-composer-ghost:hover {
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-action-default-hover);
}

.mw-chat-composer-ghost .mud-icon-root {
    transition: transform 0.18s ease;
}

/* NOTE: The "+" wears the primary tint permanently (the mockup's look); while its menu is
   open (MWMenu stamps mw-menu-open on the activator wrapper) the icon rotates into an × */
.mw-chat-composer-plus,
.mw-chat-composer-plus:hover {
    color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 13%, transparent);
}

.mw-chat-composer-plus:hover {
    background: color-mix(in srgb, var(--mud-palette-primary) 20%, transparent);
}

.mw-menu-open .mw-chat-composer-plus .mud-icon-root {
    transform: rotate(45deg);
}

/* NOTE: Filled send — primary squircle with a soft resting shadow */
.mw-chat-composer-send {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    box-shadow: 0 3px 12px -5px color-mix(in srgb, var(--mud-palette-primary) 45%, transparent);
    transition: box-shadow 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.mw-chat-composer-send:hover:not(:disabled) {
    box-shadow: 0 3px 14px -4px color-mix(in srgb, var(--mud-palette-primary) 85%, transparent);
}

/* NOTE: Disabled stays visibly violet (the mockup's vivid send) — just slightly muted,
   no hover lift, so the bar never shows a washed-out grey block. */
.mw-chat-composer-send:disabled {
    background: color-mix(in srgb, var(--mud-palette-primary) 70%, var(--mud-palette-surface));
    cursor: default;
    box-shadow: none;
}

/* NOTE: Auto-growing borderless field — the grid-replica trick: the wrapper's ::after
   renders the typed text invisibly (same font/padding/wrapping) and sizes the grid cell,
   the rows=1 textarea stretches over it. No sizing JS, no intrinsic-height fights.
   Caps at 140px, then the textarea scrolls instead of shoving the message list away. */
.mw-chat-composer-grow {
    flex: 1;
    min-width: 0;
    display: grid;
    max-height: 140px;
    font-size: 0.92rem;
    line-height: 1.4;
}

.mw-chat-composer-grow::after {
    content: attr(data-value) " ";
    visibility: hidden;
    grid-area: 1 / 1;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    padding: 5px 7px;
    max-height: 140px;
}

.mw-chat-composer-grow textarea {
    grid-area: 1 / 1;
    width: 100%;
    min-width: 0;
    padding: 5px 7px;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    overflow-y: auto;
    color: var(--mud-palette-text-primary);
    font: inherit;
    scrollbar-width: thin;
}

.mw-chat-composer-grow textarea::placeholder {
    color: var(--mud-palette-text-secondary);
    opacity: 0.7;
}

/* NOTE: The upload control is headless — the picker opens from the composer menu, but its
   hidden input stays in the DOM as the paste/drop hand-off target. */
.mw-chat-input--composer .mw-chat-attach {
    display: none;
}

/* NOTE: Composer "+" menu — the SAME edge-glow panel recipe as the entitlements person
   action menu (.mw-et-actionmenu): neutralize the MudPopover paper so the content div IS
   the surface, paint the vpanel there. Tail corner bottom-left (the "+" sits below-left),
   glow anchored at the tail. Primary rail — the composer is the viewer's own surface. */
.mud-popover:has(> .mw-chat-composer-menu) {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
}

.mw-chat-composer-menu {
    --rail: var(--mud-palette-primary);
    min-width: 214px;
    padding: 5px;
    border: 1.5px solid transparent;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    background:
        linear-gradient(var(--mud-palette-surface), var(--mud-palette-surface)) padding-box,
        radial-gradient(135% 125% at 0% 100%,
            color-mix(in srgb, var(--rail) 72%, transparent) 0%,
            color-mix(in srgb, var(--rail) 40%, transparent) 40%,
            transparent 72%) border-box,
        linear-gradient(var(--mud-palette-lines-default), var(--mud-palette-lines-default)) border-box;
    box-shadow:
        0 22px 44px -20px hsla(0 0% 0% / 0.85),
        -3px 3px 12px -9px color-mix(in srgb, var(--rail) 70%, transparent);
}

/* NOTE: Menu rows — the entitlements ".vitem" treatment; icons rest muted, tint primary on hover */
.mw-chat-composer-menu .mw-menu-submenu-activator {
    border-radius: 9px;
    padding: 7px 11px;
    gap: 10px;
    transition: background 0.12s ease, color 0.12s ease;
}

.mw-chat-composer-menu .mw-menu-submenu-activator:hover {
    background: color-mix(in srgb, var(--mud-palette-text-primary) 6%, transparent);
}

.mw-chat-composer-menu .mw-menu-submenu-icon-start {
    margin-inline-end: 0;
    color: var(--mud-palette-text-secondary);
    transition: color 0.12s ease;
}

.mw-chat-composer-menu .mw-menu-submenu-activator:hover .mw-menu-submenu-icon-start {
    color: var(--mud-palette-primary);
}

.mw-chat-composer-menu .mw-menu-submenu-label {
    height: auto;
    margin: 0;
    font-size: 13.5px;
    font-family: inherit;
}

/* NOTE: Narrow embeds (side panels, split views) — shrink chrome before content wraps */
@container (max-width: 360px) {
    .mw-chat-input--composer {
        padding: 8px 8px 10px;
        gap: 4px;
    }

    .mw-chat-composer-bar {
        padding: 3px;
        gap: 2px;
    }

    .mw-chat-pending {
        padding: 6px 10px;
    }
}

/* NOTE: Typing indicator (animated dots) */
.mw-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: var(--mud-palette-surface);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

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

.mw-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.mw-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes mw-chat-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-5px);
        opacity: 0.8;
    }
}

/* NOTE: Empty state — no conversation selected */
.mw-chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0.4;
    user-select: none;
}

.mw-chat-empty-icon {
    font-size: 64px;
    opacity: 0.3;
    animation: mw-chat-empty-float 4s ease-in-out infinite;
}

@keyframes mw-chat-empty-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

/* NOTE: Date separator line */
.mw-chat-date-sep {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 16px 0 8px;
    color: var(--mud-palette-text-secondary);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.mw-chat-date-sep::before,
.mw-chat-date-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: color-mix(in srgb, var(--mud-palette-lines-default) 40%, transparent);
}

/* NOTE: Unread count badge */
.mw-chat-unread-badge {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

/* NOTE: Responsive */
@media (max-width: 768px) {
    .mw-chat-sidebar {
        width: 260px;
    }

    .mw-chat-bubble {
        max-width: 85%;
    }
}

@media (max-width: 600px) {
    .mw-chat-sidebar {
        display: none;
    }
}
