/* ---- צ׳אט (WhatsApp-style conversations — see public/js/chat.js) ----
   RTL like Hebrew WhatsApp: my own messages sit on the left in a soft lilac, the other side's on
   the right in white, over a soft cream "wallpaper". */

:root {
  --chat-wall: #f6ebe1;
  /* "לילך ורדרד" (Karin's pick, 7.10.2026): a soft pinkish lilac for my bubbles, the open row in
     the list, avatar circles and the home tile; a deeper mauve for names and the send button. */
  --chat-teal-row: #f2e7f0;
  --chat-mine: #fbedf3;
  --chat-mine-border: #f1d8e3;
  --chat-teal-ink: #8a4f80;
  --chat-teal-name: #8a4f80; /* sender names */
  --chat-send: #9a6290;
  --chat-theirs: #ffffff;
  --chat-read: #1f9bd1;
  --chat-height: calc(100dvh - 130px);
}

/* Header link badge (sits next to the name, like the system-messages badge). */
#chat-link .badge { margin-inline-start: 4px; }

/* ---------- shared bits ---------- */

.chat-avatar {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--chat-teal-row);
  color: var(--chat-teal-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.15rem;
  overflow: hidden;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-avatar-support { background: color-mix(in srgb, var(--text) 10%, white); color: var(--text); }

.chat-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.chat-row-name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row-time { font-size: 0.74rem; color: var(--text-muted); flex: none; }
.chat-row-time.is-unread { color: var(--accent); font-weight: 600; }
.chat-row-preview, .chat-row-sub {
  font-size: 0.86rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-preview-me { color: var(--text); opacity: 0.7; }
.chat-unread {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---------- participant: the two chats ---------- */

.chat-home { max-width: 640px; margin: 0 auto; }
.chat-channel-list { display: flex; flex-direction: column; gap: 12px; }
.chat-channel-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: right;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 150ms ease, box-shadow 150ms ease;
  font: inherit;
  color: inherit;
}
.chat-channel-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.chat-channel-card .chat-avatar { width: 56px; height: 56px; font-size: 1.35rem; }
.chat-channel-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-channel-card .chat-row-name { font-size: 1.05rem; }

/* Participant's own conversation fills the column like a phone screen. */
.chat-standalone { max-width: 760px; margin: 0 auto; }
.chat-standalone .chat-conv {
  height: var(--chat-height);
  min-height: 420px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

/* ---------- staff: inbox (list + conversation side by side) ---------- */

main:has(.chat-inbox) { max-width: 1280px; }
.chat-inbox {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  height: var(--chat-height);
  min-height: 460px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.chat-list-pane {
  display: flex;
  flex-direction: column;
  border-inline-end: 1px solid var(--border);
  min-height: 0;
  background: var(--card);
}
.chat-list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; gap: 8px; }
.chat-list-title { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 6px; }
.chat-new-btn { padding: 6px 12px; font-size: 0.82rem; }

.chat-filters { padding: 4px 16px 0; display: flex; flex-direction: column; gap: 6px; }
.chat-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chat-chip.is-active { background: var(--text); border-color: var(--text); color: #fff; }
.chat-chip-count { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 0.72rem; font-weight: 700; }

.chat-search {
  margin: 10px 16px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 999px;
  padding: 7px 14px;
  color: var(--text-muted);
}
.chat-search input { border: 0; background: transparent; outline: none; flex: 1; font-size: 0.9rem; color: var(--text); min-width: 0; }

.chat-list { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.chat-list-empty { padding: 28px 18px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  background: transparent;
  text-align: right;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 120ms ease;
}
.chat-row:hover { background: var(--hover-tint); }
/* The open conversation's row — in the chat's lilac. */
.chat-row.is-open { background: var(--chat-teal-row); }
.chat-row.is-open:hover { background: #ecdeea; }
.chat-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-row-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.chat-tag { font-size: 0.7rem; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--text-muted); }
.chat-tag-support { background: color-mix(in srgb, var(--text) 9%, white); color: var(--text); }
.chat-waiting {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.chat-row.is-waiting .chat-row-name::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-inline-end: 6px;
  vertical-align: middle;
}

.chat-conv-pane { min-width: 0; min-height: 0; display: flex; }
.chat-conv-pane .chat-conv { flex: 1; }
.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  background: var(--chat-wall);
  height: 100%;
}
.chat-placeholder-icon { opacity: 0.45; }

/* On a wide screen the list is always visible, so the conversation's back arrow isn't needed. */
.chat-inbox .chat-back { display: none; }

/* ---------- the conversation itself ---------- */

.chat-conv {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--chat-wall);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(237, 22, 103, 0.035) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 70%, rgba(5, 39, 39, 0.035) 0 2px, transparent 3px);
  background-size: 38px 38px, 46px 46px;
}

.chat-conv-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.chat-conv-head .chat-avatar { width: 42px; height: 42px; font-size: 1.05rem; }
.chat-conv-title { flex: 1; min-width: 0; }
.chat-conv-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv-sub { font-size: 0.8rem; color: var(--text-muted); }
.chat-conv-actions { display: flex; gap: 6px; flex: none; }
.chat-conv-actions .btn { padding: 6px 11px; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 4px; }
.chat-handled-btn { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, white); }
.chat-back {
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  padding: 4px 2px;
}

.chat-scroll { flex: 1; overflow-y: auto; min-height: 0; padding: 14px 6% 10px; overscroll-behavior: contain; }
.chat-messages { display: flex; flex-direction: column; gap: 2px; }

.chat-day { text-align: center; margin: 12px 0 8px; }
.chat-day span {
  display: inline-block;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-muted);
  font-size: 0.76rem;
  padding: 4px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(5, 39, 39, 0.06);
}

.chat-empty {
  margin: 40px auto;
  max-width: 360px;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.chat-msg { display: flex; max-width: 100%; }
.chat-msg.is-first { margin-top: 8px; }
/* RTL flex: flex-start is the right edge. Theirs → right, mine → left. */
.chat-msg.is-theirs { justify-content: flex-start; }
.chat-msg.is-mine { justify-content: flex-end; }

.chat-bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 7px 11px 5px;
  border-radius: 12px;
  box-shadow: 0 1px 1.5px rgba(5, 39, 39, 0.1);
  font-size: 0.95rem;
  line-height: 1.45;
  animation: chat-pop 160ms ease-out;
}
.is-theirs .chat-bubble { background: var(--chat-theirs); }
.is-mine .chat-bubble { background: var(--chat-mine); }
/* Tail on the first bubble of a run, pointing outward toward that side's edge. */
.is-first.is-theirs .chat-bubble { border-start-start-radius: 0; }
.is-first.is-mine .chat-bubble { border-start-end-radius: 0; }
.is-first .chat-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 9px;
  height: 12px;
}
.is-first.is-theirs .chat-bubble::before {
  right: -8px;
  background: var(--chat-theirs);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.is-first.is-mine .chat-bubble::before {
  left: -8px;
  background: var(--chat-mine);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.chat-sender { font-size: 0.78rem; font-weight: 700; color: var(--chat-teal-name); margin-bottom: 1px; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-text a { color: #0b6fa4; text-decoration: underline; }
.chat-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 0.68rem;
  color: var(--text-muted);
  direction: ltr;
}
.chat-ticks { font-size: 0.74rem; letter-spacing: -3px; padding-inline-end: 3px; display: inline-flex; align-items: center; }
.chat-ticks.is-read { color: var(--chat-read); }
.chat-failed { color: var(--risk); letter-spacing: 0; cursor: pointer; direction: rtl; }
.chat-msg.is-failed .chat-bubble { opacity: 0.75; }

@keyframes chat-pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--card) 70%, var(--chat-wall));
  border-top: 1px solid var(--border);
  flex: none;
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  max-height: 140px;
  outline: none;
  color: var(--text);
}
.chat-composer textarea:focus { border-color: color-mix(in srgb, var(--chat-teal-name) 45%, white); }
.chat-send {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--chat-send);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}
.chat-send:hover { filter: brightness(1.07); }
.chat-send:active { transform: scale(0.94); }
/* The plane points left — the direction text flows in RTL. */
.chat-send svg { transform: scaleX(-1); }

