:root {
  --bg: #f4f4f6; --fg: #1d1d1f; --muted: #6b6b72; --card: #fff; --border: #e2e2e7; --hover: #f7f7f9;
  --accent: #2f6fde; --ok: #1f8a4c; --warn: #b7791f; --bad: #c53030;
  --ok-tint: rgba(31, 138, 76, .12); --warn-tint: rgba(183, 121, 31, .14); --accent-tint: rgba(47, 111, 222, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --fg: #ececf0; --muted: #9a9aa3; --card: #1f1f23; --border: #303036; --hover: #26262b;
    --ok: #3fb872; --warn: #e0a640; --bad: #ef5b5b; --accent: #5b8ff0;
    --ok-tint: rgba(63, 184, 114, .14); --warn-tint: rgba(224, 166, 64, .15); --accent-tint: rgba(91, 143, 240, .15);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
h1 { font-size: 1.2rem; margin: .3rem 0; }
h2 { font-size: 1.05rem; margin-top: 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: .9em; }
.error { color: var(--bad); }
.notice { background: var(--card); border-left: 4px solid var(--accent); border-radius: 4px; padding: .5rem .75rem; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

/* Layout */
header { display: flex; align-items: center; gap: .5rem 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--border); }
nav { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; margin-left: auto; }
nav a { padding: .3rem .65rem; border-radius: 6px; color: var(--muted); text-decoration: none; }
nav a:hover { color: var(--fg); background: var(--hover); }
nav a[aria-current=page] { color: var(--accent); background: var(--accent-tint); font-weight: 600; }
form.logout { padding-left: .75rem; border-left: 1px solid var(--border); }
form.logout button.link { color: var(--muted); font-size: .85em; }
form.logout button.link:hover { color: var(--fg); }
.dry-run summary { cursor: pointer; }
.dry-run[open] summary { margin-bottom: .3rem; }
main { padding: 1rem; max-width: 960px; margin: auto; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem 1rem; }
.toolbar h1 { text-align: center; }
.nav-week { white-space: nowrap; text-decoration: none; }

/* Buttons */
button { padding: .35rem .85rem; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; cursor: pointer; font: inherit; font-size: .9em; white-space: nowrap; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.danger { background: var(--bad); border-color: var(--bad); }
button.secondary { background: transparent; color: var(--fg); border-color: var(--border); }
input[type=checkbox] { margin: 0; vertical-align: -2px; accent-color: var(--accent); }
form.inline { display: inline; }

/* Login */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; }
.login { max-width: 340px; margin: 10vh auto; display: flex; flex-direction: column; gap: .4rem; }
.login input { width: 100%; padding: .5rem; font: inherit; }
.login label { margin-top: .4rem; }
.login button { margin-top: .8rem; padding: .5rem; }

/* Tables (jobs) */
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: .85em; color: var(--muted); font-weight: 600; }
.log { background: var(--card); border: 1px solid var(--border); padding: .75rem; overflow-x: auto; font-size: .85em; }

/* Badges (job status) */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 10px; font-size: .85em; background: var(--border);
  color: var(--fg); text-decoration: none; white-space: nowrap; }
