/* ========================================
 * COMUNICACIÓ — Estils xat intern
 * Fase 3b: Layout redesign (9 mar 2026)
 * ======================================== */

/* ── Container principal ── */
.chat-container {
  display: flex;
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px); /* Dynamic viewport per mòbil */
  overflow: hidden;
}

/* ── Sidebar canals ── */
.chat-sidebar {
  width: 360px;
  min-width: 360px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-primary);
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-sidebar-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.chat-sidebar-header .btn-sm {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 20px;
}

.chat-canals-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  -webkit-overflow-scrolling: touch;
}

/* ── Notícies (canal general) — fix sobre els tabs ── */
.chat-noticies-section {
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-noticies-section .chat-canal-item {
  border-radius: 0;
}

/* ── Tabs navegació canals ── */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  padding: 4px 4px 0;
  gap: 2px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--color-bg-primary);
  z-index: 2;
}

.chat-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 2px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.73rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  color: var(--color-text-tertiary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  position: relative;
  border-radius: 0;
}

.chat-tab .material-symbols-outlined {
  font-size: 16px;
  flex-shrink: 0;
  display: none;
}

/* Mòbil: mostrar icones (hi ha més espai amb 100% width) */
@media (max-width: 1023px) {
  .chat-tab .material-symbols-outlined {
    display: inline;
  }
}

.chat-tab:hover {
  color: var(--color-text-secondary);
  background: var(--color-bg-hover);
}

.chat-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.chat-tab-label {
  white-space: nowrap;
}

.chat-tab-badge {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
  line-height: 1.3;
}

.chat-tab-content {
  padding-top: 4px;
}

/* ── Tab action button (FCT crear) ── */
.chat-tab-action {
  padding: var(--space-2) var(--space-3);
}

.chat-tab-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  justify-content: center;
}

.chat-tab-action-btn .material-symbols-outlined {
  font-size: 18px;
}

/* ── FCT modal membres ── */
.fct-membres-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
}

.fct-section-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  margin: var(--space-1) 0;
}

.fct-section-label--spaced {
  margin-top: var(--space-2);
}

.fct-membre-rol {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

.fct-empty-membres {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

/* ── Canal color bar (línia vertical formació) ── */
.chat-canal-color-bar {
  width: 4px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Canal item ── */
.chat-canal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.chat-canal-item:hover {
  background: var(--color-bg-hover);
}

.chat-canal-item.active {
  background: var(--color-primary-light, rgba(19, 117, 188, 0.1));
}

.chat-canal-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-canal-icon .material-symbols-outlined {
  font-size: 20px;
  color: var(--color-text-secondary);
}

.chat-canal-icon-avatar {
  font-size: 0.8rem;
  font-weight: 700;
}

/* Icona color per tipus especial */
.chat-canal-item[data-tipus="general"] .chat-canal-icon {
  background: rgba(99, 102, 241, 0.12);
}
.chat-canal-item[data-tipus="general"] .chat-canal-icon .material-symbols-outlined {
  color: #6366f1;
}
.chat-canal-item[data-tipus="coordinacio"] .chat-canal-icon {
  background: rgba(99, 102, 241, 0.12);
}
.chat-canal-item[data-tipus="coordinacio"] .chat-canal-icon .material-symbols-outlined {
  color: #6366f1;
}
.chat-canal-item[data-tipus="professors"] .chat-canal-icon {
  background: rgba(245, 158, 11, 0.12);
}
.chat-canal-item[data-tipus="professors"] .chat-canal-icon .material-symbols-outlined {
  color: #f59e0b;
}
.chat-canal-item[data-tipus="grup"] .chat-canal-icon {
  background: rgba(59, 130, 246, 0.12);
}
.chat-canal-item[data-tipus="grup"] .chat-canal-icon .material-symbols-outlined {
  color: #3b82f6;
}
.chat-canal-item[data-tipus="claustro"] .chat-canal-icon {
  background: rgba(139, 92, 246, 0.12);
}
.chat-canal-item[data-tipus="claustro"] .chat-canal-icon .material-symbols-outlined {
  color: #8b5cf6;
}

.chat-canal-info {
  flex: 1;
  min-width: 0;
}

.chat-canal-nom {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-canal-preview {
  font-size: 0.8rem;
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}


.chat-canal-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.chat-canal-time {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
}

.chat-canal-badge {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.chat-canal-item.has-unread .chat-canal-nom {
  font-weight: 700;
}

.chat-canal-item.has-unread .chat-canal-preview {
  color: var(--color-text-primary);
  font-weight: 500;
}

/* ── Area principal xat ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--color-bg-secondary, var(--color-bg-primary));
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--color-text-tertiary);
}

.chat-empty .material-symbols-outlined {
  font-size: 64px;
  opacity: 0.3;
}

.chat-empty p {
  font-size: 1rem;
}

/* ── Header canal ── */
.chat-main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  flex-shrink: 0;
  z-index: 5;
}

.chat-main-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-color-bar {
  width: 4px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chat-header-text {
  min-width: 0;
}

.chat-main-header-info h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-membres-count {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
}

.chat-main-header-info {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.chat-main-header-info:hover {
  background: var(--color-bg-secondary, rgba(0, 0, 0, 0.04));
}

.chat-header-chevron {
  font-size: 20px;
  color: var(--color-text-tertiary);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.chat-main-header-info[aria-expanded="true"] .chat-header-chevron {
  transform: rotate(180deg);
}

/* Botó engranatge config rols (Admin) */
.chat-header-config-btn {
  flex-shrink: 0;
  color: var(--color-text-tertiary);
  transition: color 0.15s, background 0.15s;
}
.chat-header-config-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-secondary, rgba(0, 0, 0, 0.04));
}

/* ── Modal configuració rols permesos ── */
.chat-rols-config-info {
  font-size: 0.875rem;
  color: var(--color-text-tertiary);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--color-bg-secondary, rgba(0, 0, 0, 0.03));
  border-radius: 8px;
}
.chat-rols-config-info .chat-rols-config-tipus {
  font-weight: 600;
  color: var(--color-text-primary);
}
.chat-rols-config-info .chat-rols-config-default-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 10px;
  background: var(--color-primary-soft, rgba(94, 92, 230, 0.12));
  color: var(--color-primary, #5E5CE6);
}
.chat-rols-config-info .chat-rols-config-override-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 10px;
  background: rgba(255, 149, 0, 0.15);
  color: #ff9500;
}

.chat-rols-config-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-rols-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg-primary);
  transition: border-color 0.15s;
}
.chat-rols-config-row:has(input:checked) {
  border-color: var(--color-primary, #5E5CE6);
}
.chat-rols-config-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-rols-config-rol-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chat-rols-config-rol-name {
  font-weight: 500;
  color: var(--color-text-primary);
}
.chat-rols-config-row input[type="checkbox"][disabled] + .chat-rols-config-rol-name {
  color: var(--color-text-tertiary);
}
.chat-rols-config-row-lock {
  font-size: 16px;
  color: var(--color-text-tertiary);
  margin-left: 4px;
}

/* iOS-style toggle */
.chat-rols-config-toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.chat-rols-config-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.chat-rols-config-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-rols-config-toggle-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.chat-rols-config-toggle input:checked + .chat-rols-config-toggle-slider {
  background: #34C759;
}
.chat-rols-config-toggle input:checked + .chat-rols-config-toggle-slider::before {
  transform: translateX(18px);
}
.chat-rols-config-toggle input[disabled] + .chat-rols-config-toggle-slider {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-rols-config-preview {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--color-bg-secondary, rgba(0, 0, 0, 0.03));
  border-radius: 8px;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}
.chat-rols-config-preview .chat-rols-config-preview-add {
  color: #34C759;
  font-weight: 600;
}
.chat-rols-config-preview .chat-rols-config-preview-remove {
  color: #FF3B30;
  font-weight: 600;
}

/* ── Panel de membres ── */

.chat-membres-panel {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-membres-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-primary);
}

.chat-membres-panel-header .material-symbols-outlined {
  font-size: 18px;
}

.chat-membres-panel-close {
  margin-left: auto;
}

.chat-membres-panel-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 40vh;
}

.chat-membre-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
}

