/* ============================================================================
   Wasfa — Design system
   Sobre, professionnel, « logiciel métier ». Un seul accent (bleu médical).
   ============================================================================ */

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #f0f3f7;
  --border: #e4e9ef;
  --border-strong: #d2dae2;
  --text: #1b2733;
  --text-2: #566472;
  --text-3: #8794a1;
  --accent: #276e7b;
  --accent-hover: #1f5a65;
  --accent-press: #174550;
  --accent-tint: #e7f2f4;
  --accent-tint-2: #d3e8ec;
  --danger: #b5382b;
  --danger-tint: #f7ecea;
  --ring: rgba(39, 110, 123, 0.20);
  --r-sm: 5px;
  --r: 7px;
  --r-lg: 10px;
  --sh-1: 0 1px 2px rgba(20, 30, 45, 0.05), 0 1px 3px rgba(20, 30, 45, 0.05);
  --sh-2: 0 10px 34px rgba(18, 28, 42, 0.20), 0 2px 8px rgba(18, 28, 42, 0.10);
  --sh-pop: 0 6px 20px rgba(18, 28, 42, 0.14), 0 1px 3px rgba(18, 28, 42, 0.10);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-doc: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
}

input, button, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
input, textarea { user-select: text; }

.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico--lg { width: 34px; height: 34px; stroke-width: 1.4; }

/* ─────────────────────────  BARRE D'APPLICATION  ───────────────────────── */
.appbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand__mark { width: 34px; height: 34px; flex: none; display: block; }
.brand__mark svg { width: 100%; height: 100%; display: block; }
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__name { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; color: var(--accent); }
.brand__by { font-size: 10px; font-weight: 600; color: var(--text-3); letter-spacing: 0.2px; margin-top: 2px; }
.appbar__doctor { margin-left: 6px; flex: 1; color: var(--text-2); font-size: 13px; }
.appbar__doctor strong { color: var(--text); font-weight: 600; }
.appbar__doctor .sep { margin: 0 8px; color: var(--border-strong); }

/* ─────────────────────────  BOUTONS  ───────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: transparent;
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .13s ease, border-color .13s ease, box-shadow .13s ease, color .13s ease;
}
.btn .ico { width: 16px; height: 16px; }
.btn--accent { background: var(--accent); color: #fff; }
.btn--accent:hover { background: var(--accent-hover); }
.btn--accent:active { background: var(--accent-press); }
.btn--soft { background: var(--surface); color: var(--accent); border-color: var(--border-strong); }
.btn--soft:hover { background: var(--accent-tint); border-color: var(--accent-tint-2); }
.btn--ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--print { padding: 0 18px; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.iconbtn {
  width: 34px; height: 34px; border-radius: var(--r);
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--text-2);
  cursor: pointer; transition: background .13s;
}
.iconbtn:hover { background: var(--surface-3); color: var(--text); }
.iconbtn--light { color: rgba(255,255,255,.85); }
.iconbtn--light:hover { background: rgba(255,255,255,.14); color: #fff; }

/* ─────────────────────────  LAYOUT  ───────────────────────── */
.layout {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 344px 1fr;
  gap: 16px;
  padding: 16px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ─────────────────────────  PANNEAU PATIENT  ───────────────────────── */
.patient { padding: 0; }
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
}
.panel__title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .2px; }
.patient > .search, .patient__form, .history { padding: 0 18px; }

