/* styles.css - PharmaHome
   Palette pharmacie de garde : fond vert d eau, encre sapin, accent croix verte.
   Signature : badge de peremption en forme de gelule bicolore. */

:root {
  --bg: #F2F7F3;
  --surface: #FFFFFF;
  --ink: #143025;
  --muted: #5E7468;
  --line: #DCE8DF;
  --accent: #0E9F5B;
  --accent-deep: #0A7A46;
  --warn: #C77B0A;
  --warn-bg: #FBF1DF;
  --danger: #C0392B;
  --danger-bg: #FAE7E4;
  --ok-bg: #E3F4EA;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em;
  flex: 1;
}
.cross { width: 22px; height: 22px; fill: var(--accent); }
.iconbtn {
  background: none; border: none; padding: 6px; cursor: pointer;
  border-radius: 10px;
}
.iconbtn svg { width: 22px; height: 22px; fill: var(--muted); }
.iconbtn:active { background: var(--line); }

/* ---------- Layout ---------- */
#main { padding: 14px 14px calc(86px + var(--safe-bottom)); max-width: 680px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- Recherche ---------- */
.searchrow input {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); outline: none;
}
.searchrow input:focus { border-color: var(--accent); }

/* ---------- Inventaire ---------- */
.cat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-top: 12px; overflow: hidden;
}
.cat-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 14px; background: none; border: none; cursor: pointer;
  font: inherit; color: inherit; text-align: left;
}
.cat-head .cat-icon { font-size: 1.2rem; }
.cat-head .cat-name { flex: 1; font-weight: 700; font-size: 1rem; }
.cat-head .cat-count {
  font-family: var(--mono); font-size: 0.8rem; color: var(--muted);
  background: var(--bg); border-radius: 99px; padding: 2px 10px;
}
.cat-head .chev { transition: transform .18s; fill: var(--muted); width: 16px; height: 16px; }
.cat.open .chev { transform: rotate(90deg); }
.cat-body { display: none; border-top: 1px solid var(--line); }
.cat.open .cat-body { display: block; }

.family { padding: 10px 14px 4px; }
.family-name {
  font-size: 0.74rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--accent-deep); margin: 4px 0 6px;
}
.med {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-top: 1px dashed var(--line);
}
.med:first-of-type { border-top: none; }
.med-info { flex: 1; min-width: 0; }
.med-name { font-weight: 600; font-size: 0.95rem; }
.med-sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.med-sub a { color: var(--accent-deep); }
.boxes { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.box-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.box-person { font-size: 0.75rem; color: var(--muted); }
.qty-ctl { display: inline-flex; align-items: center; gap: 2px; }
.qty-ctl button {
  width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1rem; cursor: pointer;
  line-height: 1;
}
.qty-ctl b { font-family: var(--mono); min-width: 22px; text-align: center; font-size: 0.9rem; }

/* ---------- Signature : badge gelule ---------- */
.pill {
  display: inline-flex; align-items: stretch; border-radius: 99px;
  overflow: hidden; font-size: 0.74rem; font-weight: 700;
  border: 1.5px solid var(--line); line-height: 1;
}
.pill .half-a { padding: 5px 8px 5px 10px; color: #fff; }
.pill .half-b {
  padding: 5px 10px 5px 8px; background: var(--surface);
  font-family: var(--mono); font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pill.ok .half-a { background: var(--accent); }
.pill.ok { border-color: var(--accent); }
.pill.soon .half-a { background: var(--warn); }
.pill.soon { border-color: var(--warn); }
.pill.expired .half-a { background: var(--danger); }
.pill.expired { border-color: var(--danger); }
.pill.none { border-color: var(--line); }
.pill.none .half-a { background: var(--muted); }

/* ---------- Scanner ---------- */
.scan-wrap {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #0B1F17; aspect-ratio: 3 / 4; max-height: 62vh;
}
#scan-video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 2.5px solid rgba(255,255,255,0.85); border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(11,31,23,0.35);
  pointer-events: none;
}
.scan-hint {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  color: #fff; font-size: 0.82rem; text-shadow: 0 1px 3px rgba(0,0,0,.6); margin: 0;
}
.scan-actions { display: flex; gap: 10px; margin-top: 12px; }
.scan-status { text-align: center; color: var(--muted); font-size: 0.85rem; min-height: 1.2em; }

/* ---------- Peremptions ---------- */
.expiry-head { display: flex; align-items: center; justify-content: space-between; }
.expiry-head h2 { font-size: 1.05rem; margin: 6px 0; }
.expiry-head select {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  background: var(--surface); color: var(--ink); font: inherit;
}
.exp-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-top: 10px;
}
.exp-item.expired { background: var(--danger-bg); border-color: #EAC4BE; }
.exp-item.soon { background: var(--warn-bg); border-color: #EAD7B4; }
.exp-info { flex: 1; min-width: 0; }
.exp-name { font-weight: 600; font-size: 0.95rem; }
.exp-sub { font-size: 0.8rem; color: var(--muted); }
.btn-trash {
  border: none; background: none; cursor: pointer; padding: 8px;
  border-radius: 10px;
}
.btn-trash svg { width: 20px; height: 20px; fill: var(--danger); }

/* ---------- Onglets ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + var(--safe-bottom));
}
.tab {
  position: relative; flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.68rem; font-weight: 600; padding: 4px 0;
}
.tab svg { width: 22px; height: 22px; fill: currentColor; }
.tab.active { color: var(--accent-deep); }
.scan-circle {
  display: grid; place-items: center;
  width: 46px; height: 46px; margin-top: -22px;
  background: var(--accent); border-radius: 50%;
  box-shadow: 0 3px 10px rgba(14,159,91,0.4);
}
.scan-circle svg { fill: #fff; width: 24px; height: 24px; }
.tab .badge {
  position: absolute; top: -2px; right: 22%;
  background: var(--danger); color: #fff; font-style: normal;
  font-size: 0.62rem; font-weight: 800; font-family: var(--mono);
  border-radius: 99px; padding: 2px 6px;
}

/* ---------- Feuilles / formulaires ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(13,30,22,0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(18px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto;
}
.sheet-grip {
  width: 38px; height: 4px; background: var(--line);
  border-radius: 99px; margin: 4px auto 10px;
}
.sheet-card h2 { margin: 4px 0 2px; font-size: 1.1rem; letter-spacing: -0.01em; }
.sheet-source { margin: 0 0 10px; font-size: 0.78rem; color: var(--muted); }
form label {
  display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted);
  margin-top: 10px;
}
form input, form select {
  display: block; width: 100%; margin-top: 4px;
  padding: 11px 12px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); outline: none;
}
form input:focus, form select:focus { border-color: var(--accent); background: var(--surface); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

.btn {
  padding: 12px 14px; border-radius: 12px; font-size: 0.95rem; font-weight: 700;
  border: 1px solid var(--line); cursor: pointer; font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--ink); }
.btn.ghost:active { background: var(--bg); }

.setting-block { margin-top: 16px; }
.setting-block h3 { margin: 0 0 4px; font-size: 0.95rem; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 4px 0 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom)); z-index: 60;
  background: var(--ink); color: #fff; font-size: 0.85rem; font-weight: 600;
  padding: 10px 18px; border-radius: 99px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

@media (prefers-reduced-motion: no-preference) {
  .sheet-card { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(30px); opacity: 0.6; } }
}
