/* ================================================================
   FriendsByChance — chat.css
   Chat feature (080): page, panel (floating), column (adaptive right)
   ================================================================ */


/* ── Shared inner layout ─────────────────────────────────────────── */

.chat-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--color-surface);
    overflow: hidden;
}

/* List section wrapper (header + search + list) — toggled as a unit in panel/column */
.chat-list-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* The one conversation a panel/column shows instead of its list. */
.chat-surface-thread {
    display: flex;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}


/* All / People / Groups — each list's own (FBC.prefs 'chat.lists'). */
.chat-filter {
    padding:       6px 8px;
    border-bottom: 1px solid var(--color-divider);
    background:    var(--color-surface);
    flex-shrink:   0;
}
.chat-filter .fbc-segchoice { width: 100%; }

/* ── Conversation list ───────────────────────────────────────────── */

.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    background: var(--color-bg);
}

.chat-conv-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-divider);
    cursor: pointer;
    background: var(--color-surface);
    transition: background var(--transition);
}

.chat-conv-row:hover,
.chat-conv-row.active {
    background: #f0f7f3;
}

.chat-conv-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--color-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-on-primary);
    font-size: 1rem;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* A group with no picture of its own wears people, not an initial. */
.chat-conv-avatar--group { background: var(--color-secondary); }

/* A row's picture and, on its corner, the unread count — as the top bar's
   chat button carries it (.fbc-view-btn-badge). */
.chat-conv-face {
    position:    relative;
    flex-shrink: 0;
}
.chat-conv-face .chat-unread-badge {
    position:   absolute;
    top:        -4px;
    right:      -7px;
    box-shadow: 0 0 0 2px var(--color-surface);
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-preview {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    flex-shrink: 0;
}

/* The Chat page's rows, while a chat is open there and more than one pane
   fits: the time's corner is a BUTTON — the chat added to a pane, held:
   which pane (chat-page.js).  The time moves up, the panes' mini map
   under it. */
.chat-conv-pane-btn {
    align-self:      stretch;
    justify-content: center;
    gap:             4px;
    margin:          -6px -6px -6px 0;
    padding:         4px 6px;
    background:      none;
    border:          1px solid transparent;
    border-radius:   8px;
    cursor:          pointer;
    color:           var(--color-text-secondary);
    touch-action:    manipulation;
    -webkit-user-select: none;
    user-select:     none;
}
.chat-conv-pane-btn:hover        { background: var(--color-hover); border-color: var(--color-divider); }
.chat-conv-pane-btn:focus-visible { outline: 2px solid var(--color-primary-light); outline-offset: 1px; }

/* The panes as the room allows them: those with a chat filled, where the
   button puts this one in green. */
.chat-pane-map { display: block; }
.chat-pane-map-slot {
    fill:         none;
    stroke:       currentColor;
    stroke-width: 1.2;
}
.chat-pane-map-slot--open   { fill: var(--color-primary-light); stroke: var(--color-primary-light); }
.chat-pane-map-slot--target { fill: var(--color-primary); stroke: var(--color-primary); }

.chat-conv-time {
    font-size: 0.72rem;
    color: var(--color-text-secondary);
}

.chat-unread-badge {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
}

.chat-conv-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

.chat-load-more {
    padding: 8px 12px;
    text-align: center;
}

.chat-load-more-btn {
    font-size: 0.78rem;
    padding: 5px 14px;
    background: none;
    border: 1px solid var(--color-divider);
    border-radius: 12px;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: background var(--transition), color var(--transition);
}

.chat-load-more-btn:hover     { background: var(--color-divider); }
.chat-load-more-btn:disabled  { opacity: 0.5; cursor: default; }

/* ── Conversation search bar ─────────────────────────────────────── */

/* The search row: THE SEARCH FIELD (shared.css). */


/* ── Message thread ──────────────────────────────────────────────── */

.chat-thread-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-divider);
    background: var(--color-surface);
    flex-shrink: 0;
}

.chat-thread-avatar {
    width:     30px;
    height:    30px;
    font-size: 0.85rem;
}

