:root {
  --bg: #f6f7fb; --panel: #ffffff; --border: #e5e7ef; --text: #1d2130; --muted: #6b7183;
  --accent: #4f46e5; --accent-soft: #eef0ff; --danger: #dc2626; --ok: #059669; --warn: #b45309; --warn-bg: #fff7e6;
  --in: #f1f2f6; --out: #4f46e5; --out-text: #fff;
  --dm: #2563eb; --dm-bg: #e8f0ff; --comment: #c2410c; --comment-bg: #fff1e6;
  --facebook: #1877f2; --instagram: #d62976; --youtube: #ff0000; --tiktok: #111;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131a; --panel: #1a1d27; --border: #2a2e3b; --text: #e8eaf2; --muted: #9298ab;
    --accent: #8b85ff; --accent-soft: #262a45; --in: #242836; --out: #5b54e8; --warn-bg: #3a2e14; --warn: #f5b041;
    --dm: #7aa7ff; --dm-bg: #1c2a48; --comment: #ffa36b; --comment-bg: #3a2416;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.center { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.btn { white-space: nowrap; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 12px; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 4px 8px; font-size: 13px; }
input, select, textarea { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.auth { width: 100%; max-width: 380px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; }
.error { color: var(--danger); margin-top: 10px; }

/* Structure */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px 1fr; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; display: flex; gap: 8px; align-items: center; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.topbar .live.on { background: var(--ok); }
.demo-banner { background: var(--warn-bg); color: var(--warn); padding: 6px 16px; font-size: 13px; text-align: center; }

.inbox { display: grid; grid-template-columns: 210px 340px minmax(0, 1fr); min-height: 0; }
.filters { border-right: 1px solid var(--border); padding: 12px; overflow: auto; background: var(--panel); }
.filters h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.filters button { display: flex; width: 100%; justify-content: space-between; align-items: center; border: 0; background: none; padding: 7px 10px; border-radius: 8px; text-align: left; }
.filters button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.filters .count { font-size: 12px; color: var(--muted); }

.list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.list .search { padding: 10px; border-bottom: 1px solid var(--border); }
.list .mobile-filters { display: none; gap: 6px; padding: 8px 10px 0; }
.list .mobile-filters select { flex: 1; min-width: 0; padding: 6px; }
.list ul { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--accent-soft); }
.conv .top { display: flex; gap: 6px; align-items: baseline; }
.conv .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .name::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.conv .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv .preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv.unread .preview { color: var(--text); }
.conv .meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--in); display: grid; place-items: center; font-weight: 700; position: relative; overflow: visible; flex: none; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .net { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--panel); display: grid; place-items: center; font-size: 9px; color: #fff; font-weight: 800; }
.net-facebook { background: var(--facebook); } .net-instagram { background: var(--instagram); } .net-youtube { background: var(--youtube); } .net-tiktok { background: var(--tiktok); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--in); color: var(--muted); white-space: nowrap; }
.tag.assigned { color: #fff; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

/* Types : messages privés (bleu) / commentaires publics (orange) */
.kind { font-size: 11px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; font-weight: 600; }
.kind.kind-dm { background: var(--dm-bg); color: var(--dm); }
.kind.kind-comment { background: var(--comment-bg); color: var(--comment); }
.conv { border-left: 4px solid transparent; }
.conv.kind-dm { border-left-color: var(--dm); }
.conv.kind-comment { border-left-color: var(--comment); }
.conv .ctx-line { font-size: 12px; color: var(--comment); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-banner { padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
.kind-banner.kind-dm { background: var(--dm-bg); color: var(--dm); }
.kind-banner.kind-comment { background: var(--comment-bg); color: var(--comment); }
.kind-banner div { color: var(--text); margin-top: 2px; }
.unread-count { color: var(--accent); }
.detail { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.detail header { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.detail header .who { flex: 1; min-width: 180px; }
.detail header .who strong { font-size: 16px; }
.detail header .actions { display: flex; gap: 8px; align-items: center; }
.detail header select { width: auto; }
.context { padding: 8px 16px; font-size: 13px; background: var(--panel); border-bottom: 1px solid var(--border); color: var(--muted); }
.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(70%, 560px); display: flex; flex-direction: column; }
.msg .bubble { padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { align-self: flex-start; }
.msg.in .bubble { background: var(--in); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.out .bubble { background: var(--out); color: var(--out-text); border-bottom-right-radius: 4px; }
.msg.failed .bubble { background: transparent; color: var(--danger); border: 1px dashed var(--danger); }
.msg.pending .bubble { opacity: .6; }
.msg .info { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.msg .author { font-size: 12px; color: var(--muted); margin-bottom: 2px; font-weight: 600; }
.msg img.att { max-width: 240px; border-radius: 10px; margin-top: 4px; display: block; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.event { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 10px 16px; }
.composer .warning { background: var(--warn-bg); color: var(--warn); padding: 7px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; max-height: 180px; }
.composer .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 24px; }
.back { display: none; }

/* Réglages */
.settings { overflow: auto; padding: 24px 16px; }
.settings .wrap { max-width: 860px; margin: 0 auto; display: grid; gap: 20px; }
.settings h2 { margin: 0 0 4px; font-size: 18px; }
.row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 160px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.status-ok { color: var(--ok); } .status-error { color: var(--danger); }
code { background: var(--in); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 1000px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .filters { display: none; }
  .list .mobile-filters { display: flex; }
}
@media (max-width: 700px) {
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .me { display: none; }
  .inbox.has-detail .list { display: none; }
  .inbox:not(.has-detail) .detail { display: none; }
  .back { display: inline-flex; }
  .msg { max-width: 88%; }
  .topbar .brand span { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
