:root {
  color-scheme: light dark;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0284c7;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --ko: #b91c1c;
  --ko-bg: #fee2e2;
  --warn-bg: #fef3c7;
  --warn: #92400e;
  --info-bg: #e0f2fe;
  --code-bg: #f8fafc;
  --radius: 14px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #111827;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1f2937;
    --accent: #38bdf8;
    --accent-text: #0f172a;
    --ok: #4ade80;
    --ok-bg: #14532d;
    --ko: #fca5a5;
    --ko-bg: #450a0a;
    --warn-bg: #451a03;
    --warn: #fcd34d;
    --info-bg: #0c4a6e;
    --code-bg: #0f172a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--safe-top) + 12px); }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
}

a { color: var(--accent); }
code { font-size: .85em; word-break: break-all; }

.top {
  background: #0f172a;
  color: #f8fafc;
  padding: calc(var(--safe-top) + 16px) 16px 16px;
}
.top h1 { margin: 0; font-size: 1.5rem; }
.top p { margin: 4px 0 0; color: #cbd5e1; }
.top a { color: #7dd3fc; }

.toc {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  scrollbar-width: none;
}
.toc a {
  flex: none;
  text-decoration: none;
  font-size: .85rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.toc a span { color: var(--muted); margin-right: 4px; }

main {
  display: grid;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 900px) {
  main { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); align-items: start; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card header { margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.card h3 { margin: 18px 0 8px; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.num {
  display: inline-grid;
  place-items: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: .8rem;
}
.compat { margin: 4px 0 0; font-size: .8rem; color: var(--muted); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }

button, .file {
  font: inherit;
  font-size: .95rem;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
button:active, .file:active { transform: scale(.97); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.danger { color: var(--ko); }
.file { display: inline-flex; align-items: center; }
.file input { display: none; }

input[type=text], input[type=number], input[type=url], textarea, select {
  font: inherit;
  font-size: 16px; /* évite le zoom auto sur iOS */
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input[type=number] { width: 6em; }
select { max-width: 100%; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.ko { background: var(--ko-bg); color: var(--ko); }

.note { padding: 10px 12px; border-radius: 10px; background: var(--info-bg); font-size: .9rem; margin: 8px 0; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.ko { background: var(--ko-bg); color: var(--ko); }

.log {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin: 12px 0 0;
  font-size: .78rem;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log:empty { display: none; }
.log .ok { color: var(--ok); }
.log .ko { color: var(--ko); }

progress { width: 100%; height: 12px; }

.preview { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 8px 0; background: #000; }
.preview.small { max-height: 120px; }
.preview[hidden] { display: none; }

.meter { height: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--ok); transition: width .05s linear; }

.ua { color: var(--muted); overflow-wrap: anywhere; }
.status { margin: 8px 0; }
.transcript { min-height: 2.5em; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; }
.transcript .interim { color: var(--muted); }
.files, .links { padding-left: 1.2em; font-size: .92rem; }
.links li { margin: 6px 0; }

.scroll-x { overflow-x: auto; }
.grid { border-collapse: collapse; width: 100%; font-size: .85rem; }
.grid th, .grid td { border-bottom: 1px solid var(--border); padding: 6px; text-align: left; vertical-align: top; }
.grid th { color: var(--muted); font-weight: 600; }

.bottom { padding: 16px 16px calc(16px + var(--safe-bottom)); color: var(--muted); font-size: .85rem; text-align: center; }

/* Sonde de lecture des safe areas (carte « Comportement standalone »). */
.safe-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* Visualisation des safe areas. */
body.show-safe-areas::before,
body.show-safe-areas::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  z-index: 100;
  pointer-events: none;
  background: rgba(239, 68, 68, .45);
}
body.show-safe-areas::before { top: 0; height: var(--safe-top); }
body.show-safe-areas::after { bottom: 0; height: var(--safe-bottom); }
body.show-safe-areas { box-shadow: inset var(--safe-left) 0 0 rgba(239, 68, 68, .45), inset calc(-1 * var(--safe-right)) 0 0 rgba(239, 68, 68, .45); }

/* Backoffice */
main.admin { grid-template-columns: 1fr; max-width: 1100px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; color: var(--muted); }
.field input, .field textarea { width: 100%; }
.actions { white-space: nowrap; }
.actions button { min-height: 36px; padding: 6px 10px; font-size: .85rem; }

.boot-error { margin: 16px; }
.boot-error p { margin: 0 0 10px; }
.boot-error[hidden] { display: none; }
.login { max-width: 420px; width: 100%; margin: 0 auto; }
.logout { justify-content: flex-end; }