.chat-thread-title {
    flex:           1;
    min-width:      0;
    display:        flex;
    flex-direction: column;
}

.chat-thread-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-thread-sub {
    font-size: 0.74rem;
    color:     var(--color-text-secondary);
}

.chat-info-btn {
    position:      relative;
    background:    none;
    border:        none;
    cursor:        pointer;
    color:         var(--color-primary);
    min-width:     34px;
    min-height:    34px;
    border-radius: 6px;
    display:       inline-flex;
    align-items:   center;
    justify-content: center;
}
.chat-info-btn:hover { background: var(--color-hover); }
/* After the name: "i", then the buttons — the side pane's and "only this
   chat" (a Chat page pane's), close at the very end (the user, 2026-11-02). */
.chat-close-btn, .chat-pane-open-btn, .chat-only-btn { flex: none; }
/* A row's "⋯" (FBC.ui.rowMenu), at its end. */
.chat-conv-more-slot { flex: none; display: inline-flex; }

/* History requests waiting for this admin. */
.chat-info-badge {
    position:      absolute;
    top:           2px;
    right:         0;
    min-width:     16px;
    padding:       0 4px;
    border-radius: 8px;
    background:    var(--color-danger);
    color:         var(--color-text-on-primary);
    font-size:     0.66rem;
    font-weight:   700;
    line-height:   16px;
}

.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 10px 10px 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--color-bg);
}

.chat-thread-load-more {
    text-align: center;
    margin-bottom: 6px;
}

.chat-thread-load-more button {
    font-size: 0.78rem;
    padding: 4px 12px;
    background: none;
    border: 1px solid var(--color-divider);
    border-radius: 12px;
    cursor: pointer;
    color: var(--color-text-secondary);
}

.chat-thread-load-more button:hover { background: var(--color-divider); }

/* ── Message bubbles ─────────────────────────────────────────────── */

.chat-msg-group {
    display: flex;
    flex-direction: column;
}

.chat-msg-group--mine   { align-items: flex-end; }
.chat-msg-group--theirs { align-items: flex-start; }

.chat-message {
    max-width: 78%;
    padding: 7px 11px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}

.chat-message--mine {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
    border-bottom-right-radius: 4px;
}

.chat-message--theirs {
    background: var(--color-surface);
    color: var(--color-text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--color-divider);
}

.chat-message--system {
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.78rem;
    font-style: italic;
    text-align: center;
    align-self: center;
    padding: 2px 8px;
    max-width: 100%;
}

/* In a group, whose message it is — once per run of theirs. */
.chat-msg-sender {
    font-size:   0.72rem;
    font-weight: 600;
    color:       var(--color-secondary);
    margin:      4px 0 2px 4px;
}

.chat-msg-group--system { align-items: center; }

/* What was said before the user joined, and is not sent to them yet. */
.chat-history-earlier {
    align-self:     center;
    display:        flex;
    flex-direction: column;
    align-items:    center;
    gap:            6px;
    margin:         4px 0 10px;
    padding:        10px 14px;
    border:         1px dashed var(--color-divider);
    border-radius:  10px;
    text-align:     center;
    max-width:      90%;
}
.chat-history-title { font-size: 0.8rem; font-weight: 600; color: var(--color-text-secondary); }
.chat-history-note  { font-size: 0.78rem; color: var(--color-text-secondary); }
.chat-history-btns  { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

.chat-msg-time {
    font-size: 0.68rem;
    color: var(--color-text-secondary);
    margin-top: 2px;
    padding: 0 2px;
}

.chat-msg-group--mine .chat-msg-time { text-align: right; }

.chat-msg-status {
    font-size: 0.68rem;
    color: var(--color-text-secondary);
    margin-left: 4px;
}

/* ── Input area (wrap + row + emoji picker) ──────────────────────── */

.chat-input-wrap {
    position: relative;
    flex-shrink: 0;
}

/* Emoji picker — floats above the input row */
.chat-emoji-picker {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: 16px;
    padding: 8px 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.14);
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    max-width: 260px;
    z-index: 10;
}


