/* chat.css, owner: track D2. Holds: Table Talk (the log, the host's switch, the chips, the composer), the message menu, and the speech bubbles.
   Load order 10 of 15: base, primitives, frame, home, room, friends, center, table, rails, chat, coach, meld, peek, results, dialogs.
   The sheet itself (a drawer, or a bottom sheet under 600) is in rails.css; docked in the right rail the same markup is `.chat` with no dialog role (render/chat.js buildSheet). */

#chat-slot { position: fixed; right: 0; bottom: 0; left: 0; z-index: var(--z-chat); height: 0; }

/* The docked panel (7.7): header, log, chips, composer, in the room the Coach card leaves. */
.chat.is-docked {
  display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; overflow: hidden; border: 1px solid var(--hair); border-radius: var(--r-xl);
  background: var(--panel);
}
.chat.is-docked .sheet-head {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: var(--sp-2); padding-block: var(--sp-1);
}
.chat.is-docked .sheet-title { grid-column: 1; white-space: nowrap; }
.chat.is-docked .sheet-head-extra { grid-column: 2; min-width: 0; justify-content: flex-end; }
.chat.is-docked .sheet-head-extra .chat-caption { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat.is-docked .sheet-hide { grid-column: 3; width: var(--hit-sm); height: var(--hit-sm); }
@media (any-pointer: coarse) { .chat.is-docked .sheet-hide { width: var(--hit); height: var(--hit); } }
.chat.is-docked .sheet-grip { display: none; }
@container rail-r (max-width: 19rem) {   /* 1440 to about 1520 wide: the caption takes a line under the title instead of an ellipsis (review R9) */
  .chat.is-docked .sheet-head { grid-template-columns: minmax(0, 1fr) auto; row-gap: 0; }
  .chat.is-docked .sheet-title { grid-column: 1; grid-row: 1; }
  .chat.is-docked .sheet-head-extra { grid-column: 1; grid-row: 2; justify-content: flex-start; }
  .chat.is-docked .sheet-hide { grid-column: 2; grid-row: 1 / span 2; }
}
.chat.is-docked .sheet-title { font: var(--t-eyebrow); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.chat-caption { color: var(--text-dim); font: var(--t-caption); font-size: max(0.75rem, 12px); }
.sheet-chat .sheet-head-extra { margin-right: var(--sp-1); }

/* The host's switch (and the guest's note) */
.chat-host-control { flex: none; padding: var(--sp-2) var(--sp-3) 0; }
.chat-host-control[hidden], .chat-switch[hidden], .chat-guest-disabled-note[hidden], .chat-quick[hidden], .chat-chip[hidden] { display: none; }
.host-switch {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); width: 100%; min-height: var(--hit); padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--control-line); border-radius: var(--r-lg); background: var(--white-04); color: var(--text); text-align: left; cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .host-switch:hover { background: var(--wash-hover); } }
.host-switch.is-on { border-color: var(--gold); background: var(--gold-wash); }
.chat-switch-info { display: flex; flex: 1; flex-direction: column; gap: 0.125rem; }
.chat-switch-label { font: var(--t-label); font-size: max(0.88rem, 12px); }
.chat-switch-caption { color: var(--text-dim); font: var(--t-caption); }
.chat-switch-toggle {
  position: relative; flex: none; width: 2.75rem; height: 1.625rem; border: 1px solid var(--control-line); border-radius: var(--r-lg);
  background: var(--switch-off); transition: background var(--dur);
}
.chat-switch-thumb {
  position: absolute; top: 0.1875rem; left: 0.1875rem; width: 1.25rem; height: 1.25rem; border-radius: 50%; background: var(--white);
  transition: translate var(--dur);
}
.host-switch.is-on .chat-switch-toggle { border-color: var(--gold); background: var(--gold); }
.host-switch.is-on .chat-switch-thumb { translate: 1.125rem 0; }
.chat-guest-disabled-note {
  display: flex; align-items: center; gap: var(--sp-2); flex: none; padding: var(--sp-2) var(--sp-3) 0; color: var(--text-dim); font: var(--t-caption);
}
.chat-guest-disabled-icon { flex: none; font-size: max(0.9rem, 12px); }
.chat-muted-bar {
  display: flex; flex: none; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--hair);
  background: var(--track-dark); color: var(--text-dim); font: var(--t-caption);
}
.chat-unmute-chip {
  min-height: var(--hit-sm); padding: 0 var(--sp-2); border: 1px solid var(--line); border-radius: var(--r-full); background: var(--white-04);
  color: var(--text); font: var(--t-caption); cursor: pointer;
}

