:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --line: rgba(60, 60, 67, .14);
  --fill: rgba(118, 118, 128, .12);
  --accent: #111111;
  --on-accent: #ffffff;
  --accent-soft: rgba(17, 17, 17, .08);
  --green: #1f9d55;
  --red: #d62d20;
  --tabbar: rgba(249, 249, 249, .88);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --accent: #ffffff;
    --on-accent: #000000;
    --accent-soft: rgba(255, 255, 255, .14);
    --green: #32d74b;
    --red: #ff453a;
    --tabbar: rgba(22, 22, 24, .88);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
body.no-tabs { padding-bottom: env(safe-area-inset-bottom); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
.marque { font-family: Futura, "Avenir Next", sans-serif; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 14px 4px 0; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 2px 4px 14px; overflow-wrap: anywhere; }
h2 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin: 26px 16px 7px; letter-spacing: .02em; }
.logo-compte { display: block; height: 44px; max-width: 70%; object-fit: contain; object-position: left; margin: 12px 4px 4px; }
.foot { font-size: 13px; color: var(--muted); margin: 7px 16px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin: 0 -4px; }
.topbar a, .topbar button { color: var(--accent); text-decoration: none; background: none; border: 0; padding: 10px 4px; font-size: 17px; }

/* Groupes façon Réglages iOS */
.group { background: var(--card); border-radius: 12px; overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 16px;
  position: relative; text-decoration: none; color: inherit; width: 100%; background: none; border: 0; text-align: left;
}
.row + .row::before, .field + .field::before, .field + .row::before, .row + .field::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line);
}
.row .grow { flex: 1; min-width: 0; }
.row .grow b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 14px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .val { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.row .val small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.row.chev::after { content: ""; width: 8px; height: 8px; border: solid #c4c4c7; border-width: 2px 2px 0 0; transform: rotate(45deg); margin-left: 4px; flex: none; }
a.row:active, button.row:active { background: var(--fill); }
.row.danger { color: var(--red); justify-content: center; }
.row.action { color: var(--accent); justify-content: center; font-weight: 500; }

/* Formulaires */
.field { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 16px; position: relative; }
.field label { width: 84px; flex: none; }
#fm .field label { width: 118px; }
.field input, .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 8px 0; text-align: right; font-size: 17px;
  -webkit-appearance: none; appearance: none;
}
.field select { direction: rtl; text-overflow: ellipsis; }
.field input[type=date] { min-height: 34px; display: flex; justify-content: flex-end; }
.field input::-webkit-date-and-time-value { text-align: right; }
.field textarea { text-align: left; resize: none; padding: 10px 0; }

/* Étapes de la journée */
.etape { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 12px 8px 16px; position: relative; }
.etape + .etape::before, .etape + .pauses::before, .pauses + .etape::before { content: ""; position: absolute; top: 0; left: 44px; right: 0; border-top: .5px solid var(--line); }
.etape .pt { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #c4c4c7; flex: none; margin-right: 6px; }
.etape.fait .pt { background: var(--accent); border-color: var(--accent); }
.etape .grow { flex: 1; min-width: 0; }
.etape .lbl { font-weight: 500; }
.etape .hint { font-size: 13px; color: var(--muted); min-height: 0; }
input[type=time] {
  border: 0; background: var(--fill); border-radius: 8px; padding: 7px 8px; font-size: 17px; font-weight: 600; min-width: 88px; min-height: 38px;
  text-align: center; font-variant-numeric: tabular-nums; outline: none; -webkit-appearance: none; appearance: none;
}
input[type=time]::-webkit-date-and-time-value { text-align: center; }
.now { border: 0; background: var(--text); color: var(--bg); border-radius: 8px; padding: 0 11px; height: 38px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; flex: none; }
.now:active { opacity: .7; }
.pauses { padding: 10px 12px 12px 44px; position: relative; }
.pauses .lbl { font-weight: 500; margin-bottom: 6px; display: flex; justify-content: space-between; }
.pauses .lbl span { color: var(--muted); font-weight: 400; font-size: 14px; }
.pause { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pause .a { color: var(--muted); font-size: 14px; }
.pause .x { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 8px; margin-left: auto; }
.mini-btn { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; }

/* Totaux */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: 14px; padding: 14px 6px; text-align: center; }
.stats.q { grid-template-columns: repeat(4, 1fr); }
.stats.q b { font-size: 18px; }
.stats.q span { font-size: 10px; }
.stats b { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stats span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 15px; font-size: 17px; font-weight: 600;
  background: var(--accent); color: var(--on-accent); margin-top: 22px; text-align: center; text-decoration: none;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .4; }
.btn.ghost { background: var(--card); color: var(--accent); margin-top: 10px; }
.btn.contour { background: none; color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.btn.noir { background: var(--text); color: var(--bg); }
.duo { display: flex; gap: 10px; margin-top: 12px; }
.duo .btn { margin-top: 0; }

.empty { text-align: center; color: var(--muted); padding: 36px 20px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--fill); color: var(--muted); }

.filtre { width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 13px 16px; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none; }

/* Écran connexion */
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; max-width: 380px; margin: 0 auto; padding: 24px; text-align: center; }
.login .logo { width: 132px; height: 132px; margin: 0 auto 18px; color: var(--text); display: block; }
.login h1 { margin: 0; font-family: Futura, "Avenir Next", sans-serif; font-size: 25px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.login .metiers { font-family: Futura, "Avenir Next", sans-serif; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text); margin: 6px 0 30px; }
.login p { color: var(--muted); margin: 0 0 12px; }
.login input { width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 15px; text-align: center; font-size: 18px; outline: none; }
.login input + input { margin-top: 10px; }
.err { color: var(--red); font-size: 15px; margin-top: 12px; min-height: 20px; }

/* Barre d'onglets */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around; align-items: flex-start;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 10px; font-weight: 500; padding-top: 2px; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 15px; max-width: 90vw; text-align: center;
}

