/* ==========================================================================
   Chat (/messages) - OrderCounter's Google Chat inside the portal (2026-10-17).
   Pages/Messages/Messages.razor and the Components/Chat folder.

   The master-detail workbench (design-system/50-patterns.md): rail | stream |
   thread or people, one white frame on the muted ground, hairlines between
   panes, each pane scrolling on its own so the page never does. Phones show one
   pane at a time (data-view on .chat-page). Tokens only (oc-theme.css); the
   gray scale flips for dark by itself, and the few fills that do not are
   overridden under [data-oc-theme="dark"] at the end of this file.
   ========================================================================== */

/* ---------- shell: fullbleed, like Mail (oc-theme.css .mail-page) ---------- */
.oc-content-inner:has(.chat-page) {
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.oc-content:has(.chat-page) {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

@media (max-width: 768px) {
    /* The global 6rem bottom-bar clearance is for flowing pages; this one is pinned
       between the topbar and the bottom bar and scrolls inside its panes. */
    .oc-content-inner:has(.chat-page) {
        padding: 0 !important;
    }

    /* ONE SCREEN AT LEAST (phone readiness 5c, 2026-10-21). Pinned like a board, so the session
       banners above (stand-up, work machine, incomplete merchants, Get the app) took their height
       out of the chat and left it a sliver, with nothing to scroll. On a phone the page is never
       shorter than the content area itself - the dynamic viewport less the top bar and its
       status-bar inset and the bottom bar with its home-indicator inset (this page has no padding
       here). With no banners that is the room there is; with banners the shell's scroller scrolls
       them away and the chat fills the screen, its panes scrolling inside it as before. The
       boards' twin is the "Phone Wave 5c" block at the end of oc-theme.css. */
    .oc-content-inner:has(.chat-page) > .chat-page {
        min-height: calc(100vh - var(--oc-shell-topbar-h, 60px) - env(safe-area-inset-top, 0px)
                         - var(--oc-shell-bottombar-total, 64px));
        min-height: calc(100dvh - var(--oc-shell-topbar-h, 60px) - env(safe-area-inset-top, 0px)
                         - var(--oc-shell-bottombar-total, 64px));
    }
}

/* ---------- page frame ---------- */
.chat-page {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--oc-space-2);
    padding: var(--oc-space-3);
    background: var(--oc-surface-muted);
    color: var(--oc-text);
    font-family: var(--oc-font-sans);
}

.chat-page ::selection {
    background: var(--oc-primary-soft);
    color: var(--oc-text);
}

.chat-sync-notice {
    display: flex;
    align-items: center;
    gap: var(--oc-space-2);
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--oc-warning-border);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-warning-bg);
    color: var(--oc-warning-text);
    font-size: var(--oc-fs-sm);
    line-height: 1.35;
}

.chat-workbench {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: clamp(240px, 22%, 300px) minmax(0, 1fr);
    background: var(--oc-surface);
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-md);
    box-shadow: var(--oc-shadow-sm);
    overflow: hidden;
}

.chat-workbench--side {
    grid-template-columns: clamp(220px, 20%, 280px) minmax(0, 1fr) clamp(320px, 30%, 400px);
}

.chat-rail,
.chat-main,
.chat-side {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-rail { border-right: 1px solid var(--oc-gray-200); background: var(--oc-gray-50); }
.chat-side { border-left: 1px solid var(--oc-gray-200); }

.chat-page--loading { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: var(--oc-space-3); background: var(--oc-surface-muted); }

/* Thin themed scrollbars on every pane. */
.chat-rail-scroll,
.chat-stream,
.chat-side-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--oc-gray-300) transparent;
}

.chat-rail-scroll::-webkit-scrollbar,
.chat-stream::-webkit-scrollbar,
.chat-side-scroll::-webkit-scrollbar { width: 8px; }
.chat-rail-scroll::-webkit-scrollbar-thumb,
.chat-stream::-webkit-scrollbar-thumb,
.chat-side-scroll::-webkit-scrollbar-thumb { background: var(--oc-gray-300); border-radius: var(--oc-radius-pill); }

/* Shared focus ring for every control on the page. */
.chat-page button:focus-visible,
.chat-page a:focus-visible,
.chat-page input:focus-visible,
.chat-page textarea:focus-visible,
.chat-page summary:focus-visible,
.chat-page [tabindex]:focus-visible {
    outline: 2px solid var(--oc-focus);
    outline-offset: 2px;
}

