/* Jalons : feuille de style.
   Les couleurs sont des variables : le mode sombre ne fait que les redéfinir. */

:root {
  color-scheme: light dark;

  --bg: #F6F3EC;
  --surface: #FFFFFF;
  --text: #17211E;
  --text-soft: #5C6A65;
  --border: #E2DDD1;
  --accent: #2F6B5C;
  --on-accent: #FFFFFF;

  /* Une couleur par type de conso */
  --type-a: #B4612F;
  --type-a-soft: #F6E4D6;
  --type-b: #2F6B5C;
  --type-b-soft: #DCEBE5;

  --error: #A63A2B;
  --error-soft: #F8E1DC;

  --radius: 20px;
  --pad: 20px;
  --actions-height: 104px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101816;
    --surface: #18231F;
    --text: #EEF2EF;
    --text-soft: #9BABA5;
    --border: #26342F;
    --accent: #7FB8A6;
    --on-accent: #0E1513;

    --type-a: #E6A070;
    --type-a-soft: #3A2A1E;
    --type-b: #7FB8A6;
    --type-b-soft: #1D3029;

    --error: #F0988A;
    --error-soft: #3A1F1B;
  }
}

* { box-sizing: border-box; }

html {
  /* Empêche iOS de grossir le texte tout seul en paysage */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  /* Pas de surbrillance grise au tap, pas de sélection de texte accidentelle */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  /* Supprime le délai de 300 ms et le zoom au double tap */
  touch-action: manipulation;
}

p, h1, h2, ul { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }

/* ===== Écran ===== */

.screen {
  /* env(safe-area-inset-*) : marges imposées par l'encoche et la barre d'accueil */
  padding:
    calc(env(safe-area-inset-top) + 24px)
    calc(env(safe-area-inset-right) + var(--pad))
    calc(env(safe-area-inset-bottom) + var(--actions-height) + 24px)
    calc(env(safe-area-inset-left) + var(--pad));
  max-width: 560px;
  margin: 0 auto;
}

.head { margin-bottom: 24px; }

.eyebrow {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.title::first-letter { text-transform: uppercase; }

.banner {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 17px;
  color: var(--text-soft);
}

.banner-error {
  background: var(--error-soft);
  border-color: transparent;
  color: var(--error);
}

/* ===== Compteurs ===== */

.counters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}

.counter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px var(--pad) 16px;
}

.counter-value {
  font-size: 64px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.counter[data-type="a"] .counter-value { color: var(--type-a); }
.counter[data-type="b"] .counter-value { color: var(--type-b); }

.counter-name {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-soft);
}

/* Petit rebond du compteur quand une conso vient d'être ajoutée */
.counter-value.bump { animation: bump 380ms cubic-bezier(.2, .9, .3, 1.2); }

@keyframes bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* ===== Liste du jour ===== */

.empty {
  padding: 8px 2px;
  color: var(--text-soft);
}

.entries {
  display: grid;
  gap: 8px;
}

.entry {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  animation: rise 240ms ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.entry-time {
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.entry-type {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 650;
}

.entry[data-type="a"] .entry-type { background: var(--type-a-soft); color: var(--type-a); }
.entry[data-type="b"] .entry-type { background: var(--type-b-soft); color: var(--type-b); }

.entry-notes {
  justify-self: end;
  font-size: 17px;
  color: var(--text-soft);
  white-space: nowrap;
}

/* ===== Pied de page ===== */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 28px;
  font-size: 16px;
  color: var(--text-soft);
}

.link {
  min-height: 44px;
  padding: 0 4px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

/* ===== Boutons d'ajout, fixés en bas ===== */

.actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding:
    12px
    calc(env(safe-area-inset-right) + var(--pad))
    calc(env(safe-area-inset-bottom) + 16px)
    calc(env(safe-area-inset-left) + var(--pad));
  background: linear-gradient(to bottom, transparent, var(--bg) 28%);
}

.add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 76px;
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 700;
  color: #FFFFFF;
  transition: transform 120ms ease-out;
}

.add[data-type="a"] { background: #B4612F; }
.add[data-type="b"] { background: #2F6B5C; }
.add:active { transform: scale(0.97); }

.add-plus {
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  opacity: 0.85;
}

/* ===== Panneaux qui montent du bas ===== */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.45);
  animation: fade 180ms ease-out;
}

.sheet-panel {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding:
    22px
    calc(env(safe-area-inset-right) + var(--pad))
    calc(env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + var(--pad));
  background: var(--bg);
  border-radius: 28px 28px 0 0;
  animation: slide-up 260ms cubic-bezier(.2, .8, .2, 1);
}

.sheet.closing { animation: fade 180ms ease-in reverse forwards; }
.sheet.closing .sheet-panel { animation: slide-up 180ms ease-in reverse forwards; }

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#entry-sheet[data-type="a"] .sheet-title { color: var(--type-a); }
#entry-sheet[data-type="b"] .sheet-title { color: var(--type-b); }

.hint {
  margin-bottom: 8px;
  font-size: 17px;
  color: var(--text-soft);
}

/* Échelles de 1 à 5 */

.scale-label {
  margin: 18px 0 10px;
  font-size: 20px;
  font-weight: 650;
}

.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.scale-btn {
  min-height: 64px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 26px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition: transform 120ms ease-out, background-color 120ms, color 120ms;
}

.scale-btn:active { transform: scale(0.95); }

.scale-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* Bouton principal */

.primary {
  width: 100%;
  min-height: 68px;
  margin-top: 26px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 24px;
  font-weight: 700;
  transition: opacity 160ms, transform 120ms ease-out;
}

.primary:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.35; }

/* Champs de texte */

.field {
  display: block;
  margin-top: 16px;
}

.field-name {
  display: block;
  margin-bottom: 6px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-soft);
}

.field input {
  width: 100%;
  min-height: 60px;
  padding: 0 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  /* 16px minimum : en dessous, iOS zoome sur le champ à la saisie */
  font-size: 22px;
  -webkit-user-select: text;
  user-select: text;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Respecte le réglage iOS "Réduire les animations" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
