/* Pharmacie familiale — interface mobile */

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d2422;
  --ink-2: #5b6662;
  --line: #e2ded5;
  --brand: #0e5e4f;
  --brand-ink: #ffffff;
  --brand-soft: #dcefe9;
  --ok: #1f7a4d;     --ok-soft: #e1f2e8;
  --soon: #a35a00;   --soon-soft: #fdf0d9;
  --bad: #b42318;    --bad-soft: #fde6e3;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #17211d;
    --surface-2: #1f2b26;
    --ink: #e8eeeb;
    --ink-2: #9aa9a3;
    --line: #2a3832;
    --brand: #5cc5a7;
    --brand-ink: #062a21;
    --brand-soft: #173a31;
    --ok: #6fd39c;     --ok-soft: #173326;
    --soon: #f0b65a;   --soon-soft: #3a2c13;
    --bad: #ff8a7a;    --bad-soft: #3d1c18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: clip; }
svg { max-width: 100%; }
img, video { max-width: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
#app {
  max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: calc(var(--vh, 1dvh) * 100);
  padding-bottom: calc(96px + var(--safe-bottom));
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar h1, .topbar .title { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 650; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.3rem !important; letter-spacing: -.01em; }
.brand svg { width: 30px; height: 30px; flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 10px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer;
  text-decoration: none; font-weight: 600;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
  display: grid; place-items: center; text-decoration: none;
}
.avatar svg { width: 21px; height: 21px; }

/* ---------- recherche & filtres */
.search { position: relative; padding: 4px 16px 10px; }
.search svg { position: absolute; left: 30px; top: 50%; transform: translateY(-58%); width: 20px; height: 20px; color: var(--ink-2); pointer-events: none; }
.search input {
  width: 100%; height: 48px; padding: 0 16px 0 44px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.chips { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .9rem; font-weight: 550;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { opacity: .65; margin-left: 4px; font-variant-numeric: tabular-nums; }

.banner {
  margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px; font-size: .92rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.warn { background: var(--soon-soft); color: var(--soon); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--brand-soft); color: var(--brand); }
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.banner button { margin-left: auto; flex: none; }

/* ---------- liste */
.list { list-style: none; margin: 0; padding: 0 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.card {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); color: inherit; text-decoration: none;
}
.card:active { transform: scale(.99); }
.thumb {
  flex: none; width: 52px; height: 52px; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; background: var(--brand-soft); color: var(--brand);
  font-weight: 700; font-size: 1.2rem;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .body { flex: 1; min-width: 0; }
.card .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--ink-2); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty { color: var(--ink-2); font-size: .8rem; font-weight: 600; }

.badge {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: .8rem; font-weight: 650; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ok { background: var(--ok-soft); color: var(--ok); }
.st-soon { background: var(--soon-soft); color: var(--soon); }
.st-expired { background: var(--bad-soft); color: var(--bad); }
.st-unknown { background: var(--surface-2); color: var(--ink-2); }
.st-empty { background: var(--surface-2); color: var(--ink-2); }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-2); }
.empty svg { width: 64px; height: 64px; color: var(--line); }
.empty h2 { color: var(--ink); font-size: 1.1rem; margin: 12px 0 6px; }

/* ---------- version déployée */
.version { text-align: center; padding: 24px 16px 0; font-size: .75rem; color: var(--ink-2); }
.version:empty { display: none; }

/* ---------- bouton flottant & feuille d'actions */
.fab {
  position: fixed; z-index: 20; right: max(calc(20px + var(--safe-right)), calc(var(--vw, 1vw) * 50 - 300px)); bottom: calc(20px + var(--safe-bottom));
  height: 58px; padding: 0 22px 0 18px; border: 0; border-radius: 20px; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(14, 94, 79, .35);
}
.fab svg { width: 24px; height: 24px; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
  max-height: 100%; overflow-y: auto; animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 1rem; margin: 4px 4px 10px; color: var(--ink-2); font-weight: 600; }
.sheet-action {
  width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 10px;
  border: 0; background: none; border-radius: 14px; cursor: pointer; text-align: left;
}
.sheet-action:active { background: var(--surface-2); }
.sheet-action .ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.sheet-action .ico svg { width: 24px; height: 24px; }
.sheet-action b { display: block; }
.sheet-action small { color: var(--ink-2); }
.sheet-action.danger { color: var(--bad); }
.sheet-action.danger .ico { background: var(--bad-soft); color: var(--bad); }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

/* ---------- détail */
.detail { padding: 0 16px; }
.hero-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 14px; }
.detail h2 { font-size: 1.5rem; line-height: 1.2; margin: 4px 0 10px; letter-spacing: -.01em; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.status-line .rel { color: var(--ink-2); font-size: .92rem; }
.use-box { background: var(--brand-soft); color: var(--ink); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.use-box .label { color: var(--brand); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.use-box p { margin: 4px 0 0; font-size: 1.05rem; font-weight: 550; }
.facts { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 14px; padding: 2px 16px; }
.facts div { display: grid; grid-template-columns: 40% 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--ink-2); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; }

.boxes { margin-bottom: 14px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin: 0 2px 8px; }
.section-head h3 { margin: 0; font-size: 1rem; }
.section-head .total { color: var(--ink-2); font-size: .92rem; }
.section-head .total b { color: var(--ink); font-size: 1.05rem; }
.boxes ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 6px 14px; display: grid; gap: 6px; }
.box.is-empty { opacity: .65; }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.box-meta { color: var(--ink-2); font-size: .85rem; }
.gauge { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.gauge span { display: block; height: 100%; border-radius: 3px; background: var(--brand); }
.box-foot { display: flex; align-items: center; gap: 6px; min-height: 40px; }
.box-count { flex: 1; color: var(--ink-2); font-size: .92rem; }
.box-count b { color: var(--ink); font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.box-foot .icon-btn { color: var(--ink-2); }
.box-foot .icon-btn svg { width: 19px; height: 19px; }
.btn.small { min-height: 36px; padding: 0 14px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 650; text-decoration: none; cursor: pointer;
}
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.meta { color: var(--ink-2); font-size: .82rem; text-align: center; margin: 18px 0; }

/* ---------- formulaire */
.form { padding: 0 16px; display: grid; gap: 14px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; position: relative; }
.field > span { font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; outline: none;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field .hint { font-size: .8rem; color: var(--ink-2); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field.half { width: calc(50% - 6px); }
.boxes-edit { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: 10px; }
.boxes-edit legend { padding: 0; margin-bottom: 6px; font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.boxes-edit .hint { margin: 0; color: var(--ink-2); font-size: .9rem; }
#boxRows { display: grid; gap: 10px; }
.box-edit { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px 12px; }
.box-edit-head { display: flex; align-items: center; justify-content: space-between; }
.box-edit-head .icon-btn { color: var(--ink-2); margin-right: -8px; }
.box-edit-head .icon-btn svg { width: 19px; height: 19px; }
details.more { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
details.more summary { padding: 10px 0; font-weight: 600; cursor: pointer; color: var(--ink-2); }
details.more[open] { padding-bottom: 14px; }
details.more .field { margin-top: 10px; }

.suggest {
  position: absolute; z-index: 15; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  max-height: 300px; overflow-y: auto; list-style: none; padding: 4px; margin-bottom: 0;
}
.suggest li button { width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.suggest li button:active, .suggest li button:focus { background: var(--surface-2); outline: none; }
.suggest small { display: block; color: var(--ink-2); }

.photo-pick { display: flex; align-items: center; gap: 12px; }
.photo-pick img { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; }
.photo-pick label { cursor: pointer; }

.save-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px calc(16px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.save-bar > div { max-width: 608px; margin: 0 auto; }

/* ---------- connexion */
.login { min-height: 100vh; min-height: calc(var(--vh, 1dvh) * 100); display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login .logo { display: grid; justify-items: center; gap: 8px; margin-bottom: 12px; text-align: center; }
.login .logo svg { width: 72px; height: 72px; }
.login h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.login p { margin: 0; color: var(--ink-2); }
.error { color: var(--bad); font-size: .9rem; min-height: 1.2em; }
.login .server { font-size: .85rem; overflow-wrap: anywhere; }
.btn.plain { border-color: transparent; background: none; color: var(--ink-2); font-weight: 600; font-size: .92rem; text-align: center; }

/* ---------- paramètres */
.settings { padding: 0 16px; display: grid; gap: 14px; }
.settings form { display: grid; gap: 12px; }
.settings h3 { margin: 4px 2px 0; font-size: 1rem; }
.settings p { margin: 0; }
.settings .hint { color: var(--ink-2); font-size: .88rem; }
.settings .error:empty { display: none; }
.welcome { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 8px 0 10px; }
.welcome svg { width: 72px; height: 72px; }
.welcome h1 { margin: 6px 0 0; font-size: 1.6rem; letter-spacing: -.02em; }
.welcome p { color: var(--ink-2); }
.choice {
  position: relative; display: flex; align-items: center; gap: 14px; padding: 14px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
}
.choice:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice input:focus-visible ~ .ico { outline: 2px solid var(--brand); outline-offset: 2px; }
.choice .ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.choice:has(input:checked) .ico { background: var(--brand-soft); color: var(--brand); }
.choice .ico svg { width: 24px; height: 24px; }
.choice b { display: block; }
.choice small { color: var(--ink-2); font-size: .88rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.panel h3 { margin: 0; }
.panel[hidden], .field[hidden] { display: none; }

/* ---------- scanner plein écran */
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  width: min(calc(var(--vw, 1vw) * 62), calc(var(--vh, 1vh) * 62), 320px); aspect-ratio: 1; border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); outline: 3px solid rgba(255, 255, 255, .9);
}
.scanner .frame::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: #5cc5a7; box-shadow: 0 0 12px #5cc5a7; animation: scanline 1.8s ease-in-out infinite;
}
.scanner.found .frame { outline-color: #5cc5a7; }
@keyframes scanline { 0%, 100% { top: 12%; } 50% { top: 88%; } }
.scanner .top, .scanner .bottom { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 16px; }
.scanner .top, .scanner .bottom { padding-left: calc(16px + var(--safe-left)); padding-right: calc(16px + var(--safe-right)); }
.scanner .top { padding-top: calc(16px + var(--safe-top)); justify-content: space-between; }
.scanner .bottom { margin-top: auto; flex-direction: column; padding-bottom: calc(24px + var(--safe-bottom)); }
.scanner .msg { text-align: center; font-size: .98rem; max-width: 320px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.scanner .round {
  width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(255, 255, 255, .18); color: #fff; cursor: pointer; backdrop-filter: blur(6px);
}
.scanner .round svg { width: 24px; height: 24px; }
.scanner .round[aria-pressed="true"] { background: #fff; color: #000; }
.scanner .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.scanner .pill {
  height: 44px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; backdrop-filter: blur(6px);
  display: inline-flex; align-items: center; gap: 8px;
}

/* ---------- téléphone à l'horizontale (peu de hauteur) */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding-top: calc(6px + var(--safe-top)); padding-bottom: 6px; }
  .hero-photo { aspect-ratio: 16 / 9; max-height: calc(var(--vh, 1vh) * 60); }
  .login { grid-template-rows: auto auto; padding: 12px 24px; }
  .login .logo { margin-bottom: 0; }
  .login .logo svg { width: 48px; height: 48px; }
  .scanner .frame { top: 50%; width: min(calc(var(--vh, 1vh) * 50), 280px); }
  .scanner .top { padding-top: calc(8px + var(--safe-top)); }
  .scanner .bottom { padding-bottom: calc(10px + var(--safe-bottom)); }
}

/* ---------- divers */
.splash { min-height: calc(var(--vh, 1vh) * 70); display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 550;
  transition: .2s ease; max-width: calc(var(--vw, 1vw) * 100 - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
