/* ---------- Thème ---------- */
:root {
  --bg: #f2f2f7;
  --bg2: #ffffff;
  --card: #ffffff;
  --card2: #e9e9ee;
  --segon: #ffffff;
  --text: #000000;
  --muted: #6c6c70;
  --sep: rgba(60, 60, 67, 0.2);
  --fill: #d1d1d6;
  --accent: #007aff;
  --danger: #ff3b30;
  --green: #34c759;
  --tabbar: rgba(249, 249, 249, 0.94);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg2: #0e0e0f;
    --card: #1c1c1e;
    --card2: #2c2c2e;
    --segon: #636366;
    --text: #ffffff;
    --muted: #8e8e93;
    --sep: rgba(84, 84, 88, 0.6);
    --fill: #39393d;
    --accent: #0a84ff;
    --danger: #ff453a;
    --green: #30d158;
    --tabbar: rgba(18, 18, 18, 0.94);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg2: #0e0e0f;
  --card: #1c1c1e;
  --card2: #2c2c2e;
  --segon: #636366;
  --text: #ffffff;
  --muted: #8e8e93;
  --sep: rgba(84, 84, 88, 0.6);
  --fill: #39393d;
  --accent: #0a84ff;
  --danger: #ff453a;
  --green: #30d158;
  --tabbar: rgba(18, 18, 18, 0.94);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
input, textarea { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { display: block; }
#haptic-switch, #haptic-label { position: fixed; left: -100px; top: -100px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ---------- Barre de navigation ---------- */
.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
  background: var(--bg2);
  border-bottom: 0.5px solid var(--sep);
  flex: none;
}
.nav h1 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; }
.nav > :first-child { justify-self: start; }
.nav > :last-child { justify-self: end; }
.link { color: var(--accent); font-size: 17px; }
.bold { font-weight: 600; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; color: var(--accent); }
.nav-arrows { display: flex; gap: 4px; }

/* ---------- Barre d'onglets ---------- */
#tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--tabbar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--sep);
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 4px);
  flex: none;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 500; color: var(--muted); padding: 2px 0; }
.tab svg { width: 28px; height: 28px; }
.tab.on { color: var(--accent); }

/* ---------- Carte semaine ---------- */
.week { padding: 16px 20px 22px; }
.week-head { display: flex; justify-content: space-between; align-items: flex-start; }
.week-head h2 { margin: 0; font-size: 21px; font-weight: 700; }
.week-head p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.week-head .link { display: flex; align-items: center; gap: 2px; }
.chart { position: relative; height: 140px; margin: 18px 0 10px; }
.gl { position: absolute; left: 0; right: 46px; border-top: 1px dashed var(--fill); }
.gl span { position: absolute; right: -46px; top: -9px; width: 42px; text-align: right; font-size: 12px; color: var(--muted); }
.bars { position: absolute; left: 0; right: 46px; top: 0; bottom: 0; display: grid; grid-template-columns: repeat(7, 1fr); align-items: end; }
.bars i { justify-self: center; width: 16px; background: var(--accent); border-radius: 4px 4px 0 0; }
.dots { display: grid; grid-template-columns: repeat(7, 1fr); padding-right: 46px; }
.dots div { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dots i { width: 26px; height: 26px; border-radius: 50%; background: var(--card2); }
.dots .has i { background: var(--accent); }
.dots .today { color: var(--accent); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 18px; }
.stats b { display: block; font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 15px; }

/* ---------- Panneau routines ---------- */
.panel { background: var(--bg2); border-radius: 18px 18px 0 0; padding: 8px 16px 120px; min-height: 55%; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--fill); margin: 0 auto 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 21px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 15px; line-height: 1.5; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px;
  padding: 12px 16px; min-height: 62px;
  transition: transform 0.15s ease;
}
.row:active { opacity: 0.85; }
.cbar { width: 6px; height: 32px; border-radius: 3px; flex: none; }
.row .name { flex: 1; min-width: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name small { display: block; color: var(--muted); font-size: 15px; margin-top: 2px; }
.row .dur { color: var(--muted); font-size: 18px; font-variant-numeric: tabular-nums; }
.chev { color: var(--muted); width: 16px; height: 16px; flex: none; }
.sel { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; color: #fff; }
.sel.on { background: var(--accent); border-color: var(--accent); }
.info { color: var(--accent); flex: none; }
.handle { touch-action: none; color: var(--muted); padding: 8px 0 8px 10px; border-left: 0.5px solid var(--sep); flex: none; cursor: grab; }
.row.dragging { position: relative; z-index: 2; transition: none; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); }

.fab {
  position: absolute; right: 20px; bottom: 20px;
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.4);
}
.fab:active { transform: scale(0.94); }
.edit-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 28px; background: var(--bg2); border-top: 0.5px solid var(--sep);
}
.edit-bar button { color: var(--accent); }
.edit-bar button:disabled { color: var(--muted); opacity: 0.5; }
.edit-mode .fab { bottom: 84px; }