.badge.booked { background: var(--ok); color: #fff; }
.badge.waitlisted { background: var(--warn); color: #1d1d1f; }
.badge.failed { background: var(--bad); color: #fff; }
.badge.running, .badge.scheduled { background: var(--accent); color: #fff; }
.badge.simulated { background: #7c5cc4; color: #fff; }
.badge.test { background: transparent; color: #9b7fe0; border: 1px dashed #7c5cc4; }

/* Activity colours, matching the Multiresa planning. Each class sets the
   colour as variables; .act (label) and .session (left bar) use them. */
.act-80 { --act: #ff0000; }              /* Cross training */
.act-88 { --act: #009900; }              /* Pilates */
.act-89 { --act: #ff00ff; }              /* Stretching */
.act-93 { --act: #ff6600; }              /* Renforcement musculaire */
.act-94 { --act: #666666; }              /* Abdo fessier */
.act-95 { --act: #99ccff; --act-fg: #111; } /* Yoga */
.act-96 { --act: #ffff00; --act-fg: #111; } /* Zumba */
.act-97 { --act: #0099cc; }              /* Body sculpt */
.act-99 { --act: #993333; }              /* Biking */
.act { display: inline-block; padding: .1rem .55rem; border-radius: 4px; background: var(--act, #777); color: var(--act-fg, #fff);
  text-decoration: none; text-transform: uppercase; font-size: .85em; white-space: nowrap; }

/* Activity selector */
.filters { display: flex; flex-wrap: wrap; gap: .35rem; margin: .6rem 0 .8rem; }
.chip { display: inline-flex; align-items: center; padding: .28rem .65rem; border-radius: 4px; font-size: .8em; line-height: 1.2;
  cursor: pointer; user-select: none; border: 2px solid transparent; text-transform: uppercase;
  background: var(--act, transparent); color: var(--act-fg, #fff); transition: opacity .12s, filter .12s; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.off { opacity: .3; filter: grayscale(.7); }
.chip-all { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 600; }
.chip-all.off { opacity: 1; filter: none; background: transparent; color: var(--fg); }

/* ── Session list (planning and reservations) ─────────────────────────── */
.day-title { position: sticky; top: 0; z-index: 1; margin: 1.2rem 0 .4rem; padding: .35rem .1rem; background: var(--bg);
  font-size: .95rem; font-weight: 700; }
.day-title::first-letter { text-transform: uppercase; }
.sessions { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }

/* One session: time | name + one line of details | status or action.
   The activity colour is the left bar. */
.session { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr) auto; grid-template-areas: "time main actions";
  align-items: center; gap: .15rem .9rem; padding: .6rem .9rem .6rem .75rem;
  border-left: 5px solid var(--act, var(--border)); border-bottom: 1px solid var(--border); }
.session:last-child { border-bottom: none; }
.session:hover { background: var(--hover); }
.session.past, .session.cancelled { opacity: .5; }
.session.cancelled .s-title { text-decoration: line-through; }

.s-time { grid-area: time; display: flex; flex-direction: column; line-height: 1.2; font-variant-numeric: tabular-nums; }
.s-time strong { font-size: 1.05em; }
.s-time span { font-size: .8em; color: var(--muted); }
.s-main { grid-area: main; min-width: 0; }
.s-title { font-weight: 600; }
.s-meta { font-size: .85em; color: var(--muted); }
.s-meta .full { color: var(--bad); font-weight: 600; }
.s-meta .free { color: var(--ok); font-weight: 600; }
.s-actions { grid-area: actions; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .4rem; }

/* What an account already has on the session. */
.holding { display: inline-flex; align-items: center; gap: .45rem; padding: .2rem .6rem; border-radius: 6px;
  font-size: .85em; font-weight: 600; white-space: nowrap; text-decoration: none; }
.holding.booked { background: var(--ok-tint); color: var(--ok); }
.holding.waiting { background: var(--warn-tint); color: var(--warn); }
.holding.job { background: var(--accent-tint); color: var(--accent); }
.holding.job.failed { background: rgba(197, 48, 48, .12); color: var(--bad); }
.holding form { display: inline; }
.cancel-btn { background: none; border: none; padding: 0 0 0 .45rem; border-left: 1px solid currentColor; border-radius: 0;
  color: var(--bad); font-size: 1em; font-weight: 500; }
.cancel-btn:hover:not(:disabled) { text-decoration: underline; }
.cancel-btn:disabled { color: var(--muted); opacity: 1; font-weight: 400; }

/* Schedule / book form. */
form.schedule { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .4rem .6rem; }
.pick { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .85em; cursor: pointer; white-space: nowrap; }
.pick:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
button.no-cancel { background: var(--warn); border-color: var(--warn); color: #1d1d1f; font-weight: 600; }
button.no-cancel::before { content: "⚠ "; }
.pick.blocked { opacity: .5; cursor: not-allowed; text-decoration: line-through; }
.blocked-note { font-size: .8em; color: var(--muted); text-align: right; }
.blocked-note::before { content: "⊘ "; }

/* Reservations page */
.person { margin-bottom: 1.6rem; }
.person > h2 { margin: 1rem 0 .2rem; font-size: 1.1rem; }
.person .day-title { position: static; margin-top: .8rem; }

/* Confirmation modal */
dialog.modal { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--card); color: var(--fg);
  width: min(28rem, calc(100vw - 2rem)); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .55); }
dialog.modal form { padding: 1.1rem 1.2rem 1rem; }
dialog.modal h2 { margin: 0 0 .6rem; font-size: 1.1rem; }
dialog.modal p { margin: 0 0 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
dialog.modal p.modal-warning { background: rgba(183, 121, 31, .15); border-left: 4px solid var(--warn); border-radius: 4px; padding: .5rem .7rem; }
dialog.modal p.modal-warning::before { content: "⚠ "; }
.modal-check { display: flex; gap: .5rem; align-items: flex-start; margin: 0 0 1.1rem; cursor: pointer; }
.modal-check input { margin-top: .2rem; }
.modal-actions button.no-cancel { background: var(--warn); border-color: var(--warn); color: #1d1d1f; font-weight: 600; }
.modal-actions button { padding: .45rem 1rem; }

/* ── Small screens ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  main { padding: .6rem; }
  /* Header: app name and logout on top, the tabs on one row below. */
  header { padding: .45rem .6rem .35rem; gap: .3rem; }
  form.logout { margin-left: auto; border-left: none; padding-left: 0; }
  nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; margin-left: 0; gap: .15rem; }
  nav a { flex: 1; text-align: center; padding: .35rem .2rem; font-size: .9em; white-space: nowrap; }

  /* Activity chips: one row scrolled sideways (enabled ones come first). */
  .filters { flex-wrap: nowrap; overflow-x: auto; margin: .5rem -.6rem .6rem; padding: 0 .6rem 2px;
    scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .dry-run { font-size: .85em; padding: .35rem .6rem; }
  /* Blocked session: the note says why, the greyed button adds nothing. */
  button.blocked-btn { display: none; }
  .toolbar h1 { font-size: 1rem; }
  .nav-week span { display: none; }

  /* Session: time + name/details on top, status or action below, right-aligned. */
  .session { grid-template-columns: 3rem minmax(0, 1fr); grid-template-areas: "time main" "actions actions";
    padding: .55rem .7rem .55rem .6rem; gap: .35rem .7rem; }
  .s-actions:not(:has(*)) { display: none; }
  .s-actions { justify-content: flex-end; }

  /* Job tables become label/value cards. */
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; }
  table.cards { background: none; }
  table.cards thead { display: none; }
  table.cards tr { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; margin-bottom: .5rem; }
  table.cards td { border: none; padding: .15rem 0; display: flex; gap: .6rem; }
  table.cards td[data-label]::before { content: attr(data-label); color: var(--muted); min-width: 5.5rem; flex-shrink: 0; font-size: .9em; }
  table.cards td.actions:empty { display: none; }
}
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { text-decoration: underline; }

/* Notifications (result of an action, outcome of a job), over the page so
   they do not move the content. */
.toasts { position: fixed; z-index: 50; left: 50%; bottom: 1rem; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; width: max-content; max-width: min(36rem, calc(100vw - 2rem)); }
.toasts:empty { display: none; }
.toast { display: flex; gap: .75rem; align-items: flex-start;
  background: var(--card); color: var(--fg); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 6px; padding: .6rem .75rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); overflow-wrap: anywhere;
  transition: opacity .3s, transform .3s; }
.toast.failed { border-left-color: var(--bad); }
.toast.booked, .toast.waitlisted { border-left-color: var(--ok); }
.toast.simulated { border-left-color: #7c5cc4; }
.toast.hide { opacity: 0; transform: translateY(.5rem); pointer-events: none; }
.toast-close { background: none; border: 0; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 0 .1rem; cursor: pointer; }

/* Comptes */
.settings { margin-bottom: 2rem; }
.settings-head h2 { margin: 1.2rem 0 .2rem; }
.settings-head p { margin: 0 0 .7rem; max-width: 46rem; }
.card.accounts { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.card.flush { padding: 0; }
.accounts > li + li { border-top: 1px solid var(--border); }
.accounts .empty { padding: .9rem 1.1rem; }

.account summary { display: flex; align-items: center; gap: .8rem; padding: .75rem 1.1rem; cursor: pointer; list-style: none; }
.account summary::-webkit-details-marker { display: none; }
.account summary:hover { background: var(--hover); }
.account summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.avatar { flex: none; display: grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent); font-weight: 700; }
.avatar.add { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 1.2em; font-weight: 400; }
.account-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.account-id span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-toggle { margin-left: auto; font-size: .85em; color: var(--accent); white-space: nowrap; }
.account-toggle::after { content: " ▾"; }
.account[open] .account-toggle::after { content: " ▴"; }
.account[open] .account-toggle { color: var(--muted); }
.account[open] > summary { background: var(--hover); }

.account-body { padding: 1rem 1.1rem; }
.account[open] .account-body { border-top: 1px solid var(--border); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem .9rem; }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fields label, .inline-field { display: flex; flex-direction: column; gap: .25rem; font-size: .85em; color: var(--muted); }
.fields input, .inline-field input { width: 100%; padding: .45rem .6rem; font: inherit; font-size: 1rem; color: var(--fg);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.fields input:focus, .inline-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.fields input::placeholder, .inline-field input::placeholder { color: var(--muted); opacity: .7; }
.form-foot { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem .9rem; margin-top: 1rem; padding-top: .9rem;
  border-top: 1px dashed var(--border); }
.form-foot > :last-child { margin-left: auto; }
.form-foot button { padding: .45rem 1.1rem; }
.inline-field { flex: 0 1 16rem; }
button.danger-outline { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
button.danger-outline:hover:not(:disabled) { background: rgba(197, 48, 48, .1); }
button.link:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 640px) {
  .fields, .fields.three { grid-template-columns: 1fr; }
  .inline-field { flex-basis: 100%; }
  .form-foot > :last-child { margin-left: 0; width: 100%; }
  .account summary { padding: .7rem .8rem; }
  .account-body { padding: .9rem .8rem; }
}
