:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17212b;
  --muted: #5d6b78;
  --border: #dde3e9;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d7f0ec;
  --danger: #b42318;
  --danger-soft: #fde4e1;
  --warn: #9a5b00;
  --warn-soft: #fdf0d5;
  --ok: #157347;
  --ok-soft: #dcf3e5;
  --info: #1d5fa8;
  --info-soft: #e0ecfa;
  --unavailable: #d64545;
  --avoid: #e5a000;
  --volunteer: #1f9d63;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #212b34;
    --text: #e8eef3;
    --muted: #9aa8b4;
    --border: #2c3843;
    --accent: #2bb3a3;
    --accent-text: #06201d;
    --accent-soft: #123a36;
    --danger: #ff8a80;
    --danger-soft: #3d1c1a;
    --warn: #f3c065;
    --warn-soft: #3a2d12;
    --ok: #6fd69e;
    --ok-soft: #153325;
    --info: #8cbcf2;
    --info-soft: #182c44;
    --unavailable: #e0605f;
    --avoid: #e6b23a;
    --volunteer: #3cb97c;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.loading {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

/* ---------- Structure ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(env(safe-area-inset-top) + 0.6rem) 16px 0.6rem;
  background: var(--accent);
  color: var(--accent-text);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
}

.who {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  min-width: 0;
}

.who span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top .link {
  color: inherit;
  opacity: 0.85;
}

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

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs a {
  flex: 1;
  max-width: 200px;
  height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
}

.tabs a.on {
  color: var(--accent);
}

.tabs svg {
  width: 24px;
  height: 24px;
}

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

.page-head {
  margin-bottom: 1rem;
}

.back {
  display: inline-block;
  margin-bottom: 0.5rem;
  text-decoration: none;
  font-size: 0.9rem;
}

/* ---------- Formulaires ---------- */

label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
}

label small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  margin-top: 0.2rem;
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 44px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 12px;
}