/* ---------- rail ---------- */
.chat-rail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--oc-space-2);
    padding: var(--oc-space-3) var(--oc-space-3) var(--oc-space-2);
}

.chat-rail-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.01em;
}

.chat-rail-new {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 32px;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--oc-gray-300);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    color: var(--oc-gray-900);
    font-size: var(--oc-fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease), border-color var(--oc-dur-fast) var(--oc-ease);
}

.chat-rail-new:hover { background: var(--oc-gray-100); border-color: var(--oc-gray-400); }

.chat-rail-search {
    position: relative;
    padding: 0 var(--oc-space-3) var(--oc-space-2);
}

.chat-rail-search-icon {
    position: absolute;
    left: calc(var(--oc-space-3) + 0.6rem);
    top: 0.55rem;
    color: var(--oc-text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

.chat-rail-search-input {
    width: 100%;
    min-height: 34px;
    padding: 0.4rem 0.6rem 0.4rem 1.9rem;
    border: 1px solid var(--oc-input-border);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    color: var(--oc-text);
    font-size: var(--oc-fs-sm);
}

.chat-rail-search-input::placeholder { color: var(--oc-text-muted); }
.chat-rail-search-input--small { padding-left: 0.6rem; }

.chat-rail-scroll {
    flex: 1;
    min-height: 0;
    padding: 0 var(--oc-space-2) var(--oc-space-4);
}

.chat-rail-section { margin-top: var(--oc-space-3); }

.chat-rail-section-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 0.2rem;
    padding: 0 0.5rem;
    color: var(--oc-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.35;
}

.chat-rail-section-unread {
    padding: 0 0.4rem;
    border-radius: var(--oc-radius-pill);
    background: var(--oc-gray-200);
    color: var(--oc-gray-800);
    font-variant-numeric: tabular-nums;
}

.chat-rail-list { list-style: none; margin: 0; padding: 0; }

.chat-rail-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-height: 34px;
    padding: 0.3rem 0.5rem;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-gray-700);
    font-size: var(--oc-fs-sm);
    text-align: left;
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease);
}

.chat-rail-item:hover { background: var(--oc-gray-100); color: var(--oc-gray-900); }

/* Selection: the workbench's one style, a 2px inset ring on a white row. */
.chat-rail-item--selected,
.chat-rail-item--selected:hover {
    background: var(--oc-surface);
    color: var(--oc-gray-900);
    box-shadow: inset 0 0 0 2px var(--oc-primary);
}

.chat-rail-item--unread { color: var(--oc-gray-900); font-weight: 700; }

.chat-rail-item-icon {
    position: relative;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.chat-rail-item-hash {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--oc-radius-xs);
    background: var(--oc-gray-200);
    color: var(--oc-gray-700);
    font-size: 0.8rem;
    font-weight: 700;
}

.chat-rail-item-more {
    position: absolute;
    right: -5px;
    bottom: -4px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    border: 1px solid var(--oc-gray-50);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-gray-700);
    color: var(--oc-surface);
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 13px;
    text-align: center;
}

