/* =====================================================================
   Morgan Suivi — style.css
   Design system : sportif / premium, inspiré Strava · Garmin · Apple Fitness
   Rouge orangé principal #F4511E — mode clair par défaut, mode sombre inclus
   ===================================================================== */

:root {
  /* Marque */
  --c-primary: #F4511E;
  --c-primary-ink: #ffffff;
  --c-secondary: #FF8A3D;
  --c-success: #2E7D32;
  --c-warning: #F9A825;
  --c-error: #C62828;

  /* Sports */
  --c-swim: #0288D1;
  --c-bike: #2E7D32;
  --c-run: #F4511E;
  --c-muscu: #6A1B9A;
  --c-brick: #00838F;

  /* Surfaces — clair */
  --bg: #f4f5f7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --ink: #1c2024;
  --ink-2: #454c54;
  --muted: #7b838d;
  --line: #e5e8ec;
  --line-2: #eef0f3;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.16);

  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 22px;
  --sidebar-w: 244px;
  --topbar-h: 58px;
  --grad: linear-gradient(135deg, #F4511E 0%, #FF8A3D 100%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0f1215;
  --bg-elev: #171b20;
  --card: #1a1f25;
  --ink: #e9ecef;
  --ink-2: #b9c0c8;
  --muted: #8a929c;
  --line: #2a313a;
  --line-2: #232a32;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.55);
  --c-primary-ink: #16191c;
  --c-run: #ff6a3d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--c-primary); }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}
.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 6px;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 16px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad); color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.brand-name { font-weight: 750; font-size: 16px; letter-spacing: -.2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 14.5px;
  transition: background .12s, color .12s;
}
.nav a .ic { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--line-2); color: var(--ink); }
.nav a.active { background: color-mix(in srgb, var(--c-primary) 12%, transparent); color: var(--c-primary); }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.profile-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px; background: var(--line-2);
  font-size: 13px;
}
.profile-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--grad); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.profile-chip b { display: block; color: var(--ink); }
.profile-chip span { color: var(--muted); }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 18px; font-weight: 750; letter-spacing: -.3px; flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-elev);
  font-size: 20px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.95); }
#menuBtn { display: none; }

