:root {
  --bg: #0a0a0c;
  --panel: #131317;
  --panel2: #1a1a20;
  --line: #26262e;
  --text: #f2f2f4;
  --muted: #8b8b96;
  --red: #e50914;
  --red-soft: rgba(229, 9, 20, .14);
  --green: #22c55e;
  --amber: #f59e0b;
  --radius: 10px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Structure */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #070708; border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 26px; font-weight: 800; font-style: italic; letter-spacing: -1px; padding: 0 10px 22px; }
.brand sup { color: var(--red); font-size: 13px; font-style: normal; font-weight: 800; margin-left: 2px; }
.brand small { display: block; font-size: 10px; font-style: normal; font-weight: 600; letter-spacing: 2px; color: var(--muted); text-transform: uppercase; margin-top: 2px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; border: 0; background: none; text-align: left; font-weight: 500; }
.nav:hover { background: var(--panel); color: var(--text); }
.nav.active { background: var(--red-soft); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .spacer { flex: 1; }
.onair-pill { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--panel); font-size: 12px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--red); box-shadow: 0 0 0 0 rgba(229, 9, 20, .7); animation: pulse 1.6s infinite; }
.dot.ok { background: var(--green); }
.dot.warn { background: var(--amber); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(229, 9, 20, 0); } 100% { box-shadow: 0 0 0 0 rgba(229, 9, 20, 0); } }