.chat-picker .chat-search { margin: 10px 0; }
.chat-picker-list { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }

/* ---------- phones: one pane at a time ---------- */

@media (max-width: 760px) {
  :root { --chat-height: calc(100dvh - 120px); }
  main:has(.chat-inbox), main:has(.chat-standalone) { padding: 8px 8px 0; }
  .chat-inbox { grid-template-columns: 1fr; border-radius: var(--radius-md); }
  .chat-inbox .chat-conv-pane { display: none; }
  .chat-inbox.has-open .chat-list-pane { display: none; }
  .chat-inbox.has-open .chat-conv-pane { display: flex; }
  .chat-inbox .chat-back { display: block; }
  .chat-standalone .chat-conv { border-radius: var(--radius-md); }
  .chat-scroll { padding: 10px 10px 8px; }
  .chat-bubble { max-width: 85%; }
}

/* ---------- staff: participant card beside the conversation ---------- */

/* Wide screens: list | conversation | card (RTL — the card sits on the left). */
.chat-inbox { position: relative; grid-template-columns: minmax(260px, 340px) 1fr 300px; }
.chat-info-pane {
  border-inline-start: 1px solid var(--border);
  background: var(--card);
  overflow-y: auto;
  min-height: 0;
}
.chat-inbox:not(.has-open) .chat-info-pane { background: var(--chat-wall); }
.chat-info-toggle { display: none !important; }
.chat-info-close { display: none; }

.chat-info { padding: 18px 18px 22px; display: flex; flex-direction: column; gap: 14px; position: relative; }
.chat-info-loading { padding: 24px; color: var(--text-muted); text-align: center; font-size: 0.9rem; }
.chat-info-head { display: flex; align-items: center; gap: 12px; }
.chat-info-head .chat-avatar { width: 56px; height: 56px; font-size: 1.3rem; }
.chat-info-name { font-weight: 700; font-size: 1.08rem; margin-bottom: 3px; }
.badge.neutral { background: var(--bg); color: var(--text-muted); }

.chat-info-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.chat-info-facts div { background: var(--bg); border-radius: var(--radius-sm); padding: 8px 10px; }
.chat-info-facts dt { font-size: 0.72rem; color: var(--text-muted); }
.chat-info-facts dd { margin: 2px 0 0; font-weight: 600; font-size: 0.9rem; }

.chat-info-block { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.chat-info-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.chat-info-sub { font-size: 0.78rem; color: var(--text-muted); }
.chat-info-deadline { border: 1.5px solid color-mix(in srgb, var(--accent) 40%, white); border-radius: var(--radius-sm); padding: 10px 12px; }
.chat-info-deadline .chat-info-label { color: var(--accent); }
.chat-info-deadline.is-late { border-color: var(--risk); background: var(--risk-bg); }
.chat-info-deadline.is-late .chat-info-label, .chat-info-late { color: var(--risk); font-weight: 600; }
.chat-info-about { white-space: pre-wrap; line-height: 1.5; }
.chat-info-about span { display: block; font-size: 0.74rem; color: var(--text-muted); }
.chat-info-links a { color: var(--accent); }

.chat-info-notes textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  border: 1px solid #f0dc9c;
  background: #fff9e3;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  outline: none;
}
.chat-info-notes textarea:focus { border-color: var(--warn); }
.chat-info-private { font-weight: 400; margin-inline-start: auto; font-size: 0.72rem; }
.chat-info-profile { align-self: flex-start; font-size: 0.82rem; padding: 7px 14px; }