.chat-rail-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-rail-item-ago {
    flex: none;
    color: var(--oc-text-muted);
    font-size: 0.72rem;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

.chat-rail-item-oversight { flex: none; color: var(--oc-text-muted); font-size: 0.8rem; }

.chat-rail-badge {
    flex: none;
    min-width: 20px;
    padding: 0 0.4rem;
    border-radius: var(--oc-radius-pill);
    /* Yellow = unread you can see; red (--urgent) = a DM, a group chat or an @mention of you (CEO 2026-10-21). */
    background: var(--oc-chat-badge-yellow);
    color: var(--oc-chat-badge-yellow-ink);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.chat-rail-badge--urgent,
.chat-rail-section-unread--urgent {
    background: var(--oc-danger);
    color: var(--oc-chat-badge-red-ink);
}

.chat-rail-empty {
    margin: 0.25rem 0;
    padding: 0 0.5rem;
    color: var(--oc-text-muted);
    font-size: var(--oc-fs-sm);
    line-height: 1.4;
}

.chat-rail-fold {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 30px;
    padding: 0 0.5rem;
    border-radius: var(--oc-radius-sm);
    list-style: none;
    color: var(--oc-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.chat-rail-fold::-webkit-details-marker { display: none; }

/* Drawn chevron that turns when the group opens. */
.chat-rail-fold::before {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--oc-dur-fast) var(--oc-ease);
}

details[open] > .chat-rail-fold::before { transform: rotate(45deg); }
.chat-rail-fold:hover { background: var(--oc-gray-100); color: var(--oc-gray-900); }

.chat-rail-older { margin-top: 0.15rem; }
.chat-rail-older-count { font-variant-numeric: tabular-nums; font-weight: 400; }

.chat-rail-more,
.chat-rail-search-messages {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.35rem 0.5rem;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-link);
    font-size: var(--oc-fs-sm);
    text-align: left;
    cursor: pointer;
}

.chat-rail-more:hover,
.chat-rail-search-messages:hover { background: var(--oc-gray-100); }

.chat-rail-oversight { margin-top: var(--oc-space-4); padding-top: var(--oc-space-2); border-top: 1px solid var(--oc-gray-200); }
.chat-rail-oversight-note { margin: 0.25rem 0 0.4rem; padding: 0 0.5rem; color: var(--oc-text-muted); font-size: 0.75rem; }
.chat-rail-oversight-search { padding: 0 0.25rem 0.35rem; }

.chat-rail-skeleton { display: flex; flex-direction: column; gap: 0.6rem; padding: var(--oc-space-3); }
.chat-rail-skel-row { display: flex; align-items: center; gap: 0.6rem; }

.chat-rail-note { padding: var(--oc-space-3); color: var(--oc-text-muted); font-size: var(--oc-fs-sm); }

/* New message panel (under the search box). */
.chat-newdm {
    margin: 0 var(--oc-space-3) var(--oc-space-2);
    padding: var(--oc-space-3);
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    box-shadow: var(--oc-shadow-sm);
}

.chat-newdm-label { display: block; margin-bottom: 0.35rem; font-size: 0.75rem; font-weight: 600; color: var(--oc-gray-700); }
.chat-newdm-foot { display: flex; justify-content: flex-end; margin-top: 0.25rem; }

/* ---------- conversation header ---------- */
.chat-conv-head,
.chat-side-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--oc-space-2);
    min-height: 56px;
    padding: 0.5rem var(--oc-space-4);
    border-bottom: 1px solid var(--oc-gray-200);
    background: var(--oc-surface);
}

.chat-conv-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.6rem; }

.chat-conv-glyph {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--oc-radius-sm);
    background: var(--oc-gray-100);
    color: var(--oc-gray-700);
    font-weight: 700;
}

.chat-conv-text { min-width: 0; display: flex; flex-direction: column; }

.chat-conv-title,
.chat-side-title h2 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.3;
}

.chat-conv-sub,
.chat-side-sub { color: var(--oc-text-muted); font-size: 0.78rem; }

.chat-side-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.chat-conv-actions { flex: none; display: flex; align-items: center; gap: 0.25rem; }

.chat-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-width: 34px;
    height: 34px;
    padding: 0 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-gray-700);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease);
}

.chat-icon-btn:hover { background: var(--oc-gray-100); color: var(--oc-gray-900); }
.chat-icon-btn--on { background: var(--oc-gray-100); border-color: var(--oc-gray-300); color: var(--oc-gray-900); }
.chat-icon-btn-count { font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* Back buttons exist only on phones (one pane at a time). */
.chat-back {
    display: none;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-left: -0.5rem;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-gray-800);
    font-size: 1.1rem;
}

.chat-oversight-banner {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--oc-space-2);
    padding: 0.5rem var(--oc-space-4);
    border-bottom: 1px solid var(--oc-warning-border);
    background: var(--oc-amber-bg);
    color: var(--oc-amber-700);
    font-size: var(--oc-fs-sm);
    font-weight: 600;
}

/* Where the message box would be, in a conversation you were only invited to (CEO 2026-10-21). */
.chat-invite-notice {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--oc-space-2) var(--oc-space-3);
    margin: 0 var(--oc-space-4) var(--oc-space-4);
    padding: var(--oc-space-3) var(--oc-space-4);
    border: 1px solid var(--oc-warning-border);
    border-radius: var(--oc-radius-md);
    background: var(--oc-amber-bg);
    color: var(--oc-amber-700);
    font-size: var(--oc-fs-sm);
    font-weight: 600;
}
.chat-invite-notice > span:first-of-type { flex: 1 1 18rem; }
.chat-invite-actions { display: flex; gap: var(--oc-space-2); }

