/* AE : écran figé façon app iOS native, mode sombre automatique. */

:root {
  --fond: #f2f2f7;
  --carte: #ffffff;
  --texte: #000000;
  --texte-2: rgba(60, 60, 67, 0.6);
  --texte-3: rgba(60, 60, 67, 0.3);
  --separateur: rgba(60, 60, 67, 0.18);
  --champ: rgba(118, 118, 128, 0.12);
  --appui: rgba(0, 0, 0, 0.06);
  --bleu: #007aff;
  --orange: #ff9500;
  --rouge: #ff3b30;
  --vert: #34c759;
  --voile: rgba(0, 0, 0, 0.32);
  --rayon: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #000000;
    --carte: #1c1c1e;
    --texte: #ffffff;
    --texte-2: rgba(235, 235, 245, 0.6);
    --texte-3: rgba(235, 235, 245, 0.3);
    --separateur: rgba(84, 84, 88, 0.55);
    --champ: rgba(118, 118, 128, 0.24);
    --appui: rgba(255, 255, 255, 0.08);
    --bleu: #0a84ff;
    --orange: #ff9f0a;
    --rouge: #ff453a;
    --vert: #30d158;
    --voile: rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Écran figé : rien ne défile, rien ne rebondit. */
html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--fond);
  color: var(--texte);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, input {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

button { cursor: pointer; }
:focus, :focus-visible { outline: none; }

svg { display: block; }

/* ── Écran principal ─────────────────────────────────────────── */

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(env(safe-area-inset-top) + 4px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 12px)
    calc(env(safe-area-inset-left) + 16px);
}