/* ---------- Groupes / cellules ---------- */
.section-title { margin: 28px 32px 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.2px; }
.section-foot { margin: 8px 32px 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.group { background: var(--card); border-radius: 12px; margin: 0 16px; overflow: hidden; }
.cell {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 54px; padding: 8px 16px; width: 100%;
  font-size: 17px; text-align: left; position: relative;
}
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
button.cell:active { background: var(--card2); }
.val { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.cell.center { justify-content: center; }
.accent { color: var(--accent); }
.danger { color: var(--danger); }
.banner { margin: 16px 16px 0; padding: 14px 16px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 18%, var(--card)); font-size: 15px; line-height: 1.45; }

.switch { flex: none; }
.switch input { display: none; }
.switch i { display: block; width: 51px; height: 31px; border-radius: 16px; background: var(--fill); position: relative; transition: background 0.2s; }
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(20px); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 48%; height: 4px; border-radius: 2px; background: var(--fill); outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35); }

.pill {
  min-width: 96px; padding: 6px 14px; border-radius: 22px;
  color: #fff; font-size: 21px; font-weight: 600;
  font-variant-numeric: tabular-nums; text-align: center; flex: none;
}
.pill:active { filter: brightness(0.9); }
.seg { display: flex; background: var(--card2); border-radius: 9px; padding: 2px; flex: none; }
.seg button { padding: 6px 16px; border-radius: 7px; font-size: 15px; }
.seg .on { background: var(--segon); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 8px; flex: none; }
.stepper button { width: 34px; height: 32px; border-radius: 8px; background: var(--card2); font-size: 20px; display: grid; place-items: center; }
.stepper span { min-width: 76px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Pages & feuilles ---------- */
.page {
  position: fixed; inset: 0; z-index: 10;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.page.in { transform: none; }
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); opacity: 0; transition: opacity 0.25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 85%; overflow-y: auto;
  background: var(--card); border-radius: 16px 16px 0 0;
  padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-wrap.in .backdrop { opacity: 1; }
.sheet-wrap.in .sheet { transform: none; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px; border-bottom: 0.5px solid var(--sep); }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.opt small { display: block; color: #e0a020; font-size: 13px; margin-top: 2px; }
.opt .check { color: var(--accent); font-size: 20px; }

.time-pick { display: flex; justify-content: center; gap: 18px; padding: 26px 16px 14px; }
.time-pick label { display: flex; align-items: center; gap: 8px; font-size: 17px; color: var(--muted); }
.time-pick select {
  -webkit-appearance: none; appearance: none;
  background: var(--c); color: #fff; border: 0; border-radius: 14px;
  font-size: 38px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 8px 20px; text-align: center; text-align-last: center;
}
.quick { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 8px 16px; }
.quick button { background: var(--card2); border-radius: 16px; padding: 7px 12px; font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- Éditeur ---------- */
.editor-page .scroll { padding-bottom: 24px; }
.editor-page .group { margin-top: 20px; }
.name-row { display: flex; align-items: center; gap: 14px; padding: 18px 20px; background: var(--bg2); }
.name-row input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font-size: 32px; font-weight: 600; }
.name-row input::placeholder { color: var(--muted); }
.swatch { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.palette { display: flex; flex-wrap: wrap; gap: 14px; padding: 0 20px 18px; background: var(--bg2); }
.palette .on { outline: 3px solid var(--text); outline-offset: 2px; }
.cy-title { display: flex; align-items: center; }
.minus { width: 24px; height: 24px; border-radius: 50%; background: var(--danger); color: #fff; margin-right: 12px; display: grid; place-items: center; font-weight: 700; flex: none; }
.ex { gap: 8px; }
.ex input.ex-name { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font-size: 17px; }
.ex .pill { min-width: 66px; font-size: 16px; padding: 5px 9px; }
.x { color: var(--muted); width: 26px; height: 26px; display: grid; place-items: center; flex: none; }
.dot { width: 22px; height: 22px; border-radius: 50%; flex: none; position: relative; overflow: hidden; }
.dot input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; padding: 0; }
.sub-link { font-size: 15px; }
.ed-foot { padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px); background: var(--bg2); border-top: 0.5px solid var(--sep); text-align: center; font-size: 17px; flex: none; }
.tbar { display: flex; height: 10px; border-radius: 2px; overflow: hidden; margin-top: 10px; background: var(--card2); }
.tbar i { display: block; height: 100%; }

/* ---------- Historique ---------- */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); padding: 12px 12px 8px; color: var(--muted); font-size: 15px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 0 12px; touch-action: pan-y; }
/* width + min-width + appearance : Safari iOS ne garantit pas qu'un <button> s'étire dans sa case de grille. */
.day { position: relative; display: block; width: 100%; min-width: 0; height: 54px; margin: 0; -webkit-appearance: none; appearance: none; background: var(--card); border-radius: 6px; text-align: left; padding: 5px 8px; font-size: 18px; font-weight: 500; overflow: hidden; }
.day.out { color: var(--muted); opacity: 0.55; }
.day.today { color: var(--accent); }
.day.has::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--accent); }
/* Bordure intérieure (box-shadow inset) plutôt qu'outline : rendu identique sur Safari iOS. */
.day.sel { box-shadow: inset 0 0 0 2px var(--accent); background: var(--card); background: color-mix(in srgb, var(--accent) 28%, var(--card)); color: var(--text); }
.day:focus { outline: none; }
.day-title { margin: 22px 20px 10px; font-size: 15px; color: var(--muted); }
.day-title::first-letter { text-transform: uppercase; }
.sessions { padding: 0 16px 24px; }
.sessions .t { color: var(--muted); font-size: 18px; font-variant-numeric: tabular-nums; }
.sessions .bdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sessions .dur { color: var(--text); }

