:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --border: #e7e5e4;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --call: #15803d;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  --radius: 12px;
  --s-a_appeler: #78716c;
  --s-pas_de_reponse: #c2410c;
  --s-rappeler: #7c3aed;
  --s-interesse: #15803d;
  --s-rdv: #0f766e;
  --s-pas_interesse: #b91c1c;
  --s-faux_numero: #44403c;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --surface: #1c1917;
    --surface-2: #171412;
    --border: #2e2a27;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --accent: #60a5fa;
    --accent-text: #0c0a09;
    --call: #4ade80;
    --danger-bg: #3b1212;
    --danger-text: #fca5a5;
    --shadow: none;
    --s-a_appeler: #a8a29e;
    --s-pas_de_reponse: #fb923c;
    --s-rappeler: #a78bfa;
    --s-interesse: #4ade80;
    --s-rdv: #2dd4bf;
    --s-pas_interesse: #f87171;
    --s-faux_numero: #d6d3d1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* App bar and toolbar */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.live { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--call); }
.live.stale::before { background: var(--danger-text); }
.appbar .spacer { flex: 1; }
.text-button { background: none; border: 0; color: var(--muted); padding: 6px; font-size: 13px; }

.toolbar { padding: 12px 16px 8px; display: grid; gap: 10px; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--border); border-radius: 10px; padding: 3px; }
.tabs button {
  border: 0; background: transparent; border-radius: 8px; padding: 8px; font-weight: 600; font-size: 14px; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs .count { font-weight: 500; color: var(--muted); margin-left: 4px; }

.search {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
}
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 10px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); max-width: 200px;
}
label.chip { display: flex; align-items: center; gap: 6px; color: var(--muted); }

/* Queue view */
/* minmax(0, 1fr): let long, unbreakable names shrink instead of pushing the call button out. */
.queue { padding: 0 16px 96px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.meta-line { font-size: 12px; color: var(--muted); padding: 0 2px; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 12px 12px 14px; box-shadow: var(--shadow); cursor: pointer;
}
.card.opposed { opacity: 0.45; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-foot { display: flex; gap: 10px; align-items: center; margin-top: 4px; font-size: 12px; }
.call-icon {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--call); color: #fff;
}
.call-icon svg { width: 20px; height: 20px; }
.call-icon[aria-disabled="true"] { background: var(--border); pointer-events: none; }
.more { margin: 8px auto; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }

.pill { font-size: 12px; font-weight: 600; color: var(--status-color, var(--muted)); white-space: nowrap; }
.pill::before { content: "● "; }

/* Board view */
.board {
  display: flex; gap: 12px; overflow-x: auto; padding: 0 16px 96px;
  scroll-snap-type: x mandatory; scroll-padding: 16px; align-items: flex-start;
}
.column {
  flex: none; width: 85vw; max-width: 320px; scroll-snap-align: start;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: calc(100dvh - 210px);
}
.column-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px;
  border-top: 3px solid var(--status-color); border-radius: var(--radius) var(--radius) 0 0;
}
.column-head .count { color: var(--muted); font-weight: 500; }
.column-body { overflow-y: auto; padding: 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.column .card { padding: 10px; gap: 8px; }
.column .call-icon { width: 36px; height: 36px; }
.column-empty { font-size: 13px; color: var(--muted); text-align: center; padding: 16px 0; }

/* Detail sheet */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 20; }
.sheet {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 16px 16px 0 0; padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.2s ease;
}
.sheet.open { transform: none; }
.grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sheet h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.sheet .sub { color: var(--muted); font-size: 14px; margin: 2px 0 0; }
.close { border: 0; background: var(--border); border-radius: 50%; width: 32px; height: 32px; flex: none; }
.warning { background: var(--danger-bg); color: var(--danger-text); padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; }