.chat-emoji-item {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.6rem;
    line-height: 1;
    padding: 4px 3px;
    border-radius: 8px;
    transition: background 0.12s, transform 0.12s;
    /* keep emoji rendering crisp */
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.chat-emoji-item:hover {
    background: var(--color-bg);
    transform: scale(1.25);
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--color-divider);
    background: var(--color-surface);
}

/* Emoji toggle button */
.chat-emoji-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 6px 4px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    transition: color var(--transition), background var(--transition);
}

.chat-emoji-btn:hover {
    color: var(--color-primary);
    background: var(--color-bg);
}

.chat-input {
    flex: 1;
    border: 1px solid var(--color-divider);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.88rem;
    resize: none;
    outline: none;
    background: var(--color-bg);
    color: var(--color-text-primary);
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
}

.chat-input:focus { border-color: var(--color-primary-light); }

.chat-send-btn {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}

.chat-send-btn:hover   { background: var(--color-primary-dark); }
.chat-send-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Empty thread ────────────────────────────────────────────────── */

.chat-thread-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    padding: 24px;
    text-align: center;
}


/* ── MODE A — the Chat page: up to four panes (chat-page.js) ────── */

/* The main pane holds the panes, the whole of its height, from the top bar
   to the window's foot (the user, 2026-11-01): each conversation scrolls
   its messages inside its pane, its composer at its foot.  The panes
   share the main pane's whole width — one alone too, no band either side
   (the user, 2026-11-01). */
#chat-page .fbc-pane-main {
    display:        flex;
    flex-direction: column;
    overflow:       hidden;
}

#chat-page .fbc-pane-main-inner {
    display:        flex;
    flex-direction: column;
    flex:           1;
    min-height:     0;
    /* A column flex item with auto side margins is not stretched: without
       the width it would shrink to its content. */
    width:          100%;
    padding:        0;
}

/* The four places: 0 top-left, 1 top-right, 2 bottom-left, 3 bottom-right
   (data-slot); the grid as many columns and rows as are on show.  A line
   of the divider's colour between panes. */