/* The log, bottom-anchored: a fresh table shows one system line at the foot, and the space above it is the log's own room (10) */
.chat-list {
  display: flex; flex: 1; flex-direction: column; gap: var(--sp-2); min-height: 6rem; padding: var(--sp-3); overflow-y: auto; overscroll-behavior: contain;
}
.chat-list > :first-child { margin-top: auto; }
.chat-empty { margin: 0; color: var(--text-dim); font: var(--t-small); }
.chat-msg {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 0.125rem; align-self: flex-start; max-width: 88%;
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-lg) var(--r-lg) var(--r-lg) var(--r-xs); background: var(--wash-hover); font: var(--t-small);
  overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
.chat-msg.is-mine { align-self: flex-end; border-radius: var(--r-lg) var(--r-lg) var(--r-xs) var(--r-lg); background: var(--gold-wash); }
.chat-msg-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); width: 100%; }
.chat-name { color: var(--gold); font: var(--t-eyebrow); }
.chat-msg.is-mine .chat-name { color: var(--gold-strong); }
.chat-text { color: var(--text); }
.chat-msg-menu-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--hit-sm); height: var(--hit-sm); margin-block: calc(var(--sp-2) * -1);
  margin-right: calc(var(--sp-2) * -1); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-dim); font-size: max(0.85rem, 12px);
  font-weight: 700; opacity: 0; cursor: pointer;
}
.chat-msg:hover .chat-msg-menu-btn, .chat-msg-menu-btn:focus-visible { opacity: 1; }
@media (any-pointer: coarse) { .chat-msg-menu-btn { width: var(--hit); height: var(--hit); opacity: 1; } }

/* The message menu (Report, Mute) */
.chat-menu-backdrop {
  position: fixed; inset: 0; z-index: var(--z-dialog); display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
  background: var(--scrim);
}
.chat-menu {
  display: flex; flex-direction: column; width: min(17.5rem, 85vw); overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--panel); box-shadow: var(--e-2);
}
.chat-menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: var(--hit); padding: var(--sp-3) var(--sp-4); border: 0;
  border-bottom: 1px solid var(--hair); background: transparent; color: var(--text); font: var(--t-small); text-align: left; cursor: pointer;
}
.chat-menu-item:last-child { border-bottom: 0; }
.chat-menu-item:hover, .chat-menu-item:focus-visible { background: var(--wash-hover); }
.chat-menu-item.is-destructive { color: var(--bad); }
.chat-menu-item.chat-menu-cancel { justify-content: center; color: var(--text-dim); }
.chat-menu-icon { font-size: max(1.1rem, 12px); }

/* The four signals and the quick lines, then the composer (7.7: 36 tall with a mouse, 44 with a touch; the apostrophe in "I'm stuck with it!" stays
   straight) */
/* three rows high in the docked panel, the drawer, and the sheet alike, so the four real signals always show whole (review R11, round 2 M5); the friendly
   lines after them scroll */
.chat-quick {
  display: flex; flex: none; flex-wrap: wrap; align-content: flex-start; gap: var(--sp-2); max-height: calc(3 * var(--hit-sm) + var(--sp-2) * 4);
  padding: var(--sp-2) var(--sp-3) 0; overflow: hidden auto; scrollbar-width: thin;
}
@media (any-pointer: coarse) { .chat-quick { max-height: calc(3 * var(--hit) + var(--sp-2) * 4); } }
.chat-chip {
  flex: none; min-height: var(--hit-sm); padding: 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-full); background: var(--white-04);
  color: var(--text); font: var(--t-caption); white-space: nowrap; cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .chat-chip:hover { background: var(--wash-hover); } }
