/* ═══════════════════════════════════════════════════════════════════
   A²CRM — thème « desk » sombre (référence : captures PulsDesk)
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --bg: #0b1020;
  --bg-2: #0f1528;
  --panel: #121a2e;
  --panel-2: #172038;
  --panel-3: #1c2742;
  --line: #222d4a;
  --line-2: #2b3758;
  --text: #e8ecf6;
  --text-2: #b7c0d6;
  --muted: #7f8aa6;
  --accent: #3d63ff;
  --accent-2: #5b7cff;
  --accent-soft: rgba(61, 99, 255, .16);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, .16);
  --orange: #f59e0b;
  --orange-soft: rgba(245, 158, 11, .16);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, .16);
  --violet: #a855f7;
  --violet-soft: rgba(168, 85, 247, .18);
  --gold: #eab308;
  --yellow: #facc15;
  --bubble-in: #1a2340;
  --bubble-out: #2a3a6b;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --topbar-h: 52px;
  --rail-w: 52px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef1f8; --bg-2: #e6eaf4; --panel: #ffffff; --panel-2: #f5f7fc; --panel-3: #eaeef8;
  --line: #dde3f0; --line-2: #cfd7ea; --text: #131a2e; --text-2: #3b4664; --muted: #6b7591;
  --bubble-in: #eef1f8; --bubble-out: #dbe4ff; --shadow: 0 10px 30px rgba(20, 30, 60, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
svg:not([width]) { width: 16px; height: 16px; flex: none; }
.search svg { width: 15px; height: 15px; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 13px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.center { text-align: center; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfw .thumb-media, .sfw .media-grid img, .sfw .content-thumb img { filter: blur(18px) saturate(.6); }

/* ── Logo / marque ─────────────────────────────────────────────── */
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  font-weight: 700; font-size: 13px; letter-spacing: -.5px; flex: none;
}
.logo-mark sup { font-size: 8px; margin-left: 1px; top: -.5em; }
.brand { font-weight: 700; font-size: 15px; letter-spacing: .2px; white-space: nowrap; }
.brand sup { font-size: 10px; color: var(--accent-2); }

/* ── Layout principal ──────────────────────────────────────────── */
.app { display: grid; grid-template-rows: var(--topbar-h) 1fr; grid-template-columns: var(--rail-w) 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.topbar .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .brand-center {
  position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.topbar .actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 10px; height: 32px; width: 260px; color: var(--muted);
}
.search input { border: 0; background: transparent; outline: 0; width: 100%; color: var(--text); }
.pill-demo { background: var(--yellow); color: #1b1600; font-weight: 600; font-size: 11px; padding: 2px 8px; border-radius: 6px; }
.icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent-2); border-color: rgba(61, 99, 255, .4); }
.icon-btn svg, .rail a svg, .btn svg { width: 17px; height: 17px; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2); cursor: pointer; user-select: none; }
.switch .track { width: 30px; height: 17px; border-radius: 10px; background: var(--line-2); position: relative; transition: .2s; }
.switch .track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input { display: none; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { left: 15px; }
.switch.green input:checked + .track { background: var(--green); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 3px; border-radius: 10px; cursor: pointer; position: relative; }
.user-chip:hover { background: var(--panel-2); }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.15; }
.user-chip .who b { font-size: 12px; }
.user-menu {
  position: absolute; right: 0; top: 44px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 190px; padding: 6px; display: none;
}
.user-menu.open { display: block; }
.user-menu a, .user-menu button {
  display: flex; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px; color: var(--text);
  background: none; border: 0; gap: 8px; align-items: center;
}
.user-menu a:hover, .user-menu button:hover { background: var(--panel-2); }

