:root {
  --bg: #0E1013;
  --surface: #171A1F;
  --surface-2: #1F242B;
  --border: #2A3039;
  --text: #E8EAED;
  --text-2: #9AA3AF;
  --text-3: #5F6873;
  --accent: #F5A524;
  --accent-soft: rgba(245, 165, 36, .14);
  --danger: #F0565E;
  --ok: #3DD68C;
  --live: #FF3B3B;
  --blue: #5B9CF5;
  --violet: #A97BF5;

  --row-h: 56px;
  --side-w: 360px;
  --r: 8px;
  --r-lg: 12px;
  --fs: 14px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs)/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
kbd {
  font: 500 11px/1 ui-monospace, Consolas, monospace;
  padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-2); background: var(--surface-2);
}
.muted { color: var(--text-2); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100vh; height: 100dvh;
}
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  transition: margin-left .25s var(--ease);
}
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 20px; gap: 14px; justify-content: center; }

.side-head {
  height: 56px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; letter-spacing: .04em; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.side-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 36px; height: 36px; flex: none; display: inline-grid; place-items: center;
  border: 0; border-radius: var(--r); background: transparent; color: var(--text-2); font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.browse { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ---------- Recherche & filtres ---------- */
.search { position: relative; margin: 12px 12px 8px; }
.search input {
  width: 100%; height: 40px; padding: 0 64px 0 34px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); outline: none;
}
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 16px; }
.search-kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
.search-clear {
  position: absolute; right: 36px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--text-2); padding: 4px 6px;
}

.filters { display: flex; gap: 8px; align-items: center; padding: 0 12px 8px; }
.chips { display: flex; gap: 6px; flex: none; }
.chip {
  height: 30px; padding: 0 10px; border-radius: 15px; white-space: nowrap;
  border: 1px solid var(--border); background: transparent; color: var(--text-2); font-size: 12px;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#groupSelect {
  flex: 1; min-width: 0; height: 30px; padding: 0 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); font-size: 12px;
}

