/* Gwennou App : palette beige et vert sauge, thème clair/sombre automatique. */
:root {
  --bg: #F6F1E7;
  --surface: #FFFDF8;
  --surface-2: #EFE8DA;
  --border: #E2D9C8;
  --text: #2E3830;
  --text-2: #56625A;
  --muted: #7A847C;
  --accent: #5B7A60;
  --accent-ink: #FFFFFF;
  --accent-soft: #DDE7D9;
  --accent-text: #46634B;
  --clay: #9C6A4E;
  --clay-soft: #F1E2D6;
  --warn: #A3641C;
  --warn-soft: #F6E6CF;
  --ok: #3F7A4A;
  --ok-soft: #DCEBDD;
  --birthday: #B07A9A;
  --f0: #3570B8;
  --f1: #D0612F;
  --f2: #1C9A70;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 4px 14px rgba(60, 50, 30, .05);
  --radius: 16px;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C201D;
    --surface: #252A26;
    --surface-2: #2E3430;
    --border: #3A413B;
    --text: #ECE7DC;
    --text-2: #C3C6BC;
    --muted: #959C93;
    --accent: #9CB89C;
    --accent-ink: #18201A;
    --accent-soft: #34433A;
    --accent-text: #A9C4A9;
    --clay: #D5A487;
    --clay-soft: #46362D;
    --warn: #E3AE62;
    --warn-soft: #463A27;
    --ok: #8CC497;
    --ok-soft: #2D4232;
    --birthday: #D3A2C0;
    --f0: #4A8BD6;
    --f1: #D66A3A;
    --f2: #2AA37A;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
a { color: var(--accent-text); }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: .4em 0; }
code { display: block; margin-top: 4px; font-size: .8em; word-break: break-all; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
button { font: inherit; color: inherit; }
.icon { flex: none; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#view { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.page { padding-bottom: 88px; }

/* En-tête */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 0 12px; }
.top h1 { font-family: var(--serif); font-size: 1.85rem; letter-spacing: -.01em; }
.subtitle { color: var(--text-2); margin: 2px 0 0; }
.subtabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 2px 16px;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtabs a {
  flex: none; padding: 7px 14px; border-radius: 999px; text-decoration: none; color: var(--text-2);
  background: var(--surface-2); font-size: .92rem;
}
.subtabs a.active { background: var(--accent); color: var(--accent-ink); }

.banner {
  width: 100%; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; padding: 10px 14px; border-radius: 12px;
  border: 0; background: var(--warn-soft); color: var(--warn); font-size: .9rem; text-align: left; cursor: pointer;
}

/* Cartes */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
summary.card-head { list-style: none; cursor: pointer; margin-bottom: 0; }
summary.card-head::-webkit-details-marker { display: none; }
details[open] > summary.card-head { margin-bottom: 6px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.card-head h2 { font-family: var(--serif); font-size: 1.15rem; flex: 1; display: flex; align-items: center; gap: 8px; }
.card-head .muted { text-decoration: none; font-size: .9rem; }
.card h3, .sheet-body h3 { font-size: .95rem; margin: 14px 0 4px; color: var(--text-2); }

.group { margin-bottom: 16px; }
.group > h3, .group > summary { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 0; font-weight: 600; }
.group > summary { cursor: pointer; padding: 6px 0; }
.group .list, .page > .list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px; box-shadow: var(--shadow); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.empty { color: var(--muted); margin: 8px 0; font-style: italic; }
.hint { color: var(--muted); font-size: .85rem; }
.late { color: var(--warn); }
.notes { white-space: pre-wrap; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }

/* Listes */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); min-height: 52px; }
.item:last-child { border-bottom: 0; }
.item-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; color: inherit;
}
.item-main.static { cursor: default; }
.item-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.item-meta { font-size: .84rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.item-meta.details { white-space: pre-wrap; display: block; }
.item.done .item-title { text-decoration: line-through; color: var(--muted); }
.item.inactive { opacity: .6; }
.with-icon { display: inline-flex; align-items: center; gap: 3px; }
.prio { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }

.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted);
  background: transparent; display: grid; place-items: center; color: transparent; padding: 0; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.chip {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); letter-spacing: .02em;
}
.chip-isp { background: var(--clay-soft); color: var(--clay); }
.chip-run { background: var(--accent-soft); color: var(--accent-text); }
.chip-crossfit { background: var(--clay-soft); color: var(--clay); }

