:root {
  --bg-app: #f6f5f2;
  --bg-sidebar: #fbfaf8;
  --bg-header: #fbfaf8;
  --bg-card: #ffffff;
  --bg-card-hover: #f1efeb;
  --bg-active: #e6eef7;
  --bg-chat: #f1efea;
  --bg-input: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #e2ecf6;
  --bubble-out-text: #25303b;
  --bubble-in-text: #2b2d31;
  --border: #e6e3dd;
  --border-strong: #d6d2ca;
  --text-main: #2b2d31;
  --text-muted: #6d7078;
  --text-dim: #9a9ca2;
  --accent: #4e79a7;
  --accent-hover: #426a95;
  --accent-soft: #e2ebf5;
  --on-accent: #ffffff;
  --send: #4f8a6b;
  --send-hover: #437a5d;
  --green: #3f7d5c;  --green-soft: #e3f1e8;
  --yellow: #93661b; --yellow-soft: #f8eed8;
  --orange: #a3552b; --orange-soft: #f9e6da;
  --red: #b0414b;    --red-soft: #f8e3e5;
  --violet: #6e5a9e; --violet-soft: #ece7f6;
  --teal: #2f7a78;   --teal-soft: #dff0ef;
  --composer-bg: #fbfaf8;
  --composer-input-bg: #ffffff;
  --composer-input-border: #dcd8d0;
  --shadow-bubble: 0 1px 1px rgba(40,38,34,0.06);
  --shadow-pop: 0 12px 32px rgba(40,38,34,0.16);
  --radius: 10px;
}
:root[data-theme="dark"] {
  --bg-app: #1b1c1f;
  --bg-sidebar: #202125;
  --bg-header: #202125;
  --bg-card: #26272b;
  --bg-card-hover: #2b2c31;
  --bg-active: #2c3542;
  --bg-chat: #1b1c1f;
  --bg-input: #26272b;
  --bubble-in: #2a2b30;
  --bubble-out: #2e3b4a;
  --bubble-out-text: #e8ebef;
  --bubble-in-text: #e6e6e3;
  --border: #303136;
  --border-strong: #3c3d43;
  --text-main: #e6e6e3;
  --text-muted: #a0a2a8;
  --text-dim: #74767d;
  --accent: #93b4d8;
  --accent-hover: #a8c3e1;
  --accent-soft: #2c3542;
  --on-accent: #16191d;
  --send: #8fc2a3;
  --send-hover: #a3cfb4;
  --green: #9dcfae;  --green-soft: #26352c;
  --yellow: #e2c27f; --yellow-soft: #3a3223;
  --orange: #e8ab86; --orange-soft: #3b2c24;
  --red: #e79ca2;    --red-soft: #3d2729;
  --violet: #bcaee3; --violet-soft: #312c3f;
  --teal: #8fcfcb;   --teal-soft: #223534;
  --composer-bg: #202125;
  --composer-input-bg: #26272b;
  --composer-input-border: #3a3b41;
  --shadow-bubble: none;
  --shadow-pop: 0 12px 32px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg-app);
  color: var(--text-main);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, select, input, textarea { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button:disabled { opacity: 0.45; cursor: default; }
[hidden] { display: none !important; }
svg.i { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* Header */
.app-header {
  height: 52px; background: var(--bg-header); border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; padding: 0 16px; gap: 20px; flex-shrink: 0;
}
.brand { margin: 0; font-size: 15px; font-weight: 450; letter-spacing: -0.3px; color: var(--text-muted); white-space: nowrap; text-align: center; }
.brand span { font-weight: 750; color: var(--text-main); }
.header-tabs { display: flex; align-items: center; gap: 7px; }
.tab-btn {
  --tab-color: var(--accent); background: color-mix(in srgb, var(--bg-card) 75%, transparent); border: 1px solid color-mix(in srgb, var(--border) 65%, transparent); color: var(--text-muted); font-size: 12.5px; font-weight: 600;
  height: 32px; padding: 0 11px; border-radius: 18px; cursor: pointer; display: flex; align-items: center; gap: 8px; white-space: nowrap;
  box-shadow: 0 2px 5px rgba(40,38,34,0.04); transition: background 150ms, border-color 150ms, box-shadow 150ms;
}
.tab-btn[data-tab="attente"] { --tab-color: var(--accent); }
.tab-btn[data-tab="non_reponse"] { --tab-color: var(--yellow); }
.tab-btn[data-tab="traite"] { --tab-color: var(--red); }
.tab-btn:hover { background: color-mix(in srgb, var(--bg-card) 70%, transparent); color: var(--text-main); }
.tab-btn.active { background: color-mix(in srgb, var(--tab-color) 14%, var(--bg-card)); color: var(--text-main); font-weight: 650; border-color: color-mix(in srgb, var(--tab-color) 28%, var(--border)); box-shadow: 0 2px 9px color-mix(in srgb, var(--tab-color) 14%, transparent); }
.tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tab-btn.active .tab-badge:not(.red) { background: color-mix(in srgb, var(--tab-color) 20%, var(--bg-card)); color: var(--text-main); }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center; height: 21px; font-size: 11px; min-width: 21px; padding: 0 6px; border-radius: 11px; font-weight: 650;
  background: var(--bg-card-hover); color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.tab-badge.red { background: var(--red-soft); color: var(--red); }
.header-right { justify-self: end; display: flex; align-items: center; gap: 14px; font-size: 12.5px; color: var(--text-muted); }
.header-status { display: flex; align-items: center; gap: 14px; padding-left: 14px; border-left: 1px solid var(--border); min-height: 30px; white-space: nowrap; }
.header-tools { display: flex; align-items: center; padding-left: 12px; border-left: 1px solid var(--border); }
.header-tools .icon-btn { border-color: var(--border); background: var(--bg-card); border-radius: 50%; }
.sync { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 4px 0; color: var(--text-muted); cursor: pointer; }
.sync:hover { color: var(--text-main); }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.sync[data-state="ok"]::before { background: var(--green); }
.sync[data-state="late"]::before { background: var(--yellow); }
.sync[data-state="down"]::before { background: var(--red); }
#kpi-wait-time { font-variant-numeric: tabular-nums; }
#kpi-wait-time.urgent { color: var(--red); }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-main); }
.console-warning-btn {
  background: var(--red-soft); border: none; color: var(--red); font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}

/* Layout */
.app-main { flex: 1; min-height: 0; display: flex; gap: 10px; padding: 10px; overflow: hidden; }
.sidebar {
  width: 320px; background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 18px;
  display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; box-shadow: 0 3px 14px rgba(40,38,34,0.035);
}
.search-box { padding: 12px 10px 9px; display: flex; gap: 8px; }
.search-input, .stage-select {
  height: 34px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-card);
  font-size: 13px; outline: none;
}
.search-input { flex: 1; min-width: 0; padding: 0 10px; }
.stage-select { width: 118px; padding: 0 6px; color: var(--text-muted); cursor: pointer; }
.stage-filter { position: relative; width: 118px; flex-shrink: 0; }
.stage-filter .stage-select { display: flex; align-items: center; gap: 6px; padding: 0 10px; }
.stage-filter-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.stage-filter .stage-select[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text-main); }
.stage-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 100; width: 218px; max-height: min(420px, 65vh); overflow-y: auto; padding: 6px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 15px; box-shadow: var(--shadow-pop); }
.stage-option { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 7px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--text-main); font-size: 12.5px; text-align: left; cursor: pointer; }
.stage-option:hover, .stage-option:focus-visible { background: var(--bg-card-hover); outline: none; }
.stage-option[aria-checked="true"] { background: var(--accent-soft); font-weight: 650; }
.stage-option::before { content: ""; width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: var(--stage-color, var(--text-dim)); }
.stage-option::after { content: ""; margin-left: auto; }
.stage-option[aria-checked="true"]::after { content: "✓"; color: var(--accent); }
.stage-option[data-stage=""] { margin-bottom: 5px; }
.stage-option[data-stage="new lead"], .stage-option[data-stage="qualifying"], .stage-option[data-stage="budget"] { --stage-color: var(--accent); }
.stage-option[data-stage="link sent"] { --stage-color: var(--violet); }
.stage-option[data-stage="waiting deposit"] { --stage-color: var(--yellow); }
.stage-option[data-stage="deposited"] { --stage-color: var(--green); }
.stage-option[data-stage="objection"] { --stage-color: var(--red); }
.stage-option[data-stage="support"] { --stage-color: var(--teal); }
/* Stage of the open conversation: a pill and the same bubble menu (stage-picker.mjs) */
#chat-etape-select { display: none; }
.stage-pill { --stage-color: var(--text-dim); display: inline-flex; align-items: center; height: 24px; padding: 0 24px 0 10px; border: 0; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--text-main); cursor: pointer; white-space: nowrap;
  background: linear-gradient(45deg, transparent 50%, currentColor 50%) right 12px center / 5px 5px no-repeat, linear-gradient(-45deg, transparent 50%, currentColor 50%) right 8px center / 5px 5px no-repeat, color-mix(in srgb, var(--stage-color) 16%, var(--bg-card)); }
