:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8a92a3;
  --accent: #3e8bff;
  --red: #e5484d;
  --green: #30a46c;
  --amber: #f5a524;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--red); }
button.icon { padding: 2px 7px; background: transparent; border-color: transparent; color: var(--muted); }
button.icon:hover { color: var(--text); border-color: var(--line); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

header {
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo { width: 18px; height: 18px; border-radius: 4px; background: var(--red); display: inline-block; }
nav { display: flex; gap: 4px; }
nav button { background: transparent; border-color: transparent; color: var(--muted); }
nav button.active { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.status { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.pill { padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.pill.onair { background: var(--red); color: #fff; }

main { padding: 16px 20px; }
.tab { display: none; }
.tab.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

/* Déroulé */
.split { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.list-pane { min-width: 0; }
.seq-table { width: 100%; border-collapse: collapse; }
.seq-table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 49px; background: var(--bg);
}
.seq-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.seq-table tr { cursor: pointer; }
.seq-table tbody tr:hover { background: var(--panel); }
.seq-table tr.selected { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.seq-table tr.onair { box-shadow: inset 3px 0 0 var(--red); }
.seq-table tr.onair td.num { color: var(--red); font-weight: 700; }
.seq-table tr.pvw td.num { color: var(--green); font-weight: 700; }
.seq-table tr.dragging { opacity: .4; }
.seq-table tr.drop-before td { border-top: 2px solid var(--accent); }
.seq-table td.num { font-variant-numeric: tabular-nums; font-weight: 600; width: 40px; }
.seq-table td.time, .seq-table td.dur { font-variant-numeric: tabular-nums; white-space: nowrap; }
.seq-table td.handle { cursor: grab; color: var(--muted); width: 18px; }
.seq-table td.actions { white-space: nowrap; text-align: right; }
.seq-table td.actions button { visibility: hidden; }
.seq-table tr:hover td.actions button { visibility: visible; }
.seq-table td.note { color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.layout.full { color: #fff; background: #5b3fd1; border-color: #5b3fd1; }
.layout.l2x2 { color: #7cc4ff; }
.layout.l3x3 { color: #ffc96b; }
.layout.l4x4 { color: #ff8f8f; }
.layout.vide { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 3px; }
.chip {
  font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.player { border-color: var(--amber); color: var(--amber); }
.warn { color: var(--amber); }

/* Éditeur */
.editor-pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; position: sticky; top: 66px; max-height: calc(100vh - 82px); overflow: auto;
}
.editor-pane .empty { text-align: center; padding: 40px 0; }
.editor-pane h2 { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.editor-pane h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.field input, .field select { color: var(--text); font-size: 14px; }
.dur-input { width: 80px; font-variant-numeric: tabular-nums; }
.dur-step { display: flex; gap: 2px; margin-top: 8px; }
.dur-step button { padding: 5px 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.dur-presets { display: flex; flex-wrap: wrap; gap: 3px; margin: -2px 0 12px; }
.dur-presets button { padding: 3px 8px; font-size: 12px; border-radius: 999px; }
.dur-presets button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.flux-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.flux-picker button {
  position: relative; text-align: left; font-size: 12px; padding: 6px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.flux-picker button .in { color: var(--muted); font-size: 10px; margin-right: 4px; }
.flux-picker button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.flux-picker button.on .in { color: #cfe0ff; }
.flux-picker button.player { border-style: dashed; }
.flux-picker button .slot {
  position: absolute; top: 2px; right: 4px; font-size: 10px; font-weight: 700;
}

/* Aperçu multiviewer = page Stream Deck */
.mv { display: grid; gap: 3px; background: #000; padding: 3px; border-radius: 6px; aspect-ratio: 16 / 9; }
.mv .cell {
  background: #20242d; border-radius: 3px; display: flex; flex-direction: column; justify-content: center; align-items: center;
  font-size: 11px; text-align: center; padding: 2px; overflow: hidden; cursor: grab; user-select: none;
}
.mv .cell .n { font-size: 9px; color: var(--muted); }
.mv .cell.player { background: #3a2c10; color: var(--amber); }
.mv .cell.empty { background: #14171d; cursor: default; }
.mv .cell.drop { outline: 2px solid var(--accent); }
.mv.full .cell { font-size: 16px; }
.warnings { margin-top: 10px; }
.warnings div { color: var(--amber); font-size: 12px; }
.saved { font-size: 12px; color: var(--green); }

/* Flux & clips */
.cards { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.cards .card.wide { grid-row: span 2; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 8px; font-size: 16px; }
.edit-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.edit-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px; }
.edit-table td { padding: 3px 4px; }
.edit-table input[type=number] { width: 64px; }
.edit-table input.w-full { width: 100%; }
.edit-table tr.dirty td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.edit-table tr.inactive input:not([type=checkbox]) { opacity: .5; }

#importText { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; margin-bottom: 10px; }
#importResult { margin-top: 10px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 16px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--red); color: #ffb3b5; }

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .editor-pane { position: static; max-height: none; }
  .cards { grid-template-columns: 1fr; }
}

/* Suggestions de sessions dans l'éditeur */
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 4px; vertical-align: middle; }
.live-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow: auto; }
.live-item { display: grid; grid-template-columns: 92px 84px 1fr; gap: 6px; font-size: 12px; padding: 3px 6px; border-radius: 4px; }
.live-item.shown { background: rgba(62, 139, 255, .12); }
.live-item .lf { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lt { font-variant-numeric: tabular-nums; color: var(--muted); }
.live-item .ln { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Grille horaire */
.grid { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-size: 12px; }
.grid .grow, .grid .gaxis { display: flex; align-items: stretch; }
.grid .grow { height: 22px; border-bottom: 1px solid var(--line); }
.grid .glab { width: 130px; flex: none; padding-right: 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; align-self: center; }
.grid .glane { position: relative; flex: 1; }
.grid .gaxis { height: 18px; color: var(--muted); font-size: 11px; }
.grid .gaxis span { position: absolute; transform: translateX(-50%); }
.grid .gseqrow { height: 26px; border-bottom: 2px solid var(--line); }
.gseq {
  position: absolute; top: 3px; bottom: 3px; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 10px; text-align: center; overflow: hidden; cursor: pointer; line-height: 18px; color: var(--muted);
}
.gseq:hover { border-color: var(--accent); color: var(--text); }
.gseq.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.gseq.onair { background: var(--red); color: #fff; border-color: var(--red); }
.gseq.warn { border-bottom: 2px solid var(--amber); }
.gs { position: absolute; top: 4px; bottom: 4px; background: #2d4a7a; border-radius: 2px; cursor: pointer; box-shadow: inset -1px 0 0 var(--panel); }
.gs:hover, .gs.sel { background: #5b8fe0; }
.gshow { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, rgba(48,164,108,.35) 0 4px, transparent 4px 8px); }
.gbody { position: relative; }
.goverlay { position: absolute; inset: 0; display: flex; pointer-events: none; }
.gcur { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); background: rgba(62,139,255,.08); }
.grid-detail { margin-top: 12px; min-height: 60px; }
.cov-flux { margin-bottom: 10px; }
.cov-flux .small { margin-left: 12px; }

/* Sources */
.source h2 { font-size: 15px; }
.source .row input { min-width: 0; }
.drop { display: block; border: 1px dashed var(--line); border-radius: 6px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; }
.drop:hover { border-color: var(--accent); color: var(--text); }
.drop input { display: block; margin: 8px auto 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
a.icon { color: var(--muted); text-decoration: none; padding: 4px 6px; }

/* Éditions & utilisateur */
#eventSel { margin-left: 8px; font-weight: 600; background: var(--panel-2); }
.pill.regie { background: rgba(229,72,77,.15); color: #ff9a9d; border: 1px solid rgba(229,72,77,.4); }
.pill.current { background: rgba(62,139,255,.15); color: #9cc2ff; }
.user-menu { position: relative; }
.drop-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: flex; flex-direction: column;
}
.drop-menu button, .drop-menu a { text-align: left; background: transparent; border: 0; padding: 8px 10px; color: var(--text); text-decoration: none; border-radius: 6px; font-size: 14px; }
.drop-menu button:hover, .drop-menu a:hover { background: var(--panel-2); }
.edited-by { margin-bottom: 4px; }
.nowrap { white-space: nowrap; }
.nowrap button { margin-left: 2px; }
h3.sub { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.secret { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--amber); border-radius: 8px; background: rgba(245,165,36,.08); }
.secret code { font-size: 15px; padding: 2px 6px; background: var(--bg); border-radius: 4px; user-select: all; }
dialog { background: transparent; border: 0; padding: 0; color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog .card { width: 360px; }

/* Connexion */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 320px; display: flex; flex-direction: column; gap: 4px; }
.login-card .brand { margin-bottom: 14px; }
.login-card button { margin-top: 8px; padding: 8px; }
.login-error { color: #ffb3b5; border: 1px solid var(--red); border-radius: 6px; padding: 8px; margin-bottom: 8px; font-size: 13px; }

/* Droits : lecture seule et admin */
body:not(.is-admin) .admin-only { display: none !important; }
.ro .edit-only, .ro .seq-table td.actions button, .ro #addSeq, .ro #addFlux, .ro #addClip, .ro #saveSettings,
.ro #edFill, .ro #edClear, .ro .dur-step, .ro .dur-presets, .ro .drop, .ro .src-sync, .ro #matrixReplaceAll,
.ro [data-act=del], .ro .seq-table td.handle { display: none !important; }
.ro main input, .ro main select, .ro main textarea, .ro #edPicker, .ro .mv .cell { pointer-events: none; }
.ro main input, .ro main select { opacity: .75; }

/* Présence */
.presence { display: flex; gap: 4px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%;
  background: hsl(var(--h, 210) 55% 35%); color: #fff; font-size: 11px; font-weight: 700; cursor: default;
  border: 2px solid var(--panel);
}
.avatar.self { box-shadow: 0 0 0 2px var(--accent); }
.avatar.companion { background: #3a2c10; color: var(--amber); border-color: var(--amber); }
.avatar.mini { width: 18px; height: 18px; font-size: 9px; margin-left: 4px; border-width: 1px; vertical-align: middle; }
.others-warn { color: var(--amber); font-size: 12px; margin: 4px 0 10px; }
@keyframes flash { from { background: rgba(245,165,36,.35); } to { background: transparent; } }
.seq-table tr.flash td { animation: flash 2.5s ease-out; }

/* Sources Google Sheets */
.src-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.src-grid .field.wide { grid-column: 1 / -1; }
.src-grid .field .row { gap: 4px; }
.src-result { margin-top: 8px; }
.src-result .ok { color: var(--green); margin-bottom: 4px; }
.src-result .live-item { grid-template-columns: 90px 1fr; }
.ro .src-preview, .ro .src-del { display: none !important; }
ol.steps { padding-left: 18px; line-height: 1.7; }
ol.steps a { color: #9cc2ff; }

/* Multiview direct */
.direct-wrap { max-width: 1100px; margin: 0 auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel-2); }
.seg button.on { background: var(--accent); color: #fff; }
.dir-grid { display: grid; gap: 6px; background: #000; padding: 6px; border-radius: 8px; aspect-ratio: 16 / 9; }
.dir-cell { background: #20242d; border-radius: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; min-width: 0; }
.dir-cell.filled { background: #233a5c; }
.dir-cell.player { background: #3a2c10; }
.dir-cell .n { font-size: 11px; color: var(--muted); }
.dir-cell select { width: 100%; max-width: 220px; }
.dir-actions { margin-top: 12px; }
button.take { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; padding: 8px 22px; }
.ok-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
a.btn-link { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--text); text-decoration: none; }
a.btn-link:hover { border-color: var(--muted); }

/* Planning des enregistrements */
.rec-table td.file { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-table tr.st-done td:not(.st) { opacity: .55; }
.rec-table tr.st-cancelled td:not(.st) { opacity: .4; text-decoration: line-through; }
.rec-table tr.st-recording { box-shadow: inset 3px 0 0 var(--red); }
.rec-table tr.next td.time { color: var(--green); font-weight: 700; }
.rec-table tr.now-line td { border-top: 2px solid var(--amber); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.badge.planned { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.recording { background: var(--red); color: #fff; animation: blink 1.2s step-start infinite; }
.badge.done { background: rgba(48,164,108,.18); color: #7ee2b0; }
.badge.cancelled { background: var(--panel-2); color: var(--muted); }
@keyframes blink { 50% { opacity: .55; } }
.fname { font-family: ui-monospace, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; word-break: break-all; }
.rec-times { display: flex; gap: 10px; }
.rec-times input { width: 110px; }