/* ---------- stream ---------- */
.chat-main { background: var(--oc-surface); }

.chat-main-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: var(--oc-space-6); }

.chat-stream {
    flex: 1;
    min-height: 0;
    padding: var(--oc-space-2) 0 var(--oc-space-2);
    outline: none;
}

.chat-stream-top { display: flex; justify-content: center; padding: var(--oc-space-3) var(--oc-space-4) var(--oc-space-1); }

.chat-stream-older {
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--oc-gray-300);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-surface);
    color: var(--oc-gray-700);
    font-size: 0.78rem;
    cursor: pointer;
}

.chat-stream-older:hover { background: var(--oc-gray-100); }
.chat-stream-loading,
.chat-stream-begin { color: var(--oc-text-muted); font-size: 0.78rem; }

.chat-stream-start { padding: var(--oc-space-8) var(--oc-space-5) var(--oc-space-4); color: var(--oc-text-muted); }
.chat-stream-start p { margin: 0 0 0.25rem; }
.chat-stream-start-title { color: var(--oc-text); font-size: 1.05rem; font-weight: 700; }

/* Date separator: a muted label set into a hairline, sticky while its day scrolls. */
.chat-day {
    /* In-flow, not sticky: stacked sticky day chips piled on top of each other and over the
       first message when a short day scrolled under a long one (walk 2026-10-18). */
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--oc-space-3);
    margin: var(--oc-space-3) 0 var(--oc-space-1);
    padding: 0 var(--oc-space-4);
    color: var(--oc-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

.chat-day::before,
.chat-day::after { content: ""; flex: 1; height: 1px; background: var(--oc-gray-200); }

.chat-day span {
    padding: 0.1rem 0.6rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-surface);
}

/* One message. Gutter (avatar or hover time) + body; continuations fold in tight. */
.chat-msg {
    position: relative;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    column-gap: 0.6rem;
    padding: 0.45rem var(--oc-space-4) 0.2rem;
    transition: background var(--oc-dur-fast) var(--oc-ease);
}

.chat-msg--cont { padding-top: 0.05rem; }
.chat-msg:hover { background: var(--oc-gray-50); }
.chat-msg--editing { background: var(--oc-gray-50); }

.chat-msg--flash { animation: chat-flash 1.6s var(--oc-ease); }
@keyframes chat-flash {
    0% { background: var(--oc-primary-soft); }
    100% { background: transparent; }
}

.chat-msg-gutter { display: flex; justify-content: center; padding-top: 0.1rem; }

.chat-msg-hover-time {
    visibility: hidden;
    padding-top: 0.2rem;
    color: var(--oc-text-muted);
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
}

.chat-msg:hover .chat-msg-hover-time { visibility: visible; }

.chat-msg-main { min-width: 0; }

.chat-msg-head { display: flex; align-items: baseline; gap: 0.5rem; }
.chat-msg-name { color: var(--oc-gray-900); font-size: 0.92rem; font-weight: 700; }
.chat-msg-time { color: var(--oc-text-muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }

.chat-msg-bot {
    padding: 0 0.35rem;
    border-radius: var(--oc-radius-xs);
    background: var(--oc-gray-100);
    color: var(--oc-gray-700);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.chat-msg-body {
    color: var(--oc-gray-900);
    font-size: 0.95rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    max-width: 78ch;
}

.chat-msg-body > :first-child { margin-top: 0; }
.chat-msg-body > :last-child { margin-bottom: 0; }
.chat-msg-body p { margin: 0 0 0.35rem; }
.chat-msg-body a { color: var(--oc-link); text-underline-offset: 2px; }
.chat-msg-body code {
    padding: 0.05rem 0.3rem;
    border-radius: var(--oc-radius-xs);
    background: var(--oc-gray-100);
    font-family: var(--oc-font-mono);
    font-size: 0.82em;
}
.chat-msg-body pre {
    margin: 0.35rem 0;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-gray-50);
    font-family: var(--oc-font-mono);
    font-size: 0.78rem;
    overflow-x: auto;
}
.chat-msg-body pre code { padding: 0; background: transparent; }
.chat-msg-body blockquote { margin: 0.25rem 0; padding-left: 0.75rem; border-left: 1px solid var(--oc-gray-300); color: var(--oc-gray-700); }
.chat-msg-body img { max-width: min(100%, 420px); height: auto; border-radius: var(--oc-radius-sm); }

.chat-msg-edited { color: var(--oc-text-muted); font-size: 0.72rem; }
.chat-msg-gone { margin: 0; color: var(--oc-text-muted); font-size: var(--oc-fs-sm); font-style: italic; }

/* Hover toolbar for a message's own actions. */
.chat-msg-tools {
    position: absolute;
    top: -14px;
    right: var(--oc-space-4);
    display: none;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    box-shadow: var(--oc-shadow-sm);
}

.chat-msg:hover .chat-msg-tools,
.chat-msg:focus-within .chat-msg-tools { display: flex; }

.chat-msg-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: 0;
    border-radius: var(--oc-radius-xs);
    background: transparent;
    color: var(--oc-gray-700);
    cursor: pointer;
}

