/* The class chat (chat.js). Wide screens: a «چت» tab beside the people in the side panel. Narrow screens: a «چت»
   button (the student's beside the big hand button, the teacher's in the bottom bar) and a sheet over the stage
   that ends at the bottom bar, so the hand button stays in sight; on a phone on its side the sheet takes the stage's
   half. Messages are plain text, each in its own direction. The teacher's messages carry «معلم» and a quiet
   turquoise ground.
   Inside: tabs «همه»، «سؤال‌ها»، «خصوصی» (and the teacher's «جواب‌ها»), the teacher's mode control and its menu,
   the teacher's alert lines («صدا نمیاد», the slow-mode offer), questions with their upvotes, folded «سلام» lines,
   the reply quote, the reveal card. Colour only for meaning: the hand amber for questions waiting, the speak green
   for «جواب داده شد» and a correct answer, the warn orange for a report. */

/* Read out, not shown. */
.chat-sr, .room[data-chat-wide="1"] .chat-head h2 {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---------- the side panel's tabs (wide): «شرکت‌کننده‌ها» and «چت» in the panel's head ---------- */
.chat-tabs { display: none; }
.room[data-chat-wide="1"] .chat-tabs { display: flex; flex: 1 1 auto; gap: 2px; align-self: stretch; }
.chat-tab {
  appearance: none; flex: 1 1 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 4px 8px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: none; color: var(--muted);
  font-size: var(--fs-sm); font-weight: var(--fw-b); cursor: pointer; touch-action: manipulation;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.chat-tab .ic { width: 20px; height: 20px; }
.chat-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
@media (hover: hover) { .chat-tab:hover { background: var(--hover); color: var(--ink); } }
.chat-tab .count.chat-unread { background: var(--accent); color: var(--on-accent); }
.room-side:not([data-tab="chat"]) > .chat { display: none; }
.room-side > .chat { flex: 1 1 auto; min-height: 0; }

/* ---------- the view ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
/* Only the list gives way when the panel is short; the head, tabs, alerts and composer keep their size. */
.chat > * { flex-shrink: 0; }
.chat > .chat-scroll { flex-shrink: 1; }
.chat-head { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin-bottom: 4px; }
.chat-head h2 { flex: 1; display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-md); font-weight: var(--fw-x); }
.chat-head h2 .ic { width: 20px; height: 20px; color: var(--accent); }
.chat-head .chat-modebtn { margin-inline-start: auto; }
.room[data-chat-wide="1"] .chat-head { min-height: 0; margin: 0; justify-content: flex-end; }
.room[data-chat-wide="1"] .chat-x { display: none; }
.chat-x { color: var(--muted); }
.chat-x .ic { width: 22px; height: 22px; }

.chat-state, .chat-note {
  margin: 0 0 8px; padding: 8px 12px;
  border-radius: var(--r);
  background: var(--hand-soft); color: var(--hand-ink);
  font-size: var(--fs-s); font-weight: var(--fw-b); line-height: 1.6;
}
.chat-note { margin: 8px 0 0; }
.chat-muted { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 8px; color: var(--muted); font-size: var(--fs-meta); }
.chat-muted .btn { gap: 4px; padding-inline: 10px; }
.chat-muted .ic { width: 16px; height: 16px; }

.chat-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
}
.chat-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; border-radius: var(--r); }
.chat-list, .chat-qs, .chat-ans, .chat-threads {
  list-style: none; margin: 0; padding: 2px 2px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-empty { margin: 12px 0; padding-inline: 16px; color: var(--muted); font-size: var(--fs-s); line-height: 1.7; text-align: center; }
.chat-empty::before {
  content: ""; display: block; width: 24px; height: 24px; margin: 0 auto 8px; opacity: .7;
  background: currentColor; -webkit-mask: var(--ic-chat) center / contain no-repeat; mask: var(--ic-chat) center / contain no-repeat;
}
/* No messages yet: the line sits in the middle of the box, not on the composer. */
.chat-list:empty, .chat-qs:empty, .chat-ans:empty, .chat-threads:empty { padding: 0; }
.chat-scroll > .chat-empty { margin-block: auto; padding-block: 12px; }

/* One message. */
.cm { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0 4px; padding: 6px 10px; border-radius: var(--r); }
/* Only a row that is new comes in with the kit's motion (chat.js marks it); a redraw never flickers. */
.chat .is-new { animation: kit-fade var(--t-med) var(--ease); }
.cm:not(.grouped) { margin-top: 6px; }
.cm:first-child { margin-top: 0; }
.cm.grouped { padding-top: 0; }
.cm-body { flex: 1 1 0; min-width: 0; }
.cm-head { display: flex; align-items: baseline; gap: 6px; min-width: 0; font-size: var(--fs-s); line-height: 1.6; }
.cm-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--fw-b); color: var(--ink); }
.cm-role { flex: none; }
.cm-time { flex: none; margin-inline-start: auto; color: var(--muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.cm-text {
  margin: 0; font-size: var(--fs-body); line-height: 1.75;
  white-space: pre-wrap; overflow-wrap: anywhere; text-align: start;
}
.cm[data-role="teacher"] { background: var(--accent-soft); }
.cm[data-role="teacher"] .cm-name { color: var(--accent-ink); }
.cm[data-role="teacher"] .cm-role { background: var(--surface); color: var(--accent-ink); font-weight: var(--fw-b); }
.cm[data-role="teacher"] + .cm[data-role="teacher"].grouped { margin-top: -2px; border-top-left-radius: 4px; border-top-right-radius: 4px; }
.cm[data-mine="1"] .cm-name { color: var(--muted); }
.cm[data-pending="1"] { opacity: .6; }
/* The teacher's actions on a message: «جواب» (reply with a quote), other modules' items (the pin), «پاک کردن». */
.cm-acts { flex: none; align-self: flex-start; display: flex; align-items: center; gap: 0; margin-top: -4px; margin-inline-end: -6px; }
.cm-acts .btn.tiny { color: var(--icon-quiet); padding: 0; }
.cm-acts .ic { width: 18px; height: 18px; }
@media (hover: hover) { .cm-del:hover { color: var(--danger-ink); } .cm-reply:hover { color: var(--accent-ink); } }
/* With a mouse, the actions show on the message under it (or on focus); a touch screen always shows them. */
@media (hover: hover) and (pointer: fine) {
  .cm-acts { opacity: 0; transition: opacity var(--t-fast) var(--ease); }
  .cm:hover .cm-acts, .cm:focus-within .cm-acts { opacity: 1; }
}
.cm-ask {
  flex: 1 1 100%;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 6px 0 2px; font-size: var(--fs-meta); font-weight: 700;
}
.cm-ask span { margin-inline-end: auto; }

/* The composer. */
.chat-compose { position: relative; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-form { display: flex; align-items: flex-end; gap: 8px; margin: 0; }
.chat-form[hidden] { display: none; }
.chat-input {
  flex: 1 1 auto; min-width: 0;
  min-height: 48px; max-height: 132px; margin: 0;
  padding: 11px 12px; resize: none;
  font-size: var(--fs-body); line-height: 1.6; /* 16px: iPhone never zooms into the box */
  overflow-y: auto;
}
.chat-send { flex: none; width: 48px; min-width: 48px; height: 48px; padding: 0; border-radius: var(--r-ctl); }
.chat-send .ic { width: 22px; height: 22px; }
.chat-count { position: absolute; top: -14px; inset-inline-end: 4px; padding: 0 6px; background: var(--surface); color: var(--muted); font-size: var(--fs-badge); }
.chat-err { margin: 6px 0 0; color: var(--danger-ink); font-size: var(--fs-meta); font-weight: 700; }
.chat-err:empty { display: none; }

/* ---------- «چت» in the room's bottom bar is a .cb (style.css); its unread count ---------- */
.chat-slot:empty { display: none; }

/* ---------- narrow: the sheet ---------- */
.chat-sheet {
  position: fixed; z-index: 14;
  inset-inline: 0; margin-inline: auto;
  width: 100%; max-width: 600px;
  top: var(--chat-top, max(calc(var(--rbar-h) + 8px), 26dvh));
  bottom: var(--chat-kb, calc(var(--cbar-h, 68px) + env(safe-area-inset-bottom)));
  display: flex; flex-direction: column;
  padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: var(--surface-raised); color: var(--ink);
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: var(--shadow-3);
  animation: kit-fade var(--t-med) var(--ease); /* a fade only: the sheet never dips over the hand button */
}
.chat-sheet[hidden] { display: none; }
/* A phone's sheet (sheet.js): at peek only the last lines and the box (A2 S5); the header and tabs from half up. */
.chat-sheet.lay-sheet { padding-top: 0; }
.chat-sheet[data-snap="peek"] :is(.chat-head, .chat-subs, .chat-modemenu) { display: none !important; }
.chat-sheet[data-snap="peek"] .chat-empty::before { display: none; }
.chat-sheet:focus { outline: none; }
.chat-sheet:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
/* The keyboard is up: the sheet fills what is left above it. */
.room[data-kb="1"] .chat-sheet { border-radius: 16px; border-bottom: 1px solid var(--line); }
/* A phone on its side: the sheet takes the stage's half; the floor and the hand button stay beside it. */
@media (max-width: 959px) and (max-height: 540px) and (orientation: landscape) {
  .chat-sheet {
    top: var(--chat-top, 8px);
    bottom: var(--chat-kb, calc(var(--cbar-h, 56px) + 8px));
    inset-inline-start: max(8px, env(safe-area-inset-right)); inset-inline-end: auto;
    width: calc(50% - 16px); max-width: none; margin: 0;
    border-radius: 16px; border-bottom: 1px solid var(--line);
  }
}

/* ---------- a teacher's message while the chat is out of sight (students) ----------
   Just above the bottom bar, by the «چت» button that opens it: never over the stage's top, the header's banners
   («برای شنیدن… بزن») or the hand button. On a phone on its side, over the stage's half. */
.chat-toast {
  appearance: none;
  position: fixed; z-index: 13;
  bottom: calc(var(--cbar-h, 68px) + env(safe-area-inset-bottom) + 12px);
  inset-inline: 12px; margin-inline: auto;
  max-width: 520px;
  display: flex; align-items: flex-start; gap: 10px;
  min-height: var(--tap); padding: 10px 14px;
  border: 1px solid var(--accent-line); border-radius: var(--r-pop);
  background: var(--surface-raised); color: var(--ink);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm); line-height: 1.6; text-align: start;
  cursor: pointer; touch-action: manipulation;
  animation: chat-in .18s ease-out;
}
.chat-toast[hidden] { display: none; }
.chat-toast .ic { width: 20px; height: 20px; margin-top: 2px; color: var(--accent); }
.chat-toast-body {
  min-width: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere;
}
.chat-toast-body b { color: var(--accent-ink); }
@media (min-width: 960px) {
  .chat-toast { bottom: calc(var(--cbar-h, 72px) + 16px); inset-inline: auto 24px; width: min(420px, 100% - 48px); }
}
@media (max-width: 959px) and (max-height: 540px) and (orientation: landscape) {
  .chat-toast {
    bottom: 8px; inset-inline-start: max(8px, env(safe-area-inset-right)); inset-inline-end: auto;
    width: calc(50% - 16px); max-width: none; margin: 0;
  }
}
@keyframes chat-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .chat-toast { animation: none; } }


/* ---------- after the class: the transcript beside attendance ---------- */
.chat-record h2 { display: flex; align-items: center; gap: 8px; }
.chat-record h2 .ic { width: 20px; height: 20px; color: var(--accent); }
.chat-record .hint { margin: 6px 0 12px; }
.chat-record-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-record-acts .btn { width: auto; }
@container (min-width: 860px) {
  .pg-att > #chat-record { grid-column: 1; }
}

/* ======================= the teaching tool (CHAT2.md) ======================= */

/* ---------- the tabs inside the chat: «همه»، «سؤال‌ها»، «خصوصی»، «جواب‌ها» ---------- */
.chat-subs {
  flex: none; display: flex; gap: 2px;
  margin: 0 0 8px; padding: 2px;
  border-radius: var(--r-ctl); background: var(--bg-sunken);
}
.chat-sub {
  appearance: none; flex: 1 1 auto; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: var(--tap); padding: 4px 8px;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: var(--fs-s); font-weight: var(--fw-b); white-space: nowrap;
  cursor: pointer; touch-action: manipulation;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.chat-sub-w { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chat-sub[aria-selected="true"] { background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-1); }
@media (hover: hover) { .chat-sub:not([aria-selected="true"]):hover { background: var(--hover); color: var(--ink); } }
.chat-sub:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.chat-sub .count { min-width: 18px; height: 18px; padding: 0 5px; }
.chat-sub[data-sub="all"] .count, .chat-sub[data-sub="priv"] .count { background: var(--accent); color: var(--on-accent); }
.chat-sub[data-sub="q"] .count { background: var(--hand-soft); color: var(--hand-ink); }

/* ---------- the teacher's mode control and its menu ---------- */
.chat { position: relative; }
.chat-modebtn { gap: 6px; padding-inline: 10px 8px; font-weight: var(--fw-b); }
.chat-modebtn .ic { width: 18px; height: 18px; }
.chat-modebtn .chat-modebtn-chev { width: 16px; height: 16px; color: var(--muted); }
.chat-modebtn[data-mode="closed"] { color: var(--hand-ink); border-color: var(--hand-line); background: var(--hand-soft); }
.chat-modebtn[data-mode="teacher"], .chat-modebtn[data-mode="questions"] { color: var(--accent-ink); border-color: var(--accent-line); background: var(--accent-soft); }
.room[data-chat-wide="1"] .chat-head:has(.chat-modebtn) { margin-bottom: 8px; }
/* The menu floats over the chat (placed by chat.js under the button), like «بیشتر». */
.chat-menu {
  position: fixed; z-index: 31; top: var(--menu-top, 120px); left: var(--menu-left, 12px);
  width: min(320px, 100vw - 24px);
  max-height: var(--menu-max, 60vh); overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--surface-raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-pop);
  box-shadow: var(--shadow-2);
  animation: kit-pop var(--t-med) var(--ease);
}
.chat-menu > *, .chat-menu-group > * { flex-shrink: 0; } /* a short screen scrolls the menu; its rows keep their height */
.chat-menu-h { margin: 4px 10px 2px; color: var(--muted); font-size: var(--fs-xs); font-weight: var(--fw-b); }
.chat-menu-group { display: flex; flex-direction: column; gap: 2px; }
.chat-menu-row {
  appearance: none; display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 6px 10px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink);
  font: inherit; text-align: start; cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}
