/* =========================================================
   XTV Admin — design system
   Thèmes sombre/clair, RTL, responsive 360 → 2560px
   ========================================================= */

/* ---------- 1. jetons de design ---------- */
:root {
  /* échelles : espacement, rayon, typo */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  --fs-xs: 11.5px; --fs-sm: 13px; --fs-md: 14.5px;
  --fs-lg: 17px;   --fs-xl: 21px;  --fs-2xl: 26px; --fs-3xl: 34px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --sidebar-w: 258px;
  --header-h: 68px;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --t-fast: .14s var(--ease);
  --t: .24s var(--ease);
}

/* ---------- 2. thème sombre (défaut) ---------- */
:root, [data-theme="dark"] {
  --bg:            #0a0d15;
  --bg-soft:       #0e1220;
  --surface:       #141a29;
  --surface-2:     #1b2334;
  --surface-3:     #232d42;
  --line:          #232e45;
  --line-soft:     #1a2333;

  --text:          #eef2fa;
  --text-2:        #a3aec6;
  --text-3:        #6c7894;

  --brand:         #7c6cf5;
  --brand-2:       #22d3ee;
  --brand-soft:    rgba(124, 108, 245, .16);

  --ok:            #34d399;
  --ok-soft:       rgba(52, 211, 153, .14);
  --warn:          #fbbf24;
  --warn-soft:     rgba(251, 191, 36, .14);
  --err:           #f87171;
  --err-soft:      rgba(248, 113, 113, .14);
  --info:          #60a5fa;
  --info-soft:     rgba(96, 165, 250, .14);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow:    0 8px 24px -6px rgba(0,0,0,.5);
  --shadow-lg: 0 24px 60px -12px rgba(0,0,0,.7);
  --glow:      0 0 0 1px var(--line), 0 10px 34px -14px rgba(124,108,245,.5);

  color-scheme: dark;
}

/* ---------- 3. thème clair ---------- */
[data-theme="light"] {
  --bg:            #f5f7fc;
  --bg-soft:       #eef1f8;
  --surface:       #ffffff;
  --surface-2:     #f7f9fd;
  --surface-3:     #eceff8;
  --line:          #dde3ef;
  --line-soft:     #e8ecf5;

  --text:          #10151f;
  --text-2:        #5a6478;
  --text-3:        #8b94a8;

  --brand:         #5b4bdb;
  --brand-2:       #0891b2;
  --brand-soft:    rgba(91, 75, 219, .10);

  --ok:            #059669;
  --ok-soft:       rgba(5, 150, 105, .11);
  --warn:          #b45309;
  --warn-soft:     rgba(180, 83, 9, .11);
  --err:           #dc2626;
  --err-soft:      rgba(220, 38, 38, .09);
  --info:          #2563eb;
  --info-soft:     rgba(37, 99, 235, .09);

  --shadow-sm: 0 1px 2px rgba(16,21,31,.06);
  --shadow:    0 8px 26px -8px rgba(16,21,31,.14);
  --shadow-lg: 0 26px 60px -18px rgba(16,21,31,.22);
  --glow:      0 0 0 1px var(--line), 0 10px 30px -16px rgba(91,75,219,.35);

  color-scheme: light;
}

/* ---------- 4. base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t), color var(--t);
}

/* fond décoratif */
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(900px 460px at 88% -8%, var(--brand-soft), transparent 70%),
    radial-gradient(700px 420px at 4% 104%, rgba(34,211,238,.07), transparent 70%);
  pointer-events: none; z-index: 0;
}

