:root {
  --bg: #0e0f13;
  --bg-2: #16181e;
  --bg-3: #1f222a;
  --line: #2a2e38;
  --text: #eceef3;
  --muted: #9aa1b2;
  --accent: #7c5cff;
  --accent-2: #9b82ff;
  --ok: #3ecf8e;
  --warn: #f5b84a;
  --err: #ff6b6b;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
body { min-height: 100vh; }
body.has-audio main { padding-bottom: 110px; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.6em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.25rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 24px;
  background: rgba(14, 15, 19, 0.88); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  position: relative; flex: none;
}
.brand-logo::after {
  content: ""; position: absolute; left: 11px; top: 8px;
  border-left: 10px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--bg-3); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--bg-3); }
.search { flex: 1; max-width: 360px; margin-left: auto; }
.search input { width: 100%; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.icon-link { color: var(--muted); font-size: 0.9rem; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-3); color: var(--text); font-weight: 700; border: 1px solid var(--line);
}
.avatar:hover { text-decoration: none; border-color: var(--accent); }

main { padding: 28px 24px 60px; max-width: 1600px; margin: 0 auto; outline: none; }

/* ---------- Formulaires & boutons ---------- */
input, select, textarea {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font: inherit; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type="range"] { padding: 0; accent-color: var(--accent); background: transparent; border: 0; }
label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #3b4050; text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--err); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 0.88rem; }
.btn-lg { padding: 12px 22px; font-size: 1.05rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.error-text { color: var(--err); }
.grid-form { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-form .full { grid-column: 1 / -1; }

/* ---------- Pages d'accueil / connexion ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(420px, 100%); background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-card form { display: grid; gap: 14px; margin-top: 18px; }
.auth-card .brand { margin-bottom: 18px; font-size: 1.1rem; }

/* ---------- Rangées et grilles d'affiches ---------- */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: -6px 0 22px;
  padding: 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
}
.filters input[type="search"] { flex: 1 1 220px; }
.filters select { flex: 0 1 auto; }
.page-head h1 { margin: 0; }
.section { margin-bottom: 36px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.shelf {
  display: grid; grid-auto-flow: column; grid-auto-columns: 160px; gap: 16px;
  overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity;
}
.shelf.wide { grid-auto-columns: 300px; }
.shelf > * { scroll-snap-align: start; }
.cards { display: grid; gap: 20px 16px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card { color: var(--text); display: grid; gap: 8px; min-width: 0; }
.card:hover { text-decoration: none; }
.card:hover .poster { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--accent); }
.poster {
  aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; position: relative;
  background: var(--bg-3); border: 1px solid var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.poster.square { aspect-ratio: 1; }
.poster.landscape { aspect-ratio: 16 / 9; }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .ph {
  position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 12px;
  font-weight: 700; font-size: 1.02rem; line-height: 1.25; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.poster .badge {
  position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, 0.7);
  font-size: 0.75rem; padding: 2px 7px; border-radius: 999px;
}
.poster .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--muted); font-size: 0.85rem; margin-top: -6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty {
  border: 1px dashed var(--line); border-radius: 14px; padding: 40px 24px; text-align: center; color: var(--muted);
}
.empty h2 { color: var(--text); }
.stats { display: flex; gap: 28px; color: var(--muted); margin-bottom: 26px; flex-wrap: wrap; }
.stats strong { color: var(--text); font-size: 1.3rem; display: block; }

/* ---------- Page détail ---------- */
.hero {
  position: relative; border-radius: 16px; overflow: hidden; margin: -8px 0 28px;
  background: var(--bg-2) center / cover no-repeat; border: 1px solid var(--line);
}
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(14, 15, 19, 0.97) 30%, rgba(14, 15, 19, 0.6) 70%, rgba(14, 15, 19, 0.35));
}
.hero-inner { position: relative; display: grid; grid-template-columns: 220px 1fr; gap: 32px; padding: 32px; }
.hero-inner .poster { width: 220px; }
.hero h1 { font-size: 2.2rem; }
.hero .overview { max-width: 70ch; color: #cfd3dd; }
.meta-line { display: flex; gap: 14px; color: var(--muted); margin-bottom: 14px; flex-wrap: wrap; }

.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.list-item:hover { border-color: #3b4050; }
a.list-link { color: var(--text); }
a.list-link:hover { text-decoration: none; border-color: var(--accent); }
.list-item .num { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .progress { height: 3px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.list-item .progress > i { display: block; height: 100%; background: var(--accent); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill { display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); border-color: rgba(62, 207, 142, 0.4); }
.pill.err { color: var(--err); border-color: rgba(255, 107, 107, 0.4); }
.pill.run { color: var(--warn); border-color: rgba(245, 184, 74, 0.4); }

/* ---------- Sources ---------- */
.source-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 18px;
  display: grid; gap: 10px;
}
.source-card .label { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; color: var(--muted); word-break: break-all; }
.source-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.type-icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--bg-3); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.03em; color: var(--accent-2); flex: none;
}
.test-result { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 0.88rem; }
.test-result code { color: var(--muted); }

/* ---------- Fenêtre modale ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal {
  width: min(640px, 100%); max-height: calc(100vh - 40px); overflow: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: var(--shadow);
}
.modal h2 { margin-bottom: 18px; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 22px; }
.code-box { font-family: ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; word-break: break-all; }

/* ---------- Lecteur vidéo ---------- */
.player { position: fixed; inset: 0; background: #000; z-index: 40; }
.player video { width: 100%; height: 100%; background: #000; }
.player-ui {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  transition: opacity 0.25s ease; pointer-events: none;
}
.player.idle .player-ui { opacity: 0; }
.player.idle { cursor: none; }
.player-top, .player-bottom { pointer-events: auto; padding: 18px 24px; }
.player-top { background: linear-gradient(rgba(0, 0, 0, 0.75), transparent); display: flex; align-items: center; gap: 16px; }
.player-top h2 { margin: 0; font-size: 1.15rem; }
.player-bottom { background: linear-gradient(transparent, rgba(0, 0, 0, 0.85)); display: grid; gap: 10px; }
.player-bottom input[type="range"] { width: 100%; }
.player-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.player-controls select { padding: 5px 8px; font-size: 0.85rem; background: rgba(30, 30, 36, 0.9); }
.player-center { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2); border-top-color: #fff; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.player-msg { background: rgba(0, 0, 0, 0.75); padding: 16px 20px; border-radius: 12px; max-width: 520px; text-align: center; pointer-events: auto; }
.icon-btn {
  background: transparent; border: 0; color: #fff; font-size: 1.15rem; width: 38px; height: 38px;
  border-radius: 50%; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn-lg { font-size: 1.4rem; width: 46px; height: 46px; }
.time { font-variant-numeric: tabular-nums; font-size: 0.88rem; color: #d6d9e0; min-width: 48px; }

/* ---------- Barre audio ---------- */
.audio-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: grid; grid-template-columns: minmax(200px, 1fr) minmax(300px, 2fr) auto; align-items: center; gap: 18px;
  padding: 12px 20px; background: rgba(22, 24, 30, 0.97); border-top: 1px solid var(--line); backdrop-filter: blur(10px);
}
.ab-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ab-cover { width: 48px; height: 48px; border-radius: 8px; flex: none; }
.ab-text { display: grid; min-width: 0; }
.ab-text > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ab-text span { color: var(--muted); font-size: 0.85rem; }
.ab-controls { display: flex; align-items: center; gap: 8px; }
.ab-controls input { flex: 1; }

/* ---------- Notifications ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: grid; gap: 10px; }
body.has-audio .toasts { bottom: 100px; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; animation: pop 0.2s ease;
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.loading { display: grid; place-items: center; padding: 80px 0; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .nav { order: 3; width: 100%; }
  .search { max-width: none; }
  main { padding: 20px 14px 60px; }
  .hero-inner { grid-template-columns: 1fr; padding: 22px; }
  .hero-inner .poster { width: 160px; }
  .grid-form { grid-template-columns: 1fr; }
  .audio-bar { grid-template-columns: 1fr auto; }
  .ab-controls { grid-column: 1 / -1; order: 3; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
