:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --ink: #1b2a41;
  --muted: #66758a;
  --line: #dde2ea;
  --accent: #2457d6;
  --accent-ink: #ffffff;
  --alert: #e8890c;
  --danger: #c0392b;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #18222f;
    --ink: #e8edf3;
    --muted: #93a1b5;
    --line: #28364a;
    --accent: #6c9bff;
    --accent-ink: #0f1620;
    --alert: #f5a43a;
    --danger: #ff7b6b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
}
h1, h2 { margin: 0; line-height: 1.15; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.top h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: none; border: 0; border-radius: 50%; color: var(--muted); cursor: pointer;
}
.icon-btn.on { color: var(--alert); }

.wrap { max-width: 640px; margin: 0 auto; padding: 4px 16px 120px; }
#q {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); margin-bottom: 14px;
  font-size: 16px; -webkit-appearance: none; appearance: none;
}

/* Liste */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.note {
  position: relative; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.note::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--line); }
.note.soon::before { background: var(--accent); }
.note.late::before { background: var(--alert); }
.note-main {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 14px 16px 14px 20px; cursor: pointer;
}
.note h2 { font-size: 18px; font-weight: 700; margin-bottom: 2px; overflow-wrap: anywhere; }
.note p {
  margin: 0; color: var(--muted); font-size: 15px; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 13px; font-weight: 600; color: var(--accent);
}
.note.late .pill { color: var(--alert); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Bouton + */
.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 10px));
  width: 62px; height: 62px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 6px 18px rgba(20, 40, 90, .3);
}
.fab:active { transform: scale(.96); }

/* Boutons */
.btn {
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; padding: 6px 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }

/* Fenêtres */
dialog { color: var(--ink); background: var(--surface); border: 0; padding: 0; }
dialog::backdrop { background: rgba(8, 14, 24, .55); }
.sheet {
  width: 100%; max-width: 640px; margin: auto auto 0;
  max-height: 94dvh; overflow: auto;
  border-radius: 22px 22px 0 0;
}
.sheet form { display: grid; gap: 14px; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); }
.sheet input[type=text], .sheet textarea, .sheet input[type=datetime-local], .sheet select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  background: var(--bg); font-size: 16px; -webkit-appearance: none; appearance: none;
}
#f-title { font-weight: 700; font-size: 19px; }
.sheet textarea { resize: vertical; min-height: 140px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); font-size: 14px; font-weight: 600; cursor: pointer;
}
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }

.alarm {
  width: min(88vw, 380px); margin: auto; padding: 28px 22px 22px;
  border-radius: 22px; text-align: center;
}
.alarm[open] { display: grid; gap: 10px; justify-items: center; }
.alarm-ring {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
  background: var(--alert); color: #fff; animation: ring 1.2s ease-in-out infinite;
}
@keyframes ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(-12deg); } 30% { transform: rotate(10deg); } 45% { transform: rotate(-8deg); } 60% { transform: rotate(0); } }
.alarm h2 { font-size: 22px; overflow-wrap: anywhere; }
.alarm p { margin: 0; color: var(--muted); max-height: 30dvh; overflow: auto; white-space: pre-line; overflow-wrap: anywhere; }
.alarm-actions { display: grid; gap: 8px; width: 100%; margin-top: 10px; }

.hint {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--alert);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 15px;
}
.hint p { margin: 0; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(100px, calc(env(safe-area-inset-bottom) + 90px));
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-size: 15px; max-width: 90vw; z-index: 20; text-align: center;
}

/* Connexion */
.login { max-width: 340px; margin: 0 auto; padding: 14vh 20px 40px; display: grid; gap: 16px; justify-items: center; }
.login img { border-radius: 20px; }
.login h1 { font-size: 34px; font-weight: 800; }
.login form { display: grid; gap: 10px; width: 100%; }
.login label { font-size: 14px; font-weight: 600; color: var(--muted); }
.login input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; }
.err { color: var(--danger); margin: 0; font-size: 15px; }

@media (prefers-reduced-motion: reduce) { .alarm-ring { animation: none; } }

/* Dictée vocale */
.body-wrap { position: relative; }
.body-wrap textarea { padding-right: 62px; }
.mic {
  position: absolute; right: 8px; bottom: 8px; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent);
}
.mic.rec { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, .45); } 50% { box-shadow: 0 0 0 10px rgba(192, 57, 43, 0); } }
.fab-mic {
  position: fixed; right: calc(max(20px, env(safe-area-inset-right)) + 74px);
  bottom: max(27px, calc(env(safe-area-inset-bottom) + 15px));
  width: 52px; height: 52px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent);
  box-shadow: 0 4px 14px rgba(20, 40, 90, .18);
}
.fab-mic:active { transform: scale(.96); }
@media (prefers-reduced-motion: reduce) { .mic.rec { animation: none; } }

/* Diagnostic */
.foot { text-align: center; margin: 24px 0 0; }
.foot .link { font-size: 14px; color: var(--muted); font-weight: 500; }
.diag-box { display: grid; gap: 14px; padding: 20px 18px max(18px, env(safe-area-inset-bottom)); }
.diag { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.diag li { display: grid; grid-template-columns: 24px 1fr; gap: 8px; font-size: 15px; }
.diag .mark { font-weight: 800; }
.diag .ok .mark { color: #2f9e44; }
.diag .ko .mark { color: var(--danger); }
.diag small { display: block; color: var(--muted); font-size: 13px; }
.diag-help { margin: 0; color: var(--muted); font-size: 14px; }

/* Photos */
.sr { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.photo-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; color: var(--accent); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; background: var(--bg); }
.thumb .x {
  position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--ink); color: var(--surface);
  font-size: 16px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.thumb.wait { display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 13px; }
.note-thumbs { display: flex; gap: 6px; margin-top: 10px; align-items: center; }
.note-thumbs img { width: 58px; height: 58px; object-fit: cover; border-radius: 10px; background: var(--bg); }
.note-thumbs .more { color: var(--muted); font-weight: 600; font-size: 14px; padding-left: 4px; }
.viewer { width: 100%; height: 100%; max-width: none; max-height: none; background: #000; color: #fff; }
.viewer[open] { display: grid; grid-template-rows: 1fr auto; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.viewer img { width: 100%; height: 100%; object-fit: contain; min-height: 0; }
.fab-photo {
  position: fixed; right: calc(max(20px, env(safe-area-inset-right)) + 140px);
  bottom: max(27px, calc(env(safe-area-inset-bottom) + 15px));
  width: 52px; height: 52px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent);
  box-shadow: 0 4px 14px rgba(20, 40, 90, .18);
}
.fab-photo:active { transform: scale(.96); }