.barre {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.titre {
  font-size: 15px;
  font-weight: 600;
  color: var(--texte-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.bouton-icone {
  width: 44px;
  height: 44px;
  margin-right: -10px;
  display: grid;
  place-items: center;
  color: var(--bleu);
  border-radius: 22px;
}
.bouton-icone svg { width: 26px; height: 26px; fill: currentColor; }
.bouton-icone:active { opacity: 0.4; }

.saisie {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 10px 0 18px;
  border-bottom: 1px solid var(--separateur);
}

.montant {
  flex: 1;
  min-width: 0;
  font-size: 56px; /* ≥ 16 px : iOS ne zoome pas au focus */
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-align: right;
  caret-color: var(--bleu);
  padding: 0 0 4px;
}
.montant::placeholder { color: var(--texte-3); }
.montant.long { font-size: 42px; }

.devise {
  font-size: 34px;
  font-weight: 500;
  color: var(--texte-2);
}

.effacer {
  align-self: center;
  width: 36px;
  height: 36px;
  margin-right: -6px;
  display: grid;
  place-items: center;
}
.effacer svg { width: 22px; height: 22px; }
.effacer circle { fill: var(--texte-3); }
.effacer path { stroke: var(--carte); stroke-width: 2.2; stroke-linecap: round; fill: none; }
.effacer:active { opacity: 0.5; }
.effacer[hidden] { display: none; }

.repartition {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--champ);
  margin-bottom: 18px;
}
.segment {
  height: 100%;
  width: 0;
  transition: width 0.25s ease;
}
.segment + .segment { box-shadow: inset 2px 0 0 var(--fond); }
.urssaf { background: var(--orange); }
.thomas { background: var(--bleu); }
.impot { background: var(--rouge); }
.foyer { background: var(--vert); }

.resultats {
  list-style: none;
  background: var(--carte);
  border-radius: var(--rayon);
  overflow: hidden;
}

.resultats li + li .ligne::before {
  content: "";
  position: absolute;
  top: 0;
  left: 38px;
  right: 0;
  border-top: 1px solid var(--separateur);
}

.ligne {
  position: relative;
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  text-align: left;
  transition: background-color 0.35s ease;
}
.ligne:active { background: var(--appui); transition: none; }
.ligne.copie { background: var(--appui); }

.pastille {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 5px;
}

.libelle { flex: 1; }
.libelle small { font-size: 13px; color: var(--texte-2); }

.valeur {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.secondaire .libelle, .secondaire .valeur { color: var(--texte-2); }
.forte .libelle { font-weight: 600; }
.forte .valeur { font-size: 22px; font-weight: 700; color: var(--vert); }

.details {
  margin-top: 10px;
  padding: 0 4px;
  font-size: 13px;
  color: var(--texte-2);
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
}

.invitation {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--rayon);
  background: var(--carte);
  color: var(--bleu);
  font-size: 15px;
  text-align: left;
}
.invitation[hidden] { display: none; }
.invitation:active { opacity: 0.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--carte);
  color: var(--texte);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ── Feuille des paramètres ──────────────────────────────────── */

.voile {
  position: fixed;
  inset: 0;
  background: var(--voile);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.feuille {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(100dvh - env(safe-area-inset-top) - 10px);
  display: flex;
  flex-direction: column;
  background: var(--fond);
  border-radius: 14px 14px 0 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  visibility: hidden;
}

.ouverte .voile { opacity: 1; pointer-events: auto; }
.ouverte .feuille { transform: none; visibility: visible; }
.feuille { transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.35s; }
.ouverte .feuille { transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s; }

.feuille-tete {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  padding: 0 calc(env(safe-area-inset-right) + 16px) 0 calc(env(safe-area-inset-left) + 16px);
  border-bottom: 1px solid var(--separateur);
}
.poignee {
  position: absolute;
  top: 6px;
  left: 50%;
  width: 36px;
  height: 5px;
  margin-left: -18px;
  border-radius: 3px;
  background: var(--texte-3);
}
.feuille-tete h2 { font-size: 17px; font-weight: 600; }
.ok {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 8px);
  top: 6px;
  height: 44px;
  padding: 0 8px;
  color: var(--bleu);
  font-weight: 600;
}
.ok:active { opacity: 0.4; }

/* Seul endroit qui défile. */
.feuille-corps {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 32px) calc(env(safe-area-inset-left) + 16px);
}

.feuille-corps h3 {
  margin: 22px 16px 7px;
  font-size: 13px;
  font-weight: 400;
  color: var(--texte-2);
  text-transform: uppercase;
}

.groupe {
  background: var(--carte);
  border-radius: var(--rayon);
  overflow: hidden;
}
.groupe + .groupe { margin-top: 16px; }

.rangee {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 6px 16px;
}
.rangee + .rangee::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--separateur);
}

.unite {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--texte-2);
  flex: none;
}

.rangee input[type="text"] {
  width: 7.5em;
  font-size: 17px; /* ≥ 16 px : pas de zoom au focus */
  text-align: right;
  color: var(--texte);
  font-variant-numeric: tabular-nums;
  padding: 6px 0;
}
.rangee input[data-type="pourcent"] { width: 4.5em; }
.rangee input[data-chemin="foyer.parts"] { width: 4em; }
.rangee input::placeholder { color: var(--texte-3); }
.rangee input:focus { color: var(--bleu); }
.rangee input:disabled { color: var(--texte-2); -webkit-text-fill-color: var(--texte-2); opacity: 1; }

.tranche .unite input[data-type="euros"] { width: 6em; }
.tranche .a { color: var(--texte-2); font-size: 15px; }

/* Interrupteur iOS */
.interrupteur {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--champ);
  transition: background-color 0.25s ease;
}
.interrupteur::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  transition: transform 0.25s ease;
}
.interrupteur:checked { background: var(--vert); }
.interrupteur:checked::after { transform: translateX(20px); }

.aide {
  margin: 8px 16px 0;
  font-size: 13px;
  color: var(--texte-2);
}

.reinitialiser {
  width: 100%;
  margin-top: 28px;
  min-height: 46px;
  border-radius: var(--rayon);
  background: var(--carte);
  color: var(--rouge);
}
.reinitialiser:active { background: var(--appui); }
