:root {
  --bg: #14161c;
  --panel: #1b1e27;
  --panel-2: #21252f;
  --border: #2a2e39;
  --text: #e7e8ec;
  --text-dim: #8b8f9c;
  --accent: #5eead4;
  --accent-ink: #0b2b26;
  --warn: #fbbf24;
  --danger: #f87171;
  --sep: rgba(255, 255, 255, 0.07);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5f1;
    --panel: #ffffff;
    --panel-2: #efeee9;
    --border: #e2e0d8;
    --text: #1c1c1e;
    --text-dim: #8a8a8e;
    --accent: #0d9488;
    --accent-ink: #ffffff;
    --warn: #c2410c;
    --danger: #dc2626;
    --sep: rgba(0, 0, 0, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: lowercase;
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
}
.login-card h1 { font-size: 34px; margin: 2px 0 28px; letter-spacing: -0.02em; }
.login-card label { font-size: 13px; color: var(--text-dim); margin: 14px 0 6px; }
.login-card input {
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 12px 0 4px; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  border-radius: 12px;
  padding: 14px;
}
.btn-primary:disabled { opacity: 0.6; }
.login-hint { font-size: 13px; color: var(--text-dim); text-align: center; margin-top: 16px; }

/* ---------- App shell ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 0 calc(80px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 20px 14px;
}
.top h1 { font-size: 34px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.summary { margin: 2px 0 0; font-size: 14px; color: var(--text-dim); }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--accent);
  background: var(--panel-2);
  margin-top: 8px;
}
.icon-btn svg { fill: currentColor; }

/* ---------- Rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }

.item {
  position: relative;
  overflow: hidden;
}
.item .row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 0 16px 0 20px;
  background: var(--bg);
  transition: transform 0.2s ease;
  touch-action: pan-y;
}
.item .row.dragging { transition: none; }

.item .body {
  flex: 1;
  min-width: 0;
  padding: 10px 0 10px;
  border-bottom: 1px solid var(--sep);
}

.check {
  flex: none;
  width: 24px; height: 24px;
  margin-top: 9px;
  border-radius: 50%;
  border: 1.6px solid var(--text-dim);
  display: grid; place-items: center;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  position: relative;
}
.check::after {
  content: '';
  width: 6px; height: 11px;
  border: solid var(--accent-ink);
  border-width: 0 2.2px 2.2px 0;
  transform: rotate(45deg) translate(-1px, -1px) scale(0);
  transition: transform 0.15s;
}
.check:active { transform: scale(0.9); }
.item.checking .check,
.item.is-done .check {
  background: var(--accent);
  border-color: var(--accent);
}
.item.checking .check::after,
.item.is-done .check::after { transform: rotate(45deg) translate(-1px, -1px) scale(1); }
.check.ghost { border-style: dashed; opacity: 0.6; margin-top: 0; }

.text {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 17px;
  line-height: 1.35;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  padding: 1px 0;
  margin: 0;
  overflow: hidden;
  min-height: 25px;
}
.item.checking .text { color: var(--text-dim); }

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-dim);
}
.meta:empty { display: none; }

/* Due-date chip and calendar button both wrap a transparent native date input
   so a tap opens the OS date picker directly (iOS wheel, with "Réinitialiser"). */
.due {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  border-radius: 6px;
}
.due svg { width: 13px; height: 13px; stroke: currentColor; fill: none; }
.due.soon { color: var(--warn); }
.due.late { color: var(--danger); }
.date-input {
  position: absolute;
  inset: -6px;
  opacity: 0;
  width: auto;
  height: auto;
  font-size: 16px;
  border: 0;
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.cal-btn {
  position: relative;
  flex: none;
  width: 30px; height: 30px;
  margin-top: 6px;
  display: grid; place-items: center;
  color: var(--text-dim);
  opacity: 0.45;
  border-radius: 8px;
}
.cal-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }
.item:focus-within .cal-btn { opacity: 0.9; color: var(--accent); }
.item.has-due .cal-btn { display: none; }

/* Swipe-to-delete */
.del-btn {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 96px;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  z-index: 0;
}
.item.swiped .row { transform: translateX(-96px); }

/* Desktop: hover × */
.x-btn {
  display: none;
  flex: none;
  width: 30px; height: 30px;
  margin-top: 6px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 18px;
}
@media (hover: hover) and (pointer: fine) {
  .x-btn { display: grid; place-items: center; visibility: hidden; }
  .item:hover .x-btn { visibility: visible; }
  .x-btn:hover { color: var(--danger); background: var(--panel-2); }
}

/* Add row */
.add-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 20px;
  color: var(--text-dim);
  text-align: left;
}

/* ---------- Done section ---------- */
.done-section { margin-top: 26px; }
.done-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 20px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.done-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 2px 8px;
}
.done-toggle .chev { margin-left: auto; color: var(--text-dim); transition: transform 0.2s; }
.done-section.collapsed .chev { transform: rotate(-90deg); }
.done-section.collapsed .done-groups { display: none; }

.done-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 20px 4px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.done-group-head button {
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--accent);
}

.item.is-done .text-static {
  padding: 1px 0;
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--text-dim) 60%, transparent);
  word-break: break-word;
}
.done-time { font-size: 12px; color: var(--text-dim); opacity: 0.8; }

/* Rows moving between sections */
@keyframes rowIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.item.enter { animation: rowIn 0.25s ease; }

/* ---------- Sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
}
.sheet {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 16px;
  overflow: hidden;
  animation: sheetUp 0.22s ease;
}
@keyframes sheetUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-info { margin: 0; padding: 14px 18px 0; font-size: 15px; text-align: center; }
.sheet-info.dim { color: var(--text-dim); font-size: 13px; padding: 4px 18px 14px; }
.sheet-btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-top: 1px solid var(--sep);
  color: var(--accent);
  font-size: 17px;
}
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.bold { font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast button { color: var(--accent); font-weight: 600; margin-left: 12px; }
