:root {
  --start-min: 420;   /* 07:00 */
  --end-min: 1110;    /* 18:30 */
  --px-per-min: 1.4;
  --axis-w: 58px;
  --bg: #fafbfc;
  --line: #e3e6ea;
  --line-strong: #c8ccd1;
  --text: #1f2328;
  --muted: #6a737d;
  --accent: #0969da;
  --accent-soft: #dbeafe;
  --danger: #b91c1c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
header {
  position: sticky; top: 0; z-index: 10;
  background: #fff;
  border-bottom: 1px solid var(--line-strong);
}
.hrow {
  padding: 10px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
}
.hrow + .hrow { padding-top: 0; }
h1 { font-size: 16px; margin: 0 8px 0 0; font-weight: 600; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}
nav.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.user-box { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.user-name { font-weight: 600; color: var(--text); }
.link-logout { color: var(--accent); text-decoration: none; }
.link-logout:hover { text-decoration: underline; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.group { display: flex; align-items: center; gap: 6px; }
label { color: var(--muted); font-size: 13px; }
select, button, input[type=month], input[type=text], input[type=time], input[type=password] {
  font: inherit;
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
input[type=text], input[type=time], input[type=password] { cursor: text; }
select { min-width: 160px; }
.btn-toggle { display: inline-flex; }
.btn-toggle button { border-radius: 0; border-left-width: 0; }
.btn-toggle button:first-child { border-radius: 6px 0 0 6px; border-left-width: 1px; }
.btn-toggle button:last-child { border-radius: 0 6px 6px 0; }
.btn-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-danger { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }
.count { color: var(--muted); font-size: 13px; }

main { padding: 16px; overflow-x: auto; }
.view { display: none; }
.view.active { display: block; }

/* Timeline grids */
.tg {
  position: relative;
  display: grid;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}
.col-header {
  height: 34px; line-height: 34px;
  text-align: center; font-weight: 600;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line-strong);
  border-left: 1px solid var(--line);
  padding: 0 4px;
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.col-header:first-child { border-left: none; }
.col-header.big { font-size: 14px; }
.axis, .lane { position: relative; border-left: 1px solid var(--line); }
.axis { border-left: none; background: #f6f8fa; }
.axis .tick {
  position: absolute; left: 0; right: 0;
  font-size: 11px; color: var(--muted);
  padding: 0 6px 0 4px;
  text-align: right;
  transform: translateY(-50%);
}
.lane .hline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--line); }
.lane .hline.hour { border-top-color: var(--line-strong); }
.event {
  position: absolute;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  border: 1px solid #93c5fd;
  color: #0b2545;
  font-size: 11px;
  overflow: hidden;
  line-height: 1.2;
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
  cursor: pointer;
}
.event:hover { filter: brightness(0.97); }
.event .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.event .a { font-weight: 600; margin-top: 1px; }
.event .s { color: #334155; }
.event.compact {
  padding: 1px 6px;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.event.compact .t { font-weight: 600; }
.event.sem-paire { background: #fef3c7; border-color: #fcd34d; color: #3f2d00; }
.event.sem-paire .s { color: #5c4300; }
.event.sem-impaire { background: #fae8ff; border-color: #e9a8f5; color: #4a0a5c; }
.event.sem-impaire .s { color: #6b1a80; }
.tag {
  display: inline-block; font-size: 10px; padding: 0 4px;
  border-radius: 3px; background: rgba(0,0,0,.08);
  margin-left: 4px; vertical-align: middle;
}
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Month */
.cal { background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.cal-weekhead { display: grid; grid-template-columns: 40px repeat(7, 1fr); background: #f6f8fa; border-bottom: 1px solid var(--line-strong); }
.cal-weekhead div { padding: 8px 6px; font-weight: 600; font-size: 12px; text-align: center; border-left: 1px solid var(--line); }
.cal-weekhead div:first-child { border-left: none; color: var(--muted); font-weight: 500; }
.cal-week { display: grid; grid-template-columns: 40px repeat(7, 1fr); border-top: 1px solid var(--line); }
.cal-week:first-of-type { border-top: none; }
.cal-week .wn {
  padding: 6px 4px; font-size: 11px; color: var(--muted);
  background: #f6f8fa; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.cal-week .wn .parity { margin-top: 2px; font-weight: 600; font-size: 10px; padding: 1px 5px; border-radius: 3px; }
.cal-week .wn .parity.paire { background: #fef3c7; color: #5c4300; }
.cal-week .wn .parity.impaire { background: #fae8ff; color: #6b1a80; }
.cal-day {
  min-height: 110px;
  padding: 4px 6px;
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.cal-day:first-child { border-left: none; }
.cal-day.other-month { background: #fafbfc; color: #b0b6bd; }
.cal-day.weekend { background: #f6f8fa; }
.cal-day .dnum { font-size: 12px; font-weight: 600; }
.cal-day .dnum.today {
  display: inline-block; min-width: 20px; text-align: center;
  background: var(--accent); color: #fff; border-radius: 10px; padding: 0 6px;
}
.cal-evt { font-size: 10.5px; padding: 1px 4px; border-radius: 3px; background: var(--accent-soft); border-left: 3px solid #93c5fd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cal-evt.sem-paire { background: #fef3c7; border-left-color: #fcd34d; }
.cal-evt.sem-impaire { background: #fae8ff; border-left-color: #e9a8f5; }
.cal-evt .ct { font-variant-numeric: tabular-nums; color: var(--muted); }
.cal-more { font-size: 10px; color: var(--muted); padding: 1px 4px; }

/* Synthèse */
.synth { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.synth th, .synth td { padding: 6px 10px; text-align: center; font-size: 13px; border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.synth thead th { background: #f6f8fa; font-weight: 600; }
.synth th:first-child, .synth td:first-child { text-align: left; border-left: none; font-weight: 500; }
.synth tfoot td { background: #f6f8fa; font-weight: 600; border-top: 1px solid var(--line-strong); }
.synth td.cell { font-variant-numeric: tabular-nums; }
h3 { margin: 20px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* Print */
.print-page { background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; padding: 18px; margin-bottom: 18px; }
.print-page h2 { margin: 0 0 4px; font-size: 18px; }
.print-page .sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

@media print {
  header, .toolbar, .user-box, #modal-root { display: none !important; }
  main { padding: 0; overflow: visible; }
  body { background: #fff; }
  .view:not(.active) { display: none !important; }
  .print-page { border: none; border-radius: 0; padding: 0; margin: 0; page-break-after: always; }
  .print-page:last-child { page-break-after: auto; }
  @page { size: A4 landscape; margin: 12mm; }
}

/* Modal + admin forms */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff; border-radius: 10px; padding: 20px 22px;
  min-width: 420px; max-width: 95vw;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.modal h2 { margin: 0 0 16px; font-size: 16px; }
.modal .field { margin-bottom: 10px; }
.modal .field label { display: block; margin-bottom: 3px; font-size: 12px; color: var(--muted); }
.modal .field input, .modal .field select {
  width: 100%; padding: 6px 8px; box-sizing: border-box;
}
.modal .row { display: flex; gap: 10px; }
.modal .row .field { flex: 1; }
.modal .actions {
  display: flex; gap: 8px; margin-top: 16px;
  border-top: 1px solid var(--line); padding-top: 14px;
}
.modal .actions .spacer { flex: 1; }

.day-row {
  display: flex; align-items: stretch; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.day-row:last-child { border-bottom: none; }
.day-row:hover { background: #f6f8fa; }
.day-row-time {
  font-variant-numeric: tabular-nums; font-weight: 600;
  min-width: 54px; text-align: right; line-height: 1.3;
  padding-top: 2px;
}
.day-row-body { flex: 1; }
.day-row-title { font-weight: 600; }
.day-row-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.day-row-tag {
  display: inline-block; margin-top: 4px; font-size: 10px; padding: 1px 6px;
  border-radius: 3px; background: rgba(0,0,0,.06);
}
.day-row-tag.sem-paire { background: #fef3c7; color: #5c4300; }
.day-row-tag.sem-impaire { background: #fae8ff; color: #6b1a80; }
.day-row-edit {
  align-self: center; padding: 4px 10px; font-size: 12px;
}

.admin-card {
  background: #fff; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 16px; margin-bottom: 16px;
}
.admin-card h2 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }

.users-table {
  width: 100%; border-collapse: collapse;
  margin-bottom: 6px;
}
.users-table th, .users-table td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.users-table thead th {
  background: #f6f8fa; font-weight: 600;
  border-bottom: 1px solid var(--line-strong);
}
.users-table tbody tr:hover { background: #fafbfc; }
.users-table button { padding: 3px 8px; font-size: 12px; }
