:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #e2e4e9;
  --border-strong: #cdd1d8;
  --text: #16181d;
  --text-2: #3d424c;
  --muted: #6b717c;
  --primary: #1f2937;
  --primary-hover: #111827;
  --accent: #2f5d8a;
  --accent-soft: #eef3f8;
  --done: #2f7a55;
  --done-soft: #edf6f1;
  --danger: #b4383a;
  --danger-soft: #fbefef;
  --warning: #93620b;
  --warning-soft: #fbf5e8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 1rem; }
h3 { font-size: .95rem; }
.loading { text-align: center; color: var(--muted); padding: 4rem 1rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }
.count { color: var(--muted); font-weight: 500; margin-left: .3rem; }

.ico { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -3px; }
.ico.big { width: 32px; height: 32px; color: var(--border-strong); margin-bottom: .5rem; }

/* ---------- Boutons & champs ---------- */
button {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: .45rem .85rem;
  cursor: pointer;
  min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #e9c3c3; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text); }
.btn-ghost.btn-danger { color: var(--muted); }
.btn-ghost.btn-danger:hover { color: var(--danger); background: var(--danger-soft); }
.btn-sm { min-height: 30px; padding: .25rem .6rem; font-size: .84rem; }
.btn-icon { min-height: 34px; min-width: 34px; padding: 0; }

label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-2); margin-bottom: .3rem; }
input, select, textarea {
  font: inherit;
  font-size: .92rem;
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 93, 138, .15);
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { margin-bottom: .9rem; }
.grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid .field { margin-bottom: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: .85rem; min-height: 1.2em; margin: .4rem 0 0; }