.stage-pill::before { content: ""; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--stage-color); }
.stage-pill:hover, .stage-pill[aria-expanded="true"] { background-color: color-mix(in srgb, var(--stage-color) 26%, var(--bg-card)); }
.stage-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stage-pill:is([data-stage="new lead"], [data-stage="qualifying"], [data-stage="budget"]) { --stage-color: var(--accent); }
.stage-pill[data-stage="link sent"] { --stage-color: var(--violet); }
.stage-pill[data-stage="waiting deposit"] { --stage-color: var(--yellow); }
.stage-pill[data-stage="deposited"] { --stage-color: var(--green); }
.stage-pill[data-stage="objection"] { --stage-color: var(--red); }
.stage-pill[data-stage="support"] { --stage-color: var(--teal); }
.stage-menu.stage-pill-menu { position: fixed; inset: auto; right: auto; margin: 0; color: var(--text-main); }
.stage-pill-menu:popover-open { animation: stage-pop .14s ease-out; }
@keyframes stage-pop { from { opacity: 0; transform: translateY(-4px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .stage-pill-menu:popover-open { animation: none; } }
.search-input:focus, .stage-select:focus { border-color: var(--accent); }

.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 7px 7px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.conv-item {
  position: relative; display: block; margin: 4px 0; padding: 10px 10px 10px 13px; border: 1px solid transparent;
  border-radius: 13px; cursor: pointer; user-select: none; transition: background 140ms, border-color 140ms, box-shadow 140ms;
}
.conv-item::before { content: ""; position: absolute; left: -4px; top: 9px; bottom: 9px; width: 4px; border-radius: 4px 0 0 4px; background: var(--acc, transparent); box-shadow: -1px 0 4px color-mix(in srgb, var(--acc, transparent) 15%, transparent); opacity: .7; pointer-events: none; }
.conv-item:hover { background: var(--bg-card-hover); }
.conv-item.active { background: var(--bg-active); }
.conv-item.is-waiting .conv-name { font-weight: 650; }
.conv-content { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.conv-row-top, .conv-row-bot { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-row-top { justify-content: space-between; }
.conv-name { font-weight: 550; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-user { color: var(--text-dim); font-size: 12px; font-weight: 400; margin-left: 3px; }
/* Comptes : la barre gauche = le compte Telegram qui repond a cette conversation */
.conv-item { background: color-mix(in srgb, var(--acc, transparent) 4%, transparent); }
.conv-item:hover { background: color-mix(in srgb, var(--acc, transparent) 8%, var(--bg-card-hover)); }
.conv-item.active { border-color: color-mix(in srgb, var(--acc, var(--accent)) 25%, var(--border)); background: color-mix(in srgb, var(--acc, var(--accent)) 15%, var(--bg-sidebar)); box-shadow: 0 2px 7px rgba(40,38,34,0.05); }
.conv-item.active::before { opacity: 1; }
/* Flat rows, Telegram-like (04/11): no boxed cards, a thin line between rows, the account kept as a short bar */
.conv-list { padding: 4px 6px 7px; }
.conv-item { margin: 0; padding: 11px 12px 11px 16px; border: 0; border-radius: 12px; box-shadow: none; background: transparent; }
.conv-item::before { left: 5px; top: 13px; bottom: 13px; width: 3px; border-radius: 3px; box-shadow: none; opacity: .85; }
.conv-item + .conv-item::after { content: ""; position: absolute; left: 16px; right: 12px; top: 0; height: 1px; background: var(--border); pointer-events: none; }
.conv-item:is(.active, :hover)::after, .conv-item:is(.active, :hover) + .conv-item::after { opacity: 0; }
.conv-item:hover { background: color-mix(in srgb, var(--acc, transparent) 6%, var(--bg-card-hover)); }
.conv-item.active { border: 0; box-shadow: none; background: color-mix(in srgb, var(--acc, var(--accent)) 14%, var(--bg-sidebar)); }
.conv-name { font-size: 14px; font-weight: 600; }
.conv-item.is-waiting .conv-name { font-weight: 750; }
.conv-content { gap: 4px; }
.accounts { display: flex; align-items: center; gap: 7px; }
.account-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent); background: color-mix(in srgb, var(--bg-card) 75%, transparent); color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 5px rgba(40,38,34,0.04); transition: background 150ms, border-color 150ms, box-shadow 150ms;
}
.account-chip:hover { background: var(--bg-card-hover); color: var(--text-main); }
.account-chip.active { border-color: color-mix(in srgb, var(--acc) 28%, var(--border)); color: var(--text-main); background: color-mix(in srgb, var(--acc) 16%, var(--bg-card)); box-shadow: 0 2px 9px color-mix(in srgb, var(--acc) 16%, transparent), inset 0 1px 0 color-mix(in srgb, var(--bg-card) 70%, transparent); }
.account-chip.account-all { min-width: 54px; }
.account-chip.account-all.active { border-color: color-mix(in srgb, var(--accent) 20%, var(--border)); background: linear-gradient(110deg, color-mix(in srgb, #5B7FA6 24%, var(--bg-card)), color-mix(in srgb, #C9A43A 26%, var(--bg-card))); box-shadow: 0 2px 9px color-mix(in srgb, var(--accent) 12%, transparent); }
.account-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.account-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--acc); flex-shrink: 0; }
.account-warn { font-weight: 800; color: var(--orange); }
.account-chip.down .account-warn { color: var(--red); }
.chat-panel[data-compte] .msg.nous { background: color-mix(in srgb, var(--acc) 32%, var(--bubble-in)); }
:root[data-theme="dark"] .chat-panel[data-compte] .msg.nous { background: color-mix(in srgb, var(--acc) 40%, var(--bubble-in)); }
.chat-panel[data-compte] { background: color-mix(in srgb, var(--acc) 13%, var(--bg-chat)); }
:root[data-theme="dark"] .chat-panel[data-compte] { background: color-mix(in srgb, var(--acc) 15%, var(--bg-chat)); }
.chat-account { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.yz-pill { display: inline-flex; align-items: center; flex-shrink: 0; padding: 1px 7px; border: 1px solid #c3b3e0; border-radius: 999px; background: #efe8fa; color: #5f4391; font-size: 10px; font-weight: 700; letter-spacing: .04em; line-height: 1.5; }
:root[data-theme="dark"] .yz-pill { background: #2f2840; color: #c7b3f0; border-color: #5d4c84; }
.send-from b { font-weight: 750; }
.photo-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.photo-row:empty { display: none; }
.photo-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); font-size: 12.5px; color: var(--text-muted); }
.photo-chip img { width: 46px; height: 46px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.photo-chip b { color: var(--text-main); font-weight: 600; }
.photo-chip.missing { border-color: var(--red); color: var(--red); padding: 6px 8px; }
.photo-chip button { border: none; background: transparent; color: var(--text-muted); font-size: 16px; line-height: 1; padding: 2px 5px; border-radius: 6px; cursor: pointer; }
.photo-chip button:hover { background: var(--red-soft); color: var(--red); }
select.btn-tool { max-width: 150px; }
.emoji-picker { position: fixed; margin: 0; width: min(320px, calc(100vw - 24px)); padding: 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg-card); color: var(--text-main); box-shadow: var(--shadow-pop); }
.emoji-picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; font-weight: 600; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.emoji-grid button { border: 0; border-radius: 8px; background: transparent; padding: 5px 0; font-size: 23px; line-height: 1.2; cursor: pointer; }
.emoji-grid button:hover { background: var(--accent-soft); }

.photo-picker { margin: auto; width: min(540px, calc(100vw - 32px)); max-height: 80vh; padding: 0; border: 1px solid var(--border); border-radius: 20px; background: var(--bg-card); color: var(--text-main); box-shadow: var(--shadow-pop); }
.photo-picker::backdrop { background: rgba(20,20,22,.45); }
.photo-picker-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.photo-picker-header h2 { margin: 0; font-size: 15px; font-weight: 650; }
.photo-picker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px; }
.photo-choice { display: flex; flex-direction: column; gap: 9px; padding: 8px; border: 1px solid var(--border); border-radius: 13px; background: var(--bg-sidebar); color: var(--text-main); cursor: pointer; text-align: left; font-size: 12.5px; }
.photo-choice:hover { background: var(--accent-soft); border-color: var(--accent); }
.photo-choice img { width: 100%; aspect-ratio: 16 / 10; object-fit: contain; border-radius: 8px; background: var(--bg-app); }
.photo-choice-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 3px 3px; }
.photo-choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.photo-choice[aria-pressed="true"] .photo-choice-label::after { content: "✓"; color: var(--accent); }
.btn-send .account-dot { box-shadow: 0 0 0 1.5px var(--send-ink, #ffffff); }
.conv-time { font-size: 11.5px; font-variant-numeric: tabular-nums; padding: 1px 7px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.conv-time.calme { background: var(--green-soft); color: var(--green); }
.conv-time.tiede { background: var(--yellow-soft); color: var(--yellow); }
.conv-time.chaud { background: var(--orange-soft); color: var(--orange); }
.conv-time.brulant { background: var(--red-soft); color: var(--red); }
.conv-time.date-subtle { background: transparent; color: var(--text-dim); font-weight: 500; padding: 1px 0; }
.conv-snippet { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-snippet .you { color: var(--text-dim); }

.badge-etape {
  font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 10px; line-height: 18px;
  background: var(--bg-card-hover); color: var(--text-muted); white-space: nowrap;
}
.badge-etape[data-stage="deposited"] { background: var(--green-soft); color: var(--green); }
.badge-etape[data-stage="waiting deposit"] { background: var(--yellow-soft); color: var(--yellow); }
.badge-etape[data-stage="qualifying"], .badge-etape[data-stage="new lead"], .badge-etape[data-stage="budget"] { background: var(--accent-soft); color: var(--accent); }
.badge-etape[data-stage="objection"], .badge-etape[data-stage="needs you"] { background: var(--red-soft); color: var(--red); }
.badge-etape[data-stage="link sent"] { background: var(--violet-soft); color: var(--violet); }
.badge-etape[data-stage="support"] { background: var(--teal-soft); color: var(--teal); }
