:root {
  --bg: #f7f8fa; --surface: #fff; --ink: #151a23; --muted: #667085; --line: #e4e7ec;
  --accent: #2b59c3; --accent-ink: #fff; --danger: #b42318;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --surface: #171b23; --ink: #eceff4; --muted: #98a2b3; --line: #262c38;
    --accent: #7fa2f5; --accent-ink: #0f1218; --danger: #f97066;
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); line-height: 1.5;
  font: 16px/1.5 "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: inherit; }

/* Barre */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -0.02em; font-size: 1.15rem; text-decoration: none; }
#userbox { display: flex; align-items: center; gap: 10px; }
#userbox .who { color: var(--muted); font-size: .9rem; }

/* Boutons et champs */
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: progress; }
label { display: block; font-size: .9rem; font-weight: 550; margin-bottom: 14px; }
label .opt { color: var(--muted); font-weight: 400; }
input:not([type=file]), textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font-weight: 400;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.msg { min-height: 1.4em; margin: 0 0 8px; font-size: .9rem; color: var(--muted); }
.msg.err { color: var(--danger); }

main { max-width: 1200px; margin: 0 auto; padding: clamp(20px, 4vw, 40px); }

/* Connexion */
.login { max-width: 360px; margin: 10vh auto 0; }
.login h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 4px; }
.login p.sub { color: var(--muted); margin: 0 0 28px; }
.login button { width: 100%; padding: 11px; }

/* Bibliothèque */
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.head h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0; }
.head input { margin: 0; width: min(100%, 280px); border-radius: 999px; }
.grid { display: grid; gap: 28px 22px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { text-decoration: none; display: block; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: #0b0e14;
}
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb .dur {
  position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 6px;
  background: rgb(0 0 0 / .7); color: #fff; font-size: .78rem; font-variant-numeric: tabular-nums;
}
.card h2 { font-size: 1rem; font-weight: 600; margin: 10px 0 2px; line-height: 1.35; }
.card:hover h2 { color: var(--accent); }
.meta { color: var(--muted); font-size: .85rem; }
.empty { text-align: center; color: var(--muted); padding: 12vh 0; }
.empty p { margin: 0 0 18px; }

/* Lecteur */
.watch { max-width: 1040px; margin: 0 auto; }
.back { display: inline-block; margin-bottom: 16px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.back:hover { color: var(--ink); }
.watch video {
  display: block; width: 100%; max-height: 72vh; background: #000;
  border-radius: 16px; box-shadow: 0 20px 50px -20px rgb(0 0 0 / .45);
}
.watch h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin: 22px 0 4px; line-height: 1.3; }
.watch .desc { max-width: 70ch; margin: 18px 0; white-space: pre-wrap; }
.watch .actions { margin-top: 20px; }

/* Dialogue d'envoi */
dialog {
  width: min(480px, calc(100vw - 32px)); padding: 26px; border: 1px solid var(--line);
  border-radius: 16px; background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(10 12 18 / .55); }
dialog h2 { margin: 0 0 20px; font-size: 1.2rem; }
.drop {
  display: block; padding: 22px 16px; text-align: center; border: 1.5px dashed var(--line);
  border-radius: 10px; cursor: pointer; color: var(--muted);
}
.drop:hover, .drop:focus-within { border-color: var(--accent); color: var(--ink); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
progress { width: 100%; height: 6px; margin-bottom: 10px; accent-color: var(--accent); }
.actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (prefers-reduced-motion: no-preference) {
  button, .drop { transition: border-color .15s, background-color .15s; }
}

/* ---------- v2 : navigation, catégories, playlists, administration ---------- */
.bar { flex-wrap: wrap; }
#mainnav { display: flex; gap: 4px; margin-right: auto; margin-left: 12px; }
#mainnav a {
  padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: .95rem;
}
#mainnav a:hover { color: var(--ink); }
#mainnav a[aria-current=page] { color: var(--ink); background: var(--line); }

select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; font-weight: 400;
  color: var(--ink); border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
td select { margin: 0; width: auto; padding: 6px 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 24px; }
.chip { padding: 5px 14px; font-size: .9rem; color: var(--muted); background: transparent; }
.chip[aria-pressed=true] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.thumb .count {
  position: absolute; right: 0; top: 0; bottom: 0; width: 38%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: rgb(8 10 16 / .72); color: #fff; font-size: .85rem;
}
.thumb .count strong { font-size: 1.4rem; line-height: 1; }
.thumb.blank { background: var(--line); }

.watch .actions { justify-content: flex-start; }
.watch .desc + .actions, .watch .meta + .actions { margin-top: 20px; }
.section-title { font-size: 1.1rem; margin: 40px 0 14px; letter-spacing: -0.01em; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 40px 0 14px; }
.section-head .section-title { margin: 0; }

/* Playlist */
.pl-layout { display: grid; gap: 28px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.pl-layout .watch { max-width: none; margin: 0; }
.pl-side { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pl-side header { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.pl-side h2 { font-size: 1.05rem; margin: 0 0 2px; }
.pl-list { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow: auto; }
.pl-list a {
  display: grid; grid-template-columns: 1.6rem 1fr; gap: 6px; padding: 10px 12px; border-radius: 8px;
  text-decoration: none; font-size: .93rem; line-height: 1.35;
}
.pl-list a:hover { background: var(--bg); }
.pl-list a[aria-current=true] { background: var(--bg); font-weight: 600; color: var(--accent); }
.pl-list .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.pl-side footer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
@media (max-width: 860px) { .pl-layout { grid-template-columns: 1fr; } }

/* Éditeur de playlist */
.pl-edit { list-style: none; margin: 0 0 10px; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.pl-edit:empty { display: none; }
.pl-edit li { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 12px; }
.pl-edit li + li { border-top: 1px solid var(--line); }
.pl-edit .t { flex: 1; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.icon { padding: 2px 9px; border-radius: 6px; border-color: transparent; background: transparent; color: var(--muted); }
button.icon:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.pl-edit + select, .pl-edit ~ select { margin-bottom: 16px; }
.field-title { font-size: .9rem; font-weight: 550; margin: 0 0 6px; }

/* Administration */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-weight: 550; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 16px; vertical-align: middle; }
.table tr + tr td { border-top: 1px solid var(--line); }
.table td.num { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; white-space: nowrap; }
.row-actions button { padding: 5px 12px; font-size: .88rem; }
.cat-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.cat-list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.cat-list li + li { border-top: 1px solid var(--line); }
.cat-list .name { flex: 1; font-weight: 550; }
.cat-list button { padding: 5px 12px; font-size: .88rem; }