@media (any-pointer: coarse) { .chat-chip { min-height: var(--hit); } }
.chat-form { display: flex; flex: none; align-items: stretch; gap: var(--sp-2); padding: var(--sp-3); }
/* 16 px keeps iOS Safari from zooming the page */
.chat-input {
  flex: 1; min-width: 0; min-height: var(--field-h); padding: 0 var(--sp-3); border: 1px solid var(--control-line); border-radius: var(--r-lg);
  background: var(--track-dark); color: var(--text); font-size: max(1rem, 12px);
}
.chat-input::placeholder { color: var(--text-dim); opacity: 1; }
.chat-input:disabled { opacity: 0.6; }
.chat-input:focus-visible { border-color: var(--gold-strong); outline-offset: 1px; }
.chat-note { flex: none; margin: calc(var(--sp-2) * -1) var(--sp-3) var(--sp-3); color: var(--text-dim); font: var(--t-caption); }
.chat-note[hidden] { display: none; }
.chat-note.is-error { color: var(--bad); }
/* 44 on the scale of AC-13; it stretches to the 48 of the field beside it */
.chat-send.btn {
  flex: none; width: auto; min-height: var(--hit); padding: 0 var(--sp-4);
}

/* Speech bubbles beside a seat (render/chat.js showSeatBubble; public/bubble-layout.js decides the slot) */
#bubble-layer { position: fixed; inset: 0; pointer-events: none; }
.seat-bubble {
  position: fixed; max-width: min(12.5rem, 55vw); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-lg); background: var(--bubble);
  box-shadow: var(--e-1); color: var(--paper-ink); font-size: max(0.8rem, 12px); font-weight: 600; line-height: 1.3; animation: bubble-in 0.18s ease-out;
  transition: opacity 0.4s;
}
.seat-bubble.in-slot {
  box-sizing: border-box; max-width: none; padding: var(--sp-1) var(--sp-2); border-radius: var(--r-md); font-size: max(0.78rem, 12px); line-height: 1.25;
  --tail: 50%;
}
.seat-bubble-text { display: block; overflow-wrap: anywhere; }
.seat-bubble.in-slot::after { content: ""; position: absolute; width: 8px; height: 8px; background: inherit; rotate: 45deg; }
.seat-bubble[data-side="below"]::after { top: -0.3em; left: calc(var(--tail) - 0.3em); }
.seat-bubble[data-side="above"]::after { bottom: -0.3em; left: calc(var(--tail) - 0.3em); }
.seat-bubble[data-side="right"]::after { top: calc(var(--tail) - 0.3em); left: -0.3em; }
.seat-bubble[data-side="left"]::after { top: calc(var(--tail) - 0.3em); right: -0.3em; }
/* No free slot: a speech mark on the plate's corner (the chat has the words); several lines in a row show their count */
.seat-bubble.is-tucked { width: 22px; height: 22px; padding: 0; border-radius: 50%; font-size: max(0.75rem, 12px); line-height: 22px; text-align: center; }
.seat-bubble.is-tucked::after { content: none; }
.seat-bubble.is-tucked .seat-bubble-text { display: none; }
.seat-bubble.is-tucked::before { content: "\1F4AC"; }
.seat-bubble.is-tucked[data-count]::after {
  content: attr(data-count); position: absolute; top: -0.4em; right: -0.5em; width: auto; min-width: 15px; height: 15px; padding: 0 0.2em; border: 0;
  border-radius: var(--r-md); background: var(--gold); color: var(--ink-0); font-size: max(0.75rem, 12px); font-weight: 700; line-height: 15px; rotate: none;
  text-align: center;
}
.seat-bubble.is-leaving { opacity: 0; }
@keyframes bubble-in { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 600px) { .seat-bubble.in-slot { font-size: max(0.92rem, 12px); } }
@media (max-height: 500px) and (orientation: landscape) { .seat-bubble.in-slot { font-size: max(0.78rem, 12px); } }   /* a phone on its side keeps the smaller line (its bubbles are placed by the pinned geometry) */
@media (prefers-reduced-motion: reduce) { .seat-bubble { animation: none; } .chat-switch-toggle, .chat-switch-thumb { transition: none; } }