@media (hover: hover) { button.chat-menu-row:hover { background: var(--hover); } }
button.chat-menu-row:active { background: var(--press); }
.chat-menu-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.chat-menu-row > .ic { flex: none; width: 20px; height: 20px; color: var(--muted); }
.chat-menu-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.chat-menu-txt b { font-size: var(--fs-sm); font-weight: var(--fw-b); }
.chat-menu-txt small { color: var(--muted); font-size: var(--fs-xs); }
.chat-radio { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; }
.chat-menu-row[aria-checked="true"] .chat-radio { border-color: var(--accent); }
.chat-menu-row[aria-checked="true"] .chat-radio::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.chat-menu-row[aria-checked="true"] b { color: var(--accent-ink); }
.chat-menu-sw, .chat-menu-act { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 2px; padding-top: 8px; cursor: default; }
.chat-menu-act { cursor: pointer; border-radius: 10px; }
.chat-menu-sw .switch[aria-pressed="true"]::before { background: var(--accent); }
.chat-menu-foot { margin: 4px 10px; color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }

/* ---------- the teacher's alert lines over the list ---------- */
.chat-alert {
  flex: none; display: flex; flex-direction: column; gap: 6px;
  margin: 0 0 8px; padding: 8px 10px 8px 12px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-s); line-height: 1.6;
  animation: kit-pop var(--t-med) var(--ease);
}
.chat-alert-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-alert-row > b, .chat-alert-row > span { flex: 1; min-width: 0; }
.chat-alert-ic { flex: none; width: 20px; height: 20px; }
.chat-alert-acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.chat-sound { border-color: var(--hand-line); background: var(--hand-soft); }
.chat-sound .chat-alert-ic, .chat-sound b { color: var(--hand-ink); }
.chat-sound .btn.quiet { color: var(--hand-ink); }
.chat-sound-names { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; }
.chat-sound-names li { display: inline-flex; align-items: center; gap: 4px; padding: 0 10px; border-radius: var(--r-pill); background: var(--surface); color: var(--ink-2); font-size: var(--fs-xs); line-height: 1.8; }
/* With conn.js: each name's avatar carries the connection dot and opens the person's card. */
.chat-sound-names li:has(.conn-av) { padding-inline-start: 4px; min-height: var(--tap); }
.chat-sound-names .chat-sound-av { width: 28px; height: 28px; font-size: var(--fs-xs); }
.chat-flood { border-color: var(--accent-line); background: var(--accent-soft); }
.chat-flood .chat-alert-ic { color: var(--accent-ink); }
.chat-collectbar {
  appearance: none; flex-direction: row; align-items: center; min-height: var(--tap);
  border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-ink);
  font: inherit; font-size: var(--fs-s); font-weight: var(--fw-b); text-align: start; cursor: pointer;
}
.chat-collectbar > span { flex: 1; }
.chat-collectbar > b { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- one message: its marks, the quote, a question's actions, the bad-word note ---------- */
.cm-kind { flex: none; }
.cm-kind-q { background: var(--hand-soft); color: var(--hand-ink); font-weight: var(--fw-b); }
.cm-kind-only { background: var(--accent-soft); color: var(--accent-ink); }
.cm-kind-ans { background: var(--speak-soft); color: var(--speak-ink); }
.cm[data-kind="question"]:not([data-answered="1"]) { border-inline-start: 3px solid var(--hand-line); border-start-start-radius: 4px; border-end-start-radius: 4px; }
.cm-quote {
  margin: 2px 0 4px; padding: 4px 10px;
  border-inline-start: 3px solid var(--accent-line); border-radius: 4px;
  background: var(--bg-sunken); color: var(--muted);
  font-size: var(--fs-s); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere;
}
.cm-quote b { color: var(--ink-2); font-weight: var(--fw-b); }
.cm[data-role="teacher"] .cm-quote { background: var(--surface); }
.cm-sub { margin: 2px 0 0; color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.cm-flag { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 4px 0 0; color: var(--hand-ink); font-size: var(--fs-xs); font-weight: var(--fw-b); }
.cm-flag .ic { width: 16px; height: 16px; }
.cm-flag .btn.tiny { padding: 0 8px; color: var(--hand-ink); }
.cm[data-masked="1"] .cm-text { color: var(--muted); }

.cq-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
.cq-vote { gap: 6px; }
.cq-vote .ic, .cq-votes .ic { width: 16px; height: 16px; }
.cq-vote[aria-pressed="true"] { background: var(--hand-soft); color: var(--hand-ink); border-color: var(--hand-line); }
.cq-n { min-width: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--bg-sunken); color: var(--ink-2); font-size: var(--fs-xs); line-height: 1.6; }
.cq-vote[aria-pressed="true"] .cq-n { background: var(--surface); }
.cq-votes { display: inline-flex; align-items: center; gap: 2px; color: var(--hand-ink); font-size: var(--fs-s); font-weight: var(--fw-b); font-variant-numeric: tabular-nums; }
.cq-state { display: inline-flex; align-items: center; gap: 4px; color: var(--speak-ink); font-size: var(--fs-s); font-weight: var(--fw-b); }
.cq-state .ic { width: 16px; height: 16px; }
.cq-done:not([aria-pressed="true"]) { color: var(--speak-ink); border-color: var(--speak-line); }
.cq-done .ic, .cq-reply .ic { width: 16px; height: 16px; }
.cq-reply { gap: 4px; }

/* ---------- «سؤال‌ها»: the open ones by votes, the answered ones folded below ---------- */
.cq {
  padding: 10px 12px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
}
.chat-qs { gap: 8px; }
.cq-head { display: flex; align-items: baseline; gap: 6px; min-width: 0; font-size: var(--fs-s); line-height: 1.6; }
.cq[data-answered="1"] { background: transparent; }
.cq[data-answered="1"] .cm-text { color: var(--muted); }
.cq[data-pending="1"] { opacity: .6; }
.chat-fold {
  appearance: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; min-height: var(--tap); margin: 4px 0; padding: 4px 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font: inherit; font-size: var(--fs-s); font-weight: var(--fw-b); cursor: pointer;
}
@media (hover: hover) { .chat-fold:hover { background: var(--hover); color: var(--ink); } }
.chat-fold .ic { width: 16px; height: 16px; transition: transform var(--t-fast) var(--ease); }
.chat-fold[aria-expanded="true"] .ic { transform: rotate(180deg); }

/* ---------- folded presence messages: «۱۲ نفر سلام کردن» ---------- */
.cm-group { margin: 6px 0 0; }
.cm-group-btn {
  appearance: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; max-width: 100%; padding: 4px 12px;
  border: 0; border-radius: var(--r-pill);
  background: var(--bg-sunken); color: var(--muted);
  font: inherit; font-size: var(--fs-s); font-weight: var(--fw-m); cursor: pointer;
}
.cm-group-btn { min-height: var(--tap); }
@media (hover: hover) { .cm-group-btn:hover { background: var(--hover); color: var(--ink); } }
.cm-group-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cm-group-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.cm-group-chev { width: 16px; height: 16px; transition: transform var(--t-fast) var(--ease); }
.cm-group-btn[aria-expanded="true"] .cm-group-chev { transform: rotate(180deg); }
.cm-group-names { margin: 4px 12px 0; color: var(--muted); font-size: var(--fs-xs); line-height: 1.7; }

/* ---------- the reveal card: the round's answers for everyone ---------- */
.cm-reveal { background: var(--accent-soft); }
.cm-reveal-h { display: flex; align-items: center; gap: 6px; margin: 2px 0 6px; font-size: var(--fs-sm); font-weight: var(--fw-x); color: var(--accent-ink); }
.cm-reveal-h .ic { width: 18px; height: 18px; }
.cm-reveal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cm-reveal-list li {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 10px;
  border-radius: 10px; background: var(--surface); font-size: var(--fs-sm); line-height: 1.6;
}
.cm-reveal-name { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--fw-b); }
.cm-reveal-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cm-reveal-ok { flex: none; align-self: center; color: var(--speak-ink); }
.cm-reveal-ok .ic { width: 18px; height: 18px; }
.cm-reveal-list li[data-correct="1"] { box-shadow: inset 0 0 0 1px var(--speak-line); }