.rail {
  background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  align-items: center; gap: 6px; padding: 10px 0;
}
.rail a {
  width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); position: relative;
}
.rail a:hover { color: var(--text); background: var(--panel-2); }
.rail a.active { color: var(--accent-2); background: var(--accent-soft); }
.rail a .tip {
  position: absolute; left: 44px; background: var(--panel-3); color: var(--text); padding: 4px 8px; border-radius: 6px;
  font-size: 11px; white-space: nowrap; opacity: 0; pointer-events: none; transition: .15s; z-index: 30;
}
.rail a:hover .tip { opacity: 1; }
.rail .sep { width: 24px; height: 1px; background: var(--line); margin: 4px 0; }
.rail .bottom { margin-top: auto; }
.main { min-width: 0; min-height: 0; overflow: auto; }
.page { padding: 22px 26px; max-width: 1280px; margin: 0 auto; }
.page h1 { font-size: 20px; margin: 0 0 4px; }
.page .sub { color: var(--muted); margin: 0 0 18px; }

/* ── Badges / pastilles ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 600; line-height: 1;
  padding: 3px 6px; border-radius: 5px; white-space: nowrap;
}
.b-green { background: var(--green); color: #052e12; }
.b-blue { background: var(--accent); color: #fff; }
.b-orange { background: var(--orange); color: #2a1700; }
.b-yellow { background: var(--yellow); color: #2b2300; }
.b-red { background: var(--red); color: #fff; }
.b-violet { background: var(--violet); color: #fff; }
.b-ghost { background: var(--panel-3); color: var(--text-2); border: 1px solid var(--line-2); }
.b-soft-green { background: var(--green-soft); color: var(--green); }
.b-soft-orange { background: var(--orange-soft); color: var(--orange); }
.b-soft-red { background: var(--red-soft); color: var(--red); }
.b-soft-violet { background: var(--violet-soft); color: var(--violet); }
.b-soft-blue { background: var(--accent-soft); color: var(--accent-2); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: inline-flex; align-items: center;
  justify-content: center; font-weight: 700; color: #fff; font-size: 13px; position: relative; background: var(--accent);
  overflow: visible;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.xl { width: 72px; height: 72px; font-size: 26px; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); background: var(--green); }

/* ── Boutons / champs ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: transparent; border-color: rgba(239, 68, 68, .5); color: var(--red); }
.btn.success { background: var(--green); border-color: var(--green); color: #052e12; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.xs { height: 24px; padding: 0 8px; font-size: 11px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, .select, .textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px;
  outline: 0; color: var(--text); min-height: 36px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 80px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg-2); }
.check input { accent-color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: var(--panel-2); }
.tabs { display: flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 600; font-size: 12px; }
.tabs button.active { background: var(--accent); color: #fff; }

/* ── Modale / toasts ───────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(4, 7, 16, .66); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 560px; max-width: 100%; max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal.wide { width: 860px; }
.modal header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal header h2 { font-size: 15px; margin: 0; }
.modal .body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: 360px; }
.toast {
  background: var(--panel); border: 1px solid var(--line-2); border-left: 4px solid var(--accent); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow); font-size: 12.5px; display: flex; gap: 10px; align-items: flex-start;
  animation: toastIn .25s ease-out; cursor: pointer;
}
.toast.payment { border-left-color: var(--green); }
.toast.orange, .toast.due { border-left-color: var(--orange); }
.toast.offlink { border-left-color: var(--violet); }
.toast.real, .toast.minor, .toast.alert, .toast.error { border-left-color: var(--red); }
.toast.hot { border-left-color: #fb7185; }
.toast .x { margin-left: auto; color: var(--muted); background: none; border: 0; padding: 0 2px; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Connexion ─────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(61, 99, 255, .18), transparent 60%), var(--bg); }
.login-card { width: 380px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px 26px 22px; box-shadow: var(--shadow); }
.login-card .head { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; }
.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card p.lead { color: var(--muted); margin: 0 0 18px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn.primary { width: 100%; height: 40px; margin-top: 8px; }
.alert-box { padding: 9px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }
.alert-box.error { background: var(--red-soft); color: #fecaca; border: 1px solid rgba(239, 68, 68, .35); }
.alert-box.info { background: var(--accent-soft); color: var(--text); border: 1px solid rgba(61, 99, 255, .35); }

/* ── Accueil : comptes Telegram ────────────────────────────────── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.acc-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px; position: relative; }
.acc-card .top { display: flex; gap: 12px; align-items: center; }
.acc-card .name { font-weight: 700; font-size: 15px; }
.acc-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.acc-card .stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px; }
.acc-card .stat b { display: block; font-size: 16px; }
.acc-card .stat span { font-size: 10.5px; color: var(--muted); }
.acc-card .btns { display: flex; gap: 8px; }
.acc-card .btns .btn { flex: 1; }
.acc-add { border: 1.5px dashed var(--line-2); background: transparent; color: var(--muted); align-items: center; justify-content: center; min-height: 220px; cursor: pointer; }
.acc-add:hover { border-color: var(--accent); color: var(--text); }
.status-pill { font-size: 10.5px; font-weight: 600; padding: 3px 8px; border-radius: 20px; }
.st-active { background: var(--green-soft); color: var(--green); }
.st-qr_pending, .st-pending { background: var(--accent-soft); color: var(--accent-2); }
.st-disconnected { background: var(--orange-soft); color: var(--orange); }
.st-error, .st-revoked { background: var(--red-soft); color: var(--red); }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px 0; }
.qr-box .qr { width: 240px; height: 240px; background: #fff; border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 8px; }
.qr-box .qr svg { width: 100%; height: 100%; }
.steps { color: var(--text-2); font-size: 12.5px; margin: 0; padding-left: 18px; }

/* ── Chat : structure 3 panneaux ───────────────────────────────── */
.chat-shell { display: grid; grid-template-rows: 38px 1fr; height: 100%; min-height: 0; }
.conv-tabs { display: flex; align-items: flex-end; gap: 4px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--bg-2); overflow-x: auto; }
.conv-tab { display: flex; align-items: center; gap: 8px; height: 31px; padding: 0 10px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--panel); color: var(--text-2); font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.conv-tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line-2); }
.conv-tab .close { border: 0; background: none; color: var(--muted); padding: 0; line-height: 1; font-size: 14px; }
.chat-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr) 330px; min-height: 0; }
.chat-grid.no-insights { grid-template-columns: 300px minmax(0, 1fr) 0; }
.chat-grid.no-insights .insights { display: none; }