.search { position: relative; margin-bottom: 6px; }
.search__ico { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search__input {
  width: 100%; height: 38px; padding: 0 12px 0 34px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2);
  transition: border-color .13s, box-shadow .13s, background .13s;
}
.search__input:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--ring); }
.search__results {
  position: absolute; top: 42px; left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--r);
  box-shadow: var(--sh-pop); max-height: 280px; overflow-y: auto; padding: 4px;
}
.search__item { padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.search__item:hover, .search__item.is-active { background: var(--accent-tint); }
.search__item strong { font-weight: 600; }
.search__item small { display: block; color: var(--text-3); font-size: 12px; }
.search__none { padding: 12px 10px; color: var(--text-3); font-size: 13px; }

.patient__form {
  display: grid; grid-template-columns: 1fr 1fr; gap: 11px 12px;
  padding-top: 8px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.field label {
  font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: .2px;
}
.field .opt { font-weight: 500; color: var(--text-3); }
.field input[type="text"], .field input[type="number"], .field input[type="date"] {
  height: 36px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: #fff; transition: border-color .13s, box-shadow .13s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.inline { display: flex; align-items: center; gap: 8px; }
.input--age { width: 100%; }
.inline__unit { color: var(--text-3); font-size: 13px; }

/* Segment (bascule) */
.segment { display: inline-flex; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r); padding: 3px; gap: 3px; }
.segment button {
  border: none; background: transparent; cursor: pointer;
  padding: 7px 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 550; color: var(--text-2);
  transition: background .12s, color .12s, box-shadow .12s;
}
.segment button:hover { color: var(--text); }
.segment button.is-active { background: #fff; color: var(--accent); box-shadow: var(--sh-1); }
.segment--sm button { padding: 5px 12px; font-size: 12.5px; }

/* Historique */
.history { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-top: 14px; padding-bottom: 14px; }
.history__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.history__head h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 700; }
.history__count { font-size: 12px; color: var(--text-3); }
.history__list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.history__empty { color: var(--text-3); font-size: 13px; line-height: 1.5; margin: 6px 2px; }
.hist-item {
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px 11px; margin-bottom: 8px; background: var(--surface-2);
  transition: border-color .12s, background .12s;
}
.hist-item:hover { border-color: var(--border-strong); background: #fff; }
.hist-item__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hist-item__date { font-size: 12.5px; font-weight: 600; color: var(--text); }
.hist-item__tag { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-tint); padding: 2px 7px; border-radius: 20px; }
.hist-item__tag--cert { color: #7a5b12; background: #f5efdf; }
.hist-item__sum { font-size: 12.5px; color: var(--text-2); margin: 5px 0 8px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hist-item__dup { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0; }
.hist-item__dup .ico { width: 14px; height: 14px; }
.hist-item__dup:hover { text-decoration: underline; }

/* ─────────────────────────  PANNEAU TRAVAIL  ───────────────────────── */
.work { padding: 16px 20px 0; }
.segment--tabs { align-self: flex-start; margin-bottom: 16px; flex-wrap: wrap; }
.segment--tabs button { padding: 8px 20px; font-size: 14px; }

.doc-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow-y: auto; }
/* Le certificat (beaucoup de champs) doit pouvoir défiler sur petits écrans */
#paneCertificat { padding-bottom: 12px; }

/* Saisie ordonnance */
.rx-entry {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 16px 16px; margin-bottom: 14px;
}
.rx-entry__row { display: flex; gap: 12px; }
.rx-entry__row--2 { margin-top: 11px; align-items: flex-end; }
.field--grow { flex: 1; }
.field--duree { width: 140px; flex: none; }
.field--addbtn { flex: none; }
.field--addbtn .btn { height: 36px; }

.ac { position: relative; }
.ac__input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; transition: border-color .13s, box-shadow .13s; }
.ac__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.ac__list {
  position: absolute; top: 42px; left: 0; right: 0; z-index: 40;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--r);
  box-shadow: var(--sh-pop); max-height: 320px; overflow-y: auto; padding: 4px;
}
.ac__item { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.ac__item:hover, .ac__item.is-active { background: var(--accent-tint); }
.ac__brand { font-weight: 600; }
.ac__dose { color: var(--text); font-weight: 500; }
.ac__meta { margin-left: auto; color: var(--text-3); font-size: 12px; white-space: nowrap; }
.ac__dci { color: var(--text-2); font-size: 12.5px; }

/* Composeur : marque / dosage / posologie sélectionnables */
.rx-suggest { margin-top: 12px; display: flex; flex-direction: column; gap: 9px; padding-top: 12px; border-top: 1px dashed var(--border-strong); }
.rx-suggest__g { display: grid; grid-template-columns: 74px 1fr; align-items: start; gap: 10px; }
.rx-suggest__lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); padding-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  border-radius: 16px; padding: 4px 12px; font-size: 12.5px; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s; max-width: 100%; text-align: left; line-height: 1.35;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip--poso { border-radius: 8px; white-space: normal; }
.chip--dose { font-variant-numeric: tabular-nums; }

/* Constructeur de posologie : quantité · prise · moment */
.poso-builder { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pb-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.pb-lbl { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); width: 58px; flex: none; }
.pb-chip {
  border: 1px solid var(--border-strong); background: #fff; color: var(--text-2);
  border-radius: 16px; padding: 3px 11px; font-size: 12px; cursor: pointer; transition: all .12s; white-space: nowrap;
}
.pb-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.pb-chip.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pb-chip--form.is-drug { border-color: var(--accent-tint-2); color: var(--accent); font-weight: 600; }

/* Certificats */
.segment--wrap { display: flex; flex-wrap: wrap; width: 100%; }
.segment--wrap button { flex: 1 1 auto; }
#certFields { display: flex; flex-direction: column; gap: 14px; }
#certFields textarea {
  width: 100%; min-height: 56px; padding: 9px 11px; resize: vertical;
  border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff;
  font-family: inherit; font-size: 14px; line-height: 1.45;
}
#certFields textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
/* Modèles de compte rendu d'échographie */
.echo-models { display: flex; flex-wrap: wrap; gap: 6px; }
.echo-model { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 16px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
.echo-model:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.echo-model.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.cert-hint { margin: 2px 0 0; color: var(--text-2); font-size: 13px; line-height: 1.55; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; }
.cert-hint b { color: var(--text); font-weight: 600; }

/* Barre d'outils ordonnance (Modèles) */
.rx-toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }

/* Modèles d'ordonnance */
.tpl-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.tpl-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px; background: var(--surface-2);
  transition: border-color .12s, background .12s;
}
.tpl-item:hover { border-color: var(--border-strong); background: #fff; }
.tpl-item__info { min-width: 0; }
.tpl-item__name { font-weight: 600; font-size: 13.5px; }
.tpl-item__sum { font-size: 12px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.tpl-item__actions { display: flex; align-items: center; gap: 6px; flex: none; }
.tpl-item__tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); background: var(--surface-3); padding: 2px 7px; border-radius: 20px; }
.tpl-save { display: flex; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.tpl-save input { flex: 1; height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--r); }
.tpl-save input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

/* Liste des lignes de prescription */
.rx-list { flex: 1 0 auto; min-height: 120px; margin: 0 -4px; padding: 0 4px 16px; }
.rx-list__empty { min-height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-3); text-align: center; }
.rx-list__empty .ico { color: var(--border-strong); }
.rx-list__empty p { margin: 0; font-size: 13.5px; }

.rx-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 12px 12px 14px; border: 1px solid var(--border);
  border-radius: var(--r); margin-bottom: 9px; background: #fff;
}
.rx-item__num {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700; margin-top: 1px;
}
.rx-item__body { flex: 1; min-width: 0; }
.rx-item__med { font-weight: 600; font-size: 14.5px; }
.rx-item__det { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.rx-item__det .dot { margin: 0 7px; color: var(--border-strong); }
.rx-item__remove { flex: none; }
.rx-item__remove .ico { width: 16px; height: 16px; }
.rx-item.is-free .rx-item__num { background: var(--surface-3); color: var(--text-3); }

/* Certificat */
.cert-form { display: flex; flex-direction: column; gap: 14px; }
.cert-form__row { display: flex; gap: 14px; }
.field--jours { width: 180px; }
.cert-preview {
  margin-top: 18px; padding: 16px 18px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-lg); border-left: 3px solid var(--accent);
}
.cert-preview__label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 700; margin-bottom: 8px; }
.cert-preview p { margin: 0; font-size: 14.5px; line-height: 1.65; color: var(--text); }