.chat-panes {
    flex:                  1;
    min-height:            0;
    display:               grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:    minmax(0, 1fr);
    gap:                   1px;
    background:            var(--color-divider);
}
.chat-panes[data-cols="2"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.chat-panes[data-rows="2"] { grid-template-rows:    minmax(0, 1fr) minmax(0, 1fr); }
.chat-pane {
    position:       relative;
    display:        flex;
    flex-direction: column;
    min-width:      0;
    min-height:     0;
    overflow:       hidden;
    background:     var(--color-bg);
}
.chat-pane[data-slot="0"] { grid-area: 1 / 1; }
.chat-pane[data-slot="1"] { grid-area: 1 / 2; }
.chat-pane[data-slot="2"] { grid-area: 2 / 1; }
.chat-pane[data-slot="3"] { grid-area: 2 / 2; }
/* Alone in its row under two side by side (a pane removed): the row's width. */
.chat-panes .chat-pane.chat-pane--span { grid-column: 1 / -1; }
/* The focused pane — where a row pressed opens its chat — framed, where
   more than one shows.  Over its content, never taking a press. */
.chat-panes--many .chat-pane--focus::after {
    content:        '';
    position:       absolute;
    inset:          0;
    border:         2px solid var(--color-primary-light);
    pointer-events: none;
    z-index:        2;
}

/* An empty pane: room all round, THE RECENT LIST in it (chat-page.js). */
.chat-pane-recent {
    flex:       1;
    min-height: 0;
    overflow-y: auto;
    padding:    16px;
}

/* THE RECENT LIST: a search, a title with "Clear list", the chats as
   pick cards (.fbc-pick-card, shared.css) — unlike the list's rows (the
   user, 2026-11-01). */
.chat-recent {
    display:        flex;
    flex-direction: column;
    gap:            8px;
    min-height:     0;
}
/* The search — and, in an empty pane, its × (the pane removed) at its end. */
.chat-recent-top {
    display:     flex;
    align-items: center;
    gap:         8px;
}
/* .chat-recent-search: THE SEARCH FIELD (shared.css). */
.chat-recent-head {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    gap:             8px;
    min-height:      30px;
}
.chat-recent-title {
    font-size:   0.8rem;
    font-weight: 600;
    color:       var(--color-text-secondary);
}
.chat-recent-list {
    display:        flex;
    flex-direction: column;
    gap:            6px;
}
.chat-recent-face { width: 28px; height: 28px; font-size: 0.8rem; }
.chat-recent-face svg { width: 15px; height: 15px; }
.chat-recent-empty   { font-size: 0.8rem; color: var(--color-text-muted); padding: 4px 2px; }
/* ARRANGE's: the name alone, tighter. */
.chat-recent--compact { gap: 6px; }
.chat-recent--compact .chat-recent-list { gap: 4px; }
.chat-recent--compact .fbc-pick-card { padding: 3px 8px; border-radius: 8px; }
.chat-recent--compact .chat-recent-head { min-height: 26px; }

/* All / People / Groups, and Clear at its end (the Chat page's list). */
.chat-filter--clear {
    display:     flex;
    align-items: center;
    gap:         8px;
}
.chat-filter--clear .fbc-segchoice { flex: 1; width: auto; min-width: 0; }
.chat-panes-clear { flex: none; }

/* The pane button HELD: the places, laid out as they are. */
.chat-pane-pick { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.chat-pane-pick-title { font-size: 0.85rem; font-weight: 600; color: var(--color-text-primary); }
.chat-pane-pick-grid {
    display:               grid;
    grid-template-columns: 140px;
    grid-template-rows:    52px;
    gap:                   6px;
}
.chat-pane-pick-grid[data-cols="2"] { grid-template-columns: 140px 140px; }
.chat-pane-pick-grid[data-rows="2"] { grid-template-rows:    52px 52px; }
.chat-pane-pick-slot {
    min-width:     0;
    padding:       4px 8px;
    border:        1px solid var(--color-divider);
    border-radius: 8px;
    background:    var(--color-surface);
    color:         var(--color-text-primary);
    font-size:     0.82rem;
    font-weight:   600;
    cursor:        pointer;
    overflow:      hidden;
    text-overflow: ellipsis;
    white-space:   nowrap;
}
.chat-pane-pick-slot--free   { color: var(--color-text-muted); font-weight: 400; border-style: dashed; }
.chat-pane-pick-slot--target { border: 2px solid var(--color-primary); }
.chat-pane-pick-slot:hover   { background: var(--color-hover); }

/* ARRANGE (Clear held): the panes as they will be, each listing the chats
   to pick from; the "+" beside them smaller.  As tall from the start as
   four panes need (two rows of a search, a title and seven names), so it
   never grows nor scrolls as panes are added (the user, 2026-11-01). */
.chat-plan {
    display:               grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:    minmax(0, 1fr);
    gap:                   10px;
    height:                600px;
}
.chat-plan[data-cols="2"]             { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.chat-plan[data-rows="2"]             { grid-template-rows:    minmax(0, 1fr) minmax(0, 1fr); }
/* The "+" a good share of it, the pane beside it a little less (the user,
   2026-11-01: "the initial pane a bit smaller, the '+' panes larger"). */
.chat-plan[data-add="right"]          { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.chat-plan[data-add="below"],
.chat-plan[data-add="row"]            { grid-template-rows:    minmax(0, 2fr) minmax(0, 1fr); }
.chat-plan-pane {
    min-width:     0;
    min-height:    0;
    overflow-y:    auto;
    padding:       10px;
    border:        1px solid var(--color-divider);
    border-radius: 8px;
    background:    var(--color-bg);
}
/* Accept waits, unseen, for a second pane: its place kept, nothing moves. */
.chat-plan-accept--waiting { visibility: hidden; }
.chat-plan-add {
    display:         flex;
    align-items:     center;
    justify-content: center;
    border:          2px dashed var(--color-divider);
    border-radius:   8px;
    background:      none;
    color:           var(--color-primary);
    cursor:          pointer;
}
.chat-plan-add:hover { background: var(--color-hover); border-color: var(--color-primary-light); }
.chat-plan-add svg   { width: 34px; height: 34px; }
.chat-plan-add--right { grid-area: 1 / 2; }
.chat-plan-add--below { grid-area: 2 / 1; }
.chat-plan-add--row   { grid-area: 2 / 1 / 3 / 3; }


/* ── MODE B — Floating panel ─────────────────────────────────────── */
/* The chat where there are no panes (the landing page).  Opened from the
   top bar's chat button, so it hangs just below it. */

.chat-panel {
    position: fixed;
    top: calc(var(--top-bar-height) + 8px);
    /* Tuck against the shell's right edge, not the window's, so the panel
       does not float out in the empty side band on a wide screen.
       --fbc-band-w is defined in main.css. */
    right: calc(var(--fbc-band-w, 0px) + 12px);
    width: 340px;
    height: min(480px, calc(100vh - var(--top-bar-height) - 24px));
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    z-index: 91;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--color-divider);
}


/* On small screens, panel takes more space */
@media (max-width: 480px) {
    .chat-panel {
        right: 8px;
        left: 8px;
        width: auto;
        height: 70vh;
    }
}


/* ── MODE C — The right pane's chat view ─────────────────────────── */
/* #chat-col is mounted into a page layout's chat view container
   (pane-layout.js), which is what shows and hides it.  Parked in <body>
   between pages, where it must not show. */

.chat-col {
    display:        none;
    flex-direction: column;
    flex:           1;
    min-height:     0;
    overflow:       hidden;
}

.fbc-pane-right-view > .chat-col { display: flex; }


/* ── Key registration state overlay ─────────────────────────────── */

.chat-setup-overlay {
    position: absolute;
    inset: 0;
    background: rgba(250,246,240,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 5;
    padding: 24px;
    text-align: center;
}

.chat-setup-overlay p {
    color: var(--color-text-secondary);
    font-size: 0.88rem;
}

.chat-setup-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--color-divider);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: chat-spin 0.7s linear infinite;
}

@keyframes chat-spin { to { transform: rotate(360deg); } }


/* ── Groups: the new-group and group-info sheets (chat-groups.js) ── */
/* One rhythm for every block of a sheet (000 L13): the body is the flex
   parent of the sections, so its gap is what spaces them. */

.chat-group-sheet {
    display:        flex;
    flex-direction: column;
    gap:            18px;
}

.chat-group-section {
    display:        flex;
    flex-direction: column;
    gap:            8px;
}

/* Its title's look is .fbc-section-title's (components/shared.css). */
.chat-group-section-title { margin: 0; }

.chat-group-label {
    display:        flex;
    flex-direction: column;
    gap:            6px;
    font-size:      0.84rem;
    font-weight:    500;
    color:          var(--color-text);
}

.chat-group-name-input {
    width:         100%;
    min-height:    40px;
    padding:       8px 10px;
    border:        1px solid var(--color-divider);
    border-radius: 6px;
    font:          inherit;
    font-size:     0.92rem;
    background:    var(--color-input-bg);
    color:         var(--color-text);
}
.chat-group-name-input:focus { outline: none; border-color: var(--color-primary-light); }

.chat-group-hint {
    font-size: 0.82rem;
    color:     var(--color-text-secondary);
    margin:    0;
}

.chat-group-error {
    color:     var(--color-danger);
    font-size: 0.84rem;
}

.chat-group-loading {
    color:      var(--color-text-secondary);
    font-size:  0.86rem;
    text-align: center;
    padding:    24px 0;
}

.chat-group-chips,
.chat-group-add-row {
    display:     flex;
    flex-wrap:   wrap;
    align-items: center;
    gap:         6px;
}

/* ── A source: a tag or a journey feeding the group ── */
.chat-source-list {
    display:        flex;
    flex-direction: column;
    gap:            8px;
    align-items:    flex-start;
}

.chat-source-row {
    display:       flex;
    align-items:   center;
    flex-wrap:     wrap;
    gap:           8px 10px;
    width:         100%;
    padding:       8px 10px;
    border:        1px solid var(--color-divider);
    border-radius: 8px;
    background:    var(--color-surface);
}

.chat-source-chip { flex-shrink: 0; max-width: 100%; }
.chat-source-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; }
.chat-source-sub  { font-size: 0.82rem; color: var(--color-text); display: inline-flex; align-items: center; gap: 4px; }
.chat-source-text { flex: 1; min-width: 0; }
.chat-source-mode  { font-size: 0.82rem; color: var(--color-text); }
.chat-source-count { font-size: 0.76rem; color: var(--color-text-secondary); }

.chat-source-remove {
    background:    none;
    border:        none;
    cursor:        pointer;
    color:         var(--color-text-secondary);
    min-width:     32px;
    min-height:    32px;
    border-radius: 6px;
}
.chat-source-remove:hover { background: var(--color-hover); color: var(--color-danger); }

/* ── The group: its face, its members ── */
.chat-group-head {
    display:     flex;
    align-items: center;
    gap:         12px;
}
.chat-group-face { width: 52px; height: 52px; font-size: 1.2rem; }
.chat-group-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-group-name   { font-size: 1.05rem; font-weight: 600; color: var(--color-text); }
.chat-group-sub    { font-size: 0.8rem; color: var(--color-text-secondary); }
.chat-group-rename { display: flex; gap: 6px; align-items: center; }
.chat-group-picture-btns { display: flex; flex-wrap: wrap; gap: 6px; }

.chat-member-row {
    display:     flex;
    align-items: center;
    flex-wrap:   wrap;
    gap:         6px 10px;
    padding:     6px 0;
    border-bottom: 1px solid var(--color-divider);
}
.chat-member-face { width: 34px; height: 34px; font-size: 0.9rem; }
.chat-member-main { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 3px; }
.chat-member-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--color-text); }
.chat-member-how  { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.chat-member-individually { font-size: 0.76rem; color: var(--color-text-secondary); }
.chat-member-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.chat-member-badge {
    font-size:     0.68rem;
    font-weight:   600;
    padding:       1px 7px;
    border-radius: 10px;
    border:        1px solid var(--color-divider);
    color:         var(--color-text-secondary);
}
.chat-member-badge--admin { border-color: var(--color-primary); color: var(--color-primary); }

.chat-group-row {
    display:     flex;
    align-items: center;
    flex-wrap:   wrap;
    gap:         6px 8px;
}
.chat-group-row-text { flex: 1; min-width: 140px; font-size: 0.86rem; color: var(--color-text); }

.chat-history-controls { display: flex; flex-direction: column; gap: 8px; }
.chat-history-requests { font-size: 0.84rem; color: var(--color-text); display: inline-flex; align-items: center; gap: 6px; }

.chat-remove-leaving { margin: 0; padding-left: 20px; font-size: 0.86rem; color: var(--color-text); }
.chat-remove-keep    { display: flex; flex-direction: column; gap: 6px; }
.chat-remove-keep-row { font-size: 0.86rem; color: var(--color-text); display: inline-flex; align-items: center; gap: 6px; }
/* The groups shared with someone (the Blocked list's overlay). */
.chat-shared-list { display: flex; flex-direction: column; gap: 8px; }

.chat-group-leave { align-items: flex-start; }
.chat-group-leave-btn.fbc-btn--secondary {
    color:        var(--color-danger);
    border-color: var(--color-danger);
}

/* ── Links from a tag or a journey to its group chats (FBC.chat.linksFor) ── */
.chat-links {
    display:     flex;
    flex-wrap:   wrap;
    align-items: center;
    gap:         6px;
}
.chat-links-title { flex-basis: 100%; }   /* its look: .fbc-section-title (components/shared.css) */
.chat-link {
    /* A chip (main.css --fbc-chip-h): the whole of it pressed opens the
       chat's card (FBC.ui.cardChip, FBC.chat._card; its look when pressed
       .fbc-pressable's). */
    display:       inline-flex;
    align-items:   center;
    gap:           7px;
    min-height:    var(--fbc-chip-h);
    padding:       2px 12px 2px 3px;
    border:        1px solid var(--color-divider);
    border-radius: calc(var(--fbc-chip-h) / 2);
    background:    var(--color-surface);
    color:         var(--color-text);
    font:          inherit;
    max-width:     100%;
    min-width:     0;
}
.chat-link-face { flex: none; width: calc(var(--fbc-chip-h) - 8px); height: calc(var(--fbc-chip-h) - 8px); }
.chat-link-face svg { width: 13px; height: 13px; }
.chat-link-name {
    font-size:     0.9rem;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
}

/* A chat's card (FBC.chat.openCard): its face and name with its two ways
   to open it beside them (THE card frame, popover.css), then its last
   messages one line each — who, what (cut), when. */
.chat-card { min-width: 240px; max-width: 320px; }
.chat-card-ident { display: flex; align-items: center; gap: 10px; min-width: 0; }   /* its face and name: the card's head */
.chat-card-face  { flex: none; width: 34px; height: 34px; }
.chat-card-name  { font-weight: 600; overflow-wrap: anywhere; }
.chat-card-messages { display: flex; flex-direction: column; gap: 6px; }
.chat-card-message  { display: flex; align-items: baseline; gap: 6px; font-size: 0.86rem; min-width: 0; }
.chat-card-who   { flex: none; font-weight: 600; color: var(--color-text-secondary); }
.chat-card-who:empty { display: none; }
.chat-card-what  { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-card-when  { flex: none; font-size: 0.74rem; color: var(--color-text-muted); }
.chat-card-empty { font-size: 0.86rem; color: var(--color-text-muted); }
/* A chat's TILE (the Chat page's tiled view): the card, as wide as its tile;
   its picture carries the unread count, as a row's. */
.chat-card.chat-card--tile { min-width: 0; max-width: none; }
.chat-card-face-wrap { flex: none; }

/* A chat in a LARGE OVERLAY (FBC.chat.openInSheet): its thread fills the sheet. */
.fbc-sheet-body.chat-sheet-body { display: flex; flex-direction: column; padding: 0; overflow: hidden; }


/* ── The composer's "+" and its error ── */
.chat-tools-btn {
    background:    none;
    border:        1px solid var(--color-divider);
    border-radius: 50%;
    width:         32px;
    height:        32px;
    flex-shrink:   0;
    cursor:        pointer;
    color:         var(--color-primary);
    font-size:     1.15rem;
    line-height:   1;
    margin-bottom: 2px;
}
.chat-tools-btn:hover { background: var(--color-hover); }

.chat-composer-error {
    color:      var(--color-danger);
    font-size:  0.8rem;
    padding:    4px 12px 0;
    background: var(--color-surface);
}

/* The composer's "+" is a shared menu (FBC.ui.Popover.menu, popover.css). */

/* ── A place, a poll: cards, readable whoever sent them ── */
.chat-message--card {
    background:     var(--color-surface);
    color:          var(--color-text);
    border:         1px solid var(--color-divider);
    display:        flex;
    flex-direction: column;
    gap:            6px;
    min-width:      220px;
}
.chat-msg-group--mine .chat-message--card { border-color: var(--color-primary-light); }
.chat-card-head  { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.chat-card-head svg { color: var(--color-primary); flex-shrink: 0; }
.chat-card-title { min-width: 0; overflow-wrap: anywhere; }
.chat-card-sub   { font-size: 0.76rem; color: var(--color-text-secondary); }
.chat-location-map-btn { align-self: flex-start; }
.chat-location-map {
    height:        180px;
    border-radius: 8px;
    overflow:      hidden;
    border:        1px solid var(--color-divider);
}

/* A picture sent in a chat: its box held at its shape before it arrives;
   an outline where it could not be fetched (chat-picture--gone). */
.chat-message--picture { width: min(280px, 70vw); }
.chat-picture {
    width:         100%;
    border-radius: 8px;
    overflow:      hidden;
    background:    var(--color-divider);
}
.chat-picture img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-picture--gone { background: none; border: 1px dashed var(--color-divider); }
.chat-picture--gone img { visibility: hidden; }
.chat-picture-caption { overflow-wrap: anywhere; }
.chat-picture-preview {
    display:       block;
    max-width:     100%;
    max-height:    50vh;
    margin:        0 auto 12px;
    border-radius: 8px;
}

.chat-poll-opt {
    position:      relative;
    display:       flex;
    align-items:   center;
    gap:           8px;
    width:         100%;
    min-height:    36px;
    padding:       6px 10px;
    border:        1px solid var(--color-divider);
    border-radius: 8px;
    background:    var(--color-bg);
    cursor:        pointer;
    font:          inherit;
    font-size:     0.86rem;
    color:         var(--color-text);
    text-align:    left;
    overflow:      hidden;
}
.chat-poll-opt--mine { border-color: var(--color-primary); }
.chat-poll-bar {
    position:   absolute;
    inset:      0 auto 0 0;
    background: var(--color-selected);
    z-index:    0;
}
.chat-poll-label { position: relative; z-index: 1; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.chat-poll-count { position: relative; z-index: 1; font-weight: 600; color: var(--color-text-secondary); }
.chat-poll-opt--mine .chat-poll-count { color: var(--color-primary); }
.chat-poll-voters { font-size: 0.72rem; color: var(--color-text-secondary); padding: 0 4px; }

.chat-poll-options { display: flex; flex-direction: column; gap: 6px; }
.chat-poll-sheet .chat-poll-add { align-self: flex-start; }

/* ── Threads: a reply under its message ── */
.chat-reply-btn {
    background:  none;
    border:      none;
    padding:     0 0 0 8px;
    cursor:      pointer;
    font:        inherit;
    font-size:   0.7rem;
    color:       var(--color-primary);
}
.chat-reply-btn:hover { text-decoration: underline; }

.chat-thread-fold {
    display:        flex;
    flex-direction: column;
    gap:            4px;
    margin:         -2px 0 6px;
    padding-left:   14px;
    border-left:    2px solid var(--color-divider);
}
.chat-thread-fold--mine { align-self: flex-end; width: 78%; }
.chat-thread-fold--theirs { align-self: flex-start; width: 78%; }
.chat-thread-fold--unread { border-left-color: var(--color-primary); }
.chat-thread-toggle {
    align-self:  flex-start;
    background:  none;
    border:      none;
    padding:     2px 0;
    cursor:      pointer;
    font:        inherit;
    font-size:   0.76rem;
    font-weight: 600;
    color:       var(--color-primary);
}
.chat-thread-replies { display: flex; flex-direction: column; gap: 4px; }
.chat-thread-replies .chat-message { max-width: 100%; font-size: 0.84rem; }
.chat-thread-loading { font-size: 0.78rem; color: var(--color-text-secondary); }
.chat-thread-reply-row { display: flex; gap: 6px; align-items: flex-end; }
.chat-thread-input {
    flex:          1;
    border:        1px solid var(--color-divider);
    border-radius: 14px;
    padding:       6px 10px;
    font:          inherit;
    font-size:     0.84rem;
    resize:        none;
    background:    var(--color-surface);
    color:         var(--color-text);
}
.chat-thread-input:focus { outline: none; border-color: var(--color-primary-light); }

/* Jumped to from the notice: a moment's highlight. */
.chat-msg--flash .chat-message { box-shadow: 0 0 0 3px var(--color-selected); }

/* "2 threads have new replies" */
.chat-updated-btn {
    display:       block;
    width:         100%;
    border:        none;
    border-bottom: 1px solid var(--color-divider);
    background:    var(--color-selected);
    color:         var(--color-primary-dark);
    padding:       6px 12px;
    font:          inherit;
    font-size:     0.8rem;
    font-weight:   600;
    cursor:        pointer;
    text-align:    left;
}
.chat-updated-list { display: flex; flex-direction: column; gap: 2px; min-width: 240px; max-width: 360px; }
.chat-updated-item {
    display:       flex;
    gap:           10px;
    align-items:   center;
    background:    none;
    border:        none;
    border-radius: 6px;
    padding:       8px 10px;
    cursor:        pointer;
    font:          inherit;
    text-align:    left;
}
.chat-updated-item:hover { background: var(--color-hover); }
.chat-updated-root  { flex: 1; min-width: 0; font-size: 0.84rem; color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-updated-count { font-size: 0.74rem; font-weight: 600; color: var(--color-primary); white-space: nowrap; }
