/* Sombre par défaut, ambiance « Nuit étoilée » : fond bleu nuit, gai sans éblouir la nuit. */
:root {
  color-scheme: dark;
  --bg: #10142e;
  --surface: #1b2146;
  --surface-2: #2a3160;
  --line: #3a4274;
  --text: #e6e8f5;
  --muted: #a4a9cc;
  --on-accent: #10142e;
  --on-fill: #fff8f4;
  --tetee: #ff8fa3;
  --biberon: #5fd3c4;
  --change: #ffd166;
  --autre: #b5a8ff;
  --tetee-fill: #b33a5e;
  --biberon-fill: #16786f;
  --change-fill: #96660c;
  --autre-fill: #5847b0;
  --danger: #ff9c8a;
  --nav-height: 68px;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #ebe3d7;
  --line: #d6cbbb;
  --text: #2b241d;
  --muted: #6c5f50;
  --on-accent: #fffdf9;
  --on-fill: #fffdf9;
  --tetee: #8f5a1c;
  --biberon: #3b6b57;
  --change: #6f4d7e;
  --autre: #3f6585;
  --tetee-fill: #8f5a1c;
  --biberon-fill: #3b6b57;
  --change-fill: #6f4d7e;
  --autre-fill: #3f6585;
  --danger: #a33d2c;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; border: 0; background: none; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--tetee); outline-offset: 2px; }
[hidden] { display: none !important; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-height) + 24px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.5rem; margin: 0 0 16px; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; color: var(--muted); font-weight: 600; }

.offline {
  margin: 0;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface-2);
  color: var(--danger);
  font-size: .9rem;
  text-align: center;
}

/* Navigation */
.nav {
  position: fixed;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav button { height: var(--nav-height); color: var(--muted); font-size: .95rem; }
.nav button[aria-current='page'] { color: var(--text); font-weight: 700; box-shadow: inset 0 3px 0 var(--tetee); }

/* Accueil */
.status { display: grid; gap: 8px; margin-bottom: 20px; }
.status-row {
  background: var(--surface);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
}
.status-row strong { display: block; font-size: 1.15rem; font-weight: 650; }
.status-row span { color: var(--muted); font-size: .92rem; }

.is-tetee { --accent: var(--tetee); --fill: var(--tetee-fill); }
.is-biberon { --accent: var(--biberon); --fill: var(--biberon-fill); }
.is-change { --accent: var(--change); --fill: var(--change-fill); }
.is-autre { --accent: var(--autre); --fill: var(--autre-fill); }

.actions { display: grid; gap: 12px; }
.big {
  display: block;
  width: 100%;
  min-height: 88px;
  padding: 12px;
  border-radius: 16px;
  background: var(--fill);
  color: var(--on-fill);
  font-size: 1.45rem;
  font-weight: 700;
}
.actions-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions-pair .big { min-height: 76px; }
.big.is-autre { min-height: 60px; font-size: 1.15rem; }

.quiet {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 1.02rem;
}
.quiet.danger { color: var(--danger); }
.quiet.armed { background: var(--danger); color: var(--on-accent); font-weight: 700; }

.timer {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  text-align: center;
}
.timer-label { color: var(--tetee); font-weight: 650; }
.timer-clock {
  display: block;
  font-size: 4rem;
  line-height: 1.15;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer-meta { color: var(--muted); font-size: .92rem; }
.big.stop { min-height: 96px; font-size: 1.7rem; }

/* Journal */
.day-nav {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  margin: calc(-16px - env(safe-area-inset-top)) -16px 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
  text-align: center;
}
.day-nav button.arrow {
  height: 60px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 1.6rem;
}
.day-title { font-weight: 650; }
.day-title::first-letter { text-transform: uppercase; }

.entries { display: grid; gap: 8px; }
.entry {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 4px 10px;
  width: 100%;
  min-height: 68px;
  padding: 10px 14px;
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
}
.entry-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-title { font-weight: 650; }
.entry-meta, .entry-note { grid-column: 2; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.entry-note { color: var(--text); white-space: pre-wrap; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* Résumé */
.summary { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.summary th { color: var(--muted); font-size: .8rem; font-weight: 600; padding: 6px 2px; text-align: right; }
.summary th:first-child, .summary td:first-child { text-align: left; }
.summary td { padding: 0; text-align: right; border-top: 1px solid var(--line); }
.summary td button, .summary td span { display: block; width: 100%; min-height: 56px; padding: 15px 2px; text-align: inherit; }
.summary td button { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.summary tr.today td { font-weight: 700; }

/* Formulaires */
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 100dvh;
  height: 100dvh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
}
.sheet::backdrop { background: var(--bg); }
.sheet form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h1 { margin: 0; color: var(--accent); }
.close { width: 60px; height: 60px; margin-right: -12px; font-size: 1.8rem; color: var(--muted); }

.field { display: block; margin: 0; padding: 0; border: 0; min-width: 0; }
.field-label { display: block; padding: 0; margin-bottom: 6px; color: var(--muted); font-size: .92rem; }

input[type='number'], input[type='password'], input[type='text'], input[type='datetime-local'], textarea {
  display: block;
  width: 100%;
  min-height: 60px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.15rem;
}
input[type='datetime-local'] { -webkit-appearance: none; appearance: none; }
textarea { min-height: 76px; resize: vertical; font-size: 1.02rem; }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.segments.wrap { grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); }
.segment { position: relative; display: block; }
.segment input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.segment span, .chip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 64px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600;
  text-align: center;
}
.segment input:checked + span, .chip.selected { background: var(--fill); color: var(--on-fill); box-shadow: inset 0 0 0 2px var(--accent); }
.segment input:focus-visible + span { outline: 3px solid var(--text); outline-offset: 2px; }
.chip { min-height: 56px; font-size: 1.05rem; }
.chips-gap { margin-bottom: 8px; }

.form-error { margin: 0; color: var(--danger); font-weight: 600; }
/* Toujours à portée de pouce, même quand le formulaire dépasse de l'écran. */
.big.save {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 1;
  min-height: 76px;
  font-size: 1.3rem;
  box-shadow: 0 0 0 16px var(--bg);
}

/* Connexion et choix du parent */
.gate { display: grid; gap: 16px; padding-top: 12vh; }
.gate h1 { margin: 0; text-align: center; }
.gate .big { --fill: var(--tetee-fill); }

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-height) + 12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 528px;
  margin: 0 auto;
  padding: 8px 8px 8px 16px;
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.toast button { min-height: 44px; padding: 0 12px; color: var(--tetee); font-weight: 700; }

.more-hint { color: var(--muted); font-size: .92rem; margin: 8px 0 0; }
