/* Planning repas — styles */
:root {
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --surface-2: #F5EFE8;
  --ink: #2B2420;
  --muted: #8A7F76;
  --line: #EDE5DC;
  --accent: #E2603B;
  --accent-ink: #FFFFFF;
  --accent-soft: #FCE6DE;
  --midi: #E39A1F;
  --soir: #5B5FC7;
  --restes: #B7791F;
  --restes-soft: #FBF0DC;
  --resto: #2F7FB8;
  --resto-soft: #E2F0FA;
  --absent: #9A928B;
  --ok: #4F8A44;
  --danger: #C8402E;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 4px 14px rgba(60, 40, 20, .06);
  --shadow-lg: 0 12px 40px rgba(40, 25, 10, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1613;
    --surface: #25201C;
    --surface-2: #2E2823;
    --ink: #F3ECE6;
    --muted: #A39689;
    --line: #3A322C;
    --accent: #F07850;
    --accent-soft: #46291F;
    --restes-soft: #3E3019;
    --resto-soft: #1C3343;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; flex: none; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .6; } }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink);
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, .field input, .field select {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 17px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 18px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.alert { background: var(--accent-soft); color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin: 0 0 14px; }
.hint { color: var(--muted); font-size: 14px; }

/* ---------- Connexion / installation ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 20px 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 24px; padding: 32px 26px; box-shadow: var(--shadow);
}
.auth-logo { display: block; margin: 0 auto 14px; border-radius: 16px; }
.auth-card h1 { font-family: var(--font-round); text-align: center; font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.auth-card .lead { text-align: center; color: var(--muted); margin: 0 0 24px; }

/* ---------- Structure ---------- */
.layout { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.brand { display: none; align-items: center; gap: 10px; font-family: var(--font-round); font-weight: 800; font-size: 19px; margin-right: 14px; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.week-title { flex: 1; min-width: 0; }
.week-title .kicker { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.week-title h1 { margin: 0; font-family: var(--font-round); font-size: 22px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-title { margin: 0; flex: 1; font-family: var(--font-round); font-size: 26px; letter-spacing: -.02em; }
.week-nav { display: flex; gap: 8px; align-items: center; }

.progress { max-width: 1400px; margin: 8px auto 0; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.progress-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s ease; }
.today-pill { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; }

.content { max-width: 1400px; margin: 0 auto; padding: 8px 16px 0; }

/* ---------- Semaine ---------- */
.week { display: grid; gap: 12px; grid-template-columns: 1fr; }
.week.anim-next { animation: slideNext .25s ease; }
.week.anim-prev { animation: slidePrev .25s ease; }
@keyframes slideNext { from { opacity: 0; transform: translateX(30px); } }
@keyframes slidePrev { from { opacity: 0; transform: translateX(-30px); } }

.day { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1.5px solid transparent; }
.day.is-today { border-color: var(--accent); }
.day.is-past { opacity: .62; }
.day-head { display: flex; align-items: baseline; gap: 8px; padding: 12px 16px 4px; }
.day-name { font-family: var(--font-round); font-weight: 800; font-size: 17px; }
.day-date { color: var(--muted); font-size: 14px; }
.day-badge { margin-left: auto; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); background: var(--accent); padding: 3px 8px; border-radius: 999px; }
.day-badge.shop { background: var(--ok); }

.slot {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 16px; min-height: 58px;
  background: none; border: 0; text-align: left;
  border-top: 1px solid var(--line);
}
.day-head + .slot { border-top: 0; }
.slot:active { background: var(--surface-2); }
@media (hover: hover) { .slot:hover { background: var(--surface-2); } }
.slot-ico { flex: none; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; }
.slot-ico svg { width: 18px; height: 18px; }
.slot[data-slot="midi"] .slot-ico { background: color-mix(in srgb, var(--midi) 16%, transparent); color: var(--midi); }
.slot[data-slot="soir"] .slot-ico { background: color-mix(in srgb, var(--soir) 16%, transparent); color: var(--soir); }
.slot-body { flex: 1; min-width: 0; }
.slot-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.slot-meal { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.slot-meal.is-empty { color: var(--muted); font-weight: 400; }
.slot-note { font-size: 13px; color: var(--muted); margin-top: 1px; overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 6px; margin-right: 6px; vertical-align: 2px; }
.tag.restes { background: var(--restes-soft); color: var(--restes); }
.tag.resto { background: var(--resto-soft); color: var(--resto); }
.tag.absent { background: var(--surface-2); color: var(--absent); }
.slot.kind-absent .slot-meal { color: var(--muted); font-weight: 500; }
.slot-chev { color: var(--line); flex: none; }
.slot-chev svg { width: 18px; height: 18px; }

.placing .slot { outline: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -5px; border-radius: 12px; }
.placing .slot.is-source { outline-style: solid; background: var(--accent-soft); }

.empty-week {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.empty-week p { margin: 0; flex: 1; min-width: 180px; font-size: 15px; }

/* Bandeau « placer un plat » */
.placebar {
  position: fixed; left: 12px; right: 12px; z-index: 40;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: var(--bg); padding: 10px 10px 10px 16px;
  border-radius: 16px; box-shadow: var(--shadow-lg); font-size: 15px;
}
.placebar span { flex: 1; }
.placebar > svg { color: var(--accent); }
.placebar .btn { min-height: 36px; background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, transparent); }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* ---------- Feuille d'édition (bottom sheet) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 12, 6, .38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--safe-top) - 24px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(16px + var(--safe-bottom));
  animation: up .24s cubic-bezier(.2, .9, .3, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex: none; }
.sheet-head h2 { flex: 1; margin: 0; font-family: var(--font-round); font-size: 20px; letter-spacing: -.01em; }
.sheet-head h2 small { display: block; font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.sheet-body { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -18px; padding: 0 18px; }
.sheet-foot { display: flex; gap: 8px; padding-top: 14px; flex: none; flex-wrap: wrap; }
.sheet-foot .spacer { flex: 1; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; margin-bottom: 14px; }
.seg button { border: 0; background: none; min-height: 38px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.meal-input { font-size: 18px !important; font-weight: 600; }
.sugg-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 14px 0 6px; }
.sugg { list-style: none; margin: 0; padding: 0; }
.sugg li button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 11px 12px; min-height: 48px; border: 0; background: none; border-radius: 12px; font-size: 16px;
}
.sugg li button:active, .sugg li button.active { background: var(--surface-2); }
@media (hover: hover) { .sugg li button:hover { background: var(--surface-2); } }
.sugg li button .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sugg li button mark { background: none; color: var(--accent); font-weight: 700; }
.sugg li button .meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sugg li button.new { color: var(--accent); }
.sugg li button.new .name { font-weight: 600; }
.note-toggle { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 10px 0; font-size: 15px; }

/* ---------- Plats & réglages ---------- */
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search .input { padding-left: 42px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; min-height: 58px; border: 0; background: none; text-align: left; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row:active { background: var(--surface-2); }
@media (hover: hover) { button.list-row:hover { background: var(--surface-2); } }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; overflow-wrap: anywhere; }
.list-row .sub { font-size: 13px; color: var(--muted); }
.count { min-width: 30px; height: 30px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty svg { width: 42px; height: 42px; opacity: .5; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 22px 4px 8px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.actions-list .list-row { font-weight: 600; }
.actions-list .list-row.danger { color: var(--danger); }
.muted { color: var(--muted); }
.settings-grid { display: grid; gap: 0 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 600; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
  animation: up .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Grands écrans ---------- */
@media (min-width: 720px) {
  .week { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 24px; padding-bottom: 18px; max-height: min(720px, calc(100dvh - 48px)); }
  .sheet-grip { display: none; }
  .settings-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (min-width: 980px) {
  :root { --tabbar-h: 0px; }
  .layout { padding-bottom: 32px; }
  .brand { display: flex; }
  .tabbar {
    position: sticky; top: 0; bottom: auto; height: 56px; padding: 0 24px;
    justify-content: flex-start; gap: 4px; border-top: 0; border-bottom: 1px solid var(--line);
    background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .tabbar button { flex: none; display: flex; gap: 8px; font-size: 15px; padding: 0 16px; border-radius: 10px; margin: 8px 0; }
  .tabbar button svg { width: 20px; height: 20px; }
  .tabbar button[aria-current="page"] { background: var(--accent-soft); }
  .topbar { position: static; padding: 20px 24px 6px; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .content { padding: 12px 24px 0; }
  .placebar, .toast { bottom: 24px; }
}

@media (min-width: 1240px) {
  .week { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
  .week .slot { flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px 14px; min-height: 104px; }
  .week .slot-chev { display: none; }
  .week .slot-ico { width: 28px; height: 28px; border-radius: 9px; }
  .week .day-head { flex-wrap: wrap; padding: 12px 14px 4px; }
  .week .day-badge { margin-left: 0; }
  .week .slot-meal { font-size: 15px; }
}

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