:root {
  --navy: #14234b; --navy2: #1f3570; --accent: #e63950; --teal: #0e9f9a;
  --bg: #f3f5fa; --card: #fff; --text: #1b2238; --muted: #6b7390; --line: #e3e7f0;
  --ok: #1f9d55; --low: #e0a100; --high: #e8590c; --hypo: #d6273f; --vhigh: #9b1c31;
  --radius: 14px; --shadow: 0 2px 10px rgba(20, 35, 75, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
a { color: var(--navy2); }
h1 { font-size: 1.4rem; margin: .4rem 0; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 .7rem; color: var(--navy); }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.center-view { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.big-logo { width: 84px; height: 84px; border-radius: 20px; }
.auth-card { background: var(--card); padding: 26px 22px; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 380px; text-align: center; }
.auth-card label { text-align: left; }

label { display: block; font-size: .88rem; color: var(--muted); margin: 10px 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
input, select, textarea { font: inherit; color: var(--text); width: 100%; padding: 10px 12px; margin-top: 4px; border: 1px solid #cfd5e3; border-radius: 10px; background: #fff; }
label.inline input { width: auto; margin: 0; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); border-color: transparent; }
.pw { position: relative; display: block; }
.pw input { padding-right: 44px; }
.eye { position: absolute; right: 4px; top: 8px; border: 0; background: none; font-size: 1.1rem; padding: 6px 8px; cursor: pointer; opacity: .6; }
.eye.on { opacity: 1; }
.error { color: var(--hypo); min-height: 1em; font-size: .9rem; margin: 6px 0; }
.info { color: var(--navy2); font-size: .9rem; margin: 4px 0; }
.info:empty, .error:empty { display: none; }

.btn { font: inherit; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; background: #e7eaf3; color: var(--navy); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.danger { background: var(--hypo); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid #cfd5e3; }
.btn.wide { width: 100%; margin-top: 8px; padding: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.big { flex: 1; flex-direction: column; padding: 18px 10px; font-size: 1.05rem; color: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.btn.big .ico { font-size: 1.8rem; }
.btn.big.weight { background: linear-gradient(135deg, var(--navy2), var(--navy)); }
.btn.big.glucose { background: linear-gradient(135deg, #f0586c, var(--accent)); }
.icon-btn { background: rgba(255,255,255,.12); color: #fff; border: 0; width: 38px; height: 38px; border-radius: 10px; font-size: 1.15rem; cursor: pointer; }

.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.hello { font-size: .9rem; opacity: .85; margin-right: 4px; }
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 58px; z-index: 4; }
.tabs button { flex: 1; border: 0; background: none; padding: 13px 4px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--accent); }

main { max-width: 900px; width: 100%; margin: 0 auto; padding: 14px; flex: 1; }
.quick { display: flex; gap: 12px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.cards .card { margin-bottom: 0; }
.cards + .center { margin-top: 18px; }
.hint { background: #fff6d8; border: 1px solid #f1dc93; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; }

.kpi { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi .v { font-size: 2.1rem; font-weight: 800; color: var(--navy); }
.kpi .u { color: var(--muted); font-weight: 600; }
.sub { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.delta { font-weight: 700; font-size: .92rem; }
.delta.down { color: var(--ok); } .delta.up { color: var(--high); } .delta.eq { color: var(--muted); }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .93rem; }
.row:first-of-type { border-top: 0; }
.row b { color: var(--navy); }
.empty { color: var(--muted); text-align: center; padding: 18px 6px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; color: #fff; white-space: nowrap; }
.s-ok { background: var(--ok); } .s-bas { background: var(--low); } .s-haut { background: var(--high); }
.s-hypo { background: var(--hypo); } .s-tres_haut { background: var(--vhigh); }
.b-maigreur { background: #3b82c4; } .b-normal { background: var(--ok); } .b-surpoids { background: var(--low); }
.b-obe1 { background: var(--high); } .b-obe2 { background: var(--hypo); } .b-obe3 { background: var(--vhigh); }

/* Jauge IMC */
.gauge { margin: 14px 0 6px; }
.gauge-bar { position: relative; height: 12px; border-radius: 6px; display: flex; overflow: visible; }
.gauge-bar span { height: 100%; }
.gauge-bar span:first-child { border-radius: 6px 0 0 6px; } .gauge-bar span:last-of-type { border-radius: 0 6px 6px 0; }
.gauge-mark { position: absolute; top: -6px; width: 4px; height: 24px; background: var(--navy); border-radius: 2px; transform: translateX(-2px); box-shadow: 0 0 0 2px #fff; }
.gauge-scale { position: relative; height: 16px; font-size: .72rem; color: var(--muted); margin-top: 4px; }
.gauge-scale i { position: absolute; transform: translateX(-50%); font-style: normal; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar select { width: auto; margin: 0; }
.seg { display: inline-flex; background: #e7eaf3; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font: inherit; font-size: .9rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chart { width: 100%; min-height: 220px; }
.chart svg { display: block; width: 100%; }
.chart .empty { padding-top: 80px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .l { font-size: .8rem; color: var(--muted); }
.stat .n { font-size: 1.3rem; font-weight: 800; color: var(--navy); margin-top: 2px; }

table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th { color: var(--muted); font-weight: 600; font-size: .8rem; border-top: 0; }
table.t td:first-child, table.t th:first-child { text-align: left; }
.scroll-x { overflow-x: auto; }

.list .item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-top: 1px solid var(--line); cursor: pointer; }
.list .item:first-child { border-top: 0; }
.list .item:hover { background: #f7f8fc; }
.list .when { flex: 1; min-width: 0; }
.list .when .d { font-weight: 600; font-size: .93rem; }
.list .when .n { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .val { font-weight: 800; color: var(--navy); white-space: nowrap; }
.list .more { text-align: center; padding-top: 10px; }

/* Fenêtres */
.modal-back { position: fixed; inset: 0; background: rgba(10, 18, 40, .55); display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100vh - 28px); display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-head { padding: 16px 18px 8px; }
.modal-body { padding: 4px 18px 10px; overflow-y: auto; overflow-x: hidden; }
.modal-foot { padding: 12px 18px 16px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); }
.modal-foot .left { margin-right: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips button { border: 1px solid #cfd5e3; background: #fff; border-radius: 999px; padding: 7px 12px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--text); }
.chips button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.preview { margin: 10px 0 4px; padding: 10px 12px; border-radius: 10px; background: #f3f5fa; font-size: .92rem; min-height: 42px; }
.menu-list button { display: flex; width: 100%; align-items: center; gap: 12px; text-align: left; background: #f6f7fb; border: 0; border-radius: 12px; padding: 13px 14px; margin-bottom: 8px; font: inherit; cursor: pointer; color: var(--text); }
.menu-list button .t { font-weight: 700; }
.menu-list button .d { font-size: .82rem; color: var(--muted); }
.menu-list button .i { font-size: 1.3rem; width: 28px; text-align: center; }
.menu-list button::after { content: "›"; margin-left: auto; font-size: 1.4rem; color: var(--muted); }
.box { background: #f6f7fb; border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
.box h4 { margin: 0 0 6px; font-size: .95rem; color: var(--navy); }
.progress { height: 10px; background: #e7eaf3; border-radius: 5px; overflow: hidden; margin: 10px 0; }
.progress span { display: block; height: 100%; width: 0; background: var(--teal); transition: width .3s; }
.result-ok { color: var(--ok); font-weight: 700; } .result-ko { color: var(--hypo); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--hypo); }

.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 18px 10px calc(18px + env(safe-area-inset-bottom)); }
.footer .links { margin-top: 4px; }

/* Rapport imprimable */
.report h2 { margin-bottom: 4px; }
.report .card { break-inside: avoid; }
@media print {
  body { background: #fff; }
  .topbar, .tabs, .no-print, .footer { display: none !important; }
  main { padding: 0; max-width: none; }
  .card, .stat { box-shadow: none; border: 1px solid #ccc; }
}
@media (max-width: 520px) {
  .hello { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kpi .v { font-size: 1.8rem; }
}
@media (max-width: 520px) { .grid2.keep2 { grid-template-columns: 1fr 1fr; } }
