/* qÚčto design system 2026 — chat.css (R3, ADR-0223; direction A
 * „Temný rám, plovoucí list", ADR-0225).
 *
 * „Zprávy“: calm two-pane B2B messenger (conversation list + thread) plus the
 * chat dialogs, the question pages and the few chat classes reused by the
 * system screens. Semantic tokens only (tokens.css) — no colour literals;
 * reduced motion is handled by the motion tokens themselves. Direction A:
 * surfaces carry a soft ink ring (--e0) and a transparent 1px border that
 * forced colours paint, never a hard outline; floating layers use
 * --pop-shadow / --dialog-shadow; the messenger is one white card (radius 16)
 * on the sheet with the thread on the canvas plate.
 *
 * Structure (DOM ids/classes/data-chat-* hooks are load-bearing for
 * chat-composer.js, chat-overlay.js, chat-scroll.js and the web tests):
 *   .qucto-chat#chat-root  ─┬─ aside.qucto-chat-list    (search, sections, items, foot)
 *                           └─ section.qucto-chat-thread (header, scroll, composer)
 *   dialog.qucto-chat-overlay[data-chat-overlay] > .qucto-chat-modal  (#chat-overlay)
 */
@layer features {
    /* ================================================================
       Page frame: the chat fills the sheet (exactly one window of the
       floating sheet, --sheet-h) below the page head and tabs. The
       content column is a flex column, so flash messages above the chat
       push it down instead of the page growing a second scrollbar.
       ================================================================ */
    .qucto-content:has(#chat-root) {
        height: calc(100vh - 2 * var(--sheet-inset));
        height: var(--sheet-h);
        min-height: 0;
    }

    /* Phone: the sheet only has the top inset (layout.css). */
    @media (max-width: 767.98px) {
        .qucto-content:has(#chat-root) {
            height: calc(100dvh - var(--sheet-inset));
        }
    }

    .qucto-content:has(#chat-root) > :not(.qucto-main) {
        flex-shrink: 0;
    }

    .qucto-main:has(> #chat-root) {
        flex: 1 1 auto;
        min-height: 0;
        padding-block-end: var(--page-py);
    }

    /* The dialog host after the chat has no box of its own, so the column
       gap of .qucto-main never shortens the messenger. */
    .qucto-main > #chat-overlay {
        display: contents;
    }

    .qucto-chat {
        --chat-list-w: clamp(264px, 30%, 344px);
        --chat-avatar: 36px;
        --chat-avatar-sm: 28px;
        --chat-bubble-max: min(64ch, 76%);
        --chat-pad-x: var(--sp-5);

        display: grid;
        grid-template-columns: var(--chat-list-w) minmax(0, 1fr);
        flex: 1 1 auto;
        min-height: 440px;
        background: var(--surface);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-card);
        box-shadow: var(--surface-ring);
        overflow: clip;
    }

    /* Icons in the chat carry no intrinsic size (shared _icon partial). */
    .qucto-chat-list-head::before,
    .qucto-chat-item-muted svg,
    .qucto-chat-mutemark svg,
    .qucto-chat-archlink svg,
    .qucto-chat-menu-pop svg,
    .qucto-chat-refchip svg,
    .qucto-chat-attachment svg,
    .qucto-chat-receipt svg,
    .qucto-chat-jump svg,
    .qucto-chat-traychip > svg,
    .qucto-chat-sendbtn svg {
        inline-size: var(--icon-sm);
        block-size: var(--icon-sm);
        flex: none;
    }

    /* ================================================================
       Avatars
       ================================================================ */
    .qucto-chat-avatar {
        display: inline-grid;
        place-items: center;
        inline-size: var(--chat-avatar);
        block-size: var(--chat-avatar);
        flex: none;
        border: 1px solid transparent; /* forced-colors outline */
        border-radius: var(--r-pill);
        background: var(--surface-2);
        color: var(--text-secondary);
        font-size: var(--fs-sm);
        font-weight: var(--fw-semibold);
        line-height: 1;
        user-select: none;
    }

    .qucto-chat-avatar svg {
        inline-size: var(--icon-sm);
        block-size: var(--icon-sm);
    }

    .qucto-chat-avatar-sm {
        inline-size: var(--chat-avatar-sm);
        block-size: var(--chat-avatar-sm);
        font-size: var(--fs-xs);
    }

    /* Mojiva (the accounting firm) — the one amber avatar in the room. */
    .qucto-chat-avatar-mojiva {
        background: var(--accent);
        color: var(--accent-ink);
    }

    .qucto-chat-avatar-channel {
        border-radius: var(--r-sm);
        background: var(--surface-2);
        color: var(--text-secondary);
        font-size: var(--fs-md);
    }

    .qucto-chat-avatar-external {
        background: var(--info-wash);
        color: var(--info-ink);
        border-color: var(--info-border);
    }

    .qucto-chat-avatar-wa {
        background: var(--success-wash);
        color: var(--success-ink);
        border-color: var(--success-border);
    }

    /* ================================================================
       Left pane — search, sections, conversation items
       ================================================================ */
    .qucto-chat-list {
        display: flex;
        flex-direction: column;
        min-width: 0;
        min-height: 0;
        border-inline-end: 1px solid var(--border-subtle);
        background: var(--surface);
    }

    .qucto-chat-list-head {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--sp-2);
        padding: var(--sp-3);
        border-block-end: 1px solid var(--border-subtle);
    }

    /* Search glyph drawn as a mask so it follows the text token. */
    .qucto-chat-list-head::before {
        content: '';
        position: absolute;
        inset-inline-start: calc(var(--sp-3) + 10px);
        inset-block-start: 50%;
        translate: 0 -50%;
        background: var(--text-muted);
        mask: var(--i-search) center / contain no-repeat;
        pointer-events: none;
        z-index: 1;
    }

    .qucto-chat-search {
        flex: 1 1 auto;
        min-width: 0;
        min-block-size: var(--control-h);
        padding-inline-start: calc(10px + var(--icon-sm) + var(--sp-2));
    }

    .qucto-chat-list-head > .qucto-button {
        flex: none;
        min-block-size: var(--control-h);
    }

    .qucto-chat-list-head > .qucto-icon-btn {
        flex: none;
        inline-size: var(--control-h);
        block-size: var(--control-h);
    }

    .qucto-chat-search::-webkit-search-cancel-button {
        cursor: pointer;
    }

    .qucto-chat-list-items {
        flex: 1 1 auto;
        min-height: 0;
        margin: 0;
        padding: var(--sp-2);
        list-style: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    .qucto-chat-section {
        padding: var(--sp-4) var(--sp-2-5) var(--sp-1);
        color: var(--text-muted);
        font-size: var(--fs-2xs);
        line-height: var(--lh-2xs);
        font-weight: var(--fw-medium);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-section:first-child {
        padding-block-start: var(--sp-1);
    }

    .qucto-chat-item + .qucto-chat-item {
        margin-block-start: var(--sp-0-5);
    }

    .qucto-chat-item a {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        min-block-size: 60px;
        padding: var(--sp-2) var(--sp-2-5);
        border: 1px solid transparent;
        border-radius: var(--r-card-nested);
        color: var(--text);
        text-decoration: none;
        transition: background-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
    }

    .qucto-chat-item a:hover {
        background: var(--row-hover);
    }

    .qucto-chat-item a:focus-visible {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    /* The open conversation: the canvas plate with an ink ring, like the
       active sidebar item (never colour alone: plate + ring + aria-current). */
    .qucto-chat-item a[aria-current] {
        background: var(--surface-inset);
        box-shadow: inset 0 0 0 1px var(--ring-color-hover);
    }

    .qucto-chat-item a[aria-current]:hover {
        background: var(--surface-inset);
    }

    .qucto-chat-item-main {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        gap: var(--sp-0-5);
        min-width: 0;
    }

    .qucto-chat-item-top,
    .qucto-chat-item-bottom {
        display: flex;
        align-items: center;
        gap: var(--sp-2);
        min-width: 0;
    }

    .qucto-chat-item-top {
        align-items: baseline;
    }

    .qucto-chat-item-title {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        font-weight: var(--fw-medium);
    }

    .qucto-chat-item-time {
        flex: none;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        font-variant-numeric: tabular-nums;
        letter-spacing: var(--tracking-xs);
        white-space: nowrap;
    }

    .qucto-chat-item-preview {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
    }

    /* Unread: weight + ink + count pill (never colour alone). */
    .qucto-chat-item-unread .qucto-chat-item-title {
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-item-unread .qucto-chat-item-time {
        color: var(--text);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-item-unread .qucto-chat-item-preview {
        color: var(--text-secondary);
    }

    .qucto-chat-item-muted {
        display: inline-flex;
        flex: none;
        color: var(--text-muted);
    }

    .qucto-chat-pill {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: none;
        min-inline-size: 20px;
        block-size: 18px;
        padding: 0 var(--sp-1-5);
        border: 1px solid transparent;
        border-radius: var(--r-pill);
        background: var(--accent);
        color: var(--accent-ink);
        font-size: var(--fs-2xs);
        line-height: 1;
        font-weight: var(--fw-semibold);
        font-variant-numeric: tabular-nums;
    }

    /* A muted conversation still counts, but quietly. */
    .qucto-chat-item:has(.qucto-chat-item-muted) .qucto-chat-pill {
        background: var(--neutral-pill);
        color: var(--neutral-ink);
    }

    .qucto-chat-list-empty {
        display: grid;
        gap: var(--sp-1);
        padding: var(--sp-10) var(--sp-4);
        color: var(--text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        text-align: center;
        text-wrap: pretty;
    }

    .qucto-chat-list-empty p {
        margin: 0;
    }

    .qucto-chat-list-empty-title {
        color: var(--text);
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-list-foot {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--sp-1) var(--sp-3);
        padding: var(--sp-2) var(--sp-2-5);
        border-block-start: 1px solid var(--border-subtle);
    }

    .qucto-chat-archlink {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-1-5);
        min-block-size: var(--control-h-sm);
        padding: 0 var(--sp-2);
        border-radius: var(--r-nav);
        color: var(--text-secondary);
        font-size: var(--fs-nav);
        font-weight: var(--fw-medium);
        text-decoration: none;
        transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-archlink:hover {
        background: var(--hover);
        color: var(--text);
    }

    .qucto-chat-archlink svg {
        color: var(--text-muted);
    }

    .qucto-chat-archmark {
        color: var(--text-muted);
        font-size: var(--fs-xs);
        font-weight: var(--fw-regular);
    }

    /* ================================================================
       Thread pane — header
       ================================================================ */
    .qucto-chat-thread {
        position: relative;
        display: flex;
        flex-direction: column;
        min-width: 0;
        min-height: 0;
        background: var(--surface);
    }

    .qucto-chat-empty {
        display: grid;
        flex: 1 1 auto;
        place-items: center;
        padding: var(--sp-8) var(--sp-6);
        background: var(--surface-inset);
    }

    .qucto-chat-empty .qucto-emptystate-title {
        margin: 0;
    }

    .qucto-chat-empty .qucto-emptystate-text {
        margin: 0;
    }

    .qucto-chat-thread-head {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        min-block-size: 64px;
        padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-5);
        border-block-end: 1px solid var(--border-subtle);
        background: var(--surface);
    }

    .qucto-chat-thread-titles {
        display: grid;
        flex: 1 1 0;
        gap: var(--sp-0-5);
        min-width: 0;
    }

    .qucto-chat-thread-title {
        display: flex;
        align-items: center;
        gap: var(--sp-1-5);
        min-width: 0;
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: var(--fs-title-sm);
        line-height: var(--lh-title-sm);
        font-weight: var(--fw-semibold);
        letter-spacing: var(--tracking-title);
    }

    .qucto-chat-mutemark {
        display: inline-flex;
        color: var(--text-muted);
    }

    .qucto-chat-participants {
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
        font-size: var(--fs-label);
        line-height: var(--lh-label);
    }

    .qucto-chat-back {
        display: none;
    }

    .qucto-chat-thread-actions {
        display: flex;
        flex: none;
        align-items: center;
        gap: var(--sp-1);
    }

    /* Header menu (details/summary) — a small floating list. */
    .qucto-chat-menu {
        position: relative;
    }

    .qucto-chat-menu > summary {
        list-style: none;
        cursor: pointer;
    }

    .qucto-chat-menu > summary::-webkit-details-marker {
        display: none;
    }

    .qucto-chat-menu[open] > summary {
        background: var(--pressed);
        color: var(--text);
    }

    .qucto-chat-menu-pop {
        position: absolute;
        inset-block-start: calc(100% + var(--sp-1));
        inset-inline-end: 0;
        z-index: var(--z-popover);
        display: grid;
        gap: var(--sp-0-5);
        min-inline-size: 232px;
        margin: 0;
        padding: var(--sp-1);
        list-style: none;
        background: var(--surface);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pop);
        box-shadow: var(--pop-shadow);
        transform-origin: top right;
        transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
    }

    @starting-style {
        .qucto-chat-menu[open] .qucto-chat-menu-pop {
            opacity: 0;
            transform: translateY(calc(-1 * var(--motion-shift)));
        }
    }

    .qucto-chat-menu-pop li form {
        margin: 0;
    }

    .qucto-chat-menu-pop button {
        display: flex;
        align-items: center;
        gap: var(--sp-2-5);
        inline-size: 100%;
        min-block-size: var(--control-h);
        padding: 0 var(--sp-2-5);
        border: 0;
        border-radius: var(--r-sm);
        background: none;
        color: var(--text);
        font: inherit;
        font-size: var(--fs-nav);
        text-align: start;
        cursor: pointer;
    }

    .qucto-chat-menu-pop button:hover {
        background: var(--hover);
    }

    .qucto-chat-menu-pop button:focus-visible {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-menu-pop svg {
        color: var(--text-muted);
    }

    /* ================================================================
       Messages
       ================================================================ */
    .qucto-chat-scroll {
        position: relative;
        flex: 1 1 auto;
        min-height: 0;
        padding: var(--sp-4) var(--chat-pad-x) var(--sp-3);
        overflow-y: auto;
        overflow-anchor: none;
        overscroll-behavior: contain;
        background: var(--surface-inset);
        scrollbar-gutter: stable;
    }

    .qucto-chat-scroll:focus-visible {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-messages {
        display: flex;
        flex-direction: column;
        gap: var(--sp-3);
    }

    .qucto-chat-day {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        margin-block: var(--sp-3) var(--sp-1);
        color: var(--text-muted);
        font-size: var(--fs-label);
        line-height: var(--lh-label);
        font-weight: var(--fw-medium);
        font-variant-numeric: tabular-nums;
    }

    .qucto-chat-day::before,
    .qucto-chat-day::after {
        content: '';
        flex: 1 1 0;
        block-size: 1px;
        background: var(--border);
    }

    .qucto-chat-newdivider {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        margin-block: var(--sp-1);
        color: var(--text);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-newdivider::before,
    .qucto-chat-newdivider::after {
        content: '';
        flex: 1 1 0;
        block-size: 1px;
        background: var(--accent);
    }

    .qucto-chat-newdivider span {
        padding: var(--sp-0-5) var(--sp-2);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pill);
        background: var(--warning-pill);
        color: var(--warning-ink);
    }

    .qucto-chat-begin,
    .qucto-chat-sentinel {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--sp-2);
        padding: var(--sp-3) var(--sp-3) var(--sp-4);
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
        text-align: center;
    }

    /* Loading older history: a calm breathing dot, static under reduced motion. */
    .qucto-chat-sentinel-dot {
        inline-size: 6px;
        block-size: 6px;
        flex: none;
        border-radius: var(--r-pill);
        background: var(--accent-700);
        animation: qucto-chat-breathe 1s var(--ease-inout) infinite alternate;
    }

    @keyframes qucto-chat-breathe {
        from { opacity: 0.35; }
        to { opacity: 1; }
    }

    /* One message row: avatar + bubble. Own messages mirror to the right. */
    .qucto-chat-msg {
        display: flex;
        align-items: flex-start;
        gap: var(--sp-2);
        min-width: 0;
        transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out);
    }

    /* Freshly swapped-in (poll/send/edit) messages settle in, no stagger. */
    .qucto-chat-msg.htmx-added {
        opacity: 0;
        transform: translateY(var(--motion-shift));
    }

    .qucto-chat-msg-own {
        flex-direction: row-reverse;
    }

    .qucto-chat-msg .qucto-chat-avatar {
        margin-block-start: var(--sp-0-5);
    }

    /* Grouping: consecutive messages of one author sit 2px apart. */
    .qucto-chat-msg-followup {
        margin-block-start: calc(var(--sp-0-5) - var(--sp-3));
    }

    .qucto-chat-msg-followup .qucto-chat-avatar {
        visibility: hidden;
        block-size: 0;
    }

    .qucto-chat-msg-bubble {
        position: relative;
        min-width: 0;
        max-inline-size: var(--chat-bubble-max);
        padding: var(--sp-2) var(--sp-3) var(--sp-1-5);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-task);
        background: var(--surface);
        box-shadow: var(--surface-ring);
        color: var(--text);
        font-size: var(--fs-md);
        line-height: var(--lh-md);
    }

    .qucto-chat-msg-bubble:focus {
        outline: none;
    }

    .qucto-chat-msg-bubble:focus-visible {
        outline: var(--focus-ring);
        outline-offset: var(--focus-offset);
    }

    /* Tail corners: flatten the author side so a group reads as one block. */
    .qucto-chat-msg:not(.qucto-chat-msg-own) .qucto-chat-msg-bubble {
        border-start-start-radius: var(--r-xs);
    }

    .qucto-chat-msg-own .qucto-chat-msg-bubble {
        border-start-end-radius: var(--r-xs);
        background: var(--accent-soft);
        box-shadow: 0 0 0 1px color-mix(in oklch, var(--accent-line) 55%, transparent), var(--e1);
    }

    .qucto-chat-msg-author {
        margin: 0 0 var(--sp-0-5);
        color: var(--text-secondary);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-weight: var(--fw-semibold);
    }

    /* chat_body already turns newlines into <br> — no pre-wrap (it doubled them). */
    .qucto-chat-msg-body {
        margin: 0;
        overflow-wrap: anywhere;
        text-wrap: pretty;
    }

    .qucto-chat-msg-body a {
        color: var(--info-ink);
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-underline-offset: 2px;
    }

    .qucto-chat-msg-body a:hover {
        text-decoration-thickness: 2px;
    }

    .qucto-chat-msg-meta {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        gap: 0 var(--sp-1-5);
        margin: var(--sp-0-5) 0 0;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
        font-variant-numeric: tabular-nums;
    }

    .qucto-chat-edited {
        font-style: italic;
    }

    /* Deleted message: an outlined ghost, not a bubble. */
    .qucto-chat-msg-deleted .qucto-chat-msg-bubble,
    .qucto-chat-msg-own.qucto-chat-msg-deleted .qucto-chat-msg-bubble {
        border: 1px dashed var(--border-strong);
        background: transparent;
        box-shadow: none;
    }

    .qucto-chat-msg-tombstone {
        margin: 0;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-style: italic;
    }

    /* Reply quote inside a bubble. */
    .qucto-chat-quote {
        display: grid;
        gap: var(--sp-0-5);
        margin: var(--sp-0-5) 0 var(--sp-2);
        padding: var(--sp-1-5) var(--sp-2-5);
        border-inline-start: 3px solid var(--border-strong);
        border-radius: var(--r-xs) var(--r-sm) var(--r-sm) var(--r-xs);
        background: var(--surface-inset);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
    }

    .qucto-chat-msg-own .qucto-chat-quote {
        border-inline-start-color: var(--accent-700);
        background: color-mix(in oklch, var(--surface) 62%, transparent);
    }

    .qucto-chat-quote-author {
        color: var(--text-secondary);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-quote-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
    }

    /* Entity references (invoice/document/transaction) and files. */
    .qucto-chat-refs,
    .qucto-chat-files {
        display: flex;
        flex-wrap: wrap;
        gap: var(--sp-1-5);
        margin-block-start: var(--sp-2);
    }

    .qucto-chat-refchip {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-1-5);
        max-inline-size: 100%;
        min-block-size: 28px;
        padding: 0 var(--sp-2-5) 0 var(--sp-2);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pill);
        background: var(--surface);
        box-shadow: var(--btn-secondary-shadow);
        color: var(--text);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-weight: var(--fw-medium);
        text-decoration: none;
        font-variant-numeric: tabular-nums;
        transition: box-shadow var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-refchip span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .qucto-chat-refchip svg {
        color: var(--text-muted);
    }

    a.qucto-chat-refchip:hover {
        box-shadow: var(--btn-secondary-shadow-hover);
        background: var(--row-hover);
    }

    a.qucto-chat-refchip:hover svg {
        color: var(--text);
    }

    .qucto-chat-attachment {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-2);
        max-inline-size: 100%;
        min-block-size: 40px;
        padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-1);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-card-nested);
        background: var(--surface);
        box-shadow: var(--btn-secondary-shadow);
        color: var(--text);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        text-decoration: none;
        transition: box-shadow var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-attachment svg {
        box-sizing: content-box;
        padding: var(--sp-2);
        border-radius: var(--r-sm);
        background: var(--surface-inset);
        color: var(--text-secondary);
    }

    .qucto-chat-attachment:hover {
        box-shadow: var(--btn-secondary-shadow-hover);
        background: var(--row-hover);
    }

    .qucto-chat-attachment-name {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-weight: var(--fw-medium);
    }

    .qucto-chat-attachment-size {
        flex: none;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    .qucto-chat-thumb-link {
        display: inline-block;
        max-inline-size: 100%;
        border-radius: var(--r-card-nested);
        line-height: 0;
        cursor: zoom-in;
    }

    .qucto-chat-thumb {
        display: block;
        max-inline-size: min(280px, 100%);
        max-block-size: 200px;
        block-size: auto;
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-card-nested);
        background: var(--surface-2);
        box-shadow: var(--surface-ring);
        object-fit: cover;
        transition: box-shadow var(--dur-1) var(--ease-out);
    }

    .qucto-chat-thumb-link:hover .qucto-chat-thumb {
        box-shadow: var(--surface-ring-hover);
    }

    .qucto-chat-refchip:focus-visible,
    .qucto-chat-attachment:focus-visible,
    .qucto-chat-thumb-link:focus-visible {
        outline: var(--focus-ring);
        outline-offset: var(--focus-offset);
    }

    /* Hover/focus toolbar (reply · edit · delete). It sits beside the bubble
       on the free side of the row, so it never covers text; the whole row is
       the hover target, so the pointer can travel to it. Touch: tapping the
       bubble focuses it (tabindex=-1), which reveals the same toolbar. */
    .qucto-chat-msg-actions {
        position: absolute;
        inset-block-start: 0;
        z-index: 2;
        display: inline-flex;
        gap: var(--sp-0-5);
        padding: var(--sp-0-5);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-md);
        background: var(--surface);
        box-shadow: var(--pop-shadow);
        opacity: 0;
        transform: translateY(var(--motion-shift));
        pointer-events: none;
        transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
    }

    .qucto-chat-msg:not(.qucto-chat-msg-own) .qucto-chat-msg-actions {
        inset-inline: calc(100% + var(--sp-2)) auto;
    }

    .qucto-chat-msg-own .qucto-chat-msg-actions {
        inset-inline: auto calc(100% + var(--sp-2));
    }

    .qucto-chat-msg:focus-within .qucto-chat-msg-actions {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }

    @media (hover: hover) {
        .qucto-chat-msg:hover .qucto-chat-msg-actions {
            opacity: 1;
            transform: none;
            pointer-events: auto;
        }
    }

    .qucto-chat-msg-actions form {
        display: inline-flex;
        margin: 0;
    }

    .qucto-chat-msg-actions .qucto-icon-btn {
        inline-size: 28px;
        block-size: 28px;
        min-block-size: 28px;
        border-radius: var(--r-sm);
    }

    .qucto-chat-msg-actions .qucto-icon-btn svg {
        inline-size: var(--icon-sm);
        block-size: var(--icon-sm);
    }

    @media (pointer: coarse) {
        .qucto-chat-msg-actions .qucto-icon-btn {
            inline-size: 40px;
            block-size: 40px;
            min-block-size: 40px;
        }
    }

    /* Inline edit */
    .qucto-chat-msg-editing {
        inline-size: min(560px, 100%);
        max-inline-size: 100%;
        padding: var(--sp-2);
    }

    .qucto-chat-msg-editing form {
        margin: 0;
    }

    .qucto-chat-msg-editing .qucto-chat-input {
        display: block;
        inline-size: 100%;
        min-block-size: 72px;
        font-size: var(--fs-md);
        line-height: var(--lh-md);
        resize: vertical;
    }

    .qucto-chat-edit-actions {
        display: flex;
        justify-content: flex-end;
        gap: var(--sp-2);
        margin-block-start: var(--sp-2);
    }

    /* ================================================================
       Receipt, typing, delivery, jump pill
       ================================================================ */
    .qucto-chat-receipt {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: var(--sp-1);
        min-block-size: var(--lh-xs);
        margin-block-start: var(--sp-1);
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-receipt svg {
        color: var(--success-ink);
    }

    .qucto-chat-typing {
        display: flex;
        align-items: center;
        gap: var(--sp-1-5);
        min-block-size: var(--lh-xs);
        margin-block-start: var(--sp-1);
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-typing-dots {
        display: inline-flex;
        align-items: center;
        gap: 3px;
        padding: var(--sp-1) var(--sp-1-5);
        border-radius: var(--r-pill);
        background: var(--surface);
        border: 1px solid transparent;
        box-shadow: var(--surface-ring);
    }

    .qucto-chat-typing-dots i {
        inline-size: 5px;
        block-size: 5px;
        border-radius: var(--r-pill);
        background: var(--text-muted);
        animation: qucto-chat-typing 1.2s var(--ease-inout) infinite both;
    }

    .qucto-chat-typing-dots i:nth-child(2) {
        animation-delay: 0.16s;
    }

    .qucto-chat-typing-dots i:nth-child(3) {
        animation-delay: 0.32s;
    }

    @keyframes qucto-chat-typing {
        0%, 70%, 100% { opacity: 0.3; }
        35% { opacity: 1; }
    }

    /* Delivery state of messages sent to e-mail/WhatsApp: glyph + word. */
    .qucto-chat-delivery {
        display: inline-flex;
        align-items: center;
        gap: 3px;
        color: var(--text-muted);
    }

    .qucto-chat-delivery::before {
        content: '';
        inline-size: 14px;
        block-size: 14px;
        flex: none;
        background: currentColor;
        mask: var(--chat-delivery-glyph) center / contain no-repeat;
    }

    .qucto-chat-delivery,
    .qucto-chat-delivery-sent {
        --chat-delivery-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    }

    .qucto-chat-delivery-delivered,
    .qucto-chat-delivery-read {
        --chat-delivery-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 7 17l-5-5'/%3E%3Cpath d='m22 10-7.5 7.5L13 16'/%3E%3C/svg%3E");
    }

    .qucto-chat-delivery-read {
        color: var(--success-ink);
        font-weight: var(--fw-medium);
    }

    .qucto-chat-delivery-failed {
        --chat-delivery-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cline x1='12' y1='7.5' x2='12' y2='12.5'/%3E%3Cline x1='12' y1='16.5' x2='12.01' y2='16.5'/%3E%3C/svg%3E");
        color: var(--danger-ink);
        font-weight: var(--fw-semibold);
    }

    /* „Nové zprávy ↓“ floats just above the composer without taking space:
       it sits in the flow between the scroller and the composer, and its
       negative top margin lifts it over the scroller's bottom edge. */
    .qucto-chat-jump {
        --chat-jump-h: 32px;

        position: relative;
        z-index: 3;
        display: inline-flex;
        align-self: center;
        align-items: center;
        gap: var(--sp-1-5);
        block-size: var(--chat-jump-h);
        margin-block: calc(-1 * (var(--chat-jump-h) + var(--sp-3))) var(--sp-3);
        padding: 0 var(--sp-3) 0 var(--sp-4);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pill);
        background: var(--surface);
        color: var(--text);
        font: inherit;
        font-size: var(--fs-sm);
        font-weight: var(--fw-semibold);
        box-shadow: var(--pop-shadow);
        cursor: pointer;
        transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out), background-color var(--dur-1) var(--ease-out);
    }

    @starting-style {
        .qucto-chat-jump {
            opacity: 0;
            transform: translateY(var(--motion-shift));
        }
    }

    .qucto-chat-jump:hover {
        background: var(--hover);
    }

    .qucto-chat-jump:active {
        transform: scale(var(--press-scale));
    }

    .qucto-chat-jump svg {
        color: var(--accent-700);
    }

    /* ================================================================
       Composer
       ================================================================ */
    .qucto-chat-composer {
        position: relative;
        flex: none;
        margin: 0;
        padding: var(--sp-3) var(--chat-pad-x) var(--sp-3);
        border-block-start: 1px solid var(--border-subtle);
        background: var(--surface);
    }

    .qucto-chat-readonly {
        flex: none;
        padding: var(--sp-4) var(--chat-pad-x);
        border-block-start: 1px solid var(--border-subtle);
        background: var(--surface-inset);
        color: var(--text-secondary);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        text-align: center;
    }

    .qucto-chat-extnote {
        flex: none;
        margin: 0;
        padding: var(--sp-2) var(--chat-pad-x);
        border-block-start: 1px solid var(--info-border);
        background: var(--info-wash);
        color: var(--info-ink);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-extnote strong {
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-extnote + .qucto-chat-composer {
        border-block-start: 0;
    }

    /* Tray: reply quote, tagged entities and picked files above the field. */
    .qucto-chat-tray {
        display: flex;
        flex-wrap: wrap;
        gap: var(--sp-1-5);
        margin-block-end: var(--sp-2);
    }

    .qucto-chat-traychip {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-1-5);
        max-inline-size: 100%;
        min-block-size: 30px;
        margin: 0;
        padding: 0 var(--sp-0-5) 0 var(--sp-2-5);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pill);
        background: var(--surface-inset);
        box-shadow: inset 0 0 0 1px var(--ring-color);
        color: var(--text);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-weight: var(--fw-medium);
    }

    .qucto-chat-traychip > span:not(.qucto-chat-traychip-text) {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .qucto-chat-traychip > svg {
        color: var(--text-muted);
    }

    .qucto-chat-traychip-quote {
        background: var(--accent-wash);
        box-shadow: inset 0 0 0 1px var(--accent-line);
    }

    .qucto-chat-traychip-quote > svg {
        color: var(--accent-700);
    }

    .qucto-chat-traychip-text {
        min-width: 0;
        max-inline-size: 280px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
        font-weight: var(--fw-regular);
    }

    .qucto-chat-traychip-x {
        display: inline-grid;
        place-items: center;
        inline-size: 24px;
        block-size: 24px;
        flex: none;
        padding: 0;
        border: 0;
        border-radius: var(--r-pill);
        background: none;
        color: var(--text-muted);
        cursor: pointer;
        transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-traychip-x:hover {
        background: var(--pressed);
        color: var(--text);
    }

    .qucto-chat-traychip-x:focus-visible {
        outline: var(--focus-ring);
        outline-offset: 0;
    }

    .qucto-chat-traychip-x svg {
        inline-size: 14px;
        block-size: 14px;
    }

    /* Reference picker („#“ or the tag button) — popover above the field. */
    .qucto-chat-refpicker {
        position: absolute;
        inset-inline: var(--chat-pad-x);
        max-inline-size: 560px;
        inset-block-end: calc(100% - var(--sp-1));
        z-index: var(--z-popover);
        display: grid;
        gap: var(--sp-2);
        padding: var(--sp-2);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pop);
        background: var(--surface);
        box-shadow: var(--pop-shadow);
    }

    .qucto-chat-refsearch {
        inline-size: 100%;
    }

    .qucto-chat-refresults {
        max-block-size: min(280px, 40dvh);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .qucto-chat-refresults:empty {
        display: none;
    }

    .qucto-chat-refresults-empty {
        margin: 0;
        padding: var(--sp-4) var(--sp-3);
        color: var(--text-muted);
        font-size: var(--fs-sm);
        text-align: center;
    }

    .qucto-chat-refgroup {
        margin: var(--sp-3) 0 var(--sp-1);
        padding: 0 var(--sp-2);
        color: var(--text-muted);
        font-size: var(--fs-2xs);
        line-height: var(--lh-2xs);
        font-weight: var(--fw-medium);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-refresults > .qucto-chat-refgroup:first-child {
        margin-block-start: var(--sp-1);
    }

    .qucto-chat-refresult {
        display: flex;
        align-items: baseline;
        gap: var(--sp-3);
        inline-size: 100%;
        min-block-size: var(--control-h);
        padding: var(--sp-2);
        border: 0;
        border-radius: var(--r-sm);
        background: none;
        color: var(--text);
        font: inherit;
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        text-align: start;
        cursor: pointer;
    }

    .qucto-chat-refresult:hover {
        background: var(--row-hover);
    }

    .qucto-chat-refresult:focus-visible {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-refresult-label {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .qucto-chat-refresult-detail {
        flex: none;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    /* The field: one rounded box holding attach · tag · text · send. */
    .qucto-chat-inputrow {
        display: flex;
        align-items: flex-end;
        gap: var(--sp-1);
        padding: var(--sp-1);
        border: 1px solid var(--border-control);
        border-radius: var(--r-task);
        background: var(--surface);
        box-shadow: var(--e1);
        transition: border-color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-inputrow:hover {
        border-color: var(--border-control-hover);
    }

    .qucto-chat-inputrow:has(.qucto-chat-input:focus-visible) {
        border-color: var(--focus);
        outline: var(--focus-ring);
        outline-offset: var(--focus-offset-input);
    }

    .qucto-chat-toolbtn {
        flex: none;
        color: var(--text-secondary);
    }

    /* The attach control is a <label> for the hidden file input: give it the
       keyboard focus ring of that input. */
    .qucto-chat-inputrow:has(#chat-files:focus-visible) label.qucto-chat-toolbtn {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-inputrow .qucto-chat-input {
        flex: 1 1 auto;
        min-width: 0;
        min-block-size: var(--control-h);
        max-block-size: 160px;
        margin: 0;
        padding: calc((var(--control-h) - var(--lh-md)) / 2) var(--sp-1);
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        color: var(--text);
        font: inherit;
        font-size: var(--fs-md);
        line-height: var(--lh-md);
        resize: none;
        field-sizing: content;
    }

    /* Focus is drawn on the whole field box above (never removed without a
       replacement). */
    .qucto-chat-inputrow .qucto-chat-input:focus,
    .qucto-chat-inputrow .qucto-chat-input:focus-visible {
        outline: none;
    }

    .qucto-chat-input::placeholder {
        color: var(--text-muted);
        opacity: 1;
    }

    .qucto-chat-sendbtn {
        display: inline-grid;
        place-items: center;
        inline-size: var(--control-h);
        block-size: var(--control-h);
        flex: none;
        padding: 0;
        border: 0;
        border-radius: var(--r-control);
        background: var(--btn-primary-bg);
        box-shadow: var(--btn-primary-shadow);
        color: var(--accent-ink);
        cursor: pointer;
        transition: color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
    }

    .qucto-chat-sendbtn:hover {
        background: var(--btn-primary-bg-hover);
    }

    .qucto-chat-sendbtn:active {
        box-shadow: var(--btn-primary-shadow-pressed);
        transform: scale(var(--press-scale));
    }

    .qucto-chat-sendbtn:focus-visible {
        outline: var(--focus-ring);
        outline-offset: var(--focus-offset);
    }

    /* Nothing to send yet: the button rests neutral (still operable — the
       server answers an empty send with a clear message). */
    .qucto-chat-composer:has(.qucto-chat-input:placeholder-shown):has(.qucto-chat-tray[hidden]) .qucto-chat-sendbtn:not(:hover) {
        background: var(--surface-2);
        box-shadow: none;
        color: var(--text-muted);
    }

    .qucto-chat-sendbtn:disabled,
    .qucto-chat-sendbtn[aria-disabled='true'] {
        background: var(--surface-2);
        box-shadow: none;
        color: var(--text-disabled);
        cursor: progress;
        transform: none;
    }

    .qucto-chat-hint {
        display: flex;
        flex-wrap: wrap;
        gap: 0 var(--sp-1);
        margin: var(--sp-1-5) 0 0;
        padding-inline: var(--sp-1);
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        letter-spacing: var(--tracking-xs);
    }

    .qucto-chat-hint kbd {
        display: inline-block;
        min-inline-size: 18px;
        padding: 0 var(--sp-1);
        border: 1px solid transparent;
        border-radius: var(--r-xs);
        background: var(--surface-2);
        color: var(--text-secondary);
        font-family: inherit;
        font-size: var(--fs-xs);
        line-height: 14px;
        font-weight: var(--fw-medium);
        text-align: center;
    }

    /* Enter sends only with a fine pointer (chat-composer.js) — on touch the
       keyboard half of the hint would be wrong. */
    @media (pointer: coarse) {
        .qucto-chat-hint-keys {
            display: none;
        }
    }

    .qucto-chat-composer .qucto-form-error {
        margin: var(--sp-1-5) 0 0;
    }

    /* Drag & drop: the whole thread becomes the drop target. */
    .qucto-chat-dropoverlay {
        position: absolute;
        inset: var(--sp-2);
        z-index: 40;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: var(--sp-2);
        border: 2px dashed var(--focus);
        border-radius: var(--r-card);
        background: color-mix(in oklch, var(--accent-wash) 92%, transparent);
        color: var(--text);
        font-size: var(--fs-base);
        font-weight: var(--fw-semibold);
        pointer-events: none;
    }

    .qucto-chat-dropoverlay svg {
        inline-size: 28px;
        block-size: 28px;
        color: var(--accent-700);
    }

    /* `hidden` must beat the display values above (author styles outrank
       the UA `[hidden]` rule, and this layer outranks base resets). */
    .qucto-chat-tray[hidden],
    .qucto-chat-jump[hidden],
    .qucto-chat-dropoverlay[hidden],
    .qucto-chat-refpicker[hidden],
    [data-chat-group-only][hidden],
    [data-chat-file-error][hidden] {
        display: none;
    }

    /* ================================================================
       Dialogs — native <dialog> opened with showModal() (chat-overlay.js):
       top layer, inert page, Esc. The <dialog> itself is the frame with no
       padding, so a click whose target is the dialog is a backdrop click.
       ================================================================ */
    .qucto-chat-overlay {
        inline-size: min(480px, 100% - 2 * var(--sp-4));
        max-inline-size: none;
        max-block-size: min(720px, 100dvh - 2 * var(--sp-6));
        margin: auto;
        padding: 0;
        overflow: hidden;
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-xl);
        background: var(--surface);
        color: var(--text);
        box-shadow: var(--dialog-shadow);
        transition: opacity var(--dur-4) var(--ease-out), transform var(--dur-4) var(--ease-out);
    }

    .qucto-chat-overlay:has(> .qucto-chat-modal-wide) {
        inline-size: min(680px, 100% - 2 * var(--sp-4));
    }

    .qucto-chat-overlay[open] {
        display: flex;
        flex-direction: column;
    }

    @starting-style {
        .qucto-chat-overlay[open] {
            opacity: 0;
            transform: scale(var(--enter-scale));
        }
    }

    .qucto-chat-overlay::backdrop {
        background: var(--backdrop);
        transition: opacity var(--dur-4) var(--ease-out);
    }

    @starting-style {
        .qucto-chat-overlay[open]::backdrop {
            opacity: 0;
        }
    }

    .qucto-chat-modal {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-height: 0;
        padding: 0 var(--sp-6) var(--sp-6);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .qucto-chat-modal > * {
        flex-shrink: 0;
    }

    .qucto-chat-modal-head {
        position: sticky;
        inset-block-start: 0;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--sp-3);
        margin-inline: calc(-1 * var(--sp-6));
        margin-block-end: var(--sp-4);
        padding: var(--sp-5) var(--sp-4) var(--sp-3) var(--sp-6);
        background: var(--surface);
    }

    .qucto-chat-modal-head h2 {
        margin: 0;
        font-size: var(--fs-title);
        line-height: var(--lh-title);
        font-weight: var(--fw-semibold);
        letter-spacing: var(--tracking-title);
        text-wrap: balance;
    }

    .qucto-chat-modal > form,
    .qucto-chat-modal form:not([class]) {
        margin: 0;
    }

    .qucto-chat-modal .qucto-form-hint {
        margin-block: var(--sp-2) 0;
    }

    /* Actions stay reachable at the bottom of long dialogs. */
    .qucto-chat-modal-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: var(--sp-2);
        margin-block-start: var(--sp-5);
    }

    .qucto-chat-modal > form:last-child > .qucto-chat-modal-actions:last-child {
        position: sticky;
        inset-block-end: calc(-1 * var(--sp-6));
        z-index: 1;
        margin-inline: calc(-1 * var(--sp-6));
        margin-block-end: calc(-1 * var(--sp-6));
        padding: var(--sp-3) var(--sp-6) var(--sp-5);
        border-block-start: 1px solid var(--border-subtle);
        background: var(--surface);
    }

    .qucto-chat-modal-sep {
        margin: var(--sp-6) 0;
        border: 0;
        border-block-start: 1px solid var(--border-subtle);
    }

    .qucto-chat-modal-subtitle {
        margin: 0 0 var(--sp-3);
        font-size: var(--fs-title-sm);
        line-height: var(--lh-title-sm);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-modal .qucto-chat-refgroup {
        margin: var(--sp-5) 0 var(--sp-2);
        padding: 0;
    }

    .qucto-chat-modal-empty {
        margin: 0;
        padding: var(--sp-6) var(--sp-4);
        border: 1px dashed var(--border-strong);
        border-radius: var(--r-card-nested);
        color: var(--text-secondary);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        text-align: center;
        text-wrap: pretty;
    }

    /* Archive/restore at the foot of channel settings: explanation + action. */
    .qucto-chat-danger-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--sp-3);
        margin: 0;
    }

    .qucto-chat-modal .qucto-chat-danger-row .qucto-form-hint {
        flex: 1 1 240px;
        margin: 0;
    }

    /* People pickers / member lists. */
    .qucto-chat-member-list {
        margin: 0;
        padding: 0;
        list-style: none;
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-card-nested);
        box-shadow: var(--surface-ring);
        overflow: hidden;
    }

    .qucto-chat-member-list > li + li {
        border-block-start: 1px solid var(--border-subtle);
    }

    .qucto-chat-member-row {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        min-block-size: 56px;
        margin: 0;
        padding: var(--sp-2) var(--sp-3);
        background: var(--surface);
        color: var(--text);
        transition: background-color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-member-row .qucto-chat-avatar {
        inline-size: 32px;
        block-size: 32px;
        font-size: var(--fs-xs);
    }

    label.qucto-chat-member-row {
        cursor: pointer;
    }

    label.qucto-chat-member-row:hover {
        background: var(--row-hover);
    }

    label.qucto-chat-member-row:has(input:checked) {
        background: var(--selected);
    }

    label.qucto-chat-member-row:has(input:checked):hover {
        background: var(--selected-hover);
    }

    label.qucto-chat-member-row:has(input:disabled) {
        cursor: default;
    }

    label.qucto-chat-member-row:has(input:focus-visible) {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-member-row form {
        margin: 0;
    }

    .qucto-chat-member-row input[type='checkbox'] {
        flex: none;
        margin: 0;
    }

    /* The accounting firm row leads the new-conversation picker. */
    .qucto-chat-member-row-firm {
        background: var(--surface-sunken);
    }

    .qucto-chat-member-row-firm .qucto-chat-member-name {
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-member-name {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-width: 0;
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        font-weight: var(--fw-medium);
        overflow-wrap: anywhere;
    }

    .qucto-chat-member-mail {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        line-height: var(--lh-xs);
        font-weight: var(--fw-regular);
        letter-spacing: var(--tracking-xs);
    }

    /* form.… outranks `.qucto-chat-modal > form { margin: 0 }` above. */
    form.qucto-chat-rename-row {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: var(--sp-2);
        margin: 0 0 var(--sp-5);
    }

    .qucto-chat-rename-row .qucto-form-field {
        flex: 1 1 220px;
        min-width: 0;
        margin: 0;
    }

    .qucto-chat-rename-row > .qucto-button {
        min-block-size: var(--control-h);
    }

    /* Two-sided channel allowlist: agency staff | client people. */
    .qucto-chat-acl {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--sp-4);
        margin-block-start: var(--sp-4);
    }

    .qucto-chat-acl-col {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .qucto-chat-modal .qucto-chat-acl-col .qucto-chat-refgroup {
        margin: 0 0 var(--sp-2);
    }

    .qucto-chat-acl .qucto-chat-member-list {
        max-block-size: 264px;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .qucto-chat-acl-col .qucto-form-hint {
        margin: 0;
        padding: var(--sp-4) var(--sp-3);
        border: 1px dashed var(--border-strong);
        border-radius: var(--r-card-nested);
        text-align: center;
    }

    /* ================================================================
       Responsive — driven by the `main` size container (layout.css), so
       the rail/drawer state of the shell does not matter.
       ================================================================ */
    @container main (width < 760px) {
        .qucto-chat {
            --chat-pad-x: var(--sp-4);

            grid-template-columns: minmax(0, 1fr);
        }

        .qucto-chat:not(.qucto-chat-thread-open) .qucto-chat-thread,
        .qucto-chat.qucto-chat-thread-open .qucto-chat-list {
            display: none;
        }

        .qucto-chat-list {
            border-inline-end: 0;
        }

        .qucto-chat-back {
            display: inline-flex;
            margin-inline-start: calc(-1 * var(--sp-2));
        }

        .qucto-chat-thread-head {
            gap: var(--sp-2);
            padding-inline: var(--sp-3) var(--sp-2);
        }

        .qucto-chat-questions-link span {
            position: absolute;
            inline-size: 1px;
            block-size: 1px;
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
        }

        .qucto-chat {
            --chat-bubble-max: 86%;
        }

        /* No room beside the bubble: float the toolbar over its top edge. */
        .qucto-chat-msg .qucto-chat-msg-actions,
        .qucto-chat-msg:not(.qucto-chat-msg-own) .qucto-chat-msg-actions {
            inset-block: auto calc(100% - var(--sp-1));
            inset-inline: auto var(--sp-2);
        }
    }

    @container main (width < 560px) {
        /* Phone: the messenger runs edge to edge. */
        .qucto-chat {
            margin-inline: calc(-1 * var(--page-px));
            margin-block-end: calc(-1 * var(--page-py));
            border-inline: 0;
            border-radius: 0;
            box-shadow: 0 -1px 0 var(--ring-color);
        }

        .qucto-chat:first-child {
            margin-block-start: calc(-1 * var(--page-py));
            border-block-start: 0;
            box-shadow: none;
        }

        .qucto-chat-thread-head .qucto-chat-avatar {
            display: none;
        }
    }

    @media (max-width: 640px) {
        .qucto-chat-acl {
            grid-template-columns: minmax(0, 1fr);
        }

        /* Dialogs become full-height sheets. */
        .qucto-chat-overlay,
        .qucto-chat-overlay:has(> .qucto-chat-modal-wide) {
            inline-size: 100%;
            max-inline-size: 100%;
            block-size: 100dvh;
            max-block-size: 100dvh;
            border: 0;
            border-radius: 0;
            box-shadow: none;
        }

        .qucto-chat-overlay[open] {
            transform: none;
        }

        @starting-style {
            .qucto-chat-overlay[open] {
                opacity: 0;
                transform: translateY(var(--motion-shift-lg));
            }
        }

        .qucto-chat-modal {
            padding-inline: var(--sp-4);
        }

        .qucto-chat-modal-head {
            margin-inline: calc(-1 * var(--sp-4));
            padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-4);
            border-block-end: 1px solid var(--border-subtle);
        }

        .qucto-chat-modal > form:last-child > .qucto-chat-modal-actions:last-child {
            margin-inline: calc(-1 * var(--sp-4));
            padding-inline: var(--sp-4);
        }

        .qucto-chat-modal .qucto-chat-modal-actions > .qucto-button {
            flex: 1 1 0;
        }

        .qucto-chat-modal > form:last-child {
            display: flex;
            flex: 1 0 auto;
            flex-direction: column;
        }

        .qucto-chat-modal > form:last-child > .qucto-chat-modal-actions:last-child {
            margin-block-start: auto;
        }
    }

    /* ================================================================
       Forced colours (Windows High Contrast): shadows vanish, so every
       floating layer and state keeps a real border/outline.
       ================================================================ */
    @media (forced-colors: active) {
        .qucto-chat-item a[aria-current] {
            outline: 2px solid Highlight;
            outline-offset: -2px;
        }

        .qucto-chat-list-head::before,
        .qucto-chat-delivery::before,
        .qucto-chat-sentinel-dot,
        .qucto-chat-typing-dots i {
            forced-color-adjust: none;
            background: CanvasText;
        }

        .qucto-chat-newdivider::before,
        .qucto-chat-newdivider::after,
        .qucto-chat-day::before,
        .qucto-chat-day::after {
            forced-color-adjust: none;
            background: CanvasText;
        }

        .qucto-chat-msg-actions,
        .qucto-chat-menu-pop,
        .qucto-chat-refpicker,
        .qucto-chat-jump,
        .qucto-chat-overlay {
            border: 1px solid CanvasText;
        }

        .qucto-chat-sendbtn {
            border: 1px solid ButtonText;
        }

        .qucto-chat-inputrow:has(.qucto-chat-input:focus-visible) {
            outline-color: Highlight;
        }
    }

    /* Reduced motion: durations/offsets already collapse via tokens; the
       looping indicators stop. */
    @media (prefers-reduced-motion: reduce) {
        .qucto-chat-sentinel-dot,
        .qucto-chat-typing-dots i {
            animation: none;
            opacity: 0.7;
        }
    }

    /* ================================================================
       Chat classes reused outside the messenger
       ================================================================ */

    /* System › Účetní: per-firm accountant assignments. */
    .qucto-chat-assign-none {
        color: var(--text-muted);
        font-size: var(--fs-sm);
    }

    .qucto-chat-assign-chips {
        display: flex;
        flex-wrap: wrap;
        gap: var(--sp-1-5);
    }

    .qucto-chat-assign-chip {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-1);
        min-block-size: 28px;
        margin: 0;
        padding: 0 var(--sp-0-5) 0 var(--sp-2-5);
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-pill);
        background: var(--surface-inset);
        box-shadow: inset 0 0 0 1px var(--ring-color);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-weight: var(--fw-medium);
    }

    .qucto-chat-assign-add {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--sp-2);
        margin: 0;
    }

    .qucto-chat-assign-add select {
        flex: 1 1 12rem;
        inline-size: auto;
        min-inline-size: 10rem;
        min-block-size: var(--control-h-sm);
    }

    /* System › Zprávy (nastavení kanálů) + subaccount delete confirmation. */
    .qucto-chat-toggle {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-2);
        min-block-size: 24px;
        margin-block-start: var(--sp-3);
        color: var(--text);
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        cursor: pointer;
    }

    .qucto-chat-toggle input {
        flex: none;
        margin: 0;
    }

    .qucto-chat-testrow {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--sp-2) var(--sp-3);
        margin-block-start: var(--sp-4);
        padding-block-start: var(--sp-4);
        border-block-start: 1px solid var(--border-subtle);
    }

    .qucto-chat-testrow .qucto-form-hint {
        margin: 0;
    }

    .qucto-chat-pairhint {
        margin: 0;
        padding: 0 var(--sp-5) var(--sp-4);
    }

    /* ================================================================
       Questions („Dotazy k vyřízení“) — list + detail pages
       ================================================================ */
    .qucto-chat-backlink {
        display: inline-flex;
        align-items: center;
        gap: var(--sp-1-5);
        align-self: flex-start;
        color: var(--text-secondary);
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        text-decoration: none;
    }

    .qucto-chat-backlink:hover {
        color: var(--text);
        text-decoration: underline;
        text-underline-offset: 2px;
    }

    .qucto-chat-backlink svg {
        inline-size: var(--icon-sm);
        block-size: var(--icon-sm);
    }

    .qucto-chat-crumbs {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--sp-1) var(--sp-4);
        margin: 0;
    }

    .qucto-chat-question-filter {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: var(--sp-2);
        margin-block: var(--sp-4);
    }

    .qucto-chat-question-filter .qucto-form-field {
        flex: 0 1 280px;
        margin: 0;
    }

    .qucto-chat-question-list {
        margin: 0;
        padding: 0;
        list-style: none;
        border: 1px solid transparent; /* forced-colours edge */
        border-radius: var(--r-card);
        background: var(--surface);
        box-shadow: var(--surface-ring);
        overflow: hidden;
    }

    .qucto-card .qucto-chat-question-list {
        border-radius: var(--r-card-nested);
    }

    .qucto-chat-question-list > li + li {
        border-block-start: 1px solid var(--border-subtle);
    }

    .qucto-chat-question-list > li {
        position: relative;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: var(--sp-1) var(--sp-4);
        padding: var(--sp-3) var(--sp-5);
        transition: background-color var(--dur-1) var(--ease-out);
    }

    .qucto-chat-question-list > li:hover {
        background: var(--row-hover);
    }

    .qucto-chat-question-list a {
        display: -webkit-box;
        overflow: hidden;
        color: var(--text);
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        font-weight: var(--fw-medium);
        text-decoration: none;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    /* Stretched link: the whole row opens the question. */
    .qucto-chat-question-list a::after {
        content: '';
        position: absolute;
        inset: 0;
    }

    .qucto-chat-question-list a:focus-visible {
        outline: none;
    }

    .qucto-chat-question-list > li:has(a:focus-visible) {
        outline: var(--focus-ring);
        outline-offset: -2px;
    }

    .qucto-chat-question-meta {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        color: var(--text-muted);
        font-size: var(--fs-label);
        line-height: var(--lh-label);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    .qucto-chat-question-empty {
        margin: var(--sp-4) 0 0;
        padding: var(--sp-8) var(--sp-4);
        border: 1px dashed var(--border-strong);
        border-radius: var(--r-card);
        color: var(--text-muted);
        text-align: center;
    }

    .qucto-chat-pager {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--sp-3);
        margin-block-start: var(--sp-4);
        color: var(--text-muted);
        font-size: var(--fs-sm);
        font-variant-numeric: tabular-nums;
    }

    .qucto-chat-pager-spacer {
        inline-size: 1px;
    }

    .qucto-chat-question-body {
        margin: 0;
        font-size: var(--fs-md);
        line-height: var(--lh-md);
        overflow-wrap: anywhere;
        text-wrap: pretty;
    }

    .qucto-chat-question-facts time,
    .qucto-chat-question-event-head time {
        white-space: nowrap;
    }

    .qucto-chat-question-facts {
        margin: var(--sp-3) 0 0;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-variant-numeric: tabular-nums;
    }

    .qucto-chat-question-history {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .qucto-chat-question-history > li {
        position: relative;
        padding: 0 0 var(--sp-5) var(--sp-6);
    }

    /* Timeline rail + node. */
    .qucto-chat-question-history > li::before {
        content: '';
        position: absolute;
        inset-block: 6px 0;
        inset-inline-start: 5px;
        inline-size: 2px;
        background: var(--border-subtle);
    }

    .qucto-chat-question-history > li:last-child {
        padding-block-end: 0;
    }

    .qucto-chat-question-history > li:last-child::before {
        display: none;
    }

    .qucto-chat-question-history > li::after {
        content: '';
        position: absolute;
        inset-block-start: 4px;
        inset-inline-start: 0;
        inline-size: 12px;
        block-size: 12px;
        box-sizing: border-box;
        border: 2px solid var(--border-control);
        border-radius: var(--r-pill);
        background: var(--surface);
    }

    .qucto-chat-question-history > li:last-child::after {
        border-color: var(--accent-700);
        background: var(--accent);
    }

    .qucto-chat-question-event-head {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--sp-1) var(--sp-2);
        color: var(--text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-sm);
        font-variant-numeric: tabular-nums;
    }

    .qucto-chat-question-event-head strong {
        color: var(--text);
        font-weight: var(--fw-semibold);
    }

    .qucto-chat-question-history p {
        margin: var(--sp-1) 0 0;
        overflow-wrap: anywhere;
    }
}
