:root {
  --green: #008069;
  --green-light: #00a884;
  --panel: #ffffff;
  --border: #e9edef;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
  --text: #111b21;
  --text-2: #667781;
  --header-h: 59px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: #dadbd3;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input { font: inherit; }

/* ---------- Authentification ---------- */
.auth-view {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--green) 0 220px, #dadbd3 220px);
}
.auth-card {
  background: #fff; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15);
  padding: 40px 36px; width: min(400px, 92vw); text-align: center;
}
.auth-logo { width: 72px; height: 72px; border-radius: 18px; }
.auth-card h1 { margin: 12px 0 4px; font-size: 24px; }
.auth-sub { color: var(--text-2); margin: 0 0 24px; font-size: 14px; }
#auth-form { display: flex; flex-direction: column; gap: 12px; }
#auth-form input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; outline: none; }
#auth-form input:focus { border-color: var(--green-light); }
#auth-submit { background: var(--green-light); color: #fff; padding: 12px; border-radius: 8px; font-weight: 600; }
#auth-submit:disabled { opacity: .6; cursor: wait; }
.auth-switch-line { font-size: 14px; color: var(--text-2); margin-top: 18px; }
.auth-switch-line a { color: var(--green); font-weight: 600; text-decoration: none; margin-left: 6px; }
.auth-notice { font-size: 12px; color: var(--text-2); margin-top: 16px; }

/* ---------- Structure ---------- */
.app-view {
  display: flex; height: 100dvh; max-width: 1600px; margin: 0 auto;
  background: var(--panel); box-shadow: 0 0 20px rgba(0,0,0,.1);
}
.sidebar {
  width: 32%; min-width: 320px; max-width: 420px;
  border-right: 1px solid var(--border); display: flex; flex-direction: column; background: #fff;
}
.side-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: #f0f2f5; height: var(--header-h);
}
.me-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-status { font-size: 12px; color: #c62828; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex: none; background: #9e9e9e; text-transform: uppercase;
}
.icon-btn { font-size: 18px; color: var(--text-2); padding: 6px 8px; border-radius: 50%; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

.search-box { padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--border); }
#search-input { width: 100%; padding: 9px 14px; border: none; border-radius: 8px; background: #f0f2f5; outline: none; }
.search-results { border-bottom: 1px solid var(--border); max-height: 40%; overflow: auto; background: #fff; }
.search-header { font-size: 13px; color: var(--green); font-weight: 600; padding: 10px 16px; }
.search-empty { padding: 12px 16px; color: var(--text-2); font-size: 14px; }

.conv-list { flex: 1; overflow-y: auto; }
.conv-item, .user-item { display: flex; gap: 12px; padding: 10px 14px; cursor: pointer; align-items: center; }
.conv-item:hover, .user-item:hover { background: #f5f6f6; }
.conv-item { border-bottom: 1px solid var(--border); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; font-size: 15px; }
.conv-time { font-size: 12px; color: var(--text-2); flex: none; }
.conv-time.unread { color: var(--green-light); font-weight: 700; }
.conv-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; align-items: center; }
.conv-preview { color: var(--text-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--green-light); color: #fff; border-radius: 999px;
  font-size: 12px; font-weight: 700; min-width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center; padding: 0 6px; flex: none;
}
.presence-dot { width: 10px; height: 10px; border-radius: 50%; background: #31a24c; display: inline-block; margin-left: 6px; }

/* ---------- Zone de discussion ---------- */
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #f0f2f5; color: var(--text-2); text-align: center; border-bottom: 6px solid var(--green-light);
}
.empty-logo { width: 80px; border-radius: 20px; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--green); color: #fff; height: var(--header-h);
}
.chat-title { font-weight: 600; }
.chat-status { font-size: 12px; opacity: .85; }
.typing { margin-left: 6px; font-style: italic; }
.back-btn { display: none; color: #fff; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 8%;
  display: flex; flex-direction: column; gap: 4px; background: #efeae2;
}
.msg { display: flex; }
.msg.sent { justify-content: flex-end; }
.bubble {
  max-width: min(65%, 560px); padding: 6px 9px 8px; border-radius: 8px;
  box-shadow: 0 1px .5px rgba(0,0,0,.13); font-size: 14.5px; line-height: 1.35;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.received .bubble { background: var(--bubble-in); }
.msg.sent .bubble { background: var(--bubble-out); }
.meta { float: right; margin: 8px 0 -2px 8px; font-size: 11px; color: var(--text-2); white-space: nowrap; }
.ticks { letter-spacing: -2px; margin-left: 2px; }
.ticks.read { color: #53bdeb; }
.undecryptable { color: var(--text-2); }
.lock { opacity: .6; }
.msg-sender { font-size: 12px; font-weight: 600; color: var(--green); margin-bottom: 2px; }

.file { display: flex; flex-direction: column; gap: 6px; }
.file-img { max-width: 280px; max-height: 280px; border-radius: 6px; display: block; }
.file-icon { font-size: 34px; }
.file-info { display: flex; flex-direction: column; }
.file-name { font-weight: 600; font-size: 13px; }
.file-size { font-size: 12px; color: var(--text-2); }
.file-dl {
  margin-top: 6px; background: var(--green-light); color: #fff;
  border-radius: 6px; padding: 6px 12px; font-size: 13px; align-self: flex-start;
}
.file-dl:disabled { opacity: .6; }

.load-more {
  align-self: center; margin: 4px 0 8px; padding: 8px 14px; border-radius: 8px;
  background: #fff; color: var(--green); font-size: 13px; box-shadow: 0 1px .5px rgba(0,0,0,.13);
}
.load-more:disabled { opacity: .6; }

.composer { display: flex; gap: 8px; padding: 8px 12px; background: #f0f2f5; align-items: center; }
#msg-input { flex: 1; border: none; border-radius: 8px; padding: 11px 14px; background: #fff; outline: none; }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--green-light); color: #fff; font-size: 18px; flex: none; }

.notif-banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: #fff3cd; color: #664d03; padding: 8px 14px; font-size: 14px;
}
#notif-btn { background: #664d03; color: #fff; border-radius: 6px; padding: 5px 12px; flex: none; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111b21; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }

/* ---------- Modal Groupe ---------- */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  background: #fff; border-radius: 12px; padding: 24px; width: min(400px, 90vw);
  max-height: 80vh; overflow-y: auto;
}
.modal-content h2 { margin: 0 0 16px; }
.modal-content input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; outline: none; }
.modal-content input:focus { border-color: var(--green-light); }
.member-results { max-height: 150px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; }
.member-results:empty { display: none; }
.member-item { padding: 8px 12px; cursor: pointer; }
.member-item:hover { background: #f5f6f6; }
.selected-members { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; min-height: 10px; }
.member-tag {
  background: var(--green-light); color: #fff; padding: 4px 10px; border-radius: 16px;
  font-size: 13px; display: flex; align-items: center; gap: 6px;
}
.member-tag button { background: none; border: none; color: #fff; cursor: pointer; font-size: 16px; padding: 0; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; }
.btn-primary { background: var(--green-light); color: #fff; padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; }
.btn-secondary { background: #e9edef; color: var(--text); padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; }
  .chat-pane { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .chat-pane { display: flex; }
  .back-btn { display: block; }
  .messages { padding: 12px 4%; }
  .bubble { max-width: 82%; }
}