:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #24211d;
  --muted: #6f685f;
  --border: #e4ded4;
  --accent: #2f6f62;
  --accent-text: #ffffff;
  --papa: #f2a900;
  --papa-soft: #fff1cc;
  --maman: #d65aa8;
  --maman-soft: #f9e0ef;
  --service: #dceaf7;
  --decouche: #d6f2da;
  --retour: #e8f5e3;
  --repos: #e7edf6;
  --dispo: #fde2e0;
  --ferie: #dfeef0;
  --danger: #b3261e;
  --ok: #2e7d32;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #262421;
    --text: #efe9e1;
    --muted: #a59d92;
    --border: #3a3732;
    --accent: #6cc3ad;
    --accent-text: #10201c;
    --papa: #f5bc2f;
    --papa-soft: #4a3a10;
    --maman: #ec8cc8;
    --maman-soft: #4b2340;
    --service: #22364a;
    --decouche: #1f3d26;
    --retour: #24361f;
    --repos: #2a3240;
    --dispo: #4a2522;
    --ferie: #213a3e;
    --danger: #ff8a80;
    --ok: #81c784;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

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

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

h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin-bottom: 8px; }

button, input, select { font: inherit; color: inherit; }

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

label { display: grid; gap: 4px; margin: 10px 0; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > .row { color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}

.muted { color: var(--muted); }
.error { color: var(--danger); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.spacer { flex: 1; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

/* Connexion */
.login { padding-top: 12vh; }
.login h1 { text-align: center; margin-bottom: 16px; }
.login .card { max-width: 380px; margin: 0 auto; }
.login button { width: 100%; margin-top: 8px; }

/* Barre du haut */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 6px;
}
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav.dim { opacity: .5; }
.month-nav h1 { font-size: 1.3rem; text-transform: capitalize; }
.month-nav button { width: 40px; height: 40px; padding: 0; font-size: 1.4rem; line-height: 1; }
.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tabs button { flex: 1; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Résumé */
.summary { display: grid; gap: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .85rem; }

/* Semaines et jours */
.week { padding: 0; overflow: hidden; }
.week > header {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: .9rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.week .total { color: var(--text); font-weight: 600; }
.diff { font-weight: 400; }
.diff.over { color: var(--danger); }
.diff.under { color: var(--muted); }
.diff.ok { color: var(--ok); }

.week-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 14px;
  font-size: .85rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.week-actions .muted { flex: 1; min-width: 160px; }
button.small { padding: 5px 12px; font-size: .85rem; }

/* Jour proposé automatiquement, pas encore validé */
.day.suggested .cell.time { font-weight: 500; opacity: .75; }
.day.suggested .cell.time.papa,
.day.suggested .cell.time.maman { background: transparent; box-shadow: none; outline-offset: -4px; }
.day.suggested .cell.time.papa { outline: 2px dashed var(--papa); }
.day.suggested .cell.time.maman { outline: 2px dashed var(--maman); }
.day.suggested .cell.total::after { content: ' ?'; }

.hint {
  font-size: .85rem;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Tableau façon Excel : Jour | Maryne | Arrivée | Départ | Heures */
.grid-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 62px 62px 52px;
  align-items: stretch;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  padding: 0;
}
.grid-row:last-child { border-bottom: 0; }
.cell { padding: 8px 6px; display: flex; align-items: center; min-width: 0; }
.cell + .cell { border-left: 1px solid var(--border); }
.cell.time, .cell.total { justify-content: center; font-variant-numeric: tabular-nums; }

.grid-head { color: var(--muted); }
.grid-head .cell,
.grid-head .cell.time,
.grid-head .cell.total {
  padding: 6px 2px;
  font-size: .7rem;
  font-weight: 500;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid-head .cell:nth-child(2) { padding-left: 6px; }

.day { min-height: 48px; }
.day:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.day.out { opacity: .45; }
.day.weekend { background: color-mix(in srgb, var(--muted) 7%, transparent); }
.day.weekend .date { color: var(--muted); }
.day.today .num { background: var(--accent); color: var(--accent-text); }

.cell.date { flex-direction: column; justify-content: center; gap: 0; padding: 4px 0; }
.date .wd { font-size: .7rem; color: var(--muted); }
.date .num { font-weight: 650; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }

.cell.sncf { flex-wrap: wrap; gap: 4px; }
.cell.time { font-weight: 600; }
.cell.time.papa { background: var(--papa-soft); box-shadow: inset 0 -3px 0 var(--papa); }
.cell.time.maman { background: var(--maman-soft); box-shadow: inset 0 -3px 0 var(--maman); }
.cell.total { font-size: .85rem; color: var(--muted); }
.cell.span-times { grid-column: 3 / 5; justify-content: center; font-size: .85rem; }
.cell.status-ferie { background: var(--ferie); }
.cell.status-aucune { color: var(--muted); }
.cell.status-vacances, .cell.status-conge, .cell.status-absence_nanou { background: var(--dispo); }
.cell.note {
  grid-column: 2 / -1;
  border-left: 1px solid var(--border);
  border-top: 1px dashed var(--border);
  padding: 4px 6px;
  font-size: .8rem;
  color: var(--muted);
}

@media (max-width: 420px) {
  .grid-row { grid-template-columns: 34px minmax(0, 1fr) 52px 52px 44px; }
  .cell { padding: 6px 4px; }
  .cell.time { font-size: .9rem; }
  .chip { font-size: .72rem; padding: 2px 6px; }
}

.chip, .badge {
  display: inline-block;
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip { background: var(--service); }
.chip.decouche { background: var(--decouche); }
.chip.retour { background: var(--retour); }
.chip.repos { background: var(--repos); }
.chip.dispo { background: var(--dispo); }
.chip.vma, .chip.autre { background: var(--repos); }
.chip.ferie, .chip.status-ferie { background: var(--ferie); }
.chip.status-vacances, .chip.status-conge, .chip.status-absence_nanou { background: var(--dispo); }

.badge.papa { background: var(--papa-soft); color: var(--text); border: 1px solid var(--papa); }
.badge.maman { background: var(--maman-soft); color: var(--text); border: 1px solid var(--maman); }

/* Dialogue d'édition */
dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { text-transform: capitalize; margin-bottom: 2px; }
fieldset { border: 0; padding: 0; margin: 10px 0; }
fieldset[hidden] { display: none; }
legend { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { font-size: .85rem; padding: 6px 10px; font-variant-numeric: tabular-nums; }
.segmented { display: flex; gap: 8px; }
.segmented button { flex: 1; }
.segmented button.papa.on { background: var(--papa); border-color: var(--papa); color: #1f1a10; }
.segmented button.maman.on { background: var(--maman); border-color: var(--maman); color: #1f1020; }

/* Réglages */
.copy .row input { font-size: .8rem; }
.copy .row button { flex: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  max-width: calc(100vw - 32px);
  z-index: 50;
}
.toast.error { background: var(--danger); color: #fff; }

/* Choix de la vue (Semaine / Mois / Calendrier) */
.switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.switch button { flex: 1; border: 0; background: transparent; padding: 6px 10px; font-size: .9rem; }
.switch button.on { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / .12); font-weight: 600; }

@media (max-width: 420px) {
  .month-nav h1 { font-size: 1.05rem; text-align: center; }
}

/* Calendrier du mois */
.cal { padding: 0; overflow: hidden; }
.cal-head, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head span {
  padding: 6px 4px;
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.cal-day {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  min-height: 88px;
  min-width: 0;
  padding: 4px;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  font-size: .78rem;
}
.cal-day:nth-child(7) { border-right: 0; }
.cal-week:last-child .cal-day { border-bottom: 0; }
.cal-day:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.cal-day.out { opacity: .4; }
.cal-day.weekend { background: color-mix(in srgb, var(--muted) 7%, transparent); }
.cal-day .num { font-weight: 650; font-size: .85rem; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); }
.cal-sncf {
  font-size: .7rem;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--service);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-sncf.decouche { background: var(--decouche); }
.cal-sncf.retour { background: var(--retour); }
.cal-sncf.repos, .cal-sncf.vma, .cal-sncf.autre { background: var(--repos); }
.cal-sncf.dispo { background: var(--dispo); }
.cal-sncf.ferie { background: var(--ferie); }
.cal-times { display: grid; gap: 2px; margin-top: auto; }
.cal-times .t {
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 4px;
  padding: 1px 0;
}
.cal-times .t.papa { background: var(--papa-soft); box-shadow: inset 3px 0 0 var(--papa); }
.cal-times .t.maman { background: var(--maman-soft); box-shadow: inset 3px 0 0 var(--maman); }
.cal-day.suggested .cal-times .t { background: transparent; box-shadow: none; font-weight: 500; opacity: .8; }
.cal-day.suggested .cal-times .t.papa { outline: 1.5px dashed var(--papa); outline-offset: -1.5px; }
.cal-day.suggested .cal-times .t.maman { outline: 1.5px dashed var(--maman); outline-offset: -1.5px; }
.cal-status { margin-top: auto; font-size: .7rem; color: var(--muted); text-align: center; }
.cal-totals .cal-total-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: .9rem;
}
.cal-totals .cal-total-row .week-actions { flex-basis: 100%; border: 0; border-radius: 10px; }

@media (max-width: 420px) {
  .cal-day { min-height: 76px; padding: 3px 2px; }
  .cal-times .t { font-size: .7rem; }
  .cal-sncf { font-size: .62rem; padding: 1px 2px; }
}

/* Export pour la nounou */
.export-sheet h2 { font-size: 1.25rem; margin: 0; }
.export-sheet .period { margin: 2px 0 12px; text-transform: none; }
.export-table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: .9rem; }
.export-table caption { text-align: left; font-weight: 600; padding: 6px 0; }
.export-table th, .export-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.export-table th { font-size: .78rem; color: var(--muted); font-weight: 500; }
.export-table td.t, .export-table td.num { font-variant-numeric: tabular-nums; text-align: center; }
.export-table td.t { font-weight: 600; }
.export-table td.t.papa { background: var(--papa-soft); }
.export-table td.t.maman { background: var(--maman-soft); }
.export-table tr.off td { color: var(--muted); font-style: italic; }
.export-table tfoot td { font-weight: 600; }
.grand-total { font-weight: 700; font-size: 1.05rem; text-align: right; }
.export-sheet td:first-child { text-transform: capitalize; white-space: nowrap; }

@media (max-width: 420px) {
  .export-table { font-size: .8rem; }
  .export-table th, .export-table td { padding: 5px 4px; }
}

/* Impression : seulement la feuille d'export */
@media print {
  @page { margin: 14mm; }
  :root { color-scheme: light; }
  body { background: #fff; color: #000; }
  .topbar, .no-print, .toast, dialog { display: none !important; }
  main { max-width: none; padding: 0; }
  .export-sheet { border: 0; padding: 0; margin: 0; background: #fff; }
  .export-table th, .export-table td { border-color: #999; color: #000; }
  .export-table td.t.papa { background: #ffe9b3 !important; }
  .export-table td.t.maman { background: #f7d3ea !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Bilan annuel */
.bilan-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.bilan-table th, .bilan-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.bilan-table th { font-size: .78rem; font-weight: 500; color: var(--muted); }
.bilan-table th:not(:first-child) { text-align: right; }
.bilan-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bilan-table td.hours { font-weight: 600; }
.bilan-table tr.over td.hours,
.bilan-table .over { color: var(--danger); }
.bilan-table tr.over { background: color-mix(in srgb, var(--danger) 9%, transparent); }
.bilan-table tr.empty td { color: var(--muted); }
.bilan-table tr.current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.bilan-table td.planned { font-size: .82rem; }
.bilan-table tfoot td { font-weight: 700; border-bottom: 0; }
.bilan-table button.link {
  border: 0;
  background: none;
  padding: 0;
  border-radius: 0;
  text-transform: capitalize;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}
p.small { font-size: .8rem; margin-bottom: 0; }

@media (max-width: 420px) {
  .tabs button { padding: 8px 6px; font-size: .9rem; }
}

/* Totaux en direct dans la fenêtre d'édition */
.live {
  display: grid;
  gap: 4px;
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.live-row { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; }
.live-row.over, .live-row.over strong { color: var(--danger); }
.live p.small { margin: 2px 0 0; }
