:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b2130;
  --border: #262d3d;
  --text: #e8ebf3;
  --muted: #8b93a7;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --plyr-color-main: var(--accent);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.icon { display: inline-flex; width: 1.15em; height: 1.15em; }
.icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Boutons & formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .9rem;
  border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #3a4560; background: #222a3b; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; }
.btn.danger:hover { background: rgba(239, 68, 68, .15); border-color: var(--danger); }
.btn.ok { background: rgba(34, 197, 94, .15); border-color: var(--ok); color: #86efac; }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; }

input, select {
  width: 100%; padding: .55rem .75rem; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, .btn:focus-visible, .check:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.field { display: grid; gap: .3rem; margin-bottom: .9rem; }
.field > span { font-size: .85rem; color: var(--muted); }
.field small { color: var(--muted); font-size: .78rem; }
.field.inline { display: flex; align-items: center; gap: .5rem; }
.field.inline > span { color: var(--text); font-size: .95rem; }
.error { color: #fca5a5; min-height: 1.2em; margin: 0 0 .5rem; font-size: .9rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; }
.login-card .brand { justify-content: center; margin-bottom: 1.5rem; font-size: 1.5rem; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1.25rem; background: rgba(11, 13, 18, .85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.15rem; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand .logo svg { width: 14px; height: 14px; fill: #fff; stroke: none; margin-left: 2px; }
.nav { display: flex; gap: .25rem; margin-left: 1rem; }
.nav a { padding: .4rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }
.userbox b { color: var(--text); font-weight: 600; }
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

/* ---------- Bibliothèque ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.toolbar .search { flex: 1 1 240px; max-width: 380px; }
.toolbar select { width: auto; }
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500; padding: .35rem .8rem; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: var(--panel-2); color: var(--text); }
.stats { display: flex; align-items: center; gap: .75rem; margin-left: auto; color: var(--muted); font-size: .9rem; }
.meter { width: 120px; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

.group-title { margin: 1.5rem 0 .75rem; font-size: 1.05rem; color: var(--muted); font-weight: 600; display: flex; gap: .5rem; align-items: baseline; }
.group-title small { font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.1rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: transform .15s, border-color .15s; }
.card:hover { transform: translateY(-2px); border-color: #3a4560; }
.thumb {
  position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; color: rgba(255, 255, 255, .85);
  background: linear-gradient(135deg, hsl(var(--h) 55% 32%), hsl(calc(var(--h) + 40) 60% 18%));
}
.thumb { overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .icon, .thumb .dur, .thumb .bar { z-index: 1; }
.thumb .icon { width: 2.6rem; height: 2.6rem; background: rgba(0, 0, 0, .35); border-radius: 50%; padding: .7rem; }
.thumb .icon svg { fill: currentColor; stroke: none; margin-left: 2px; }
.card:hover .thumb .icon { background: var(--accent); }
.thumb .dur { position: absolute; right: 8px; bottom: 10px; background: rgba(0, 0, 0, .7); padding: 1px 7px; border-radius: 6px; font-size: .78rem; }
.thumb .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .2); }
.thumb .bar i { display: block; height: 100%; background: var(--accent-2); }
.card.seen .thumb { filter: saturate(.4) brightness(.75); }
.meta { display: flex; align-items: center; gap: .6rem; padding: .7rem .8rem; }
.meta .title { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card.seen .title { color: var(--muted); }
.check {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 2px solid var(--border); background: transparent; color: transparent; transition: all .15s;
}
.check:hover { border-color: var(--ok); color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); color: #05210f; }
.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); }

/* ---------- Arborescence & navigation par dossier ---------- */
.library { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.lib-main { min-width: 0; }
.sidebar {
  position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding-bottom: .5rem;
}
.sidebar h3 { padding: .8rem 1rem .4rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 1rem; border-left: 1px solid var(--border); padding-left: .15rem; }
.tree > li > ul { margin-left: 0; border-left: 0; padding-left: 0; }
.tn { display: flex; align-items: center; margin: 1px .4rem; border-radius: 8px; }
.tn:hover { background: var(--panel-2); }
.tn.active { background: rgba(99, 102, 241, .2); }
.tn.active a { color: #fff; font-weight: 600; }
.tn a { flex: 1; min-width: 0; display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem .4rem .1rem; color: var(--text); }
.tn a .icon { flex: none; color: var(--accent-2); }
.tn a .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn a small { color: var(--muted); font-size: .75rem; }
.tn .check { width: 22px; height: 22px; margin: 0 .35rem 0 .1rem; border-width: 1.5px; padding: 0; }
.tn .check .icon { width: .8rem; height: .8rem; }
.tn .check:disabled { visibility: hidden; }
.check.part { border-color: var(--ok); color: var(--ok); background: rgba(34, 197, 94, .12); }
.tg, .tg-sp { flex: none; width: 24px; height: 24px; }
.tg { display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px; padding: 0; }
.tg:hover { color: var(--text); }
.tg .icon { width: .95em; height: .95em; transition: transform .12s; }
.tg.open .icon { transform: rotate(90deg); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-bottom: 1rem; color: var(--muted); font-size: .95rem; }
.crumbs a, .crumbs .cur, .crumbs > span { display: inline-flex; align-items: center; gap: .35rem; }
.crumbs a:hover { color: var(--text); }
.crumbs .cur { color: var(--text); font-weight: 600; }
.crumbs > .icon { width: .9em; height: .9em; opacity: .6; }
.tree-toggle { display: none; }

.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.folder-card { display: flex; align-items: center; gap: .9rem; padding: .9rem 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); transition: transform .15s, border-color .15s; }
.folder-card:hover { transform: translateY(-2px); border-color: #3a4560; }
.f-icon { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; background: rgba(99, 102, 241, .18); color: var(--accent-2); }
.f-icon .icon { width: 1.4rem; height: 1.4rem; }
.f-info { flex: 1; min-width: 0; display: grid; gap: .2rem; }
.f-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-info small { color: var(--muted); }
.f-info .meter { width: 100%; height: 4px; margin-top: .15rem; }

.meta-text { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.where { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .78rem; min-width: 0; }
.where:hover { color: var(--accent-2); }
.where .icon { flex: none; width: 1em; height: 1em; }
.where.big { font-size: .9rem; margin-bottom: .1rem; }

.checklist { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); padding: .3rem; }
.check-row { display: flex; align-items: center; gap: .5rem; padding: .3rem .5rem; border-radius: 6px; cursor: pointer; }
.check-row:hover { background: var(--panel-2); }
.checklist .muted { margin: .4rem .5rem; font-size: .85rem; }

/* ---------- Page lecture ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.5rem; align-items: start; }
.player-wrap { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; position: relative; }
.player-wrap .plyr { height: 100%; }
.player-wrap video { width: 100%; height: 100%; }
.player-err { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 2rem; background: rgba(0, 0, 0, .85); z-index: 5; }
.player-err > div { display: grid; gap: .7rem; justify-items: center; max-width: 560px; }
.player-err p { margin: 0; }
.player-err .error { min-height: 0; }
.watch-info { margin-top: 1rem; }
.watch-info h1 { font-size: 1.35rem; margin-bottom: .25rem; }
.watch-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.watch-actions label { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; cursor: pointer; }
.hint { margin-top: 1rem; color: var(--muted); font-size: .8rem; }
kbd { background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 .35rem; font-size: .78rem; }
.playlist { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); max-height: 70vh; overflow: auto; }
.playlist h3 { padding: .8rem 1rem; font-size: .95rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.pl-item { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.pl-item:last-child { border-bottom: 0; }
.pl-item:hover { background: var(--panel-2); }
.pl-item.current { background: rgba(99, 102, 241, .18); }
.pl-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item .icon { color: var(--ok); opacity: 0; flex: none; }
.pl-item.seen .icon { opacity: 1; }
.pl-item.seen .t { color: var(--muted); }

/* ---------- Admin ---------- */
.admin-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat b { display: block; font-size: 1.7rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 220px; }
td.actions { text-align: right; }
td.actions .btn + .btn { margin-left: .4rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.badge.ok { background: rgba(34, 197, 94, .15); color: #86efac; }
.badge.off { background: rgba(239, 68, 68, .15); color: #fca5a5; }
.badge.warn { background: rgba(245, 158, 11, .15); color: #fcd34d; }
.badge.admin { background: rgba(99, 102, 241, .2); color: var(--accent-2); }
.badge.user { background: var(--panel-2); color: var(--muted); }
.upload { background: var(--panel); border: 1px dashed #3a4560; border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.upload input[type="text"] { max-width: 340px; }
.upload .progress { flex: 1 1 100%; font-size: .85rem; color: var(--muted); }
.upload .meter { width: 100%; margin-top: .3rem; }
.upload.drag { border-color: var(--accent); background: rgba(99, 102, 241, .08); }

/* ---------- Dialog & toasts ---------- */
dialog.modal { width: min(440px, 92vw); background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .65); }
dialog.modal h2 { margin-bottom: 1rem; font-size: 1.15rem; }
.actions-row { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .5rem; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 100; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: .7rem 1rem; border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); max-width: 340px; animation: slide .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

.badge.folder { background: var(--panel-2); color: var(--accent-2); margin: 0 .3rem .2rem 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }

@media (max-width: 960px) {
  .library { grid-template-columns: 1fr; }
  .sidebar { display: none; position: static; max-height: 45vh; }
  .library.nav-open .sidebar { display: block; }
  .tree-toggle { display: inline-flex; margin-right: .4rem; }
  .watch { grid-template-columns: 1fr; }
  .playlist { max-height: 50vh; }
  .stats { margin-left: 0; width: 100%; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: .6rem .8rem; }
  .nav { margin-left: 0; }
  .userbox .name { display: none; }
  .container { padding: 1rem .8rem 2rem; }
}
