/* Mise en page : barre fixe, colonne de lecture ~68 caractères, sommaire collant à gauche sur grand écran.
   Couleurs d'UE inspirées des étiquettes de seringues : une bande colorée par UE, le reste reste neutre. */
:root {
  --paper: #f3f5f8;
  --surface: #ffffff;
  --sunken: #e9edf2;
  --ink: #141b2b;
  --muted: #586174;
  --line: #d8dde6;
  --focus: #2f6fdf;

  --vert: #17806a;
  --corail: #cf4f27;
  --violet: #6a47b8;
  --bleu: #2563b0;
  --ocre: #a86a12;
  --rose: #b83a74;

  --ajout: #9a6400;
  --ajout-bg: #fff6e0;
  --gravite: #c0262d;
  --gravite-bg: #fdecec;
  --ide-bg: #e8f1fb;
  --ide: #2159a3;

  --accent: var(--bleu);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));

  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-text: "Atkinson Hyperlegible", "Helvetica Neue", Arial, system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --step--1: 0.84rem;
  --step-0: 1.02rem;
  --step-1: 1.2rem;
  --step-2: 1.5rem;
  --step-3: clamp(1.9rem, 1.4rem + 2.2vw, 2.8rem);

  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 27 43 / 0.06), 0 6px 20px rgb(20 27 43 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f131a;
    --surface: #171c25;
    --sunken: #1e2430;
    --ink: #e7eaf0;
    --muted: #9aa3b4;
    --line: #2a3140;
    --focus: #7aa7ff;
    --vert: #3cc3a2;
    --corail: #ff8a62;
    --violet: #a98bff;
    --bleu: #6ea3f0;
    --ocre: #e0a54a;
    --rose: #f07bb0;
    --ajout: #f2bd55;
    --ajout-bg: #2a2212;
    --gravite: #ff7a7f;
    --gravite-bg: #2c1618;
    --ide-bg: #142235;
    --ide: #8dbaf5;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f131a;
  --surface: #171c25;
  --sunken: #1e2430;
  --ink: #e7eaf0;
  --muted: #9aa3b4;
  --line: #2a3140;
  --focus: #7aa7ff;
  --vert: #3cc3a2;
  --corail: #ff8a62;
  --violet: #a98bff;
  --bleu: #6ea3f0;
  --ocre: #e0a54a;
  --rose: #f07bb0;
  --ajout: #f2bd55;
  --ajout-bg: #2a2212;
  --gravite: #ff7a7f;
  --gravite-bg: #2c1618;
  --ide-bg: #142235;
  --ide: #8dbaf5;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

[data-ue="vert"] { --accent: var(--vert); }
[data-ue="corail"] { --accent: var(--corail); }
[data-ue="violet"] { --accent: var(--violet); }
[data-ue="bleu"] { --accent: var(--bleu); }
[data-ue="ocre"] { --accent: var(--ocre); }
[data-ue="rose"] { --accent: var(--rose); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: var(--step-0)/1.6 var(--f-text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--surface);
}
img { max-width: 100%; display: block; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.15; text-wrap: balance; margin: 0; }
svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { font: 500 0.75rem var(--f-mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--muted); }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-in, .wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: none; }
.brand-mark {
  font: 800 0.8rem var(--f-display);
  letter-spacing: 0.08em;
  background: var(--ink);
  color: var(--surface);
  padding: 5px 8px 4px;
  border-radius: 6px;
}
.brand-name { font: 700 1rem var(--f-display); }
.crumbs { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: var(--step--1); color: var(--muted); overflow: hidden; white-space: nowrap; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs span:last-child { overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.crumbs .sep { opacity: 0.5; }
.tools { margin-left: auto; display: flex; gap: 6px; flex: none; }
.tool {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: var(--step--1); color: var(--ink);
  background: var(--sunken); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; cursor: pointer;
}
.tool:hover { border-color: var(--muted); }

.wrap { padding-block: 32px 80px; }

/* ---------- éléments communs ---------- */
.eyebrow, .side-title, .box-label, .td-label, .card-kind, .block-title {
  font: 700 0.74rem var(--f-text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.lede { color: var(--muted); font-size: var(--step-1); max-width: 62ch; margin: 0; }
.label-strip { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ue-chip {
  display: inline-flex; align-items: center;
  font: 500 0.78rem var(--f-mono);
  color: #fff; background: var(--accent);
  padding: 3px 8px; border-radius: 5px; letter-spacing: 0.02em;
  white-space: nowrap; flex: none;
}
:root[data-theme="dark"] .ue-chip { color: #10131a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ue-chip { color: #10131a; } }
.label-meta { font-size: var(--step--1); color: var(--muted); }

.progress { display: flex; align-items: center; gap: 10px; font-size: var(--step--1); color: var(--muted); }
.progress-bar { flex: 1; max-width: 220px; height: 6px; border-radius: 6px; background: var(--sunken); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

/* ---------- accueil ---------- */
.home-sem { display: grid; gap: 28px; }
.home-head { display: grid; gap: 10px; }
.home-head h1 { font-size: var(--step-3); font-weight: 800; letter-spacing: -0.01em; }
.ue-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.ue-card {
  position: relative; display: grid; gap: 10px; align-content: start; height: 100%;
  text-decoration: none; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 20px 20px; overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.ue-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 8px; background: var(--accent); }
.ue-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.ue-code { font: 500 0.9rem var(--f-mono); color: var(--accent); }
.ue-title { font: 700 var(--step-2)/1.15 var(--f-display); }
.ue-list { color: var(--muted); font-size: var(--step--1); }

/* ---------- page UE ---------- */
.ue-hero { display: grid; gap: 14px; padding-bottom: 28px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.ue-hero h1 { font-size: var(--step-3); font-weight: 800; }
.block { display: grid; gap: 14px; margin-bottom: 36px; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.card {
  display: grid; gap: 6px; height: 100%; align-content: start;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 16px 18px; text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-title { font: 700 var(--step-1) var(--f-display); }
.card-text { color: var(--muted); font-size: var(--step--1); }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: var(--step--1); color: var(--muted); }
.card-done { display: none; align-items: center; gap: 4px; color: var(--vert); font-weight: 700; }
.card.is-done .card-done { display: inline-flex; }
.td-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.td-list a { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; padding: 12px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); text-decoration: none; }
.td-list a:hover { border-color: var(--accent); }
.td-name { font-weight: 700; }
.td-where { color: var(--muted); font-size: var(--step--1); }
.empty { color: var(--muted); }

/* ---------- fiche ---------- */
.fiche-head { display: grid; gap: 14px; padding-bottom: 22px; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.fiche-head h1 { font-size: var(--step-3); font-weight: 800; letter-spacing: -0.01em; }
.fiche-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.views { display: inline-flex; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.views button {
  font: 700 var(--step--1) var(--f-text); color: var(--muted);
  background: none; border: 0; border-radius: 7px; padding: 8px 14px; cursor: pointer;
}
.views button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.done-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font: 700 var(--step--1) var(--f-text); color: var(--muted);
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; cursor: pointer;
}
.done-toggle[aria-pressed="true"] { color: var(--vert); border-color: var(--vert); background: color-mix(in srgb, var(--vert) 10%, transparent); }

.fiche-grid { display: grid; gap: 32px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 980px) {
  .fiche-grid { grid-template-columns: 240px minmax(0, 1fr); }
  .fiche-side { position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 100px); overflow: auto; }
}
.fiche-side { display: grid; gap: 22px; align-content: start; font-size: var(--step--1); }
.toc ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; counter-reset: toc; }
.toc a { display: block; padding: 5px 10px; border-left: 2px solid var(--line); text-decoration: none; color: var(--muted); }
.toc a:hover, .toc a.is-current { color: var(--ink); border-left-color: var(--accent); }
@media (max-width: 979px) {
  .toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
  .toc ol { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .fiche-side { order: 2; }
}
.side-block ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.links a, .sources a { display: flex; gap: 8px; align-items: center; text-decoration: none; padding: 6px 8px; border-radius: 6px; }
.links a:hover, .sources a:hover { background: var(--sunken); }
.sources a span { overflow-wrap: anywhere; }

/* corps de texte */
.fiche-body { min-width: 0; }
.view { display: grid; gap: 18px; max-width: 72ch; }
.view > * { margin: 0; }
.view h2 {
  font-size: var(--step-2); font-weight: 700;
  padding-top: 18px; margin-top: 12px; border-top: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 10px;
}
.view h2::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); flex: none; transform: translateY(-2px); }
.view > h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.view h3 { font-size: var(--step-1); font-weight: 700; }
.view ul, .view ol { padding-left: 1.3em; display: grid; gap: 4px; }
.view li::marker { color: var(--accent); }
.view strong { font-weight: 700; }
.view p, .view li { overflow-wrap: break-word; }
.val {
  font: 500 0.86em var(--f-mono);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  padding: 1px 5px; border-radius: 4px; white-space: nowrap;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: var(--step--1); font-variant-numeric: tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { background: var(--sunken); font-weight: 700; }
tr:last-child td { border-bottom: 0; }

.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.cols > * { margin: 0; min-width: 0; }

/* encadrés */
.box { display: grid; gap: 8px; align-content: start; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.box > * { margin: 0; }
.box ul { gap: 2px; }
.box-retenir { border: 2px solid var(--accent); background: var(--accent-soft); }
.box-retenir .box-label { color: var(--accent); }
.box-ajout {
  border: 2px dashed var(--ajout);
  background: repeating-linear-gradient(-45deg, var(--ajout-bg) 0 12px, color-mix(in srgb, var(--ajout-bg) 70%, var(--surface)) 12px 24px);
}
.box-ajout .box-label { color: var(--ajout); }
.box-ajout .box-label::before { content: "+ "; }
.box-src { font-size: var(--step--1); color: var(--muted); font-style: italic; }
.box-gravite { border-left: 6px solid var(--gravite); background: var(--gravite-bg); }
.box-gravite .box-label { color: var(--gravite); }
.box-ide { border-left: 6px solid var(--ide); background: var(--ide-bg); }
.box-ide .box-label { color: var(--ide); }
.box-ecart { border-left: 6px solid var(--muted); background: var(--sunken); }
.box-piege { border-left: 6px solid var(--ocre); background: color-mix(in srgb, var(--ocre) 8%, var(--surface)); }
.box-piege .box-label { color: var(--ocre); }

/* schémas */
.schema { margin: 0; display: grid; gap: 8px; }
.schema-zoom { display: block; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: zoom-in; width: 100%; }
.schema-zoom img { margin: 0 auto; max-height: 520px; width: auto; height: auto; object-fit: contain; }
.schema figcaption { font-size: var(--step--1); color: var(--muted); }
.schema figcaption::before { content: "Schéma · "; font-weight: 700; color: var(--accent); }

/* TD */
.td { display: grid; gap: 12px; padding: 18px; border: 1px dashed color-mix(in srgb, var(--accent) 60%, var(--line)); border-radius: var(--radius); background: var(--surface); }
.td > * { margin: 0; }
.td-label { color: var(--accent); }
.situation { display: grid; gap: 6px; align-content: start; padding: 12px 14px; background: var(--sunken); border-radius: 8px; font-size: var(--step--1); }
.situation > * { margin: 0; }
.question { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.question summary { cursor: pointer; padding: 10px 14px; font-weight: 700; list-style: none; display: flex; gap: 10px; }
.question summary::-webkit-details-marker { display: none; }
.question summary::before { content: "+"; font-family: var(--f-mono); color: var(--accent); flex: none; }
.question[open] summary::before { content: "−"; }
.question[open] summary { border-bottom: 1px solid var(--line); }
.answer { display: grid; gap: 10px; padding: 12px 14px 14px; }
.answer > * { margin: 0; }

/* ---------- recherche ---------- */
.search { position: fixed; inset: 0; z-index: 40; background: rgb(10 14 22 / 0.45); display: grid; justify-items: center; align-items: start; padding: calc(env(safe-area-inset-top, 0px) + 8vh) max(12px, env(safe-area-inset-right, 0px)) 12px max(12px, env(safe-area-inset-left, 0px)); }
.search-panel { width: min(680px, 100%); max-height: 78vh; display: grid; grid-template-rows: auto auto 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.search-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-head input { flex: 1; min-width: 0; font: inherit; font-size: var(--step-1); border: 0; outline: 0; background: none; color: var(--ink); }
.search-close { font: inherit; font-size: var(--step--1); background: var(--sunken); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; color: var(--ink); }
.search-filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.search-filters button { font: 700 0.78rem var(--f-text); border: 1px solid var(--line); background: none; color: var(--muted); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.search-filters button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.search-results { list-style: none; margin: 0; padding: 6px; overflow: auto; }
.search-results a { display: grid; gap: 3px; padding: 10px 12px; border-radius: 8px; text-decoration: none; }
.search-results a:hover, .search-results a.is-active { background: var(--sunken); }
.sr-top { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.sr-snip { font-size: var(--step--1); color: var(--muted); }
.sr-snip mark { background: color-mix(in srgb, var(--ocre) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.sr-empty { padding: 18px; color: var(--muted); }

/* ---------- visionneuse ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgb(8 10 16 / 0.92); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 92vh; background: #fff; border-radius: 6px; }
.lightbox-close { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 12px); right: calc(env(safe-area-inset-right, 0px) + 12px); font: inherit; background: #fff; color: #111; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }

/* ---------- connexion ---------- */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(400px, 100%); display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { font-size: var(--step-2); }
.login-card label { font-weight: 700; font-size: var(--step--1); }
.login-card input { font: 500 1.2rem var(--f-mono); letter-spacing: 0.1em; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); width: 100%; }
.login-card button { font: 700 var(--step-0) var(--f-text); padding: 11px; border: 0; border-radius: 8px; background: var(--ink); color: var(--surface); cursor: pointer; }
.login-error { color: var(--gravite); font-size: var(--step--1); margin: 0; }

@media (max-width: 640px) {
  .brand-name, .tool-label, .tool kbd { display: none; }
  .crumbs { font-size: 0.78rem; }
  .wrap { padding-block: 22px 60px; }
  .views button { padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