.badge {
  flex: none; font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge.soon { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* Formations ISP */
.chip-formation { display: inline-flex; align-items: center; gap: 5px; }
.f-dot { flex: none; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.f-dot.f-0 { background: var(--f0); }
.f-dot.f-1 { background: var(--f1); }
.f-dot.f-2 { background: var(--f2); }
.card-head h2 .f-dot { width: 12px; height: 12px; }
.formation-card { display: block; text-decoration: none; color: inherit; }
.formation-card .card-head { color: var(--muted); }
.formation-card .card-head h2 { color: var(--text); }
.stats { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--text-2); }
.stats strong { color: var(--text); }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 14px; font-size: .9rem; font-weight: 600; text-decoration: none; }
.back-link + .top { padding-top: 4px; }

/* Rendez-vous */
.event-time { flex: none; width: 52px; font-size: .85rem; color: var(--text-2); font-variant-numeric: tabular-nums; line-height: 1.2; }
.cal-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.cal-dot.isp { background: var(--clay); }
.cal-dot.birthday { background: var(--birthday); }
.cal-dot.sport { background: var(--accent); }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: .85rem; color: var(--muted); cursor: pointer;
}
.chip-toggle.on { color: var(--text); background: var(--surface-2); }
.chip-toggle:not(.on) .cal-dot { opacity: .35; }

/* Citation */
.quote { margin: 4px 4px 18px; padding: 6px 0 6px 16px; border-left: 3px solid var(--accent); }
.quote blockquote { margin: 0; font-family: var(--serif); font-size: 1.08rem; font-style: italic; color: var(--text); }
.quote figcaption { margin-top: 6px; color: var(--muted); font-size: .88rem; }
.quote figcaption::before { content: "— "; }