[dir="rtl"] body { direction: rtl; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.ok-t { color: var(--ok); }
.err-t { color: var(--err); }
.nowrap { white-space: nowrap; }

::selection { background: var(--brand); color: #fff; }

/* barre de défilement discrète */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- 5. connexion ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4);
  position: relative; z-index: 1;
}
.login-card {
  width: 100%; max-width: 404px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
}
.login-card .brand { margin-bottom: var(--sp-5); }
.login-card .sub { color: var(--text-2); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.login-card input { margin-bottom: var(--sp-3); }
.login-card .btn { margin-top: var(--sp-2); }

/* ---------- 6. marque ---------- */
.brand { display: flex; align-items: center; gap: var(--sp-3); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px -6px var(--brand);
  font-size: 18px; color: #fff;
}
.brand-text { line-height: 1.15; }
.brand-name {
  font-size: var(--fs-lg); font-weight: 800; letter-spacing: .4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-tag { font-size: var(--fs-xs); color: var(--text-3); letter-spacing: .6px; }

/* ---------- 7. contrôles ---------- */
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 10px 13px;
  font-size: var(--fs-md);
  font-family: inherit;
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
select { cursor: pointer; appearance: none; padding-inline-end: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
[dir="rtl"] select { background-position: 12px 52%, 17px 52%; }

label { display: block; font-size: var(--fs-sm); color: var(--text-2); margin: var(--sp-3) 0 var(--sp-1); }
label:first-child { margin-top: 0; }

/* boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 9px 16px;
  font-size: var(--fs-md); font-family: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(135deg, var(--brand), #8f7dff);
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 6px 18px -8px var(--brand);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 8px 22px -8px var(--brand); }

.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 34%, transparent); background: var(--err-soft); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--err) 22%, transparent); }

.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 11px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.xs { padding: 3px 8px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn.block { width: 100%; }
.btn.icon { padding: 8px; width: 36px; height: 36px; border-radius: var(--r-sm); }

/* segments / onglets */
.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.seg button {
  border: none; background: transparent; color: var(--text-2);
  padding: 6px 13px; border-radius: var(--r-sm); cursor: pointer;
  font-size: var(--fs-sm); font-family: inherit; font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .2px;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge.active, .badge.unused, .badge.alive, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.expired, .badge.used, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.banned, .badge.revoked, .badge.dead { background: var(--err-soft); color: var(--err); }
.badge.unseen, .badge.info { background: var(--info-soft); color: var(--info); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- 8. structure ---------- */
.app { display: flex; min-height: 100vh; position: relative; z-index: 1; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width var(--t), transform var(--t);
}
.sidebar-head {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-4); border-bottom: 1px solid var(--line-soft);
}
.sidebar nav {
  flex: 1; overflow-y: auto; padding: var(--sp-3) var(--sp-2) var(--sp-4);
  display: flex; flex-direction: column; gap: 2px;
}
.nav-group { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .8px;
  color: var(--text-3); text-transform: uppercase; padding: var(--sp-4) var(--sp-3) var(--sp-1); }
.nav-group:first-child { padding-top: var(--sp-2); }

.sidebar a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px var(--sp-3); border-radius: var(--r-md);
  color: var(--text-2); font-size: var(--fs-md); font-weight: 500;
  cursor: pointer; user-select: none; text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.sidebar a .ic { font-size: 15px; width: 20px; text-align: center; flex: none; }
.sidebar a .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar a .count {
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-3);
  background: var(--surface-3); padding: 1px 7px; border-radius: var(--r-full);
}
.sidebar a:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.active { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.sidebar a.active .ic { color: var(--brand); }
.sidebar a.active::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 50%;
  transform: translateY(-50%); width: 3px; height: 20px;
  border-radius: 0 3px 3px 0; background: var(--brand);
}
[dir="rtl"] .sidebar a.active::before { border-radius: 3px 0 0 3px; }

.sidebar-foot { padding: var(--sp-3); border-top: 1px solid var(--line-soft); display: grid; gap: var(--sp-2); }

/* barre repliée : icônes seules */
.app.collapsed { --sidebar-w: 74px; }
.app.collapsed .sidebar .lbl,
.app.collapsed .sidebar .count,
.app.collapsed .nav-group,
.app.collapsed .brand-text,
.app.collapsed .sidebar-foot .btn span { display: none; }
.app.collapsed .sidebar a { justify-content: center; padding-inline: 0; }
.app.collapsed .sidebar-head { justify-content: center; padding-inline: 0; }

/* zone principale */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-size: var(--fs-lg); font-weight: 700; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }

.content { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }
.page { display: flex; flex-direction: column; gap: var(--sp-5); animation: fade .22s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-2xl); font-weight: 750; letter-spacing: -.4px; margin-inline-end: auto; }
.page-head .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

h2 { font-size: var(--fs-lg); font-weight: 700; }
h3 { font-size: var(--fs-md); font-weight: 650; color: var(--text-2); }

/* ---------- 9. cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.card-head h2 { margin-inline-end: auto; }
.card .hint { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--sp-4); line-height: 1.6; }

.grid { display: grid; gap: var(--sp-4); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* cartes de statistiques */
.stats { display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: 2px;
  position: relative; overflow: hidden;
  transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line); }
