:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1f2933; --muted: #6b7280; --line: #e2e5ea;
  --accent: #1d4ed8; --red: #dc2626; --red-bg: #fde8e8; --orange: #b45309; --orange-bg: #fef3c7;
  --green: #15803d; --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }

/* En-tête */
.top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 16px; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 7px 12px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: #e8eefc; color: var(--accent); }
.sync { margin-left: auto; color: var(--muted); font-size: 12px; }
#banner .apercu { background: #7c3aed; color: #fff; text-align: center; padding: 6px 16px; font-size: 13px; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.loading { color: var(--muted); }

/* Boutons et formulaires */
.btn { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 6px; color: var(--ink); }
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.danger.armed { background: var(--red); color: #fff; border-color: var(--red); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
input[type=text], input[type=date], input[type=month], input[type=number], input[type=password], select {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.msg { font-size: 13px; margin-top: 8px; }
.msg.err { color: var(--red); }
.msg.warn { color: var(--orange); }
.msg.ok { color: var(--green); }
.muted { color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t .rouge { color: var(--red); font-weight: 700; }
.tablewrap { overflow-x: auto; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; background: #eef0f3; color: var(--muted); }
.badge.demande { background: #e0e7ff; color: #3730a3; }
.badge.indispo { background: var(--orange-bg); color: var(--orange); }
.badge.conges { background: #dcfce7; color: var(--green); }
.badge.formation { background: #e0f2fe; color: #0369a1; }
.badge.alerte { background: var(--red-bg); color: var(--red); }

/* Planning */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .range { font-weight: 700; font-size: 15px; min-width: 210px; text-align: center; }
.toolbar .spacer { flex: 1; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 16px; align-items: start; }
.side { position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow-y: auto; }
@media (max-width: 1050px) { .layout { grid-template-columns: 1fr; } .side { position: static; max-height: none; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.legend .it { white-space: nowrap; }
.legend .mk { font-size: 12px; color: var(--muted); margin-top: 8px; }

.month { margin-bottom: 18px; }
.month h3 { font-size: 16px; margin: 0 0 6px; text-transform: capitalize; }
.month .hist { font-size: 11px; font-weight: 600; color: #7c3aed; background: #ede9fe; border-radius: 4px; padding: 1px 6px; margin-left: 8px; text-transform: none; vertical-align: middle; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.grid .dow { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; padding: 2px 0; }
.cell { background: #fff; border: 1px solid var(--line); border-radius: 6px; min-height: 64px; padding: 3px 4px; position: relative; overflow: hidden; }
.cell.vide { background: transparent; border-color: transparent; }
.cell.nocs { background: #fafbfc; }
.cell.past { background: #f7f7f8; }
.cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell .top2 { display: flex; justify-content: space-between; align-items: baseline; }
.cell .dn { font-size: 12px; font-weight: 600; color: #4b5563; }
.cell.nocs .dn { color: #b0b6bf; font-weight: 400; }
.cell .wk { font-size: 10px; color: #9aa1ab; }
.cell .top2 .r { display: inline-flex; align-items: center; gap: 3px; }
.cell .lock { border: 0; background: none; padding: 0 1px; font-size: 11px; line-height: 1; opacity: .3; cursor: pointer; }
.cell .lock.on { opacity: 1; }
.cell .lock:hover, .cell .lock:focus-visible { opacity: 1; }
.cell.ferie { background: repeating-linear-gradient(135deg, #eceef1 0 6px, #f8f9fa 6px 12px); }
.cell .fname { font-size: 11px; color: #4b5563; font-style: italic; margin-top: 4px; line-height: 1.2; }
.cell.cs { cursor: pointer; }
.cell.cs:hover { border-color: #9db2e6; }
.cs-pill { margin-top: 4px; border-radius: 5px; padding: 4px 5px; font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-pill .mk { font-weight: 400; margin-left: 3px; }
.cs-pill .court { display: none; }
@media (max-width: 600px) {
  .cs-pill { font-size: 11px; padding: 3px; }
  .cs-pill .long { display: none; }
  .cs-pill .court { display: inline; }
  .cell { min-height: 54px; padding: 2px 3px; }
}
.cell.uncov { background: var(--red-bg); border-color: #f5a3a3; }
.cell.uncov .cs-pill { color: var(--red); background: transparent; padding-left: 0; white-space: normal; }
.cell.nonrens .cs-pill { color: #9aa1ab; font-weight: 400; font-style: italic; background: transparent; border: 1px dashed #cfd4db; }
.cell.conflit { border: 2px solid var(--red); }
.cs-pill[draggable] { cursor: grab; }
.cell.drag-src { opacity: .5; }
.cell.drop-ok { outline: 2px dashed var(--green); outline-offset: -2px; background: #ecfdf3; }
.cell.drop-no { outline: 2px dashed var(--red); outline-offset: -2px; }
.cell .warn { position: absolute; right: 3px; bottom: 2px; font-size: 12px; color: var(--red); }

.alerts .al { border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; }
.al.rouge { background: var(--red-bg); color: #991b1b; }
.al.orange { background: var(--orange-bg); color: #92400e; }
.al.info { background: #eef2ff; color: #3730a3; }
.al .dates { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.al .dates button { border: 0; background: rgba(255,255,255,.7); border-radius: 4px; padding: 1px 6px; font-size: 12px; color: inherit; }
.ok-line { color: var(--green); font-size: 13px; }

/* Menu contextuel d'une CS */
.pop { position: absolute; z-index: 40; width: 320px; background: #fff; border: 1px solid #cdd3dc; border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.18); padding: 12px; }
.pop .ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pop .x { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); }
.pop select, .pop input { width: 100%; }
.pop .sect { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.pop .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.pop .pbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pop .pbtn { border: 2px solid transparent; border-radius: 7px; padding: 8px 6px; font-weight: 700; font-size: 13px; line-height: 1.2; text-align: center; }
.pop .pbtn small { display: block; font-weight: 400; font-size: 11px; opacity: .9; }
.pop .pbtn:hover { filter: brightness(.93); }
.pop .pbtn.actuel { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.pop .pbtn.indispo { opacity: .5; }
@media (max-width: 600px) {
  .pop { position: fixed; left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; border-radius: 14px 14px 0 0; max-height: 85vh; overflow-y: auto; }
}

/* Fenêtres modales */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 10px; padding: 18px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.checks label { display: flex; gap: 6px; align-items: center; text-transform: capitalize; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; font-size: 13px; }
.toast.err { background: var(--red); }

/* Paramètres */
.prat-row { display: grid; grid-template-columns: 1.4fr 70px 100px 1fr 1fr 70px 120px 230px; gap: 8px; align-items: end; padding: 8px 0; border-bottom: 1px solid var(--line); }
.prat-row input[type=color] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; }
.prat-row .acts { display: flex; gap: 6px; }
.prat-row .horsauto { display: flex; gap: 5px; align-items: center; font-size: 12px; line-height: 1.2; padding-bottom: 6px; }
@media (max-width: 800px) { .prat-row { grid-template-columns: 1fr 1fr; } .prat-row .acts { grid-column: 1 / -1; } }
.jours label { display: inline-flex; gap: 4px; align-items: center; margin-right: 12px; }
.list-simple { list-style: none; padding: 0; margin: 8px 0 0; }
.list-simple li { display: flex; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list-simple li .grow { flex: 1; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 800px) { .cols2 { grid-template-columns: 1fr; } }

/* Impression / export PDF : une page A4 portrait par mois */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ppage { page-break-after: always; break-after: page; }
  .ppage:last-child { page-break-after: auto; break-after: auto; }
  .ppage h1 { font-size: 18px; margin: 0 0 2px; }
  .ppage .meta { font-size: 11px; color: #555; margin-bottom: 8px; }
  .ppage .cell { min-height: 84px; }
  .ppage .cs-pill { font-size: 11px; }
  .ppage .legend { margin: 10px 0; }
  .ppage table.t { font-size: 11px; }
  .ppage table.t th, .ppage table.t td { padding: 3px 6px; }
}

.stats { max-width: 900px; }
.side table.t { font-size: 12px; }
.side table.t th, .side table.t td { padding: 5px 3px; }
.side table.t .chip { padding: 1px 6px; font-size: 11px; }
