:root {
  --bg: #f7f2eb;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --ink: #2b2118;
  --ink-2: #6f6052;
  --ink-3: #a39383;
  --line: #e9e0d5;
  --brand: #8a3b52;
  --brand-ink: #ffffff;
  --brand-soft: #f6e6eb;
  --ok: #2f7a4f;
  --ok-soft: #e3f2e8;
  --warn: #9a6200;
  --warn-soft: #fdf0d6;
  --bad: #b3372e;
  --bad-soft: #fbe4e1;
  --info: #2d5d8a;
  --info-soft: #e3eef8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 33, 24, .06), 0 4px 16px rgba(43, 33, 24, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- Mise en page ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 750; font-size: 18px; color: var(--brand); letter-spacing: -.01em; text-decoration: none; }
.brand small { color: var(--ink-3); font-weight: 500; font-size: 13px; margin-left: 6px; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; font: inherit; color: var(--ink-2); padding: 7px 12px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; position: relative;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tab .dot {
  display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px;
}
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
main.narrow { max-width: 640px; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }

/* ---------- Formulaires ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=number], textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; color: var(--ink); font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.code-input { font-size: 26px !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 10px; padding: 9px 16px; min-height: 40px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; padding: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.notice {
  border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px;
  background: var(--info-soft); color: var(--info);
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Grille du planning ---------- */
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.week-title { font-size: 18px; font-weight: 700; min-width: 220px; }
.grid-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
table.planning { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 980px; table-layout: fixed; }
.planning col.c-name { width: 150px; }
.planning col.c-total { width: 86px; }
.planning col.c-status { width: 170px; }
.planning th, .planning td { border-bottom: 1px solid var(--line); padding: 6px; vertical-align: middle; }
.planning thead th {
  font-size: 12px; font-weight: 600; color: var(--ink-2); text-align: center; padding: 10px 6px;
  background: var(--surface-2); position: sticky; top: 0;
}
.planning thead th.today { color: var(--brand); }
.planning thead th .dnum { display: block; font-size: 16px; color: var(--ink); font-weight: 700; }
.planning thead th.today .dnum { color: var(--brand); }
.planning th.name, .planning td.name { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 140px; }
.planning thead th.name { background: var(--surface-2); z-index: 2; }
.planning td.name .who { font-weight: 650; }
.planning td.name .contract { font-size: 12px; color: var(--ink-3); }
.planning tr:last-child td { border-bottom: 0; }

.cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 100%; min-height: 54px; border-radius: 10px; border: 1px dashed transparent;
  background: none; font: inherit; cursor: pointer; color: var(--ink); padding: 4px;
}
.cell:hover { border-color: var(--ink-3); background: var(--surface-2); }
.cell.empty { color: var(--ink-3); }
.cell.empty::after { content: "+"; font-size: 18px; }
.cell.shift { background: #fff6ef; border: 1px solid #f1dccb; }
.cell .hours { font-weight: 650; font-size: 13.5px; white-space: nowrap; }
.cell .worked { font-size: 11.5px; color: var(--ink-2); }
.cell .note-dot { font-size: 11px; color: var(--brand); }
.cell.code { font-weight: 650; font-size: 13px; }
.cell.code-RH { background: #f1efec; color: #6f6052; }
.cell.code-CP { background: #e3f2e8; color: #2f7a4f; }
.cell.code-ECOLE, .cell.code-STAGE { background: #e3eef8; color: #2d5d8a; }
.cell.code-ABS { background: #fdf0d6; color: #9a6200; }
.cell.code-IN { background: #fbe4e1; color: #b3372e; }
.cell.code-FERIE, .cell.code-FERME { background: #efe9f6; color: #5d4a86; }
td.total { text-align: center; font-weight: 700; white-space: nowrap; }
td.total .delta { display: block; font-size: 11.5px; font-weight: 500; color: var(--ink-3); }
td.status { text-align: center; min-width: 130px; }
td.status .badge { cursor: default; }
.status-sub { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

/* ---------- Boîte de dialogue ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 24px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink);
}
dialog::backdrop { background: rgba(43, 33, 24, .35); }
.dlg-head { padding: 18px 20px 6px; }
.dlg-body { padding: 8px 20px 4px; max-height: 70vh; overflow-y: auto; }
.dlg-foot { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.dlg-section { margin: 12px 0 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip:hover { border-color: var(--brand); }
.chip.selected { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 180px; }
.empty-state { color: var(--ink-3); text-align: center; padding: 18px 0; font-size: 14px; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.simple td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.simple tr:last-child td { border-bottom: 0; }
table.simple td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------- Connexion ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo .brand { font-size: 26px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--bad); }

/* ---------- Récap imprimable ---------- */
.recap h1 { margin-bottom: 4px; }
.recap .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; font-size: 14px; margin: 14px 0; }
.recap .hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; word-break: break-all; color: var(--ink-2); }
.print-only { display: none; }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-inner { gap: 8px; }
  .week-title { min-width: 0; width: 100%; order: -1; }
  .recap .meta { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
}

@media print {
  body { background: #fff; font-size: 12px; }
  .topbar, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  main { padding: 0; }
}
