:root {
  --blue: #1a73e8;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dfe5ef;
  --surface: #ffffff;
  --page: #f6f8fb;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 45px rgba(60, 64, 67, 0.08);
}

.brand {
  display: inline-flex;
  margin-bottom: 10px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 1080px;
  margin-bottom: 0;
  font-size: clamp(1.5rem, 3vw, 2.8rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.stat-card {
  min-height: 86px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-card strong {
  display: block;
  color: var(--blue);
  font-size: 1.8rem;
  line-height: 1;
}

.stat-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) minmax(220px, 320px);
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(116px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #edf2f7;
}

.segmented.source {
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  margin-bottom: 18px;
}

.segmented button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #3c4043;
  font-weight: 800;
}

.segmented button.active {
  background: var(--blue);
  color: #ffffff;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cfd8e6;
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
}

input {
  padding: 0 12px;
}

select {
  padding: 0 38px 0 12px;
}

.planner,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 45px rgba(60, 64, 67, 0.07);
}

.planner {
  overflow: hidden;
}

.planner-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.planner-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.grid-scroll {
  overflow-x: auto;
}

.calendar {
  display: grid;
  min-width: 1040px;
  grid-template-columns: 88px repeat(var(--cols, 6), minmax(150px, 1fr));
}

.corner,
.day-head,
.time {
  background: #f8fafc;
  color: #3c4043;
  font-weight: 900;
}

