:root {
  --bg: #f4f5f7; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-text: #fff; --success: #16a34a; --danger: #dc2626;
  --late: #dc2626; --late-bg: #fee2e2; --today: #c2410c; --today-bg: #ffedd5;
  --soon: #1d4ed8; --soon-bg: #dbeafe; --chip-bg: #f3f4f6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --card: #1b1e25; --text: #e5e7eb; --muted: #9ca3af; --line: #2b2f38;
    --primary: #3b82f6; --late: #f87171; --late-bg: #3b1a1a; --today: #fb923c; --today-bg: #3a2414;
    --soon: #93c5fd; --soon-bg: #1e2a44; --chip-bg: #262a33;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: 96px; -webkit-tap-highlight-color: transparent;
}
button, input, select, a.ghost { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* Boutons */
.primary, .success, .danger, .ghost, .quick button {
  border-radius: 8px; padding: 9px 14px; text-decoration: none; display: inline-flex; align-items: center;
}
.primary { background: var(--primary); color: var(--primary-text); font-weight: 600; }
.success { background: var(--success); color: #fff; font-weight: 600; }
.danger  { color: var(--danger); border: 1px solid var(--danger); }
.ghost   { color: var(--muted); }
.ghost:hover { background: var(--chip-bg); }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--card); padding: 32px 24px; border-radius: 16px; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 14px; align-items: center; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input, .login-card button { width: 100%; justify-content: center; }
.error { color: var(--danger); margin: 0; text-align: center; }

/* Barre du haut */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center;
  justify-content: space-between; padding: 12px 16px 6px; max-width: 760px; margin: 0 auto; }
.topbar h1 { font-size: 22px; margin: 0; }
.top-actions { display: flex; gap: 2px; }
.summary { max-width: 760px; margin: 0 auto; padding: 0 16px 10px; color: var(--muted); font-size: 14px; }
.summary b.late { color: var(--late); }
.summary b.today { color: var(--today); }

/* Dossiers */
.folders { max-width: 760px; margin: 0 auto; padding: 0 12px; display: flex; flex-direction: column; gap: 10px; }
.folder { background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.folder-head { display: flex; align-items: center; }
.toggle { flex: 1; display: flex; align-items: center; gap: 8px; padding: 14px 12px; text-align: left; min-width: 0; }
.chev { transition: transform .15s; color: var(--muted); width: 14px; display: inline-block; transform: rotate(90deg); }
.folder.collapsed .chev { transform: rotate(0); }
.fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { background: var(--chip-bg); color: var(--muted); font-size: 12px; border-radius: 10px; padding: 1px 8px; }
.badge-late { background: var(--late-bg); color: var(--late); font-size: 12px; border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.icon { width: 44px; height: 44px; font-size: 22px; color: var(--muted); flex-shrink: 0; border-radius: 8px; }
.icon:hover { background: var(--chip-bg); }
.folder.collapsed .tasks { display: none; }

/* Tâches */
.tasks { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.task { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line);
  transition: opacity .25s, transform .25s; }
.task:last-child { border-bottom: 0; }
.task.done { opacity: 0; transform: translateX(40px); }
.check { width: 26px; height: 26px; border: 2px solid var(--muted); border-radius: 50%; flex-shrink: 0; margin-top: 1px;
  display: grid; place-items: center; color: transparent; font-size: 14px; }
.check:hover { border-color: var(--success); color: var(--success); }
.task.done .check { background: var(--success); border-color: var(--success); color: #fff; }
.tbody { flex: 1; min-width: 0; cursor: pointer; }
.label { word-wrap: break-word; }
.date { display: inline-block; font-size: 12px; margin-top: 3px; border-radius: 6px; padding: 1px 7px;
  background: var(--chip-bg); color: var(--muted); }
.date.late  { background: var(--late-bg);  color: var(--late); font-weight: 600; }
.date.today { background: var(--today-bg); color: var(--today); font-weight: 600; }
.date.soon  { background: var(--soon-bg);  color: var(--soon); }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; margin: 0; }
.tasks .empty { padding: 12px; font-size: 14px; }

/* Bouton flottant */
.fab { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 58px; height: 58px;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgba(37,99,235,.4); z-index: 6; }

/* Dialogues */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 24px));
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 19px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--muted); }
input, select { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  color: var(--text); font-size: 16px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { background: var(--chip-bg); font-size: 13px; padding: 6px 10px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.full { width: 100%; justify-content: center; }
.actions .ghost { padding: 9px 10px; }

/* Notification */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom));
  background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 10px; display: flex; gap: 14px; align-items: center;
  z-index: 10; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast[hidden] { display: none; }
.toast button { color: #93c5fd; font-weight: 600; }
