/* Foyer — feuille de style unique. Une famille, une couleur d'accent par écran. */

:root {
  --bg: #EEF1F4;
  --ink: #14213D;
  --surface: #FFFFFF;
  --border: #D5DAE1;
  --muted: #55607A;
  --mustard: #E7B10A;
  --mustard-soft: #F7E7B0;
  --green: #3A7D44;
  --green-soft: #CFE5D3;
  --brick: #C8402A;
  --brick-soft: #F4D6CF;
  --track: #DDE2E9;
  --on-mustard: #14213D;
  --on-green: #FFFFFF;
  --accent: var(--mustard);
  --accent-soft: var(--mustard-soft);
  --on-accent: var(--on-mustard);
  --radius: 14px;
  --tabbar-h: 64px;
  --font: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F172A;
    --ink: #E2E8F0;
    --surface: #1E293B;
    --border: #334155;
    --muted: #A3AFC2;
    --mustard: #D9AB2F;
    --mustard-soft: #4A3F1A;
    --green: #4E9159;
    --green-soft: #1F3A26;
    --brick: #D0604B;
    --brick-soft: #4A2620;
    --track: #2B3A50;
    --on-mustard: #0F172A;
  }
}
:root[data-theme="dark"] {
  --bg: #0F172A;
  --ink: #E2E8F0;
  --surface: #1E293B;
  --border: #334155;
  --muted: #A3AFC2;
  --mustard: #D9AB2F;
  --mustard-soft: #4A3F1A;
  --green: #4E9159;
  --green-soft: #1F3A26;
  --brick: #D0604B;
  --brick-soft: #4A2620;
  --track: #2B3A50;
  --on-mustard: #0F172A;
}
body[data-accent="budget"] { --accent: var(--mustard); --accent-soft: var(--mustard-soft); --on-accent: var(--on-mustard); }
body[data-accent="cuisine"] { --accent: var(--green); --accent-soft: var(--green-soft); --on-accent: var(--on-green); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  font-optical-sizing: auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, .amount-display, .hero-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.block { display: block; }
.mono-free { font-family: var(--font); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip-link:focus { top: 8px; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 8px 0 20px;
  padding-top: env(safe-area-inset-top);
  background: #14213D; color: #F5F7FA;
}
.brand { font-weight: 700; font-size: 1.25rem; letter-spacing: -0.01em; }
.topbar-settings { color: #F5F7FA; }
.topbar-settings[aria-current="page"] { color: var(--accent); }
.topbar :focus-visible { outline-color: #F5F7FA; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #14213D;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: #B7C0D3; text-decoration: none; font-size: 0.78rem; min-height: 44px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tab:focus-visible { outline-color: #F5F7FA; outline-offset: -4px; }

/* ---------- Écrans ---------- */
main { display: block; outline: none; }
.screen { padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.lead { font-size: 1.35rem; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.lead.is-over .num { color: var(--brick); }
.h-section { font-size: 1.05rem; font-weight: 600; margin-top: 4px; }
.h-small { font-size: 1rem; font-weight: 600; margin: 12px 0 6px; }
.date-line { font-size: 0.9rem; }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.empty-line { padding: 4px 0; }
.streak { padding-top: 4px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 2px solid transparent;
  font-weight: 600; text-decoration: none; text-align: center;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-tall { min-height: 56px; font-size: 1.05rem; }
.btn-sm { min-height: 44px; padding: 6px 12px; font-size: 0.95rem; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-danger { background: var(--brick); color: #fff; }
.btn-danger-outline { background: transparent; color: var(--brick); border-color: var(--brick); }
/* Le seul élément qui mélange budget et cuisine. */
.btn-validate { background: var(--green); color: #fff; border-color: var(--mustard); box-shadow: inset 0 -5px 0 var(--mustard); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: inherit;
}
.btn-icon:disabled { opacity: 0.35; cursor: not-allowed; }
.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; text-align: left; }
.link.small { font-size: 0.9rem; font-weight: 500; }
a.link { display: inline; min-height: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.row-actions.center { justify-content: center; }
.row-actions > .btn { flex: 1 1 auto; }

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; min-width: 0; }
.field-row { display: flex; gap: 12px; }
.field-date { flex: 0 1 46%; }
label { font-weight: 600; font-size: 0.95rem; }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--ink);
}
textarea.input { resize: vertical; line-height: 1.4; }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.input:focus-visible { border-color: var(--accent); }
.input-big { font-size: 1.6rem; min-height: 60px; }
.form-error { color: var(--brick); font-weight: 500; }
.form-error ul { list-style: disc; padding-left: 20px; margin-top: 4px; }
.summary { padding: 10px 12px; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; }

/* ---------- Jauges ---------- */
.hero { padding: 6px 0 4px; display: flex; flex-direction: column; gap: 10px; }
.hero-text { font-size: 1.15rem; font-weight: 400; line-height: 1.3; }
.hero-amount { display: block; font-size: 3.2rem; line-height: 1.05; letter-spacing: -0.02em; color: var(--ink); }
.hero.is-over .hero-amount { color: var(--brick); }
.gauge { width: 100%; background: var(--track); border-radius: 999px; overflow: hidden; }
.gauge-large { height: 22px; }
.gauge-small { height: 10px; }
.gauge-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 450ms cubic-bezier(.2,.7,.2,1); }
.gauge.is-over .gauge-fill { background: var(--brick); }
.mini-gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.mini-label { font-size: 0.9rem; line-height: 1.3; }
.mini.is-over .mini-label strong { color: var(--brick); }
@media (max-width: 360px) { .mini-gauges { grid-template-columns: 1fr; } }

/* ---------- Liste de dépenses ---------- */
.expense-list { display: flex; flex-direction: column; gap: 6px; }
.expense-row { position: relative; overflow: hidden; border-radius: 12px; max-height: 120px; transition: max-height 300ms ease, opacity 300ms ease; }
.expense-row::before {
  content: 'Supprimer'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end;
  padding-right: 18px; background: var(--brick); color: #fff; font-weight: 600;
}
.expense-row.is-removing { max-height: 0; opacity: 0; }
.expense-inner { position: relative; display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; touch-action: pan-y; }
.swipe-ready .expense-inner { border-color: var(--brick); }
.expense-main { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 4px 8px 14px; background: none; border: 0; text-align: left; border-radius: 12px 0 0 12px; min-width: 0; }
.expense-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.expense-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-cat { font-size: 0.85rem; }
.expense-amount { font-size: 1.05rem; }
.chip-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--chip, var(--muted)); flex: none; }
.expense-delete { color: var(--muted); }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; }
.day-head.is-over .day-total { color: var(--brick); }
.over-mark { font-weight: 500; font-size: 0.85rem; }

/* ---------- Filtres et barres ---------- */
.filters { display: flex; gap: 12px; }
.bars { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.bar-head { display: flex; justify-content: space-between; font-size: 0.95rem; margin-bottom: 4px; }
.bar-track { height: 10px; background: var(--track); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }

/* ---------- Zones (Menus, Courses, Réglages) ---------- */
.zone { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.zone-title { font-size: 1.05rem; font-weight: 600; padding: 14px 16px; cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.zone-title::-webkit-details-marker { display: none; }
details > .zone-title::after { content: ''; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; }
details[open] > .zone-title::after { transform: rotate(-135deg); }
.zone-open .zone-title { border-bottom: 1px solid var(--border); cursor: default; }
.zone-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.prompt-fallback { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Menus ---------- */
.week-head { display: flex; flex-direction: column; gap: 6px; }
.validated-line { padding: 8px 12px; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; }
.day-cards { display: flex; flex-direction: column; gap: 10px; }
.day-card { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--accent); border-radius: 12px; padding: 4px 0 6px; }
.day-name { font-size: 1rem; font-weight: 700; padding: 8px 14px 4px; }
.meal { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; min-height: 52px; background: none; border: 0; text-align: left; border-radius: 8px; }
.meal-empty { color: var(--muted); }
.meal-moment { flex: none; width: 44px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.meal-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.meal-name { font-weight: 600; }
.meal-chevron { color: var(--muted); }
.tips { display: flex; flex-direction: column; gap: 6px; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; }
.plain-list { display: flex; flex-direction: column; gap: 6px; padding-left: 0; }
.plain-list li { padding-left: 14px; position: relative; }
.plain-list li::before { content: ''; position: absolute; left: 0; top: 0.65em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.steps { list-style: decimal; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.history { display: flex; flex-direction: column; gap: 14px; }
.history-item { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

/* ---------- Courses ---------- */
.shop-head { display: flex; flex-direction: column; gap: 4px; }
.rayon { display: flex; flex-direction: column; gap: 8px; }
.shop-list { display: flex; flex-direction: column; gap: 6px; }
.shop-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px 12px 6px 8px; }
.shop-main { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check { width: 24px; height: 24px; flex: none; accent-color: var(--accent); margin: 0 4px; }
.shop-label { flex: 1; font-weight: 500; position: relative; padding: 8px 0; min-width: 0; }
.shop-name { position: relative; }
.shop-name::after { content: ''; position: absolute; left: 0; right: 0; top: 55%; height: 2px; background: currentColor; transform: scaleX(0); transform-origin: left; transition: transform 250ms ease; }
.is-checked .shop-name::after { transform: scaleX(1); }
.is-checked .shop-label { color: var(--muted); }
.is-unavailable .shop-name { color: var(--muted); }
.tag-unavailable { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--brick-soft); color: var(--brick); font-size: 0.8rem; font-weight: 600; }
.shop-sub { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-left: 42px; margin-top: -6px; min-height: 32px; }
.shop-sub .link { min-height: 36px; }

/* ---------- Réglages ---------- */
.rows { display: flex; flex-direction: column; gap: 6px; }
.row-item { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.row-text { flex: 1; min-width: 0; }
.row-item .input { flex: 1; }
.color { width: 44px; height: 44px; padding: 0; border: 1.5px solid var(--border); border-radius: 10px; background: none; flex: none; }
.switch { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 48px; height: 28px; border-radius: 999px; background: var(--track); position: relative; flex: none; transition: background 200ms ease; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform 200ms ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent); outline-offset: 2px; }
.segmented { display: flex; border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 46px; font-weight: 600; }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- Feuilles (dialog) ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh;
  background: var(--bg); color: var(--ink); display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(20, 33, 61, 0.55); }
@media (min-width: 640px) {
  dialog.sheet { width: 560px; height: auto; max-height: 92dvh; margin: auto; border-radius: 16px; }
}
/* Feuille basse : hauteur au contenu (inset 0 du dialog modal → on ancre en bas). */
dialog.sheet-compact { height: fit-content; max-height: 92dvh; top: auto; bottom: 0; border-radius: 16px 16px 0 0; }
@media (min-width: 640px) { dialog.sheet-compact { top: 0; margin: auto; border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 8px 20px; padding-top: max(12px, env(safe-area-inset-top)); }
.sheet-title { font-size: 1.2rem; font-weight: 700; }
.sheet-body { flex: 1; overflow: auto; padding: 4px 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 20px; padding-bottom: max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.sheet-foot .btn { flex: 1; }
.sheet-foot .btn-secondary { flex: 0 1 auto; }

/* Feuille de saisie */
.expense-body { gap: 12px; }
.amount-display { display: block; font-size: 2.8rem; line-height: 1.1; text-align: right; padding: 8px 0; letter-spacing: -0.02em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); font-weight: 500; }
.chip[aria-checked="true"] { border-color: var(--chip); background: color-mix(in srgb, var(--chip) 16%, var(--surface)); font-weight: 600; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: auto; }
.key { min-height: 60px; font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); display: flex; align-items: center; justify-content: center; }
.key:active { background: var(--accent-soft); }
.key-del { color: var(--muted); }

/* ---------- Premier lancement ---------- */
.screen-onboarding { min-height: calc(100dvh - 52px); justify-content: center; gap: 24px; }
.onboarding-head { text-align: center; }
.brand-big { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.onboarding-body > div { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); z-index: 60; display: flex; justify-content: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; max-width: 480px; text-align: center; }
:root[data-theme="dark"] .toast { background: #E2E8F0; color: #0F172A; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