.chat-msg-tool:hover { background: var(--oc-gray-100); color: var(--oc-gray-900); }
.chat-msg-tool--danger:hover { background: var(--oc-danger-bg); color: var(--oc-danger-text); }

.chat-msg-edit-input {
    width: 100%;
    min-height: 60px;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--oc-input-border);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    color: var(--oc-text);
    font-size: 0.95rem;
    resize: vertical;
}

.chat-msg-edit-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.4rem; margin-top: 0.35rem; }
.chat-msg-edit-hint { margin-right: auto; color: var(--oc-text-muted); font-size: 0.72rem; }

.chat-msg-confirm {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--oc-danger-border);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-danger-bg);
    color: var(--oc-danger-text);
    font-size: var(--oc-fs-sm);
}

.chat-msg-confirm span { margin-right: auto; }

/* Attachments: quiet chips under the text. */
.chat-attachments { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.35rem 0 0; padding: 0; list-style: none; }

.chat-attachment {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: 320px;
    min-height: 34px;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-surface);
    color: var(--oc-gray-800);
    font-size: var(--oc-fs-sm);
    text-decoration: none;
    cursor: pointer;
}

.chat-attachment:hover { background: var(--oc-gray-50); border-color: var(--oc-gray-300); color: var(--oc-gray-900); }
.chat-attachment-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-attachment-go { color: var(--oc-text-muted); font-size: 0.75rem; }

/* Reactions row: pills with counts, filled when I reacted. */
.chat-reactions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin-top: 0.3rem; }
.chat-reactions:empty { display: none; }

/* No reactions yet: the add button floats at the message's bottom-right on hover/focus instead of
   reserving a 26px row under every message (walk 2026-10-18: grouped messages sat far apart). */
.chat-reactions--empty {
    position: absolute;
    right: var(--oc-space-4);
    bottom: 0.15rem;
    margin: 0;
    display: none;
}
.chat-msg:hover .chat-reactions--empty,
.chat-msg:focus-within .chat-reactions--empty { display: flex; }
.chat-reactions--empty .chat-reaction-add--quiet { visibility: visible; }
/* Never over the edit box's Save button (walk 2026-10-18 step 21). */
.chat-msg--editing .chat-reactions--empty,
.chat-msg--editing:hover .chat-reactions--empty { display: none; }

.chat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 26px;
    padding: 0 0.5rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-gray-50);
    color: var(--oc-gray-700);
    font-size: 0.78rem;
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease), border-color var(--oc-dur-fast) var(--oc-ease);
}

span.chat-reaction { cursor: default; }
button.chat-reaction:hover { border-color: var(--oc-gray-400); background: var(--oc-surface); }

.chat-reaction--mine {
    border-color: var(--oc-info);
    background: var(--oc-info-bg);
    color: var(--oc-info-text);
}

button.chat-reaction--mine:hover { border-color: var(--oc-info); background: var(--oc-info-bg); }

.chat-reaction-emoji { font-size: 0.95rem; line-height: 1; }
.chat-reaction-count { font-weight: 600; font-variant-numeric: tabular-nums; }

.chat-reaction-add-wrap { position: relative; display: inline-flex; }

.chat-reaction-add {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 0.45rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-surface);
    color: var(--oc-text-muted);
    cursor: pointer;
}

.chat-reaction-add:hover { color: var(--oc-gray-900); border-color: var(--oc-gray-400); }
.chat-reaction-add-plus { margin-left: -2px; font-size: 0.7rem; }

