:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #5d6470;
  --line: #e3e6eb;
  --accent: #e4572e;
  --accent-soft: #fdeee9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --accent: #ff7a50;
    --accent-soft: #2e1e19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
h1, h3 { line-height: 1.2; margin: 0; }

/* --- Barre du haut --------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
}
.bar-top { display: flex; align-items: center; gap: 12px; max-width: 1380px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: inherit; text-decoration: none; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 800;
}
.search { flex: 1; min-width: 0; }
.search input, .menu select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: 15px;
}
.menu { display: flex; gap: 6px; }
.menu select { width: auto; }
.pager { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#logout svg { width: 17px; height: 17px; }
.pager button, .menu button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  width: 38px; height: 38px; display: grid; place-items: center;
}
.pager button:hover:not(:disabled), .menu button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#pos { min-width: 56px; text-align: center; font-weight: 600; }
.tourne { animation: tourne 1s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

.filters { display: flex; flex-wrap: wrap; gap: 8px; max-width: 1380px; margin: 10px auto 0; }
.dd { position: relative; }
.dd-btn {
  white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 14px;
}
.dd-btn.actif { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dd-btn b { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 12px; }
.caret { opacity: .6; font-size: 11px; }
.dd-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 240px; max-width: min(340px, calc(100vw - 32px)); max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px;
}
.opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.opt:hover { background: var(--bg); }
.opt span { flex: 1; }
.opt em { font-style: normal; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.opt.vide { opacity: .45; }
.opt input { accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-width: 1380px; margin: 0 auto; }
.chips:not(:empty) { margin-top: 8px; }
.chip { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.chip.reset { background: transparent; color: var(--muted); text-decoration: underline; }

/* --- Référence ------------------------------------------------------------- */
main { min-width: 0; padding: 24px 0 64px; }
.state { text-align: center; color: var(--muted); padding: 64px 0; }
.notice {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 32px); margin: 0; padding: 8px 14px; border-radius: 10px;
  background: #fff4d6; color: #6b4e00; font-size: 14px; box-shadow: var(--shadow);
}

.ref { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-top: 4px solid var(--accent); }
.ref-head { display: flex; align-items: center; gap: 18px; padding: 28px 32px 0; }
.logo {
  width: 84px; height: 84px; object-fit: contain; flex: none;
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 8px;
  box-shadow: var(--shadow);
}
.ref-head h1 { font-size: clamp(24px, 4vw, 34px); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.resume { font-size: 19px; line-height: 1.5; padding: 16px 32px 0; margin: 0; max-width: 820px; }

.faits { display: flex; flex-wrap: wrap; gap: 24px; padding: 16px 32px 0; margin: 0; }
.faits dt { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.faits dd { margin: 0; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; padding: 20px 32px 0; }
.kpi { background: var(--accent-soft); border-radius: 12px; padding: 14px 16px; }
.kpi strong { display: block; font-size: 24px; color: var(--accent); }
.kpi span { font-size: 14px; color: var(--muted); }

.blocs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; padding: 24px 32px 0; }
.bloc { border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.bloc.accent { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: color-mix(in srgb, var(--accent-soft) 50%, var(--surface)); }
.bloc h3, .galerie h3, .meta h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 8px;
}
.bloc p { margin: 0 0 .7em; font-size: 15px; }
.bloc p:last-child { margin-bottom: 0; }

.temoignage { margin: 24px 32px 0; padding: 18px 24px; border-left: 4px solid var(--accent); background: var(--bg); border-radius: 0 12px 12px 0; font-style: italic; }
.temoignage cite { display: block; margin-top: 8px; font-style: normal; color: var(--muted); }

.galerie { padding: 28px 32px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.vignette {
  position: relative; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 10; background: var(--bg);
}
.vignette img, .vignette video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.vignette:hover img, .vignette:hover video { transform: scale(1.03); }
.play {
  position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .55); color: #fff; font-size: 18px;
}

.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; padding: 28px 32px 32px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 3px 9px; font-size: 13px; }
.tag:hover, .lien:hover { border-color: var(--accent); color: var(--accent); }
.equipe { list-style: none; margin: 0; padding: 0; }
.equipe li { padding: 3px 0; font-size: 14px; }
.equipe span { color: var(--muted); margin-left: 6px; }
.lien { border: 0; background: none; padding: 0; font-weight: 600; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }

/* --- Visionneuse plein écran ---------------------------------------------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 14, .92); display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lb-body { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 56px 72px; }
.lb-body img, .lb-body video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lb-close, .lb-nav { position: absolute; border: 0; background: rgba(255, 255, 255, .12); color: #fff; border-radius: 50%; width: 44px; height: 44px; }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-nav[hidden] { display: none; }

/* --- Connexion ------------------------------------------------------------- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; display: grid; gap: 10px; }
.login-card .brand { font-size: 20px; margin-bottom: 12px; }
.login-card label { font-size: 14px; color: var(--muted); }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--bg); color: var(--ink); }
.login-card button { padding: 10px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; }
.login-error { color: #c0392b; min-height: 1.4em; margin: 0; font-size: 14px; }

/* --- Petits écrans --------------------------------------------------------- */
@media (max-width: 760px) {
  .bar-top { flex-wrap: wrap; gap: 8px; justify-content: space-between; }
  .bar-top > .brand { display: none; }
  .search { flex-basis: 100%; }
  .pager button, .menu button { width: 34px; height: 34px; }
  .menu select { max-width: 130px; padding: 6px 8px; font-size: 14px; }
  .ref-head, .resume, .faits, .kpis, .blocs, .galerie, .meta { padding-left: 18px; padding-right: 18px; }
  .temoignage { margin-left: 18px; margin-right: 18px; }
  .blocs { grid-template-columns: 1fr; }
  .logo { width: 64px; height: 64px; }
  .lb-body { padding: 56px 8px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .dd { position: static; }
  .dd-panel { left: 16px; right: 16px; top: auto; max-width: none; }
}

/* --- Impression : une référence par feuille ------------------------------- */
@media print {
  .bar, .notice, .lightbox, .play { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .ref { box-shadow: none; }
  .bloc { break-inside: avoid; }
}

/* --- Synthèse « En bref » --------------------------------------------------- */
.pitch {
  margin: 20px 32px 0; padding: 20px 24px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 35%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
}
.pitch-head { display: flex; justify-content: space-between; align-items: baseline; }
.pitch h3, .pitch h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin: 0; }
.pitch h4 { margin-bottom: 6px; }
.discret { font-weight: 400; font-size: 13px; color: var(--muted); }
.accroche { font-size: 20px; line-height: 1.45; font-weight: 600; margin: 8px 0 14px; }
.ps { display: grid; gap: 6px; margin: 0 0 16px; }
.ps div { display: grid; grid-template-columns: 90px 1fr; gap: 12px; }
.ps dt { font-size: 13px; font-weight: 600; color: var(--muted); padding-top: 1px; }
.ps dd { margin: 0; }
.pitch-cols { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; }
.pitch ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pitch li { position: relative; padding-left: 26px; }
.resultats li::before {
  content: "✓"; position: absolute; left: 0; top: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.citer li::before { content: "→"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.pitch-attente { margin: 20px 32px 0; padding: 12px 16px; border-radius: 12px; border: 1px dashed var(--line); color: var(--muted); font-size: 14px; }

.complet { margin-top: 20px; border-top: 1px solid var(--line); }
.complet > summary {
  cursor: pointer; padding: 14px 32px; font-weight: 600; color: var(--muted); list-style: none;
}
.complet > summary::-webkit-details-marker { display: none; }
.complet > summary::before { content: "▸ "; color: var(--accent); }
.complet[open] > summary::before { content: "▾ "; }
.complet > summary:hover { color: var(--accent); }
.complet[open] { padding-bottom: 8px; }
.complet .resume { padding-top: 0; }

@media (max-width: 760px) {
  .pitch, .pitch-attente { margin-left: 18px; margin-right: 18px; padding: 16px; }
  .pitch-cols { grid-template-columns: 1fr; gap: 16px; }
  .accroche { font-size: 18px; }
  .ps div { grid-template-columns: 1fr; gap: 0; }
  .complet > summary { padding-left: 18px; padding-right: 18px; }
}
@media print { .complet:not([open]) > *:not(summary) { display: block; } #regen { display: none; } }

/* --- Colonne de gauche : références de la sélection ------------------------ */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 24px; max-width: 1380px; margin: 0 auto; padding: 0 16px; }
#side {
  position: sticky; top: var(--bar-h, 110px); align-self: start;
  max-height: calc(100vh - var(--bar-h, 110px)); overflow-y: auto; padding: 24px 4px 24px 0;
}
.side-total { margin: 0 0 12px 8px; font-size: 13px; color: var(--muted); }
.side-groupe { margin-bottom: 14px; }
.side-groupe h3 {
  display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--accent); margin: 0 8px 4px;
}
.side-groupe h3 span { color: var(--muted); font-weight: 400; }
.side-groupe ul { list-style: none; margin: 0; padding: 0; }
.side-ref {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; border-radius: 10px; padding: 6px 8px;
}
.side-ref:hover { background: var(--surface); }
.side-ref.actif { background: var(--surface); box-shadow: var(--shadow); }
.side-ref.actif b { color: var(--accent); }
.side-logo {
  flex: none; width: 32px; height: 32px; border-radius: 8px; background: #fff;
  border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden;
}
.side-logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.side-txt { min-width: 0; display: grid; line-height: 1.25; }
.side-txt b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-txt small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#toggle-side { display: none; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #toggle-side {
    display: grid; place-items: center; width: 38px; height: 38px; flex: none;
    border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  }
  #side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(300px, 85vw);
    max-height: none; padding: 20px 12px; background: var(--bg); box-shadow: var(--shadow);
    transform: translateX(-105%); transition: transform .2s;
  }
  body.side-ouverte #side { transform: none; }
  body.side-ouverte::after { content: ""; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .35); }
}
@media (max-width: 760px) {
  .layout { padding: 0 12px; }
  #toggle-side { width: 34px; height: 34px; }
}
@media print { #side { display: none; } .layout { display: block; padding: 0; } }