/* Boutons */
.icon-btn {
  flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: var(--surface-2); color: var(--text-2); cursor: pointer; text-decoration: none;
}
.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; }
.icon-btn:disabled { opacity: .35; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid transparent; cursor: pointer; font-weight: 600; text-decoration: none; font-size: .95rem;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .5; }
.page > .btn { width: 100%; margin-bottom: 14px; }
.btn.full { width: 100%; margin: 4px 0 12px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--accent-text);
  padding: 8px 0; cursor: pointer; font-weight: 600; font-size: .92rem;
}
.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(88px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(40, 60, 40, .25); cursor: pointer; z-index: 5;
}

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; }
.toolbar strong { font-family: var(--serif); font-size: 1.05rem; text-align: center; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tabbar a.active { color: var(--accent-text); }

/* Feuille modale */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(20, 24, 20, 0); display: flex; align-items: flex-end;
  justify-content: center; transition: background .2s;
}
.sheet-backdrop.open { background: rgba(20, 24, 20, .4); }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease-out; overscroll-behavior: contain;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; position: sticky; top: -8px; background: var(--surface); z-index: 1; }
.sheet-head h2 { font-family: var(--serif); font-size: 1.25rem; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.field label { font-size: .88rem; color: var(--text-2); font-weight: 600; }
.field input, .field select, .field textarea, .inline-add input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 46px; -webkit-appearance: none; 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% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
.field input:focus, .field select:focus, .field textarea:focus, .inline-add input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field-check { flex-direction: row; align-items: center; gap: 10px; }
.field-check input { width: 22px; height: 22px; accent-color: var(--accent); }
.field-check label { font-weight: 500; color: var(--text); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.form-actions .btn.primary { flex: 1; }
.inline-add { display: flex; gap: 8px; margin-bottom: 14px; }
.card .inline-add { margin: 4px 0 6px; }
.card .inline-add .btn { min-height: 46px; padding: 10px 14px; }
.card h3.subhead { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 0; }
.inline-add input { flex: 1; }
input[type="color"] { width: 32px; height: 32px; border: 0; padding: 0; background: none; border-radius: 50%; flex: none; }

.switch { position: relative; flex: none; width: 46px; height: 28px; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span:first-of-type { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .15s; }
.switch span:first-of-type::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

/* Habitudes */
.habit { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.habit:last-child { border-bottom: 0; }
.habit > div:first-child { flex: 1; min-width: 0; }
.habit-label { font-weight: 600; margin: 0; }
.habit .muted { margin: 0; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--surface-2); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 72px; text-align: center; font: inherit; font-size: 16px; padding: 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.habit-status { width: 22px; color: var(--ok); }
.habit-grid { width: 100%; border-collapse: collapse; font-size: .85rem; }
.habit-grid th { font-weight: 500; color: var(--muted); padding: 4px 2px; }
.habit-grid tbody th { text-align: left; color: var(--text-2); }
.habit-grid td { text-align: center; color: var(--muted); }
.habit-grid td.ok { color: var(--ok); }

/* Progression et jauges */
.progress { display: block; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 4px 0; max-width: 220px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter-row { margin: 10px 0; }
.meter-label { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; margin-bottom: 4px; }
.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 999px; margin: 6px 0; }
.meter-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; max-width: 100%; }
.meter-fill.over { background: var(--warn); }
.meter-budget { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-2); border-radius: 2px; }

/* Tuiles chiffrées */
.tiles { display: flex; gap: 10px; margin-bottom: 14px; }
.tile { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.tile-label { margin: 0; color: var(--muted); font-size: .8rem; }
.tile-value { margin: 2px 0 0; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-value.big { font-size: clamp(1.15rem, 5.2vw, 1.8rem); white-space: nowrap; }
.amount { flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.in { color: var(--ok); }

/* Sport */
.goal { display: flex; align-items: flex-start; justify-content: space-between; }
.goal-count { font-family: var(--serif); font-size: 2.4rem; font-weight: 600; margin: 0; color: var(--accent-text); line-height: 1.1; }
.goal-line { margin: 8px 0 0; color: var(--text-2); font-size: .9rem; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 8px; }
.day.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-head { display: flex; align-items: center; justify-content: space-between; }
.day-head h3 { font-size: .95rem; text-transform: capitalize; }
.rest { margin: 2px 0 4px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 16px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; outline: none; }
.bar-value { font-size: .78rem; font-weight: 700; color: var(--text); height: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-col.current .bar-label { color: var(--text); font-weight: 700; }
.bar-track { position: relative; flex: 1; width: 100%; max-width: 22px; }
.bar-planned, .bar-fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 4px 4px 0 0; }
.bar-planned { background: var(--accent-soft); }
.bar-fill { background: var(--accent); left: 3px; right: 3px; }
.bar-col:hover .bar-fill, .bar-col:focus .bar-fill { filter: brightness(1.1); }
.bar-label { font-size: .66rem; color: var(--muted); }
.legend { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key.fill { background: var(--accent); }
.key.planned { background: var(--accent-soft); margin-left: 8px; }

.km-list { list-style: none; margin: 0; padding: 0; }
.km-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.km-row:last-child { border-bottom: 0; }
.km-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.km-line > span:last-child { white-space: nowrap; }
.km-done { font-family: var(--serif); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tile .tile-label + .tile-value + .tile-label { margin-top: 2px; }

/* Verrouillage */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.lock-inner { text-align: center; width: 100%; max-width: 300px; }
.lock-title { font-family: var(--serif); font-size: 1.6rem; margin: 0; }
.lock-sub { color: var(--muted); }
.dots { display: flex; justify-content: center; gap: 14px; margin: 22px 0 28px; }
.dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.dots span.on { background: var(--accent); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; justify-items: center; }
.keypad button { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 1.6rem; cursor: pointer; }

/* Message éphémère */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
[hidden] { display: none !important; }