/* With no reactions yet, the add button appears only on hover/focus, so a quiet stream stays quiet. */
.chat-reaction-add--quiet { visibility: hidden; }
.chat-msg:hover .chat-reaction-add--quiet,
.chat-msg:focus-within .chat-reaction-add--quiet,
.chat-reaction-add--quiet[aria-expanded="true"] { visibility: visible; }

.chat-emoji-picker {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(6, 36px);
    gap: 2px;
    padding: 6px;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-md);
    background: var(--oc-surface);
    box-shadow: var(--oc-shadow-md);
}

.chat-emoji-option {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

.chat-emoji-option:hover { background: var(--oc-gray-100); }

/* "N replies" chip under a message that started a thread. */
.chat-thread-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.3rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid transparent;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-link);
    font-size: 0.8rem;
    cursor: pointer;
}

.chat-thread-chip:hover { border-color: var(--oc-gray-200); background: var(--oc-surface); }
.chat-thread-chip-count { font-weight: 700; }
.chat-thread-chip-last { color: var(--oc-text-muted); }
.chat-thread-chip-go { color: var(--oc-text-muted); font-size: 0.7rem; }

/* Below the stream: jump-to-latest and who is typing. */
.chat-stream-foot {
    position: relative;
    flex: none;
    min-height: 1.4rem;
    padding: 0 var(--oc-space-4);
}

.chat-typing { color: var(--oc-text-muted); font-size: 0.75rem; line-height: 1.4rem; font-style: italic; }

.chat-jump {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--oc-gray-300);
    border-radius: var(--oc-radius-pill);
    background: var(--oc-surface);
    color: var(--oc-gray-800);
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: var(--oc-shadow-md);
    cursor: pointer;
    z-index: 2;
}

.chat-jump--new { border-color: var(--oc-btn-primary-bg); background: var(--oc-btn-primary-bg); color: var(--oc-btn-primary-ink); }

/* ---------- composer ---------- */
.chat-main-compose,
.chat-side-compose { flex: none; padding: 0 var(--oc-space-4) var(--oc-space-3); }

.chat-composer {
    border: 1px solid var(--oc-gray-300);
    border-radius: var(--oc-radius-md);
    background: var(--oc-surface);
    transition: border-color var(--oc-dur-fast) var(--oc-ease), box-shadow var(--oc-dur-fast) var(--oc-ease);
}

.chat-composer:focus-within { border-color: var(--oc-gray-500); box-shadow: var(--oc-shadow-sm); }
.chat-composer.chat-drop-refused { border-style: dashed; border-color: var(--oc-warning-border); }
.chat-composer--disabled { opacity: 0.6; }

.chat-composer-input {
    display: block;
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 0.65rem 0.8rem 0.25rem;
    border: 0;
    border-radius: var(--oc-radius-md) var(--oc-radius-md) 0 0;
    background: transparent;
    color: var(--oc-text);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    caret-color: var(--oc-primary);
}

.chat-composer-input:focus,
.chat-composer-input:focus-visible { outline: none; }
.chat-composer-input::placeholder { color: var(--oc-text-muted); }

.chat-composer-bar { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.4rem 0.4rem 0.55rem; }

.chat-composer-attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: transparent;
    color: var(--oc-gray-600);
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease), color var(--oc-dur-fast) var(--oc-ease);
}

.chat-composer-attach:hover:not(:disabled) { background: var(--oc-gray-100); color: var(--oc-gray-900); }
.chat-composer-attach:disabled { color: var(--oc-gray-400); cursor: default; }

/* The file chosen for the next message: the sent-attachment chip's shape, plus size and a remove x. */
.chat-composer.chat-drop-ready { border-style: dashed; border-color: var(--oc-primary); }
.chat-composer-files { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.15rem 0.6rem 0.1rem; }

.chat-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: min(100%, 360px);
    min-height: 34px;
    padding: 0.25rem 0.25rem 0.25rem 0.6rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-sm);
    background: var(--oc-gray-50);
    color: var(--oc-gray-800);
    font-size: var(--oc-fs-sm);
}

.chat-file-chip-icon { flex: none; color: var(--oc-text-muted); }
.chat-file-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-chip-size { flex: none; color: var(--oc-text-muted); font-variant-numeric: tabular-nums; }

.chat-file-chip-remove {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: var(--oc-radius-xs);
    background: transparent;
    color: var(--oc-gray-600);
    cursor: pointer;
}

