/* Armoire : verre d'apothicaire (cobalt, ambre) sur émail blanc, plaquette d'aluminium pour les prises. */
:root {
  --enamel: #f2f5f4;
  --opaline: #ffffff;
  --sunken: #e7ecea;
  --line: #d5dcd9;
  --ink: #1b2430;
  --ink-soft: #566170;
  --cobalt: #1f3c88;
  --cobalt-ink: #ffffff;
  --cobalt-tint: #e3e9f8;
  --amber: #a85a08;
  --amber-tint: #fbebd3;
  --red: #b42318;
  --red-tint: #fbe3e0;
  --fern: #2a6a4c;
  --fern-tint: #def0e6;
  --foil-hi: #f7f9fa;
  --foil-lo: #cdd5da;
  --focus: #1f3c88;
  --display: "Bahnschrift", "DIN Alternate", "Avenir Next Condensed", "Roboto Condensed", "sans-serif-condensed", "Arial Narrow", system-ui, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --r-s: 6px;
  --r-m: 12px;
  --r-l: 22px;
  --rail: 232px;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --enamel: #0f151c; --opaline: #171f28; --sunken: #1d2732; --line: #2b3745;
    --ink: #e8edf2; --ink-soft: #99a6b5;
    --cobalt: #8ea8f2; --cobalt-ink: #0d1530; --cobalt-tint: #1c2a52;
    --amber: #f0a34d; --amber-tint: #3a2a13; --red: #ff8f84; --red-tint: #3d1c19;
    --fern: #7ccba0; --fern-tint: #173326; --foil-hi: #3a4650; --foil-lo: #232d36; --focus: #8ea8f2;
  }
}
:root[data-theme="dark"] {
  --enamel: #0f151c; --opaline: #171f28; --sunken: #1d2732; --line: #2b3745;
  --ink: #e8edf2; --ink-soft: #99a6b5;
  --cobalt: #8ea8f2; --cobalt-ink: #0d1530; --cobalt-tint: #1c2a52;
  --amber: #f0a34d; --amber-tint: #3a2a13; --red: #ff8f84; --red-tint: #3d1c19;
  --fern: #7ccba0; --fern-tint: #173326; --foil-hi: #3a4650; --foil-lo: #232d36; --focus: #8ea8f2;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--enamel); color: var(--ink);
  font: 16px/1.45 var(--text); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.small { font-size: .8125rem; }
svg.i { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Structure ---------- */
.shell { min-height: 100dvh; }
.main { padding: 20px 16px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.rail { display: none; }
.tabbar {
  position: fixed; inset: auto 0 0 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--opaline); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); z-index: 20;
}
.tab { display: grid; place-items: center; align-content: center; gap: 2px; border: 0; background: none; text-decoration: none; color: var(--ink-soft); font-size: .6875rem; padding: 6px 0; min-height: 48px; }
.tab[aria-current="page"] { color: var(--cobalt); font-weight: 650; }
.tab svg { width: 24px; height: 24px; }
.tab.scan { position: relative; }
.tab.scan span.fab {
  display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; margin-top: -26px;
  background: var(--cobalt); color: var(--cobalt-ink); border: 4px solid var(--enamel);
}
.tab.scan svg { width: 28px; height: 28px; }
.tab.scan small { color: var(--cobalt); font-weight: 650; }

@media (min-width: 880px) {
  .shell { display: grid; grid-template-columns: var(--rail) 1fr; }
  .tabbar { display: none; }
  .rail { display: flex; flex-direction: column; gap: 4px; padding: 24px 14px; position: sticky; top: 0; height: 100dvh; border-right: 1px solid var(--line); background: var(--opaline); }
  .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font: 700 1.5rem/1 var(--display); letter-spacing: .01em; }
  .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .rail a.nav { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--r-s); color: var(--ink); text-decoration: none; font-weight: 500; }
  .rail a.nav:hover { background: var(--sunken); }
  .rail a.nav[aria-current="page"] { background: var(--cobalt-tint); color: var(--cobalt); font-weight: 650; }
  .rail .btn.scan-btn { margin: 0 0 16px; }
  .rail .foot { margin-top: auto; padding: 10px; }
  .main { padding: 36px 40px 60px; max-width: 980px; margin: 0; }
}