/* Feuilles (confirmation, nouveau contrat) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30; display: flex; align-items: flex-end; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.sheet .group { border-radius: 14px; margin-bottom: 8px; }
.sheet .msg { text-align: center; color: var(--muted); font-size: 13px; padding: 14px 16px; }
.sheet .msg b { display: block; color: var(--text); font-size: 17px; margin-bottom: 2px; }
.sheet .row { justify-content: center; font-size: 20px; color: var(--accent); min-height: 56px; }
.sheet .row.cancel { font-weight: 600; }
.sheet .row.destroy { color: var(--red); }
.sheet .field input { text-align: left; }
.sheet .field label { width: 118px; }
.avis { white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet.haut { align-self: flex-start; padding-top: calc(12px + env(safe-area-inset-top)); }
@media (prefers-color-scheme: dark) { .logo-compte { background: #fff; padding: 5px 8px; border-radius: 8px; height: 54px; } }

/* Choix à deux options (point de départ) */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; flex: none; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font-size: 14px; font-weight: 500; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
h2 .badge { text-transform: none; margin-left: 6px; }

/* Sélecteur de semaine */
.semaine { display: flex; align-items: center; background: var(--card); border-radius: 12px; }
.semaine button { border: 0; background: none; font-size: 28px; line-height: 1; padding: 10px 20px 14px; color: var(--accent); }
.semaine div { flex: 1; text-align: center; }
.semaine b { display: block; font-weight: 600; }
.semaine span { font-size: 13px; color: var(--muted); }

/* ================= Habillage : béton, noir et blanc ================= */
:root {
  --bg: #e9e8e5;
  --titre: Futura, "Avenir Next", "Century Gothic", "Trebuchet MS", sans-serif;
  --ombre: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .07);
  --bandeau: #111111;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0b0c; --card: #19191b; --ombre: 0 0 0 .5px rgba(255, 255, 255, .08); --bandeau: #19191b; }
}
/* Grain discret, comme une dalle polie */
body {
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23g)'/%3E%3C/svg%3E");
}