main { padding: 28px 34px 60px; max-width: 1400px; width: 100%; }
.page { display: none; }
.page.active { display: block; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.3px; }
.sub { color: var(--muted); margin: 0 0 24px; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 650; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head .sub { margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Boutons & champs */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: #3a3a45; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #f6121e; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff6b72; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 6px; display: inline-flex; }
.icon-btn:hover { color: var(--text); background: var(--panel2); }
.icon-btn svg { width: 16px; height: 16px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 550; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=date], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span.track { width: 36px; height: 20px; border-radius: 20px; background: #33333d; position: relative; transition: .15s; flex: none; }
.switch span.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span.track { background: var(--red); }
.switch input:checked + span.track::after { left: 19px; }

/* ---------- Antenne */
.player { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player .badge { position: absolute; top: 12px; left: 12px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 4px 8px; border-radius: 4px; }
.player .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.now { margin-top: 16px; }
.now .label { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: var(--red); text-transform: uppercase; }
.now .title { font-size: 20px; font-weight: 700; margin: 4px 0 2px; }
.progress { height: 4px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin: 12px 0 6px; }
.progress > div { height: 100%; background: var(--red); width: 0; transition: width 1s linear; }
.outs { display: flex; flex-direction: column; gap: 10px; }
.out { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel2); border-radius: 8px; }
.out b { font-weight: 600; }
.out .st { margin-left: auto; font-size: 12px; color: var(--muted); }
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .time { font-variant-numeric: tabular-nums; color: var(--muted); width: 64px; flex: none; font-weight: 600; }
.li .grow { flex: 1; min-width: 0; }
.li .ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.tag.red { background: var(--red-soft); color: #ff6b72; }
.logs { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-height: 260px; overflow: auto; background: #070708; border-radius: 8px; padding: 10px 12px; line-height: 1.6; }
.logs .error { color: #ff6b72; }
.logs .warn { color: var(--amber); }
.logs .t { color: #55555f; margin-right: 8px; }

/* ---------- Médiathèque */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; margin-bottom: 18px; }
.drop.over, .drop:hover { border-color: var(--red); color: var(--text); background: var(--red-soft); }
.drop b { color: var(--text); }
.uploads { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.up { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.up .bar { height: 3px; background: var(--panel2); margin-top: 8px; border-radius: 3px; overflow: hidden; }
.up .bar div { height: 100%; background: var(--red); width: 0; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { aspect-ratio: 16/9; background: #000 center/cover no-repeat; position: relative; }
.thumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.8); font-size: 11px; padding: 2px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; font-weight: 600; }
.mcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.mcard .t { font-weight: 600; outline: none; border-radius: 4px; padding: 1px 3px; margin: -1px -3px; word-break: break-word; }
.mcard .t:focus { background: var(--bg); box-shadow: 0 0 0 1px var(--red); }
.mcard .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; align-items: center; }
.mcard select { padding: 5px 8px; font-size: 12px; }
.search { max-width: 280px; }

/* ---------- Playlists */
.pl-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.pl-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.pl-item:hover { background: var(--panel2); }
.pl-item.active { background: var(--red-soft); }
.pl-item .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.pl-item .n { flex: 1; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: var(--panel2); margin-bottom: 6px; }
.track.dragging { opacity: .4; }
.track.over { box-shadow: 0 -2px 0 var(--red); }
.track .grip { cursor: grab; color: var(--muted); display: flex; }
.track .mini { width: 64px; aspect-ratio: 16/9; background: #000 center/cover; border-radius: 4px; flex: none; }
.track .num { color: var(--muted); width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.picker { max-height: 340px; overflow: auto; margin-top: 10px; }
.empty-state { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---------- Grille */
.week { display: grid; grid-template-columns: 50px repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.week .colh { padding: 10px 6px; text-align: center; font-size: 12px; font-weight: 650; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); }
.week .colh.today { color: var(--red); }
.week .colh span { display: block; color: var(--muted); font-weight: 500; }
.week .hours, .week .day { position: relative; height: 960px; }
.week .day { border-left: 1px solid var(--line); background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% 40px; }
.week .hours div { position: absolute; right: 6px; font-size: 10px; color: var(--muted); transform: translateY(-6px); }
.week .blk { position: absolute; left: 3px; right: 3px; border-radius: 5px; padding: 3px 6px; font-size: 11px; overflow: hidden; background: var(--red); color: #fff; cursor: pointer; border-left: 3px solid rgba(255,255,255,.5); line-height: 1.25; }
.week .blk:hover { filter: brightness(1.15); z-index: 2; }
.week .blk b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week .nowline { position: absolute; left: 0; right: 0; height: 2px; background: #fff; z-index: 3; }
.week .nowline::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.week-scroll { max-height: 640px; overflow: auto; border-radius: var(--radius); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { cursor: pointer; }
.days input { display: none; }
.days span { display: inline-block; padding: 7px 11px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.days input:checked + span { background: var(--red); border-color: var(--red); color: #fff; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12px; }
.seg button.on { background: var(--panel2); color: var(--text); }

/* ---------- Modale & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: none; place-items: center; z-index: 50; padding: 20px; }
.modal-bg.open { display: grid; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 14px; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0; font-size: 18px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--green); padding: 12px 16px; border-radius: 8px; z-index: 60; transform: translateY(120px); transition: .25s; max-width: 380px; }
.toast.show { transform: none; }
.toast.err { border-left-color: var(--red); }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #070708; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; display: block; white-space: pre-wrap; word-break: break-all; color: #d4d4d8; }
.logo-prev { width: 160px; height: 90px; border-radius: 8px; background: #000 center/contain no-repeat; border: 1px solid var(--line); flex: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at top, #2a0306 0%, var(--bg) 55%); }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { text-align: center; font-size: 40px; padding: 0 0 10px; }
.err-msg { color: #ff6b72; font-size: 13px; min-height: 18px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .brand { padding: 4px 10px; width: 100%; }
  .side .spacer { display: none; }
  main { padding: 20px 16px 60px; }
  .grid2, .pl-layout { grid-template-columns: 1fr; }
}

/* ---------- Grille v2 : bibliothèque + glisser-déposer */
.grid-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.lib { position: sticky; top: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 32px); }
.lib-tabs { width: 100%; }
.lib-tabs button { flex: 1; }
.lib-list { overflow: auto; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 7px; border-radius: 8px; background: var(--panel2); cursor: grab; border: 1px solid transparent; }
.lib-item:hover { border-color: #3a3a45; }
.lib-item:active { cursor: grabbing; }
.lib-item .mini { width: 54px; aspect-ratio: 16/9; border-radius: 4px; background: #000 center/cover; flex: none; }
.lib-item .sw { width: 54px; height: 30px; border-radius: 4px; flex: none; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; }
.lib-item .n { font-size: 13px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lib-item .d { font-size: 11px; color: var(--muted); }
.lib-help { margin: 0; }
.week-title { font-weight: 650; margin: 0 0 10px; color: var(--muted); }
.week-scroll { max-height: calc(100vh - 210px); min-height: 420px; }
.week { position: relative; }
.week .colh { position: sticky; top: 0; z-index: 5; background: var(--panel); }
.week .day.drop-ok { background-color: rgba(229, 9, 20, .05); }
.week .day { cursor: copy; }
.week .blk { cursor: grab; display: flex; flex-direction: column; gap: 1px; }
.week .blk.dragging { opacity: .35; }
.week .blk .tm { opacity: .85; font-size: 10px; }
.week .blk .tag { position: absolute; right: 4px; bottom: 3px; font-size: 9px; background: rgba(0,0,0,.3); color: #fff; padding: 1px 5px; border-radius: 3px; }
.week .blk .x { position: absolute; top: 2px; right: 2px; border: 0; background: rgba(0,0,0,.35); color: #fff; width: 18px; height: 18px; border-radius: 4px; cursor: pointer; display: none; line-height: 1; font-size: 13px; padding: 0; }
.week .blk:hover .x { display: block; }
.week .ghost { position: absolute; left: 3px; right: 3px; border: 2px dashed #fff; border-radius: 5px; background: rgba(229, 9, 20, .35); pointer-events: none; z-index: 4; font-size: 11px; padding: 3px 6px; color: #fff; font-weight: 700; }
.week .hover-slot { position: absolute; left: 0; right: 0; height: 1px; background: rgba(255,255,255,.25); pointer-events: none; display: none; }
@media (max-width: 1000px) { .grid-layout { grid-template-columns: 1fr; } .lib { position: static; max-height: 300px; } }
