/* ---------- Thème ---------- */
:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe1;
  --ink: #2b2520;
  --muted: #7a6f64;
  --line: #e4dbcd;
  --accent: #b9472a;
  --accent-ink: #ffffff;
  --accent-soft: #f8e3da;
  --today: #b9472a;
  --danger: #a32d2d;
  --ok-bg: #e5f2e3; --ok-ink: #2c5b26;
  --warn-bg: #fbf0d6; --warn-ink: #6d4f0b;
  --err-bg: #f9e1df; --err-ink: #8a2420;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Couleurs des familles (par nom de famille) */
  --c0: #f6dccf; --c0i: #7b2e14;
  --c1: #dbe8d2; --c1i: #2f5323;
  --c2: #d6e4f0; --c2i: #1f4565;
  --c3: #efdcf0; --c3i: #5d2a63;
  --c4: #f6eac4; --c4i: #6a4f08;
  --c5: #d3ece8; --c5i: #1c544c;
  --c6: #f3d6dd; --c6i: #75253a;
  --c7: #e3def3; --c7i: #3e3270;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --surface: #24201c;
    --surface-2: #2d2823;
    --ink: #efe8df;
    --muted: #a99d90;
    --line: #3a332c;
    --accent: #e0805f;
    --accent-ink: #1b1815;
    --accent-soft: #3d2a22;
    --today: #e0805f;
    --danger: #e57a72;
    --ok-bg: #22331f; --ok-ink: #b6dcae;
    --warn-bg: #3a3018; --warn-ink: #f0d58e;
    --err-bg: #3d2120; --err-ink: #f4b2ac;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --c0: #4a2e22; --c0i: #f6cbb7;
    --c1: #2e3d27; --c1i: #c6e2b8;
    --c2: #233749; --c2i: #bcd6ee;
    --c3: #432c45; --c3i: #ebc8ee;
    --c4: #463b1a; --c4i: #f2dc95;
    --c5: #1f3e3a; --c5i: #b3e3db;
    --c6: #4a2731; --c6i: #f3c1cd;
    --c7: #332d4f; --c7i: #d4cbf6;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: normal; }