/* Narrower screens: the card becomes a drawer over the conversation, opened from "פרטים". */
@media (max-width: 1180px) {
  .chat-inbox { grid-template-columns: minmax(260px, 340px) 1fr; }
  .chat-info-toggle { display: inline-flex !important; }
  .chat-info-close {
    display: block;
    position: absolute;
    top: 10px;
    left: 10px;
    border: 0;
    background: transparent;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
  }
  .chat-info-pane {
    position: absolute;
    inset-block: 0;
    left: 0;
    width: min(340px, 100%);
    z-index: 5;
    box-shadow: var(--shadow-lift);
    transform: translateX(-105%);
    transition: transform 200ms ease;
  }
  .chat-inbox.show-info .chat-info-pane { transform: none; }
}
@media (max-width: 760px) {
  .chat-inbox { grid-template-columns: 1fr; }
  .chat-info-pane { width: 100%; }
  .chat-conv-actions .btn { padding: 6px 9px; }
}

/* ---------- staff: "הודעות מוכנות" / "לינקים" drawer above the composer ---------- */

.chat-conv { position: relative; }
.chat-attach {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.chat-attach:hover { background: var(--hover-tint); color: var(--accent); }

.chat-sheet {
  position: absolute;
  inset-inline: 12px;
  bottom: 70px;
  max-height: min(70%, 460px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  padding: 12px 12px 10px;
  z-index: 4;
  animation: chat-pop 160ms ease-out;
}
.chat-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-sheet-x { border: 0; background: transparent; font-size: 1rem; color: var(--text-muted); cursor: pointer; padding: 4px; }
.chat-sheet .chat-search { margin: 0; }
.chat-sheet-list { overflow-y: auto; min-height: 60px; display: flex; flex-direction: column; }
.chat-sheet-empty { padding: 18px; text-align: center; color: var(--text-muted); font-size: 0.88rem; }
.chat-snippet { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.chat-snippet-use {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
  border: 0;
  background: transparent;
  padding: 9px 6px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: var(--radius-sm);
}
.chat-snippet-use:hover { background: var(--hover-tint); }
.chat-snippet-title { font-weight: 600; font-size: 0.9rem; }
.chat-snippet-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-snippet-tools { display: flex; gap: 2px; opacity: 0.55; }
.chat-snippet:hover .chat-snippet-tools { opacity: 1; }
.chat-snippet-tools button { border: 0; background: transparent; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: 6px; font-size: 0.8rem; }
.chat-snippet-tools button:hover { background: var(--hover-tint); color: var(--text); }
.chat-sheet-foot { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-sheet-foot .btn { font-size: 0.82rem; padding: 7px 12px; }

.chat-snippet-form { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.chat-snippet-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-muted); }
.chat-snippet-form input, .chat-snippet-form textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.92rem;
  color: var(--text);
  resize: vertical;
}
.chat-sheet-hint { font-size: 0.76rem; color: var(--text-muted); }
.chat-sheet-hint code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.chat-sheet-error { color: var(--risk); font-size: 0.82rem; min-height: 1em; }

@media (max-width: 760px) {
  .chat-sheet { inset-inline: 6px; bottom: 66px; max-height: 75%; }
  .chat-attach { width: 38px; }
}

/* ---------- images & files ---------- */
.chat-img-link { display: block; margin: 2px -5px 4px; }
.chat-img { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: 8px; object-fit: cover; }
.chat-img.is-uploading { opacity: 0.55; }
.chat-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 8px;
  background: rgba(5, 39, 39, 0.05);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
}
.chat-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-composer .chat-attach { width: 38px; }

/* ---------- waiting more than a day ---------- */
.chat-row.is-overdue .chat-waiting { color: var(--risk); }
.chat-row.is-overdue .chat-row-name::before { background: var(--risk); }
.chat-row.is-overdue { box-shadow: inset -3px 0 0 var(--risk); }

/* ---------- push prompt + stats ---------- */
.chat-list-actions { display: inline-flex; gap: 6px; }
.chat-push-slot:empty { display: none; }
.chat-push-slot { padding: 6px 16px 0; }
.chat-push-card {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  background: color-mix(in srgb, var(--accent) 7%, white);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, white);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.86rem;
  margin-bottom: 12px;
}
.chat-push-slot .chat-push-card { margin-bottom: 0; }
.chat-push-card span { flex: 1; min-width: 180px; }
.chat-push-card .btn { padding: 6px 12px; font-size: 0.82rem; }
.home-push-slot { padding: 0; margin-bottom: 14px; }
.home-push-slot .chat-push-card { padding: 14px 16px; font-size: 1rem; line-height: 1.5; }
.home-push-slot .chat-push-card .btn { padding: 10px 20px; font-size: 1rem; }
.chat-stats { width: 100%; }
.chat-stats td, .chat-stats th { text-align: right; }

