:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1d2422;
  --muted: #6b726f;
  --line: #e4dfd4;
  --board: #1e2b29;
  --board-ink: #f3f1e8;
  --chalk: #9fd3b4;
  --accent: #1f7a55;
  --accent-ink: #ffffff;
  --danger: #b3362f;
  --payment: #8a5a14;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121716;
    --surface: #1a2120;
    --ink: #ecebe5;
    --muted: #9aa29f;
    --line: #2b3432;
    --board: #22312e;
    --accent: #3fae80;
    --accent-ink: #0d1312;
    --danger: #ef7b72;
    --payment: #e0b061;
    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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* --- Boutons ----------------------------------------------------------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  font-weight: 600;
  min-height: 50px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); }
.btn.danger { background: none; color: var(--danger); padding-inline: 8px; margin-right: auto; }
.btn:disabled { opacity: .6; }

/* --- Connexion --------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card img { border-radius: 18px; }
.login-card h1 { margin: 12px 0 4px; font-size: 28px; }
.login-card > p { color: var(--muted); margin: 0 0 24px; }
.login-card form { display: grid; gap: 14px; text-align: left; }
.login-card .btn { margin-top: 4px; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input:not([type=radio]):not([type=checkbox]) {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 17px;
  color: var(--ink);
  min-height: 48px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 14px; }
.error:empty { display: none; }

/* --- Ardoise (total) --------------------------------------------------- */
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(100px + env(safe-area-inset-bottom)); }
.board {
  margin: calc(12px + env(safe-area-inset-top)) -4px 0;
  background: var(--board);
  color: var(--board-ink);
  border-radius: 22px;
  padding: 22px 22px 20px;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,.04);
  background-image: radial-gradient(120% 80% at 20% 0%, rgba(255,255,255,.06), transparent 60%);
}
.board-label { margin: 0; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; opacity: .75; }
.board-total {
  margin: 4px 0 6px;
  font-size: clamp(40px, 13vw, 56px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--chalk);
}
.board-total.negative { color: #f2c27b; }
.board-detail { margin: 0; font-size: 14px; opacity: .8; }

/* --- Filtres ----------------------------------------------------------- */
.filters { display: flex; gap: 8px; margin: 16px 0 4px; overflow-x: auto; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
  min-height: 38px;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* --- Liste ------------------------------------------------------------- */
.list h2 {
  display: flex;
  justify-content: space-between;
  margin: 20px 4px 6px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.list h2 span:first-child::first-letter { text-transform: uppercase; }
.list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.row { display: flex; align-items: center; }
.row + .row { border-top: 1px solid var(--line); }
.tick {
  flex: none;
  width: 52px;
  align-self: stretch;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  padding: 0;
}
.tick::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
}
.paid .tick::before {
  border-color: var(--accent);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E") center/16px no-repeat;
}
.payment .tick { color: var(--payment); font-size: 18px; cursor: default; }
.payment .tick::before { display: none; }

.row-body {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label amount" "sub amount";
  column-gap: 12px;
  text-align: left;
  border: 0;
  background: none;
  padding: 12px 16px 12px 0;
  min-height: 60px;
}
.row-label { grid-area: label; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row-sub { grid-area: sub; font-size: 13px; color: var(--muted); }
.row-amount { grid-area: amount; align-self: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.payment .row-amount { color: var(--payment); }
.paid .row-label, .paid .row-amount { text-decoration: line-through; color: var(--muted); }

.empty { text-align: center; color: var(--muted); margin: 40px 0; }

/* --- Boutons d'ajout --------------------------------------------------- */
.actions {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 35%);
}
.actions .btn { flex: 1; max-width: 260px; box-shadow: 0 6px 18px rgba(0,0,0,.12); }

/* --- Feuille de saisie ------------------------------------------------- */
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  background: var(--bg);
  color: var(--ink);
  border-radius: 22px 22px 0 0;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 22px; } }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet form { display: grid; gap: 14px; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; }
.seg label { display: block; color: var(--ink); font-size: 15px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 10px; font-weight: 600; }
.seg input:checked + span { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.amount { position: relative; }
.amount input:not([type]) , .amount input[name=amount] {
  font-size: 40px;
  font-weight: 700;
  text-align: center;
  padding: 10px 44px;
  font-variant-numeric: tabular-nums;
}
.euro { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 28px; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.check { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--ink); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.meta { margin: 0; font-size: 13px; color: var(--muted); }
.meta:empty { display: none; }
.sheet-actions { display: flex; gap: 8px; align-items: center; }
.sheet-actions .btn.primary { min-width: 130px; }

/* --- Toast ------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  max-width: calc(100% - 32px);
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
