/* Messagerie — feuille de style */
:root {
  --accent: #1d4ed8;
  --accent-strong: #1e3a8a;
  --accent-soft: #dbeafe;
  --bg: #e8edf5;
  --panel: #ffffff;
  --panel-2: #f4f6fa;
  --chat-bg: #edf1f7;
  --border: #dfe4ec;
  --text: #0f172a;
  --muted: #64748b;
  --bubble-in: #ffffff;
  --bubble-out: #dce8fd;
  --read: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15,23,42,.10);
  --radius: 10px;
  color-scheme: light;
}
[data-theme="dark"] {
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: #1e3a5f;
  --bg: #0b1120;
  --panel: #111827;
  --panel-2: #1a2333;
  --chat-bg: #0f172a;
  --border: #243044;
  --text: #e5e9f0;
  --muted: #94a3b8;
  --bubble-in: #1e293b;
  --bubble-out: #1e3a6b;
  --read: #93c5fd;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- Pages de connexion / installation ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px;
  padding: 32px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.08); text-align: center;
}
.auth-card.wide { max-width: 520px; text-align: left; }
.auth-card h1 { margin: 12px 0 4px; font-size: 24px; }
.auth-logo img { border-radius: 16px; }
.auth-card form { text-align: left; margin-top: 20px; }
.auth-card label, .modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.auth-card input, .modal input[type=text], .modal input[type=email], .modal input[type=password], .modal input[type=search], .modal select {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text);
}
.auth-card input:focus, .modal input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.alert { background: #fee2e2; color: #991b1b; padding: 10px 12px; border-radius: 8px; margin: 12px 0; font-size: 14px; text-align: left; }
.alert.success { background: #dcfce7; color: #166534; }
.small-title { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; }
.checks { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.checks .ok { color: #16a34a; } .checks .ko { color: var(--danger); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.noscript { text-align: center; padding: 40px; }

/* ---------- Mise en page principale ---------- */
.app { display: flex; height: 100vh; height: 100dvh; max-width: 1600px; margin: 0 auto; background: var(--panel); box-shadow: 0 0 30px rgba(0,0,0,.06); }
.sidebar { width: 380px; min-width: 300px; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); }
.chat { flex: 1; display: flex; flex-direction: column; position: relative; background: var(--chat-bg); min-width: 0; }

.side-head, .chat-head {
  display: flex; align-items: center; gap: 6px; height: 60px; padding: 0 10px 0 14px;
  background: var(--panel-2); border-bottom: 1px solid var(--border); flex: none;
}
.side-title { flex: 1; font-weight: 600; font-size: 17px; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.side-search input {
  width: 100%; padding: 8px 14px; border-radius: 8px; border: 0; background: var(--panel-2); color: var(--text);
}
.side-search input:focus { outline: 2px solid var(--accent); }

.conn-banner { background: #fef3c7; color: #92400e; font-size: 13px; padding: 6px 14px; }
.notif-banner { display: flex; align-items: center; gap: 10px; justify-content: space-between; background: var(--accent-soft); font-size: 13px; padding: 8px 14px; }

/* ---------- Avatars ---------- */
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; position: relative;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 15px; background: #94a3b8; user-select: none;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 84px; height: 84px; font-size: 30px; margin: 0 auto 10px; }
.avatar .dot {
  position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--panel);
}

/* ---------- Liste des conversations ---------- */
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.conv-main { flex: 1; min-width: 0; }
.conv-top, .conv-bottom { display: flex; align-items: center; gap: 8px; }
.conv-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-item.unread .conv-time { color: var(--accent); font-weight: 600; }
.conv-preview { flex: 1; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview.typing { color: var(--accent); font-style: italic; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.conv-empty { padding: 30px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.section-label { padding: 12px 14px 6px; font-size: 12px; text-transform: uppercase; color: var(--accent); letter-spacing: .04em; }

.search-results { overflow-y: auto; flex: 1; }
.search-hit { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-hit:hover { background: var(--panel-2); }
.search-hit .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.search-hit .txt { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Discussion ---------- */
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 20px; background: var(--panel-2); }
.chat-empty img { border-radius: 22px; opacity: .9; }
.chat-empty h2 { color: var(--text); font-weight: 400; margin: 18px 0 6px; }
.chat-head .back { display: none; }
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; border: 0; background: none; cursor: pointer; padding: 0 8px; text-align: left; }
.chat-title .name { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title .status { font-size: 13px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title .status.typing { color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 14px 6% 8px; display: flex; flex-direction: column; gap: 2px; }
.load-more { align-self: center; margin: 6px 0 12px; }
.day-sep { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 10px 0; box-shadow: var(--shadow); }
.sys-msg { align-self: center; background: var(--accent-soft); color: var(--text); font-size: 12.5px; padding: 4px 12px; border-radius: 8px; margin: 6px 0; max-width: 85%; text-align: center; }
.unread-sep { align-self: stretch; text-align: center; font-size: 12px; color: var(--accent); background: var(--panel); margin: 8px -6% ; padding: 4px; opacity: .95; }

.msg { display: flex; max-width: 72%; margin-top: 2px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.msg.first { margin-top: 8px; }
.bubble {
  position: relative; padding: 6px 9px 6px; border-radius: var(--radius);
  background: var(--bubble-in); box-shadow: var(--shadow); min-width: 80px; max-width: 100%;
  overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.first .bubble { border-top-left-radius: 2px; }
.msg.out.first .bubble { border-top-right-radius: 2px; }
.msg.highlight .bubble { animation: flash 1.4s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }
.sender { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text a { word-break: break-all; }
.deleted-text { font-style: italic; color: var(--muted); }
.meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.meta .ticks { width: 16px; height: 16px; }
.meta .ticks.read { color: var(--read); }
.quote {
  border-left: 4px solid var(--accent); background: rgba(0,0,0,.05); border-radius: 6px;
  padding: 4px 8px; margin-bottom: 4px; font-size: 13px; cursor: pointer;
}
[data-theme="dark"] .quote { background: rgba(255,255,255,.06); }
.quote strong { display: block; color: var(--accent); font-size: 12.5px; }
.quote span { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.img-wrap { margin: -2px -5px 4px; border-radius: 8px; overflow: hidden; cursor: zoom-in; background: rgba(0,0,0,.06); }
.img-wrap img { display: block; max-width: 100%; width: 320px; max-height: 360px; object-fit: cover; }
.file-card { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.05); border-radius: 8px; padding: 8px 10px; margin-bottom: 4px; text-decoration: none; color: var(--text); }
[data-theme="dark"] .file-card { background: rgba(255,255,255,.06); }
.file-card .ext { width: 36px; height: 42px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px; text-transform: uppercase; flex: none; }
.file-card .fname { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-card .fsize { font-size: 12px; color: var(--muted); }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin: -4px 0 4px; position: relative; z-index: 1; }
.msg.out .reactions { justify-content: flex-end; }
.reaction-chip { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 0 7px; font-size: 13px; cursor: pointer; line-height: 22px; }
.reaction-chip.mine { border-color: var(--accent); }
.msg-col { display: flex; flex-direction: column; max-width: 100%; }

.msg-menu-btn {
  position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: inherit; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .15s;
  display: flex; align-items: center; justify-content: center;
}
.msg-menu-btn svg { width: 18px; height: 18px; }
.bubble:hover .msg-menu-btn, .msg-menu-btn:focus { opacity: 1; }
@media (hover: none) { .msg-menu-btn { opacity: .6; } }

.scroll-down {
  position: absolute; right: 22px; bottom: 84px; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: var(--panel); color: var(--muted); box-shadow: 0 2px 6px rgba(0,0,0,.2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.scroll-down .badge { position: absolute; top: -6px; right: -4px; }

/* ---------- Zone de saisie ---------- */
.composer { background: var(--panel-2); border-top: 1px solid var(--border); padding: 8px 12px; flex: none; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--panel); color: var(--text);
  max-height: 140px; min-height: 42px; line-height: 1.4;
}
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; flex: none; }
.send-btn:hover { background: var(--accent-strong); }
.send-btn:disabled { opacity: .6; }
.composer-bar { display: flex; align-items: center; gap: 10px; background: var(--panel); border-left: 4px solid var(--accent); border-radius: 8px; padding: 6px 6px 6px 10px; margin-bottom: 8px; }
.bar-content { flex: 1; min-width: 0; font-size: 13px; }
.bar-content strong { display: block; color: var(--accent); }
.bar-content span { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }

/* ---------- Menus, modales, toasts ---------- */
.menu {
  position: fixed; z-index: 60; background: var(--panel); border-radius: 10px; min-width: 200px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); padding: 6px 0; border: 1px solid var(--border);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 18px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.menu .emoji-row { display: flex; gap: 2px; padding: 4px 10px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu .emoji-row button { padding: 4px 6px; font-size: 20px; border-radius: 8px; width: auto; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 460px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 14px 10px 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.pick-list { list-style: none; margin: 0 -20px; padding: 0; }
.pick-item { display: flex; align-items: center; gap: 12px; padding: 9px 20px; cursor: pointer; }
.pick-item:hover { background: var(--panel-2); }
.pick-item .pi-main { flex: 1; min-width: 0; }
.pick-item .pi-sub { font-size: 12.5px; color: var(--muted); }
.pick-item input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.tag { font-size: 11px; border: 1px solid var(--accent); color: var(--accent); border-radius: 6px; padding: 1px 6px; }
.tag.off { border-color: var(--muted); color: var(--muted); }
.center { text-align: center; }
.info-head { text-align: center; padding: 6px 0 14px; }
.info-head h4 { margin: 4px 0 2px; font-size: 19px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; background: var(--panel-2); padding: 14px; border-radius: 10px; margin-bottom: 16px; }
.inline-form label { margin: 0; }
.inline-form .full { grid-column: 1 / -1; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 70; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.error { background: var(--danger); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 80; display: flex; flex-direction: column; }
.lightbox-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 10px; }
.lightbox-bar .icon-btn, .lightbox-bar a { color: #fff; }
.lightbox-img { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 0; }
.lightbox-img img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { box-shadow: none; }
  .sidebar { width: 100%; min-width: 0; border-right: 0; }
  .chat { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .chat { display: flex; }
  .chat-head .back { display: inline-flex; }
  .chat-head { padding-left: 4px; }
  .messages { padding: 10px 10px 6px; }
  .unread-sep { margin: 8px -10px; }
  .msg { max-width: 86%; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-height: 92vh; border-radius: 14px 14px 0 0; }
  .inline-form { grid-template-columns: 1fr; }
  table.grid .hide-sm { display: none; }
}
.btn.primary.danger-bg { background: var(--danger); border-color: var(--danger); }
.avatar svg { width: 60%; height: 60%; }
