:root {
  --bg: #eeeff1;
  --card: #ffffff;
  --text: #16171a;
  --muted: #6b6e76;
  --line: #e3e4e8;
  --field: #f5f6f8;
  --accent: #ff4f00;
  --accent-ink: #ffffff;
  --accent-soft: #fff0e8;
  --ok: #1f8a4c;
  --ok-soft: #e6f5ec;
  --warn: #a86400;
  --warn-soft: #fff4dc;
  --idle: #5b5f69;
  --idle-soft: #eceef2;
  --danger: #c62828;
  --tabbar: rgba(255, 255, 255, 0.92);
  --shadow: 0 1px 2px rgba(16, 17, 20, .05), 0 4px 16px rgba(16, 17, 20, .05);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1c1d21;
    --text: #f2f3f5;
    --muted: #9a9da6;
    --line: #2c2e34;
    --field: #25272c;
    --accent: #ff5f1a;
    --accent-soft: #3a2014;
    --ok: #4cc27f;
    --ok-soft: #173223;
    --warn: #f0b44c;
    --warn-soft: #3a2c12;
    --idle: #b5b8c0;
    --idle-soft: #2a2c32;
    --danger: #ff6b6b;
    --tabbar: rgba(28, 29, 33, 0.92);
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { min-height: 100dvh; display: grid; place-items: center; }

/* ---------- Mise en page ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: var(--bg);
  display: flex; align-items: center; gap: 12px;
}
.top img { width: 34px; height: 34px; border-radius: 9px; }
.top h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.01em; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--card);
  display: grid; place-items: center; box-shadow: var(--shadow); cursor: pointer;
}
.iconbtn svg { width: 22px; height: 22px; }
main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--tabbar); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 120px; border: 0; background: none; padding: 6px 0 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; font-weight: 500;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button.on { color: var(--accent); }

/* ---------- Cartes ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card.tap { cursor: pointer; }
.card h2 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -.005em; }
.card .sub { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; }
.section-title:first-child { margin-top: 6px; }
.label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 4px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty svg { width: 44px; height: 44px; opacity: .5; display: block; margin: 0 auto 10px; }
.chev { display: block; width: 20px; height: 20px; color: var(--muted); flex: none; }
.chev svg { width: 100%; height: 100%; display: block; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; min-height: 48px;
}
.btn svg { width: 20px; height: 20px; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--field); color: var(--text); }
.btn.danger { background: none; color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btns .btn { flex: 1; }

.mat { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.mat:first-child { border-top: 0; }
.mat .q { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; min-width: 34px; }

/* ---------- Planning ---------- */
.day { display: flex; gap: 14px; }
.day .d { width: 46px; flex: none; text-align: center; }
.day .d b { display: block; font-size: 22px; line-height: 1.1; }
.day .d span { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.day.today .d b, .day.today .d span { color: var(--accent); }
.time { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Heures ---------- */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.totals .card { margin: 0; }
.big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.monthnav b { text-transform: capitalize; }
.entry { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; padding-top: 0; }
.entry:last-child { padding-bottom: 0; }
.fab {
  position: fixed; right: 18px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 9;
  width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(255, 79, 0, .35); cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- Formulaires ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--field); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err { color: var(--danger); font-size: 14px; margin: 4px 0 10px; min-height: 1em; }
.hint { color: var(--muted); font-size: 13.5px; }

/* ---------- Connexion ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); max-width: 420px; margin: 0 auto; }
.login .logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 14px; display: block; }
.login h1 { text-align: center; font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }

/* ---------- Feuille (formulaire en bas d'ecran) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto;
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500; font-size: 14.5px; max-width: 90vw; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 20px; font-weight: 600; background: var(--field); padding: 10px 14px; border-radius: 10px; text-align: center; user-select: all; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }
