:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --accent: #1d4ed8; --accent-soft: #e0e7ff; --accent-text: #ffffff;
  --t1: #0e7490; --t1-soft: #cffafe; --t2: #7c3aed; --t2-soft: #ede9fe;
  --green: #15803d; --green-soft: #dcfce7; --red: #b91c1c; --red-soft: #fee2e2;
  --rentree: #4338ca; --rentree-soft: #e0e7ff; --sable: #b45309; --sable-soft: #fef3c7;
  --garde: #0369a1; --garde-soft: #e0f2fe; --warn: #b45309;
  --now: #fff7ed; --now-border: #fb923c; --past: .42;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 10px; --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --border-strong: #334155;
    --text: #e5e7eb; --muted: #94a3b8; --faint: #64748b;
    --accent: #60a5fa; --accent-soft: #1e293b; --accent-text: #0b1120;
    --t1: #22d3ee; --t1-soft: #083344; --t2: #a78bfa; --t2-soft: #2e1065;
    --green: #4ade80; --green-soft: #052e16; --red: #f87171; --red-soft: #450a0a;
    --rentree: #a5b4fc; --rentree-soft: #1e1b4b; --sable: #fbbf24; --sable-soft: #422006;
    --garde: #7dd3fc; --garde-soft: #082f49; --warn: #fbbf24;
    --now: #1c1917; --now-border: #f97316; --past: .38;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --border-strong: #334155;
  --text: #e5e7eb; --muted: #94a3b8; --faint: #64748b;
  --accent: #60a5fa; --accent-soft: #1e293b; --accent-text: #0b1120;
  --t1: #22d3ee; --t1-soft: #083344; --t2: #a78bfa; --t2-soft: #2e1065;
  --green: #4ade80; --green-soft: #052e16; --red: #f87171; --red-soft: #450a0a;
  --rentree: #a5b4fc; --rentree-soft: #1e1b4b; --sable: #fbbf24; --sable-soft: #422006;
  --garde: #7dd3fc; --garde-soft: #082f49; --warn: #fbbf24;
  --now: #1c1917; --now-border: #f97316; --past: .38;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.tnum { font-variant-numeric: tabular-nums; font-family: var(--mono); letter-spacing: -.01em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- En-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.clock { font-size: 26px; font-weight: 700; }
