/* Charte « Compagnons » (compagnons-cyber.fr), reprise de PHARE : bleu nuit #0D1F2D / #1D2E3D / #354656,
   sarcelle #0D6E6E / #316C6C / #4A9D9C, rouge d'alerte, pêche. Nuit par défaut, jour au choix (bas de la barre latérale).
   Police Source Sans 3 embarquée : aucune dépendance réseau. */
@font-face { font-family: "Source Sans 3"; font-weight: 400; src: url(../vendor/fonts/source-sans-3-400.woff2) format("woff2"), url(../vendor/fonts/source-sans-3-ext-400.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Source Sans 3"; font-weight: 600; src: url(../vendor/fonts/source-sans-3-600.woff2) format("woff2"), url(../vendor/fonts/source-sans-3-ext-600.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Source Sans 3"; font-weight: 700; src: url(../vendor/fonts/source-sans-3-700.woff2) format("woff2"), url(../vendor/fonts/source-sans-3-ext-700.woff2) format("woff2"); font-display: swap; }

:root {
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 12px; --radius-sm: 8px; --side-w: 228px; --ctl-h: 38px;
  --brand: #0D6E6E; --brand-hover: #316C6C; --brand-ink: #FFFFFF;
  /* jour */
  --bg: #EEF3F5; --surface: #FFFFFF; --surface2: #E6EDF1; --ink: #0D1F2D; --ink2: #354656; --muted: #56697A; --rule: #D3DEE4; --rule2: #E3EAEE;
  --accent: #0D6E6E; --accent-ink: #FFFFFF; --accent-soft: #DCEFEE;
  --danger: #D42A2A; --danger-bg: #FDE3E1; --warn: #A8650A; --warn-bg: #FFF1CC; --ok: #1B7F4C; --ok-bg: #E3F3EA; --info-bg: #DCEFEE;
  --peach: #C25A12;
  --sel: rgba(13,110,110,.13); --shadow: 0 8px 28px rgba(13,31,45,.14); --flat: 0 1px 2px rgba(13,31,45,.08);
  --side-bg: #0D1F2D; --side-ink: #E0E0E0; --side-muted: #9DB0BF; --side-hover: #1D2E3D; --side-rule: #213345; --side-accent: #4FB0AE;
  --btn-rule: #D5DBE5;
  color-scheme: light;
}
:root[data-theme="compagnons-dark"] {
  --bg: #0D1F2D; --surface: #14283A; --surface2: #1D2E3D; --ink: #F2F6F8; --ink2: #D5DEE5; --muted: #93A7B6; --rule: #2A3E50; --rule2: #1F3344;
  --accent: #4FB0AE; --accent-ink: #06191A; --accent-soft: #143B40;
  --danger: #FF5C5C; --danger-bg: #47202A; --warn: #F2B85C; --warn-bg: #3D3014; --ok: #4DC57E; --ok-bg: #163827; --info-bg: #143B40;
  --peach: #FFC9A0;
  --sel: rgba(79,176,174,.22); --shadow: 0 12px 32px rgba(0,0,0,.5); --flat: none;
  --side-bg: #0A1925; --side-hover: #1D2E3D; --side-rule: #1D2E3D; --side-muted: #93A7B6;
  --btn-rule: #334054;
  color-scheme: dark;
}

/* ===================== Base ===================== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; font: 15px/1.45 var(--sans); color: var(--ink); background: var(--bg); display: flex; align-items: stretch; -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 .75rem; letter-spacing: 0; }
h2 { font-size: 16px; font-weight: 700; margin: 1.4rem 0 .6rem; color: var(--ink); }
h3 { font-size: 14px; font-weight: 700; margin: 1rem 0 .4rem; }
.card > h2:first-child, section:first-of-type > h2:first-child, .card > section:first-child h2 { margin-top: 0; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface2); padding: 0 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { color: var(--muted); font-style: italic; padding: .5rem 0; }
.grow { flex: 1; min-width: 0; }

/* ===================== Champs ===================== */
label { display: block; margin-bottom: .75rem; font-size: 13px; color: var(--muted); }
label small { font-size: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 8px 11px; min-width: 0;
}
:root[data-theme="compagnons-dark"] :is(input, select, textarea) { background: var(--bg); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
input[type=color] { padding: 3px; height: var(--ctl-h); }
input[type=date] { min-height: var(--ctl-h); -webkit-appearance: none; appearance: none; }
input[readonly] { opacity: .65; cursor: not-allowed; }
label.check { display: flex; gap: .55rem; align-items: flex-start; color: var(--ink); }
label.check input { width: auto; margin: .2rem 0 0; flex: none; }
label.check > span { display: flex; flex-direction: column; }
.hint { display: block; margin-top: .25rem; font-size: 12.5px; color: var(--muted); }
.hint.good { color: var(--ok); } .hint.bad { color: var(--danger); }
.code-input { font-family: var(--mono); letter-spacing: .14em; text-transform: uppercase; font-size: 18px; text-align: center; }

.grid2, .grid3, .grid4 { display: grid; gap: 0 .9rem; }
.grid2 > *, .grid3 > *, .grid4 > * { min-width: 0; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: 92px repeat(3, minmax(0, 1fr)) 110px; }
.span2 { grid-column: span 2; }

/* ===================== Boutons ===================== */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: var(--ctl-h);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand); border-radius: 10px; padding: 7px 15px; margin: 0;
}
button:hover, .button:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
:root[data-theme="compagnons-dark"] :is(button, .button):not(.ghost):not(.danger):not(.icon) { border-color: #1A8A88; }
button.ghost, .button.ghost { background: var(--surface); color: var(--ink); border-color: var(--btn-rule); }
button.ghost:hover, .button.ghost:hover { background: var(--surface2); border-color: var(--muted); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-bg); }
button.icon { background: transparent; color: var(--muted); border: none; min-height: 0; padding: .3rem .5rem; }
button.icon:hover { color: var(--ink); background: var(--surface2); }
button.small, .button.small, .small-btn { min-height: 30px; padding: 4px 11px; font-size: 13px; border-radius: var(--radius-sm); }
button:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: .75rem 0; }
.row.end { justify-content: flex-end; }
.ic { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ===================== Coque : barre latérale, en-tête ===================== */
.side { width: var(--side-w); flex: 0 0 var(--side-w); position: sticky; top: 0; height: 100vh; height: 100dvh;
  background: var(--side-bg); color: var(--side-ink); border-right: 1px solid var(--side-rule); display: flex; flex-direction: column; z-index: 12; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; text-decoration: none; color: #FFFFFF; }
.brand-mark { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; background: var(--brand); color: #FFFFFF;
  font-weight: 700; font-size: 15px; border-radius: 8px; letter-spacing: .04em; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { display: block; font-size: 11.5px; font-weight: 600; color: var(--side-muted); letter-spacing: .06em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--side-muted);
  text-decoration: none; font-weight: 600; font-size: 14.5px; }
.nav a:hover { color: #FFFFFF; background: var(--side-hover); }
.nav a.on { color: #FFFFFF; background: rgba(79,176,174,.18); box-shadow: inset 3px 0 0 var(--side-accent); }
.nav-group { margin: 10px 10px 2px; font-size: 11px; font-weight: 700; color: var(--side-muted); letter-spacing: .08em; text-transform: uppercase; opacity: .75; }
.tile { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 1px solid var(--side-rule); color: var(--side-muted); background: transparent; }
.tile .ic { width: 15px; height: 15px; }
.nav a:hover .tile { color: #FFFFFF; border-color: var(--side-muted); }
.nav a.on .tile { color: #06191A; background: var(--side-accent); border-color: var(--side-accent); }
.nav .count { margin-left: auto; }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #FFFFFF; font-size: 11.5px; font-weight: 700; }
.side-foot { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid var(--side-rule); display: flex; flex-direction: column; gap: 8px; }
.side-foot .who { font-size: 13px; color: var(--side-ink); line-height: 1.35; }
.side-foot .who small { display: block; color: var(--side-muted); font-size: 12px; }
.side-foot button { justify-content: flex-start; background: transparent; color: var(--side-muted); border-color: transparent; min-height: 32px; padding: 4px 8px; font-size: 13.5px; }
.side-foot button:hover { color: #FFFFFF; background: var(--side-hover); border-color: transparent; }

.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 56px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--rule); box-shadow: inset 0 3px 0 var(--brand); }
.top h1 { margin: 0; font-size: 18px; }
.top .crumb { color: var(--muted); font-size: 13px; font-weight: 600; }
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 20px 24px 48px; }
main.wide { max-width: 1320px; }
.legal { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 24px; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.banner.crit { background: var(--danger-bg); color: var(--danger); }

/* ===================== Panneaux ===================== */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.25rem 1.35rem; margin-bottom: 1rem; box-shadow: var(--flat); min-width: 0; overflow-wrap: anywhere; }
.card.narrow, .narrow { max-width: 660px; margin-left: auto; margin-right: auto; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.card-head h2 { margin: 0; }
.card-head .tile { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.notice { background: var(--info-bg); color: var(--accent); padding: .65rem .85rem; border-radius: var(--radius-sm); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.crit { background: var(--danger-bg); color: var(--danger); }
.errors p { background: var(--danger-bg); color: var(--danger); padding: .55rem .8rem; border-radius: var(--radius-sm); margin: .4rem 0; }
.identity { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: .75rem 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 1rem 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.1rem; margin: .9rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.secret { font: 700 26px/1.2 var(--mono); letter-spacing: .12em; text-align: center; color: var(--ink); background: var(--accent-soft); padding: .9rem; border-radius: var(--radius-sm); user-select: all; border: 1px dashed var(--accent); }

/* ===================== Badges, statuts ===================== */
.badges { display: flex; gap: .3rem; flex-wrap: wrap; margin: .3rem 0; }
.badge, .status { display: inline-block; width: fit-content; font-size: 12px; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.badge.block, .status.suspended, .status.rejected, .badge.error { background: var(--danger-bg); color: var(--danger); }
.badge.warn, .status.pending, .badge.warning { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--accent); }
.badge.ok, .status.active { background: var(--ok-bg); color: var(--ok); }
.badge.neutral { background: var(--surface2); color: var(--ink2); }

/* ===================== Tableaux ===================== */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: .55rem .65rem; border-bottom: 1px solid var(--rule2); vertical-align: top; }
table.grid th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .03em; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover, table.grid tbody tr.clickable:focus { background: var(--sel); outline: none; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.mono { font-family: var(--mono); font-size: 13px; }

/* ===================== Indicateurs (santé, tableaux de bord) ===================== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .85rem 1rem; }
.stat b { display: block; font-size: 24px; font-weight: 700; color: var(--accent); line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.warn b { color: var(--warn); } .stat.crit b { color: var(--danger); }
.state { display: flex; align-items: center; gap: .8rem; padding: .9rem 1.1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 700; }
.state.ok { background: var(--ok-bg); color: var(--ok); } .state.warn { background: var(--warn-bg); color: var(--warn); } .state.crit { background: var(--danger-bg); color: var(--danger); }
.state .ic { width: 22px; height: 22px; }
.spark { width: 100%; height: 70px; display: block; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark path.area { fill: var(--accent-soft); stroke: none; }
.issues { list-style: none; padding: 0; margin: 0; }
.issues li { display: flex; gap: .5rem; align-items: flex-start; padding: .45rem 0; border-bottom: 1px solid var(--rule2); }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.toolbar label { margin: 0; min-width: 170px; }
.cols2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.cols2 > .card { margin-bottom: 0; }

/* ===================== Connexion ===================== */
body.anonymous .side, body.anonymous .top, body.anonymous .legal { display: none; }
body.anonymous main { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; max-width: none; padding: 24px 16px; }
.login-card { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 28px 28px 24px; box-shadow: var(--shadow); }
.login-card.wide { max-width: 680px; }
.login-card .brand { padding: 0 0 6px; color: var(--ink); }
.login-card .brand-name { color: var(--ink); }
.login-card .brand-sub { color: var(--muted); }
.login-card h1 { font-size: 21px; margin: 14px 0 6px; display: flex; align-items: center; gap: 10px; }
.login-card h1 .ic { width: 22px; height: 22px; color: var(--accent); }
.login-card p { color: var(--ink2); line-height: 1.5; }
.login-card .block { width: 100%; margin-top: 10px; }
.login-foot { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.or-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 14px 0 4px; }
.or-sep::before, .or-sep::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

/* ===================== Ordonnance ===================== */
.steps { display: flex; gap: .6rem; list-style: none; padding: 0; margin: 0 0 1.25rem; counter-reset: s; flex-wrap: wrap; }
.steps li { counter-increment: s; color: var(--muted); font-size: 14px; font-weight: 600; }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; margin-right: .35rem; border-radius: 50%; border: 1px solid var(--rule); }
.steps li.current { color: var(--accent); }
.steps li.current::before { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.steps li.done::before { content: "✓"; color: var(--ok); }
#sigpad { width: 100%; max-width: 600px; aspect-ratio: 600 / 220; height: auto; border: 1px dashed var(--rule); border-radius: var(--radius-sm); background: #fff; touch-action: none; display: block; }
.template-editor { display: grid; grid-template-columns: 1fr 1.1fr; gap: 1rem; }
.preview { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 14px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: #8a97a3; align-self: start; }
.preview canvas { display: block; width: 100%; max-width: 600px; aspect-ratio: 210 / 297; height: auto; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.search { position: relative; }
.results { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; margin: .3rem 0 0; padding: 0; list-style: none; max-height: 360px; overflow: auto;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.results li { padding: .55rem .8rem; border-bottom: 1px solid var(--rule2); cursor: pointer; display: flex; flex-direction: column; gap: .1rem; }
.results li:hover, .results li.active { background: var(--sel); }
.results li.blocked { opacity: .55; cursor: not-allowed; }
.results li.none { cursor: default; color: var(--muted); }
.ligne { border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: .8rem; margin: .75rem 0; background: var(--surface); }
.ligne-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.ligne-head .tools { margin-left: auto; display: flex; }
.num { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 700; }
input.label { font-weight: 700; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--btn-rule); border-radius: 10px; background: var(--surface); }
.seg button { background: transparent; color: var(--muted); border: 0; border-radius: 7px; min-height: 26px; padding: 0 10px; font-size: 13px; }
.seg button:hover { background: var(--surface2); color: var(--ink); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
#addFree { margin: .25rem 0 1rem; }
.sticky { position: sticky; bottom: 0; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); }
.history { list-style: none; padding: 0; margin: 1rem 0 0; }
.history li { display: flex; gap: 1rem; justify-content: space-between; align-items: center; padding: .75rem 0; border-bottom: 1px solid var(--rule2); }
.history .tools { display: flex; gap: .3rem; flex-shrink: 0; }
.activites { border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: .5rem .9rem; margin: 0 0 1rem; }
.activites legend { font-size: 13px; color: var(--muted); padding: 0 .3rem; }
label.check.activite { margin: .5rem 0; }

/* ===================== Comparaison (administration) ===================== */
.compare { display: grid; grid-template-columns: max-content 1fr 1fr; font-size: 14px; }
.compare > * { padding: .45rem .6rem; border-bottom: 1px solid var(--rule2); white-space: pre-line; }
.compare .head { font-weight: 700; color: var(--muted); font-size: 12px; }
.compare .k { color: var(--muted); }
.compare .diff { background: var(--warn-bg); }
pre.detail { margin: 0; font-size: 12px; white-space: pre-wrap; color: var(--muted); font-family: var(--mono); }

/* ===================== Dialogues, toasts ===================== */
dialog { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); color: var(--ink); max-width: min(520px, calc(100vw - 32px)); width: 100%; padding: 1.3rem 1.4rem; box-shadow: var(--shadow); }
dialog.wide-dialog { max-width: min(920px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(6,16,24,.55); }
dialog h2 { margin-top: 0; }
.toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--bg);
  padding: .65rem 1.05rem; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); font-weight: 600; }
.toast.error { background: var(--danger); color: #fff; }

/* ===================== Mobile : la barre latérale devient une barre du haut (comme PHARE) ===================== */
@media (max-width: 980px) {
  body { flex-direction: column; }
  .side { position: sticky; top: 0; width: 100%; flex: none; height: auto; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--side-rule);
    padding: env(safe-area-inset-top) 6px 0; }
  .brand { padding: 8px; }
  .brand-name, .brand-sub, .nav-group { display: none; }
  .nav { flex-direction: row; padding: 0; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 10px 8px; font-size: 13.5px; white-space: nowrap; }
  .nav a .tile { width: 24px; height: 24px; }
  .side-foot { margin: 0; padding: 0 4px; border: 0; flex-direction: row; gap: 2px; }
  .side-foot .who, .side-foot .lbl { display: none; }
  .side-foot button { padding: 4px 6px; }
  .top { position: static; padding: 10px 16px; min-height: 0; }
  main { padding: 16px 16px 40px; }
  .cols2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .template-editor { grid-template-columns: 1fr; }
  .history li { flex-direction: column; align-items: stretch; }
  .compare { grid-template-columns: 1fr; } .compare .head { display: none; }
  .nav a .lbl { display: none; }
  .nav a.on .lbl { display: inline; }
}

#ms-icons { position: absolute; width: 0; height: 0; overflow: hidden; }
body.restricted .nav .app-only { display: none; }
.row > input, .row > select { width: auto; margin-top: 0; }
.row > input { flex: 1 1 200px; }
.row > select { flex: 0 0 auto; }
.impersonation { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .6rem 24px; background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--rule); font-size: 14px; }
.impersonation > span { flex: 1; min-width: 220px; line-height: 1.45; }
.impersonation > span .ic { vertical-align: -3px; margin-right: .3rem; }
.card table.grid { overflow-wrap: normal; }
table.grid td.mono { white-space: nowrap; }

/* ===================== iPhone / Safari iOS ===================== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
/* Safari zoome sur tout champ de moins de 16 px : jamais en dessous */
input, select, textarea { font-size: 16px; }
/* listes déroulantes à la charte (Safari impose sinon son style natif) */
select {
  -webkit-appearance: none; appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2393A7B6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
/* dates : Safari centre la valeur et réduit la hauteur */
input[type=date]::-webkit-date-and-time-value { text-align: left; }
input[type=date] { line-height: 1.4; }
.results { max-height: min(360px, 50dvh); -webkit-overflow-scrolling: touch; }

/* écrans tactiles : cibles d'au moins 44 × 44 px (recommandation Apple) */
@media (pointer: coarse) {
  button, .button { min-height: 44px; }
  button.small, .button.small, .small-btn { min-height: 44px; padding: 6px 14px; }
  button.icon { min-width: 44px; min-height: 44px; }
  .seg button { min-height: 44px; padding: 0 14px; }
  select { min-height: 44px; }
  .nav a { min-height: 44px; min-width: 44px; justify-content: center; }
  .side-foot button { min-height: 44px; min-width: 44px; }
  label.check input { width: 22px; height: 22px; }
  input[type=color] { height: 44px; }
  .history li .tools button { min-width: 44px; }
  button:active, .button:active, .nav a:active { opacity: .75; }
}
@media (hover: none) {
  .nav a:hover { background: none; color: var(--side-muted); }
  .nav a.on:hover { background: rgba(79,176,174,.18); color: #FFFFFF; }
}

/* encoche en paysage */
@supports (padding: max(0px)) {
  main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .top { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}

.top-actions { display: none; }

/* ---- Application médecin sur téléphone : barre d'onglets en bas, comme une application iOS ---- */
@media (max-width: 720px) {
  body[data-app="medecin"] .side {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 30; height: auto;
    padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    border-top: 1px solid var(--side-rule); border-bottom: 0;
  }
  body[data-app="medecin"] .side .brand, body[data-app="medecin"] .side .side-foot, body[data-app="medecin"] .nav-group { display: none; }
  body[data-app="medecin"] .nav { flex: 1; justify-content: space-around; overflow: visible; gap: 0; }
  body[data-app="medecin"] .nav a {
    flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 7px 2px 6px; font-size: 10.5px; font-weight: 600;
    border-radius: 0; box-shadow: none; text-align: center; line-height: 1.1;
  }
  body[data-app="medecin"] .nav a .lbl { display: block !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  body[data-app="medecin"] .nav a .tile { width: 30px; height: 26px; border: 0; }
  body[data-app="medecin"] .nav .lbl-long { display: none; }
  body[data-app="medecin"] .nav a.on { background: none; box-shadow: none; color: var(--side-accent); }
  body[data-app="medecin"] .nav a.on .tile { background: rgba(79,176,174,.22); color: var(--side-accent); }
  body[data-app="medecin"] .shell { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  body[data-app="medecin"] .sticky { bottom: calc(62px + env(safe-area-inset-bottom)); padding-bottom: .75rem; }
  /* clavier ouvert : la barre s'efface pour ne pas masquer le champ saisi */
  body[data-app="medecin"].kbd .side { display: none; }
  body[data-app="medecin"].kbd .shell { padding-bottom: 0; }
  body[data-app="medecin"].kbd .sticky { bottom: 0; }
  body[data-app="medecin"] .top { position: sticky; top: 0; padding-top: max(10px, env(safe-area-inset-top)); }
  body[data-app="medecin"] .top-actions { display: flex; gap: 2px; margin-left: auto; }
  .top-actions button { background: transparent; border: 0; color: var(--muted); min-width: 44px; min-height: 44px; padding: 0; }
  .top-actions button .lbl { display: none; }
  .top-actions button .ic { width: 20px; height: 20px; }
  body.anonymous .top-actions { display: none; }
  .top h1 { font-size: 17px; }
}

/* ---- Dialogues sur téléphone : panneau qui monte du bas ---- */
@media (max-width: 720px) {
  dialog, dialog.wide-dialog {
    margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
  }
  dialog .row { flex-direction: column; align-items: stretch; }
  dialog .row > * { width: 100%; }
  dialog .row .grow { display: none; }
  #deliver .row #deliverShare { order: -1; }
}
.deliver-preview { display: block; width: auto; max-width: 100%; max-height: min(420px, 42dvh); margin: .4rem auto .8rem; aspect-ratio: 210 / 297; height: auto; background: #fff; border-radius: 4px; box-shadow: 0 4px 18px rgba(0,0,0,.3); }