.chat-file-chip-remove:hover:not(:disabled) { background: var(--oc-gray-200); color: var(--oc-gray-900); }
.chat-file-chip-remove:disabled { opacity: 0.5; cursor: default; }

.chat-composer-note { padding: 0.15rem 0.8rem 0; color: var(--oc-danger-text); font-size: var(--oc-fs-sm); }

.chat-composer-hint { flex: 1; color: var(--oc-text-muted); font-size: 0.7rem; }

.chat-composer-hint kbd {
    padding: 0 0.25rem;
    border: 1px solid var(--oc-gray-200);
    border-radius: var(--oc-radius-xs);
    background: var(--oc-gray-50);
    color: var(--oc-gray-700);
    font-family: inherit;
    font-size: 0.68rem;
    box-shadow: none;
}

.chat-composer-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 32px;
    border: 0;
    border-radius: var(--oc-radius-sm);
    background: var(--oc-btn-primary-bg);
    color: var(--oc-btn-primary-ink);
    cursor: pointer;
    transition: background var(--oc-dur-fast) var(--oc-ease);
}

.chat-composer-send:hover:not(:disabled) { background: var(--oc-btn-primary-hover-bg); color: var(--oc-btn-primary-hover-ink); }
.chat-composer-send:disabled { background: var(--oc-gray-200); color: var(--oc-gray-500); cursor: default; }

/* ---------- side pane (thread / people) ---------- */
.chat-side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--oc-surface); }
.chat-side-scroll { flex: 1; min-height: 0; padding-bottom: var(--oc-space-2); }
.chat-side .chat-msg { padding-left: var(--oc-space-3); padding-right: var(--oc-space-3); }

.chat-thread-root { padding-top: var(--oc-space-2); }