.corner,
.day-head {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 48px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

.day-head {
  text-transform: capitalize;
}

.corner,
.time {
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 1px solid var(--line);
}

.time {
  min-height: 104px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

.cell {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 104px;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

/* Bande de pause (déjeuner / récréation) — pleine largeur entre deux lignes */
.break-band {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 34px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: repeating-linear-gradient(
    45deg,
    #f1f5fb,
    #f1f5fb 10px,
    #e9eff8 10px,
    #e9eff8 20px
  );
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.01em;
}
.break-label {
  color: #34507a;
  font-size: 0.88rem;
}
.break-detail {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.course {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 86px;
  padding: 10px;
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 10%, white);
}

.course strong {
  font-size: 0.9rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.course span,
.course small {
  color: #3c4043;
  font-size: 0.78rem;
  line-height: 1.2;
}

.course small {
  color: var(--muted);
  font-weight: 800;
}

.notice {
  display: grid;
  gap: 8px;
  padding: 28px;
}

.notice strong {
  color: var(--blue);
  font-size: 1.2rem;
}

.notice span,
.loading {
  color: var(--muted);
}

.error strong {
  color: #b42318;
}

footer {
  padding: 22px 4px 4px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (max-width: 900px) {
  .shell {
    padding: 16px;
  }

  .header {
    padding: 20px;
  }

  .stats,
  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .segmented {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .stats,
  .toolbar,
  .segmented {
    grid-template-columns: 1fr;
  }

  .calendar {
    min-width: 860px;
    grid-template-columns: 78px repeat(var(--cols, 6), minmax(130px, 1fr));
  }
}

/* --- Assistant Sam (panneau chat) --- */
.assistant {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.assistant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.assistant-head strong { font-size: 15px; }
.thinking { color: var(--blue); font-size: 13px; }
.chat-log {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.chat-hint { color: var(--muted); font-size: 14px; margin: 4px 0; }
.msg { max-width: 88%; }
.msg .who { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.msg p { margin: 2px 0 0; padding: 9px 12px; border-radius: 12px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-end; text-align: right; }
.msg.user p { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.msg.agent p { background: #eef2f8; color: var(--ink); border-bottom-left-radius: 4px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.chat-form input:focus { border-color: var(--blue); }
.chat-form button {
  padding: 11px 18px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.chat-form button:disabled { opacity: 0.5; cursor: not-allowed; }
.toast {
  background: #e7f6ec;
  border: 1px solid #b6e3c4;
  color: #1b5e36;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
}

/* --- Bouton engrenage dans le header --- */
.gear-btn {
  align-self: flex-start;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}
.gear-btn:hover { border-color: var(--blue); color: var(--blue); }

/* --- Modale fiche profs --- */
.profs-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.profs-card {
  width: min(960px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.25);
  overflow: hidden;
}
.profs-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.profs-head h2 { margin: 0 0 4px; }
.profs-head p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.profs-head .profs-note { margin-top: 6px; font-size: 0.85rem; color: var(--muted); font-style: italic; }
.profs-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.profs-filters .field { flex: 1 1 180px; min-width: 160px; gap: 4px; }
.profs-filters input,
.profs-filters select { min-height: 36px; }
.profs-count {
  margin-left: auto;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.svc-niveau {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f8;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
}
.profs-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}
.profs-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.profs-error {
  background: #fdecec;
  border: 1px solid #f4b6b6;
  color: #b42318;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 14px;
}
.profs-list {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}
.prof-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 14px;
  display: grid;
  gap: 12px;
}
.prof-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto auto auto;
  align-items: end;
  gap: 12px;
}
.prof-row .field { margin: 0; }
.prof-row .checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  font-size: 0.88rem;
  color: var(--ink);
  white-space: nowrap;
}
.prof-row .checkbox input {
  width: auto;
  min-height: 0;
  margin: 0;
}
.svc-list {
  display: grid;
  gap: 8px;
}
.svc-row {
  display: grid;
  grid-template-columns: 70px minmax(90px, 1fr) minmax(180px, 1.6fr) 80px auto auto;
  align-items: center;
  gap: 8px;
}
.svc-row select,
.svc-row input {
  min-height: 38px;
}
.svc-unit { color: var(--muted); font-size: 0.85rem; }
.ghost-btn {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}
.ghost-btn:hover { border-color: var(--blue); color: var(--blue); }
.ghost-btn.small { padding: 6px 10px; font-size: 0.85rem; }
.ghost-btn.icon { padding: 6px 10px; }
.ghost-btn.danger { color: #b42318; border-color: #f4b6b6; }
.ghost-btn.danger:hover { background: #fdecec; }
.primary-btn {
  padding: 11px 18px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 800;
}
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 720px) {
  .prof-row {
    grid-template-columns: 1fr 1fr;
  }
  .prof-row .checkbox { grid-column: span 1; }
  .svc-row {
    grid-template-columns: 56px 1fr 1fr 70px auto;
  }
  .svc-row .svc-unit { display: none; }
  .profs-filters .field { flex-basis: 100%; }
  .profs-count { margin-left: 0; }
}

/* Boîte "Contraintes à arbitrer" — alerte décisionnelle en haut de page. */
.conflicts {
  margin: 12px 0;
  border: 1px solid #f0c36d;
  border-left: 4px solid #e8a200;
  border-radius: 8px;
  background: #fff8e8;
  padding: 16px 18px;
  box-shadow: 0 10px 30px rgba(232, 162, 0, 0.08);
}
.conflicts-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.conflicts-head strong {
  font-size: 1rem;
  color: #8a5a00;
}
.conflicts-head span {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.4;
}
.conflicts-list {
  display: grid;
  gap: 10px;
}
.conflict-item {
  border: 1px solid #f0d9a8;
  border-radius: 6px;
  background: var(--surface);
  padding: 12px 14px;
}
.conflict-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 6px;
}
.conflict-head strong {
  font-size: 0.95rem;
  color: var(--ink);
}
.conflict-slot {
  font-size: 0.8rem;
  color: var(--muted);
}
.conflict-reason {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--ink);
}
.conflict-options {
  font-size: 0.86rem;
  color: var(--muted);
}
.conflict-options > span {
  font-weight: 600;
  color: #8a5a00;
}
.conflict-options ul {
  margin: 4px 0 0;
  padding-left: 20px;
}
.conflict-options li {
  margin: 2px 0;
  line-height: 1.4;
}

/* Box "Contraintes structures sportives" — informative (sobre, bleutée). */
.sports {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #f3f7fd;
  padding: 14px 16px;
}
.sports-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.sports-head strong { font-size: 0.95rem; color: #1a4b8a; }
.sports-head span { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.sports-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}
.sport-item {
  display: grid;
  gap: 3px;
  border: 1px solid #d7e3f4;
  border-radius: 6px;
  background: var(--surface);
  padding: 9px 11px;
}
.sport-item strong { font-size: 0.86rem; color: var(--ink); }
.sport-detail { font-size: 0.8rem; color: #3c4043; line-height: 1.35; }
.sport-impact { font-size: 0.76rem; color: var(--muted); font-style: italic; }

/* --- Actions du header (boutons) --- */
.header-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

/* --- Impression : PDF A4 paysage --- */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  :root,
  body {
    background: #ffffff;
  }

  .shell {
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  /* Masquer tout ce qui est interactif / non pertinent à l'impression */
  .header-actions,
  .segmented.source,
  .toolbar,
  .assistant,
  .toast,
  .readonly-banner,
  .sports,
  footer {
    display: none !important;
  }

  /* En-tête allégé conservé comme bandeau de la feuille */
  .header {
    border: 0;
    border-bottom: 2px solid var(--blue);
    border-radius: 0;
    box-shadow: none;
    padding: 0 0 8px;
    margin-bottom: 10px;
  }
  .brand { margin-bottom: 4px; font-size: 9pt; }
  h1 { font-size: 16pt; line-height: 1.1; }

  /* Stats compactes */
  .stats { gap: 6px; margin: 8px 0; }
  .stat-card {
    min-height: 0;
    padding: 6px 10px;
    box-shadow: none;
  }
  .stat-card strong { font-size: 13pt; }
  .stat-card span { margin-top: 2px; font-size: 7pt; }

  /* Contraintes à arbitrer : gardées, compactes, non coupées */
  .conflicts {
    box-shadow: none;
    margin: 8px 0;
    padding: 10px 12px;
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Planning sur toute la largeur, sans défilement */
  .planner {
    box-shadow: none;
    overflow: visible;
    break-inside: avoid;
  }
  .planner-head { padding: 8px 10px; }
  .planner-head h2 { font-size: 12pt; }
  .planner-head p { font-size: 8pt; }

  .grid-scroll { overflow: visible !important; }
  .calendar {
    min-width: 0 !important;
    width: 100%;
    grid-template-columns: 52px repeat(var(--cols, 6), 1fr) !important;
  }

  /* Le sticky n'a pas de sens à l'impression */
  .corner,
  .day-head,
  .time {
    position: static !important;
  }
  .corner,
  .day-head {
    min-height: 0;
    padding: 5px 4px;
    font-size: 8pt;
  }
  .time {
    min-height: 0;
    padding: 5px 4px;
    font-size: 7.5pt;
  }
  .cell {
    min-height: 0;
    padding: 3px;
    gap: 3px;
  }

  /* Bande de pause conservée à l'impression, fond forcé, non coupée */
  .break-band {
    min-height: 0;
    padding: 2px 8px;
    gap: 8px;
    break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .break-label { font-size: 7.5pt; }
  .break-detail { font-size: 6.5pt; }

  /* Forcer les couleurs de fond (accents matières) à l'impression */
  .course {
    min-height: 0;
    padding: 4px 5px;
    gap: 2px;
    break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .course strong { font-size: 7.5pt; line-height: 1.1; }
  .course span { font-size: 6.5pt; line-height: 1.15; }
  .course small { font-size: 6pt; }
}

/* ── Barrettes de spé cliquables ───────────────────────────────── */
.course--barrette {
  cursor: pointer;
  transition: box-shadow 0.12s ease, transform 0.12s ease;
}
.course--barrette:hover,
.course--barrette:focus-visible {
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.barrette-hint {
  font-size: 0.7rem;
  opacity: 0.55;
  vertical-align: middle;
}

.barrette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.barrette-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.25);
  overflow: hidden;
}
.barrette-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.barrette-head h2 { margin: 0; font-size: 1.1rem; }
.barrette-x {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.barrette-x:hover { background: rgba(0, 0, 0, 0.06); }
.barrette-body { padding: 18px 20px; overflow-y: auto; }
.barrette-sub { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }
.barrette-spes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.barrette-spe {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 9%, white);
}
.barrette-spe strong { font-size: 0.95rem; }
.barrette-meta { color: #3c4043; font-size: 0.82rem; line-height: 1.3; }
.barrette-slots { margin-top: 16px; font-size: 0.82rem; color: var(--muted); }
.barrette-slots code {
  display: inline-block;
  margin: 2px 2px 0 0;
  padding: 1px 6px;
  border-radius: 5px;
  background: #eef2f7;
  color: #475569;
}

/* ── Accordéon (boîtes de contraintes repliables) ──────────────── */
.accordion-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}
.acc-title { display: flex; align-items: center; gap: 8px; }
.conflicts .acc-title strong { font-size: 1rem; color: #8a5a00; }
.sports .acc-title strong { font-size: 0.95rem; color: #1a4b8a; }
.acc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: #e8a200;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}
.sports .acc-badge { background: #1a4b8a; }
.acc-sub { margin-left: auto; font-size: 0.82rem; color: var(--muted); }
.acc-chevron { font-size: 0.8rem; color: var(--muted); width: 14px; text-align: center; }
.accordion.open .conflicts-list,
.accordion.open .sports-list { margin-top: 12px; }
@media (max-width: 640px) { .acc-sub { display: none; } }