.clock small { font-size: 15px; color: var(--muted); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.lg { height: 42px; padding: 0 18px; font-size: 14px; }
.btn svg { width: 16px; height: 16px; }

/* ---------- Barre de date ---------- */
.daybar { display: flex; align-items: center; gap: 10px; padding: 12px 20px 0; flex-wrap: wrap; }
.daybar .date-label { font-size: 16px; font-weight: 650; text-transform: capitalize; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; border: 1px solid var(--border); background: var(--surface); white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.scn-bleu .dot { background: #2563eb; } .scn-rose .dot { background: #db2777; } .scn-gris .dot { background: #6b7280; }
.scn-vert .dot { background: #16a34a; } .scn-orange .dot { background: #ea580c; } .scn-violet .dot { background: #7c3aed; }

/* ---------- Mise en page ---------- */
main { padding: 12px 20px 24px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.board { display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 12px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.card-title { font-weight: 700; font-size: 14px; }
.card-count { font-size: 12px; color: var(--muted); }
.card-body { padding: 14px; }
.scroll { overflow: auto; }
.board .main-card .scroll { max-height: calc(100vh - 250px); }
.side .scroll { max-height: calc((100vh - 330px) / 2); }

/* ---------- Tableaux ---------- */
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tr.past td { opacity: var(--past); }
.grid tr.now td { background: var(--now); }
.grid tr.now td:first-child { box-shadow: inset 3px 0 0 var(--now-border); }
.grid tr.cont td.c-releve, .grid tr.cont td.c-svc { color: var(--faint); }
.grid td.num { text-align: right; }
.c-releve { font-weight: 700; }
.c-svc { font-weight: 650; }
.st { font-size: 10px; font-weight: 700; color: var(--muted); margin-left: 4px; letter-spacing: .03em; }
.name { font-weight: 650; }
.name .first { font-weight: 500; }
.name.vac-first { color: var(--green); }
.name.vac-last { color: var(--red); }
.name.vac-only { color: var(--green); }
.name.missing { color: var(--faint); font-style: italic; font-weight: 400; }
.vac-tag { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; }
.vac-tag.f { background: var(--green-soft); color: var(--green); }
.vac-tag.l { background: var(--red-soft); color: var(--red); }

.line { display: inline-grid; place-items: center; width: 28px; height: 20px; border-radius: 5px; font-weight: 800; font-size: 11px; }
.line.T1 { background: var(--t1-soft); color: var(--t1); }
.line.T2 { background: var(--t2-soft); color: var(--t2); }
.circ { font-weight: 650; }
.rame { font-family: var(--mono); font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); }
.rame.empty { color: var(--faint); border-style: dashed; font-weight: 500; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.pill.rentree { background: var(--rentree-soft); color: var(--rentree); }
.pill.sable { background: var(--sable-soft); color: var(--sable); }
.pill.garde { background: var(--garde-soft); color: var(--garde); }
.pill.jv { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--sable-soft); color: var(--warn); }
.retour-cdm { color: var(--rentree); font-weight: 800; }
.term { color: var(--muted); }
.term b { color: var(--text); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 10px; font-size: 12px; font-weight: 650; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.input, select.input, textarea.input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); min-width: 0;
}
textarea.input { height: auto; padding: 10px; font-family: var(--mono); font-size: 12px; resize: vertical; width: 100%; }
.input:focus, textarea.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.sm { height: 28px; padding: 0 6px; font-size: 12px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state h3 { color: var(--text); margin: 0 0 6px; }

/* ---------- Pages Feuille / Admin ---------- */
.page { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 800; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.form-row > label { font-size: 12px; font-weight: 650; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.days-pick { display: flex; gap: 4px; }
.days-pick label { display: grid; place-items: center; width: 38px; height: 32px; border: 1px solid var(--border-strong); border-radius: 7px; cursor: pointer; font-size: 12px; font-weight: 700; color: var(--muted); }
.days-pick input { display: none; }
.days-pick label:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.scn-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.scn-card { border-left: 4px solid var(--border-strong); }
.scn-card.c-bleu { border-left-color: #2563eb; } .scn-card.c-rose { border-left-color: #db2777; } .scn-card.c-gris { border-left-color: #6b7280; }
.scn-card.c-vert { border-left-color: #16a34a; } .scn-card.c-orange { border-left-color: #ea580c; } .scn-card.c-violet { border-left-color: #7c3aed; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.admin-hero { display: flex; align-items: center; gap: 16px; padding: 18px; }
.admin-hero .big { font-size: 15px; font-weight: 700; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.notice.warn { background: var(--sable-soft); border-color: transparent; color: var(--warn); }
.notice.ok { background: var(--green-soft); border-color: transparent; color: var(--green); }
.savebar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sable); }
.rame-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.rame-tile { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 7px; font-size: 12px; }
.rame-tile.off { background: var(--red-soft); border-color: transparent; }
.rame-tile .rame { border: 0; padding: 0; }

/* ---------- Modale / toasts ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(2, 6, 23, .55); backdrop-filter: blur(6px); padding: 16px; }
.modal { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 760px; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 4px; font-size: 19px; }
.modal p { margin: 0 0 18px; color: var(--muted); }
.pin-boxes { display: flex; gap: 10px; justify-content: center; margin: 8px 0 14px; }
.pin-boxes input { width: 54px; height: 62px; text-align: center; font-size: 26px; font-weight: 700; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface-2); }
.pin-boxes input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pin-error { color: var(--red); text-align: center; min-height: 20px; font-size: 13px; font-weight: 600; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--red); color: #fff; }

@media (max-width: 1280px) {
  .board { grid-template-columns: 1fr; }
  .side .scroll { max-height: 420px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-sub { display: none; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .nav { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  main, .daybar { padding-left: 16px; padding-right: 16px; }
  .cols-2 { grid-template-columns: 1fr; }
  .clock { font-size: 20px; }
}

/* ---------- Impression A4 portrait ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 9mm 8mm; }
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000; font-size: 8.5pt; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  .p-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 1.5pt solid #000; padding-bottom: 3pt; margin-bottom: 5pt; }
  .p-head h1 { font-size: 13pt; margin: 0; }
  .p-head div { font-size: 8.5pt; text-align: right; }
  .p-section { break-before: page; }
  .p-section:first-of-type { break-before: auto; }
  .p-section h2 { font-size: 10.5pt; margin: 4pt 0; }
  table.p { width: 100%; border-collapse: collapse; }
  table.p thead { display: table-header-group; }
  table.p th { background: #e5e7eb !important; font-size: 7.5pt; text-transform: uppercase; text-align: left; padding: 2.5pt 3pt; border: .5pt solid #9ca3af; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.p td { padding: 2pt 3pt; border: .5pt solid #cbd5e1; white-space: nowrap; }
  table.p tr { break-inside: avoid; }
  table.p tr.seg-start td { border-top: 1pt solid #475569; }
  .p .vac-first { color: #15803d !important; font-weight: 700; }
  .p .vac-last { color: #b91c1c !important; font-weight: 700; }
  .p .retour-cdm { color: #4338ca !important; font-weight: 800; }
  .p .sable { font-weight: 800; color: #b45309 !important; }
  .p * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-legend { margin-top: 4pt; font-size: 7.5pt; color: #374151; }
}