/* ---------- Typographie ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font: 700 clamp(1.9rem, 6vw, 2.6rem)/1.05 var(--display); letter-spacing: .005em; }
.page-sub { color: var(--ink-soft); margin-top: 4px; }
.section-title { font: 650 1.25rem/1.2 var(--display); margin: 30px 0 10px; letter-spacing: .01em; }
.name { font: 650 1.2rem/1.2 var(--display); letter-spacing: .01em; overflow-wrap: anywhere; }

/* ---------- Boutons et champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 999px;
  border: 1.5px solid var(--cobalt); background: var(--cobalt); color: var(--cobalt-ink); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.quiet { background: transparent; color: var(--cobalt); }
.btn.plain { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--ink-soft); flex: none; }
.icon-btn:hover { background: var(--sunken); color: var(--ink); }

.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label, .field > .lbl { font-size: .875rem; font-weight: 600; }
.field .hint { font-size: .8125rem; color: var(--ink-soft); }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="time"], input[type="password"], select, textarea {
  width: 100%; min-height: 46px; padding: 9px 12px; border: 1.5px solid var(--line); border-radius: var(--r-m); background: var(--opaline); color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--cobalt) 25%, transparent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row.auto > * { flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--cobalt); }
.stepper { display: inline-flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--opaline); }
.stepper button { width: 44px; border: 0; background: transparent; font-size: 1.25rem; color: var(--cobalt); }
.stepper button:hover { background: var(--sunken); }
.stepper output, .stepper input { min-width: 48px; display: grid; place-items: center; font-weight: 650; text-align: center; border: 0; background: transparent; width: 56px; min-height: 40px; padding: 0; }
.stepper input:focus { box-shadow: none; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--opaline); font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"], .chip.on { background: var(--cobalt-tint); border-color: var(--cobalt); color: var(--cobalt); font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--sunken); color: var(--ink-soft); white-space: nowrap; }
.pill.red { background: var(--red-tint); color: var(--red); }
.pill.amber { background: var(--amber-tint); color: var(--amber); }
.pill.fern { background: var(--fern-tint); color: var(--fern); }
.pill.cobalt { background: var(--cobalt-tint); color: var(--cobalt); }

/* ---------- Alertes ---------- */
.alerts { display: grid; gap: 8px; margin-bottom: 8px; }
.alert { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-s); border-left: 6px solid; text-decoration: none; color: var(--ink); background: var(--opaline); }
.alert.red { border-color: var(--red); background: var(--red-tint); }
.alert.amber { border-color: var(--amber); background: var(--amber-tint); }
.alert.cobalt { border-color: var(--cobalt); background: var(--cobalt-tint); }
.alert b { font-weight: 650; }
.alert .go { margin-left: auto; color: var(--ink-soft); }

