/* Chatroom - en-tête fixe + footer adapté au clavier (Visual Viewport) */
.chatroom.screen.active {
  position: absolute;
  inset: 0;
  z-index: 50;
  padding: 0;
  display: flex !important;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: transparent;
}
.chatroom.screen.active .chat-slider {
  flex-shrink: 0;
}
.chatroom.screen.active .chatroom-body {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chatroom.screen.active .chatroom-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
/* Barre en-tête chat : adaptée à l'écran, flèche + titre (tronqué) + burger */
.chatroom-header {
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  min-height: 56px;
  padding: 10px 8px;
  padding-top: 10px;
  padding-left: 8px;
  padding-right: 8px;
  background: #000;
  border-bottom: 1px solid #222;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chatroom-back {
  flex-shrink: 0;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: clamp(1.25rem, 5vw, 1.5rem);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.chatroom-title {
  flex: 1;
  min-width: 0;
  font-size: clamp(0.95rem, 4vw, 1.1rem);
  font-weight: 600;
  text-align: center;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}
.chatroom-title-btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  display: block;
  width: 100%;
}
.chatroom-title-btn:hover { opacity: 0.9; }
.chatroom-title-btn:active { opacity: 0.8; }
/* Panneau conversations archivées (consultation) */
.chat-archived-view-panel .chat-archived-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 120px;
  max-height: 40vh;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.chat-archived-view-panel .chat-msg {
  max-width: 90%;
  padding: 8px 12px;
  font-size: 0.9rem;
}
.chat-archived-view-panel .chat-msg.user {
  background: #0a0a0a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
/* Panneau conversations archivées */
.chat-archived-overlay {
  position: fixed;
  inset: 0;
  /* Au-dessus du clavardage (footer 202) pour que le panneau soit cliquable. */
  z-index: 10050;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}
.chat-archived-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
.chat-archived-title {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}
.chat-archived-empty {
  margin: 0 0 16px 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.chat-archived-list {
  list-style: none;
  padding: 0;
  margin: 0 0 16px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.chat-archived-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.chat-archived-list-item .chat-archived-name { font-weight: 500; flex: 1; min-width: 0; }
.chat-archived-list-item .chat-archived-date { color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; }
.chat-archived-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.chat-archived-action-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.chat-archived-action-btn:hover,
.chat-archived-action-btn:active { background: rgba(255,255,255,0.15); }
.chat-archived-action-btn svg { width: 20px; height: 20px; }
.chat-archived-name { font-weight: 500; }
.chat-archived-date { color: var(--text-muted); font-size: 0.8rem; margin-left: 8px; }
.chat-archived-close {
  align-self: flex-end;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-archived-close:active { opacity: 0.9; }
.chatroom-burger {
  flex-shrink: 0;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: clamp(1.2rem, 5vw, 1.5rem);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
/* Sidebar (liste employés) : pleine hauteur, adapté à l'écran */
.chat-slider {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 150;
  pointer-events: none;
  visibility: hidden;
  max-width: 100vw;
  max-height: 100vh;
}
.chat-slider.open { pointer-events: auto; visibility: visible; }
.chat-slider-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.25s;
}
.chat-slider.open .chat-slider-backdrop { opacity: 1; }
.chat-slider-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(280px, 85vw);
  min-width: 260px;
  max-height: 100vh;
  max-height: 100dvh;
  background: var(--bg-dark);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
  transform: translateX(100%);
  transition: transform 0.25s;
  padding-top: 56px;
  padding-bottom: 20px;
  padding-right: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.chat-slider.open .chat-slider-panel { transform: translateX(0); }
.chat-slider-title {
  font-size: clamp(0.9rem, 3.5vw, 1rem);
  padding: 12px 16px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.chat-slider-list { list-style: none; padding: 8px 0; margin: 0; }
.chat-slider-list li {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.chat-slider-list li .chat-slider-item-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-slider-list li .chat-slider-item-text-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
}
.chat-slider-list li .chat-slider-item-main .chat-slider-item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-slider-item-offline-meta {
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--text-muted);
  white-space: normal;
}
.chat-slider-eye-wrap { margin-left: 8px; flex-shrink: 0; }
.chat-slider-eye-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-slider-eye-btn:hover { background: var(--bg-card); color: var(--text); }
.chat-slider-eye-btn:active { opacity: 0.8; }
.chat-slider-eye-icon { width: 22px; height: 22px; }
.chat-slider-eye-icon.chat-slider-eye-closed { opacity: 0.7; }
.chat-slider-list li:active { background: var(--bg-card); }
.chat-slider-loading { color: var(--text-muted); font-style: italic; padding: 14px 16px; }
.chatroom-body { flex: 1 1 0%; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.chatroom-messages {
  flex: 1 1 0%;
  min-height: 120px;
  overflow-y: auto;
  padding: 12px 16px 16px;
  padding-top: 64px;
  padding-left: 16px;
  padding-right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  cursor: pointer;
}
.chatroom-footer {
  flex-shrink: 0;
  display: flex !important;
  flex-direction: column;
  padding: 8px 8px 6px;
  padding-bottom: 24px;
  padding-left: 8px;
  padding-right: 8px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  visibility: visible;
}
.chatroom-input-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 10px; }
.chatroom-input-editable {
  flex: 1;
  padding: 14px 18px;
  border-radius: 24px;
  border: 1px solid #ddd;
  background: #f5f5f5;
  color: #111;
  font-size: 16px;
  min-height: 48px;
  max-height: 120px;
  overflow-y: auto;
  cursor: text;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
}
.chatroom-input-editable:focus { outline: none; border-color: #0084ff; }
.chat-input-placeholder { color: #888; }
.chat-input-loupe {
  position: fixed;
  z-index: 200;
  transform: translate(-50%, 0);
  pointer-events: none;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.3;
  white-space: pre;
  max-width: 90vw;
  max-height: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  border: 2px solid var(--primary);
  visibility: hidden;
}
.chat-input-loupe.visible { visibility: visible; }
.chat-input-char { display: inline; }
.chat-input-char[data-i]:empty { display: inline-block; min-width: 2px; }
.chat-input-char.chat-input-selected {
  background: rgba(37, 99, 235, 0.5);
  color: #fff;
  border-radius: 3px;
  padding: 0 1px;
}
.chat-caret {
  display: inline-block;
  color: var(--primary);
  font-weight: bold;
  animation: chat-caret-blink 0.8s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes chat-caret-blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.chatroom-photo-wrap { position: relative; flex-shrink: 0; }
.chatroom-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #e5e7eb;
  color: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chatroom-photo:active { background: #0084ff; color: #fff; }
.chat-photo-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 160;
  background: transparent;
  visibility: hidden;
  opacity: 0;
}
.chat-photo-menu-backdrop.open { visibility: visible; opacity: 1; }
.chat-photo-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  min-width: 260px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  padding: 6px 0;
  z-index: 161;
  visibility: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}
.chat-photo-menu.open {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}
.chat-photo-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-photo-menu-item:hover,
.chat-photo-menu-item:active { background: rgba(255,255,255,0.08); }
.chat-photo-menu-icon { font-size: 1.25rem; }
.chatroom-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #0084ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.chatroom-send:hover { background: #0066cc; }
.chatroom-send:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-msg {
  max-width: 85%;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: stretch;
}
.chat-msg-column {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  gap: 4px;
}
.chat-msg.user {
  align-self: flex-end;
  margin-left: auto;
  background: transparent;
  color: inherit;
}
.chat-msg.user .chat-msg-column {
  align-items: flex-end;
}
.chat-msg.assistant .chat-msg-column {
  align-items: flex-start;
}
.chat-msg.user > .chat-msg-column > .chat-msg-content {
  background: #0084ff;
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 10px 14px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: transparent;
  border: none;
}
.chat-msg.assistant > .chat-msg-column > .chat-msg-content {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 14px;
}
.chat-msg.chat-msg-image > .chat-msg-column > .chat-msg-content {
  padding: 4px;
  background: transparent !important;
  border: none !important;
}
.chat-msg.chat-msg-image { padding: 0; }
.chat-msg.chat-msg-image .chat-msg-img,
.chat-msg.chat-msg-image .chat-msg-media-thumb .chat-msg-img {
  max-width: min(288px, 100%);
  max-height: min(220px, 42vh);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
  border-radius: 12px;
  display: block;
}
.chat-msg-media-thumb {
  display: block;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  border-radius: 12px;
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.chat-msg-video-thumb {
  position: relative;
  display: block;
  cursor: pointer;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 12px;
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.chat-msg-video-preview {
  max-width: min(288px, 100%);
  max-height: min(220px, 42vh);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
  border-radius: 12px;
  display: block;
  vertical-align: middle;
  pointer-events: none;
}
.chat-msg-video-play-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 18px;
  line-height: 44px;
  text-align: center;
  pointer-events: none;
}
.chat-msg .chat-msg-file {
  color: #0084ff;
  text-decoration: underline;
  word-break: break-all;
}