/* ---------- View ---------- */
.view {
  flex: 1; overflow-y: auto;
  padding: 20px;
  padding-bottom: 40px;
  scroll-behavior: smooth;
}
.page { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.page-head h2 { font-size: 20px; font-weight: 780; letter-spacing: -.3px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.section-title { font-size: 15px; font-weight: 750; margin-bottom: 2px; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 14px; font-weight: 700; color: var(--ink-2); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card h3 .ic { width: 16px; height: 16px; }

.hero {
  background: var(--grad);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.hero .eyebrow { text-transform: uppercase; letter-spacing: 1.4px; font-size: 11px; font-weight: 700; opacity: .9; }
.hero .big { font-size: 30px; font-weight: 820; letter-spacing: -.5px; margin: 4px 0 2px; }
.hero .sub { opacity: .92; font-size: 14px; }
.hero .hero-row { display: flex; gap: 22px; margin-top: 16px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero .hero-row div b { display: block; font-size: 20px; font-weight: 800; }
.hero .hero-row div span { font-size: 12px; opacity: .9; }

/* Stat tiles */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin-top: 4px; }
.stat .value small { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat .delta { font-size: 12px; font-weight: 700; margin-top: 2px; }
.delta.up { color: var(--c-success); }
.delta.down { color: var(--c-error); }

/* ---------- Chips / tags ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .2px;
  background: var(--line-2); color: var(--ink-2);
}
.tag.ok { background: color-mix(in srgb, var(--c-success) 16%, transparent); color: var(--c-success); }
.tag.warn { background: color-mix(in srgb, var(--c-warning) 20%, transparent); color: #8a6d05; }
.tag.err { background: color-mix(in srgb, var(--c-error) 14%, transparent); color: var(--c-error); }
html[data-theme="dark"] .tag.warn { color: var(--c-warning); }
.badge-active {
  background: var(--grad); color: #fff; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
}

/* ---------- Progress ---------- */
.progress { height: 9px; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--grad); }
.progress-row { display: flex; flex-direction: column; gap: 6px; }
.progress-row .pr-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--ink);
  font-weight: 650; font-size: 14px; cursor: pointer;
  transition: transform .08s, background .12s, border-color .12s;
  white-space: nowrap;
}
.btn .ic { width: 16px; height: 16px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--c-primary) 90%, #000); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--line-2); }
.btn-danger { color: var(--c-error); border-color: color-mix(in srgb, var(--c-error) 40%, var(--line)); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; justify-content: center; }
.action-bar { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Entry list ---------- */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group-title { font-size: 13px; font-weight: 750; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-top: 6px; }
.entry {
  display: flex; align-items: stretch; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--accent, var(--c-primary));
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}
.entry.warn-row { border-left-color: var(--c-warning); }
.entry-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.entry-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-title { font-weight: 720; font-size: 15px; }
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.stat-row b { color: var(--ink); font-weight: 750; }
.entry-actions { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.entry-actions button {
  width: 32px; height: 32px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg-elev);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.entry-actions button:hover { color: var(--c-primary); border-color: var(--c-primary); }
.entry-actions button .ic { width: 15px; height: 15px; }

.empty {
  text-align: center; color: var(--muted);
  padding: 44px 16px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty .ic { width: 30px; height: 30px; opacity: .5; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.field input[type=text], .field input[type=number], .field input[type=date],
.field input[type=time], .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 18%, transparent);
}
.field textarea { min-height: 74px; resize: vertical; }
.field .range-wrap { display: flex; align-items: center; gap: 12px; }
.field input[type=range] { flex: 1; accent-color: var(--c-primary); }
.field .range-val { font-weight: 800; min-width: 26px; text-align: right; }
.field-check { flex-direction: row; align-items: center; gap: 10px; }
.field-check input { width: 18px; height: 18px; accent-color: var(--c-primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 12px; color: var(--muted); }

/* Ingredient repeater */
.ingr-rows { display: flex; flex-direction: column; gap: 8px; }
.ingr-row { display: grid; grid-template-columns: 1fr 74px 80px 34px; gap: 6px; }
.ingr-row input, .ingr-row select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.ingr-row button { border: 1px solid var(--line); border-radius: 8px; background: var(--bg-elev); cursor: pointer; }

/* ---------- Modal ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(12,16,20,.5);
  z-index: 60; backdrop-filter: blur(2px);
}
.modal {
  position: fixed; z-index: 70;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; font-weight: 760; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1; justify-content: center; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--bg-elev);
  padding: 10px 16px; border-radius: 999px;
  font-weight: 650; font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .18s ease-out;
}
.toast.success { background: var(--c-success); color: #fff; }
.toast.error { background: var(--c-error); color: #fff; }
.toast.warning { background: var(--c-warning); color: #241c00; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Charts ---------- */
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 8px; box-shadow: var(--shadow); }
.chart-card .chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.chart-card .chart-head h3 { font-size: 14px; font-weight: 730; }
.chart-card .chart-head .now { font-size: 18px; font-weight: 820; }
.chart-card canvas { width: 100%; display: block; }
.chart-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ---------- Cuisine grid ---------- */
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-nav .wk { font-weight: 720; flex: 1; text-align: center; }
.cuisine-table { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.cuisine-table table { border-collapse: collapse; width: 100%; min-width: 720px; }
.cuisine-table th, .cuisine-table td { border: 1px solid var(--line-2); padding: 8px; vertical-align: top; text-align: left; font-size: 13px; }
.cuisine-table th { background: var(--line-2); font-weight: 700; position: sticky; top: 0; }
.cuisine-table td .slot { min-height: 30px; cursor: pointer; border-radius: 6px; padding: 4px; }
.cuisine-table td .slot:hover { background: var(--line-2); }
.cuisine-table .meal { background: color-mix(in srgb, var(--c-primary) 10%, transparent); border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; }
.cuisine-table .meal.done { opacity: .55; text-decoration: line-through; }

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 650; text-align: right; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.pill-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.pill-toggle button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-weight: 650; font-size: 13px; }
.pill-toggle button.on { background: var(--c-primary); color: #fff; }
.list-plain { display: flex; flex-direction: column; gap: 8px; }
.row-check { display: flex; align-items: center; gap: 10px; }
.row-check input { width: 18px; height: 18px; accent-color: var(--c-primary); }
.row-check.done span { text-decoration: line-through; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 65; inset: 0 auto 0 0;
    width: 270px; transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  #menuBtn { display: grid; }
  .view { padding: 16px; padding-bottom: 90px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; text-decoration: none; color: var(--muted);
    font-size: 10.5px; font-weight: 650;
  }
  .bottom-nav a .ic { width: 21px; height: 21px; }
  .bottom-nav a.active { color: var(--c-primary); }
  .form-grid { grid-template-columns: 1fr; }
  .hero .big { font-size: 25px; }
  .modal {
    top: auto; bottom: 0; transform: none; left: 0;
    width: 100%; max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}
@media (max-width: 380px) {
  .ingr-row { grid-template-columns: 1fr 60px 62px 30px; }
}