/* ---------- Plaquette du jour ---------- */
.blister-wrap { margin-bottom: 22px; }
.person-line { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.blister {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 14px 10px; padding: 16px 14px 14px;
  border-radius: var(--r-l); background: linear-gradient(160deg, var(--foil-hi), var(--foil-lo)); border: 1px solid var(--line);
}
.cell { display: grid; justify-items: center; gap: 6px; border: 0; background: none; padding: 0; text-align: center; color: var(--ink); }
.cell .well {
  position: relative; width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffffff, #e9eef3 70%); box-shadow: inset 0 -3px 6px rgba(20,40,70,.18), 0 1px 0 rgba(255,255,255,.8);
  border: 3px solid var(--cobalt); font: 700 1.05rem var(--display); color: var(--cobalt);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cell .well { background: radial-gradient(circle at 35% 30%, #3b4854, #26313b 70%); } }
.cell.late .well { border-color: var(--amber); color: var(--amber); }
.cell.taken .well {
  background: radial-gradient(circle at 50% 55%, #0f151c 0 38%, #55616c 39% 52%, transparent 53%), repeating-conic-gradient(from 8deg, #d9dfe3 0 14deg, #b9c2c8 14deg 28deg);
  border-color: var(--fern); color: transparent; box-shadow: none;
}
.cell.taken.fresh .well { animation: punch .35s ease-out; }
.cell.taken .well svg { position: absolute; color: #fff; width: 28px; height: 28px; stroke-width: 3; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
.cell .well svg { display: none; }
.cell.taken .well svg { display: block; }
.cell .med { font: 600 .8rem/1.15 var(--display); letter-spacing: .01em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.cell .dose { font-size: .72rem; color: var(--ink-soft); }
@keyframes punch { 0% { transform: scale(.82); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .cell.taken.fresh .well { animation: none; } * { scroll-behavior: auto !important; } }
.sheet-foot:empty { display: none; }
.prn-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prn-row:last-child { border-bottom: 0; }
.prn-row .grow { flex: 1; min-width: 0; }

/* ---------- Armoire ---------- */
.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }
.search input { padding-left: 42px; }
.group { background: var(--opaline); border: 1px solid var(--line); border-left: 7px solid var(--line); border-radius: var(--r-s); margin-bottom: 10px; overflow: hidden; }
.group.red { border-left-color: var(--red); }
.group.amber { border-left-color: var(--amber); }
.group.ok { border-left-color: var(--fern); }
.group-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; width: 100%; min-width: 0; text-align: left; border: 0; background: none; padding: 14px 14px 12px; align-items: start; }
.group-head .meta { grid-column: 1 / -1; display: grid; gap: 3px; }
.group-head .count { text-align: right; font: 650 1.05rem var(--display); white-space: nowrap; }
.group-head .count small { display: block; font: 400 .75rem var(--text); color: var(--ink-soft); }
.tagline { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.uses { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; font-size: .875rem; color: var(--ink-soft); padding: 0 14px 12px; cursor: pointer; }
.uses-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.uses .more { display: inline-block; margin-top: 2px; color: var(--cobalt); font-weight: 600; font-size: .8125rem; }
.uses:hover .more { text-decoration: underline; }
.med-name { margin: 0 0 14px; font: 650 1.1rem var(--display); }
.boxes { border-top: 1px dashed var(--line); }
.box { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.box:last-child { border-bottom: 0; }
.box.red { background: var(--red-tint); }
.box.amber { background: var(--amber-tint); }
.box .when { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.box .when.red { color: var(--red); } .box .when.amber { color: var(--amber); }
.box .when .pill { background: transparent; border: 1px solid currentColor; }
.box .qty { font-weight: 600; margin-top: 2px; }
.box .sub { font-size: .8125rem; color: var(--ink-soft); }
.box .actions { display: flex; gap: 4px; align-items: center; }
/* Téléphone : l'en-tête et les boutons passent sous le texte pour ne rien couper */
@media (max-width: 520px) {
  .group-head { grid-template-columns: minmax(0, 1fr); }
  .group-head .count { text-align: left; white-space: normal; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
  .group-head .count small { display: inline; }
  .box { grid-template-columns: 1fr; }
  .box .actions { flex-wrap: wrap; }
}
.units { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; max-width: 320px; }
.units i { width: 9px; height: 9px; border-radius: 50%; background: var(--cobalt); }
.units i.gone { background: transparent; border: 1.5px solid var(--line); }
.bar { height: 8px; border-radius: 4px; background: var(--sunken); overflow: hidden; margin-top: 6px; max-width: 260px; }
.bar b { display: block; height: 100%; background: var(--cobalt); }

/* ---------- Listes génériques ---------- */
.list { background: var(--opaline); border: 1px solid var(--line); border-radius: var(--r-s); }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px; border-bottom: 1px solid var(--line); align-items: center; }
.item:last-child { border-bottom: 0; }
.item .t { font: 650 1.1rem/1.2 var(--display); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); border: 1.5px dashed var(--line); border-radius: var(--r-m); }
.empty h2 { font: 650 1.3rem var(--display); color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ---------- Fenêtres ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--opaline); color: var(--ink); width: 100%; max-width: 100%; max-height: 94dvh; margin: auto 0 0; border-radius: var(--r-l) var(--r-l) 0 0;
  overflow: hidden; display: none;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: rise .22s ease-out; }
dialog.sheet::backdrop { background: rgba(10, 18, 30, .55); }
@keyframes rise { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 10px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font: 700 1.4rem/1.1 var(--display); letter-spacing: .01em; }
.sheet-body { padding: 18px 20px 12px; overflow: auto; flex: 1; }
.sheet-foot { padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 10px; background: var(--opaline); }
.sheet-foot .btn { flex: 1 1 auto; min-width: 0; justify-content: center; }
@media (min-width: 880px) {
  dialog.sheet { margin: auto; max-width: 600px; border-radius: var(--r-l); max-height: 90dvh; }
  dialog.sheet.wide { max-width: 760px; }
}
dialog.sheet.full { height: 100dvh; max-height: 100dvh; border-radius: 0; }
@media (min-width: 880px) { dialog.sheet.full { height: auto; max-height: 90dvh; border-radius: var(--r-l); } }

/* ---------- Scanner ---------- */
.viewfinder { position: relative; background: #05080c; border-radius: var(--r-m); overflow: hidden; aspect-ratio: 4 / 3; max-height: 46dvh; width: 100%; margin: 0 auto 14px; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder .frame { position: absolute; inset: 18% 14%; border-radius: 14px; pointer-events: none; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 0 0 999px rgba(5,8,12,.38); }
.viewfinder .frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ffb454; box-shadow: 0 0 10px #ffb454; animation: sweep 2.2s ease-in-out infinite alternate; }
@keyframes sweep { from { top: 18%; } to { top: 82%; } }
@media (prefers-reduced-motion: reduce) { .viewfinder .frame::after { animation: none; } }
.viewfinder .msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: #dfe6ee; }
.facts { display: grid; gap: 10px; margin: 0 0 16px; }
.fact { display: grid; grid-template-columns: 118px 1fr; gap: 10px; font-size: .95rem; }
.fact dt { color: var(--ink-soft); font-size: .84rem; padding-top: 1px; }
.fact dd { margin: 0; overflow-wrap: anywhere; }
.fact a { color: var(--cobalt); }
@media (max-width: 520px) { .fact { grid-template-columns: 1fr; gap: 2px; } }
.callout { padding: 12px 14px; border-radius: var(--r-s); border-left: 6px solid var(--cobalt); background: var(--cobalt-tint); margin-bottom: 14px; font-size: .92rem; }
.callout.amber { border-color: var(--amber); background: var(--amber-tint); }
.callout.red { border-color: var(--red); background: var(--red-tint); }
.picker-list { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; margin-bottom: 14px; }
.picker-list button { text-align: left; background: var(--opaline); border: 0; border-bottom: 1px solid var(--line); padding: 11px 14px; display: grid; gap: 2px; }
.picker-list button:last-child { border-bottom: 0; }
.picker-list button:hover { background: var(--sunken); }
.times { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.time-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 14px; border-radius: 999px; background: var(--cobalt-tint); color: var(--cobalt); font-weight: 650; }
.time-chip button { border: 0; background: none; color: inherit; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatches button[aria-pressed="true"] { border-color: var(--ink); }

/* ---------- Notifications ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 100; pointer-events: none; padding: 0 16px; }
@media (min-width: 880px) { #toasts { bottom: 24px; } }
.toast { background: var(--ink); color: var(--enamel); padding: 11px 18px; border-radius: 999px; font-weight: 550; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 480px; animation: rise .2s ease-out; pointer-events: auto; }
.toast.err { background: var(--red); color: #fff; }

.login { max-width: 380px; margin: 14vh auto 0; padding: 0 20px; }
.login .brand { padding: 0 0 18px; font: 700 2rem/1 var(--display); display: flex; align-items: center; gap: 12px; }
.login .brand img { width: 44px; height: 44px; border-radius: 11px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .95rem; }
.kv dt { color: var(--ink-soft); } .kv dd { margin: 0; }
.merge-bar{padding:0 14px 10px}
.group.none { border-left-color: #9aa0a8; border-left-style: dashed; }
.legend { margin: 0 0 10px; }
.month-field{display:flex;flex-direction:column;gap:4px;margin-top:8px}.month-field input{max-width:11em}

/* Mobile : les noms longs et les pastilles (« Générique de … ») passent à la ligne au lieu de déborder de la carte */
.group, .group-head > *, .group-head .meta, .tagline { min-width: 0; max-width: 100%; }
.group-head .name, .group-head .small { overflow-wrap: anywhere; word-break: break-word; }
.group-head .pill, .box .pill { white-space: normal; max-width: 100%; text-align: left; border-radius: 14px; line-height: 1.3; padding-block: 3px; }
.ordo-link{margin:0 0 16px;justify-content:flex-start;text-decoration:none}