.chat-membre-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.chat-membre-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.chat-membre-nom {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-membre-rol {
  font-size: 0.7rem;
  font-weight: 500;
}

.chat-membre-excloure-btn,
.chat-membre-incloure-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.chat-membre-excloure-btn .material-symbols-outlined,
.chat-membre-incloure-btn .material-symbols-outlined {
  font-size: 18px;
}

.chat-membre-excloure-btn:hover {
  color: var(--color-error, #ef4444);
  background: rgba(239, 68, 68, 0.1);
}

.chat-membre-incloure-btn:hover {
  color: var(--color-success, #22c55e);
  background: rgba(34, 197, 94, 0.1);
}

.chat-membre-exclos {
  opacity: 0.7;
}

.chat-membre-tutor-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  vertical-align: middle;
}

@media (prefers-color-scheme: dark) {
  .chat-membre-tutor-badge {
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
  }
}

/* ── Banner tauló informatiu ── */
.chat-taulon-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-info-bg, rgba(59, 130, 246, 0.08));
  color: var(--color-info-text, #2563eb);
  font-size: 0.8rem;
  font-weight: 500;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.chat-taulon-banner .material-symbols-outlined {
  font-size: 18px;
}

@media (prefers-color-scheme: dark) {
  .chat-taulon-banner {
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
  }
}

/* ── Missatges scroll ── */
.chat-missatges {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-missatges-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

/* Empenta missatges al fons */
.chat-missatges-scroll::before {
  content: '';
  flex: 1;
}

/* ── Missatge bubble (Slack flat style) ── */
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  padding: 4px 0;
}

.chat-msg.msg-own {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 92%;
}

.chat-msg.msg-other {
  align-self: flex-start;
}

/* DMs: sense avatar, missatges aprofiten més ample */
.chat-main[data-canal-tipus="direct"] .chat-msg.msg-other {
  max-width: 92%;
}

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

.chat-msg-avatar-sm {
  width: 24px;
  height: 24px;
  font-size: 0.6rem;
}

/* Avatar inicials a la llista de canals (preview últim missatge) */
.chat-canal-preview-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.55rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-right: 5px;
  vertical-align: middle;
}

.chat-msg-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chat-msg-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* Noms clicables → obrir DM */
.chat-dm-link {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.chat-dm-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.chat-msg-time {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
}

.chat-msg-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  /* TS-172 Fase 2: swipe-to-reply. Variables actualitzades pel JS al drag. */
  --swipe-dx: 0px;
  --swipe-progress: 0;
  position: relative;
  transform: translateX(var(--swipe-dx));
  /* TS-172 v6 fix iOS Safari: el long-press nadiu d'iOS mostrava el menu
     "Copy / Share / Lookup" abans que el JS pogués processar el gest, i
     l'usuari mai veia el nostre picker. -webkit-touch-callout:none desactiva
     aquell menu del sistema sense afectar selecció de text al children. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.chat-msg-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  /* user-select:none hereta del bubble per evitar interferència del long-press
     iOS amb la selecció de text. Per copiar el text d'un missatge: long-press
     → botó "Copiar" al picker (substitueix la funció nativa que perdem). */
}
/* TS-172 v3 fix #4: imatges amb marc fi (sense globo gros). Si la bombolla
   només conté imatge, el padding i background s'eliminen i la imatge es veu
   amb només una vora subtil. */
.chat-msg-bubble.image-only {
  padding: 2px;
  background: transparent !important;
  border: 1px solid var(--color-border, #e0e0e0);
}
.msg-own .chat-msg-bubble.image-only {
  background: transparent !important;
}
.chat-msg-bubble.image-only .chat-msg-image {
  margin: 0;
  max-width: 240px;
}
/* TS-187 (1 jul 2026): quan la bombolla només conté un adjunt de fitxer sense
   text, la card del fitxer ja té border+background propis — el globo del
   missatge sobra i fa el conjunt visualment recarregat. */
.chat-msg-bubble.file-only {
  padding: 0;
  background: transparent !important;
  border: none;
}
.msg-own .chat-msg-bubble.file-only {
  background: transparent !important;
}
.chat-msg-bubble.file-only .taulon-card-fitxer {
  margin-top: 0;
  max-width: 320px;
}
.chat-msg-bubble.chat-msg-swiping {
  transition: none;
  /* Indicador visual ↩ darrere de la bombolla, opacity creix amb el progrés */
}
.chat-msg-bubble.chat-msg-swiping::before {
  content: 'reply';
  font-family: 'Material Symbols Outlined', sans-serif;
  position: absolute;
  left: -36px;
  top: 50%;
  transform: translateY(-50%) scale(calc(0.6 + 0.4 * var(--swipe-progress)));
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary, #2563eb);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  opacity: var(--swipe-progress);
  pointer-events: none;
}
.chat-msg-bubble.chat-msg-swipe-snap {
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* TS-172 Fase 5.7: panel cerca dins canal (sota header) */
.chat-search-panel {
  background: var(--color-bg-elevated, #fff);
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  max-height: 50vh;
  overflow-y: auto;
  animation: typingFade 200ms ease-out;
}
.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  position: sticky;
  top: 0;
  background: var(--color-bg-elevated, #fff);
  z-index: 1;
}
.chat-search-bar > .material-symbols-outlined {
  color: var(--color-text-secondary, #6b7280);
  font-size: 18px;
}
.chat-search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  outline: none;
  color: var(--color-text-primary, #111);
}
.chat-search-results {
  padding: 4px 0;
}
.chat-search-result {
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border, #f3f4f6);
  transition: background 0.1s;
}
.chat-search-result:hover {
  background: var(--color-bg-hover, #f9fafb);
}
.chat-search-result-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-text-secondary, #6b7280);
  margin-bottom: 2px;
}
.chat-search-result-text {
  font-size: 13px;
  color: var(--color-text-primary, #111);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-search-result-text mark {
  background: rgba(245, 158, 11, 0.3);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* TS-172 Fase 5.5: badge "missatge fixat" (push_pin) */
.chat-msg-pin-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: var(--color-warning, #d97706);
  margin-bottom: 2px;
  margin-left: 2px;
}
.chat-msg-pin-badge .material-symbols-outlined {
  font-size: 14px;
  font-variation-settings: 'FILL' 1, 'wght' 500;
  transform: rotate(35deg);
}
.chat-msg-wrapper[data-fixat="true"] .chat-msg-bubble {
  border-left: 3px solid var(--color-warning, #d97706);
}

/* TS-172 v2: imatges dins missatge xat (upload real des del dispositiu) */
.chat-msg-image {
  margin: 4px 0;
  max-width: 280px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-bg-base, #f3f4f6);
}
.chat-msg-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  cursor: zoom-in; /* TS-172 v7: indicador visual que es pot ampliar */
}

/* TS-172 v7: lightbox per veure imatges del xat a pantalla completa.
   Tancament amb ESC, click overlay, swipe down (mòbil) o botó × */
.chat-lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: zoom-out;
}
.chat-lightbox-overlay.active {
  opacity: 1;
}
.chat-lightbox-image {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  /* TS-iphone-zoom: ara la imatge capta gestos (pinch-zoom + pan propi).
     touch-action: none deixa que JS controli tots els touches sense que
     iOS Safari zomi la pàgina. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform: scale(0.92);
  transform-origin: center center;
  transition: transform 0.2s ease;
  will-change: transform;
}
.chat-lightbox-overlay.active .chat-lightbox-image {
  transform: scale(1);
}
/* Quan està en mode zoom actiu, eliminar la transició perquè el moviment
   sigui directe (gesture-following). */
.chat-lightbox-image.is-zooming {
  transition: none;
}
.chat-lightbox-close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.chat-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.28);
}
.chat-lightbox-close .material-symbols-outlined {
  font-size: 24px;
}
/* Botó adjuntar foto al composer */
.chat-input-attach {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  color: var(--color-text-secondary, #6b7280);
  transition: background 0.1s, color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-input-attach:hover {
  background: var(--color-bg-hover, #f3f4f6);
  color: var(--color-primary, #2563eb);
}
.chat-input-attach .material-symbols-outlined {
  font-size: 22px;
}

/* Wrapper amb popup vertical d'opcions d'adjuntar (Arxiu / Foto / Càmera) */
.chat-input-attach-wrapper {
  position: relative;
  flex-shrink: 0;
}
.chat-attach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--color-bg-elevated, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  padding: 4px;
  min-width: 160px;
  z-index: 100;
  animation: chat-attach-menu-in 0.15s ease-out;
}
.chat-attach-menu[hidden] { display: none; }

@keyframes chat-attach-menu-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-attach-menu-item {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--color-text-primary);
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
  width: 100%;
}
.chat-attach-menu-item:hover {
  background: var(--color-bg-hover, #f3f4f6);
}
.chat-attach-menu-item .material-symbols-outlined {
  font-size: 20px;
  color: var(--color-primary);
}

@media (prefers-color-scheme: dark) {
  .chat-attach-menu {
    background: var(--color-bg-elevated, #1f2937);
    border-color: var(--color-border, #374151);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
  .chat-attach-menu-item:hover {
    background: var(--color-bg-hover, #374151);
  }
}

/* Chip de previsualització d'arxiu seleccionat al composer */
.chat-input-fitxer-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-right: 6px;
  background: var(--color-bg-card, #f3f4f6);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 18px;
  font-size: 0.82rem;
  color: var(--color-text-primary);
  flex-shrink: 0;
  max-width: 240px;
}
.chat-input-fitxer-chip .material-symbols-outlined {
  font-size: 18px;
  color: var(--color-primary);
}
.chat-input-fitxer-nom {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.chat-input-fitxer-mida {
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  flex-shrink: 0;
}
.chat-input-fitxer-remove {
  background: none;
  border: none;
  padding: 2px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
}
.chat-input-fitxer-remove:hover {
  background: var(--color-bg-hover);
  color: var(--color-danger);
}
.chat-input-fitxer-remove .material-symbols-outlined {
  font-size: 16px;
  color: inherit;
}

/* TS-172 v2: preview imatge seleccionada al composer (abans d'enviar) */
.chat-input-preview {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 6px;
}
.chat-input-preview img {
  max-width: 70px;
  max-height: 70px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}
.chat-input-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--color-danger, #ef4444);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.chat-input-preview-remove .material-symbols-outlined {
  font-size: 14px;
}

/* TS-172 Fase 4: badge "↪ Reenviat de X" dins la bombolla */
.chat-msg-forwarded {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-style: italic;
  color: var(--color-text-secondary, #6b7280);
  margin-bottom: 4px;
  opacity: 0.8;
}
.chat-msg-forwarded .material-symbols-outlined {
  font-size: 14px;
}

/* TS-172 Fase 4: modal reenviar — items checklist */
.chat-forward-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.chat-forward-item:hover {
  background: var(--color-bg-hover, #f5f5f5);
}
.chat-forward-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
.chat-forward-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-forward-item-tipus {
  font-size: 11px;
  color: var(--color-text-secondary, #6b7280);
  background: var(--color-bg-base, #f3f4f6);
  padding: 2px 8px;
  border-radius: 10px;
}

/* TS-172 Fase 3.5: typing indicator.
   Span ARIA-live invisible (només per a screen readers).
   La indicació visual es renderitza com a bombolla al feed (.chat-typing-bubble). */
.chat-typing-indicator {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Bombolla al feed amb 3 punts animats (estil Telegram/WhatsApp). */
.chat-typing-bubble {
  animation: typingBubbleIn 0.2s ease-out;
}
.chat-typing-bubble-inner {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  padding: 10px 14px !important;
  min-width: auto;
}
.chat-typing-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-secondary, #6b7280);
  opacity: 0.4;
  animation: typingDot 1.4s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes typingDot {
  0%, 60%, 100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}
@keyframes typingBubbleIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* TS-172 Fase 3: read receipts (només DM) — ✓ enviat / ✓✓ blau llegit */
.chat-msg-receipt {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  vertical-align: middle;
}
.chat-msg-receipt .material-symbols-outlined {
  font-size: 14px;
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 14;
}
.chat-msg-receipt.sent .material-symbols-outlined {
  color: var(--color-text-secondary, #9ca3af);
}
.chat-msg-receipt.read .material-symbols-outlined {
  color: var(--color-primary, #2563eb);
  animation: receiptRead 250ms ease-out;
}
@keyframes receiptRead {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* TS-172 Fase 2: hover toolbar (desktop) — 3 accions ràpides al sobrevolar bombolla.
   Mòbil: ocult absolut (display:none + !important per evitar afegir espai vertical).
   Hover desktop revela amb display:flex via override específic. */
.chat-msg-toolbar {
  display: none !important;
  position: absolute;
  top: -16px;
  gap: 2px;
  padding: 3px 4px;
  background: var(--color-bg-elevated, #fff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
  transform: translateY(4px);
  z-index: 5;
}
.msg-own .chat-msg-toolbar { right: 8px; }
.msg-other .chat-msg-toolbar { left: 8px; }
@media (hover: hover) and (pointer: fine) {
  .chat-msg-bubble:hover .chat-msg-toolbar,
  .chat-msg-toolbar:hover {
    display: flex !important;
    opacity: 1;
    transform: translateY(0);
  }
}
.chat-msg-toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-secondary, #666);
  transition: background 0.1s, color 0.1s;
  font-size: 12px;
  font-family: inherit;
}
.chat-msg-toolbar-btn:hover {
  background: var(--color-hover, #e8e8e8);
  color: var(--color-primary, #2563eb);
}
.chat-msg-toolbar-btn .material-symbols-outlined {
  font-size: 16px;
}
.chat-msg-toolbar-label {
  font-weight: 500;
}
@media (prefers-color-scheme: dark) {
  .chat-msg-toolbar {
    background: var(--color-bg-elevated, #2a2a2a);
    border-color: var(--color-border, #444);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  }
  .chat-msg-toolbar-btn:hover {
    background: var(--color-hover, #333);
  }
}

.msg-own .chat-msg-bubble {
  background: #d0e8ff;
  color: #1a1a1a;
  border-bottom-right-radius: 4px;
}

.msg-other .chat-msg-bubble {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  border-bottom-left-radius: 4px;
}

.chat-msg-bubble.msg-deleted {
  opacity: 0.5;
  font-style: italic;
}

/* ── Missatge sistema ── */
.chat-msg-sistema {
  text-align: center;
  padding: 8px 16px;
  color: var(--color-text-tertiary);
  font-size: 0.8rem;
  font-style: italic;
}

.chat-msg-sistema-academic {
  background: var(--color-bg-warning-subtle, rgba(245, 158, 11, 0.1));
  border-radius: 8px;
  margin: 4px 16px;
  padding: 10px 16px;
  font-style: normal;
  color: var(--color-text-secondary);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ── Seccions canals ── */
.chat-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-tertiary);
}
.chat-section-header .material-symbols-outlined {
  font-size: 16px;
}
.chat-section-subheader {
  padding: 6px 16px 2px 28px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: capitalize;
}

/* ── Separador data ── */
.chat-date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px;
}

.chat-date-separator::before,
.chat-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.chat-date-separator span {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  white-space: nowrap;
}

/* ── Load more ── */
.chat-load-more {
  text-align: center;
  padding: 8px;
}

.chat-load-more button {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 12px;
}

.chat-load-more button:hover {
  text-decoration: underline;
}

/* ── Input area ── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  position: relative; /* Per dropdown mencions */
  flex-shrink: 0;
}

.chat-readonly-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  color: var(--color-text-tertiary);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.chat-readonly-banner .material-symbols-outlined {
  font-size: 18px;
}

.chat-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 10px 16px;
  /* iOS Safari zoom fix: font-size < 16px triggers auto-zoom on focus */
  font-size: 16px;
  font-family: inherit;
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  max-height: 120px;
  line-height: 1.4;
}

.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send .material-symbols-outlined {
  font-size: 20px;
}

/* ── Connexió status ── */
.chat-connection-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  font-size: 0.75rem;
  background: var(--color-warning-bg, #fef3cd);
  color: var(--color-warning-text, #856404);
}

.chat-connection-status.connected {
  display: none;
}

.chat-connection-status.disconnected {
  background: var(--color-error-bg, #fee2e2);
  color: var(--color-error, #ef4444);
  animation: sseReconnectPulse 2s ease-in-out infinite;
}

@keyframes sseReconnectPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── Message wrapper ── */
.chat-msg-wrapper {
  position: relative;
  /* Fix mòbil: sense min-width:0, els flex items hereten min-width:auto i
     el reply-quote amb white-space:nowrap pot fer que la bombolla sobresurti
     del 92% del pare .chat-msg. Amb min-width:0, la bombolla respecta el
     constraint del pare i el text del quote es trunca amb ellipsis. */
  min-width: 0;
  max-width: 100%;
}

/* Mateix motiu: la bombolla ha de poder encongir-se dins del wrapper. */
.chat-msg-bubble {
  min-width: 0;
  max-width: 100%;
}

/* ── Context menu (Apple HIG) ── */
.chat-context-menu {
  position: fixed;
  z-index: 1000;
  display: none;
  flex-direction: column;
  min-width: 180px;
  background: var(--color-bg-primary, #fff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
  padding: 4px 0;
}

.chat-context-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--color-text-primary);
  text-align: left;
  transition: background 0.1s;
}

.chat-context-menu button:hover {
  background: var(--color-bg-hover, #f3f4f6);
}

.chat-context-menu button .material-symbols-outlined {
  font-size: 20px;
  color: var(--color-text-secondary);
}

.chat-context-menu button[data-action="delete"] {
  color: #ef4444;
}
.chat-context-menu button[data-action="delete"] .material-symbols-outlined {
  color: #ef4444;
}

/* ── Reply quote DINS la bombolla (estil WhatsApp) — TS-148 ── */
.chat-msg-bubble.has-reply {
  padding-top: 6px;
}

.chat-msg-bubble .chat-reply-quote {
  border-left: 3px solid var(--color-primary, #2563eb);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 100%;
  transition: background 0.15s;
}

.chat-msg-bubble .chat-reply-quote:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Bombolla pròpia light mode (#d0e8ff fons blau clar + text fosc) — quote: blau més intens, text fosc */
.msg-own .chat-msg-bubble .chat-reply-quote {
  background: rgba(37, 99, 235, 0.12);
  border-left-color: var(--color-primary, #2563eb);
}
.msg-own .chat-msg-bubble .chat-reply-quote:hover {
  background: rgba(37, 99, 235, 0.18);
}

.chat-msg-bubble-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-reply-quote-author {
  font-weight: 600;
  color: var(--color-primary, #2563eb);
}

.msg-own .chat-reply-quote-author {
  color: var(--color-primary, #2563eb);
}

.chat-reply-quote-text {
  color: var(--color-text-secondary);
  /* Fix mòbil (14 maig 2026): nowrap + ellipsis no contenia el flex item
     i la bombolla sortia del 92%. Canviat a clamp 2 línies (patró WhatsApp).
     word-break per a URLs llargues / paraules sense espais. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
  /* Constraint explícita: el text ocupa l'ample del seu pare flex i no més. */
  min-width: 0;
  max-width: 100%;
}

.msg-own .chat-reply-quote-text {
  color: rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  .chat-msg-bubble .chat-reply-quote {
    background: rgba(255, 255, 255, 0.06);
  }
  .chat-msg-bubble .chat-reply-quote:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  /* Bombolla pròpia dark mode (#1e3a5f fons blau fosc + text clar) — quote: fons translúcid clar, text clar */
  .msg-own .chat-msg-bubble .chat-reply-quote {
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--color-primary-light, #93c5fd);
  }
  .msg-own .chat-msg-bubble .chat-reply-quote:hover {
    background: rgba(255, 255, 255, 0.16);
  }
  .msg-own .chat-reply-quote-author {
    color: #93c5fd;
  }
  .msg-own .chat-reply-quote-text {
    color: rgba(224, 236, 248, 0.85);
  }
}

/* ── Compose bar (reply/edit preview above input) ── */
.chat-compose-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-bg-elevated, #f8f9fa);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-compose-bar-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-compose-bar-icon {
  font-size: 20px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.chat-compose-bar-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-compose-bar-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-primary);
}

.chat-compose-bar-preview {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-compose-bar-close {
  flex-shrink: 0;
}

/* ── Edited label ── */
.chat-msg-edited {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
  margin-left: 4px;
  font-style: italic;
}

/* ── Message highlight (scroll-to animation) ── */
.chat-msg-highlight {
  animation: msgHighlight 1.5s ease;
}

@keyframes msgHighlight {
  0%, 30% { background: rgba(37, 99, 235, 0.12); }
  100% { background: transparent; }
}

/* ── Reaccions ── */
.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.chat-reaction {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e0e0e0);
  background: var(--color-surface, #f5f5f5);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s;
}

.chat-reaction:hover {
  background: var(--color-hover, #e8e8e8);
}

.chat-reaction.mine {
  border-color: var(--color-primary, #2563eb);
  background: rgba(37, 99, 235, 0.1);
}

.chat-reaction-count {
  font-size: 12px;
  color: var(--color-text-secondary, #666);
}

/* TS-172: Emoji picker popover — viewport-aware, posicionat al punt de tap.
   v5: ara conté també una fila d'accions (Respondre / Reenviar) sota els emojis
   per a touch devices que no veuen el toolbar hover desktop. */
.chat-emoji-picker {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 6px;
  background: var(--color-surface-elevated, #fff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  z-index: 10000;
  animation: chatPopupIn 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-emoji-row {
  display: flex;
  gap: 2px;
}
.chat-emoji-actions-row {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--color-border, #e0e0e0);
  padding-top: 4px;
  margin-top: 2px;
}
.chat-emoji-action {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--color-text-primary, #111);
  font-family: inherit;
  flex: 1;
  justify-content: center;
}
.chat-emoji-action:hover,
.chat-emoji-action:active {
  background: var(--color-bg-hover, #f3f4f6);
  color: var(--color-primary, #2563eb);
}
.chat-emoji-action .material-symbols-outlined {
  font-size: 18px;
}
@media (prefers-color-scheme: dark) {
  .chat-emoji-actions-row { border-top-color: var(--color-border, #444); }
  .chat-emoji-action:hover, .chat-emoji-action:active {
    background: var(--color-hover, #333);
  }
}
@keyframes chatPopupIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.chat-emoji-option {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  padding: 6px 8px;
  border-radius: 50%;
  transition: background 0.1s, transform 0.1s;
}

.chat-emoji-option:hover {
  background: var(--color-hover, #e8e8e8);
  transform: scale(1.15);
}

/* TS-172: Popup llista d'usuaris que han reaccionat (long-press / right-click sobre .chat-reaction) */
.chat-reaccions-popup {
  position: fixed;
  min-width: 220px;
  max-width: 280px;
  max-height: 320px;
  background: var(--color-surface-elevated, #fff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 10000;
  overflow: hidden;
  animation: chatPopupIn 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-reaccions-popup-header {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border, #e0e0e0);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-reaccions-popup-header span {
  color: var(--color-text-secondary, #666);
  font-weight: 400;
  font-size: 13px;
}
.chat-reaccions-popup-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 0;
}
.chat-reaccions-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 14px;
}
.chat-reaccions-popup-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary, #2563eb);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.chat-reaccions-popup-name {
  flex: 1;
  color: var(--color-text-primary, #1a1a1a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .chat-reaction {
    border-color: var(--color-border, #333);
    background: var(--color-surface, #1e1e1e);
  }
  .chat-reaction:hover {
    background: var(--color-hover, #2a2a2a);
  }
  .chat-reaction.mine {
    border-color: var(--color-primary, #60a5fa);
    background: rgba(96, 165, 250, 0.15);
  }
  .chat-emoji-picker {
    background: var(--color-surface-elevated, #2a2a2a);
    border-color: var(--color-border, #444);
  }
  .chat-emoji-option:hover {
    background: var(--color-hover, #333);
  }
  .chat-reaccions-popup {
    background: var(--color-surface-elevated, #2a2a2a);
    border-color: var(--color-border, #444);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  }
  .chat-reaccions-popup-header {
    border-bottom-color: var(--color-border, #444);
  }
  .chat-context-menu {
    background: var(--color-surface-elevated, #2a2a2a);
    border-color: var(--color-border, #444);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  }
  .chat-context-menu button:hover {
    background: var(--color-hover, #333);
  }
  .chat-reply-quote {
    background: rgba(255,255,255,0.06);
  }
  .chat-compose-bar {
    background: var(--color-surface-elevated, #1e1e1e);
  }
}

/* ========================================
   RESPONSIVE MÒBIL — Flex natural (no position:fixed)
   Elimina els bugs iOS Safari de position:fixed + teclat virtual
   ======================================== */

@media (max-width: 1023px) {
  /* Body flex column per que 100dvh funcioni naturalment amb el teclat.
     17 jun 2026: estès a /alumnat.html (data-page=alumnat). Sense aquestes
     regles el body no tenia flex column → header/tabbar fixed amagaven el
     compose btn i el scroll del xat no funcionava per a Profesor i altres
     rols staff que entrava a /alumnat.html. */
  body[data-page="comunicacio"],
  body[data-page="alumnat"] {
    overflow: hidden;
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic viewport — sobreescriu 100vh si el browser ho suporta */
    display: flex;
    flex-direction: column;
    padding-top: 0; /* Treure padding del header.css — el header participa al flex */
    padding-bottom: 0; /* Safety: cap padding residual */
    margin: 0;
    box-sizing: border-box;
  }

  /* Header: treure position:fixed perquè participi al flex 100dvh */
  body[data-page="comunicacio"] .app-header,
  body[data-page="alumnat"] .app-header {
    position: relative;
    top: auto;
  }

  /* Header i tabbar fix, chat container ocupa l'espai restant */
  body[data-page="comunicacio"] #app-header,
  body[data-page="alumnat"] #app-header {
    flex-shrink: 0;
  }

  body[data-page="comunicacio"] #app-tabbar,
  body[data-page="alumnat"] #app-tabbar {
    flex-shrink: 0;
  }

  /* Tabbar: treure position:fixed perquè participi al flex 100dvh */
  body[data-page="comunicacio"] .global-tab-bar,
  body[data-page="alumnat"] .global-tab-bar {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
  }

  .chat-container {
    flex: 1;
    height: auto;
    display: flex;
    overflow: hidden;
    min-height: 0; /* Permetre que flex:1 es comprimi correctament */
  }

  /* Amagar banner onboarding push dins comunicació — evita solapament amb input */
  body[data-page="comunicacio"] .push-onboarding-banner,
  body[data-page="alumnat"] .push-onboarding-banner {
    display: none !important;
  }

  .chat-sidebar {
    width: 100%;
    min-width: 100%;
  }

  .chat-main {
    display: none;
  }

  .chat-container.canal-obert .chat-sidebar {
    display: none;
  }

  .chat-container.canal-obert .chat-main {
    display: flex;
  }

  /* Amagar tabbar quan canal obert (patró WhatsApp/Telegram — guanya 56px) */
  .chat-container.canal-obert ~ #app-tabbar {
    display: none !important;
  }

  /* Header xat: sticky dins el flex container */
  .chat-main-header {
    position: sticky;
    top: 0;
    z-index: 10;
  }

  /* Missatges: scroll natiu amb touch */
  .chat-missatges-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Amagar tabbar quan teclat obert al xat */
  body.chat-keyboard-open #app-tabbar {
    display: none !important;
  }
}

/* Mòbil petit */
@media (max-width: 480px) {
  .chat-canal-item {
    padding: 8px 10px;
    gap: 10px;
  }

  .chat-canal-icon {
    width: 36px;
    height: 36px;
  }

  .chat-canal-icon .material-symbols-outlined {
    font-size: 18px;
  }
}

/* ── PWA standalone mode ── */
@media (display-mode: standalone) and (max-width: 1023px) {
  body[data-page="comunicacio"] {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ── Modal DM: dropdown visible ── */
#modalNouDM .modal-content {
  overflow: visible;
}
#modalNouDM .modal-body {
  overflow: visible;
  min-height: 280px;
}

/* ── @ Mencions dropdown ── */
.mention-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  margin-bottom: 4px;
  z-index: 100;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.mention-item:hover,
.mention-item.mention-highlighted {
  background: var(--color-bg-hover);
}

.mention-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary-light, rgba(19, 117, 188, 0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-primary);
  flex-shrink: 0;
}

.mention-name {
  font-size: 0.85rem;
  color: var(--color-text-primary);
}

/* Menció dins missatge */
.chat-mention {
  background: var(--color-primary-light, rgba(19, 117, 188, 0.15));
  color: var(--color-primary);
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 500;
}

/* TS-149: enllaços URL clicables dins de missatges */
.chat-link {
  color: var(--color-primary, #2563eb);
  text-decoration: underline;
  word-break: break-all;
}
.chat-link:hover {
  text-decoration: none;
  opacity: 0.85;
}
.msg-own .chat-link {
  color: var(--color-primary, #2563eb);
}

/* ── Tauló canal icon (grup) ── */
.chat-canal-item[data-tipus="grup"] .chat-canal-icon {
  background: rgba(6, 182, 212, 0.12);
}
.chat-canal-item[data-tipus="grup"] .chat-canal-icon .material-symbols-outlined {
  color: #06b6d4;
}

/* ── Section headers — XATS / TAULONS principals ── */
.chat-section-header.chat-section-main {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  padding: 16px 16px 6px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 4px;
}

/* ── Compose Sheet trigger (taulons) ── */
.chat-compose-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  flex-shrink: 0;
}

.chat-compose-trigger .btn-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 0.9rem;
}

/* ── Compose Sheet modal ── */
.compose-sheet .compose-title-input {
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.compose-sheet .compose-title-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.compose-category-picker {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.compose-cat-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}

.compose-cat-btn .material-symbols-outlined {
  font-size: 18px;
}

.compose-cat-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.compose-cat-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.compose-schedule {
  margin-top: 8px;
}

.compose-schedule-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.compose-schedule-toggle input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
}

.compose-schedule-fields {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.compose-schedule-fields .form-control {
  font-size: 16px;
  flex: 1;
}

.compose-sheet .compose-textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  line-height: 1.5;
}

.compose-sheet .compose-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Compose image upload */
.compose-image-upload {
  margin-bottom: 12px;
}

.compose-image-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.compose-image-dropzone:hover,
.compose-image-dropzone.dragover {
  border-color: var(--color-primary);
}

.compose-image-hint {
  font-size: 0.82rem;
  color: var(--color-text-tertiary);
}

.compose-image-preview {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.compose-image-preview img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  object-fit: contain;
}

.compose-image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
}

.compose-image-remove:hover {
  background: rgba(0, 0, 0, 0.75);
}

/* ── Taulon Cards ── */
/* Highlight deeplink (scroll des de dashboard) */
.msg-highlight .taulon-card-inner,
.msg-highlight .chat-msg {
  animation: msgHighlight 2s ease-out;
}

@keyframes msgHighlight {
  0% { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.4); }
  100% { box-shadow: none; }
}

.taulon-card {
  margin-bottom: 12px;
}

.taulon-card-inner {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 16px;
  background: var(--color-bg-elevated);
  transition: box-shadow 0.15s;
  position: relative;
}

/* TS-238 (15 jun 2026): stripe esquerre de color de la matèria.
   Quan la card té --taulon-stripe definit (color hex), apareix una franja a l'esquerra. */
.taulon-card--colored .taulon-card-inner {
  border-left: 4px solid var(--taulon-stripe, var(--color-primary));
  padding-left: 18px;
}

/* Chip d'assignatura (substitueix l'antic "Dirigit a" — TS-239 15 jun 2026). */
.taulon-card-modul-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  background: var(--color-bg-base);
  color: var(--color-text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  margin-left: 4px;
}

.taulon-card-inner:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.taulon-scheduled .taulon-card-inner,
.taulon-card-inner.taulon-scheduled {
  border-style: dashed;
  opacity: 0.7;
}

.taulon-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.taulon-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.taulon-card-author {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--color-text-primary);
}

.taulon-card-time {
  font-size: 0.78rem;
  color: var(--color-text-tertiary);
}

.taulon-card-cat-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.taulon-badge-scheduled {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Debat 036: Important (vora vermella) */
.taulon-card-inner.taulon-important {
  border-left: 4px solid #FF3B30;
}

/* Debat 036: Badge fixat */
.taulon-badge-pinned {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #007AFF;
  background: rgba(0, 122, 255, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Debat 036: Badge audiència */
.taulon-badge-audience {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #8b5cf6;
  background: rgba(139, 92, 246, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Debat 036: Compose options */
.compose-audience {
  margin-bottom: 12px;
}

.compose-field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.compose-audience-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compose-audience-pill {
  padding: 5px 14px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.compose-audience-pill.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.compose-options {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.compose-option-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.compose-option-toggle input[type="checkbox"] {
  margin: 0;
}

.compose-expiry {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.compose-expiry .form-control {
  max-width: 180px;
}

.taulon-card-title {
  margin: 6px 0 4px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.3;
}

/* Taulon card image */
.taulon-card-image {
  margin: 8px 0;
}

.taulon-card-image img {
  max-width: 100%;
  max-height: 500px;
  object-fit: contain;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.taulon-card-body {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--color-text-secondary);
  word-break: break-word;
  white-space: pre-wrap;
}

/* TS-149: adjunt PDF dins d'un anunci */
.taulon-card-fitxer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--color-border, rgba(0,0,0,0.1));
  border-radius: 10px;
  background: var(--color-bg-elevated, #fff);
  text-decoration: none;
  color: var(--color-text-primary);
  transition: background 0.15s, border-color 0.15s;
}
.taulon-card-fitxer:hover {
  background: var(--color-bg-hover, rgba(0,0,0,0.04));
  border-color: var(--color-primary, #2563eb);
}
.taulon-card-fitxer-icon {
  font-size: 32px;
  color: #dc2626;
  flex-shrink: 0;
}
.taulon-card-fitxer-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.taulon-card-fitxer-nom {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.taulon-card-fitxer-meta {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  margin-top: 2px;
}
.taulon-card-fitxer-dl {
  font-size: 22px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

/* Compose: bloc adjuntar PDF */
.compose-fitxer-upload {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.compose-fitxer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px dashed var(--color-border);
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 0.88rem;
  width: max-content;
}
.compose-fitxer-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}
.compose-fitxer-hint {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  margin: 0;
  line-height: 1.35;
}
.compose-fitxer-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-top: 4px;
}
.compose-fitxer-preview .material-symbols-outlined {
  color: #dc2626;
  font-size: 24px;
}
.compose-fitxer-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compose-fitxer-size {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
}
.compose-fitxer-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 4px;
}
.compose-fitxer-remove:hover {
  color: var(--color-danger);
}

.taulon-card-footer {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* TS-242 (2 jul 2026) — Badge d'ID de missatge (auditoria).
   Visible només per l'autor i staff. Discret per no distreure els altres.
   Al hover: color d'accent + subratllat perquè s'entengui que és clicable.
   Doble classe: `.taulon-card-msgid` (footer taulon) + `.msgid-badge`
   (header xats regulars). El comportament visual és el mateix. */
.msgid-badge,
.taulon-card-msgid {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-tertiary);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
  vertical-align: middle;
}
.taulon-card-msgid { margin-left: auto; }
.msgid-badge { margin-left: 8px; }
.msgid-badge:hover,
.taulon-card-msgid:hover {
  background: var(--color-bg-hover, rgba(0,0,0,0.04));
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.msgid-badge.copied,
.taulon-card-msgid.copied {
  background: var(--color-success, #059669);
  color: #fff;
  border-color: var(--color-success, #059669);
}
.msgid-badge .material-symbols-outlined,
.taulon-card-msgid .material-symbols-outlined {
  font-size: 13px;
}

/* ── Taulon Card Sistema (missatges automàtics) ── */
.taulon-card--sistema .taulon-card-inner {
  background: var(--color-bg-surface, var(--color-bg-secondary));
  border-style: solid;
  border-color: var(--color-border);
}

.taulon-card-sistema-avatar {
  background: var(--color-text-tertiary) !important;
  color: #fff !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.taulon-card--sistema .taulon-card-author {
  font-weight: 500;
  color: var(--color-text-tertiary);
  font-style: italic;
}

.taulon-card--sistema .taulon-card-title {
  font-size: 0.95rem;
  font-weight: 600;
}

/* TS-203: regles undo (chat-msg-undo, chat-msg-sending, chat-undo-bar/label/btn)
   eliminades — l'undo de 3s al enviament s'ha tret. */

.chat-msg-bubble.chat-msg-error {
  opacity: 0.5;
  border: 1px solid var(--color-error, #ef4444);
}

.chat-msg-error-label {
  font-size: 0.7rem;
  color: var(--color-error, #ef4444);
  padding: 2px 0;
  text-align: right;
}

.chat-msg-error-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  justify-content: flex-end;
}

.chat-retry-btn,
.chat-discard-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chat-retry-btn {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.chat-retry-btn:hover {
  background: var(--color-primary-light, rgba(19, 117, 188, 0.1));
}

.chat-discard-btn {
  color: var(--color-text-tertiary);
}

.chat-discard-btn:hover {
  color: var(--color-error, #ef4444);
  border-color: var(--color-error, #ef4444);
}

/* ── DM: amagar avatar (nom suficient en xats 1:1) ── */
.chat-main[data-canal-tipus="direct"] .chat-msg-avatar {
  display: none;
}

/* ── DM amb alumne — diferenciació visual (P27) ── */
.chat-canal-item.dm-alumne .chat-canal-icon {
  background: rgba(245, 158, 11, 0.12);
}
.chat-canal-item.dm-alumne .chat-canal-icon .material-symbols-outlined {
  color: #f59e0b;
}

.chat-canal-alumne-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
  vertical-align: middle;
}

/* Banner DM alumne (taronja en lloc de blau) */
.chat-taulon-banner--alumne {
  background: rgba(245, 158, 11, 0.15) !important;
  color: #92400e !important;
  font-weight: 600;
  border-bottom: 2px solid rgba(245, 158, 11, 0.4) !important;
}

/* Fons diferent a tota l'àrea de xat quan és DM amb alumne */
.chat-main--dm-alumne {
  background: rgba(245, 158, 11, 0.04);
}
.chat-main--dm-alumne .chat-missatges-scroll {
  background: rgba(245, 158, 11, 0.04);
}
.chat-main--dm-alumne .chat-main-header {
  background: rgba(245, 158, 11, 0.06);
  border-bottom-color: rgba(245, 158, 11, 0.2);
}
.chat-main--dm-alumne .chat-input-area {
  background: rgba(245, 158, 11, 0.06);
  border-top-color: rgba(245, 158, 11, 0.2);
}

/* Watermark diagonal "ALUMNAT" / "FAMÍLIA" al fons del xat (refactor maig 2026).
   El watermark es queda fix mentre els missatges es desplacen — l'scroll viu al
   fill (.chat-missatges-scroll), mentre el pseudo-element està al pare absolut.
   Inset negatiu + overflow:hidden expandeix la rotació sense vores visibles. */
.chat-main--dm-alumne .chat-missatges {
  position: relative;
  overflow: hidden;
}
.chat-main--dm-alumne .chat-missatges::before {
  content: '';
  position: absolute;
  inset: -25%;
  background-repeat: repeat;
  background-size: 320px 80px;
  transform: rotate(-22deg);
  pointer-events: none;
  opacity: 0.07;
  z-index: 0;
}
.chat-main--dm-alumne[data-altre-rol="Alumne"] .chat-missatges::before {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='80' viewBox='0 0 320 80'%3E%3Ctext x='0' y='58' font-family='-apple-system,system-ui,sans-serif' font-size='42' font-weight='900' letter-spacing='4' fill='%23ea580c'%3EALUMNAT%3C/text%3E%3C/svg%3E");
}
.chat-main--dm-alumne[data-altre-rol="Pare"] .chat-missatges::before {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='80' viewBox='0 0 320 80'%3E%3Ctext x='0' y='58' font-family='-apple-system,system-ui,sans-serif' font-size='42' font-weight='900' letter-spacing='4' fill='%23ea580c'%3EFAM%C3%8DLIA%3C/text%3E%3C/svg%3E");
}
/* Els missatges per damunt del watermark */
.chat-main--dm-alumne .chat-missatges-scroll {
  position: relative;
  z-index: 1;
}

@media (prefers-color-scheme: dark) {
  .chat-canal-item.dm-alumne .chat-canal-icon {
    background: rgba(245, 158, 11, 0.18);
  }
  .chat-canal-alumne-badge {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
  }
  .chat-taulon-banner--alumne {
    background: rgba(245, 158, 11, 0.18) !important;
    color: #fbbf24 !important;
    border-bottom-color: rgba(245, 158, 11, 0.35) !important;
  }
  .chat-main--dm-alumne {
    background: rgba(245, 158, 11, 0.06);
  }
  .chat-main--dm-alumne .chat-missatges-scroll {
    background: rgba(245, 158, 11, 0.06);
  }
  .chat-main--dm-alumne .chat-main-header {
    background: rgba(245, 158, 11, 0.08);
    border-bottom-color: rgba(245, 158, 11, 0.25);
  }
  .chat-main--dm-alumne .chat-input-area {
    background: rgba(245, 158, 11, 0.08);
    border-top-color: rgba(245, 158, 11, 0.25);
  }
}

/* ── Bubbles pròpies taronja en DMs amb Alumne/Pare ── */
.chat-main--dm-alumne .msg-own .chat-msg-bubble {
  background: #fef3c7;
  color: #1a1a1a;
}
@media (prefers-color-scheme: dark) {
  .chat-main--dm-alumne .msg-own .chat-msg-bubble {
    background: #78350f;
    color: #fef3c7;
  }
}

/* ── "Respondre en privat" button ── */
.chat-reply-private {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  margin-top: 4px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-bg-primary);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-reply-private:hover {
  background: var(--color-primary-light, rgba(19, 117, 188, 0.1));
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
  .msg-own .chat-msg-bubble {
    background: #1e3a5f;
    color: #e0ecf8;
  }

  .chat-canal-item[data-tipus="general"] .chat-canal-icon {
    background: rgba(34, 197, 94, 0.18);
  }
  .chat-canal-item[data-tipus="coordinacio"] .chat-canal-icon {
    background: rgba(239, 68, 68, 0.18);
  }
  .chat-canal-item[data-tipus="professors"] .chat-canal-icon {
    background: rgba(245, 158, 11, 0.18);
  }
  .chat-canal-item[data-tipus="formacio"] .chat-canal-icon {
    background: rgba(59, 130, 246, 0.18);
  }
  .chat-canal-item[data-tipus="claustro"] .chat-canal-icon {
    background: rgba(139, 92, 246, 0.18);
  }
  .chat-canal-item[data-tipus="grup"] .chat-canal-icon {
    background: rgba(6, 182, 212, 0.18);
  }

  .taulon-card-inner {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
  }
  .taulon-card-inner:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .compose-cat-btn {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
  }

  .chat-reply-private {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
  }
  .chat-reply-private:hover {
    background: rgba(96, 165, 250, 0.15);
    color: var(--color-primary);
  }
}

/* ========================================
   SWIPE-TO-ARCHIVE DMs
   ======================================== */

.dm-swipe-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.dm-swipe-content {
  position: relative;
  z-index: 2;
  background: var(--color-bg-primary);
  will-change: transform;
  touch-action: pan-y;
}

/* TS-257: contenidor d'accions — el swipe pot revelar 1-3 botons (data-reveal) */
.dm-swipe-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  z-index: 1;
}

.dm-swipe-action {
  position: relative;
  width: 72px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  background: #ef4444;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.dm-swipe-action:last-child {
  border-radius: 0 8px 8px 0;
}

.dm-swipe-wrapper.swiping .dm-swipe-action {
  opacity: 1;
  pointer-events: auto;
}

.dm-swipe-action .material-symbols-outlined {
  font-size: 22px;
}

.dm-swipe-action:active {
  background: #dc2626;
}

/* TS-257: variants de color de les accions del grup de treball */
.dm-swipe-action--mute {
  background: #8e8e93;
}

.dm-swipe-action--mute:active {
  background: #6d6d72;
}

.dm-swipe-action--danger {
  background: #991b1b;
}

.dm-swipe-action--danger:active {
  background: #7f1d1d;
}

/* Secció "Arxivats" al final de cada tab (TS-82) */
.chat-archived-section {
  margin-top: 12px;
  border-top: 1px solid var(--color-border);
  padding-top: 4px;
}

.chat-archived-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-align: left;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.chat-archived-header:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.chat-archived-section.expanded .chat-archived-header {
  color: var(--color-text-primary);
}

.chat-archived-header .material-symbols-outlined {
  font-size: 18px;
}

/* Items dins d'Arxivats: degradat visual per diferenciar */
.chat-archived-section .chat-canal-item {
  opacity: 0.72;
}

.chat-archived-section .chat-canal-item:hover,
.chat-archived-section .chat-canal-item.active {
  opacity: 1;
}

/* Botó desarxivar al swipe: verd en lloc del vermell d'arxivar */
.dm-swipe-wrapper[data-canal-id] .dm-swipe-action[onclick*="_desarxivarCanal"] {
  background: #16a34a;
}
.dm-swipe-wrapper[data-canal-id] .dm-swipe-action[onclick*="_desarxivarCanal"]:active {
  background: #15803d;
}

/* Context menu escriptori (click dret sobre item de canal) */
.canal-ctx-menu {
  background: var(--color-bg-elevated, var(--color-bg-card, #ffffff));
  border: 1px solid var(--color-border, rgba(0,0,0,0.1));
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 4px;
  min-width: 160px;
  animation: canalCtxMenuIn 0.12s ease-out;
}

@keyframes canalCtxMenuIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.canal-ctx-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: 0.9rem;
  text-align: left;
  transition: background 0.1s ease;
}

.canal-ctx-item:hover {
  background: var(--color-bg-hover, var(--color-bg-base, rgba(0,0,0,0.06)));
}

.canal-ctx-item .material-symbols-outlined {
  font-size: 20px;
  color: var(--color-text-secondary);
}

/* ========================================
   DM SELECTOR — Modal nou missatge directe
   ======================================== */

.dm-selector-modal .modal-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  overflow: hidden;
}

/* Search box */
.dm-search-box {
  position: relative;
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.dm-search-icon {
  position: absolute;
  left: calc(var(--spacing-md) + 10px);
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.dm-search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.dm-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(19, 117, 188, 0.12);
}

/* Role filter pills */
.dm-role-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.dm-role-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  border-radius: 20px;
  border: 1.5px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.dm-role-pill:hover {
  border-color: var(--color-text-tertiary);
}

.dm-role-pill.active {
  font-weight: 600;
}

.dm-role-pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* User list */
.dm-user-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xs) 0;
}

/* TS-307 — capçalera de secció (Personal del centre / Alumnat i famílies):
   nivell superior als grups de rol, més pes visual i sense sticky (els
   grups de rol ja són sticky i s'apilarien). */
.dm-seccio-header {
  padding: 14px var(--spacing-md) 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}
.dm-seccio-header:not(:first-child) {
  margin-top: 10px;
  border-top: 1px solid var(--color-border);
}

.dm-group-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 10px var(--spacing-md) 6px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: -4px;
  background: var(--color-bg-card);
  z-index: 1;
  border-bottom: 1px solid var(--color-border);
  padding-top: 14px;
}

.dm-group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dm-group-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  background: var(--color-bg-elevated);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.dm-user-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  width: 100%;
  padding: 8px var(--spacing-md);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s ease;
  text-align: left;
}

.dm-user-item:hover {
  background: var(--color-bg-hover);
}

.dm-user-item:active {
  background: var(--color-bg-active, var(--color-bg-hover));
}

.dm-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.dm-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dm-user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-user-fills {
  font-size: 12px;
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-empty {
  text-align: center;
  padding: var(--spacing-xl) var(--spacing-md);
  color: var(--color-text-tertiary);
  font-size: 14px;
}

/* TS-180 — DM selector al mòbil: més espai per a la llista d'usuaris quan
 * el teclat virtual ocupa la part inferior. Canvis:
 *   1. Modal usa 100dvh (dynamic viewport) en lloc d'un max-height fix.
 *      Combinat amb interactive-widget=resizes-content del meta viewport,
 *      el dvh ja descompta l'espai del teclat → la llista no queda oculta.
 *   2. Filters de rol passen de wrap (multi-línia) a una sola línia amb
 *      scroll horitzontal. Estalvia 30-60px de vertical fins i tot amb
 *      molts rols.
 *   3. Padding compactat al search box i als filters per a maximitzar la
 *      llista.
 *   4. Sticky search bar perquè sempre quedi visible mentre l'usuari
 *      escroleja la llista.
 */
@media (max-width: 768px) {
  /* Sheet quasi pantalla completa: cap padding al overlay perquè el modal
     ocupi tot l'ample. */
  #modalNouDM.modal-overlay { padding: 0; }
  .dm-selector-modal.modal-content {
    height: 100dvh;
    max-height: 100dvh;
    width: 100%;
    max-width: none;
    border-radius: 0;
    /* Override de la regla base .modal-content { overflow-y: auto } —
       no volem scroll a tot el modal, sinó dins la llista d'usuaris. */
    overflow: hidden;
    /* Convertim en flex column perquè header (fix) i body (creix) es
       distribueixin l'altura correctament. */
    display: flex;
    flex-direction: column;
  }
  .dm-selector-modal .modal-header { flex-shrink: 0; }
  .dm-selector-modal .modal-body {
    /* Pren l'altura restant. min-height:0 és imprescindible per a què el
       fill (.dm-user-list) pugui activar overflow-y: auto correctament
       (sense això, el flex item té min-height:auto i el contingut força
       l'expansió). */
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }
  .dm-user-list {
    /* flex:1 + min-height:0 perquè el scroll vertical funcioni dins del
       contenidor bounded del modal-body. */
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Search box: sticky dins el modal-body. */
  .dm-search-box {
    flex-shrink: 0;
    background: var(--color-bg-card);
    padding: 8px 12px;
  }
  .dm-role-filters {
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 6px 12px 8px;
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    /* Amaga la barra de scroll horitzontal per a una UI neta. */
    scrollbar-width: none;
  }
  .dm-role-filters::-webkit-scrollbar {
    display: none;
  }
  .dm-role-pill {
    flex-shrink: 0; /* els pills no es comprimeixen — scroll horitzontal */
    padding: 4px 10px;
    font-size: 12px;
  }
}

/* TS-191 iPhone fix: file inputs ocults però clicables via .click() a iOS PWA.
   `display: none` impedeix que el file picker s'obri en alguns navegadors
   (iOS standalone, Safari mòbil amb extension). Off-screen positioning manté
   l'input al DOM com a element vàlid clicable. */
.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Watermark a dark mode: una mica menys saturat per no ser massa prominent */
@media (prefers-color-scheme: dark) {
  .chat-main--dm-alumne .chat-missatges::before {
    opacity: 0.10;
  }
}

/* G3 (TS-184) — deeplink "Veure al calendari" a les cards sistema v2 */
.taulon-card-deeplink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-primary, #1375BC);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease;
}
.taulon-card-deeplink:hover {
  background: var(--color-primary-dark, #0f5a94);
}
.taulon-card-deeplink:visited {
  color: #fff;
}

/* TS-184 Opció B Fase 1 — chip bar filtre per MP al canal grup v2 */
.chat-mp-chips {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--color-bg-subtle, rgba(0,0,0,0.02));
  border-bottom: 1px solid var(--color-border, rgba(0,0,0,0.08));
  flex-shrink: 0;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.chat-mp-chips::-webkit-scrollbar {
  height: 4px;
}
.chat-mp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  background: var(--color-bg-card, #fff);
  color: var(--color-text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.chat-mp-chip:hover {
  background: var(--color-bg-hover, rgba(0,0,0,0.04));
}
.chat-mp-chip.active {
  background: var(--color-primary, #1375BC);
  color: #fff;
  border-color: var(--color-primary, #1375BC);
}
/* TS-238 (15 jun 2026): dot de color de matèria al chip de filtre. */
.chat-mp-chip-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}
/* TS-239 (15 jun 2026): hint de color sota el selector d'assignatura al Compose */
.compose-modul-color-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-bg-base);
  border: 1px solid var(--color-border);
  font-size: 0.72rem;
  color: var(--color-text-secondary);
}
.compose-modul-color-hint[hidden] { display: none; }
.compose-modul-color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}
@media (prefers-color-scheme: dark) {
  .chat-mp-chips {
    background: rgba(255,255,255,0.03);
    border-bottom-color: rgba(255,255,255,0.08);
  }
}

/* TS-184 Opció B Fase 2 — selector MP al Compose Sheet (canals grup v2) */
.compose-modul {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border, rgba(0,0,0,0.08));
}
.compose-modul-select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  background: var(--color-bg-card, #fff);
  color: var(--color-text-primary);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* === Banner d'assignatura prominent al top de la card (15 jun 2026 v2) ===
 * Substitueix el chip petit per una franja amb el color de la matèria.
 * És el primer que l'ull veu i fa evident a quin mòdul es refereix l'anunci.
 */
.taulon-card-modul-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px 10px 0 0;
  margin: -16px -16px 12px;
  background: var(--color-bg-base);
  color: var(--color-text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.taulon-card-modul-banner .material-symbols-outlined {
  font-size: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.taulon-card-modul-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Quan el banner té background propi (color de matèria), el separador inferior
 * sobra perquè ja contrasta amb el cos. */
.taulon-card-modul-banner[style*="background"] {
  border-bottom: none;
}

/* Encapçalament tipus "Anglès Professional (MP01) — dl. 30 set. 09:00→10:00"
 * que apareix sota el títol als missatges sistema. Resaltat amb monospace + caixa. */
.taulon-card-encap {
  display: inline-block;
  margin: 4px 0 12px;
  padding: 4px 10px;
  background: var(--color-bg-base);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* Facts estructurats (Data, Hora, Aula, Estat, Docents, Motiu) per a system cards.
 * Cada fact: icona + label + value en una fila vertical alineada. */
.taulon-card-facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 0;
  padding: 12px 14px;
  background: var(--color-bg-base);
  border-radius: 8px;
  border: 1px solid var(--color-border);
}
.taulon-fact {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
}
.taulon-fact-icon {
  font-size: 16px !important;
  flex-shrink: 0;
  color: var(--color-text-secondary);
  align-self: center;
}
.taulon-fact-label {
  flex-shrink: 0;
  min-width: 60px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
}
.taulon-fact-value {
  flex: 1;
  min-width: 0;
  color: var(--color-text-primary);
  word-break: break-word;
}
.taulon-fact-value strong, .taulon-fact-value em {
  font-weight: 700;
  font-style: normal;
}
.taulon-fact-info { color: var(--color-primary); }
.taulon-fact-warn .taulon-fact-value { color: #b45309; font-weight: 600; }
.taulon-card-prose {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-border);
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* 15 jun 2026 v3: la franja esquerra (.taulon-card--colored) s'elimina perquè
 * el banner d'assignatura al top ja porta el color. Doble accent era redundant. */
.taulon-card--colored .taulon-card-inner {
  border-left: 1px solid var(--color-border);
  padding-left: 16px;
}

/* Resum natural humà al top del cos: text gran, fàcil de llegir d'una sola ullada. */
.taulon-card-resum {
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: var(--color-bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--color-border);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text-primary);
}
.taulon-card-resum strong {
  font-weight: 700;
  color: var(--color-primary);
}
@media (prefers-color-scheme: dark) {
  .taulon-card-resum strong {
    color: var(--color-primary);
  }
}

/* === Impeccable polish /alumnat.html (15 jun 2026) ===
 * Amaga elements staff-only quan el rol és Alumne o Pare.
 * Els elements continuen al DOM (compat. amb codi existent que els referencia
 * per JS), però visualment no apareixen i no consumeixen layout.
 */
body[data-rol="Alumne"] .chat-header-config-btn,
body[data-rol="Pare"]  .chat-header-config-btn,
body[data-rol="Alumne"] .chat-header-chevron,
body[data-rol="Pare"]  .chat-header-chevron,
body[data-rol="Alumne"] #chatRolsConfigModal,
body[data-rol="Pare"]  #chatRolsConfigModal,
body[data-rol="Alumne"] #chatForwardModal,
body[data-rol="Pare"]  #chatForwardModal,
body[data-rol="Alumne"] #chatHeaderSearchBtn,
body[data-rol="Pare"]  #chatHeaderSearchBtn {
  display: none !important;
}

/* L'avatar+nom del header de canal deixa de ser clickable (no obre panel
 * de membres per a Alumne/Pare — no els aporta valor i confon). */
body[data-rol="Alumne"] #chatHeaderInfo,
body[data-rol="Pare"]  #chatHeaderInfo {
  cursor: default;
  pointer-events: none;
}

/* Empty state amb una mica més de respiració per al to més humà. */
body[data-rol="Alumne"] #chatEmpty p,
body[data-rol="Pare"]  #chatEmpty p {
  max-width: 36ch;
  line-height: 1.5;
  margin: 16px auto 0;
  text-wrap: balance;
}

/* TS-289 (6 jul 2026) — mode fosc: banner DM alumne (tint taronja + !important inline) */
@media (prefers-color-scheme: dark) {
  .chat-taulon-banner--alumne { color: #FF9F0A !important; }
}

/* ── TS-257 (Consell 041): Grups de treball autogestionats ── */

.chat-gt-header {
  position: relative;
}

.chat-gt-add-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: rgba(10, 132, 255, 0.12);
  color: var(--color-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.chat-gt-add-btn .material-symbols-outlined {
  font-size: 18px;
}

.chat-gt-add-btn:hover {
  background: rgba(10, 132, 255, 0.22);
}

.chat-gt-empty {
  padding: 6px 16px 10px;
  font-size: 0.8rem;
  color: var(--color-text-tertiary);
}

/* Pill "Inactiu" (60d sense missatges) — mai destructiu, només senyal */
.chat-gt-inactiu-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: rgba(142, 142, 147, 0.18);
  color: var(--color-text-secondary);
  vertical-align: middle;
}

/* Campana tallada al costat de l'hora quan el canal està silenciat */
.chat-canal-mute-ic {
  font-size: 14px;
  vertical-align: -2px;
  color: var(--color-text-tertiary);
  margin-right: 2px;
}

/* Barra d'accions del grup de treball (panell de membres) */
.chat-gt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chat-gt-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-base);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-height: 32px;
}

.chat-gt-action-btn .material-symbols-outlined {
  font-size: 16px;
}

.chat-gt-action-btn:hover {
  background: var(--color-bg-hover);
}

.chat-gt-action-btn.active {
  background: rgba(10, 132, 255, 0.14);
  color: var(--color-primary);
  border-color: transparent;
}

.chat-gt-action-danger {
  color: var(--color-danger, #ef4444);
}

.chat-gt-action-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Botó transferir propietat (clau) a la fila de membre */
.chat-membre-transferir-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.chat-membre-transferir-btn .material-symbols-outlined {
  font-size: 18px;
}

.chat-membre-transferir-btn:hover {
  color: var(--color-primary);
  background: rgba(10, 132, 255, 0.1);
}

/* Badge "Propietari" al panell de membres */
.chat-gt-owner-badge {
  background: rgba(10, 132, 255, 0.14);
  color: var(--color-primary);
}