.call-button {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 8px;
  background: var(--call); color: #fff; font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums; padding: 14px; border-radius: 12px;
}
.call-button svg { width: 22px; height: 22px; }
.call-button[aria-disabled="true"] { background: var(--muted); pointer-events: none; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.actions a, .actions button {
  text-align: center; padding: 8px; border-radius: 10px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.actions [aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

.facts { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; margin: 0 0 14px; font-size: 14px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.section-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 16px 0 8px; }
.outcomes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.outcomes button {
  text-align: left; padding: 11px 12px; border-radius: 10px; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border); border-left: 4px solid var(--status-color); background: var(--surface);
}
.outcomes button[aria-pressed="true"] { background: var(--surface-2); outline: 2px solid var(--status-color); }
.field { display: grid; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.field textarea, .field input { padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.history { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.history li { padding: 8px 0; border-top: 1px solid var(--border); }
.history time { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; z-index: 40; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form {
  width: 100%; max-width: 360px; display: grid; gap: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 24px;
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login input { padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.login button { padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.login .error { color: var(--danger-text); font-size: 14px; margin: 0; }

/* Larger screens */
@media (min-width: 900px) {
  .toolbar { grid-template-columns: 280px 1fr auto; align-items: center; padding: 14px 24px 10px; }
  .queue { max-width: 760px; margin: 0 auto; padding: 0 24px 40px; }
  .board { padding: 0 24px 24px; scroll-snap-type: none; }
  .column { width: 290px; max-height: calc(100dvh - 140px); }
  .sheet {
    left: auto; top: 0; width: 440px; max-height: none; border-radius: 0;
    border-left: 1px solid var(--border); transform: translateX(100%); padding: 20px 24px;
  }
  .sheet.open { transform: none; }
  .grabber { display: none; }
}

/* Dev tab */
.dev { padding: 0 16px 40px; display: grid; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: grid; gap: 2px; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 24px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile-detail { font-size: 12px; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.panel h2 { font-size: 14px; margin: 0; }
.dev-grid, .dev-side { display: grid; gap: 12px; min-width: 0; }

.feed { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; max-height: 60dvh; overflow-y: auto; }
.feed-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.feed-main { display: grid; min-width: 0; }
.feed-side { display: grid; text-align: right; font-variant-numeric: tabular-nums; flex: none; }
/* LIFO stack: each new lead drops in on top and pushes the rest down. */
.feed-item.fresh { animation: push-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), glow 2.5s ease-out; }
@keyframes push-in { from { opacity: 0; transform: translateY(-16px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes glow { from { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); } to { border-color: var(--border); background: transparent; } }
@media (prefers-reduced-motion: reduce) { .feed-item.fresh { animation: none; } }

.hbar { display: grid; grid-template-columns: 110px 1fr 48px; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.hbar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 10px; }
.hbar-fill { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; }
.vbars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 90px; border-bottom: 1px solid var(--border); }
.vbar { height: 100%; display: flex; align-items: flex-end; cursor: default; }
.vbar:hover .vbar-fill { opacity: 0.7; }
.vbar-fill { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.vbars-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

.table-wrap { overflow-x: auto; }
.team { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.team th, .team td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.team th:first-child, .team tbody th { text-align: left; }
.team thead th { color: var(--muted); font-weight: 500; font-size: 12px; }

@media (min-width: 900px) {
  .dev { max-width: 1200px; margin: 0 auto; padding: 0 24px 40px; }
  .tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .dev-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; }
}

/* Call mode (swipe), full screen */
:root { --s-corbeille: #a8a29e; --trash: #dc2626; }
body.fullscreen .toolbar { padding-bottom: 4px; }
.swipe { padding: 0 12px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  height: calc(100dvh - 112px); max-width: 560px; margin: 0 auto; }
.swipe-top { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
.swipe-stage { position: relative; flex: 1; min-height: 0; display: grid; }
.swipe-stage > * { grid-area: 1 / 1; }
.swipe-card {
  position: relative; z-index: 3; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 22px 18px; box-shadow: 0 10px 30px rgb(0 0 0 / 0.12);
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 0.25s ease, opacity 0.25s ease; will-change: transform;
}
.swipe-card.dragging { transition: none; cursor: grabbing; }
.swipe-card.leaving { opacity: 0; }
.swipe-card textarea, .swipe-card input { user-select: text; }
.swipe-front { display: flex; flex-direction: column; min-height: 100%; }
.swipe-category { margin: 0; font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.swipe-card h2 { margin: 6px 0 0; font-size: 26px; line-height: 1.2; }
.swipe-card .sub { color: var(--muted); margin: 4px 0 0; font-size: 16px; }
.swipe-phone { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 18px 0; }
.swipe-phone svg { width: 22px; height: 22px; color: var(--call); }
.swipe-help { margin-top: auto; text-align: center; color: var(--muted); font-size: 13px; padding-top: 12px; }
.swipe-stamp {
  position: absolute; top: 22px; padding: 6px 12px; border: 3px solid; border-radius: 10px;
  font-weight: 800; font-size: 20px; text-transform: uppercase; pointer-events: none;
}
.stamp-trash { right: 18px; color: var(--trash); transform: rotate(12deg); opacity: var(--trash-opacity, 0); }
.stamp-call { left: 18px; color: var(--call); transform: rotate(-12deg); opacity: var(--call-opacity, 0); }
.swipe-card.after-call { border-color: var(--call); }
.swipe-outcome h2 { font-size: 20px; }
.outcomes.big button { padding: 16px 12px; font-size: 15px; }
.swipe-peek { border-radius: 22px; background: var(--surface-2); border: 1px solid var(--border); transform: translateY(10px) scale(0.96); z-index: 2; }
.swipe-peek.peek-2 { transform: translateY(20px) scale(0.92); z-index: 1; opacity: 0.6; }
.swipe-bar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px 4px; }
.round-button { width: 64px; height: 64px; border-radius: 50%; border: 0; font-size: 26px; color: #fff; box-shadow: 0 4px 14px rgb(0 0 0 / 0.15); }
.round-button.trash { background: var(--trash); }
.round-button.call { background: var(--call); }
.swipe-empty { text-align: center; padding: 48px 16px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .swipe-card { transition: none; } }
.bar-action { display: grid; justify-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.swipe-card.after-call { touch-action: auto; }
