:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #1c211e;
  --muted: #6b716c;
  --line: #e2dfd7;
  --accent: #2e6b4f;
  --accent-soft: #e3efe8;
  --accent-ink: #ffffff;
  --no: #b8473b;
  --no-soft: #f7e6e3;
  --shadow: 0 1px 2px rgba(28, 33, 30, .06), 0 8px 24px rgba(28, 33, 30, .08);
  --radius: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141715;
    --surface: #1d211f;
    --surface-2: #262b28;
    --ink: #ecefe9;
    --muted: #9aa29c;
    --line: #2f3531;
    --accent: #5fae86;
    --accent-soft: #233a2e;
    --accent-ink: #0f1a14;
    --no: #e0776b;
    --no-soft: #3a2421;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ─── Boutons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: .6rem 1.1rem; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none; transition: transform .15s var(--ease), background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); padding-inline: .6rem; }
.btn-lg { padding: .85rem 1.5rem; font-size: 1rem; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; fill: var(--ink);
}
.icon-btn:hover { background: var(--surface-2); }

/* ─── Connexion, chargement ───────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { max-width: 360px; text-align: center; }
.login-box h1 { margin: .75rem 0 .25rem; font-size: 1.75rem; letter-spacing: -.02em; }
.login-box p { margin: 0 0 1.5rem; }
.login-icon { border-radius: 16px; }
.login-error { color: var(--no); margin-top: 1rem !important; }
.loading { min-height: 100dvh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Structure ───────────────────────────────────────── */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 6px;
  max-width: 760px; width: 100%; margin: 0 auto;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.client-select {
  font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 10px; padding: .3rem .5rem;
}
.menu {
  position: absolute; right: 16px; top: 52px; z-index: 20; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu-user { padding: .5rem .75rem; font-size: .85rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-wrap: anywhere; }
.menu button { text-align: left; border: 0; background: transparent; padding: .6rem .75rem; border-radius: 10px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 6px auto 0;
  max-width: 760px; width: calc(100% - 32px);
  background: var(--surface-2); border-radius: 14px; overflow-x: auto; scrollbar-width: none;
}
.tabs button {
  flex: 1 0 auto; border: 0; background: transparent; padding: .5rem .7rem; border-radius: 10px;
  font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.count:not(:empty) {
  display: inline-block; min-width: 1.4em; padding: 0 .35em; margin-left: .15em; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: .78rem; line-height: 1.4em; text-align: center;
}

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }
.foot { text-align: center; padding: 16px 16px max(20px, env(safe-area-inset-bottom)); }
.powered-by {
  display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted);
  text-decoration: none; opacity: .85;
}
.powered-by img { height: 22px; width: auto; }
@media (prefers-color-scheme: dark) { .powered-by img { filter: invert(1) hue-rotate(180deg); } }

