/* "Nhóm chat chung" (chat.js): mobile ChatScreen's style (the list on the app background, the
   shared CommentCard bubbles and CommentComposer from quotes.css, Mầm Sleepy when the room is
   quiet), laid out for the web: the room is a panel that fills the content height (header row,
   a scrolling message column up to 760 px, the composer at its foot) beside an aside with the
   rules, the activity and the notification note. Below 1024 px the aside folds into "Nội quy";
   phones get the app's full-height room with the composer above the bottom bar (or the keyboard). */
.chat-page {
  --ch-shadow: var(--md-card-shadow);
  --ch-gap-bottom: 24px;
  height: calc(var(--chat-viewport, 100dvh) - var(--header-h, 64px) - var(--main-pad-top) - var(--ch-gap-bottom));
  min-height: 460px;
  gap: 0;
}
main[data-route="chat"] {
  min-height: 0;
  padding-bottom: 24px;
}
/* The room fills the window; the shell footer would only push it out of view. */
.workspace:has(.chat-page) .app-footer {
  display: none;
}
/* The room's own glyphs; the shared cards keep quotes.css's sizes (16 px reaction icons). */
.chat-room-chip .mi,
.chat-guide-button .mi,
.chat-new-pill .mi {
  width: 20px;
  height: 20px;
  flex: none;
}
.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  height: 100%;
  min-height: 0;
}

/* ---------- the room ---------- */
.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--md-outline-variant);
  border-radius: 20px;
  background: var(--md-surface);
  box-shadow: var(--ch-shadow);
}
.chat-skip {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 3;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--md-primary);
  color: #fff;
  font: 700 14px/20px var(--font-app-bold);
  transform: translate(-50%, -160%);
}
.chat-skip:focus-visible {
  transform: translate(-50%, 0);
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px 16px 12px 20px;
  border-bottom: 1px solid var(--md-outline-variant);
}
.chat-room-chip {
  display: grid;
  flex: none;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(to bottom right, #778ded, #9962d1);
  color: #fff;
}
.chat-room-text {
  min-width: 0;
}
.chat-room-text h2 {
  color: var(--md-on-surface);
  font: 700 17px/22px var(--font-app-bold);
}
.chat-room-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  color: var(--md-on-surface-variant);
  font-size: 13px;
  line-height: 18px;
}
.chat-room-meta #chat-count:empty {
  display: none;
}
.chat-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chat-live::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--md-outline);
}
.chat-live[data-state="live"]::before {
  background: var(--md-brand);
  box-shadow: 0 0 0 3px #00968824;
}
.chat-live[data-state="reconnecting"]::before {
  background: var(--md-streak);
}
.chat-guide-button {
  display: none;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-left: auto;
  padding: 0 14px 0 12px;
  border: 1px solid var(--md-outline-variant);
  border-radius: 999px;
  background: var(--md-surface);
  color: var(--md-hero);
  font: 700 14px/20px var(--font-app-bold);
}
.chat-guide-button:hover {
  border-color: var(--md-primary);
  background: #00796b0f;
}
.chat-body {
  position: relative;
  min-height: 0;
  background: var(--md-background);
}
.chat-scroll {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.chat-scroll:focus-visible {
  outline-offset: -3px;
}
.chat-feed {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}
/* Few messages sit at the bottom, as mobile's list does (Arrangement.Bottom). */
/* "Xem tin nhắn cũ hơn" above the oldest message shown. */
.chat-older {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}

.chat-list {
  margin-top: auto;
}
.chat-loading {
  margin: auto;
}
.chat-state {
  display: grid;
  justify-items: center;
  gap: 6px;
  max-width: 380px;
  margin: auto;
  padding: 16px;
  text-align: center;
}
.chat-state-mam {
  width: 160px;
}
.chat-state.is-error .chat-state-mam {
  width: 120px;
}
.chat-state h3 {
  margin-top: 6px;
  color: var(--md-on-surface);
  font: 700 19px/26px var(--font-app-bold);
}
.chat-state p {
  color: var(--md-on-surface-variant);
  font-size: 15px;
  line-height: 22px;
}
.chat-state .button {
  margin-top: 10px;
}
.chat-new-pill {
  position: absolute;
  bottom: 14px;
  left: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--md-primary);
  box-shadow: 0 2px 6px #0e242026, 0 10px 24px #0e24201f;
  color: #fff;
  font: 700 14px/20px var(--font-app-bold);
  transform: translateX(-50%);
}
.chat-new-pill[hidden] {
  display: none;
}
.chat-new-pill:hover {
  background: var(--md-hero);
}
.chat-new-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ffffff33;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}
.chat-new-count:empty {
  display: none;
}
.chat-compose {
  padding: 12px 24px;
  border-top: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
}
.chat-compose .comment-composer {
  max-width: 760px;
  margin: 0 auto;
}
#chat-composer-text {
  max-height: 113px;
  overflow-y: auto;
}
.chat-status {
  max-width: 760px;
  margin: 8px auto 0;
  color: var(--md-on-surface-variant);
  font-size: 13px;
  line-height: 18px;
  text-align: center;
}
.chat-status:empty {
  display: none;
}
.chat-status a {
  color: var(--md-hero);
  font-weight: 700;
}

