/* ---------------------------------------------------------------------------
   Suivi — feuille de style unique. Mobile d'abord, thème clair/sombre auto.
   --------------------------------------------------------------------------- */

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef1f2;
  --text: #16211f;
  --text-muted: #5b6b68;
  --border: #d9dfde;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --surface: #172020;
    --surface-2: #1e2a29;
    --text: #e7ecea;
    --text-muted: #9aa8a4;
    --border: #2b3a38;
    --accent: #2dd4bf;
    --accent-contrast: #05201d;
    --danger: #ff6b5e;
    --danger-bg: #2a1512;
    --ok: #4ade80;
    --ok-bg: #10231a;
    --warn: #fbbf5a;
    --warn-bg: #241a0c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); }

h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }

.muted { color: var(--text-muted); }
.small { font-size: .875rem; }

/* --- En-tête / navigation --- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: block;
  padding: .7rem 1rem .3rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: 0 .5rem .4rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-nav::-webkit-scrollbar { display: none; }

.app-nav > a {
  flex: 0 0 auto;
  padding: .45rem .7rem;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .95rem;
  white-space: nowrap;
}
.app-nav > a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.app-menu { position: relative; flex: 0 0 auto; margin-left: auto; }
.app-menu > summary {
  list-style: none;
  cursor: pointer;
  padding: .45rem .7rem;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: .95rem;
}
.app-menu > summary::-webkit-details-marker { display: none; }
.app-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .3rem);
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .3rem;
  display: flex;
  flex-direction: column;
}
.app-menu-panel a {
  padding: .55rem .6rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.app-menu-panel a:hover { background: var(--surface-2); }

/* --- Structure de page --- */

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.app-footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  color: var(--text-muted);
  font-size: .85rem;
}

.app-disclaimer {
  margin-top: 2rem;
  padding: .7rem .9rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .85rem;
}

/* --- Cartes --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card-list { display: grid; gap: .6rem; }

/* --- Boutons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.btn-block { display: flex; width: 100%; }
.btn-lg { padding: 1rem 1.2rem; font-size: 1.05rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; }

/* Grille de raccourcis sur l'accueil */
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .7rem;
  margin-bottom: 1.5rem;
}
.quick-grid .btn { min-height: 76px; flex-direction: column; text-align: center; }
@media (max-width: 380px) { .quick-grid { grid-template-columns: 1fr; } }

/* --- Formulaires --- */

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; }
.field .hint { font-weight: 400; color: var(--text-muted); font-size: .85rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: .65rem .7rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.checkbox-row { display: flex; align-items: center; gap: .5rem; }
.checkbox-row input { width: auto; min-height: 0; }

/* --- Curseur de douleur 0–10 --- */

.pain-slider { display: flex; align-items: center; gap: 1rem; }
.pain-slider input[type="range"] { flex: 1; }
.pain-value {
  font-size: 1.6rem;
  font-weight: 700;
  min-width: 2.2ch;
  text-align: center;
}

/* --- Messages flash --- */

.flash {
  padding: .7rem .9rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.flash-info    { background: var(--surface-2); }
.flash-success { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok); }
.flash-error   { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.flash-warn    { background: var(--warn-bg);   color: var(--warn);   border-color: var(--warn); }

/* --- Badges / puces --- */

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-pain { background: var(--danger-bg); color: var(--danger); }
.badge-ok   { background: var(--ok-bg);     color: var(--ok); }
.badge-warn { background: var(--warn-bg);   color: var(--warn); }

/* --- Tableaux --- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
table.data th { color: var(--text-muted); font-size: .85rem; }

/* --- Écran de connexion --- */

.auth-wrap {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 1rem;
}
.auth-wrap h1 { text-align: center; }

/* --- En-tête de page avec bouton --- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: .2rem 0; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 420px) { .row-2 { grid-template-columns: 1fr; } }

.btn.small { min-height: 0; padding: .35rem .6rem; font-size: .85rem; }

/* --- Formulaire repas : lignes d'aliments --- */

fieldset.items {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem;
  margin: 0 0 1rem;
}
fieldset.items legend { font-weight: 600; padding: 0 .3rem; }

.item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: .4rem;
  padding: .5rem 0;
  border-bottom: 1px dashed var(--border);
}
.item-row:last-of-type { border-bottom: 0; }
@media (min-width: 560px) {
  .item-row { grid-template-columns: 2fr 1fr auto; align-items: start; }
}

.item-qty, .item-cook { min-height: 40px; }

/* --- Champ avec autocomplétion --- */

.food-field { position: relative; }
.food-field .food-input { padding-right: 2rem; }
.food-status {
  position: absolute;
  right: .6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ok);
  font-weight: 700;
  pointer-events: none;
}
.food-field.matched .food-input { border-color: var(--ok); }

.ac-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  margin: 0;
  padding: .25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
}
.ac-list li {
  padding: .55rem .6rem;
  border-radius: 8px;
  cursor: pointer;
}
.ac-list li.active,
.ac-list li:hover { background: var(--surface-2); }

/* --- Cartes de repas --- */

.meal-card { display: block; color: inherit; text-decoration: none; }
.meal-card:hover { background: var(--surface-2); }
.meal-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .6rem;
  margin-bottom: .3rem;
}
.meal-card-items { color: var(--text); }

/* --- À rattacher --- */

.unmatched-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  margin-bottom: .5rem;
}
.unmatched-form .food-field { margin-bottom: .5rem; }

/* --- Analyse --- */

.factor {
  padding: .7rem 0;
  border-bottom: 1px solid var(--border);
}
.factor:last-child { border-bottom: 0; }
.factor-head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.factor-stats { color: var(--text-muted); margin: .3rem 0; }
.factor-bars { display: grid; gap: .25rem; max-width: 320px; }

.bar {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill { display: block; height: 100%; border-radius: 999px; }
.bar-ex { background: var(--danger); }
.bar-un { background: var(--text-muted); }

.dot {
  display: inline-block;
  width: .7rem; height: .7rem;
  border-radius: 50%;
  vertical-align: middle;
}
.dot-ex { background: var(--danger); }
.dot-un { background: var(--text-muted); }

details.card > summary { cursor: pointer; }
details.card > summary > strong { font-weight: 600; }

/* --- Rapport imprimable --- */

.report h2 { border-bottom: 1px solid var(--border); padding-bottom: .2rem; }
.report-head h1 { margin-bottom: .2rem; }
.report-pain { margin: .6rem 0; padding-left: .6rem; border-left: 3px solid var(--border); }
.report-pain-head { margin: 0 0 .3rem; }
.report-meals { margin: .2rem 0; padding-left: 1.2rem; }
.report-meals li { margin: .15rem 0; }
.report-footer { margin-top: 1.5rem; color: var(--text-muted); }

@media print {
  .app-header, .app-footer, .app-disclaimer, .no-print { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 12px; }
  .card { border: 1px solid #bbb; box-shadow: none; background: #fff; }
  a { color: #000; text-decoration: none; }
  h1 { font-size: 18px; }
  h2 { font-size: 14px; }
  table.data th, table.data td { border-bottom: 1px solid #ccc; }
  .report-pain { break-inside: avoid; }
  .muted, .text-muted { color: #444 !important; }
}
@page { margin: 1.5cm; }