.row input {
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn.danger {
  color: var(--danger);
}

.btn.block {
  width: 100%;
}

.btn.sm {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0.75rem 0;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

details > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

details > summary::before {
  content: '+ ';
  color: var(--accent);
}

details[open] > summary {
  margin-bottom: 1rem;
}

details[open] > summary::before {
  content: '− ';
}

/* Contrôle segmenté */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.seg button {
  flex: 1;
  min-height: 40px;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.seg button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

.seg .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ---------- Connexion ---------- */

.auth {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 48px) 16px 32px;
}

.auth h1 {
  color: var(--accent);
  font-size: 1.8rem;
}

/* ---------- Puces ---------- */

.chip {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}

.chip.open {
  background: var(--info-soft);
  color: var(--info);
}

.chip.draft {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.published {
  background: var(--ok-soft);
  color: var(--ok);
}

.period {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

/* ---------- Calendrier ---------- */

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cal-head h2 {
  margin: 0;
  text-transform: capitalize;
}

.cal-nav {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.grid .wd {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 2px;
}

.day {
  position: relative;
  aspect-ratio: 1;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.day .n {
  font-size: 0.95rem;
}

.day.out {
  opacity: 0.4;
}

.day.today {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.day.hol {
  background: var(--surface-2);
}

.day.range-start {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.day.k-unavailable {
  background: var(--unavailable);
  border-color: var(--unavailable);
  color: #fff;
}

.day.k-avoid {
  background: var(--avoid);
  border-color: var(--avoid);
  color: #231a00;
}

.day.k-volunteer {
  background: var(--volunteer);
  border-color: var(--volunteer);
  color: #fff;
}

.day.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: repeating-linear-gradient(135deg, transparent 0 5px, rgb(127 127 127 / 0.18) 5px 7px);
  pointer-events: none;
}

.day .hol-dot {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 0.6rem;
  font-weight: 800;
  opacity: 0.8;
}

.day .oth {
  position: absolute;
  bottom: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 8px;
  font-size: 0.65rem;
  line-height: 16px;
  background: var(--text);
  color: var(--surface);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}

.unavailable {
  background: var(--unavailable);
}

.avoid {
  background: var(--avoid);
}

.volunteer {
  background: var(--volunteer);
}

.absence,
.day.k-absence {
  background: var(--muted);
  border-color: var(--muted);
  color: var(--surface);
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.list li:last-child {
  border-bottom: 0;
}

.banner {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.banner.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- Planning ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.5rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody th {
  text-align: left;
  font-weight: 600;
}

td small {
  color: var(--muted);
  font-weight: 400;
}

tr.me th,
tr.me td {
  background: var(--accent-soft);
}

td.tot {
  font-weight: 700;
}

.slot {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  scroll-margin-top: 80px;
}

.slot.t-weekend {
  border-left-color: var(--accent);
}

.slot.t-holiday {
  border-left-color: var(--avoid);
}

.slot.mine {
  background: var(--accent-soft);
}

.slot .when b {
  display: block;
}

.slot .when b::first-letter {
  text-transform: uppercase;
}

.slot .hours {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.slot .who {
  font-weight: 600;
  text-align: right;
}

.slot .who select {
  margin: 0;
  width: 160px;
  max-width: 48vw;
  padding: 0.45rem 0.5rem;
  font-size: 0.9rem;
}

.slot .flags {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.flag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 6px;
}

.flag.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.flag.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.flag.info {
  background: var(--surface-2);
  color: var(--muted);
}

.issues li button {
  text-align: left;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.toggle input {
  width: auto;
  min-height: 0;
  margin: 0;
}

/* ---------- Équipe ---------- */

.member {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.member .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.member .email {
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.member label {
  margin: 0;
}

/* ---------- Échanges ---------- */

.cap::first-letter {
  text-transform: uppercase;
}

.cap {
  display: inline-block;
}

fieldset {
  border: 0;
  margin: 0 0 0.85rem;
  padding: 0;
}

fieldset .toggle {
  margin-bottom: 0.6rem;
  align-items: flex-start;
}

fieldset .toggle input {
  margin-top: 0.2rem;
}

.returns {
  width: 100%;
}

.returns legend {
  margin-bottom: 0.5rem;
}

dialog.sheet {
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 90vh;
  margin: auto auto 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px);
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--text);
}

dialog.sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

@media (min-width: 640px) {
  dialog.sheet {
    margin: auto;
    border-radius: 18px;
  }
}

/* ---------- Accueil ---------- */

.top .brand {
  color: inherit;
  text-decoration: none;
}

.top .who a {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

.top .who a svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.tabs a {
  position: relative;
}

.badge {
  position: absolute;
  top: 8px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.badge.static {
  position: static;
}

.hero-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0.15rem 0;
}

a.plain {
  color: inherit;
  text-decoration: none;
  display: block;
}

.entries li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- Version imprimable ---------- */

.print-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.print-page h1 {
  font-size: 1.3rem;
  margin-top: 0.5rem;
}

.print-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.print-table {
  border: 1px solid var(--border);
}

.print-table th,
.print-table td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.5rem;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  min-width: 90px;
}

.print-table thead th {
  background: var(--surface-2);
}

.print-table tbody th {
  white-space: nowrap;
  min-width: 0;
}

.print-table td small {
  display: block;
  font-size: 0.75rem;
}

.print-table td.we {
  background: var(--accent-soft);
  font-weight: 600;
}

.print-table td.hol {
  background: var(--warn-soft);
}

.print-table td.out {
  background: var(--surface-2);
  color: var(--muted);
}

.unassigned {
  color: var(--danger);
  font-weight: 700;
}

@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --surface-2: #f1f3f5;
    --text: #000;
    --muted: #444;
    --border: #999;
    --accent-soft: #e3f4f1;
    --warn-soft: #fdf0d5;
    --danger: #b42318;
  }

  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
    font-size: 10pt;
  }

  .no-print,
  #toast {
    display: none !important;
  }

  .print-page {
    max-width: none;
    padding: 0;
  }

  .table-wrap {
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  .print-table th,
  .print-table td {
    padding: 3px 5px;
  }

  .print-table tr {
    break-inside: avoid;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ---------- Notification ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%) translateY(20px);
  max-width: min(92vw, 480px);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.error {
  background: var(--danger);
  color: #fff;
}

#modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

@media (min-width: 560px) {
  #modes {
    grid-template-columns: repeat(4, auto);
  }
}

@media (min-width: 640px) {
  .member {
    grid-template-columns: 1fr 160px 120px auto;
    align-items: end;
  }
}

/* Clé de double vérification : lisible et facile à recopier. */
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.06em;
}
#totp-card ol.list {
  padding-left: 1.3em;
  list-style: decimal;
}
#totp-card > .btn {
  margin: 4px 0 12px;
}
