/* Suivi Labo — porcelaine froide et cire verte. Polices système uniquement (aucun appel externe). */
:root {
  --bg: #f3f5f4; --surface: #ffffff; --ink: #16201d; --muted: #5b6965; --line: #d9e0dd;
  --accent: #1f6b5a; --accent-ink: #ffffff; --accent-soft: #e3efeb;
  --late: #b3361f; --late-soft: #fbe9e5; --warn: #9a6300; --warn-soft: #fbf1dc; --ok: #2b6d34; --ok-soft: #e5f2e6;
  --f-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715; --surface: #18201d; --ink: #e6ecea; --muted: #9aa8a3; --line: #2a3532;
    --accent: #5fbfa6; --accent-ink: #0d1412; --accent-soft: #1d3029;
    --late: #f08a72; --late-soft: #3a201a; --warn: #e6b45a; --warn-soft: #352a14; --ok: #7fcb88; --ok-soft: #1c2e1f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body);
  padding: env(safe-area-inset-top, 0px) 16px calc(48px + env(safe-area-inset-bottom, 0px)); }
.wrap { max-width: 1180px; margin: 0 auto; padding-block: 20px; display: flex; flex-direction: column; gap: 18px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; margin-bottom: 10px; }
p { margin: 0; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: var(--r); font-weight: 500; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--late); border-color: var(--late); }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