.list-meta { padding: 0 16px 6px; color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.banner {
  margin: 0 12px 8px; padding: 8px 10px; border-radius: var(--r); font-size: 12px;
  background: rgba(240, 86, 94, .12); border-left: 3px solid var(--danger);
}
.banner button { background: none; border: 0; color: var(--accent); padding: 0 0 0 6px; font-size: 12px; }

/* ---------- Liste virtualisée ---------- */
.list { flex: 1; min-height: 0; overflow-y: auto; position: relative; outline: none; overscroll-behavior: contain; }
.list-spacer { position: relative; width: 100%; }
.row {
  position: absolute; left: 0; right: 0; height: var(--row-h);
  display: flex; align-items: center; gap: 10px; padding: 0 8px 0 12px;
  border-left: 3px solid transparent; cursor: pointer; user-select: none;
}
.row:hover { background: var(--surface-2); }
.row.active { background: var(--accent-soft); border-left-color: var(--accent); }
.list:focus-visible .row.focus, body.tv .row.focus {
  box-shadow: inset 0 0 0 2px var(--accent); background: var(--surface-2);
}
.row-num { width: 34px; flex: none; text-align: right; color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.row-text { flex: 1; min-width: 0; }
.row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row-name mark { background: none; color: var(--accent); }
.row-group { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); font-size: 12px; }
.row .live-dot { flex: none; }
.row:not(.active) .live-dot { display: none; }
.row.off .logo-box, .row.off .row-text { opacity: .45; }
.row.off .row-group::before { content: "Hors ligne · "; color: var(--danger); }
.row-star { border: 0; background: none; color: var(--text-3); font-size: 18px; width: 32px; height: 32px; border-radius: 6px; }
.row-star:hover { color: var(--text); background: var(--surface); }
.row-star.on { color: var(--accent); }

.logo-box {
  width: 40px; height: 40px; flex: none; border-radius: 6px; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center;
  color: var(--text-2); font-size: 12px; font-weight: 600;
}
.logo-box img { width: 100%; height: 100%; object-fit: contain; }

.skeleton { position: absolute; left: 12px; right: 12px; height: calc(var(--row-h) - 12px); border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.list-empty { padding: 32px 20px; text-align: center; color: var(--text-2); }
.list-empty .big { font-size: 28px; display: block; margin-bottom: 8px; color: var(--text-3); }
.list-empty button { background: none; border: 0; color: var(--accent); margin-top: 6px; }

/* ---------- Accueil ---------- */
.welcome { flex: 1; overflow-y: auto; padding: 28px 16px; display: flex; flex-direction: column; gap: 10px; }
.welcome h1 { margin: 0; font-size: 22px; font-weight: 600; }
.welcome p { margin: 0 0 10px; }
.card {
  display: flex; gap: 14px; align-items: center; text-align: left; padding: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r);
  transition: border-color .15s, background .15s;
}
.card:hover, .card:focus-visible { border-color: var(--accent); background: var(--surface-2); }
.card-ico { font-size: 26px; }
.card-body { display: flex; flex-direction: column; gap: 3px; }
.card-title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-sub { color: var(--text-2); font-size: 12px; }
.badge { font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .04em; }
.badge-green { background: rgba(61, 214, 140, .14); color: var(--ok); }
.badge-blue { background: rgba(91, 156, 245, .14); color: var(--blue); }
.badge-violet { background: rgba(169, 123, 245, .14); color: var(--violet); }

/* ---------- Player ---------- */
.player {
  position: relative; width: 100%; max-height: calc(100dvh - 120px); aspect-ratio: 16 / 9;
  margin: 0 auto; background: #000; border-radius: var(--r); overflow: hidden; outline: none;
}
.player video { width: 100%; height: 100%; display: block; background: #000; transition: opacity .15s; }
.player.switching video { opacity: 0; }
.player .embed { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.player.embedded video, .player.embedded .controls { display: none; }
.player:fullscreen { max-height: none; border-radius: 0; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 20px; text-align: center; background: rgba(0, 0, 0, .55);
}
#ovEmpty { background: #000; color: var(--text-2); }
.overlay h2 { margin: 0; font-size: 18px; font-weight: 600; }
.overlay p { margin: 0; }
.ov-logo { font-size: 44px; filter: grayscale(1); opacity: .4; }
.ov-warn { font-size: 36px; color: var(--danger); }
.ov-hint { max-width: 520px; color: var(--text); }
.ov-detail { color: var(--text-2); font: 12px ui-monospace, Consolas, monospace; max-width: 90%; word-break: break-word; }
.ov-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.spinner { width: 48px; height: 48px; border-radius: 50%; border: 3px solid rgba(245, 165, 36, .2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.osd {
  position: absolute; top: 16px; left: 16px; display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 8px 8px; border-radius: var(--r); background: rgba(14, 16, 19, .85);
  font-size: 16px; font-weight: 600; animation: osdIn .2s var(--ease);
}
.osd .logo-box { width: 32px; height: 32px; }
.osd-num { color: var(--accent); font-variant-numeric: tabular-nums; }
@keyframes osdIn { from { transform: translateY(-12px); opacity: 0; } }

.controls {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 4px;
  padding: 28px 12px 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .8));
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.player.show-controls .controls, .player:focus-within .controls { opacity: 1; pointer-events: auto; }
.ctl { width: 38px; height: 38px; border: 0; border-radius: var(--r); background: transparent; font-size: 16px; color: #fff; }
.ctl:hover { background: rgba(255, 255, 255, .12); }
.ctl-spacer { flex: 1; }
.volume { width: 90px; accent-color: var(--accent); }
.live-pill { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; font-size: 11px; font-weight: 600; letter-spacing: .06em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.info { display: flex; align-items: center; gap: 12px; width: 100%; max-width: calc((100dvh - 120px) * 16 / 9); margin: 0 auto; }
.info-text { flex: 1; min-width: 0; }
.info-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-meta { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-actions { display: flex; gap: 2px; }
.star.on { color: var(--accent); }
.star.pop { animation: pop .12s var(--ease); }
@keyframes pop { 50% { transform: scale(1.3); } }

/* ---------- Boutons ---------- */
.btn { height: 38px; padding: 0 16px; border-radius: var(--r); border: 1px solid transparent; font-weight: 500; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #1a1205; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--text-3); }
.btn-text { background: none; color: var(--text-2); }
.btn-text:hover { color: var(--text); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.loading::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }

/* ---------- Modales ---------- */
.modal {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.modal-sm { width: min(460px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal[open] { display: flex; flex-direction: column; animation: osdIn .18s var(--ease); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.modal-foot { display: flex; gap: 20px; justify-content: space-between; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-foot p { margin: 0 0 6px; }
.lan-url { display: inline-block; padding: 4px 8px; margin: 0 4px 4px 0; border-radius: 6px; background: var(--bg); color: var(--accent); font-size: 13px; user-select: all; }

.sources-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.span-all { grid-column: 1 / -1; }
.outproxy { border-top: 1px solid var(--border); padding-top: 16px; }
.outproxy p { margin: 0 0 10px; }
.outproxy code { font-size: 12px; color: var(--accent); }
.outproxy-row { display: flex; gap: 8px; flex-wrap: wrap; }
.outproxy-row input, .outproxy-row select {
  height: 38px; padding: 0 10px; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); outline: none;
}
.outproxy-row input { flex: 1 1 260px; min-width: 0; }
.outproxy-row input:focus, .outproxy-row select:focus { border-color: var(--accent); }
.proxy-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.proxy-row { display: grid; grid-template-columns: minmax(120px, 180px) 1fr auto auto; gap: 8px; align-items: center; }
.proxy-row input {
  height: 38px; padding: 0 10px; font-size: 14px; color: var(--text); min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); outline: none;
}
.proxy-row input:focus { border-color: var(--accent); }
.proxy-row .test-result { grid-column: 1 / -1; margin: 0; }
#formLogout { margin-top: 8px; }
#formLogout .btn { padding: 0; height: auto; }
@media (max-width: 767px) {
  .proxy-row { grid-template-columns: 1fr auto; }
  .proxy-row .proxy-url { grid-column: 1 / -1; grid-row: 2; }
  .proxy-row [data-proxy="test"] { grid-row: 3; }
}
.source-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.source-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg); }
.source-item.off { opacity: .55; }
.source-top { display: flex; align-items: center; gap: 8px; }
.source-name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-meta { color: var(--text-2); font-size: 12px; margin-top: 4px; }
.source-meta.err { color: var(--danger); }
.source-meta.ok { color: var(--ok); }
.source-actions { display: flex; align-items: center; gap: 2px; }
.source-actions .icon-btn { width: 30px; height: 30px; font-size: 14px; }
.confirm { display: flex; gap: 6px; align-items: center; font-size: 12px; margin-top: 8px; }
.confirm .btn { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }

.tabs { display: flex; gap: 4px; padding: 3px; margin-bottom: 14px; background: var(--bg); border-radius: var(--r); }
.tab { flex: 1; height: 32px; border: 0; border-radius: 6px; background: none; color: var(--text-2); font-weight: 500; }
.tab.active { background: var(--surface-2); color: var(--text); }
.tab-panel { display: flex; flex-direction: column; gap: 12px; }
.tab-panel label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); }
.tab-panel input:not([type=radio]):not([type=file]), .tab-panel select {
  height: 38px; padding: 0 10px; width: 100%; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); outline: none;
}
.tab-panel input:focus, .tab-panel select:focus { border-color: var(--accent); }
.tab-panel p { margin: 0; }
.seg { display: flex; gap: 16px; }
.seg label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.drop {
  border: 1px dashed var(--border); border-radius: var(--r); padding: 22px 12px; text-align: center; cursor: pointer;
  align-items: center;
}
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.pw { display: flex; gap: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.test-result:empty { display: none; }
.test-result.ok { color: var(--ok); }
.test-result.err { color: var(--danger); }

.settings { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; align-items: center; }
.keys dt { text-align: right; }
.keys dd { margin: 0; color: var(--text-2); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  padding: 10px 14px; border-radius: var(--r); background: var(--surface-2); border-left: 3px solid var(--accent);
  box-shadow: 0 0 0 1px var(--border); max-width: 340px; animation: osdIn .2s var(--ease);
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  :root { --side-w: 300px; }
  .stage { padding: 14px; }
}
@media (max-width: 767px) {
  :root { --fs: 16px; --row-h: 60px; }
  .app { display: flex; flex-direction: column; }
  .stage { order: -1; flex: none; padding: 0; gap: 0; }
  .player { border-radius: 0; max-height: none; }
  .info { padding: 8px 12px; max-width: none; border-bottom: 1px solid var(--border); background: var(--surface); }
  .info-name { font-size: 15px; }
  .info .logo-box { width: 32px; height: 32px; }
  #iPrev, #iNext { display: none; }
  .sidebar { flex: 1; border-right: 0; }
  .side-head { height: 48px; }
  .search-kbd { display: none; }
  .search input { padding-right: 36px; }
  .search-clear { right: 6px; }
  .volume, .live-pill { display: none; }
  .player .controls { opacity: 1; pointer-events: auto; padding-top: 18px; }
  .sources-grid { grid-template-columns: 1fr; }
  .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .toasts { left: 16px; align-items: center; }
}

/* ---------- Mode TV ---------- */
body.tv { --fs: 20px; --row-h: 72px; --side-w: 480px; }
body.tv .logo-box { width: 52px; height: 52px; }
body.tv .row-group { font-size: 15px; }
body.tv .row-num { font-size: 14px; width: 44px; }
body.tv .chip, body.tv #groupSelect { height: 40px; font-size: 16px; }
body.tv .search input { height: 52px; }
body.tv .row.focus { transform: scale(1.02); z-index: 1; }
body.tv :focus-visible { outline-width: 3px; }
body.tv .info-name { font-size: 22px; }
body.tv.side-hidden .app { grid-template-columns: 0 1fr; }
body.tv.side-hidden .sidebar { overflow: hidden; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
