/* Charte inspirée du site pharmacie-capsule.fr (Pharmacie des Écoles) :
   marine + indigo, accent vert menthe, Plus Jakarta Sans, boutons pilule, cartes à liseré. */
:root {
  --navy: #1B2A4A; --navy2: #243B75; --navy3: #2E4F9C;
  --indigo: #4155A8; --indigo-d: #3547A0;
  --sky: #EEF3FF; --sky2: #F7F9FF; --white: #fff;
  --text: #2D3A52; --muted: #6B7A99; --line: #E4EAF7;
  --green: #7DDFB0; --green-d: #1F9D63; --green-bg: #E7F8EF;
  --red: #F97062; --red-d: #D2412F; --red-bg: #FEECEA;
  --amber: #B7791F; --amber-bg: #FFF4E0;
  --stup: #7A3FB8; --stup-bg: #F3EBFD; --cold: #1E6FB8; --cold-bg: #E6F1FC;
  --fn: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r: 12px; --rl: 20px;
  --sh: 0 4px 24px rgba(27,42,74,.08); --sh2: 0 12px 48px rgba(27,42,74,.13);
  --hero: linear-gradient(140deg, var(--navy) 0%, var(--navy2) 55%, var(--navy3) 100%);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--sky2); color: var(--text); font: 500 16px/1.5 var(--fn);
  padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: transparent;
}
a { color: var(--indigo); }
code { background: var(--sky); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

/* Croix de pharmacie (comme le logo du site) */
.pharma-cross { display: inline-block; width: 22px; height: 22px; position: relative; flex-shrink: 0; color: var(--green); }
.pharma-cross::before, .pharma-cross::after { content: ''; position: absolute; background: currentColor; border-radius: 3px; }
.pharma-cross::before { width: 22px; height: 8px; top: 7px; left: 0; }
.pharma-cross::after { width: 8px; height: 22px; left: 7px; top: 0; }
.pharma-cross.lg { transform: scale(1.6); margin: 8px; }

/* ---------- Barre du haut ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 2px;
  background: var(--hero); color: #fff; padding: 6px 8px 6px 12px; min-height: 60px;
  box-shadow: 0 2px 16px rgba(27,42,74,.25);
}
#topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
#topbar .brand-txt { min-width: 0; line-height: 1.15; }
#topbar .brand-name { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar h1 { font-size: 17px; font-weight: 800; letter-spacing: -.02em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  position: relative; background: transparent; border: 0; color: inherit; font-size: 22px;
  min-width: 46px; min-height: 46px; border-radius: 100px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { background: rgba(255,255,255,.14); }
.icon-btn svg { width: 24px; height: 24px; }
#badge {
  position: absolute; top: 4px; right: 2px; background: var(--green); color: var(--navy); border-radius: 100px;
  font-size: 11px; font-weight: 800; padding: 1px 6px; min-width: 18px; text-align: center;
}
#menu {
  position: fixed; top: 64px; right: 8px; z-index: 30; background: #fff; border-radius: var(--rl);
  box-shadow: var(--sh2); min-width: 260px; overflow: hidden; border: 1px solid var(--line); padding: 6px;
}
#menu a, #menu button {
  display: block; width: 100%; text-align: left; padding: 12px 14px; color: var(--navy); text-decoration: none;
  background: none; border: 0; border-radius: 10px; font: 600 15px var(--fn); cursor: pointer;
}
#menu a:active, #menu button:active, #menu a:hover { background: var(--sky); color: var(--indigo); }
#menu #logout { color: var(--red-d); }
#menu .who { padding: 12px 14px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
#menu .who b { color: var(--navy); font-size: 15px; display: block; }

main { max-width: 1100px; margin: 0 auto; padding: 14px 14px 24px; }
h2 { font-size: 22px; font-weight: 800; letter-spacing: -.03em; color: var(--navy); margin: 6px 0 12px; line-height: 1.15; }
h2 em { font-style: normal; color: var(--indigo); }
h3 { font-size: 16px; font-weight: 800; color: var(--navy); margin: 16px 0 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--indigo); margin: 18px 0 10px;
}
.chip::before { content: ''; width: 16px; height: 2px; background: var(--indigo); border-radius: 2px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 180px; min-width: 0; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* ---------- Bandeau « hero » (comme le site) ---------- */
.hero {
  position: relative; overflow: hidden; background: var(--hero); color: #fff;
  border-radius: var(--rl); padding: 20px 18px; margin-bottom: 14px; box-shadow: var(--sh2);
}
.hero::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 28px 28px;
}
.hero::after {
  content: ''; position: absolute; width: 360px; height: 360px; border-radius: 50%; top: -160px; right: -120px; pointer-events: none;
  background: radial-gradient(circle, rgba(91,143,232,.25), transparent 65%);
}
.hero > * { position: relative; z-index: 1; }
.hero h2 { color: #fff; font-size: 26px; margin: 10px 0 4px; }
.hero h2 em { color: var(--green); }
.hero p { color: rgba(255,255,255,.7); margin: 0; }
.badge {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.92); padding: 5px 12px; border-radius: 100px; font-size: 11px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
}
.badge i { width: 7px; height: 7px; background: var(--green); border-radius: 50%; animation: dp 2s infinite; }
@keyframes dp { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 14px 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12); }
.kpi b { display: block; font-size: 28px; font-weight: 800; line-height: 1; color: var(--green); letter-spacing: -.03em; }
.kpi span { display: block; font-size: 9.5px; font-weight: 600; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.kpi.alert b { color: var(--red); }
.kpi.zero b { color: rgba(255,255,255,.35); }

/* ---------- Cartes ---------- */
.card {
  background: #fff; border-radius: var(--r); padding: 16px; margin-bottom: 10px;
  box-shadow: var(--sh); border: 1.5px solid var(--line);
}
a.card { display: block; color: inherit; text-decoration: none; transition: transform .2s, box-shadow .2s, border-color .2s; }
a.card:hover { border-color: var(--indigo); box-shadow: var(--sh2); }
a.card:active { transform: scale(.99); background: var(--sky2); }
.card.urgent { border-left: 4px solid var(--red); }
.card.pda { border-left: 4px solid var(--indigo); }
.card-title { font-weight: 800; color: var(--navy); letter-spacing: -.01em; }
.card-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.card-head .tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Boutons (pilules) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 100px; border: 1.5px solid var(--line);
  background: #fff; color: var(--navy); font: 700 15px/1.1 var(--fn); cursor: pointer; text-decoration: none; text-align: center;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--indigo); color: #fff; border-color: var(--indigo); box-shadow: 0 4px 16px rgba(65,85,168,.3); }
.btn.primary:hover { background: var(--indigo-d); }
.btn.navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.ok { background: var(--green); color: var(--navy); border-color: var(--green); box-shadow: 0 4px 16px rgba(61,190,130,.35); }
.btn.danger { background: #fff; color: var(--red-d); border-color: #F8C9C2; }
.btn.white { background: #fff; color: var(--navy); border-color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.18); }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.btn.block { width: 100%; }
.btn.big { min-height: 62px; font-size: 18px; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.actions { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 12px 0; }

/* ---------- Formulaires ---------- */
label { display: block; font-size: 13px; font-weight: 700; color: var(--navy); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; min-height: 50px; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: var(--r);
  font: 500 16px var(--fn); background: #fff; color: var(--text); transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 4px rgba(65,85,168,.12); }
textarea { min-height: 90px; }
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--indigo); vertical-align: middle; }
label.check { display: inline-flex; gap: 8px; align-items: center; color: var(--text); font-weight: 600; font-size: 14.5px; margin: 6px 14px 6px 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--sky); padding: 5px; border-radius: 100px; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 11px 8px; border-radius: 100px; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: #fff; color: var(--navy); box-shadow: var(--sh); }
.seg input[value=urgence]:checked + span { color: var(--red-d); }

/* ---------- Étiquettes ---------- */
.tag {
  display: inline-block; font-size: 10.5px; font-weight: 800; padding: 3px 9px; border-radius: 100px;
  background: var(--sky); color: var(--indigo); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
.tag.urgence { background: var(--red-bg); color: var(--red-d); }
.tag.pda { background: var(--sky); color: var(--indigo); }
.tag.stup { background: var(--stup-bg); color: var(--stup); }
.tag.cold { background: var(--cold-bg); color: var(--cold); }
.tag.s-a_preparer { background: var(--amber-bg); color: var(--amber); }
.tag.s-prete { background: var(--sky); color: var(--indigo); }
.tag.s-en_tournee { background: var(--navy); color: #fff; }
.tag.s-livree { background: var(--green-bg); color: var(--green-d); }
.tag.s-incident { background: var(--red-bg); color: var(--red-d); }
.tag.s-annulee { background: #EEF0F4; color: #8A94A8; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding: 5px; background: var(--sky); border-radius: 100px; scrollbar-width: none; }
.tabs a {
  padding: 10px 16px; border-radius: 100px; color: var(--muted); text-decoration: none;
  white-space: nowrap; font-weight: 700; font-size: 14px; flex: 1 0 auto; text-align: center;
}
.tabs a.on { background: #fff; color: var(--navy); box-shadow: var(--sh); }

/* ---------- Écran de scan (Zebra) ---------- */
.scanbox { position: sticky; top: 60px; z-index: 10; background: var(--sky2); padding: 8px 0; margin-top: -6px; }
.scanbox input {
  font-size: 17px; font-weight: 700; border: 2px dashed var(--indigo); background: var(--sky); color: var(--navy); border-radius: 100px; padding-left: 20px;
}
.flash-ok input { animation: fok .6s; }
.flash-err input { animation: ferr .8s; }
@keyframes fok { 0% { background: var(--green); } 100% { background: var(--sky); } }
@keyframes ferr { 0%, 50% { background: #FBB3AA; } 100% { background: var(--sky); } }
.scanmsg { margin-top: 8px; padding: 11px 16px; border-radius: var(--r); font-weight: 700; display: none; }
.scanmsg.ok { display: block; background: var(--green-bg); color: var(--green-d); }
.scanmsg.err { display: block; background: var(--red-bg); color: var(--red-d); }
.scanmsg.warn { display: block; background: var(--amber-bg); color: var(--amber); }

.item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .qty {
  min-width: 62px; text-align: center; font-weight: 800; font-size: 18px; border-radius: var(--r); padding: 10px 4px;
  background: var(--amber-bg); color: var(--amber); letter-spacing: -.02em;
}
.item.done .qty { background: var(--green-bg); color: var(--green-d); }
.item.manual .qty { background: var(--sky); color: var(--indigo); }
.item .name { font-weight: 700; color: var(--navy); }
.progress { height: 8px; background: var(--sky); border-radius: 100px; overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #3BC98F, var(--green)); border-radius: 100px; transition: width .3s; }
.hero .progress { background: rgba(255,255,255,.14); }

.req { list-style: none; padding: 0; margin: 6px 0 0; }
.req li { padding: 7px 0; font-weight: 700; display: flex; gap: 10px; align-items: center; }
.req li::before { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; flex-shrink: 0; }
.req li.ok::before { content: "✓"; background: var(--green); color: var(--navy); }
.req li.ko::before { content: "!"; background: var(--red-bg); color: var(--red-d); }
.hero .req li { color: #fff; }

.sigpad { width: 100%; height: 220px; border: 2px dashed var(--line); border-radius: var(--r); background: #fff; touch-action: none; display: block; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { width: 104px; height: 104px; object-fit: cover; border-radius: var(--r); border: 1.5px solid var(--line); cursor: zoom-in; }
.thumbs figcaption { font-size: 11.5px; color: var(--muted); max-width: 104px; }
.thumbs .del { position: absolute; top: 4px; right: 4px; background: rgba(27,42,74,.75); color: #fff; border: 0; border-radius: 50%; width: 28px; height: 28px; }
img.signature { max-width: 320px; width: 100%; border: 1.5px solid var(--line); border-radius: var(--r); background: #fff; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 6px 0 12px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 9px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--line); }
.timeline li.livree::before { background: var(--green); border-color: var(--green); }
.timeline li.incident::before { background: var(--red); border-color: var(--red); }
.timeline li.en_tournee::before, .timeline li.creee::before { background: var(--indigo); border-color: var(--indigo); }
.timeline li.message_ehpad::before, .timeline li.message_pharmacie::before { background: var(--sky); border-color: var(--indigo); }
.notif { padding: 13px 0; border-bottom: 1px solid var(--line); }
.notif:last-child { border-bottom: 0; }
.notif.unread { padding-left: 12px; border-left: 3px solid var(--green); }
.notif.unread .msg { font-weight: 700; color: var(--navy); }
.notif a { color: inherit; text-decoration: none; display: block; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th { text-align: left; padding: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--sky2); border-bottom: 1.5px solid var(--line); }
td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1.5px solid var(--line); box-shadow: var(--sh); }

.lines .line { border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 10px; background: var(--sky2); }
.lines .line input, .lines .line select { min-height: 46px; }
.suggest { border: 1.5px solid var(--line); border-radius: var(--r); background: #fff; margin-top: 4px; max-height: 220px; overflow: auto; box-shadow: var(--sh2); }
.suggest div { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.suggest div:hover { background: var(--sky); }

.info { background: #fff; border: 1.5px solid var(--line); border-left: 4px solid var(--indigo); border-radius: var(--r); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; box-shadow: var(--sh); }
.info.warn { border-left-color: var(--red); }
.info b { color: var(--navy); }

#toast {
  position: fixed; left: 50%; top: 70px; transform: translate(-50%, -12px); z-index: 50;
  background: var(--navy); color: #fff; padding: 13px 20px; border-radius: 100px; max-width: 92vw; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: pre-line; box-shadow: var(--sh2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red-d); border-radius: var(--r); }
#toast.ok { background: var(--green); color: var(--navy); }

.overlay { position: fixed; inset: 0; background: rgba(27,42,74,.92); z-index: 60; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; }
.overlay img, .overlay video { max-width: 96vw; max-height: 80vh; border-radius: var(--r); }

/* ---------- Connexion (même ambiance que l'accueil du site) ---------- */
body.login-page { background: var(--hero); min-height: 100vh; }
body.login-page::before {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 38px 38px;
}
.login { position: relative; max-width: 420px; margin: 0 auto; padding: 8vh 6px 24px; color: #fff; }
.login .logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; margin-bottom: 7vh; }
.login h2 { color: #fff; font-size: 40px; line-height: .98; letter-spacing: -.035em; margin: 18px 0 12px; }
.login h2 em { color: var(--green); font-style: normal; }
.login .sub { color: rgba(255,255,255,.65); margin: 0 0 28px; line-height: 1.7; }
.login .panel { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(20px); border-radius: var(--rl); padding: 20px; }
.login label { color: rgba(255,255,255,.8); }
.login input { background: rgba(255,255,255,.95); border-color: transparent; }

/* ---------- Impression ---------- */
.print-only { display: none; }
@media print {
  #topbar, #menu, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  main { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
@media (min-width: 800px) {
  .two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; align-items: start; }
  main { padding: 20px; }
}

/* ---------- Étiquettes 62 mm (Brother QL-800) : QR à gauche, infos patient à droite ---------- */
#print-labels { display: none; }
.plabel {
  --k: 1; /* facteur d'agrandissement selon la hauteur de l'étiquette */
  display: flex; gap: calc(1.2mm * var(--k)); align-items: center; padding: 1mm 3mm; background: #fff; color: #000;
  font-family: Arial, Helvetica, sans-serif; overflow: hidden; box-sizing: border-box;
}
.label-preview .plabel { border: 1px dashed #b8c2d8; }
.pl-qr { flex-shrink: 0; }
.pl-qr svg { width: 100%; height: 100%; display: block; }
.pl-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.12; }
.pl-txt > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-name { font-size: calc(8pt * var(--k)); font-weight: 900; color: #cc2222; }
.pl-ch { font-size: calc(6.3pt * var(--k)); font-weight: 700; color: #111; }
.pl-sec { font-size: calc(5pt * var(--k)); color: #444; }
.pl-prod { font-size: calc(5.6pt * var(--k)); font-weight: 700; color: #111; white-space: normal !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pl-prod b { color: #cc2222; }
.pl-foot { display: flex; justify-content: space-between; gap: 1mm; font-size: calc(4pt * var(--k)); color: #555; border-top: 0.3pt solid #ccc; margin-top: 0.3mm; padding-top: 0.2mm; }
input[type=range] { min-height: 30px; padding: 0; accent-color: var(--indigo); }
.item { flex-wrap: wrap; }
.item > .grow { flex: 1 1 55%; min-width: 0; }
.item-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