/* ─── Tri ─────────────────────────────────────────────── */
.view-trier { display: flex; flex-direction: column; align-items: center; }
.progress { margin: 0 0 10px; font-size: .85rem; color: var(--muted); }
.deck { position: relative; width: 100%; max-width: 460px; height: clamp(340px, calc(100dvh - 360px), 560px); }
.card {
  position: absolute; inset: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
  display: flex; flex-direction: column; gap: 14px; overflow: hidden;
  touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab;
  will-change: transform;
}
.card.dragging { cursor: grabbing; transition: none; }
.card.back { transform: scale(.95) translateY(14px); opacity: .7; pointer-events: none; }
.card.settle { transition: transform .35s var(--ease), opacity .35s var(--ease); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.where { font-size: .85rem; color: var(--muted); }
.card h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; letter-spacing: -.015em; overflow-wrap: anywhere; }
.contact-line { margin-top: -8px; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.contact-line .no-mail { color: var(--no); font-weight: 600; }
.card-body {
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto; flex: 1; min-height: 0;
  padding-bottom: 18px; -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent);
}
.block-label { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.block p { margin: 0; }
.card-foot a { font-size: .9rem; font-weight: 600; text-decoration: none; }
.stamp {
  position: absolute; top: 22px; padding: .25rem .7rem; border: 3px solid; border-radius: 10px;
  font-weight: 800; font-size: 1.25rem; letter-spacing: .06em; opacity: 0; pointer-events: none;
  background: var(--surface);
}
.stamp-yes { left: 18px; color: var(--accent); transform: rotate(-12deg); }
.stamp-no { right: 18px; color: var(--no); transform: rotate(12deg); }

.deck-actions { display: flex; align-items: center; gap: 22px; margin-top: 20px; }
.round {
  width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center;
  cursor: pointer; transition: transform .15s var(--ease);
}
.round svg { fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.round:active { transform: scale(.92); }
.round-no svg { stroke: var(--no); }
.round-yes svg { stroke: var(--accent); }
.round-undo { width: 48px; height: 48px; }
.round-undo svg { stroke: var(--muted); stroke-width: 2.2; }
.round:disabled { opacity: .35; cursor: default; box-shadow: none; }
/* Emplacement fixe sous les boutons : l'aide, ou la raison d'un écart, sans décaler la page */
.slot { width: 100%; max-width: 460px; min-height: 40px; margin-top: 12px; display: flex; align-items: center; justify-content: center; }
.slot:has(.reasons:not([hidden])) .hint { display: none; }
.hint { font-size: .8rem; margin: 0; text-align: center; }
@media (pointer: coarse) { .hint { display: none; } }

.reasons {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; width: 100%;
  animation: rise .25s var(--ease);
}
.reasons-label { flex: none; font-size: .8rem; font-weight: 600; color: var(--muted); }
.reasons-list { display: contents; }
.reasons-list button {
  flex: none; white-space: nowrap; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: .35rem .75rem; font-size: .85rem; cursor: pointer;
}
.reasons-list button:hover { border-color: var(--no); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); max-width: 420px; margin: 0 auto; }
.empty strong { display: block; color: var(--ink); font-size: 1.1rem; margin-bottom: .35rem; }

/* ─── Listes (envoyer, appeler, suivi) ────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.item-head {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 0;
  background: transparent; text-align: left; cursor: pointer;
}
.item-head .grow { flex: 1; min-width: 0; }
.item-title { font-weight: 600; display: block; overflow-wrap: anywhere; }
.item-sub { font-size: .85rem; color: var(--muted); display: block; overflow-wrap: anywhere; }
.chev { flex: none; width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; transition: transform .2s var(--ease); }
.item.open .chev { transform: rotate(180deg); }
.item-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.mail-subject { font-weight: 600; }
.mail-text {
  white-space: pre-wrap; font: inherit; font-size: .92rem; background: var(--surface-2); border-radius: 12px;
  padding: 12px 14px; margin: 0; max-height: 46dvh; overflow-y: auto; overflow-wrap: anywhere;
}
.mail-text .sig { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.confirm {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--accent-soft); border-radius: 12px; font-size: .92rem;
}
.confirm span { flex: 1 1 160px; }
.tel { font-size: 1.1rem; font-weight: 700; text-decoration: none; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.4rem; letter-spacing: -.02em; }
.stat span { font-size: .8rem; color: var(--muted); }
.group-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.line {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px;
}
.line .grow { flex: 1 1 200px; min-width: 0; }
.line .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-sm { padding: .35rem .75rem; font-size: .82rem; }

/* ─── Réglages, toast ─────────────────────────────────── */
.sheet {
  border: 0; border-radius: 20px; padding: 0; width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet p { margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
legend { font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice span { display: flex; flex-direction: column; }
.choice small, .switch small { color: var(--muted); font-size: .8rem; display: block; }
.choice input { accent-color: var(--accent); margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; font-weight: 600; }
.field input {
  font: inherit; font-weight: 400; padding: .6rem .75rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.switch { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; cursor: pointer; }
.switch input { accent-color: var(--accent); margin-top: 4px; width: 18px; height: 18px; }
.sheet-actions { display: flex; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%);
  z-index: 30; background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