/* ---------- the aside (and the "Nội quy" dialog) ---------- */
.chat-aside {
  display: grid;
  align-content: start;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
.chat-card {
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--md-outline-variant);
  border-radius: 20px;
  background: var(--md-surface);
  box-shadow: var(--ch-shadow);
}
.chat-card-title {
  color: var(--md-on-surface);
  font: 700 16px/22px var(--font-app-bold);
}
.chat-rules {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chat-rules li {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  color: var(--md-on-surface-variant);
  font-size: 13px;
  line-height: 19px;
}
.chat-rules strong {
  display: block;
  color: var(--md-on-surface);
  font: 700 14px/20px var(--font-app-bold);
}
.chat-rule-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 10px;
  background: var(--md-violet-chip);
  color: var(--md-violet-icon);
}
.chat-rule-icon .mi {
  width: 18px;
  height: 18px;
}
.chat-policy {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--md-background);
  color: var(--md-on-surface-variant);
  font-size: 12px;
  line-height: 18px;
}
.chat-policy .mi {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  color: var(--md-primary);
}
.chat-stats {
  display: grid;
  margin: 0;
  border-radius: 14px;
  background: var(--md-background);
}
.chat-stats > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
}
.chat-stats > div + div {
  border-top: 1px solid var(--md-outline-variant);
}
.chat-stats dt {
  color: var(--md-on-surface-variant);
  font-size: 13px;
  line-height: 18px;
}
.chat-stats dd {
  margin: 0;
  color: var(--md-on-surface);
  font: 700 14px/20px var(--font-app-bold);
  text-align: right;
}
.chat-notify {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--md-outline-variant);
}
.chat-notify-tile {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 11px;
  background: var(--md-streak-container);
  color: var(--md-warning);
}
.chat-notify-tile .mi {
  width: 18px;
  height: 18px;
}
.chat-notify h3 {
  color: var(--md-on-surface);
  font: 700 14px/20px var(--font-app-bold);
}
.chat-notify p {
  margin-top: 2px;
  color: var(--md-on-surface-variant);
  font-size: 13px;
  line-height: 19px;
}
.chat-store-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  color: var(--md-hero);
  font: 700 14px/20px var(--font-app-bold);
  text-decoration: none;
}
.chat-store-link:hover {
  text-decoration: underline;
}
/* The global #dialog: the guide, and mobile's ConfirmSheet for the send checks. */
.chat-guide-dialog,
.chat-rule {
  font-family: var(--font-app);
}
.chat-guide-dialog {
  text-align: start;
}
.chat-guide-dialog h2 {
  text-align: center;
}
.chat-guide-dialog .chat-rules li {
  font-size: 14px;
  line-height: 20px;
}
.chat-guide-dialog .chat-policy {
  margin: 14px 0 0;
}
.chat-dialog-notify {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--md-outline-variant);
}
.chat-dialog-notify h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--md-on-surface);
  font: 700 15px/22px var(--font-app-bold);
}
.chat-dialog-notify h3 .mi {
  width: 18px;
  height: 18px;
  color: var(--md-warning);
}
dialog .chat-dialog-notify p {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 19px;
}
.chat-rule {
  display: grid;
  justify-items: center;
  text-align: center;
}
dialog h2.chat-rule-text {
  margin: 6px 0 0;
  padding: 0;
  color: var(--md-on-surface);
  font: 400 17px/26px var(--font-app);
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.chat-rule .dialog-actions {
  justify-content: center;
  width: 100%;
}
.chat-rule .dialog-actions .button {
  min-width: 140px;
  border-radius: 999px;
}

/* ---------- widths ---------- */
/* One line of placeholder, as mobile's field (maxLines = 1 for the hint). */
.chat-compose .comment-field::placeholder {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Narrow desktop: a slimmer aside and mobile's icon-only send button keep the room wide enough. */
@media (min-width: 1024px) and (max-width: 1279px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr) 272px;
    gap: 20px;
  }
  .chat-scroll {
    padding: 14px 16px;
  }
  .chat-compose {
    padding: 10px 16px;
  }
  .chat-compose .comment-send {
    width: 46px;
    padding: 0;
  }
  .chat-compose .comment-send-label {
    display: none;
  }
  .chat-card {
    padding: 16px;
  }
}
@media (min-width: 1280px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr) 340px;
  }
  .chat-scroll {
    padding: 20px 28px;
  }
}
/* Tablet and phone: one column; the aside's rules and note open from "Nội quy". */
@media (max-width: 1023px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .chat-aside {
    display: none;
  }
  .chat-guide-button {
    display: inline-flex;
  }
}
@media (max-width: 767px) {
  /* Mobile ChatScreen: the room fills the screen between the app bar and the bottom bar. */
  main[data-route="chat"] {
    padding: 0;
  }
  .chat-page {
    --ch-nav: calc(66px + env(safe-area-inset-bottom));
    height: calc(var(--chat-viewport, 100dvh) - var(--header-h, 64px) - var(--ch-nav));
    min-height: 300px;
  }
  /* The keyboard is up: the bottom bar steps aside and the composer rides on the keyboard. */
  .chat-page.is-keyboard {
    --ch-nav: 0px;
  }
  .app-shell:has(.chat-page.is-keyboard) .sidebar {
    display: none;
  }
  .app-shell:has(.chat-page.is-keyboard) .workspace {
    padding-bottom: 0;
  }
  .chat-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .chat-head {
    gap: 10px;
    min-height: 56px;
    padding: 6px 10px 6px 16px;
  }
  .chat-room-chip {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
  .chat-room-chip .mi {
    width: 18px;
    height: 18px;
  }
  .chat-room-text h2 {
    font-size: 15px;
    line-height: 20px;
  }
  .chat-room-meta {
    font-size: 12px;
    line-height: 16px;
  }
  .chat-guide-button {
    padding: 0 12px 0 10px;
  }
  /* Mobile: 7 dp list padding, 16 / 5 dp around each card. */
  .chat-scroll {
    padding: 7px 0;
  }
  .chat-list {
    gap: 0;
  }
  .chat-list > li {
    padding: 5px 16px;
  }
  .chat-state-mam {
    width: 140px;
  }
  .chat-compose {
    padding: 0 0 4px;
  }
  .chat-compose .comment-composer {
    padding: 10px 16px 6px;
    border: 0;
    border-radius: 0;
    background: var(--md-surface);
  }
  .chat-status {
    margin: 0 16px 4px;
  }
  .comment-identity-label {
    font-size: 12px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .chat-skip,
  .chat-guide-button {
    transition: transform 0.18s, background-color 0.18s, border-color 0.18s;
  }
  .chat-new-pill:not([hidden]) {
    animation: chat-pill-in 0.24s ease-out;
  }
  @keyframes chat-pill-in {
    from {
      opacity: 0;
      transform: translate(-50%, 8px);
    }
  }
}