/* ---------- Connexion ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem 1.75rem;
  box-shadow: 0 4px 24px rgba(16, 24, 40, .06);
}
.auth-card .logo { width: 40px; height: 40px; display: block; margin-bottom: 1.25rem; }
.auth-card h1 { font-size: 1.25rem; }
.auth-card p.sub { color: var(--muted); margin: .3rem 0 1.5rem; font-size: .9rem; }
.auth-card button[type=submit] { width: 100%; margin-top: .3rem; min-height: 40px; }

/* ---------- En-tête & navigation ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.top-bar {
  max-width: 1100px; margin: 0 auto;
  padding: .6rem 1rem;
  display: flex; align-items: center; gap: .7rem;
}
.top-bar img { width: 28px; height: 28px; }
.top-bar .title { font-weight: 600; font-size: .98rem; }
.top-bar .who { font-size: .8rem; color: var(--muted); }

.tabs {
  max-width: 1100px; margin: 0 auto;
  display: flex; gap: 0; overflow-x: auto; padding: 0 .5rem;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: none; border-radius: 0; background: transparent; white-space: nowrap;
  color: var(--muted); font-weight: 500; padding: .65rem .8rem; min-height: 0;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); background: transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }

/* ---------- Bandeau d'information ---------- */
.banner {
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: 1.25rem;
  display: flex; gap: .7rem; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  white-space: pre-wrap;
  word-break: break-word;
}
.banner-icon { color: var(--accent); padding-top: 1px; }
.banner .text { flex: 1; color: var(--text); font-size: .92rem; }
.banner .meta { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.banner .btn-icon { min-height: 28px; min-width: 28px; margin: -.2rem -.3rem -.2rem 0; }
.banner.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.banner.warning .banner-icon { color: var(--warning); }
.banner.danger { border-left-color: var(--danger); background: var(--danger-soft); }
.banner.danger .banner-icon { color: var(--danger); }
.banner.success { border-left-color: var(--done); }
.banner.success .banner-icon { color: var(--done); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.card > h2 { margin-bottom: 1rem; }
.card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
details.card > summary {
  cursor: pointer; font-weight: 600; font-size: .95rem; list-style: none;
  display: flex; align-items: center; gap: .5rem;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: ''; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; margin-right: .2rem;
}
details.card[open] > summary::before { transform: rotate(45deg); }
details.card[open] > summary { margin-bottom: 1rem; }

/* ---------- Date ---------- */
.datebar { display: flex; align-items: center; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.datebar .date-label { font-weight: 600; font-size: 1.15rem; flex: 1; min-width: 200px; letter-spacing: -.01em; }
.datebar input[type=date] { width: auto; }

/* ---------- Progression ---------- */
.progress { height: 6px; background: #eceef1; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--done); border-radius: 99px; transition: width .3s; }
.progress-label { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); margin-bottom: .45rem; }
.progress-label span:last-child { color: var(--text-2); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- Tâches ---------- */
.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin-bottom: .6rem;
  position: relative;
}
.task::before {
  content: ''; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 3px;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--border-strong);
}
.task.done::before { background: var(--done); }
.task.done .task-title { color: var(--muted); }
.task-main { display: flex; gap: 1rem; align-items: flex-start; }
.task-body { flex: 1; min-width: 0; }
.task-time { display: flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; margin-bottom: .1rem; }
.task-time .ico { width: 13px; height: 13px; color: var(--muted); }
.task-title { font-weight: 600; font-size: 1rem; word-break: break-word; }
.task-details { margin-top: .35rem; white-space: pre-wrap; word-break: break-word; color: var(--text-2); font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .45rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 4px; padding: .1rem .45rem;
}
.chip b { color: var(--muted); font-weight: 500; }
.chip .ico { width: 12px; height: 12px; }
.chip.fixed { background: var(--accent-soft); border-color: #d6e2ee; color: var(--accent); }
.btn-done {
  flex-shrink: 0;
  min-width: 130px; min-height: 40px;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-done:hover { border-color: var(--done); color: var(--done); background: var(--done-soft); }
.task.done .btn-done { background: var(--done-soft); color: var(--done); border-color: #bcdccb; }
.done-info { display: flex; align-items: center; gap: .3rem; font-size: .78rem; color: var(--done); margin-top: .4rem; font-weight: 500; }
.done-info .ico { width: 13px; height: 13px; }
.comment-box { margin-top: .7rem; }
.comment-view {
  margin-top: .55rem; padding: .5rem .7rem; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; font-size: .88rem; color: var(--text-2); white-space: pre-wrap; word-break: break-word;
}
.task-actions { display: flex; gap: .25rem; margin-top: .55rem; flex-wrap: wrap; margin-left: -.5rem; }
.task-actions:empty { display: none; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; font-size: .9rem; }

/* Avancement de l'équipe */
.emp-tiles { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin-top: 1rem; }
.emp-tile {
  display: block; text-align: left; width: 100%; min-height: 0; padding: .8rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.emp-tile:hover { border-color: var(--border-strong); background: var(--surface); }
.emp-tile.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.emp-tile-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.emp-name { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-tile-nums { display: flex; align-items: baseline; gap: .5rem; margin: .35rem 0 .5rem; font-size: .8rem; flex-wrap: wrap; }
.emp-tile-nums .pct { font-size: 1.35rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.status { font-size: .7rem; font-weight: 600; border-radius: 4px; padding: .08rem .4rem; white-space: nowrap; border: 1px solid var(--border); color: var(--muted); }
.status.ok { background: var(--done-soft); color: var(--done); border-color: #cfe5d8; }
.status.progress { background: var(--accent-soft); color: var(--accent); border-color: #d6e2ee; }
.status.todo { background: var(--warning-soft); color: var(--warning); border-color: #eedfbf; }

/* Saisie rapide */
.planned { display: inline-block; font-size: .76rem; font-weight: 500; background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: .05rem .4rem; margin: 0 .2rem .25rem 0; }
.planned.done { background: var(--done-soft); color: var(--done); }
table.matrix td select { min-width: 92px; }
table.matrix th { white-space: nowrap; }

/* Groupes par employé */
.emp-group { margin-bottom: 1.5rem; }
.emp-group:last-child { margin-bottom: 0; }
.emp-group-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.emp-group-head .progress { flex: 1; max-width: 200px; }
.badge {
  font-size: .72rem; font-weight: 600; border-radius: 4px; padding: .1rem .45rem;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.badge.ok { background: var(--done-soft); color: var(--done); border-color: #cfe5d8; }
.badge.admin { background: var(--accent-soft); color: var(--accent); border-color: #d6e2ee; }
.badge.off { color: var(--muted); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
th { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td select, td input { min-height: 32px; padding: .25rem .45rem; font-size: .86rem; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { min-height: 30px; min-width: 30px; padding: 0 .45rem; }

/* Listes */
.lists-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.list-item { display: flex; align-items: center; justify-content: space-between; padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.list-item button { min-height: 28px; min-width: 28px; padding: 0; }

.ridden-toggle {
  display: inline-flex; align-items: center; gap: .3rem; margin: 0; cursor: pointer;
  font-size: .78rem; font-weight: 500; color: var(--muted); user-select: none;
}
.ridden-toggle input { width: 15px; height: 15px; min-height: 0; margin: 0; accent-color: var(--primary); }
.badge.ridden { background: var(--warning-soft); color: var(--warning); border-color: #eedfbf; }
tr.row-ridden td:first-child b { color: var(--text-2); }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .86rem; }

/* Jours de la semaine */
.days { display: flex; gap: .3rem; flex-wrap: wrap; }
.days label {
  margin: 0; display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; min-height: 34px; border: 1px solid var(--border-strong); border-radius: 6px;
  cursor: pointer; color: var(--text-2); font-weight: 500; user-select: none; font-size: .85rem;
}
.days input { display: none; }
.days label:has(input:checked) { background: var(--primary); color: #fff; border-color: var(--primary); }

.color-choices { display: flex; gap: .4rem; flex-wrap: wrap; }
.color-choices label {
  margin: 0; display: inline-flex; gap: .45rem; align-items: center; padding: .4rem .75rem;
  border-radius: 6px; cursor: pointer; border: 1px solid var(--border-strong); font-weight: 500; color: var(--text-2);
}
.color-choices label::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.color-choices input { display: none; }
.color-choices label:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); color: var(--text); }
.color-choices .warning::before { background: var(--warning); }
.color-choices .danger::before { background: var(--danger); }
.color-choices .success::before { background: var(--done); }

/* ---------- Modale ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 10px; padding: 1.4rem; width: min(520px, calc(100vw - 2rem));
  box-shadow: 0 20px 50px rgba(16, 24, 40, .18); color: var(--text);
}
dialog::backdrop { background: rgba(16, 24, 40, .4); }
dialog h2 { margin-bottom: 1.1rem; font-size: 1.05rem; }

/* ---------- Notification ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(150%); opacity: 0;
  background: var(--primary); color: #fff; padding: .6rem 1rem; border-radius: 6px; z-index: 100; font-size: .88rem;
  transition: transform .2s, opacity .2s; max-width: calc(100vw - 2rem); box-shadow: 0 8px 24px rgba(16, 24, 40, .2);
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.err { background: var(--danger); }

/* Encart « Installez l'appli » */
.install-hint {
  display: flex; gap: .8rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.auth-wrap .install-hint { width: 100%; max-width: 360px; margin: 1rem 0 0; }
.install-hint > img { width: 40px; height: 40px; border-radius: 9px; flex-shrink: 0; }
.install-body { flex: 1; min-width: 0; font-size: .88rem; color: var(--text-2); }
.install-title { font-weight: 600; color: var(--text); margin-bottom: .35rem; }
.install-body ol { margin: 0; padding-left: 1.1rem; }
.install-body li { margin-bottom: .15rem; }
.install-body li .ico { margin: 0 .2rem; color: var(--accent); }
.install-body .btn-primary { margin-top: .2rem; }
.install-hint .btn-icon { min-height: 30px; min-width: 30px; margin: -.3rem -.4rem 0 0; }
.auth-wrap { grid-auto-flow: row; align-content: center; justify-items: center; }

/* ---------- Appli mobile ---------- */
html { -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior-y: none; }
.bottom-nav { display: none; }

/* Feuille « Plus » (menu du bas) */
dialog.sheet {
  margin: auto 0 0; width: 100%; max-width: 100%; border: none; border-radius: 14px 14px 0 0;
  padding: .5rem .75rem calc(1rem + env(safe-area-inset-bottom));
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet-handle { width: 36px; height: 4px; border-radius: 99px; background: var(--border-strong); margin: .2rem auto .7rem; }
.sheet-item {
  width: 100%; justify-content: flex-start; gap: .8rem; border: none; border-radius: 8px;
  min-height: 50px; font-size: 1rem; padding: 0 .8rem; background: transparent;
}
.sheet-item .ico { width: 20px; height: 20px; color: var(--muted); }
.sheet-item.active { background: var(--accent-soft); color: var(--accent); }
.sheet-item.active .ico { color: var(--accent); }
.sheet-item.btn-danger .ico { color: var(--danger); }

@media (max-width: 600px) {
  main { padding: 1rem .75rem 2rem; }
  .top-bar .who, .hide-sm { display: none; }
  .task-main { flex-direction: column; gap: .7rem; }
  .btn-done { width: 100%; min-height: 48px; font-size: 1rem; }
  .card { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .datebar .date-label { font-size: 1.05rem; min-width: 0; order: -1; flex-basis: 100%; }
  .datebar input[type=date] { flex: 1; }

  /* Champs à 16px : évite le zoom automatique de l'iPhone */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  td select, td input { font-size: 16px; min-height: 40px; }
  button { min-height: 42px; }
  .btn-sm { min-height: 38px; }
  .task-actions button { min-height: 40px; }

  /* Barre d'onglets en bas, comme une appli */
  body.has-bottom-nav .tabs { display: none; }
  body.has-bottom-nav main { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
  body.has-bottom-nav #toast { bottom: calc(4.8rem + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav button {
    flex: 1; flex-direction: column; gap: .15rem; border: none; border-radius: 0; background: transparent;
    min-height: 58px; padding: .4rem 0; font-size: .7rem; font-weight: 500; color: var(--muted);
  }
  .bottom-nav button:hover { background: transparent; }
  .bottom-nav .ico { width: 22px; height: 22px; }
  .bottom-nav button.active { color: var(--primary); font-weight: 600; }
  .bottom-nav button.active .ico { stroke-width: 2.2; }

  /* Tableaux transformés en fiches */
  .table-wrap:has(table.stack) { margin: 0; padding: 0; overflow: visible; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .8rem; margin-bottom: .6rem; }
  table.stack tbody tr:hover { background: transparent; }
  table.stack td { border: none; padding: .2rem 0; text-align: left; }
  table.stack td:empty { display: none; }
  table.stack td[data-label] { display: flex; gap: .6rem; align-items: center; }
  table.stack td[data-label]::before { content: attr(data-label); flex: 0 0 6.5rem; font-size: .78rem; color: var(--muted); }
  table.stack td.stack-title { font-size: 1rem; padding-bottom: .35rem; }
  table.stack td.actions { text-align: left; border-top: 1px solid var(--border); margin-top: .45rem; padding-top: .5rem; display: flex; gap: .3rem; flex-wrap: wrap; }
  table.stack td.actions button { min-height: 40px; min-width: 40px; }
}

/* Appli installée : pas de sélection de texte accidentelle sur les boutons */
@media (display-mode: standalone) {
  button, .bottom-nav, .tabs { -webkit-user-select: none; user-select: none; }
}
