/* app.css — Système de design mobile-first, mode clair/sombre.
   Priorités UX : cibles tactiles 48px, hiérarchie claire, feedback, offline. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e4e7ec;
  --text: #101828;
  --text-2: #667085;
  --text-3: #98a2b3;
  --brand: #16a34a;
  --brand-ink: #ffffff;
  --brand-soft: #dcfce7;
  --protein: #f43f5e;
  --carbs: #f59e0b;
  --fat: #3b82f6;
  --kcal: #16a34a;
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.16);
  --r: 16px; --r-sm: 10px; --r-lg: 22px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 64px;
  --maxw: 480px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", sans-serif;
}
:root[data-theme="dark"], :root:not([data-theme="light"]) {
  --bg: #0b0f14; --surface: #151b23; --surface-2: #1d242e; --border: #262f3a;
  --text: #f2f4f7; --text-2: #98a2b3; --text-3: #667085;
  --brand: #22c55e; --brand-soft: #14351f;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 40px rgba(0,0,0,.55);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:#f6f7f9; --surface:#fff; --surface-2:#f0f2f5; --border:#e4e7ec;
    --text:#101828; --text-2:#667085; --text-3:#98a2b3; --brand:#16a34a; --brand-soft:#dcfce7;
    --shadow:0 1px 2px rgba(16,24,40,.06),0 1px 3px rgba(16,24,40,.08); --shadow-lg:0 12px 32px rgba(16,24,40,.16);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.45; overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select { font: inherit; }
a { color: var(--brand); }

.app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; position: relative; background: var(--bg); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  display: flex; align-items: center; gap: 10px; padding: 12px 16px calc(12px);
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 800; letter-spacing: -.02em; flex: 1; }
.topbar .logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 900; font-size: 16px; }

/* Profile switcher (segmented) */
.pswitch { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.pswitch button { padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--text-2);
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; }
.pswitch button .dot { width: 8px; height: 8px; border-radius: 50%; }
.pswitch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Layout ---------- */
main { padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase;
  letter-spacing: .04em; margin: 22px 4px 10px; display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap);
  padding: 0 18px; border-radius: 12px; font-weight: 700; background: var(--surface-2); color: var(--text);
  transition: transform .06s, filter .15s; user-select: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn:disabled { opacity: .5; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.chip.on { background: var(--brand); color: #fff; }

/* ---------- Rings & macros ---------- */
.ring { --p: 0; width: 128px; height: 128px; }
.ring text { fill: var(--text); }
.macros { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.macro { background: var(--surface-2); border-radius: var(--r-sm); padding: 10px; text-align: center; }
.macro b { font-size: 16px; display: block; }
.macro span { font-size: 11px; color: var(--text-2); font-weight: 600; }
.macro.p b { color: var(--protein); } .macro.c b { color: var(--carbs); } .macro.f b { color: var(--fat); }

.bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--brand); transition: width .4s; }

/* ---------- Meal / recipe cards ---------- */
.meal { display: flex; gap: 12px; padding: 12px; align-items: center; }
.meal .thumb { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 22px; flex: none; }
.meal .info { flex: 1; min-width: 0; }
.meal .info .t { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .info .s { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.meal .kcal { font-weight: 800; font-size: 14px; }
.meal .kcal small { display: block; font-weight: 600; color: var(--text-2); font-size: 11px; text-align: right; }
.slot-label { font-size: 11px; font-weight: 800; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }

.recipe-card { overflow: hidden; }
.recipe-card .top { padding: 14px 14px 10px; }
.recipe-card .name { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.recipe-card .foot { display: flex; gap: 6px; padding: 0 14px 14px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.pill-kcal { font-weight: 800; }

/* Day header */
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 4px 8px; }
.day-head .d { font-weight: 800; font-size: 16px; }
.day-head .k { font-size: 13px; font-weight: 700; color: var(--text-2); }
.day-head .k.ok { color: var(--brand); }
.day-head .k.hi { color: var(--carbs); }

/* ---------- Shopping ---------- */
.shop-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; min-height: var(--tap); }
.shop-item .cbx { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--border); flex: none;
  display: grid; place-items: center; transition: .12s; }
.shop-item.done .cbx { background: var(--brand); border-color: var(--brand); }
.shop-item.done .cbx svg { opacity: 1; }
.shop-item .cbx svg { opacity: 0; width: 15px; height: 15px; color: #fff; }
.shop-item .nm { flex: 1; font-weight: 600; font-size: 14.5px; }
.shop-item.done .nm { text-decoration: line-through; color: var(--text-3); }
.shop-item .q { font-size: 13px; color: var(--text-2); font-weight: 700; white-space: nowrap; }
.aisle { font-size: 12px; font-weight: 800; color: var(--brand); text-transform: uppercase; letter-spacing: .04em;
  padding: 16px 6px 6px; display: flex; gap: 8px; align-items: center; }

/* ---------- Sheet (bottom modal) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; opacity: 0; transition: .2s;
  backdrop-filter: blur(2px); }
.scrim.open { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; background: var(--surface);
  border-radius: 22px 22px 0 0; max-width: var(--maxw); margin: 0 auto; transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,.72,0,1); max-height: 88vh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); box-shadow: var(--shadow-lg); }
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 10px auto 4px; flex: none; }
.sheet .sheet-head { display: flex; align-items: center; gap: 10px; padding: 6px 16px 12px; }
.sheet .sheet-head h3 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; }
.sheet .sheet-body { overflow-y: auto; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 700; font-size: 14px;
  z-index: 120; opacity: 0; transition: .25s; box-shadow: var(--shadow-lg); max-width: 90%; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: var(--maxw); margin: 0 auto; z-index: 50;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border); display: flex; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 10.5px; font-weight: 700; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--brand); }

/* ---------- Progress ring header (dashboard) ---------- */
.hero { display: flex; gap: 16px; align-items: center; }
.hero .ringwrap { position: relative; flex: none; }
.hero .ringwrap .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.hero .ringwrap .center b { font-size: 26px; font-weight: 800; line-height: 1; }
.hero .ringwrap .center span { font-size: 11px; color: var(--text-2); font-weight: 600; }

/* Motivation banner */
.motiv { background: linear-gradient(135deg, var(--brand), #0ea5e9); color: #fff; border-radius: var(--r);
  padding: 16px; font-weight: 700; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.motiv .k { font-size: 12px; opacity: .85; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.motiv .m { font-size: 15px; line-height: 1.4; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; display: block; }
.field input, .field select { width: 100%; min-height: var(--tap); padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 700; font-size: 13.5px; min-width: 72px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Weight sparkline */
.spark { width: 100%; height: 64px; }

.empty { text-align: center; color: var(--text-2); padding: 40px 20px; }
.empty .e-ic { font-size: 40px; margin-bottom: 8px; }

.offline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }

.hidden { display: none !important; }
.center { text-align: center; }
.spin { animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