/* Bandeau de marque en haut des pages principales */
.bandeau {
  display: flex; align-items: center; gap: 14px; color: #fff; background: var(--bandeau);
  margin: calc(-8px - env(safe-area-inset-top)) -16px 20px; padding: calc(20px + env(safe-area-inset-top)) 20px 20px;
  border-radius: 0 0 24px 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.bandeau .logo { width: 46px; height: 46px; flex: none; }
.bandeau .nom { font-family: var(--titre); font-weight: 700; font-size: 17px; letter-spacing: .06em; text-transform: uppercase; line-height: 1.15; }
.bandeau .app { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; opacity: .6; margin-top: 3px; }
.bandeau.clair { background: #fff; color: #111; justify-content: space-between; }
.bandeau.clair .logo-compte { height: 46px; max-width: 62%; margin: 0; padding: 0; background: none; border-radius: 0; }
.bandeau.clair .app { margin: 0; text-align: right; }

/* Titres */
h1 { font-family: var(--titre); font-weight: 700; font-size: 30px; letter-spacing: .01em; text-transform: uppercase; margin: 4px 4px 16px; line-height: 1.1; }
h2 { font-family: var(--titre); font-weight: 700; font-size: 11px; letter-spacing: .16em; margin: 28px 6px 9px; }
.marque { margin-left: 4px; }

/* Cartes */
.group, .semaine, .filtre { border-radius: 16px; box-shadow: var(--ombre); }
.row { min-height: 54px; }
.row .val { font-family: var(--titre); font-size: 17px; }
.row .val small { font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }

/* Totaux : carte noire, chiffres en gros */
.stats { background: var(--accent); color: var(--on-accent); border-radius: 18px; padding: 18px 6px 16px; box-shadow: 0 10px 28px rgba(0, 0, 0, .2); }
.stats b { font-family: var(--titre); font-size: 22px; letter-spacing: 0; white-space: nowrap; }
.stats.q b { font-size: 19px; }
.stats span { color: inherit; opacity: .6; letter-spacing: .1em; font-size: 10px; }
.stats > div + div { border-left: .5px solid color-mix(in srgb, currentColor 22%, transparent); }

/* Boutons */
.btn { font-family: var(--titre); text-transform: uppercase; letter-spacing: .1em; font-size: 15px; font-weight: 700; padding: 17px; border-radius: 14px; box-shadow: 0 8px 22px rgba(0, 0, 0, .16); transition: transform .08s; }
.btn:active { transform: scale(.985); opacity: .9; }
.btn.ghost, .btn.contour { box-shadow: none; }
.btn.ghost { box-shadow: var(--ombre); }
.btn.contour { box-shadow: inset 0 0 0 2px var(--accent); }
.now { font-family: var(--titre); border-radius: 10px; letter-spacing: .06em; }
.mini-btn { font-family: var(--titre); letter-spacing: .04em; }
input[type=time] { border-radius: 10px; }

/* Étapes de la journée : une ligne du temps relie les points */
.etape, .pauses { --rail: 21px; }
.etape::after, .pauses::after { content: ""; position: absolute; left: var(--rail); top: 0; bottom: 0; width: 2px; background: var(--line); }
.etape:first-child::after { top: 50%; }
.etape:last-child::after { bottom: 50%; }
.etape .pt { position: relative; z-index: 1; background: var(--card); width: 14px; height: 14px; margin-left: -1px; }
.etape.fait .pt { box-shadow: 0 0 0 4px var(--accent-soft); }
.etape .lbl { font-weight: 600; }

/* Barre d'onglets */
#tabs a { font-family: var(--titre); letter-spacing: .08em; text-transform: uppercase; font-size: 9.5px; font-weight: 700; position: relative; padding-top: 6px; }
#tabs a.on::before { content: ""; position: absolute; top: -6px; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* Connexion */
.login input { border-radius: 14px; box-shadow: var(--ombre); }
.login .logo { width: 140px; height: 140px; }

/* Connexion : icône de l'application */
.login .icone { width: 148px; height: 148px; margin: 0 auto 22px; display: block; border-radius: 22.5%; box-shadow: 0 14px 34px rgba(0, 0, 0, .28); }
.login .metiers { color: var(--muted); letter-spacing: .1em; font-size: 11px; margin: 8px 0 30px; }

/* Connexion : toujours sur fond noir, pour que le logo Chrono Chantier s'y fonde */
body.ecran-login { background: #0c0c0c; color: #f2f2f7; }
.login .logo-app {
  display: block; width: 290px; max-width: 84%; height: auto; margin: 0 auto 2px;
  /* seuls les bords s'estompent, pour ne pas ternir le nom au bas du logo */
  -webkit-mask-image: linear-gradient(to right, transparent, #000 9%, #000 91%, transparent), linear-gradient(to bottom, transparent, #000 7%, #000 95%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent, #000 9%, #000 91%, transparent), linear-gradient(to bottom, transparent, #000 7%, #000 95%, transparent);
  mask-composite: intersect;
}
body.ecran-login .login .metiers { color: #8e8e93; margin: 0 0 28px; }
body.ecran-login .login input { background: #1c1c1e; color: #fff; box-shadow: none; }
body.ecran-login .login input::placeholder { color: #8e8e93; }
body.ecran-login .login .btn { background: #f5a41c; color: #111; box-shadow: 0 8px 24px rgba(245, 164, 28, .25); }
body.ecran-login .err { color: #ff6b61; }
