:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d1d1f;
  --ink-2: #5d5a55;
  --ink-3: #8f8b84;
  --line: #e2ded5;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --red: #c8372d;
  --blue: #2e6fbd;
  --ok: #2f8a4e;
  --late: #b4501c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --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: #16181c;
    --surface: #1f2228;
    --surface-2: #272b32;
    --ink: #f1efe9;
    --ink-2: #b6b2aa;
    --ink-3: #8a867f;
    --line: #30343c;
    --accent: #7fb0e0;
    --accent-ink: #0f1a26;
    --red: #ff7a6e;
    --blue: #7fb0ff;
    --ok: #6fcf8e;
    --late: #ffa36b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--ink); }

/* ---------- Boutons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: var(--surface-2); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid currentColor; width: 100%; margin-top: 8px; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 4px; cursor: pointer; font-size: 16px; }
.link.strong { font-weight: 700; }

/* ---------- Connexion ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px;
  padding: 28px 24px; box-shadow: var(--shadow); text-align: center;
}
.login-card img { border-radius: 14px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-card p { margin: 0 0 20px; color: var(--ink-2); }
.login-card .field { text-align: left; }
.login-card .btn { width: 100%; padding: 13px; }
.err { color: var(--red); min-height: 1.4em; margin: 12px 0 0 !important; font-size: 14px; }

/* ---------- Structure ---------- */
.app { max-width: 920px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(96px + var(--safe-b)); }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 0 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 7px; }
.tabs { display: none; gap: 4px; margin-left: 12px; }
.tabs button {
  border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  color: var(--ink-2); font-weight: 600;
}
.tabs button[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.add-top { display: none; margin-left: auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-b));
}
.tabbar button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--ink-3); padding: 4px 0; cursor: pointer;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--accent); }

.fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-b)); z-index: 11;
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

@media (min-width: 760px) {
  .app { padding-bottom: 48px; }
  .tabs { display: flex; }
  .add-top { display: inline-block; }
  .tabbar, .fab { display: none; }
}

.view:focus { outline: none; }
.banner {
  background: #fff3cd; color: #6a4d00; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}
@media (prefers-color-scheme: dark) { .banner { background: #3b3216; color: #f3dd9b; } }

/* ---------- Contenus ---------- */
h2.page-title { font-size: 28px; margin: 4px 0 2px; letter-spacing: -.3px; }
.page-sub { color: var(--ink-2); margin: 0 0 16px; }
h3.section {
  font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3);
  margin: 22px 0 8px; font-weight: 700;
}
h3.section.late { color: var(--late); }

.next { display: grid; gap: 8px; }
@media (min-width: 760px) { .next { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); } }
.next-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; width: 100%;
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  border: 0; border-left: 4px solid var(--t, var(--accent)); cursor: pointer; text-align: left;
}
.nc-main { min-width: 0; display: flex; flex-direction: column; }
.nc-main b { font-size: 16px; }
.nc-sub { font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next-card .days { font-size: 18px; font-weight: 800; white-space: nowrap; }
.next-card .days.soon { color: var(--red); }
.link.more { display: block; margin: 6px 0 0 auto; font-weight: 600; font-size: 15px; }

.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row.done .r-title { text-decoration: line-through; color: var(--ink-3); }
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--c, var(--ink-3));
  background: none; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.check svg { width: 16px; height: 16px; opacity: 0; }
.row.done .check { background: var(--c, var(--ok)); }
.row.done .check svg { opacity: 1; color: #fff; }
.r-title { font-weight: 600; }
.r-sub { font-size: 14px; color: var(--ink-2); }
.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 1px 8px 1px 6px;
  border-radius: 6px; color: var(--ink); background: var(--surface-2); margin-right: 6px; vertical-align: 1px;
}
/* La couleur de la matière n'est qu'une pastille : la couleur forte est réservée au type d'échéance. */
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ink-3)); flex: none; }
.kebab { background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 6px; font-size: 14px; white-space: nowrap; }
.kebab:hover { color: var(--accent); }

.due-row { grid-template-columns: 34px 1fr auto; background: color-mix(in srgb, var(--c) 9%, var(--surface)); }
.due-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800; background: var(--c); }

.day { margin-top: 18px; }
.day-head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 6px 2px; }
.day-head strong { font-size: 16px; }
.day-head span { color: var(--ink-3); font-size: 14px; }
.day-head.today strong { color: var(--accent); }
.week-head { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); margin: 28px 0 0; font-weight: 700; border-top: 1px solid var(--line); padding-top: 12px; }

