:root {
  --bg: #f6f2eb;
  --card: #ffffff;
  --ink: #1f1a14;
  --muted: #7a6f62;
  --line: #e7dfd3;
  --accent: #c27c0e;
  --accent-ink: #ffffff;
  --accent-soft: #fbefd9;
  --danger: #c0392b;
  --danger-soft: #fbe5e2;
  --ok: #2e8b57;
  --ok-soft: #e1f3e8;
  --info: #2f6db3;
  --info-soft: #e3edf9;
  --shadow: 0 1px 2px rgba(40, 28, 10, .06), 0 4px 14px rgba(40, 28, 10, .06);
  --radius: 16px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d;
    --card: #211c16;
    --ink: #f3ece2;
    --muted: #a99c8b;
    --line: #342c23;
    --accent: #e3a034;
    --accent-ink: #1b1209;
    --accent-soft: #3a2a12;
    --danger: #ef6b5c;
    --danger-soft: #3d1d19;
    --ok: #5cc38a;
    --ok-soft: #173525;
    --info: #78a9e6;
    --info-soft: #1a2a40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
.sprite { position: absolute; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#i-grip circle { fill: currentColor; stroke: none; }
.ico.sm { width: 18px; height: 18px; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
button.row-link { width: 100%; border: 0; text-align: left; font: inherit; color: inherit; }
.info-line input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.section-title .btn.plain { min-height: 36px; padding: 0 6px; font-size: 14px; text-transform: none; letter-spacing: 0; }

.splash { display: grid; place-items: center; min-height: 100dvh; }

/* ---------- Mise en page ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabbar) + var(--safe-b) + 96px);
}
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -16px 12px; padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { font-size: 26px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top h1.small { font-size: 20px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 160px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabbar a.on { color: var(--accent); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- Éléments ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 12px;
}
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 2px 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty .ico { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; text-decoration: none; cursor: pointer;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 12px; border: 0; background: transparent; color: var(--ink); cursor: pointer; text-decoration: none;
}
.icon-btn.tint { background: var(--accent-soft); color: var(--accent); }
.fab {
  position: fixed; z-index: 9; right: max(16px, calc(50% - 304px));
  bottom: calc(var(--tabbar) + var(--safe-b) + 16px);
  width: 60px; height: 60px; border-radius: 20px; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgba(150, 90, 0, .35); cursor: pointer;
}
.fab .ico { width: 28px; height: 28px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap;
  background: var(--line); color: var(--ink);
}
.st-a_contacter { background: var(--info-soft); color: var(--info); }
.st-en_cours { background: var(--accent-soft); color: var(--accent); }
.st-interesse { background: #f3e6fb; color: #8a3fb8; }
.st-client { background: var(--ok-soft); color: var(--ok); }
.st-pas_interesse { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) { .st-interesse { background: #2f1d3b; color: #c99ae6; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 8px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 10px; background: transparent; font-weight: 650; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 14px; padding: 0 14px; box-shadow: var(--shadow); margin-bottom: 10px;
}
.search input { flex: 1; border: 0; background: transparent; min-height: 48px; outline: none; font-size: 16px; }
.search .ico { color: var(--muted); }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.row-link {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 12px 14px 16px; margin-bottom: 10px; color: inherit; text-decoration: none; cursor: pointer;
}
.row-link .grow { flex: 1; min-width: 0; }
.row-link .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link .sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.row-link > .ico { color: var(--muted); }

/* ---------- Tâches ---------- */
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  position: relative; display: flex; align-items: center; gap: 4px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px 4px 8px 8px; margin-bottom: 10px;
  border-left: 5px solid transparent;
  transition: box-shadow .15s, opacity .2s;
}
.task.late { border-left-color: var(--danger); }
.task.today { border-left-color: var(--accent); }
.task.soon { border-left-color: var(--info); }
.task.dragging { z-index: 20; box-shadow: 0 12px 30px rgba(0, 0, 0, .22); transition: none; opacity: .97; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-main { flex: 1; min-width: 0; padding: 4px 4px; cursor: pointer; }
.task-title { font-weight: 650; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.due { font-weight: 700; }
.due.late { color: var(--danger); }
.due.today { color: var(--accent); }
.due.soon { color: var(--info); }
.check {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border: 0; background: transparent; cursor: pointer; color: transparent;
}
.check::before {
  content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--muted);
}
.check { position: relative; }
.check .ico { position: relative; width: 16px; height: 16px; stroke-width: 3; }
.check.on { color: #fff; }
.check.on::before { background: var(--ok); border-color: var(--ok); }
.grip { width: 40px; height: 44px; display: grid; place-items: center; color: var(--muted); touch-action: none; cursor: grab; flex: none; }
.task .icon-btn { width: 40px; height: 40px; color: var(--accent); }
details.done-list { margin-top: 18px; }
details.done-list summary { cursor: pointer; color: var(--muted); font-weight: 650; padding: 8px 2px; list-style: none; }
details.done-list summary::-webkit-details-marker { display: none; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 2px 10px; }

/* ---------- Fiche structure ---------- */
.hero { margin-bottom: 4px; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 6px; }
.quick a, .quick button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow);
  color: var(--accent); font-size: 12px; font-weight: 650; text-decoration: none; cursor: pointer;
}
.quick .off { opacity: .35; pointer-events: none; }
.info-line { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 15px; word-break: break-word; }
.info-line .ico { color: var(--muted); margin-top: 1px; }
.contact-card .head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.contact-card .head .grow { flex: 1; min-width: 0; }
.contact-card .acts { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.contact-card .note { margin-top: 8px; font-size: 14px; color: var(--muted); white-space: pre-wrap; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 750;
}
.followup textarea { min-height: 140px; }
.stamp { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Formulaires ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 2px 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px; outline: none;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-row label { flex: 1; min-width: 30%; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 14px; font-weight: 650; cursor: pointer; text-align: center;
}
.radio-row input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.radio-row input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick-dates button { min-height: 34px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 650; cursor: pointer; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 2px; }

/* ---------- Feuilles (modales) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(15, 10, 5, .45); opacity: 0; transition: opacity .22s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px;
  max-height: calc(100dvh - var(--safe-t) - 24px); display: flex; flex-direction: column;
  background: var(--card); border-radius: 22px 22px 0 0;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet-wrap.open .sheet-bg { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 8px 6px 20px; }
.sheet-head h2 { flex: 1; font-size: 19px; }
.sheet-body { overflow-y: auto; padding: 8px 20px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.tpl-body { white-space: pre-wrap; background: var(--bg); border-radius: 12px; padding: 14px; font-size: 15px; max-height: 50dvh; overflow-y: auto; }

/* ---------- Connexion ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 48px) 20px 40px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 32px; text-align: center; }
.auth .logo h1 { font-size: 28px; }
.bio-btn { min-height: 64px; font-size: 17px; margin-bottom: 18px; }
.bio-btn .ico { width: 28px; height: 28px; }
.sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 8px 0 18px; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; z-index: 100; bottom: calc(var(--tabbar) + var(--safe-b) + 90px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px; text-align: center;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; border-radius: 22px; transform: translateY(-40%) scale(.98); opacity: 0; transition: transform .2s, opacity .2s; }
  .sheet-wrap.open .sheet { transform: translateY(-50%); opacity: 1; }
}