.participant-chat-btns { display: inline-flex; gap: 6px; margin-inline-start: auto; }
.participant-chat-btn { padding: 6px 12px; font-size: 0.85rem; }

/* Participant home: the "צ׳אט" tile above "הצעות חיבור בתוך הקהילה". */
.chat-home-tile {
  background: var(--chat-mine) !important;
  border: 1px solid var(--chat-mine-border) !important;
  box-shadow: none !important;
  cursor: pointer;
}
.chat-home-tile .who { color: var(--chat-teal-ink); }

/* Rollout: staff opened a chat with someone it isn't open to yet. */
.chat-closed-note { padding: 14px 16px; text-align: center; font-size: 0.88rem; color: var(--text-muted); background: var(--card); border-top: 1px solid var(--border); }
.participant-chat-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); cursor: pointer; margin-inline-end: 6px; }

/* Inbox: women the chat is open to that she hasn't written to yet. */
.chat-list-section { padding: 12px 16px 4px; font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }
.chat-start-cta { flex: none; font-size: 0.78rem; color: var(--chat-teal-name); font-weight: 600; }

/* Women the chat isn't open to yet — shown, but greyed out and not clickable. */
.chat-row.is-closed { cursor: default; opacity: 0.5; filter: grayscale(1); }
.chat-row.is-closed:hover { background: transparent; }

/* ---------- "📣 תפוצה" ---------- */
.chat-broadcast { max-width: 600px; }
.chat-bc-label { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.chat-bc-sub { font-size: 0.78rem; color: var(--text-muted); margin: 8px 0 4px; }
.chat-bc-custom { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); }
.chat-bc-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.88rem; }
.chat-bc-checks label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.chat-bc-count { margin-top: 10px; font-size: 0.88rem; }
.chat-bc-count details { display: inline; margin-inline-start: 6px; color: var(--text-muted); }
.chat-bc-count summary { display: inline; cursor: pointer; text-decoration: underline; }
.chat-bc-select { width: 100%; margin-bottom: 6px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 0.88rem; }
.chat-bc-body { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; font-size: 0.92rem; line-height: 1.5; resize: vertical; }
.chat-bc-history { border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 200px; overflow-y: auto; }
.chat-bc-hrow { padding: 8px 12px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); font-size: 0.84rem; }

.chat-list-actions .btn { white-space: nowrap; }

/* Inbox header: Karin/Dar have three buttons — let them wrap under the title instead of being
   pushed out of the (overflow-hidden) list column on narrower screens. */
.chat-list-head { flex-wrap: wrap; row-gap: 8px; }
.chat-list-actions { flex-wrap: wrap; justify-content: flex-end; }