.chat-thread-divider {
    display: flex;
    align-items: center;
    gap: var(--oc-space-2);
    margin: var(--oc-space-2) 0;
    padding: 0 var(--oc-space-3);
    color: var(--oc-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

.chat-thread-divider::after { content: ""; flex: 1; height: 1px; background: var(--oc-gray-200); }

.chat-thread-empty { padding: var(--oc-space-3); color: var(--oc-text-muted); font-size: var(--oc-fs-sm); }

.chat-members { margin: 0; padding: var(--oc-space-2) 0; list-style: none; }
.chat-member { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem var(--oc-space-3); }
.chat-member-text { min-width: 0; display: flex; flex-direction: column; }
.chat-member-name { color: var(--oc-gray-900); font-size: var(--oc-fs-sm); font-weight: 600; }
.chat-member-sub { color: var(--oc-text-muted); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-inline-note { margin: var(--oc-space-3); padding: 0.5rem 0.75rem; border-radius: var(--oc-radius-sm); background: var(--oc-danger-bg); color: var(--oc-danger-text); font-size: var(--oc-fs-sm); }

/* ---------- search results ---------- */
.chat-hits { margin: 0; padding: var(--oc-space-2) var(--oc-space-3); list-style: none; }

.chat-hit {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 0;
    border-bottom: 1px solid var(--oc-gray-200);
    background: transparent;
    color: var(--oc-text);
    text-align: left;
    cursor: pointer;
}

.chat-hit:hover { background: var(--oc-gray-50); }
.chat-hit-head { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.78rem; }
.chat-hit-space { color: var(--oc-gray-900); font-weight: 700; }
.chat-hit-who { color: var(--oc-gray-700); }
.chat-hit-time { margin-left: auto; color: var(--oc-text-muted); font-variant-numeric: tabular-nums; }
.chat-hit-snippet { color: var(--oc-gray-800); font-size: var(--oc-fs-sm); line-height: 1.45; }

/* ---------- skeletons ---------- */
.chat-stream-skeleton { display: flex; flex-direction: column; gap: var(--oc-space-4); padding: var(--oc-space-4); }
.chat-skel-msg { display: flex; gap: 0.6rem; }
.chat-skel-msg > div,
.chat-skel-lines { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }

/* ---------- 769-1279px: with a side pane open, the rail steps aside ---------- */
@media (max-width: 1279px) and (min-width: 769px) {
    .chat-workbench--side { grid-template-columns: minmax(0, 1fr) clamp(300px, 40%, 380px); }
    .chat-workbench--side > .chat-rail { display: none; }
}

/* ---------- phones: one pane at a time ---------- */
@media (max-width: 768px) {
    .chat-page { padding: 0; gap: 0; }
    .chat-sync-notice { border-radius: 0; border-width: 0 0 1px; }

    .chat-workbench,
    .chat-workbench--side {
        grid-template-columns: minmax(0, 1fr);
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-workbench > .chat-rail,
    .chat-workbench > .chat-main,
    .chat-workbench > .chat-side { display: none; border: 0; }

    .chat-page[data-view="list"] .chat-rail,
    .chat-page[data-view="conversation"] .chat-main,
    .chat-page[data-view="side"] .chat-side { display: flex; }

    /* A side pane asked for with nothing in it falls back to the conversation. */
    .chat-page[data-view="side"] .chat-workbench:not(.chat-workbench--side) > .chat-main { display: flex; }

    .chat-back { display: inline-flex; }
    .chat-side-close { display: none; }

    .chat-rail-item { min-height: 44px; }
    .chat-rail-new { min-height: 44px; }
    .chat-rail-search-input { min-height: 44px; font-size: 16px; }
    .chat-composer-input { font-size: 16px; }
    .chat-composer-hint { display: none; }
    .chat-composer-send { width: 44px; height: 40px; }
    .chat-composer-attach { width: 40px; height: 40px; }
    .chat-file-chip-remove { width: 36px; height: 36px; }
    .chat-msg { padding-left: var(--oc-space-3); padding-right: var(--oc-space-3); }
    /* No hover on touch: a tap on a message (chat-msg--selected) shows its actions inline. */
    .chat-msg-tools { position: static; display: none; justify-self: end; grid-column: 2; margin-top: 0.15rem; border: 0; box-shadow: none; background: transparent; }
    .chat-msg--selected .chat-msg-tools { display: flex; }
    .chat-msg:hover .chat-msg-tools { display: none; }
    .chat-msg--selected:hover .chat-msg-tools { display: flex; }
    .chat-reactions--empty { position: static; display: none; }
    .chat-msg:hover .chat-reactions--empty { display: none; }
    .chat-msg--selected .chat-reactions--empty { display: flex; }
    .chat-msg-tool { width: 40px; height: 36px; }
    .chat-reaction-add--quiet { visibility: visible; }
    .chat-main-compose,
    .chat-side-compose { padding: 0 var(--oc-space-2) var(--oc-space-2); }
}

/* ---------- touch screens (phone readiness X7 + X8, 21 Oct 2026) ----------
   Return makes a new line here and the Send button sends (oc-chat.js), so the "Enter to send"
   keyboard hint would be wrong - phones already hide it; a tablet now does too. And a finger
   needs 44px: Send and the paperclip were 40px on a phone, the conversation's header buttons
   34px, a message's tools 40x36, a reaction 26px. */
@media (pointer: coarse) {
    .chat-composer-hint { display: none; }

    .chat-composer-send,
    .chat-composer-attach,
    .chat-file-chip-remove,
    .chat-msg-tool,
    .chat-emoji-option { width: 44px; height: 44px; }

    .chat-icon-btn { min-width: 44px; height: 44px; }

    .chat-rail-new,
    .chat-rail-item,
    .chat-rail-fold,
    .chat-rail-search-messages,
    .chat-attachment,
    .chat-thread-chip,
    .chat-stream-older,
    .chat-jump,
    button.chat-reaction,
    .chat-reaction-add { min-height: 44px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .chat-msg--flash { animation: none; }
    .chat-rail-fold::before { transition: none; }
}

/* ---------- dark overrides (fills that do not flip with the gray scale) ---------- */
[data-oc-theme="dark"] .chat-rail-badge--urgent,
[data-oc-theme="dark"] .chat-rail-section-unread--urgent {
    background: var(--oc-danger);
    color: var(--oc-chat-badge-red-ink);
}

[data-oc-theme="dark"] .chat-rail-item-more {
    background: var(--oc-gray-600);
    color: var(--oc-gray-900);
    border-color: var(--oc-gray-50);
}

[data-oc-theme="dark"] .chat-rail-item--selected,
[data-oc-theme="dark"] .chat-rail-item--selected:hover {
    background: var(--oc-gray-100);
}

[data-oc-theme="dark"] .chat-emoji-picker,
[data-oc-theme="dark"] .chat-msg-tools,
[data-oc-theme="dark"] .chat-jump {
    background: var(--oc-gray-100);
}