.center { text-align: center; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 420px; margin: 0 auto; padding: 8vh 16px 40px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card h2 { font-size: 1.3rem; margin-bottom: 16px; }

/* ---------- Boutons & formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  font: inherit; font-weight: 500; color: var(--ink); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .up:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-icon { width: 40px; padding: 0; font-size: 1.5rem; line-height: 1; }
.btn-small { min-height: 32px; padding: 0 12px; font-size: .9rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--err-bg); border-color: var(--err-bg); }

label { display: block; font-weight: 500; font-size: .95rem; margin-bottom: 14px; }
input[type=text], input[type=password], input[type=number], input[type=search], select {
  display: block; width: 100%; margin-top: 6px;
  min-height: 42px; padding: 8px 12px;
  font: inherit; font-weight: normal; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus { border-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0 0 6px; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: .85rem; color: var(--muted); margin: -6px 0 14px; }
.row-2, .row-3 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr 1.5fr 1.2fr; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.alert { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; font-size: .95rem; }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert-error { background: var(--err-bg); color: var(--err-ink); }

/* ---------- Pages de connexion ---------- */
.login h1 { font-size: 1.6rem; margin-bottom: 4px; }
.login > p.muted { margin: 0 0 20px; }
.login .btn-primary { width: 100%; margin-top: 4px; }
.login-mark { font-size: 2.2rem; margin-bottom: 6px; }

/* ---------- En-tête ---------- */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); margin-bottom: 24px; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; flex-wrap: wrap; }
.site-title { font-size: 1.35rem; }
.admin-link { font-size: .95rem; text-decoration: none; }
.admin-link:hover { text-decoration: underline; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.header-actions form { margin: 0; }
.site-footer { color: var(--muted); font-size: .85rem; padding-top: 18px; padding-bottom: 32px; }

/* ---------- Prochains anniversaires ---------- */
.upcoming { margin-bottom: 26px; }
.upcoming h2 { font-size: 1.05rem; font-family: var(--sans); font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.upcoming-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.up {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; cursor: pointer;
  transition: border-color .15s;
}
.up:hover { border-color: var(--accent); }
.up.is-today { background: var(--accent-soft); border-color: var(--accent); }
.up-when { font-size: .8rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.up-name { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
.up-date { font-size: .88rem; color: var(--muted); }
.dot::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 2px; background: var(--chip-i); }

/* ---------- Barre d'outils ---------- */
.calendar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.nav { display: flex; gap: 6px; }
.period-title { flex: 1; font-size: 1.55rem; min-width: 180px; }
.week-no { display: block; font-family: var(--sans); font-size: .8rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.views { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.views button {
  font: inherit; font-size: .92rem; font-weight: 500; color: var(--muted);
  background: none; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; min-height: 34px;
}
.views button.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- Pastilles (personnes) ---------- */
.chip {
  --chip-bg: var(--c0); --chip-i: var(--c0i);
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px;
  background: var(--chip-bg); color: var(--chip-i);
  border-radius: 7px; padding: 2px 8px; font-size: .86rem; line-height: 1.35; max-width: 100%;
}
.chip-name { font-weight: 600; overflow-wrap: anywhere; }
.chip-age { font-size: .8em; opacity: .85; white-space: nowrap; }
.chip-note { flex-basis: 100%; font-size: .8em; opacity: .8; font-style: italic; }
.c0 { --chip-bg: var(--c0); --chip-i: var(--c0i); } .c1 { --chip-bg: var(--c1); --chip-i: var(--c1i); }
.c2 { --chip-bg: var(--c2); --chip-i: var(--c2i); } .c3 { --chip-bg: var(--c3); --chip-i: var(--c3i); }
.c4 { --chip-bg: var(--c4); --chip-i: var(--c4i); } .c5 { --chip-bg: var(--c5); --chip-i: var(--c5i); }
.c6 { --chip-bg: var(--c6); --chip-i: var(--c6i); } .c7 { --chip-bg: var(--c7); --chip-i: var(--c7i); }

/* ---------- Vue annuelle ---------- */
.year-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.ycard { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.ycard.is-current { border-color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.ycard-title {
  font: 600 1.15rem var(--serif); color: var(--ink); background: none; border: 0; padding: 0; margin-bottom: 8px; cursor: pointer;
}
.ycard-title:hover { color: var(--accent); }
.ylist, .mlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ylist li, .mlist li { display: flex; gap: 10px; align-items: flex-start; }
.ynum {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: .85rem;
  background: var(--surface); border: 1px solid var(--line);
}
.is-today .ynum { background: var(--today); border-color: var(--today); color: var(--accent-ink); }
.ynames { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 2px; min-width: 0; }
.yempty { color: var(--muted); font-size: .9rem; }

/* ---------- Vue mensuelle ---------- */
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.mhead { padding: 8px; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.mcell { min-height: 108px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mcell.is-weekend { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.mcell.is-out .mnum { color: var(--muted); opacity: .5; }
.mnum {
  align-self: flex-start; font: 600 .9rem var(--sans); color: var(--ink);
  width: 28px; height: 28px; border-radius: 50%; border: 0; background: none; cursor: pointer;
}
.mnum:hover { background: var(--surface-2); }
.mcell.is-today .mnum { background: var(--today); color: var(--accent-ink); }
.mchips { display: flex; flex-direction: column; gap: 3px; }
.mchips .chip { font-size: .8rem; }
.mlist { display: none; margin-top: 16px; }
.mlist-date { flex: none; width: 58px; font-weight: 600; font-size: .9rem; padding-top: 2px; }

/* ---------- Vue hebdomadaire ---------- */
.week-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.wday { display: grid; grid-template-columns: 170px 1fr; align-items: center; border-bottom: 1px solid var(--line); min-height: 70px; }
.wday:last-child { border-bottom: 0; }
.wday.is-weekend { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.wday.is-today { background: var(--accent-soft); }
.wdate { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "num dow" "num mon"; column-gap: 12px; padding: 12px 16px; align-items: center; }
.wnum { grid-area: num; font: 600 1.8rem/1 var(--serif); }
.wdow { grid-area: dow; font-weight: 600; font-size: .95rem; }
.wmon { grid-area: mon; font-size: .85rem; color: var(--muted); }
.wday.is-today .wnum { color: var(--today); }
.wchips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.wchips .chip { font-size: .98rem; padding: 6px 12px; border-radius: 9px; }
.wnone { color: var(--muted); }

.empty-hint { text-align: center; color: var(--muted); margin: 20px 0 0; }

/* ---------- Administration ---------- */
.admin-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; padding-bottom: 40px; }
.admin-grid .alert { margin: 0; }
.span-all { grid-column: 1 / -1; }
.list-card { grid-row: span 3; }
.list-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.list-head h2 { margin: 0; }
.list-head input { width: auto; flex: 1; max-width: 240px; margin: 0; }
.count { font: 600 .8rem var(--sans); background: var(--surface-2); color: var(--muted); border-radius: 20px; padding: 2px 9px; vertical-align: 3px; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.person-main { display: flex; flex-direction: column; min-width: 0; }
.person-main .muted { font-size: .9rem; }
.note { font-size: .85rem; font-style: italic; color: var(--muted); }
.person-actions { display: flex; gap: 6px; flex: none; }
.person-actions form { margin: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .admin-grid { grid-template-columns: 1fr; }
  .list-card { grid-row: auto; }
}
@media (max-width: 680px) {
  .site-title { font-size: 1.15rem; }
  .toolbar { gap: 10px; }
  .period-title { order: -1; flex-basis: 100%; font-size: 1.35rem; }
  .views { margin-left: auto; }
  .views button { padding: 7px 10px; }
  .calendar { padding: 12px; }
  .upcoming-list li:nth-child(n+4) { display: none; }
  .mcell { min-height: 52px; padding: 3px; align-items: center; }
  .mchips { display: none; }
  .mcell.has-bday .mnum { box-shadow: inset 0 0 0 2px var(--accent); }
  .mcell.is-today.has-bday .mnum { box-shadow: none; }
  .mhead { padding: 6px 2px; text-align: center; font-size: .7rem; }
  .mlist { display: grid; }
  .wday { grid-template-columns: 1fr; }
  .wdate { padding-bottom: 0; }
  .row-3 { grid-template-columns: 1fr 1.5fr; }
  .row-3 label:last-child { grid-column: 1 / -1; }
  .people li { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 420px) {
  .row-2 { grid-template-columns: 1fr; }
  .nav .btn:not(.btn-icon) { padding: 0 10px; }
}

/* ---------- Impression (ex. vue annuelle pour le frigo) ---------- */
@media print {
  body { background: #fff; color: #000; }
  .site-header, .upcoming, .nav, .views, .site-footer, .empty-hint { display: none; }
  .calendar { border: 0; box-shadow: none; padding: 0; }
  .ycard { break-inside: avoid; }
}

/* ---------- Abonnement agenda ---------- */
.agenda-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.agenda-actions form { margin: 0; }
.agenda-actions + .hint { margin-top: 10px; }
.sub { padding-bottom: 40px; }
.sub-intro { max-width: 68ch; margin: 0 0 20px; color: var(--muted); }
.sub-link { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: center; margin-bottom: 20px; }
.qr { width: 200px; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-block .hint { margin: 8px 0 0; }
.link-block label { margin-bottom: 6px; }
.copy-row { display: flex; gap: 8px; margin-bottom: 14px; }
.copy-row input { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.sub-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.sub-card h2 { margin-bottom: 14px; }
.sub-card ol { padding-left: 1.2em; margin: 14px 0 10px; }
.sub-card li { margin-bottom: 6px; }
.sub-card .hint { margin: 0; }
@media (max-width: 680px) {
  .sub-link { grid-template-columns: 1fr; justify-items: center; }
  .link-block { width: 100%; }
  .header-actions .btn-small { padding: 0 10px; }
}

/* ---------- Plusieurs calendriers ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cal-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--chip-i); vertical-align: -1px; flex: none; }
.site-title .cal-swatch { width: 16px; height: 16px; vertical-align: 0; margin-right: 2px; }
.title-block { display: flex; flex-direction: column; padding: 8px 0; }
.back-link { font-size: .85rem; text-decoration: none; color: var(--muted); }
.back-link:hover { color: var(--accent); }

.home { padding-bottom: 40px; }
.home-title { font-size: 1.05rem; font-family: var(--sans); font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 12px; }
.cal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.cal-card {
  display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; row-gap: 2px;
  height: 100%; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s;
}
.cal-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.cal-card .cal-swatch { width: 18px; height: 18px; grid-row: span 2; }
.cal-card-name { font: 600 1.25rem var(--serif); }
.cal-card-meta { font-size: .85rem; color: var(--muted); }
.home-empty { max-width: 520px; }

.cal-badge { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 20px; background: var(--chip-bg); color: var(--chip-i); margin: 2px 4px 0 0; }
.badges { display: flex; flex-wrap: wrap; margin-top: 2px; }
.cal-checks { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.cal-check {
  display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 8px 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 500;
}
.cal-check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.cal-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* Administration : onglets */
.admin-header { margin-bottom: 24px; }
.admin-header .header-inner { min-height: 60px; }
.who { font-size: .9rem; color: var(--muted); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-main { padding-bottom: 40px; }
.admin-main > .alert { margin-bottom: 16px; }
.admin-main .admin-grid { padding-bottom: 0; }
.admin-main .list-card { grid-row: auto; }
.filter-form { margin: 0; }
.filter-form select { margin: 0; min-height: 38px; width: auto; }
.stack { display: grid; gap: 20px; align-content: start; }
.card h3 { font-size: 1.05rem; margin: 22px 0 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.cal-admin { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); }
.cal-admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.cal-admin-list a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.cal-admin-list a:hover { background: var(--surface-2); }
.cal-admin-list .is-selected a { background: var(--accent-soft); }
.cal-admin-name { flex: 1; font-weight: 600; }
.cal-admin-list .muted { font-size: .85rem; }
.cal-links { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 16px; }
.cal-form { margin-top: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.swatch-pick { margin: 0; cursor: pointer; position: relative; }
.swatch-pick input { position: absolute; opacity: 0; }
.swatch-pick .cal-swatch { width: 30px; height: 30px; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatch-pick input:checked + .cal-swatch { box-shadow: 0 0 0 2px var(--accent); }
.swatch-pick input:focus-visible + .cal-swatch { outline: 2px solid var(--accent); outline-offset: 3px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.danger-zone h2 { color: var(--danger); font-size: 1.1rem; }
@media (max-width: 860px) {
  .cal-admin { grid-template-columns: 1fr; }
  .who { display: none; }
}
