/* Guild chat sheet (chat-ui.ts; docs/workorders/GUILDS_AND_CHAT.md §3). The Inbox / Tasks dialog frame: title + (?),
   tabs only when more than one channel is open, the message list (the sheet's only contained scroll region), the
   one-line composer and the shared Close. Long press opens the message menu inside the sheet. */
#modal:has(.chat-panel){width:min(410px,calc(100vw - 28px));padding:14px 14px 12px;background:linear-gradient(165deg,var(--cream-200),var(--row-inset))}
#modal:has(.chat-panel)>button.secondary{width:100%;min-height:var(--tier-full-h);margin:10px 0 0;padding:8px 10px;font:var(--tier-full-fs)/1.1 Lucky;flex:none}
#modal:has(.chat-panel)>button.secondary:before{inset:0}
.chat-panel{position:relative;display:flex;flex-direction:column;gap:8px;min-height:0;flex:0 1 auto}
.chat-header{display:grid;grid-template-columns:var(--tier-compact) minmax(0,1fr) var(--tier-compact);align-items:center}
.chat-header h1{grid-column:2;margin:0;text-align:center;font:28px/1.1 Lucky;overflow-wrap:anywhere}
.chat-header .help-button{grid-column:3}
.chat-tabs{display:flex}
.chat-tabs>button{flex:1 1 0;min-width:0;white-space:nowrap}
.chat-main{display:flex;flex-direction:column;gap:8px;min-height:0;flex:0 1 auto}
.chat-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
/* The list: one inset paper box, rows without their own frame; bubbles carry the only border inside it. */
/* A fixed-height box: the list fills it; the New messages jump takes its own slot under the list (the list gives up
   that height), so it never covers a row and the composer never moves. */
/* v2 (owner 2026-11-21): a tall sheet; the list takes the safe viewport minus the fixed parts (title, composer, Close and
   the dialog's own margins), never less than 200px, so the dialog stays inside the safe area (Inbox rule AC90). */