.top { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.who { font-size: 0.85rem; color: var(--muted); }
.rgpd { font-size: 0.86rem; color: var(--muted); border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.rgpd b { color: var(--ink); }
.notice { padding: 12px 14px; border-radius: var(--r); background: var(--warn-soft); font-size: 0.9rem; }
.notice.ok { background: var(--ok-soft); }

/* Écrans de connexion */
.auth { max-width: 420px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 24px; display: flex; flex-direction: column; gap: 16px; }
.secret { font-family: var(--f-mono); font-size: 1.05rem; letter-spacing: 0.06em; background: var(--bg); border-radius: var(--r); padding: 10px 12px; word-break: break-all; user-select: all; }
.steps-text { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }

/* Formulaires */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form.one { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label, .field .label { font-size: 0.82rem; font-weight: 600; }
.hint { font-size: 0.76rem; color: var(--muted); }
.field input, .field select, .field textarea, .compose textarea { border: 1px solid var(--line); background: var(--bg); border-radius: var(--r); padding: 8px 10px; width: 100%; }
.code-input { font-family: var(--f-mono); font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; }
.err { color: var(--late); font-size: 0.85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }

/* Synthèse et filtres */
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { display: flex; align-items: baseline; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.stat strong { font-family: var(--f-mono); font-size: 1.1rem; }
.stat.is-late strong { color: var(--late); }
.stat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters input, .filters select { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; min-width: 0; }
.filters input { flex: 1 1 220px; }

/* Liste des cas */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 240px 170px 100px; gap: 12px; align-items: center; padding: 12px 16px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.row:first-child { border-top: 0; }
button.row:hover { background: var(--accent-soft); }
.row.head { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.code { font-family: var(--f-mono); font-weight: 500; }
.what { min-width: 0; }
.what small { display: block; color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due { font-family: var(--f-mono); font-size: 0.88rem; }
.due.late { color: var(--late); font-weight: 600; }
.cab { font-size: 0.84rem; color: var(--muted); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 800px) {
  .row.head { display: none; }
  .row { grid-template-columns: 1fr auto; grid-template-areas: "code status" "what what" "cab due"; }
  .row > .code { grid-area: code; } .row > .what { grid-area: what; } .row > .cab { grid-area: cab; } .row > .st { grid-area: status; } .row > .due { grid-area: due; text-align: right; }
}

.pill { display: inline-flex; max-width: 100%; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.s-late { background: var(--late-soft); color: var(--late); }
.pill.s-ok { background: var(--ok-soft); color: var(--ok); }
.pill.s-warn { background: var(--warn-soft); color: var(--warn); }
.pill.s-muted { background: var(--bg); color: var(--muted); }
.badge { font-size: 0.72rem; color: var(--muted); margin-left: 6px; }

/* Panneau latéral */
.scrim { position: fixed; inset: 0; background: rgba(10, 16, 14, 0.45); z-index: 10; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 100%); background: var(--surface); z-index: 11; display: flex; flex-direction: column; border-left: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-body { overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 22px; flex: 1; }
.close { border: 0; background: none; font-size: 1.5rem; line-height: 1; padding: 4px 8px; color: var(--muted); }
.mt { margin-top: 6px; }
@media (prefers-reduced-motion: no-preference) { .panel { animation: slide 0.18s ease-out; } @keyframes slide { from { transform: translateX(24px); opacity: 0.6; } } }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.facts > div { min-width: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } }

.timeline { list-style: none; margin: 0 0 12px; padding: 0; }
.timeline li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding-bottom: 10px; position: relative; color: var(--muted); }
.timeline li::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); margin-top: 5px; z-index: 1; }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li.done { color: var(--ink); }
.timeline li.done::before { background: var(--accent); border-color: var(--accent); }
.timeline li.done:not(:last-child)::after { background: var(--accent); }
.timeline li.current { font-weight: 600; }
.timeline li.current::before { box-shadow: 0 0 0 3px var(--accent-soft); }
.timeline small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }

.filelist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.file { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); }
.file > div { min-width: 0; }
.file .name { font-weight: 500; overflow-wrap: anywhere; }
.file.gone { opacity: 0.6; }
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 14px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
progress { width: 100%; accent-color: var(--accent); }

.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 12px; border-radius: var(--r); max-width: 88%; }
.msg.labo { align-self: flex-start; border: 1px solid var(--line); background: var(--surface); }
.msg.cabinet { align-self: flex-end; background: var(--accent-soft); }
.msg .meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.msg p { white-space: pre-wrap; overflow-wrap: anywhere; }
.compose { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.compose textarea { flex: 1; min-width: 0; }
.confirm { padding: 12px; border-radius: var(--r); background: var(--late-soft); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Administration */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tr.inactive td { color: var(--muted); }
.reveal { padding: 14px; border-radius: var(--r); background: var(--ok-soft); display: flex; flex-direction: column; gap: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r); z-index: 20; font-size: 0.9rem; max-width: calc(100% - 32px); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field .checks input { width: auto; padding: 0; }
.checks label { font-weight: 400; font-size: 0.92rem; white-space: nowrap; }
.mailpref { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); padding: 0 6px; }
.head-actions { display: flex; gap: 8px; align-items: flex-start; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; width: fit-content; max-width: 100%; flex-wrap: wrap; }
.seg-btn { border: 0; background: var(--bg); padding: 8px 14px; font-size: 0.9rem; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#print-root { display: none; }

/* ---------- Impression du bon de commande (A4) ---------- */
@page { size: A4; margin: 14mm; }
@media print {
  body { background: #fff !important; color: #000 !important; padding: 0 !important; font-size: 11pt; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: flex !important; flex-direction: column; gap: 7mm; color: #000; }
  #print-root * { color: #000; }
  .p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10mm; border-bottom: 2px solid #000; padding-bottom: 4mm; }
  .p-cab { font-size: 14pt; font-weight: 700; }
  .p-title { text-align: right; font-size: 9pt; letter-spacing: 0.08em; font-weight: 600; }
  .p-code { font-family: var(--f-mono); font-size: 26pt; font-weight: 700; letter-spacing: 0.04em; margin-top: 1mm; }
  .p-small { font-size: 8pt; letter-spacing: 0; font-weight: 400; }
  .p-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 8mm; align-items: start; }
  .p-table { width: 100%; border-collapse: collapse; font-size: 10.5pt; }
  .p-table th, .p-table td { border: 1px solid #000; padding: 2.2mm 3mm; text-align: left; vertical-align: top; }
  .p-table th { width: 38%; font-weight: 600; background: #f0f0f0; }
  .p-label { font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin: 0 0 2mm; }
  .p-label + .odonto { margin-bottom: 5mm; }
  .odonto { width: 100%; height: auto; display: block; }
  .odonto .tooth { fill: #fff; stroke: #000; stroke-width: 1; }
  .odonto .tooth.on { fill: #000; }
  .odonto .tnum { font: 600 11px var(--f-body); fill: #000; }
  .odonto .tnum.on { font-weight: 800; text-decoration: underline; }
  .odonto .midline { stroke: #000; stroke-dasharray: 3 3; }
  .odonto .side { font: italic 8.5px var(--f-body); fill: #000; }
  .p-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5mm 4mm; font-size: 9.5pt; }
  .pbox { display: flex; gap: 2mm; align-items: center; }
  .pbox .sq { width: 4mm; height: 4mm; border: 1px solid #000; display: inline-flex; align-items: center; justify-content: center; font-size: 8pt; flex: none; }
  .p-notes { border: 1px solid #000; min-height: 35mm; padding: 3mm; white-space: pre-wrap; font-size: 10.5pt; }
  .p-lines { display: flex; flex-direction: column; gap: 6mm; font-size: 10pt; }
  .p-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 8mm; }
  .p-sign > div { border-bottom: 1px solid #000; height: 26mm; }
  .p-foot { border-top: 1px solid #000; padding-top: 2mm; font-size: 8pt; }
}