/* Sidebar */
.inbox { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.inbox .tools { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.inbox .tools .row1 { display: flex; gap: 6px; }
.inbox .tools .row1 .input { height: 34px; min-height: 34px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 25px; padding: 0 8px; border-radius: 7px; font-size: 11.5px;
  font-weight: 600; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2); cursor: pointer;
}
.chip svg { width: 13px; height: 13px; }
.chip:hover { color: var(--text); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.chip .n { font-variant-numeric: tabular-nums; }
.c-hot svg { color: var(--yellow); } .c-unread svg { color: var(--accent-2); } .c-reply svg { color: var(--orange); }
.c-pay svg { color: var(--red); } .c-active svg { color: var(--green); } .c-mine svg { color: var(--accent-2); }
#releaseAllBtn { white-space: nowrap; flex: 0 0 auto; }
.assign-box { display: inline-flex; align-items: center; gap: 4px; }
.assign-pill { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2); font-size: 11.5px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.assign-pill svg { width: 13px; height: 13px; }
.assign-pill.mine { border-color: rgba(34, 197, 94, .5); background: var(--green-soft); color: var(--green); }
.assign-pill.other { border-color: rgba(245, 158, 11, .5); background: var(--orange-soft, rgba(245,158,11,.12)); color: var(--orange); cursor: default; }
.assign-pill .caret { font-size: 10px; opacity: .75; margin-left: 1px; }
.assign-pill.other { cursor: pointer; }
.assign-pill .x { border: 0; background: none; color: inherit; padding: 0 0 0 2px; font-size: 14px; line-height: 1; cursor: pointer; }
.assign-banner { padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--orange); background: var(--orange-soft, rgba(245,158,11,.12)); border-top: 1px solid var(--line); }
.conv-tab .who { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; }
.conv-tab .who.other { background: var(--orange); }
.release-menu { position: absolute; z-index: 30; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.release-menu button { text-align: left; }
.sort-row { display: flex; gap: 6px; align-items: center; }
.sort-row .select { height: 28px; min-height: 28px; padding: 0 8px; font-size: 12px; }
.conv-list { overflow-y: auto; flex: 1; min-height: 0; }
.conv-item {
  display: flex; gap: 10px; padding: 11px 12px 11px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
  border-left: 3px solid transparent; position: relative;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-3); border-left-color: var(--accent); }
.conv-item.st-pending { border-left-color: var(--orange); }
.conv-item.st-offlink { border-left-color: var(--violet); background: linear-gradient(90deg, rgba(168, 85, 247, .09), transparent 60%); }
.conv-item.st-attention { border-left-color: var(--red); background: linear-gradient(90deg, rgba(239, 68, 68, .09), transparent 60%); }
.conv-item.st-closed { opacity: .6; }
.conv-item .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-item .l1 { display: flex; align-items: center; gap: 6px; }
.conv-item .l1 .nm { font-weight: 700; font-size: 13px; max-width: 120px; }
.conv-item .l1 .tm { margin-left: auto; font-size: 11px; color: var(--muted); flex: none; }
.conv-item .handle { font-size: 11px; color: var(--muted); }
.conv-item .pv { font-size: 12.5px; font-weight: 600; color: var(--text); }
.conv-item .pv.out { font-weight: 400; color: var(--text-2); }
.conv-item .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.conv-item .unread-dot { position: absolute; right: 12px; bottom: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
.conv-item .unread-n { position: absolute; right: 10px; bottom: 11px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.list-footer { padding: 10px; text-align: center; }

/* Conversation */
.convo { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); position: relative; }
.convo-head { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 54px; }
.convo-head .nm { font-weight: 700; font-size: 14px; }
.convo-head .handle { color: var(--muted); font-size: 12px; margin-left: 4px; }
.convo-head .tools { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.ai-toggle { white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px 4px 8px; border-radius: 8px; border: 1px solid var(--line-2); font-size: 11.5px; font-weight: 600; }
.ai-toggle.on { border-color: rgba(34, 197, 94, .5); background: var(--green-soft); color: var(--green); }
.ai-toggle.off { color: var(--muted); }
.state-select { height: 30px; min-height: 30px; padding: 0 6px; font-size: 12px; width: auto; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px 10px; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.day-sep { align-self: center; font-size: 11px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); padding: 2px 10px; border-radius: 10px; margin: 10px 0 6px; }
.msg { display: flex; flex-direction: column; max-width: 68%; align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { background: var(--bubble-in); border: 1px solid var(--line); padding: 8px 12px; border-radius: 12px 12px 12px 4px; font-weight: 600; font-size: 13px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--bubble-out); border-color: rgba(91, 124, 255, .35); border-radius: 12px 12px 4px 12px; font-weight: 500; }
.msg .stamp { font-size: 10.5px; color: var(--muted); margin: 2px 4px 6px; display: flex; gap: 6px; align-items: center; }
.msg .sig { color: var(--orange); font-weight: 600; }
.msg .sig.ai { color: var(--green); }
.thumb-media { display: block; width: 210px; max-width: 100%; border-radius: 12px; overflow: hidden; position: relative; cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); margin-bottom: 2px; }
.thumb-media img { display: block; width: 100%; height: auto; min-height: 80px; object-fit: cover; }
.thumb-media .play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.thumb-media .play span { width: 44px; height: 44px; border-radius: 50%; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; }
.thumb-media .ph { height: 140px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; background: linear-gradient(160deg, #ff4fa3, #ff8c42 55%, #ffb547); }
.media-chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.load-older { align-self: center; margin-bottom: 8px; }
.typing-banner { padding: 4px 18px; font-size: 11px; color: var(--muted); min-height: 20px; }
.empty-convo { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px; color: var(--muted); }

/* Suggestion IA */
.suggestion {
  margin: 0 14px 8px; border: 1px solid rgba(61, 99, 255, .45); background: var(--accent-soft); border-radius: 12px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.suggestion.orange { border-color: rgba(245, 158, 11, .55); background: var(--orange-soft); }
.suggestion .lbl { font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; display: flex; gap: 6px; align-items: center; }
.suggestion .txt { font-size: 13px; font-weight: 600; white-space: pre-wrap; }

/* Composer */
.composer { min-width: 0; border-top: 1px solid var(--line); background: var(--panel); padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 8px; position: relative; }
.toolbar { display: flex; align-items: center; gap: 5px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.tb-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; }
.tb-btn:hover, .tb-btn.on { color: var(--text); border-color: var(--accent); }
.tb-btn.icon-only { padding: 0 7px; }
.tb-btn.note { border-color: rgba(245, 158, 11, .6); color: var(--orange); }
.tb-btn svg { width: 14px; height: 14px; }
.emoji-btn { border: 0; background: none; font-size: 17px; padding: 0 2px; flex: none; line-height: 1; }
.emoji-btn:hover { transform: scale(1.18); }
.send-row { display: flex; gap: 10px; align-items: stretch; }
.send-row .textarea { min-width: 0; min-height: 44px; max-height: 160px; resize: none; padding: 11px 12px; }
.send-col { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.send-btn { height: 44px; padding: 0 22px; border-radius: 9px; background: var(--accent); color: #fff; border: 0; font-weight: 700; letter-spacing: .6px; }
.send-btn:hover { background: var(--accent-2); }
.send-btn:disabled { opacity: .55; }
.clear-btn { border: 0; background: none; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .5px; }
.note-mode .textarea { border-color: var(--orange); background: rgba(245, 158, 11, .06); }

/* Popovers (scripts, médias, liens, programmer) */
.popover {
  position: absolute; bottom: calc(100% + 6px); left: 12px; right: 12px; max-width: 640px; background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow); z-index: 40; display: none; max-height: 70vh;
  flex-direction: column; overflow: hidden;
}
.popover.open { display: flex; }
.popover .pop-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.popover .pop-body { overflow-y: auto; padding: 0 12px 10px; }
.popover .pop-foot { padding: 8px 12px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-chip { height: 26px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2); font-size: 11.5px; font-weight: 600; display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.cat-chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.cat-chip .n { color: var(--muted); font-weight: 500; }
.cat-desc { font-size: 12px; color: var(--muted); padding: 6px 2px; border-top: 1px solid var(--line); margin-top: 2px; }
.script-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.script-item:hover { background: var(--panel-2); }
.script-item.sent { background: var(--panel-2); border-color: var(--line); }
.script-item .num { width: 22px; height: 22px; border-radius: 6px; background: var(--panel-3); color: var(--text-2); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none; }
.script-item.sent .num { background: var(--green); color: #052e12; }
.script-item .t { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.script-item .b { font-weight: 600; font-size: 13px; }
.script-item .when { color: var(--orange); font-size: 11px; font-weight: 600; margin-top: 2px; }
.script-item .prog { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.content-thumb { position: relative; border-radius: 9px; overflow: hidden; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; aspect-ratio: 1; }
.content-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.content-thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; font-size: 10.5px; font-weight: 600; background: linear-gradient(transparent, rgba(0, 0, 0, .8)); color: #fff; }
.content-thumb .price { position: absolute; top: 5px; right: 5px; }
.content-thumb.sel { outline: 2px solid var(--accent); }
.link-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); margin-bottom: 6px; }
.link-item .price { font-weight: 700; font-size: 14px; min-width: 64px; }

/* Panneau Fan insights */
.insights { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }
.insights .since { text-align: center; font-size: 12px; font-weight: 600; padding: 12px 10px 8px; color: var(--text-2); }
.ins-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 12px 10px; }
.ins-tabs button { border: 0; background: transparent; color: var(--text-2); padding: 7px 4px; border-radius: 8px; font-weight: 600; font-size: 12px; }
.ins-tabs button.active { background: var(--accent); color: #fff; }
.ins-body { padding: 0 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.ins-intro { color: var(--text-2); font-size: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.ins-explain { font-size: 12px; line-height: 1.45; color: var(--text-2); background: var(--bg-2); border: 1px solid var(--line-2); border-left: 3px solid var(--muted); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }
.ins-explain b { color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.kpi { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 9px; }
.kpi b { display: block; font-size: 15px; color: var(--green); }
.kpi.neutral b { color: var(--text); }
.kpi span { font-size: 10.5px; color: var(--muted); }
.ins-section h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.fan-head { display: flex; gap: 12px; align-items: center; }
.tier-select { display: flex; flex-wrap: wrap; gap: 5px; }
.tier-btn { border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2); border-radius: 7px; height: 26px; padding: 0 8px; font-size: 11.5px; font-weight: 600; }
.tier-btn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.pay-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.timeline-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline-item .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--green); }
.timeline-item .dot.pending { background: var(--orange); }
.timeline-item .dot.cancelled { background: var(--muted); }
.tag-input { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px; }
.tag-input input { border: 0; background: transparent; outline: 0; min-width: 80px; flex: 1; color: var(--text); font-size: 12px; }
.tag-input .badge button { background: none; border: 0; color: inherit; padding: 0 0 0 2px; font-size: 12px; line-height: 1; }
.notes-area { min-height: 150px; font-size: 12.5px; }
.saved-flag { font-size: 11px; color: var(--green); opacity: 0; transition: .3s; }
.saved-flag.show { opacity: 1; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); display: none; align-items: center; justify-content: center; z-index: 300; flex-direction: column; gap: 10px; }
.lightbox.open { display: flex; }
.lightbox img, .lightbox video { max-width: 92vw; max-height: 84vh; border-radius: 10px; }
.lightbox .lb-close { position: absolute; top: 14px; right: 18px; font-size: 26px; color: #fff; background: none; border: 0; }

/* Scénarios */
.sc-card { border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 7px; }
.sc-card.current { border-color: var(--accent); background: var(--accent-soft); }
.sc-bar { height: 6px; background: var(--bg-2); border-radius: 4px; overflow: hidden; display: flex; gap: 2px; }
.sc-bar i { flex: 1; background: var(--line-2); }
.sc-bar i.done { background: var(--accent); }
.sc-bar i.paid { background: var(--green); }
.st-badge-not_started { background: var(--panel-3); color: var(--text-2); }
.st-badge-started, .st-badge-media_offered { background: var(--accent-soft); color: var(--accent-2); }
.st-badge-media_sold { background: var(--green-soft); color: var(--green); }
.st-badge-goal_reached { background: var(--green); color: #052e12; }
.st-badge-crammed { background: var(--red-soft); color: var(--red); }

/* Bibliothèque / pages owner */
.lib-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-list button { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; color: var(--text-2); display: flex; gap: 6px; }
.cat-list button.active { background: var(--accent-soft); color: var(--text); }
.cat-list button .n { margin-left: auto; color: var(--muted); }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.kpi-card span { color: var(--muted); font-size: 11.5px; }
.kpi-card b { display: block; font-size: 22px; margin-top: 4px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; }
.bars { justify-content: center; }
.bars .bar { flex: 1; max-width: 26px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar.alt { background: var(--green); }
.bars .bar:hover { opacity: .8; }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Bottom nav (mobile) */
.mobile-back { display: none; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1250px) {
  .chat-grid { grid-template-columns: 280px minmax(0, 1fr) 0; }
  .chat-grid .insights { display: none; }
  .chat-grid.show-insights .insights { display: flex; position: fixed; right: 0; top: var(--topbar-h); bottom: 0; width: 340px; z-index: 50; box-shadow: var(--shadow); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) 1fr 56px; }
  .rail { grid-row: 3; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 0 6px; }
  .rail .sep, .rail .bottom { display: none; }
  .rail a { width: 44px; height: 44px; }
  .rail a .tip { display: none; }
  .search, .hide-sm { display: none !important; }
  .topbar .brand-center { position: static; transform: none; pointer-events: auto; }
  .page { padding: 16px; }
  .grid-2, .grid-3, .lib-layout { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .chat-grid { grid-template-columns: minmax(0, 1fr); }
  .convo-head .tools { gap: 2px; }
  .convo-head .icon-btn#searchMsgBtn { display: none; }
  .chat-grid .convo { display: none; }
  .chat-grid.in-convo .inbox { display: none; }
  .chat-grid.in-convo .convo { display: flex; }
  .chat-grid.show-insights .insights { left: 0; width: auto; top: var(--topbar-h); bottom: 56px; }
  .mobile-back { display: inline-flex; }
  .msg { max-width: 86%; }
  .conv-tabs { display: none; }
  .chat-shell { grid-template-rows: 1fr; }
  .send-btn { padding: 0 14px; }
  .icon-btn, .tb-btn, .chip { min-height: 32px; }
  .popover { left: 6px; right: 6px; }
  .modal { border-radius: 12px; }
}

/* ── Sélecteur rapide de comptes (barre gauche) ─────────────────── */
.acc-switch { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail a.acc-dot { width: 36px; height: 36px; padding: 0; }
.rail a.acc-dot .avatar { width: 30px; height: 30px; font-size: 12px; border: 2px solid transparent; }
.rail a.acc-dot.active .avatar { border-color: var(--accent); }
.rail a.acc-dot.off .avatar { filter: grayscale(1); opacity: .6; }
.acc-unread { position: absolute; top: -3px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--red, #ef4444); color: #fff; font-size: 9.5px; font-weight: 700; line-height: 16px; text-align: center; }
.acc-unread.hidden { display: none; }

/* ── Double vue : deux comptes côte à côte ──────────────────────── */
.duo { display: grid; grid-template-columns: 1fr 1fr; height: 100%; min-height: 0; }
.duo-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.duo-pane:last-child { border-right: 0; }
.duo-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--bg-2); border-bottom: 1px solid var(--line); overflow-x: auto; }
.duo-acc { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 4px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.duo-acc .avatar { width: 24px; height: 24px; font-size: 11px; }
.duo-acc.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.duo-acc.taken { opacity: .35; cursor: not-allowed; }
.duo-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }
@media (max-width: 860px) { .duo { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } .duo-pane { border-right: 0; border-bottom: 1px solid var(--line); } }

/* Page chargée dans la double vue : ni barre du haut ni barre gauche. */
html.embed { --topbar-h: 0px; }
html.embed .topbar, html.embed .rail { display: none !important; }
html.embed .app { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: minmax(0, 1fr) !important; }
@media (min-width: 600px) and (max-width: 860px) {
  html.embed .chat-grid { grid-template-columns: 230px minmax(0, 1fr); }
  html.embed .chat-grid .convo, html.embed .chat-grid.in-convo .inbox { display: flex; }
  html.embed .mobile-back { display: none; }
  html.embed .chat-grid.show-insights .insights { left: auto; width: 320px; bottom: 0; }
}
@media (max-width: 860px) { html.embed .chat-grid.show-insights .insights { bottom: 0; } }
@media (max-width: 860px) { .acc-switch { flex-direction: row; } .acc-switch #duoLink { display: none; } }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { overflow-x: auto; justify-content: flex-start; gap: 4px; min-width: 0; scrollbar-width: none; }
  .rail > *, .acc-switch > * { flex: 0 0 auto; }
}

.pin-mark { font-size: 11px; margin-right: 3px; }
#pinBtn { font-size: 13px; filter: grayscale(1); opacity: .65; }
#pinBtn.active { filter: none; opacity: 1; }

/* ── Kill-switch global IA (v4) ─────────────────────────────────── */
#globalAiBtn { background: #22c55e; color: #fff; }
#globalAiBtn.ai-off { background: #ef4444; animation: pulse-red 1.2s infinite; }
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
  50%       { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}
body.global-ai-off .ai-toggle { opacity: .4; pointer-events: none; }