.cards { display: grid; gap: 10px; }
@media (min-width: 760px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
  border-left: 5px solid var(--t, var(--accent));
}
.card-top { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; }
.card-main { min-width: 0; }
.card-side { text-align: right; }
.card-type { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--t); }
.card h4 { margin: 2px 0 6px; font-size: 17px; }
.card .meta { margin-top: 6px; }
.card .meta { color: var(--ink-2); font-size: 14px; }
.when { font-weight: 800; font-size: 14px; white-space: nowrap; }
.when.soon { color: var(--red); }
.steps { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.pill {
  border: 1.5px solid var(--line); background: none; border-radius: 999px; padding: 5px 10px; font-size: 13px;
  cursor: pointer; display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2);
}
.pill b { color: var(--ink); }
.pill.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.pill.done b { color: #fff; }
.pill.late { border-color: var(--late); color: var(--late); }
.note { font-weight: 800; }

.seg-inline { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg-inline button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-weight: 600; }
.seg-inline button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.empty { text-align: center; color: var(--ink-2); padding: 28px 16px; background: var(--surface); border-radius: var(--radius); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.panel h4 { margin: 0 0 6px; font-size: 17px; }
.panel p, .panel li { color: var(--ink-2); font-size: 15px; }
.panel ol { padding-left: 20px; margin: 8px 0; }
.panel .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.code { font: 12px/1.4 ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; color: var(--ink-2); }

/* ---------- Formulaire (feuille) ---------- */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 520px; max-height: 92dvh;
  border-radius: 18px; background: var(--bg); color: var(--ink);
  margin: auto;
}
.sheet::backdrop { background: rgba(0,0,0,.4); }
@media (max-width: 759px) {
  .sheet { margin: auto 0 0; max-width: none; border-radius: 18px 18px 0 0; max-height: 94dvh; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-body { padding: 16px; padding-bottom: calc(24px + var(--safe-b)); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.field em { font-weight: 400; font-style: normal; color: var(--ink-3); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 16px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.preview { background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); }
.preview:empty { display: none; }
.preview strong { color: var(--ink); display: block; margin-bottom: 4px; }
.preview ul { margin: 0; padding-left: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 760px) { .toast { bottom: 32px; } }

/* ---------- Types d'échéances ---------- */
.tbadge {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: inline-grid; place-items: center; background: var(--t); color: #fff;
}
.tbadge svg { width: 18px; height: 18px; }
.tbadge.sm { width: 26px; height: 26px; border-radius: 8px; }
.tbadge.sm svg { width: 15px; height: 15px; }
.tbadge.lg { width: 40px; height: 40px; border-radius: 11px; }
.tbadge.lg svg { width: 23px; height: 23px; }
@media (prefers-color-scheme: dark) { .tbadge { color: #16181c; } }
.tlabel {
  display: inline-flex; align-items: center; gap: 3px; font-weight: 700; color: var(--t);
  margin-right: 6px; white-space: nowrap;
}
.tlabel svg { width: 14px; height: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 5px 11px 5px 9px; font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.chip svg { width: 15px; height: 15px; color: var(--t, var(--ink-3)); }
button.chip { cursor: pointer; }
.chip.on { background: var(--t, var(--ink)); border-color: var(--t, var(--ink)); color: #fff; }
.chip.on svg { color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on, .chip.on svg { color: #16181c; } }
.types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.type-opt { position: relative; }
.type-opt input { position: absolute; opacity: 0; inset: 0; }
.type-opt span {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 10px 4px 8px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  color: var(--t); height: 100%;
}
.type-opt svg { width: 24px; height: 24px; }
.type-opt em { font-style: normal; font-size: 12px; font-weight: 700; line-height: 1.15; color: var(--ink-2); }
.type-opt input:checked + span { background: var(--t); border-color: var(--t); color: #fff; }
.type-opt input:checked + span em { color: #fff; }
.type-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) {
  .type-opt input:checked + span, .type-opt input:checked + span em { color: #16181c; }
}
.preview { border-left: 4px solid var(--t, var(--accent)); }
.rules { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 10px; }
.rule { display: flex; gap: 10px; align-items: flex-start; }
.rule b { color: var(--ink); }

/* ---------- Pièces jointes & liens ---------- */
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.att {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  padding: 5px 10px; border-radius: 8px; background: var(--surface-2);
  color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none;
}
.att svg { width: 14px; height: 14px; flex: none; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att:hover { text-decoration: underline; }
.attn {
  display: inline-flex; align-items: center; gap: 3px; border: 0; background: var(--surface-2);
  color: var(--ink-2); border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700;
  cursor: pointer; vertical-align: 1px;
}
.attn svg { width: 12px; height: 12px; }

.rep { display: grid; gap: 8px; }
.rep:empty { display: none; }
.rep-row {
  display: grid; grid-template-columns: 22px 1fr 36px; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px 8px 10px;
}
.rep-ico { color: var(--ink-3); display: grid; place-items: center; }
.rep-ico svg { width: 18px; height: 18px; }
.rep-fields { display: grid; gap: 6px; min-width: 0; }
.rep-row.link .rep-fields { grid-template-columns: 1fr; }
@media (min-width: 760px) { .rep-row.link .rep-fields { grid-template-columns: 3fr 2fr; } }
.field .rep-fields input {
  padding: 8px 10px; border-radius: 8px; font-size: 16px; background: var(--bg);
}
.rep-fields a, .rep-fields > span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); text-decoration: none; }
.rep-fields > span { color: var(--ink); }
.rep-fields small { color: var(--ink-3); font-size: 12px; }
.rep-row.pending { border-style: dashed; }
.rep-del {
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--surface-2);
  color: var(--ink-2); font-size: 20px; line-height: 1; cursor: pointer;
}
.rep-del:hover { color: var(--red); }
.add-row {
  margin-top: 8px; border: 1.5px dashed var(--line); background: none; color: var(--accent);
  border-radius: 12px; padding: 10px; width: 100%; font-weight: 600; cursor: pointer;
}
.add-row:hover { border-color: var(--accent); }
