:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --stage: #e9ebe6;
  --ink: #1a1c19;
  --muted: #646960;
  --line: #d9dcd4;
  --accent: #2c3a2a;
  --accent-ink: #ffffff;
  --highlight: #b8c94a;
  --danger: #a23a2a;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.04);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 650; }
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.pad { padding: 24px clamp(16px, 4vw, 48px) 120px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tag { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 4px; background: var(--stage); color: var(--muted); vertical-align: middle; }
.form-error { color: var(--danger); }

/* ---------- boutons */
.btn {
  display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 1px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 0.875rem; font-weight: 550;
  text-decoration: none; cursor: pointer; transition: border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sub { font-size: 0.75rem; font-weight: 400; color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary .btn-sub { color: rgb(255 255 255 / .7); }
.btn-primary:hover:not(:disabled) { background: #1d281c; border-color: #1d281c; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { border-color: var(--line); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px clamp(16px, 4vw, 48px); background: rgb(243 244 241 / .9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .02em; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--muted); }
.topbar-user form { margin: 0; }

/* ---------- accueil */
.page-head { display: flex; align-items: baseline; gap: 16px; margin: 8px 0 24px; flex-wrap: wrap; }
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.model-card {
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius);
  text-decoration: none; box-shadow: var(--shadow); overflow: hidden; transition: transform .15s, box-shadow .15s;
}
.model-card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgb(0 0 0 / .06), 0 12px 28px rgb(0 0 0 / .08); }
.model-card .thumb { aspect-ratio: 16 / 9; background: var(--stage); }
.model-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.model-meta { padding: 14px 16px 16px; display: grid; gap: 4px; }
.model-meta h2 { font-size: 1.0625rem; font-weight: 650; }
.model-meta p { margin: 0; font-size: .875rem; }
.meter { height: 3px; border-radius: 2px; background: var(--stage); margin-top: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--highlight); }

/* ---------- page modèle */
.crumbs { font-size: .875rem; color: var(--muted); display: flex; gap: 6px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.controls { display: grid; gap: 14px; margin-bottom: 18px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--stage); border-radius: 9px; justify-self: start; }
.seg a { padding: 7px 14px; border-radius: 7px; text-decoration: none; font-size: .9375rem; font-weight: 550; color: var(--muted); }
.seg a[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.seg-small a { font-size: .8125rem; padding: 5px 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); text-decoration: none; font-size: .875rem;
}
.chip[aria-current="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgb(0 0 0 / .15); background-size: cover; background-position: center; }
.swatch-unknown { background: repeating-linear-gradient(45deg, #cfd2ca 0 3px, #eceee9 3px 6px); }

.packs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 14px 0 6px; border-top: 1px solid var(--line); }
.packs-label { flex-basis: 100%; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

.group-title { font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; }
.view-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.view-card { position: relative; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.view-card .thumb { display: grid; place-items: center; width: 100%; aspect-ratio: 16 / 9; padding: 0; border: 0; background: var(--stage); cursor: zoom-in; }
.view-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.view-card figcaption { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 12px; font-size: .8125rem; }
.view-card .dl { font-size: .75rem; color: var(--muted); text-decoration: none; white-space: nowrap; padding: 3px 7px; border-radius: 5px; border: 1px solid var(--line); }
.view-card .dl:hover { color: var(--ink); border-color: var(--ink); }
.view-card.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.no-preview { color: var(--muted); font-size: .8125rem; padding: 24px; text-align: center; }
.view-card.is-missing .thumb { cursor: default; border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: .8125rem; }
.view-card.is-missing figcaption { color: var(--muted); }
.pick { position: absolute; top: 8px; left: 8px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: rgb(255 255 255 / .9); box-shadow: 0 1px 2px rgb(0 0 0 / .15); cursor: pointer; }
.pick input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }

/* ---------- barre de sélection / progression */
.tray { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 12px clamp(16px, 4vw, 48px) calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgb(0 0 0 / .06); }
.tray-inner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .9375rem; }
.spacer { flex: 1; }
.progress-text { flex: 1 1 280px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { flex: 2 1 200px; height: 6px; background: var(--stage); border-radius: 3px; overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s; }

/* ---------- visionneuse */
.viewer { width: min(1400px, 96vw); max-height: 96vh; padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--ink); }
.viewer::backdrop { background: rgb(20 22 19 / .6); }
.viewer-inner { display: flex; flex-direction: column; max-height: 96vh; }
.viewer header, .viewer footer { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; }
.viewer header { justify-content: space-between; border-bottom: 1px solid var(--line); }
.viewer footer { border-top: 1px solid var(--line); }
.viewer-stage { position: relative; display: grid; place-items: center; background: var(--stage); min-height: 0; flex: 1; }
.viewer-stage img { max-height: calc(96vh - 150px); width: auto; object-fit: contain; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgb(255 255 255 / .9); font-size: 1.6rem; line-height: 1; cursor: pointer; box-shadow: var(--shadow); }
.viewer .prev { left: 12px; }
.viewer .next { right: 12px; }

/* ---------- connexion */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); padding: 32px 28px; border-radius: 14px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.375rem; margin-bottom: 22px; }
.eyebrow { margin: 0 0 4px; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: .875rem; font-weight: 550; }
.login-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login-card .btn { align-items: center; margin-top: 6px; }

/* ---------- administration */
.admin .seg { margin-bottom: 18px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.panel h2 { font-size: 1.0625rem; font-weight: 650; margin-bottom: 12px; }
.panel > p:first-child { margin-top: 0; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.admin label { display: grid; gap: 4px; font-size: .8125rem; font-weight: 550; }
.admin input[type=text], .admin input[type=email], .admin select {
  font: inherit; font-size: .875rem; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-width: 0;
}
.admin input.cc { width: 5.5em; text-transform: uppercase; }
.admin code { font-size: .8125rem; background: var(--stage); padding: 1px 5px; border-radius: 4px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }
.notice { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid var(--line); background: var(--surface); }
.notice p { margin: 0 0 8px; }
.notice p:last-child { margin-bottom: 0; }
.notice-ok { border-color: var(--highlight); box-shadow: inset 4px 0 0 var(--highlight); }
.notice-error { border-color: var(--danger); box-shadow: inset 4px 0 0 var(--danger); color: var(--danger); }
.credentials { margin: 8px 0; padding: 12px 14px; background: var(--stage); border-radius: 8px; font-size: .9375rem; line-height: 1.6; white-space: pre-wrap; user-select: all; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; white-space: nowrap; }
table.data tr.is-off td { color: var(--muted); }
td.actions { text-align: right; width: 1%; white-space: nowrap; }
td.actions details { display: inline-block; text-align: left; }
td.actions summary { list-style: none; }
td.actions summary::-webkit-details-marker { display: none; }
td.actions details[open] summary { border-color: var(--line); }
.menu { position: absolute; right: clamp(16px, 4vw, 48px); z-index: 5; margin-top: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgb(0 0 0 / .12); white-space: normal; max-width: min(640px, 92vw); }
.menu-section { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.menu-section input[name=password] { width: 16em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.menu-actions form { margin: 0; }
.radios { display: flex; gap: 18px; margin-bottom: 10px; }
.radios label, .checks label { display: flex; align-items: center; gap: 6px; font-weight: 450; font-size: .875rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; margin-bottom: 14px; padding: 12px; background: var(--bg); border-radius: 8px; }
.radios input, .checks input { accent-color: var(--accent); }
.warnings { margin: 0; padding-left: 18px; font-size: .875rem; display: grid; gap: 4px; }

@media (max-width: 600px) {
  .view-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .topbar-user span { display: none; }
}