.chat-scroll{position:relative;display:flex;flex-direction:column;gap:6px;box-sizing:border-box;height:calc(100dvh - var(--safe-top,0px) - var(--safe-bottom,0px) - var(--chat-fixed,250px));min-height:200px}
.chat-list{display:flex;flex-direction:column;gap:10px;box-sizing:border-box;flex:1 1 auto;min-height:0;margin:0;padding:8px 8px 10px;list-style:none;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;touch-action:pan-y;border-radius:14px;background:var(--paper);box-shadow:inset 0 2px 0 #3a2a1a22}
:root:not([data-input-modality=keyboard]) .chat-list:focus{outline:none}
:root[data-input-modality=keyboard] .chat-list:focus-visible{outline:2px solid #b67939;outline-offset:2px}
.chat-row{display:grid;grid-template-columns:42px minmax(0,1fr);align-items:start;gap:0 8px;flex:none;min-width:0}
.chat-row.is-own{grid-template-columns:minmax(0,1fr) 42px}
.chat-row.is-own>.chat-avatar{grid-column:2;grid-row:1}
.chat-row.is-own>.chat-body{grid-column:1;grid-row:1;justify-items:end}
.chat-avatar{display:block;width:42px;height:42px;box-sizing:border-box;border:2px solid var(--vs-ink);border-radius:12px;object-fit:cover;background:linear-gradient(#ffe7a6,#f3b54a);box-shadow:0 2px 0 #00000033}
.chat-body{display:grid;gap:2px;min-width:0}
.chat-head{display:flex;align-items:center;gap:4px;min-width:0;max-width:100%;min-height:22px}
/* min-height: the crown (22px) made rows with a Leader or Vice 4px taller above the bubble than plain rows. */
.chat-row.is-own .chat-head{flex-direction:row-reverse}
.chat-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:14px/1.25 Lucky,system-ui,sans-serif;color:#5a3f26}
.chat-role{display:inline-grid;place-items:center;flex:none;width:22px;height:22px}
.chat-role>img{width:22px;height:22px;object-fit:contain}
.chat-head time{flex:none;margin-inline-start:auto;padding-inline-start:6px;font:600 11px/1.2 system-ui;color:#8a7454}
.chat-row.is-own .chat-head time{margin-inline-start:0;margin-inline-end:auto;padding-inline:0 6px}
/* A speech bubble whose square corner points at the speaker's avatar; own lines are green on the right. */
.chat-bubble{position:relative;display:flex;align-items:flex-start;gap:6px;justify-self:start;max-width:100%;box-sizing:border-box;margin:0;padding:7px 12px;border:2px solid #b8955c;border-radius:4px 16px 16px 16px;background:linear-gradient(#fffdf6,var(--cream-50));box-shadow:0 2px 0 #b8955c55;color:#2f2418;font:600 15px/1.35 system-ui;overflow-wrap:anywhere;-webkit-touch-callout:none;cursor:default}
.chat-row.is-own .chat-bubble{justify-self:end;border-color:#5f9b3c;border-radius:16px 4px 16px 16px;background:linear-gradient(#e6f8cf,#d2f0b1);box-shadow:0 2px 0 #5f9b3c55}
.chat-bubble[role=button]{cursor:pointer}
:root[data-input-modality=keyboard] .chat-bubble:focus-visible{outline:2px solid #b67939;outline-offset:2px}
.chat-text{min-width:0;white-space:pre-wrap}
.chat-translated{display:grid;place-items:center;flex:none;width:30px;height:30px;margin:-5px -8px -5px 0;padding:0;border:0;border-radius:50%;background:none;box-shadow:none}
.chat-translated>img{width:26px;height:26px;object-fit:contain}
/* Showing the original: the mark rests greyed, a tap brings the translation back. */
.chat-translated.is-original>img{filter:grayscale(1);opacity:.6}
.chat-translated:before{content:none}
/* The 30px mark sits in a 46px target. */
.chat-translated{position:relative}
.chat-translated::after{content:'';position:absolute;inset:-8px;border:0;background:none}
.chat-row.is-blocked{grid-template-columns:minmax(0,1fr)}
.chat-blocked{justify-self:start;border-style:dashed;border-color:#b9a684;background:transparent;color:#8a7454;font:italic 600 13px/1.3 system-ui}
.chat-row.is-system{grid-template-columns:minmax(0,1fr)}
.chat-system{display:flex;flex-wrap:wrap;justify-content:center;align-items:baseline;gap:2px 8px;justify-self:center;margin:2px 0;padding:5px 14px;border:2px solid #d2b98c;border-radius:999px;background:linear-gradient(#fff3d6,var(--row-inset));color:#5d4a2f;font:700 13px/1.3 system-ui;text-align:center}
.chat-system time{font:600 11px/1.2 system-ui;color:#8a7454}
.chat-empty{margin:auto;font:600 14px/1.4 system-ui;color:#8a7454;text-align:center}
/* Sized to its label, never full width. */
#modal .chat-scroll>.chat-jump{flex:none;align-self:center;display:inline-flex;align-items:center;gap:4px;width:auto;margin:0;white-space:nowrap}
#modal .chat-scroll>.chat-jump[hidden]{display:none}
.chat-jump .ui-icon{width:18px;height:18px}
.chat-note{margin:0;font:700 13px/1.3 system-ui;color:#3f6f2a;text-align:center}
.chat-note[hidden]{display:none}
/* Composer: the field and Send share the design system's dense tier (52px), one size in the row. */
.chat-composer{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:8px}
.chat-field{position:relative;display:block;min-width:0;margin:0}
/* The generic `#modal label` rule (story-ui.css, margin:12px 0) outranked margin:0 above and made the composer 76px
   tall: 18px over the field and 28px under it (measured with layout guides, owner 2026-11-21). */
#modal .chat-composer .chat-field{margin:0}
.chat-field>input{display:block;width:100%;box-sizing:border-box;height:var(--tier-dense-h);margin:0;padding:0 14px;border:2px solid #a88c65;border-radius:16px;background:var(--paper);box-shadow:inset 0 2px 0 #3a2a1a1f;color:var(--ink-plum);font:600 17px/1.2 system-ui;-webkit-user-select:text;user-select:text}
.chat-field>input:focus{outline:3px solid #e2a13f;outline-offset:0}
.chat-field>input:disabled{opacity:.6}
.chat-field:has(.chat-count:not([hidden]))>input{padding-inline-end:62px}
.chat-count{position:absolute;right:10px;top:50%;transform:translateY(-50%);font:700 12px/1 system-ui;color:#8a7454;pointer-events:none}
.chat-count.is-full{color:#b4442e}
.chat-count[hidden]{display:none}
#modal .chat-composer .chat-send{display:grid;place-items:center;width:64px;height:var(--tier-dense-h);min-height:var(--tier-dense-h);margin:0;padding:0;border-radius:16px;white-space:nowrap}
#modal .chat-send .button-label{display:grid;place-items:center}
.chat-send-icon{display:block;width:34px;height:34px;object-fit:contain;filter:drop-shadow(0 2px 0 #00000033)}
/* The painted face fills the 52px box, so it matches the field's height (one control size in the row). */
#modal .chat-composer .chat-send:before{inset:0}
.chat-field-error{margin:0;font:700 13px/1.3 system-ui;color:#b4442e}
.chat-field-error[hidden]{display:none}
.chat-readonly{margin:0;padding:10px 12px;border-radius:10px;background:var(--row-inset);font:700 13px/1.3 system-ui;color:#5d4a2f;text-align:center}
.chat-state{display:grid;justify-items:center;align-content:center;gap:10px;min-height:160px;margin:0;font:700 15px/1.4 system-ui;color:#5d4a2f;text-align:center}
.chat-state p{margin:0}
/* Rules once before first use (acceptance recorded by the server); the same lines live behind (?). */
.chat-rules{display:grid;gap:10px;padding:12px 14px;border-radius:14px;background:var(--paper)}
.chat-rules h2{margin:0;text-align:center;font:22px/1.15 Lucky;color:#3b3024}
.chat-rules ul{display:grid;gap:6px;margin:0;padding:0 0 0 18px;font:600 14px/1.4 system-ui;color:#3b3024}
#modal .chat-rules .chat-accept{width:100%;min-height:var(--tier-full-h);margin:0}
/* Message menu: a sheet inside the panel over a scrim; one Cancel, no second close. */
.chat-panel.has-menu>:is(.chat-header,.chat-tabs,.chat-main){pointer-events:none}
/* While the menu is up its Cancel is the only exit in the sheet (the backdrop still closes the dialog). */
#modal:has(.chat-panel.has-menu)>button.secondary{visibility:hidden}
.chat-menu-scrim{position:absolute;inset:-14px -14px -12px;z-index:3;border-radius:inherit;background:#17141e66}
.chat-menu{position:absolute;left:0;right:0;bottom:0;z-index:4;display:grid;gap:8px;padding:12px;border-radius:16px;background:var(--cream-200);box-shadow:0 -2px 0 #fff inset,0 6px 18px #17141e66}
.chat-menu-title{font:20px/1.15 Lucky;color:#3b3024;text-align:center}
#modal .chat-menu .chat-menu-item{width:100%;min-height:var(--tier-compact);margin:0}
.chat-menu-note{margin:0;font:700 13px/1.3 system-ui;color:#8a7454;text-align:center}
@media (max-height:700px){:root{--chat-fixed:234px}.chat-header h1{font-size:24px}}