.stat::after {
  content: ""; position: absolute; inset-inline-start: 0; top: 0;
  width: 100%; height: 2px; opacity: .85;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}
.stat.t-ok::after   { background: linear-gradient(90deg, var(--ok), #6ee7b7); }
.stat.t-warn::after { background: linear-gradient(90deg, var(--warn), #fcd34d); }
.stat.t-err::after  { background: linear-gradient(90deg, var(--err), #fca5a5); }
.stat.t-info::after { background: linear-gradient(90deg, var(--info), #93c5fd); }
.stat .num { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: -1px; line-height: 1.1;
  font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.stat .sub { font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- 10. tableaux ---------- */
.tbl-wrap {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); overflow: auto; max-width: 100%;
}
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.tbl th {
  text-align: start; font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase; color: var(--text-3);
  background: var(--surface-2); padding: 10px var(--sp-4);
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .arrow { opacity: .35; margin-inline-start: 4px; font-size: 9px; }
.tbl th.sorted .arrow { opacity: 1; color: var(--brand); }
.tbl td { padding: 10px var(--sp-4); border-bottom: 1px solid var(--line-soft); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl td.actions { text-align: end; white-space: nowrap; }
.tbl td.actions .btn { margin-inline-start: 4px; }
.tbl .thumb {
  width: 34px; height: 46px; border-radius: var(--r-sm); object-fit: cover;
  background: var(--surface-3); flex: none;
}
.tbl .cell-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
.tbl .cell-main .txt { min-width: 0; }
.tbl .cell-main .txt b { display: block; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.tbl .cell-main .txt small { color: var(--text-3); font-size: var(--fs-xs); }

/* barre d'outils : recherche + filtres + pagination */
.toolbar {
  display: flex; align-items: center; gap: var(--sp-3);
  flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.toolbar .search { max-width: 320px; flex: 1 1 200px; }
.toolbar select { width: auto; min-width: 150px; }
.toolbar .spacer { flex: 1; }

.pager { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-4); }
.pager .info { font-size: var(--fs-sm); color: var(--text-2); margin-inline-end: auto; }
.pager .pages { display: flex; gap: 4px; }
.pager .pages button {
  min-width: 32px; height: 32px; padding: 0 9px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  font-size: var(--fs-sm); cursor: pointer; font-family: inherit;
}
.pager .pages button:hover:not(:disabled) { border-color: var(--brand); color: var(--text); }
.pager .pages button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .pages button:disabled { opacity: .4; cursor: not-allowed; }

/* état vide */
.empty { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--text-3); }
.empty .big { font-size: 34px; margin-bottom: var(--sp-3); opacity: .5; }
.empty p { font-size: var(--fs-sm); }

/* ---------- 11. graphiques ---------- */
.chart { width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 10px; }
.chart .bar { transition: opacity var(--t-fast); }
.chart .bar:hover { opacity: .78; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* anneau de progression */
.ring-wrap { display: flex; align-items: center; gap: var(--sp-4); }
.ring { flex: none; }
.ring .track { stroke: var(--surface-3); }
.ring .val { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset .5s var(--ease); }
.ring-text { display: grid; gap: 2px; }
.ring-text b { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.6px; }
.ring-text small { color: var(--text-2); font-size: var(--fs-sm); }

/* barre de progression linéaire */
.meter { height: 7px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .5s var(--ease); }
.meter.ok  > i { background: linear-gradient(90deg, var(--ok), #6ee7b7); }
.meter.err > i { background: linear-gradient(90deg, var(--err), #fca5a5); }
.meter.warn > i { background: linear-gradient(90deg, var(--warn), #fcd34d); }

/* ---------- 12. tiroir / modale ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(4, 7, 14, .62);
  backdrop-filter: blur(3px); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity var(--t);
}
.scrim.on { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed; inset: 0; z-index: 61;
  display: grid; place-items: center; padding: var(--sp-4);
  pointer-events: none;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(14px) scale(.985);
  transition: opacity var(--t), transform var(--t);
}
.modal.on .modal-card { opacity: 1; transform: none; pointer-events: auto; }
.modal.wide .modal-card { max-width: 860px; }
.modal-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { margin-inline-end: auto; }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: var(--sp-2); justify-content: flex-start;
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
  border-top: 1px solid var(--line-soft);
}

/* tiroir latéral */
.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 61;
  width: min(460px, 92vw); background: var(--surface);
  border-inline-start: 1px solid var(--line);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform var(--t);
}
[dir="rtl"] .drawer { transform: translateX(-100%); }
.drawer.on { transform: none; }
.drawer-head { display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line-soft); }
.drawer-head h2 { margin-inline-end: auto; font-size: var(--fs-lg); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); }

/* fiche de détail */
.detail-hero { display: flex; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.detail-hero img, .detail-hero .ph {
  width: 96px; height: 132px; border-radius: var(--r-md); object-fit: cover; flex: none;
  background: var(--surface-3); display: grid; place-items: center; font-size: 28px; color: var(--text-3);
}
.detail-hero .meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.detail-hero .meta h3 { font-size: var(--fs-lg); color: var(--text); font-weight: 700; }
.detail-hero .meta .desc { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.55;
  max-height: 5.4em; overflow: hidden; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); }
.kv dd { color: var(--text); word-break: break-all; text-align: end; }

/* liste EPG */
.epg-list { display: flex; flex-direction: column; gap: 1px; background: var(--line-soft);
  border-radius: var(--r-md); overflow: hidden; }
.epg-item { display: flex; gap: var(--sp-3); padding: 9px var(--sp-3); background: var(--surface); }
.epg-item.now { background: var(--brand-soft); }
.epg-item .t { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-3);
  flex: none; width: 46px; }
.epg-item .ttl { font-size: var(--fs-sm); font-weight: 550; }

/* ---------- 13. divers ---------- */
.row-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-4); }
.stack { display: grid; gap: var(--sp-4); }
.inline { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

pre, code { font-family: var(--mono); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: .9em; }

.danger-zone {
  border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line));
  background: linear-gradient(180deg, var(--err-soft), transparent 220%);
  border-radius: var(--r-lg); padding: var(--sp-5);
}
.danger-zone h2 { color: var(--err); font-size: var(--fs-md); margin-bottom: var(--sp-2); }
.purge-grid { display: grid; gap: var(--sp-2); margin-top: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.purge-card {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 11px var(--sp-3); border: 1px solid var(--line);
  border-radius: var(--r-md); background: var(--surface);
}
.purge-card strong { display: block; font-size: var(--fs-sm); font-weight: 600; }
.purge-card .muted { font-size: var(--fs-xs); }

/* indicateur temps réel */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs);
  color: var(--text-3); }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.live.on .dot { background: var(--ok); box-shadow: 0 0 0 0 var(--ok);
  animation: pulse 2.2s infinite; }
.live.on { color: var(--ok); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* notification */
.toast {
  position: fixed; inset-inline: 0; bottom: -90px; margin-inline: auto;
  width: max-content; max-width: min(92vw, 460px); z-index: 9999;
  display: flex; align-items: center; gap: 9px;
  padding: 11px 18px; border-radius: var(--r-md); font-size: var(--fs-sm); font-weight: 500;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--ok); box-shadow: var(--shadow-lg);
  transition: bottom .3s var(--ease), opacity .3s var(--ease); opacity: 0;
}
.toast.show { bottom: var(--sp-5); opacity: 1; }
.toast.err { border-color: var(--err); }

/* écran de chargement */
.loading { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-2);
  font-size: var(--fs-sm); padding: var(--sp-6); justify-content: center; }
.spin {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid var(--surface-3); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* squelette */
.skel { background: var(--surface-2); border-radius: var(--r-sm); height: 14px;
  animation: shimmer 1.5s infinite; }
@keyframes shimmer { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* ---------- 14. responsive ---------- */
@media (max-width: 1180px) {
  .content, .topbar { padding-inline: var(--sp-4); }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 240px; --header-h: 60px; }

  /* barre latérale en tiroir */
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 55;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .app.nav-open .sidebar { transform: none; }

  .app.collapsed { --sidebar-w: 240px; }
  .app.collapsed .sidebar .lbl,
  .app.collapsed .sidebar .count,
  .app.collapsed .nav-group,
  .app.collapsed .brand-text { display: initial; }
  .app.collapsed .nav-group { display: block; }
  .app.collapsed .sidebar a { justify-content: flex-start; padding-inline: var(--sp-3); }

  .stats { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
  .stat .num { font-size: var(--fs-2xl); }
  .page-head h1 { font-size: var(--fs-xl); }
  .tbl th, .tbl td { padding: 9px var(--sp-3); }
}

@media (max-width: 620px) {
  .content { padding: var(--sp-3); gap: var(--sp-4); }
  .topbar { padding-inline: var(--sp-3); }
  .card { padding: var(--sp-4); border-radius: var(--r-md); }
  .stats { grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
  .stat { padding: var(--sp-3); }
  .stat .num { font-size: var(--fs-lg); letter-spacing: -.3px; }
  .stat .lbl { font-size: var(--fs-xs); }
  .stat .sub { display: none; }
  .toolbar .search { max-width: none; flex: 1 1 100%; }
  .toolbar select { flex: 1 1 auto; }

  /* tableaux → cartes empilées */
  .tbl-wrap.stack-on-mobile { border: none; background: transparent; overflow: visible; }
  .stack-on-mobile .tbl, .stack-on-mobile .tbl tbody,
  .stack-on-mobile .tbl tr, .stack-on-mobile .tbl td { display: block; width: 100%; }
  .stack-on-mobile .tbl thead { display: none; }
  .stack-on-mobile .tbl tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-md); margin-bottom: var(--sp-2); padding: var(--sp-2) var(--sp-3);
  }
  .stack-on-mobile .tbl td {
    border: none; padding: 5px 0; display: flex; justify-content: space-between;
    align-items: center; gap: var(--sp-3); text-align: end;
  }
  .stack-on-mobile .tbl td::before {
    content: attr(data-label); color: var(--text-3); font-size: var(--fs-xs);
    font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
    text-align: start; flex: none;
  }
  .stack-on-mobile .tbl td.actions { justify-content: flex-end; padding-top: var(--sp-2); }
  .stack-on-mobile .tbl td.actions::before { display: none; }

  .modal-card { max-height: 92vh; border-radius: var(--r-lg); }
  .modal-head, .modal-body, .modal-foot { padding-inline: var(--sp-4); }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .pager .info { width: 100%; margin-bottom: var(--sp-2); }
  .detail-hero { flex-direction: column; }
}

@media (max-width: 340px) {
  .stats { grid-template-columns: 1fr; }
  .seg button { padding: 6px 9px; }
}

/* écrans tactiles : cibles plus grandes */
@media (hover: none) {
  .sidebar a { padding-block: 11px; }
  .btn.sm { padding: 7px 12px; }
}

/* impression */
@media print {
  .sidebar, .topbar, .toast, .pager, .toolbar { display: none !important; }
  .content { padding: 0; }
  .card, .tbl-wrap { box-shadow: none; border-color: #ccc; }
}

/* mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* build stamp: tells at a glance whether the browser shows a cached panel */
.build-tag { font-size: 10px; opacity: .5; font-weight: 400; letter-spacing: 0; }

/* ---------- source tester ---------- */
.preview-box {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
}
.preview-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  display: grid;
  place-items: center;
}
.preview-stage video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.preview-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: var(--fs-sm);
  color: var(--fg-mute);
  text-align: center;
  padding: 12px;
  pointer-events: none;
}
.preview-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.preview-bar .mono {
  font-size: var(--fs-xs);
  color: var(--fg-mute);
  margin-inline-end: auto;
}
