/* ── RESET ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:     #e63946;
  --red-d:   #c1121f;
  --green:   #2ecc71;
  --bg:      #f0f2f5;
  --white:   #fff;
  --border:  #e8eaed;
  --text:    #1a1a2e;
  --muted:   #8892a4;
  --sh:      0 2px 8px rgba(0,0,0,.08);
  --sh-lg:   0 8px 32px rgba(0,0,0,.12);
  --sw:      272px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────────────────────── */
#login, #token-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e63946 0%, #c1121f 45%, #1a1a2e 100%);
  z-index: 99;
}

.auth-card {
  background: var(--white);
  border-radius: 20px;
  padding: 44px 36px;
  width: 100%; max-width: 360px;
  box-shadow: var(--sh-lg);
  text-align: center;
}

.auth-logo  { display: inline-block; margin-bottom: 10px; }
.auth-logo img {
    height: 200px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-form { display: flex; flex-direction: column; gap: 10px; }

/* Token screen */
.token-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f0fdf4; border: 1.5px solid #86efac;
  color: #16a34a; border-radius: 20px;
  padding: 5px 14px; font-size: 12px; font-weight: 700; margin-bottom: 16px;
}

.token-user {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px; text-align: left;
}

.pwd-bar {
  height: 4px; border-radius: 2px; width: 0;
  transition: width .3s, background .3s; margin-top: 6px;
}

/* ── FORM ELEMENTS ─────────────────────────────────────────────────────────── */
.field-label {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: .6px; text-align: left; margin-bottom: 4px;
}

.field-input {
  width: 100%; padding: 11px 13px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit;
  color: var(--text); background: var(--white);
  transition: border-color .15s;
}

.field-input:focus { outline: none; border-color: var(--red); }

.field-wrap { position: relative; }
.field-wrap .field-input { padding-right: 40px; }
.toggle-pwd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 15px;
}

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 700; font-family: inherit;
  cursor: pointer; transition: background .15s, transform .1s;
  padding: 11px 20px;
}