/* ---------- phones: everything in the chat fits and stays comfortable ---------- */
@media (max-width: 760px) {
  /* A slimmer app header while in the chat, so the conversation gets the screen. */
  body:has(.chat-inbox) .app-header > div:first-child .who,
  body:has(.chat-standalone) .app-header > div:first-child .who,
  body:has(.chat-home) .app-header > div:first-child .who { display: none; }
  body:has(.chat-inbox) .app-header,
  body:has(.chat-standalone) .app-header { padding: 8px 12px; row-gap: 4px; }
  body:has(.chat-inbox) #logout-btn,
  body:has(.chat-standalone) #logout-btn { padding: 6px 12px; font-size: 0.82rem; }

  /* Filters: one swipeable row instead of three stacked ones. */
  .chat-filters { flex-direction: row; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .chat-filters::-webkit-scrollbar { display: none; }
  .chat-filters .chat-chip-row { flex-wrap: nowrap; flex: none; }
  .chat-chip { white-space: nowrap; padding: 6px 12px; }
  .chat-list-head { padding: 10px 12px 4px; }
  .chat-filters, .chat-push-slot { padding-inline: 12px; }
  .chat-search { margin: 8px 12px 4px; }
  .chat-row { padding: 10px 12px; }

  /* The notifications prompt as a slim strip. */
  .chat-push-card { padding: 8px 10px; font-size: 0.8rem; gap: 6px; }
  .chat-push-card span { min-width: 0; }

  /* iPhone zooms the page into any field under 16px when tapped — keep them at 16px. */
  .chat-search input,
  .chat-composer textarea,
  .chat-snippet-form input,
  .chat-snippet-form textarea,
  .chat-info-notes textarea,
  .chat-bc-body,
  .chat-bc-select,
  .chat-picker input { font-size: 16px; }

  /* Conversation header: keep the name readable, the sub-line short. */
  .chat-conv-head { padding: 8px 10px; gap: 8px; }
  .chat-conv-sub { font-size: 0.74rem; line-height: 1.3; }
  .chat-conv-actions .btn { font-size: 0.76rem; }

  /* Drawers and modals use the full width. */
  .chat-sheet { inset-inline: 4px; bottom: 62px; max-height: 70%; }
  .modal-box.chat-broadcast, .modal-box.chat-picker { padding: 16px; max-height: 88vh; }
  .chat-bc-checks { gap: 8px 12px; }
  .chat-bc-history { max-height: 140px; }

  /* Participant's own chat list. */
  .chat-channel-card { padding: 12px 14px; }
  .chat-channel-card .chat-avatar { width: 48px; height: 48px; }
}

@media (max-width: 760px) {
  /* Grid children default to min-width:auto — without this the unwrapped filter row widens the
     list column past the screen and its left edge gets cut off. */
  .chat-inbox, .chat-list-pane, .chat-conv-pane, .chat-filters { min-width: 0; max-width: 100%; }
  .chat-list-pane { overflow: hidden; }

  /* Participant / staff header in the chat screens: one tidy row of short links. */
  body:has(.chat-inbox) #who,
  body:has(.chat-standalone) #who,
  body:has(.chat-home) #who { display: none; }
  body:has(.chat-inbox) .app-header .back-link,
  body:has(.chat-standalone) .app-header .back-link,
  body:has(.chat-home) .app-header .back-link { white-space: nowrap; font-size: 0.82rem; }
  body:has(.chat-standalone) .app-header > div:last-child,
  body:has(.chat-home) .app-header > div:last-child,
  body:has(.chat-inbox) .app-header > div:last-child { gap: 10px; flex-wrap: wrap; row-gap: 4px; }
  body:has(.chat-home) .app-header { padding: 8px 12px; row-gap: 4px; }
  body:has(.chat-home) #logout-btn { padding: 6px 12px; font-size: 0.82rem; }
}

/* Broadcast: hand-picked recipients. */
.chat-bc-people { margin-top: 8px; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; }
.chat-bc-person { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); cursor: pointer; font-size: 0.92rem; }
.chat-bc-person input { width: 18px; height: 18px; flex: none; }
@media (max-width: 760px) { #bc-manual-q { font-size: 16px; } .chat-bc-people { max-height: 40vh; } }

/* Phones, keyboard up while typing in the chat (set by chatFitToKeyboard): the conversation gets
   the whole visible screen. */
@media (max-width: 760px) {
  body.chat-kb-open .app-header,
  body.chat-kb-open .view-as-bar { display: none; }
  body.chat-kb-open main { padding-top: 0; }
  body.chat-kb-open .chat-inbox,
  body.chat-kb-open .chat-standalone .chat-conv { min-height: 0; border-radius: 0; }
}
