:root {
  --bg: #f3f7f6; --surface: #ffffff; --surface-2: #eaf1ef; --text: #12201e; --muted: #5a6b68; --line: #d6e2df;
  --primary: #0f766e; --primary-ink: #ffffff; --primary-soft: #d5efeb;
  --bad: #b3203f; --bad-soft: #fbe3e8; --warn: #9a5b00; --warn-soft: #fdf0cf;
  --good: #17734a; --good-soft: #dcf3e6; --info: #1d4ed8; --info-soft: #e1e9fd;
  --radius: 14px; --shadow: 0 1px 2px rgba(10, 30, 28, .08), 0 4px 14px rgba(10, 30, 28, .05);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1615; --surface: #17211f; --surface-2: #1f2c2a; --text: #e8f1ef; --muted: #9bb0ab; --line: #2b3b38;
    --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #123a35;
    --bad: #ff8fa3; --bad-soft: #3b1822; --warn: #fbbf4a; --warn-soft: #3a2c0c;
    --good: #5fd49b; --good-soft: #11301f; --info: #8fb0ff; --info-soft: #172647;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); }
body.noscroll { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Coque */
#app { min-height: 100vh; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--primary); color: var(--primary-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; box-shadow: var(--shadow); }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; gap: 8px; align-items: baseline; }
.brand small { font-weight: 500; opacity: .85; font-size: .85rem; }
#view { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(88px + env(safe-area-inset-bottom)); outline: none; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 7px;
  color: var(--muted); text-decoration: none; font-size: .72rem; min-height: 56px; }
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab.on { color: var(--primary); font-weight: 700; }
.update-banner { background: var(--info-soft); color: var(--info); padding: 8px 14px; text-align: center; font-size: .9rem; }

/* Texte */
.view-title { font-size: 1.35rem; margin: 4px 0 10px; }
.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.sub { margin: 18px 0 6px; font-size: 1rem; }
.sheet-title { font-size: 1.2rem; margin-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; margin: 0; }
.ok-text { color: var(--good); font-weight: 600; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.link { border-color: transparent; background: transparent; color: var(--primary); }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.big { min-height: 52px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .88rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; min-height: 38px; cursor: pointer; }
.pill.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.filters, .seg, .daychips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.daychips .pill { padding: 7px 11px; }

/* Barre d'outils, recherche */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.search { flex: 1; min-width: 0; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }

/* Pastilles et bandeaux */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chips:empty { display: none; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.info { background: var(--info-soft); color: var(--info); }
.banner { padding: 10px 14px; border-radius: var(--radius); margin: 10px 0; background: var(--surface-2); font-size: .92rem; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.info { background: var(--info-soft); color: var(--info); }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty-icon { font-size: 2.4rem; margin-bottom: 8px; }
.empty strong { color: var(--text); display: block; }

/* Cartes */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; }
.card.med.ok { border-left-color: var(--good); }
.card.med.soon { border-left-color: var(--warn); }
.card.med.expired { border-left-color: var(--bad); }
.card.med.empty { opacity: .65; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-size: 1.02rem; }
.card-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card.treatment { border-left-color: var(--primary); }
.card.treatment.paused { opacity: .6; }
.card.dose { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; cursor: default; }
.card.dose.due { border-left-color: var(--primary); }
.card.dose.missed { border-left-color: var(--bad); }
.card.dose.upcoming { border-left-color: var(--line); }
.card.dose.taken { border-left-color: var(--good); opacity: .75; }
.card.dose.skipped { opacity: .6; }
.dose-time { font-weight: 700; font-size: 1.05rem; min-width: 58px; font-variant-numeric: tabular-nums; }
.dose-main { flex: 1; min-width: 150px; }
.dose-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dose.missed .card-sub { color: var(--bad); }

/* Fenêtres */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(5, 15, 14, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; background: var(--bg); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25); }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px 4px 18px; }
.sheet-head h2 { font-size: 1.1rem; }
.sheet-body { overflow-y: auto; padding: 6px 16px calc(20px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
input:focus, select:focus, textarea:focus, button:focus-visible, .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input:disabled, select:disabled { opacity: .6; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details.more { margin: 12px 0; border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px 10px; background: var(--surface); }
details.more summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.check { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.check input, .switch-row input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.switch-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
.delay { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.times { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.time-row { display: flex; gap: 6px; align-items: center; }
.time-row input { width: 140px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 4px 0; }

/* Boîtes */
.boxes { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.box { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--good);
  border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.box.soon { border-left-color: var(--warn); }
.box.expired { border-left-color: var(--bad); }
.box.empty { border-left-color: var(--line); opacity: .6; }
.box-sub { font-size: .88rem; color: var(--muted); margin-top: 2px; }

/* Ajout / scan */
.scan-mount:empty { display: none; }
.scan-mount { position: relative; margin: 10px 0; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 22% 16%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); pointer-events: none; }
.scan-status { min-height: 1.4em; margin: 6px 0; }
.or { text-align: center; color: var(--muted); margin: 12px 0 8px; font-size: .85rem; }
.results { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.result { display: flex; flex-direction: column; text-align: left; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }

/* Réglages et divers */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.panel h3 { font-size: 1rem; margin-bottom: 6px; }
.members { list-style: none; margin: 8px 0 0; padding: 0; }
.members li { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.members .chip { margin-left: 6px; }
.prescription { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin: 8px 0; }
.prescription summary { cursor: pointer; padding: 10px 0; }
.prescription ul { list-style: none; margin: 0; padding: 0 0 8px; }
.prescription li { padding: 8px 0; border-top: 1px solid var(--line); }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.hist-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; }
.hist-name { flex: 1; }
.login { max-width: 380px; margin: 0 auto; padding: calc(60px + env(safe-area-inset-top)) 22px 40px; text-align: center; }
.login-logo { font-size: 3.2rem; }
.login h1 { margin: 6px 0; }
.login .form { text-align: left; margin-top: 22px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 40; max-width: 92vw;
  background: #12201e; color: #fff; padding: 11px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: .92rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b3203f; color: #fff; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