.btn-primary  { background: var(--red); color: #fff; width: 100%; }
.btn-primary:hover  { background: var(--red-d); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-outline {
  background: transparent; border: 1.5px solid var(--red);
  color: var(--red); width: 100%;
}
.btn-outline:hover { background: #fff0f1; }

.btn-ghost {
  background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; font-family: inherit;
  padding: 10px 16px; border: none; border-radius: 9px; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }

.btn-icon {
  background: none; border: none; cursor: pointer;
  padding: 6px 10px; border-radius: 8px;
  font-size: 13px; color: var(--muted);
  transition: background .12s; display: flex; align-items: center; gap: 3px;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

.btn-x {
  background: none; border: none; cursor: pointer;
  font-size: 15px; color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.btn-x:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-danger { background: #fff0f1; color: var(--red); border: 1.5px solid #ffc9cc; border-radius: 9px; }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ── APP LAYOUT ────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100dvh; }

/* ── SIDEBAR ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sw); min-width: var(--sw);
  background: var(--white); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100dvh; transition: transform .25s;
  box-shadow: 2px 0 8px rgba(0,0,0,.04);
}

.sb-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--border);
}
.sb-logo  { font-size: 20px; }
.sb-title { font-weight: 800; font-size: 14px; line-height: 1.2; display: block; }
.sb-sub   { font-size: 10px; color: var(--red); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; display: block; }

.sb-me {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.sb-me-meta { flex: 1; min-width: 0; }
.me-name { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role { display: block; font-size: 11px; color: var(--muted); }
.dot-online { width: 9px; height: 9px; border-radius: 50%; background: var(--green); border: 2px solid var(--white); flex-shrink: 0; }

.rooms-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--muted);
}
.btn-plus {
  background: none; border: none; font-size: 20px;
  color: var(--red); cursor: pointer; padding: 1px 8px;
  border-radius: 8px; transition: background .12s; line-height: 1;
}
.btn-plus:hover { background: #fff0f1; }

.room-list { flex: 1; overflow-y: auto; list-style: none; padding: 4px 8px; }

.ri {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  cursor: pointer; transition: background .12s;
}
.ri:hover       { background: var(--bg); }
.ri.active      { background: #fff0f1; }
.ri-icon        { font-size: 17px; flex-shrink: 0; }
.ri-meta        { flex: 1; min-width: 0; }
.ri-name        { display: block; font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri.active .ri-name { color: var(--red); }
.ri-count       { display: block; font-size: 11px; color: var(--muted); }
.badge          { background: var(--red); color: #fff; font-size: 10px; font-weight: 700; border-radius: 10px; padding: 2px 6px; }

.sb-footer { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }

/* ── AVATAR ────────────────────────────────────────────────────────────────── */
.avatar {
  border-radius: 50%; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.av-lg { width: 40px; height: 40px; font-size: 16px; }
.av-md { width: 36px; height: 36px; font-size: 14px; }
.av-sm { width: 30px; height: 30px; font-size: 12px; }
.av-xs { width: 24px; height: 24px; font-size: 10px; }

/* ── MAIN CHAT ─────────────────────────────────────────────────────────────── */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--muted);
}
.empty-ico { font-size: 44px; opacity: .4; }

.chat-view { flex: 1; display: flex; flex-direction: column; height: 100dvh; }

.chat-head {
  height: 62px; background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.ch-info    { display: flex; align-items: center; gap: 10px; }
.ch-icon    { font-size: 20px; }
.ch-name    { font-size: 15px; font-weight: 700; display: block; }
.ch-desc    { font-size: 11px; color: var(--muted); display: block; }
.ch-actions { display: flex; gap: 4px; }

/* ── DATE SÉPARATRICE ──────────────────────────────────────────────────────── */
.date-sep {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 8px; color: var(--muted);
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 6px 4px;
}
.date-sep::before,
.date-sep::after {
  content: ''; flex: 1;
  height: 1px; background: var(--border);
}
.date-sep span {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
  white-space: nowrap;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.msg-group { position: relative; z-index: 2; }

/* ── SCROLL INFINI ─────────────────────────────────────────────────────────── */
.msgs-loading {
  display: flex; justify-content: center; gap: 4px;
  padding: 12px 0;
}

.loading-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); opacity: .4;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: .2s; }
.loading-dot:nth-child(3) { animation-delay: .4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(1); opacity: .4; }
  40%            { transform: scale(1.3); opacity: 1; }
}

/* ── MESSAGES ──────────────────────────────────────────────────────────────── */
.msgs {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 2px;
}
.msg-group      { display: flex; flex-direction: column; margin-bottom: 12px; }
.msg-group.own  { align-items: flex-end; }

.msg-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px; padding: 0 2px;
}
.msg-group.own .msg-header { flex-direction: row-reverse; }

.msg-av { flex-shrink: 0; }

.msg-meta       { display: flex; align-items: baseline; gap: 6px; }
.ms             { font-size: 12px; font-weight: 700; color: var(--text); }
.mt             { font-size: 11px; color: var(--muted); opacity: .8; }

.mb {
  max-width: 420px; padding: 9px 13px;
  border-radius: 18px; font-size: 14px; line-height: 1.5;
  word-break: break-word; margin-bottom: 2px;
  background: var(--white); border: 1px solid var(--border);
  color: var(--text); box-shadow: var(--sh);
}
.mb.new { animation: pop .15s ease; }

.msg-group:not(.own) .mb { align-self: flex-start; }
.msg-group.own .mb        { background: var(--red); color: #fff; border-color: var(--red); align-self: flex-end; }

/* Par défaut — tout arrondi (message unique) */
/* Par défaut — tout arrondi */
.msg-group .mb { border-radius: 18px; }

/* 1ère bulle (après header) si groupe */
.msg-group:not(.own) .msg-header + .mb:not(.mb-last) { border-bottom-left-radius: 4px; }
.msg-group.own       .msg-header + .mb:not(.mb-last) { border-bottom-right-radius: 4px; }

/* Milieu — après n'importe quelle .mb */
.msg-group:not(.own) .mb + .mb:not(.mb-last) { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.msg-group.own       .mb + .mb:not(.mb-last) { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }

/* Dernière bulle */
.msg-group:not(.own) .mb-last:not(:first-child) { border-top-left-radius: 4px; }
.msg-group.own       .mb-last:not(:first-child) { border-top-right-radius: 4px; }

.sys {
  text-align: center; font-size: 11px; color: var(--muted);
  padding: 5px 14px; background: var(--bg);
  border-radius: 20px; align-self: center; margin: 6px 0;
}

/* ── FICHIERS ──────────────────────────────────────────────────────────────── */
.btn-attach {
  background: none; border: none; cursor: pointer;
  font-size: 20px; padding: 4px 6px;
  border-radius: 8px; transition: background .12s;
  flex-shrink: 0; color: var(--muted);
}
.btn-attach:hover { background: var(--bg); }

.mb-fichier {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; min-width: 160px;
}

.mb-fichier.uploading { opacity: .6; }

.fi-icon  { font-size: 22px; flex-shrink: 0; }
.fi-info  { flex: 1; min-width: 0; }
.fi-nom   { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fi-size  { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.fi-uploading { font-size: 11px; color: var(--muted); font-style: italic; }

.fi-dl {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px;
  text-decoration: none; font-size: 14px;
  flex-shrink: 0; transition: background .12s;
}
.fi-dl:hover { background: var(--border); }

.fi-img {
  max-width: 220px; max-height: 220px;
  width: 100%; border-radius: 10px; cursor: pointer;
  display: block; object-fit: cover;
  transition: opacity .15s;
}
.fi-img:hover { opacity: .9; }

.mb-fichier {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; min-width: 140px; max-width: 240px;
}

/* Bulle image — pas de padding autour */
.mb-fichier:has(.fi-img) {
  padding: 4px;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* ── ACTIONS MESSAGE (hover desktop) ───────────────────────────────────────── */
.msg-actions {
  display: none; align-items: center; gap: 2px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 6px;
  box-shadow: var(--sh); z-index: 8;
  white-space: nowrap;
    position: absolute;
}
/* Mes messages (own) : actions à gauche */

.mb:hover ~ .msg-actions,
.msg-actions:hover { display: flex; }

/* Pont invisible entre la bulle et les actions */
.msg-actions::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 10px;
  right: 100%;
}
.msg-group.own .msg-actions::before {
  right: auto;
  left: 100%;
}

.ma-btn {
  background: none; border: none; cursor: pointer;
  font-size: 15px; padding: 3px 5px; border-radius: 6px;
  transition: background .12s; line-height: 1;
}
.ma-btn:hover { background: var(--bg); }

/* ── CITATION REPLY ────────────────────────────────────────────────────────── */
.mt-reply {
  font-size: 10px; color: var(--muted);
  font-style: italic;
}

.mb-quote {
  background: #e4e4e4;
  font-size: 12px; color: #555;
  cursor: pointer;
  margin-top: 4px !important;
  margin-bottom: -5px !important;
  border-radius: 18px;
  font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-group.own .mb-quote {
 background: #e4e4e4;
  font-size: 12px; color: #555;
    border: 0;
}

/* Milieu et dernière — toute .mb qui n'est pas la première */
.msg-group:not(.own) .mb ~ .mb:not(.mb-last) { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.msg-group.own       .mb ~ .mb:not(.mb-last) { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }

.msg-group:not(.own) .mb ~ .mb-last { border-top-left-radius: 4px; }
.msg-group.own       .mb ~ .mb-last { border-top-right-radius: 4px; }

/* Citation = première bulle visible après reply-header */
.msg-group:not(.own) .mb-quote { border-bottom-left-radius: 4px; }
.msg-group.own       .mb-quote { border-bottom-right-radius: 4px; }

/* Bulle réponse = toujours après citation = milieu ou last */
/* mb ~ mb gère déjà ça automatiquement */


.mb.highlight { animation: highlight-flash .6s ease; }
@keyframes highlight-flash { 0%,100% { box-shadow: none; } 50% { box-shadow: 0 0 0 3px var(--red); } }

/* ── REPLY BAR ─────────────────────────────────────────────────────────────── */
.reply-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: #fff8f8;
  border-top: 1px solid #ffc9cc; gap: 10px;
}
.reply-bar-content { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.reply-bar-icon    { font-size: 16px; color: var(--red); flex-shrink: 0; }
.reply-bar-user    { display: block; font-size: 12px; font-weight: 700; color: var(--red); }
.reply-bar-text    { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close   { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 16px; flex-shrink: 0; }

/* ── MENU CONTEXTUEL DESKTOP ───────────────────────────────────────────────── */
.msg-menu {
  position: fixed; z-index: 100;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--sh-lg);
  overflow: hidden; min-width: 160px;
  animation: pop .15s ease;
}
.msg-menu-item {
  display: flex; align-items: center; width: 100%;
  padding: 10px 16px; border: none; background: none;
  font-size: 14px; cursor: pointer; text-align: left;
  font-family: inherit; color: var(--text);
  transition: background .12s;
}
.msg-menu-item:hover { background: var(--bg); }
.msg-menu-item.danger { color: var(--red); }
.msg-menu-item.danger:hover { background: #fff0f1; }

/* ── BOTTOM SHEET MOBILE (long press) ─────────────────────────────────────── */
.msg-sheet { position: fixed; inset: 0; z-index: 80; }
.msg-sheet-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.msg-sheet-content {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--white); border-radius: 20px 20px 0 0;
  animation: slide-up-sheet .2s ease;
  overflow: hidden;
}
.msg-sheet-emojis {
  display: flex; justify-content: space-around;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.sheet-emoji-btn {
  background: none; border: none; cursor: pointer;
  font-size: 28px; padding: 6px;
  border-radius: 10px; transition: transform .1s, background .1s;
}
.sheet-emoji-btn:hover { transform: scale(1.2); background: var(--bg); }
.msg-sheet-actions { display: flex; flex-direction: column; }
.msg-sheet-item {
  display: flex; align-items: center; width: 100%;
  padding: 16px 20px; border: none; background: none;
  font-size: 15px; cursor: pointer; text-align: left;
  font-family: inherit; color: var(--text);
  border-top: 1px solid var(--border);
  transition: background .12s;
}
.msg-sheet-item:hover { background: var(--bg); }
.msg-sheet-item.danger { color: var(--red); }

/* ── RÉACTIONS ─────────────────────────────────────────────────────────────── */
.reaction-bar {
  position: absolute;
  bottom: -15px;
  display: flex; gap: 2px;
  z-index: 5;
    background: #fff;
    border-radius: 999px;
    padding: 0 5px;
    border: 1px solid #F0F2F5;
}

/* Gauche pour messages des autres, droite pour les miens */
.msg-group:not(.own) .reaction-bar { left: 5px; }
.msg-group.own       .reaction-bar { right: 5px; }

.reaction-btn {
  display: inline-flex; align-items: center;
  background: var(--white); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 0 4px;
  font-size: 12px; cursor: pointer;
  transition: all .15s; position: relative;
  line-height: 1.4;
}
.reaction-btn:hover { border-color: var(--red); background: #fff0f1; }
.reaction-btn.mine  { border-color: var(--red); background: #fff0f1; }
.reaction-count     { font-size: 12px; font-weight: 700; color: var(--muted); margin-left: 2px; margin-top: 2px}

/* Tooltip custom */
.reaction-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  font-size: 10px; font-weight: 500;
  padding: 3px 7px; border-radius: 6px;
  white-space: nowrap;
  box-shadow: var(--sh);
  z-index: 10;
}
.reaction-btn:hover .reaction-tip { display: block; }

.reaction-names-tip {
  position: fixed;
  background: var(--text); color: #fff;
  font-size: 11px; font-weight: 500;
  padding: 4px 8px; border-radius: 6px;
  white-space: nowrap; box-shadow: var(--sh);
  z-index: 100; pointer-events: none;
}

/* Espace sous la bulle si elle a des réactions */
.mb { position: relative; margin-bottom: 2px; }
.mb-text { display: block; }
.mb:has(.reaction-bar) { margin-bottom: 16px; }

.emoji-trigger {
  position: absolute; top: -10px; right: -10px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 50%; width: 24px; height: 24px;
  font-size: 13px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
  box-shadow: var(--sh); transition: transform .15s;
  line-height: 1;
}
.emoji-trigger:hover { transform: scale(1.15); }
.mb { position: relative; -webkit-user-select: none; user-select: none; }
.mb:hover .emoji-trigger { display: flex; }

@media (max-width: 680px) {
  .emoji-trigger { display: none !important; }
}
.emoji-pick-btn.selected {
  background: #fff0f1;
  outline: 2px solid var(--red);
  border-radius: 8px;
}


.emoji-picker {
  display: flex; gap: 4px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 24px; padding: 6px 10px;
  box-shadow: var(--sh-lg);
  z-index: 100;
  animation: pop .15s ease;
  white-space: nowrap;
}

.msg-group.own .emoji-picker {
  left: auto;
  right: 0;
}

.emoji-pick-btn {
  background: none; border: none; cursor: pointer;
  font-size: 22px; padding: 4px;
  border-radius: 8px; transition: transform .1s, background .1s;
  line-height: 1;
}
.emoji-pick-btn:hover { transform: scale(1.3); background: var(--bg); }

/* ── READ RECEIPTS ─────────────────────────────────────────────────────────── */
.read-zone {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 3px; padding: 2px 4px 0; min-height: 18px;
}

.read-avatar {
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 9px; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--white); cursor: default;
}

.read-label {
  font-size: 10px; color: var(--muted);
  font-style: italic; margin-left: 2px;
}

/* ── TYPING ────────────────────────────────────────────────────────────────── */
.typing-b {
  min-height: 18px; padding: 0 20px 2px;
  font-size: 12px; color: var(--muted); font-style: italic;
}

/* ── INPUT ─────────────────────────────────────────────────────────────────── */
.input-area {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; background: var(--white);
  border-top: 1px solid var(--border); flex-shrink: 0;
}

.msg-input {
  flex: 1; padding: 11px 15px;
  border: 1.5px solid var(--border); border-radius: 24px;
  font-size: 14px; font-family: inherit;
  color: var(--text); background: var(--bg);
  transition: border-color .15s, background .15s;
}
.msg-input:focus { outline: none; border-color: var(--red); background: var(--white); }

.btn-send {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--red); border: none; color: #fff;
  font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s; flex-shrink: 0;
}
.btn-send:hover  { background: var(--red-d); transform: scale(1.06); }
.btn-send:active { transform: scale(.94); }

/* ── BOTTOM SHEET ──────────────────────────────────────────────────────────── */
.bottom-sheet {
  position: fixed; inset: 0; z-index: 55;
}
.bs-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
}
.bs-content {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-radius: 20px 20px 0 0;
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: slide-up-sheet .25s ease;
  box-shadow: 0 -4px 32px rgba(0,0,0,.12);
}
@keyframes slide-up-sheet {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.bs-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 12px auto 0;
  flex-shrink: 0;
}
.bs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.bs-header h3 { font-size: 15px; font-weight: 700; }
.bs-body {
  flex: 1; overflow-y: auto;
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px;
}

/* ── FICHIER ITEM ──────────────────────────────────────────────────────────── */
.fi-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); cursor: pointer;
  transition: background .12s;
}
.fi-item:hover { background: var(--bg); }
.fi-item .fi-thumb {
  width: 48px; height: 48px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
}
.fi-item .fi-thumb-icon {
  width: 48px; height: 48px; border-radius: 8px;
  background: var(--bg); display: flex; align-items: center;
  justify-content: center; font-size: 24px; flex-shrink: 0;
}
.fi-item .fi-info { flex: 1; min-width: 0; }
.fi-item .fi-nom  { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fi-item .fi-meta { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.fi-item .fi-dl-btn {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px;
  cursor: pointer; flex-shrink: 0; text-decoration: none; color: var(--text);
  transition: background .12s;
}
.fi-item .fi-dl-btn:hover { background: var(--border); }

.bs-empty { text-align: center; color: var(--muted); padding: 32px 0; font-size: 14px; }

/* ── PANEL ─────────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3); z-index: 50;
  display: flex; justify-content: flex-end;
  backdrop-filter: blur(2px);
}
.panel {
  width: 300px; background: var(--white); height: 100%;
  display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.12);
  animation: slide-r .2s ease;
}
@keyframes slide-r { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.p-head { display: flex; align-items: center; justify-content: space-between; padding: 18px; border-bottom: 1px solid var(--border); }
.p-head h3 { font-size: 15px; font-weight: 700; }
.p-body { flex: 1; overflow-y: auto; padding: 10px; }
.p-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.p-foot select { flex: 1; padding: 9px 10px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 13px; font-family: inherit; }

.mrow { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 9px; transition: background .12s; }
.mrow:hover { background: var(--bg); }
.mrow:hover .btn-rm { opacity: 1; }
.minfo { flex: 1; }
.mname { font-size: 13px; font-weight: 600; display: block; }
.mstat { font-size: 11px; display: flex; align-items: center; gap: 4px; }
.mstat::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.mstat.on  { color: var(--green); } .mstat.on::before  { background: var(--green); }
.mstat.off { color: var(--muted); } .mstat.off::before { background: var(--muted); }
.btn-rm { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px 7px; border-radius: 6px; font-size: 13px; opacity: 0; transition: all .12s; }
.btn-rm:hover { background: #fff0f1; color: var(--red); }

/* ── MODALS ────────────────────────────────────────────────────────────────── */
.modover {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35); z-index: 60;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px); padding: 16px;
}
.modal     { background: var(--white); border-radius: 16px; width: 100%; max-width: 460px; box-shadow: var(--sh-lg); animation: pop .2s ease; }
.modal-sm  { max-width: 340px; }
@keyframes pop { from { transform: scale(.95) translateY(6px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.mhd   { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.mhd h3 { font-size: 15px; font-weight: 700; }
.mbody { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.mft   { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); }

.fg    { display: flex; flex-direction: column; gap: 5px; }

.icon-row { display: flex; flex-wrap: wrap; gap: 5px; }
.iopt {
  width: 38px; height: 38px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; cursor: pointer;
  border: 2px solid transparent; background: var(--bg); transition: all .12s;
}
.iopt:hover { background: #fff0f1; }
.iopt.sel   { border-color: var(--red); background: #fff0f1; }

.cblist { display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.cbrow  { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px; cursor: pointer; transition: background .12s; }
.cbrow:hover { background: var(--bg); }
.cbrow input { accent-color: var(--red); width: 15px; height: 15px; }

/* ── TOAST ─────────────────────────────────────────────────────────────────── */
.toasts  { position: fixed; bottom: 20px; right: 20px; z-index: 99; display: flex; flex-direction: column; gap: 8px; }
.toast   { background: var(--text); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: var(--sh-lg); animation: sup .2s ease; max-width: 260px; }
.toast.ok  { background: #2ecc71; }
.toast.err { background: var(--red); }
@keyframes sup { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── SCROLLBAR ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 4px; }

/* ── MOBILE ────────────────────────────────────────────────────────────────── */
.btn-menu { display: none; background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; color: var(--text); }

@media (max-width: 680px) {
  .btn-menu { display: flex; align-items: center; }
  .sidebar  { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sb-overlay   { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 39; display: none; }
  .sb-overlay.show { display: block; }

  /* Zone messages — padding réduit */
  .msgs { padding: 8px 8px; }


  /* Bulles — largeur max adaptée */
  .mb { max-width: calc(100vw - 40px); font-size: 13px; padding: 8px 11px; }

  /* Input area */
  .input-area { padding: 8px 10px; gap: 7px; }

  /* Chat header */
  .chat-head { padding: 0 10px; }
}