/* ---------- «خصوصی»: the teacher's threads, one thread, a student's thread with the teacher ---------- */
.chat-threads { gap: 4px; }
.chat-thread {
  appearance: none; display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 56px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink);
  font: inherit; text-align: start; cursor: pointer;
}
@media (hover: hover) { .chat-thread:hover { background: var(--hover); } }
.chat-thread-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.chat-thread-last { color: var(--muted); font-size: var(--fs-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread-go { flex: none; width: 18px; height: 18px; color: var(--icon-quiet); }
.chat-privhead { flex: none; display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.chat-back { gap: 4px; }
.chat-back .ic { width: 18px; height: 18px; }
.chat-privwho { flex: 1; min-width: 0; font-size: var(--fs-sm); font-weight: var(--fw-b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm[data-kind="private"] { background: var(--bg-sunken); }
.cm[data-kind="private"][data-role="teacher"] { background: var(--accent-soft); }

/* ---------- the teacher's «جواب‌ها»: one row per student ---------- */
.chat-anshead { flex: none; display: flex; flex-direction: column; gap: 8px; margin: 0 0 8px; }
.chat-ans-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 0; font-size: var(--fs-s); color: var(--muted); }
.chat-ans-h b { color: var(--ink); font-size: var(--fs-sm); }
.chat-ans-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-ans-acts .ic { width: 18px; height: 18px; }
.chat-ans { gap: 4px; }
.ca {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
.ca-body { flex: 1; min-width: 0; line-height: 1.5; }
.ca-body .cm-name { display: block; font-size: var(--fs-s); }
.ca .cm-text { font-size: var(--fs-sm); line-height: 1.6; }
.ca[data-correct="1"] { border-color: var(--speak-line); background: var(--speak-soft); }
.ca-ok { flex: none; gap: 4px; }
.ca-ok .ic { width: 16px; height: 16px; }
.ca-ok[aria-pressed="true"] { background: var(--speak); color: var(--on-solid); }
@media (hover: hover) { .ca-ok[aria-pressed="true"]:hover { background: var(--speak-hover); } }

/* ---------- the composer: the reply quote, the line about where the message goes, «سؤاله», slow mode ---------- */
.chat-reply {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 4px 4px 4px 10px;
  border-inline-start: 3px solid var(--accent); border-radius: 8px; background: var(--bg-sunken);
  font-size: var(--fs-s); line-height: 1.6;
}
.chat-reply > .ic { flex: none; width: 18px; height: 18px; color: var(--accent-ink); }
.chat-reply-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.chat-reply-body b { color: var(--ink-2); }
.chat-modenote { margin: 0 0 8px; color: var(--muted); font-size: var(--fs-xs); font-weight: var(--fw-m); line-height: 1.6; }
.chat-ask {
  appearance: none; flex: none; position: relative;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  width: 56px; min-height: 48px; padding: 2px 4px;
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: var(--fs-micro); font-weight: var(--fw-b); line-height: 1.3; cursor: pointer; touch-action: manipulation;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.chat-ask .ic { width: 20px; height: 20px; }
.chat-ask[aria-pressed="true"] { background: var(--hand-soft); color: var(--hand-ink); border-color: var(--hand-line); }
.chat-ask:disabled { cursor: default; }
@media (hover: hover) { .chat-ask:not(:disabled):not([aria-pressed="true"]):hover { background: var(--hover); color: var(--ink); } }
.chat-ask:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chat-send { position: relative; }
.chat-send-wait { display: none; }
.chat-send[data-wait="1"] { background: var(--bg-sunken); color: var(--muted); }
.chat-send[data-wait="1"] .ic { display: none; }
.chat-send[data-wait="1"] .chat-send-wait { display: block; font-size: var(--fs-sm); font-weight: var(--fw-x); font-variant-numeric: tabular-nums; }

/* ---------- after the class: the questions, the answers, the reports ---------- */
.chat-record-body { display: flex; flex-direction: column; gap: 12px; margin: 0 0 12px; }
.chat-record-body:empty, .chat-record-more:empty { display: none; }
.chat-record-sec h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: var(--fs-sm); font-weight: var(--fw-x); }
.chat-record-sec h3 .ic { width: 18px; height: 18px; color: var(--accent); }
.chat-record-line { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.7; }
.chat-record-quiet { color: var(--muted); font-size: var(--fs-s); }
.chat-record-sub { margin: 6px 0 4px; color: var(--muted); font-size: var(--fs-s); font-weight: var(--fw-b); }
.chat-record-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-record-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding: 6px 10px; border-radius: 10px; background: var(--bg-sunken); font-size: var(--fs-sm); line-height: 1.6; }
/* The words take the row's rest, or a row of their own under the name when that would be too narrow. */
.chat-record-list li > span { flex: 1 1 12em; min-width: 0; overflow-wrap: anywhere; }
.chat-record-list .ic { flex: none; align-self: center; width: 16px; height: 16px; color: var(--speak-ink); }
.chat-record-name { flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--fw-b); }
.chat-record-votes { flex: none; color: var(--hand-ink); font-weight: var(--fw-b); font-size: var(--fs-s); }
.chat-record-round summary { min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: 8px; list-style: none; cursor: pointer; font-size: var(--fs-sm); font-weight: var(--fw-b); }
.chat-record-round summary::-webkit-details-marker { display: none; }
.chat-record-round summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.chat-record-see { flex: none; display: inline-flex; align-items: center; gap: 4px; color: var(--accent-ink); font-size: var(--fs-s); }
.chat-record-chev { width: 16px; height: 16px; transition: transform var(--t-fast) var(--ease); }
.chat-record-round[open] .chat-record-chev { transform: rotate(180deg); }
.chat-record-round[open] summary { margin-bottom: 4px; }

/* ---------- the weekly class panel: a past session's «چت» (under the session, across its row) ---------- */
.sessions > li > .s-chat {
  grid-column: 1 / -1;
  margin-top: 8px; padding: 12px 14px;
  border-radius: var(--r-card); background: var(--bg-sunken);
  animation: kit-fade var(--t-med) var(--ease);
}
.s-chat .s-chat-line { margin: 0 0 8px; }
.s-chat .chat-record-body { margin-bottom: 10px; }
.s-chat .chat-record-list li { background: var(--surface); }
.s-acts { flex-wrap: wrap; justify-content: flex-end; }
/* With «چت» beside «حضور و غیاب», a phone gives the session's buttons their own row (the date and the count keep theirs). */
@media (max-width: 559px) {
  .sessions > li { grid-template-areas: "head head" "info info" "acts acts" "recs recs" "err err"; }
  .s-acts { justify-content: flex-start; }
}