/* Barre d'action */
.actionbar {
  margin: auto -20px 0; padding: 14px 20px;
  border-top: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
}
.actionbar__left, .actionbar__right { display: flex; align-items: center; gap: 12px; }
.actionbar__fmtlabel { font-size: 12px; font-weight: 600; color: var(--text-2); }

/* ─────────────────────────  MODALES  ───────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(20, 30, 42, 0.42); backdrop-filter: none; }
.modal__box {
  position: relative; width: 560px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px);
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal__head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.modal__body { padding: 18px 20px; overflow-y: auto; }
.modal__hint { margin: 0 0 16px; color: var(--text-2); font-size: 13px; line-height: 1.5; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 14px; }

.logo-row { display: flex; align-items: center; gap: 14px; }
.logo-preview {
  width: 96px; height: 60px; border: 1px dashed var(--border-strong); border-radius: var(--r);
  display: grid; place-items: center; background: var(--surface-2); overflow: hidden;
}
.logo-preview span { font-size: 11px; color: var(--text-3); }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; }

/* Aperçu / impression */
.modal--preview { flex-direction: column; align-items: stretch; justify-content: flex-start; background: #55606c; }
.preview-toolbar {
  height: 56px; flex: none; background: #2c343d; color: #fff;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px; z-index: 2;
}
.preview-toolbar__title { font-size: 14px; font-weight: 600; }
.preview-toolbar__right { display: flex; align-items: center; gap: 12px; }
.preview-toolbar__right .actionbar__fmtlabel { color: rgba(255,255,255,.75); }
.preview-toolbar__right .segment { background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.14); }
.preview-toolbar__right .segment button { color: rgba(255,255,255,.75); }
.preview-toolbar__right .segment button.is-active { background: #fff; color: var(--accent); }
.preview-scroll { flex: 1; overflow: auto; padding: 28px; display: flex; justify-content: center; align-items: flex-start; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: #21303e; color: #fff; padding: 11px 18px; border-radius: var(--r);
  font-size: 13.5px; box-shadow: var(--sh-2); z-index: 200; opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Démonstration : pastille + écran de blocage */
.demo-chip { font-size: 12px; font-weight: 600; color: #8a5a12; background: #fdf1dc; border: 1px solid #f2dcae; padding: 5px 11px; border-radius: 20px; white-space: nowrap; }
.demo-chip.is-warn { color: #b5382b; background: #f9e7e4; border-color: #eecac4; }
.demo-overlay { position: fixed; inset: 0; z-index: 500; background: rgba(20, 30, 42, 0.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.demo-overlay__box { background: #fff; border-radius: 14px; box-shadow: var(--sh-2); padding: 34px 40px; max-width: 460px; text-align: center; }
.demo-overlay__logo { width: 72px; height: 72px; display: inline-block; margin-bottom: 16px; }
.demo-overlay__logo svg { width: 100%; height: 100%; }
.demo-overlay__box h2 { margin: 0 0 12px; font-size: 20px; color: var(--text); font-weight: 650; }
.demo-overlay__box p { margin: 0 0 8px; color: var(--text-2); font-size: 14.5px; line-height: 1.55; }
.demo-overlay__box p:last-child { margin-bottom: 0; }
.demo-overlay__sub { color: var(--text-3) !important; }

/* Médicament ajouté par le médecin (badge dans l'autocomplétion) */
.ac__tag { display: inline-block; margin-left: 6px; font-size: 10.5px; font-weight: 600; color: var(--accent); background: var(--accent-tint); border: 1px solid var(--accent-tint-2); border-radius: 10px; padding: 1px 7px; vertical-align: middle; }

/* ─────────────────────────  RÉSEAU (PLUSIEURS POSTES)  ───────────────────────── */
/* Bandeau d'alerte : n'apparaît que si le dossier partagé est injoignable. */
.net-banner {
  height: 28px; display: flex; align-items: center; justify-content: center;
  background: #fbece3; color: #9b2f42; border-bottom: 1px solid #f2ccd6;
  font-size: 12.5px; font-weight: 600; padding: 0 16px; text-align: center;
  position: relative; z-index: 19;
}
body.has-net-banner .layout { height: calc(100vh - 56px - 28px); }

/* Section « plusieurs postes » dans les Paramètres */
.net-settings { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.net-settings__hint { margin: 2px 0 10px; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.net-settings .segment { display: inline-flex; }
.net-folder {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
}
.net-folder__path {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 8px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: "Consolas", "Courier New", monospace;
}
.net-settings__status { margin: 10px 0 0; font-size: 12.5px; font-weight: 600; }
.net-settings__status.is-ok { color: var(--accent); }
.net-settings__status.is-warn { color: var(--danger); }

/* Sous-titre de section dans les Paramètres (ex. en-tête en arabe) */
.settings-sep { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; margin-bottom: -2px; }
.settings-sep > label { font-weight: 650; color: var(--text); }

/* Sélecteur de style d'en-tête (couleur + police) */
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.style-swatch { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 9px 11px; background: #fff; border: 1px solid var(--border-strong); border-radius: var(--r); cursor: pointer; text-align: left; transition: border-color .12s, box-shadow .12s; overflow: hidden; }
.style-swatch:hover { border-color: var(--accent); }
.style-swatch.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--ring); }
.style-swatch__name { font-size: 15px; font-weight: 700; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.style-swatch__rule { height: 3px; width: 46px; border-radius: 2px; }
.style-swatch__lbl { font-size: 11.5px; color: var(--text-2); }

/* ─────────────────────────  EXAMENS COMPLÉMENTAIRES (panneau)  ───────────────────────── */
#paneExamen { overflow: hidden; }
.exam-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; flex: none; }
.exam-search { flex: 1 1 200px; margin: 0; position: relative; }
/* La barre d'examens n'a pas le padding 18px de la colonne patient → recaler la loupe */
.exam-search .search__ico { left: 12px; }
.exam-catalog { flex: 1 1 auto; min-height: 90px; overflow-y: auto; padding-right: 4px; }
.exam-group { margin-bottom: 12px; }
.exam-group__name { font-size: 11.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.exam-group__items { display: flex; flex-wrap: wrap; gap: 6px; }
.exam-chip { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 16px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
.exam-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.exam-chip.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.exam-empty { color: var(--text-3); font-size: 13px; padding: 8px 0; }

.exam-selected { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px; flex: none; }
.exam-selected__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.exam-selected__head h3 { margin: 0; font-size: 13px; font-weight: 650; color: var(--text); }
.exam-selected__count { font-size: 12px; color: var(--text-3); }
.exam-add { display: flex; gap: 8px; margin-bottom: 8px; }
.exam-add input { flex: 1; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; }
.exam-add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.exam-list { max-height: 30vh; overflow-y: auto; }
.exam-list__empty { color: var(--text-3); font-size: 13px; }
.exam-fam { margin-bottom: 8px; }
.exam-fam__name { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 3px; }
.exam-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--border); }
.exam-item__name { font-size: 13px; }
.exam-item__rm { width: 26px; height: 26px; }
.exam-item__rm .ico { width: 15px; height: 15px; }

/* Étiquette « Examen » dans l'historique */
.hist-item__tag--exam { color: #7a5b12; background: #fbf1da; }
/* Étiquette « Orientation » dans l'historique */
.hist-item__tag--orient { color: #3b4b8a; background: #e8ecf9; }

/* Orientation : espace sous chaque champ du formulaire */
.orient-form .field { margin-bottom: 12px; }
.orient-form textarea { width: 100%; resize: vertical; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; font-family: inherit; font-size: 13.5px; line-height: 1.5; }
.orient-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

/* ─────────────────────────  DOSSIER MÉDICAL  ───────────────────────── */
#paneDossier { overflow-y: auto; }
.dossier-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.dossier-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dossier-head__info { min-width: 0; }
.dossier-head__info h3 { margin: 0; font-size: 16px; font-weight: 650; color: var(--text); }
.dossier-head__count { font-size: 12.5px; color: var(--text-3); }
.consult-form { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px; margin-bottom: 14px; }
.consult-form .field { margin-bottom: 10px; }
.consult-form textarea { width: 100%; resize: vertical; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; font-family: inherit; font-size: 13.5px; line-height: 1.5; }
.consult-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.consult-form__actions { display: flex; justify-content: flex-end; gap: 8px; }
.dossier-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.dossier__empty { color: var(--text-3); font-size: 13.5px; padding: 12px 0; }
.consult { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-lg); background: var(--surface); padding: 12px 14px; box-shadow: var(--sh-1); }
.consult__date { font-size: 12.5px; font-weight: 650; color: var(--accent); margin-bottom: 8px; }
.consult__block { margin-bottom: 8px; }
.consult__block:last-child { margin-bottom: 0; }
.consult__lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); margin-bottom: 2px; }
.consult__txt { font-size: 13.5px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }
.consult__vitals { font-size: 13.5px; color: var(--text); font-weight: 600; }

/* Constantes (Taille / Poids / TA / FC / FR) — saisie des chiffres */
.vitals { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.vitals__item { display: flex; align-items: center; gap: 6px; }
.vitals__lbl { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.vitals__item input { width: 62px; height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; text-align: center; font-size: 13.5px; }
.vitals__item input#vTa { width: 72px; }
.vitals__item input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.vitals__unit { font-size: 12px; color: var(--text-3); }

/* ============================================================================
   LE DOCUMENT (ordonnance / certificat) — livrable-roi
   Dimensions en mm : l'aperçu à l'écran = l'impression, au pixel près.
   ============================================================================ */
.paper { background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.28); }
.paper[data-fmt="A4"] .doc { width: 210mm; min-height: 297mm; }
.paper[data-fmt="A5"] .doc { width: 148mm; min-height: 210mm; }

.doc {
  background: #fff; color: #16202b;
  display: flex; flex-direction: column;
  font-family: var(--font);
  position: relative; /* contexte pour le filigrane de démonstration */
}
/* Filigrane « DÉMONSTRATION » (version web de démonstration uniquement) */
.doc__watermark { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; justify-content: space-around; align-items: center; pointer-events: none; overflow: hidden; }
.doc__watermark span { font-size: 24pt; font-weight: 800; color: rgba(190, 40, 40, 0.11); letter-spacing: 3px; transform: rotate(-24deg); white-space: nowrap; }
.doc[data-fmt="A4"] { padding: 16mm 18mm 14mm; }
.doc[data-fmt="A5"] { padding: 11mm 12mm 10mm; font-size: 10.2pt; }
.doc[data-fmt="A4"] { font-size: 11.4pt; }

/* En-tête du document */
/* En-tête bilingue : français à gauche, arabe à droite, logo au centre */
.doc__header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8mm; }
.doc__ident { flex: 1 1 0; min-width: 0; }
.doc__logo-wrap { flex: 0 0 auto; display: flex; align-items: flex-start; padding-top: 1mm; }
.doc__logo { max-height: 22mm; max-width: 44mm; display: block; }
.doc__name { font-family: var(--doc-name-font, var(--font-doc)); font-size: 1.55em; font-weight: 700; color: #123; line-height: 1.15; }
.doc__spec { font-size: 1.02em; color: #2a3946; margin-top: 1mm; letter-spacing: .2px; }
.doc__contact { margin-top: 2.5mm; font-size: .82em; color: #47555f; line-height: 1.55; }
.doc__contact div { display: flex; gap: 6px; }
.doc__contact .k { color: #7c8894; min-width: 0; }
/* Colonne arabe (droite) — miroir de l'en-tête */
.doc__aside-ar { flex: 1 1 0; min-width: 0; text-align: right; direction: rtl; line-height: 1.5; }
.doc__name-ar { font-family: "Traditional Arabic", "Segoe UI", Tahoma, sans-serif; font-size: 1.7em; font-weight: 700; color: #123; line-height: 1.25; }
.doc__spec-ar { font-family: "Segoe UI", Tahoma, sans-serif; font-size: 1.05em; color: #2a3946; margin-top: 1mm; }
.doc__contact-ar { font-family: "Segoe UI", Tahoma, sans-serif; margin-top: 2.5mm; font-size: .84em; color: #47555f; line-height: 1.65; }
.doc__rule { height: 0; border: none; border-top: 2px solid var(--accent); margin: 5mm 0 0; }
.doc__rule2 { height: 0; border: none; border-top: 1px solid #d7dee4; margin: 1.2px 0 0; }

/* Ligne méta : date + patient */
.doc__meta { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 6mm; gap: 8mm; }
.doc__patient { font-size: .96em; }
.doc__patient .lbl { color: #7c8894; font-size: .82em; text-transform: uppercase; letter-spacing: .6px; }
.doc__patient .val { font-weight: 600; font-size: 1.12em; color: #16202b; margin-top: 1mm; }
.doc__patient .sub { color: #47555f; font-size: .92em; margin-top: .5mm; }
.doc__date { text-align: right; font-size: .92em; color: #2a3946; white-space: nowrap; }

/* Titre du document */
.doc__title { text-align: center; margin: 7mm 0 5mm; }
.doc__title span { font-size: .82em; letter-spacing: 3px; text-transform: uppercase; color: var(--accent); font-weight: 700; border-bottom: 1px solid var(--accent-tint-2); padding-bottom: 1.5mm; }

/* Corps : prescription */
.doc__body { flex: 1; }
.rx-line { display: flex; gap: 4mm; padding: 2.6mm 0; border-bottom: 1px dotted #dbe1e7; }
.rx-line:last-child { border-bottom: none; }
.rx-line__mark { color: var(--accent); font-weight: 700; }
.rx-line__content { flex: 1; }
.rx-line__med { font-weight: 700; font-size: 1.04em; }
.rx-line__det { color: #3c4a55; margin-top: .6mm; }
.rx-line__det .dot { margin: 0 2.2mm; color: #b7c0c8; }

/* Corps : certificat */
.doc__certbody { flex: 1; font-size: 1.05em; line-height: 1.8; margin-top: 8mm; }
.doc__certbody p { margin: 0 0 3mm; }
.doc__certbody p:empty { margin: 0; }
.doc__certbody .fill { font-weight: 600; }

/* Corps : examens complémentaires (« Prière de faire ») */
.doc__exams { flex: 1; margin-top: 5mm; }
.doc-exam__fam { margin-bottom: 5mm; break-inside: avoid; }
.doc-exam__famname { font-weight: 700; color: var(--accent); font-size: .9em; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--accent-tint-2); padding-bottom: 1mm; margin-bottom: 2.5mm; }
.doc-exam__items { column-count: 2; column-gap: 9mm; }
.doc-exam__item { display: flex; align-items: center; gap: 2.5mm; padding: 1.05mm 0; break-inside: avoid; font-size: .96em; }
.doc-exam__box { width: 3.3mm; height: 3.3mm; border: 1px solid #4a4a4a; border-radius: .5mm; flex: none; display: inline-block; }
.doc-exam__empty { color: #9aa4ad; }
.doc[data-fmt="A5"] .doc-exam__items { column-count: 1; }

/* Corps : orientation (lettre de liaison) */
.doc__orient { flex: 1; font-size: 1.05em; line-height: 1.8; margin-top: 6mm; }
.doc__orient p { margin: 0 0 3mm; }
.doc-orient__opts { margin: 1mm 0 3mm 4mm; }
.doc-orient__opt { display: flex; align-items: center; gap: 2.5mm; padding: 1mm 0; }
.doc-orient__box { width: 3.6mm; height: 3.6mm; border: 1px solid #333; border-radius: .5mm; display: inline-flex; align-items: center; justify-content: center; font-size: 2.9mm; line-height: 1; flex: none; color: #16202b; }

/* Dossier patient imprimable (export PDF) */
.dd-patient { margin: 4mm 0 1mm; font-size: 1.02em; }
.dd-section { margin: 6mm 0 2.5mm; font-weight: 700; color: var(--accent); font-size: .85em; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #dbe1e7; padding-bottom: 1mm; }
.dd-consult { border-left: 2px solid var(--accent); padding-left: 3.5mm; margin-bottom: 4.5mm; break-inside: avoid; }
.dd-date { font-weight: 700; color: var(--accent); font-size: .9em; margin-bottom: 1.5mm; }
.dd-block { margin-bottom: 2mm; }
.dd-lbl { font-size: .72em; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: #7c8894; }
.dd-txt { white-space: pre-wrap; font-size: .95em; color: #16202b; }
.dd-empty { color: #9aa4ad; }
.dd-doc { display: flex; gap: 4mm; padding: 1.2mm 0; border-bottom: 1px dotted #dbe1e7; font-size: .92em; }
.dd-doc-date { color: var(--accent); font-weight: 600; min-width: 34mm; flex: none; }

/* Pied : signature */
.doc__foot { margin-top: 10mm; display: flex; justify-content: flex-end; }
.doc__sign { text-align: center; width: 62mm; }
.doc__sign .lbl { font-size: .84em; color: #47555f; }
.doc__sign .box { height: 24mm; border-bottom: 1px solid #c4ccd3; margin-top: 1mm; }

/* ============================================================================
   IMPRESSION
   ============================================================================ */
#print-root { display: none; }

@media print {
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root .doc { box-shadow: none; }
  .paper { box-shadow: none; }
}

/* ============================================================================
   RESPONSIVE — tablette & téléphone (version web ; le bureau reste ≥ 1000px)
   ============================================================================ */
@media (max-width: 860px) {
  html, body { height: auto; overflow: auto; -webkit-text-size-adjust: 100%; }
  .appbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px 12px; position: sticky; top: 0; }
  .appbar__doctor { order: 5; flex-basis: 100%; margin-left: 0; }
  .demo-chip { order: 4; }
  .layout { display: block; height: auto; padding: 12px; }
  .panel { display: block; height: auto; overflow: visible; margin-bottom: 12px; }
  .patient > .search, .patient__form, .history { padding: 0 14px; }
  .work { padding: 14px; }
  .doc-pane { overflow: visible; }
  #paneExamen { overflow: visible; }
  .exam-catalog { overflow: visible; min-height: 0; }
  .exam-list { max-height: none; }
  .segment--tabs { width: 100%; }
  .segment--tabs button { padding: 8px 12px; font-size: 13px; }
  /* Modales plein écran sur mobile */
  .modal__box { max-width: 100%; width: 100%; max-height: 100%; border-radius: 0; }
  .rx-entry__row--2 { flex-wrap: wrap; }
  .field--duree, .field--addbtn { flex-basis: 100%; }
  /* Aperçu : le papier tient dans l'écran */
  .preview-scroll { padding: 10px; }
  .paper[data-fmt="A4"] .doc, .paper[data-fmt="A5"] .doc { width: 100%; min-height: 0; }
  .doc[data-fmt="A4"] { padding: 10mm 8mm; }
  .preview-toolbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 12px; }
}
@media (max-width: 480px) {
  .brand__by { display: none; }
  .btn span { font-size: 13px; }
  .style-grid { grid-template-columns: 1fr 1fr; }
}