/* ---------- Écran d'exécution ---------- */
.run-page { background: var(--phase, #e8445f); color: #fff; transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.35s; }
.run-top { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top) + 6px) 20px 16px; }
.run-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.run-nav h1 { margin: 0; text-align: center; font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-nav button { width: 44px; height: 44px; display: grid; place-items: center; }
.run-time {
  margin: auto 0 0; text-align: center; line-height: 1;
  font-size: min(31vw, 25vh); font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.run-time.long { font-size: min(22vw, 22vh); }
.run-phase { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; margin-top: 4vh; }
.run-phase button { width: 44px; height: 44px; display: grid; place-items: center; }
#run-name { font-size: 30px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#run-sub { font-size: 17px; opacity: 0.9; margin-top: 2px; min-height: 21px; }
.run-stats { display: flex; justify-content: space-between; margin-top: auto; padding-top: 3vh; }
.run-stats b { display: block; font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.run-stats span { font-size: 17px; opacity: 0.95; }
.run-stats div:last-child { text-align: right; }
.progress { height: 4px; background: rgba(255, 255, 255, 0.3); border-radius: 2px; margin-top: 14px; overflow: hidden; }
.progress i { display: block; height: 100%; background: #fff; width: 0; }
.run-bottom { background: rgba(0, 0, 0, 0.09); display: flex; flex-direction: column; align-items: center; padding: 3vh 22px calc(env(safe-area-inset-bottom) + 18px); flex: none; }
.run-ctrls { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.ring { position: relative; width: min(54vw, 30vh); aspect-ratio: 1; container-type: inline-size; }
.ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
/* Taille du libellé relative au cercle (cqi) : « REPRENDRE » doit tenir quel que soit l'écran. */
.ring button { position: absolute; inset: 6%; border-radius: 50%; font-size: clamp(26px, 9vw, 42px); font-size: min(42px, 19cqi); font-weight: 500; letter-spacing: 1px; white-space: nowrap; overflow: hidden; }
.ring button.long { font-size: clamp(16px, 5.5vw, 28px); font-size: min(28px, 11.5cqi); letter-spacing: 0.5px; }
.ring button:active { background: rgba(255, 255, 255, 0.1); }
.round-btn { width: 62px; height: 62px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85); display: grid; place-items: center; }
.round-btn:active { background: rgba(255, 255, 255, 0.15); }
.next-up { margin-top: 14px; font-size: 15px; opacity: 0.9; min-height: 18px; text-align: center; }
.run-page.locked .run-bottom, .run-page.locked .run-phase button, .run-page.locked .run-nav button { opacity: 0.3; }
.lock-overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(env(safe-area-inset-bottom) + 34px); }
.unlock { position: relative; overflow: hidden; display: flex; align-items: center; gap: 10px; padding: 15px 24px; border-radius: 30px; background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 16px; font-weight: 500; touch-action: none; }
.unlock .fill { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.35); transform: scaleX(0); transform-origin: left; }
.unlock.hold .fill { transform: scaleX(1); transition: transform 0.8s linear; }
.unlock span { position: relative; }
.done-overlay { position: absolute; inset: 0; z-index: 6; background: var(--phase); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
.done-overlay h2 { margin: 0; font-size: 38px; }
.done-overlay p { margin: 0 0 18px; font-size: 19px; opacity: 0.95; }
.done-overlay button { min-width: 220px; padding: 15px 24px; border-radius: 30px; font-size: 18px; font-weight: 600; }
.btn-white { background: #fff; color: #000; }
.btn-ghost { border: 2px solid rgba(255, 255, 255, 0.85); }
[hidden] { display: none !important; }

/* ---------- Bandeau de mise à jour ---------- */
#update-banner {
  flex: none; display: flex; align-items: center; gap: 12px;
  margin: 0 12px 8px; padding: 10px 8px 10px 16px;
  border-radius: 14px; background: var(--card2); font-size: 15px;
}
#update-banner span { flex: 1; }
#update-banner .link { font-size: 15px; }
.banner-x { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); }

/* En fin de fichier pour primer sur #app et .page. */
/* App installée sur iPhone : avec la barre d'état translucide, « inset: 0 » s'arrête avant
   le bas de l'écran (bande noire sous les onglets). 100vh = l'écran entier en mode app. */
@media (display-mode: standalone) {
  #app, .page { bottom: auto; height: 100vh; }
}

/* ---------- Paysage (téléphone couché) ---------- */
/* Encoche / Dynamic Island sur les côtés : les contenus ne passent pas dessous. */
#app, .page:not(.run-page) {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
@media (orientation: landscape) and (max-height: 600px) {
  /* Minuteur sur deux colonnes : infos à gauche, commandes à droite. */
  .run-page { flex-direction: row; }
  .run-top {
    flex: 1.35; min-width: 0;
    padding: calc(env(safe-area-inset-top) + 4px) 16px calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 16px);
  }
  .run-time, .run-time.long { font-size: min(17vw, 30vh); margin: auto 0 0; }
  .run-phase { margin-top: 1.5vh; }
  #run-name { font-size: 24px; }
  #run-sub { font-size: 15px; }
  .run-stats { padding-top: 1.5vh; }
  .run-stats b { font-size: 22px; }
  .run-stats span { font-size: 14px; }
  .progress { margin-top: 8px; }
  .run-bottom {
    flex: 1; min-width: 0; justify-content: center;
    padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 10px) 16px;
  }
  .ring { width: min(24vw, 52vh); }
  .round-btn { width: 52px; height: 52px; }
  .next-up { margin-top: 10px; }
  .lock-overlay { padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
  .done-overlay { gap: 8px; }
  .done-overlay h2 { font-size: 30px; }
  .done-overlay p { margin-bottom: 8px; }
  .done-overlay button { padding: 11px 24px; }

  /* Écrans de liste : carte semaine plus compacte, onglets plus bas. */
  .chart { height: 90px; }
  .tab svg { width: 24px; height: 24px; }
}
