:root {
  color-scheme: light;
  --bg: #f6f5f2; --surface: #fcfcfb; --surface-2: #efeee9; --line: #dcdad3;
  --text: #0b0b0b; --text-2: #52514e; --muted: #77756f;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e3eefb;
  --danger: #c73534; --ok: #157a3a; --warn-bg: #fff4d6; --warn-ink: #6b4b00;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --line: #34342f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9b9a90;
    --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d2f47;
    --danger: #e66767; --ok: #4cc77a; --warn-bg: #3a3014; --warn-ink: #f3d68a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --line: #34342f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9b9a90;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d2f47;
  --danger: #e66767; --ok: #4cc77a; --warn-bg: #3a3014; --warn-ink: #f3d68a;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* En-tête */
.top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 4px 6px; width: auto; min-height: 34px; flex: none; }

/* Boutons */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; min-height: 40px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }

/* Cartes / formulaires */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card > p.muted { margin: 0 0 12px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
input[type=text], input[type=password], input[type=date], input[type=email], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input[type=color] { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: start; }
.banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }

/* Onglets */
.tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 65px; z-index: 19; overflow-x: auto; }
.tab { border: 0; background: none; padding: 12px 14px; border-bottom: 3px solid transparent; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* Tableaux */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
thead th { background: var(--surface-2); font-weight: 600; color: var(--text-2); white-space: nowrap; position: sticky; top: 0; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; color: var(--muted); font-size: 11px; }
th[aria-sort="ascending"]::after { content: " ↑"; color: var(--text); }
th[aria-sort="descending"]::after { content: " ↓"; color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.is-archived td { color: var(--muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 6px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

/* ================= Page de saisie ================= */
.fill .intro { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
.weeknav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.weeknav .label { flex: 1; text-align: center; font-weight: 650; }
.weeknav .total { font-size: 13px; color: var(--text-2); font-weight: 500; display: block; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); position: sticky; top: 58px; z-index: 10; }
.palette h2 { width: 100%; font-size: 13px; margin: 0; color: var(--text-2); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px 8px 8px; min-height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); touch-action: none; user-select: none; -webkit-user-select: none; font-weight: 550; }
.chip:hover { background: var(--surface-2); }
.chip .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.ghost-chip { position: fixed; z-index: 200; pointer-events: none; transform: translate(-50%, -50%) scale(1.05); box-shadow: 0 8px 24px rgba(0,0,0,.2); }

.daystrip { display: none; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.daytile { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 2px; text-align: center; min-height: 58px; display: grid; gap: 2px; align-content: center; }
.daytile .dn { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.daytile .dd { font-weight: 650; }
.daytile .dh { font-size: 11px; color: var(--text-2); min-height: 14px; }
.daytile[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.daytile.we .dd { color: var(--muted); }
.daytile.off { opacity: .4; }

.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 200px; display: flex; flex-direction: column; gap: 6px; transition: border-color .12s, background .12s; }
.day.we { background: var(--surface-2); }
.day.today .dh-date { color: var(--accent); }
.day.off { opacity: .45; }
.day.drop-ok, .daytile.drop-ok { border-color: var(--accent); background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -4px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; padding: 2px 2px 6px; border-bottom: 1px solid var(--line); }
.dh-date { font-weight: 650; font-size: 14px; }
.dh-total { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.dh-total.over { color: var(--danger); font-weight: 650; }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 12px; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 4px; }
.entry { display: grid; grid-template-columns: 4px 1fr; gap: 0 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.day.we .entry { background: var(--surface); }
.entry .bar { grid-row: span 2; border-radius: 4px; }
.entry .ename { font-size: 13px; font-weight: 550; background: none; border: 0; padding: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; line-height: 1; padding: 0; }
.stepper button:hover { background: var(--surface-2); }
.stepper .val { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.day-actions { margin-top: auto; }
.day-actions .btn { width: 100%; font-size: 12px; min-height: 32px; padding: 4px 8px; }
.savestate { font-size: 12px; color: var(--muted); min-width: 90px; text-align: right; }

/* Feuille de saisie d'heures */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 300; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 440px; border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
@media (min-width: 600px) { .sheet-bg { align-items: center; } .sheet { border-radius: 16px; } }
.sheet h3 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet .sub { margin: 2px 0 16px; color: var(--text-2); font-size: 14px; }
.big-stepper { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 8px 0 16px; }
.big-stepper button { width: 56px; height: 56px; border-radius: 50%; font-size: 26px; border: 1px solid var(--line); background: var(--surface-2); }
.big-stepper .val { font-size: 32px; font-weight: 700; min-width: 110px; text-align: center; font-variant-numeric: tabular-nums; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; }
.quick button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; min-height: 36px; font-variant-numeric: tabular-nums; }
.quick button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sheet .actions { display: flex; gap: 8px; }
.sheet .actions .btn { flex: 1; }

/* Mobile : un seul jour visible, choisi dans le bandeau */
@media (max-width: 899px) {
  .daystrip { display: grid; }
  .days { grid-template-columns: 1fr; }
  .day { display: none; min-height: 160px; }
  .day.selected { display: flex; }
  .day .day-head { display: none; }
  .entry { grid-template-columns: 4px 1fr auto; align-items: center; padding: 8px; }
  .entry .bar { grid-row: auto; align-self: stretch; }
  .entry .ename { font-size: 15px; }
  .stepper button { width: 40px; height: 40px; }
  .palette { top: 58px; }
}

/* ================= Admin ================= */
.login { max-width: 380px; margin: 10vh auto; }
.list { display: grid; gap: 6px; }
.list-item { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px; border: 1px solid var(--line); border-radius: 10px; }
.list-item.is-archived { opacity: .55; }
.list-item input[type=text] { flex: 1; min-width: 140px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface); }
.check input { width: 18px; height: 18px; }
.radio { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; }
.radio input { margin-top: 3px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .k { font-size: 13px; color: var(--text-2); }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 200px) 1fr; gap: 10px; align-items: center; }
.bar-label { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 26px; display: flex; align-items: center; gap: 8px; }
.bar-fill { height: 18px; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-val { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row:hover .bar-fill { filter: brightness(1.08); }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 150px; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.cardhead h2 { margin: 0; }
td.masked { color: var(--muted); font-style: italic; }
@media (max-width: 599px) {
  .tabs { top: 61px; }
  .bar-row { grid-template-columns: 1fr; gap: 2px; }
}
