:root {
  --bg: #f5f6f8; --card: #fff; --text: #1b1d22; --muted: #6b7180; --line: #e2e5ea;
  --accent: #2563eb; --accent-text: #fff; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111318; --card: #1a1d24; --text: #e8eaef; --muted: #9aa1b0; --line: #2b2f39; --accent: #3b82f6; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button.small { padding: 5px 10px; font-size: 13px; }
button.active-cmd { outline: 2px solid var(--accent); }
input, select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px; }
.error { color: var(--bad); min-height: 1.2em; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.login .card { width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login label { display: grid; gap: 6px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px;
}
.brand { margin-right: auto; }
.tabs { display: flex; gap: 4px; order: 3; width: 100%; overflow-x: auto; }
@media (min-width: 720px) { .tabs { order: 0; width: auto; } .brand { margin-right: 12px; } #logout { margin-left: auto; } }
.tabs button { border: none; background: transparent; padding: 8px 12px; border-radius: 8px; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-top: 12px; }
.row.end { justify-content: flex-end; }
.row label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* Direct */
.screen { margin-bottom: 18px; }
.screen-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.screen-head h2 { margin: 0; font-size: 18px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid currentColor; }
.pill.ok { color: var(--ok); } .pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); }
.live-items { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.live-item { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.live-item.current { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok); }
.live-item .thumb { aspect-ratio: 16/9; }
.live-item .body { padding: 8px; display: grid; gap: 6px; }
.live-item .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Médias */
.thumb { position: relative; background: #000; aspect-ratio: 16/9; overflow: hidden; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px;
  padding: 2px 6px; border-radius: 6px;
}
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: 55vh; overflow: auto; }
.media { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.media .body { padding: 6px 8px; font-size: 12px; display: grid; gap: 4px; }
.media .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media .meta { color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.pick { position: relative; cursor: pointer; border: 2px solid transparent; border-radius: 8px; overflow: hidden; }
.pick.selected { border-color: var(--accent); }
.pick .order {
  position: absolute; right: 6px; top: 6px; background: var(--accent); color: #fff; border-radius: 99px;
  min-width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px;
}
.dropzone {
  display: grid; gap: 6px; place-items: center; text-align: center; padding: 26px 16px; margin-bottom: 14px;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); }
.dropzone input { display: none; }
.dropzone small { color: var(--muted); }
.upload { display: flex; gap: 10px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.upload progress { flex: 1; }

/* Programmes */
.items { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 160px 1fr; gap: 12px; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.item.disabled { opacity: .5; }
.item .thumb { border-radius: 6px; }
.item .fields { display: grid; gap: 8px; align-content: start; }
.item .fields .line { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.item .fields input[type=number] { width: 80px; }
.item .fields input[type=text] { flex: 1; min-width: 140px; }
.strip { display: flex; gap: 4px; overflow-x: auto; }
.strip img { height: 38px; border-radius: 4px; }
@media (max-width: 560px) { .item { grid-template-columns: 1fr; } }
.empty { color: var(--muted); text-align: center; padding: 30px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); width: min(820px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.picker h2 { margin-top: 0; font-size: 18px; }
code.token { user-select: all; word-break: break-all; background: var(--bg); padding: 2px 6px; border-radius: 6px; }
pre.cmd { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; }
