:root {
  --bg: #0b0f17; --panel: #131a26; --panel2: #1a2335; --border: #243047;
  --text: #e2e8f0; --muted: #8595ad; --accent: #6366f1; --accent2: #818cf8;
  --live: #22c55e; --danger: #ef4444; --warn: #f59e0b;
  --twitch: #9146ff; --youtube: #ff0033;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #0008; padding: .1em .4em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
textarea {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: .55rem .7rem; border-radius: 8px; font: inherit; font-size: .9rem; width: 100%; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .8rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar nav { display: flex; gap: 1.2rem; flex: 1; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.logout button { background: none; border: 1px solid var(--border); color: var(--muted); padding: .4rem .8rem; border-radius: 6px; cursor: pointer; }

.topstatus { display: flex; gap: .4rem; align-items: center; }
.hpill {
  display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap;
  padding: .2rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--border);
}
.hpill .hdot { width: .45rem; height: .45rem; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.hpill .hpill-meta { font-weight: 800; }
.hpill.status-ok { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .35); color: #86efac; }
.hpill.status-ok .hdot { background: var(--live); }
.hpill.status-err { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }
.hpill.status-err .hdot { background: var(--danger); }
.hpill.hpill-neutral .hdot { background: var(--accent2); }

.appfoot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem 0 .5rem; margin-top: 1rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
h1 { margin: 0 0 1.2rem; font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; grid-column: 1 / -1; }
section { margin-bottom: 2rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1.3rem; margin-bottom: 1.5rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 800px) { .cols { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }

.grid-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-form label, label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
.grid-form .actions, .actions { grid-column: 1 / -1; display: flex; gap: .8rem; align-items: center; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
small.muted { font-weight: 400; }

.switch { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .switch-track { position: relative; flex-shrink: 0; width: 42px; height: 23px; background: var(--border); border-radius: 999px; transition: background .15s ease; }
.switch .switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; background: #e2e8f0; border-radius: 50%; transition: transform .15s ease; }
.switch input:checked + .switch-track { background: var(--live); }
.switch input:checked + .switch-track::after { transform: translateX(19px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .switch-label { font-size: .85rem; font-weight: 600; color: var(--muted); min-width: 3.6em; }

input, select { background: var(--panel2); border: 1px solid var(--border); color: var(--text); padding: .55rem .7rem; border-radius: 8px; font-size: .95rem; }
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.inline-form { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }

button, .btn { background: var(--accent); color: #fff; border: 0; padding: .55rem 1rem; border-radius: 8px; cursor: pointer; font-size: .9rem; font-weight: 600; display: inline-flex; align-items: center; gap: .4rem; }
button:hover, .btn:hover { background: var(--accent2); text-decoration: none; }
button:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--panel2); color: var(--text); }
.btn-danger { background: var(--danger); }
.row-actions { display: flex; gap: .5rem; align-items: center; }
.row-actions form { margin: 0; }

.badge { display: inline-block; padding: .12em .55em; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--panel2); color: var(--muted); }
.badge-live { background: rgba(34,197,94,.15); color: var(--live); }
.badge-forced { background: rgba(245,158,11,.15); color: var(--warn); }
.badge-err { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-twitch { background: rgba(145,70,255,.18); color: #c4b5fd; }
.badge-youtube { background: rgba(255,0,51,.15); color: #fca5a5; }
.badge-dl { background: var(--panel2); color: var(--muted); }
.badge-dl-ready { background: rgba(34,197,94,.15); color: var(--live); }
.badge-dl-downloading { background: rgba(59,130,246,.15); color: #93c5fd; }
.badge-dl-failed { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-dl-pending { background: rgba(148,163,184,.15); color: #cbd5e1; }
.btn-xs { padding: .25rem .5rem; font-size: .8rem; }

.copy-btn {
  display: inline-flex; align-items: center; gap: .3rem; vertical-align: middle;
  background: transparent; border: 1px solid var(--border); color: var(--accent2);
  padding: .25rem .55rem; border-radius: 7px; font-size: .82rem; font-weight: 600;
  font-family: inherit; cursor: pointer; line-height: 1.2;
}
.copy-btn:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.copy-btn.copied { border-color: rgba(34, 197, 94, .5); color: #86efac; background: rgba(34, 197, 94, .1); }

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  white-space: nowrap; background: #0b0f17; color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: .3rem .55rem; font-size: .75rem; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .15s ease; z-index: 60;
}
[data-tip]:hover::after, [data-tip].copied::after { opacity: 1; }

.page-links { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: -.6rem 0 1.4rem; }
.page-links .links-sep { color: var(--muted); font-size: .82rem; margin-left: .4rem; }

/* ---- Transport (lecture) ---- */
.player-card .transport { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }
.btn-play { min-width: 7rem; justify-content: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { background: var(--panel2); color: var(--muted); border: 0; border-radius: 0; padding: .5rem .9rem; font-weight: 600; }
.seg-btn:hover { background: var(--border); }
.seg-btn.active { background: var(--accent); color: #fff; }
.btn-loop.on, .btn-stinger.on { border-color: rgba(34,197,94,.5); color: #86efac; }
.btn-loop.on .loop-state, .btn-stinger.on .stinger-state { color: var(--live); }

.nowplaying { background: var(--panel2); border-radius: 8px; padding: .9rem 1rem; }
.np-line { display: flex; align-items: center; gap: .7rem; }
.np-bar { flex: 1; height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.np-bar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .25s linear; }
.np-pos, .np-dur { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); min-width: 3em; }
.np-dur { text-align: right; }
.np-title { margin-top: .5rem; font-weight: 600; color: var(--text); }

/* ---- Clips ---- */
.clips-table td { padding: .55rem .7rem; }
.thumb-cell img { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; display: block; background: #000; }
.thumb-ph { display: inline-block; width: 96px; height: 54px; border-radius: 6px; background: var(--panel2); }
tr.clip-row.playing { background: rgba(99,102,241,.12); box-shadow: inset 3px 0 0 var(--accent); }
tr.clip-row.dragging { opacity: .45; background: var(--panel2); }
.num-cell { white-space: nowrap; }
.drag-handle { cursor: grab; color: var(--muted); padding-right: .2rem; user-select: none; }
.drag-handle:active { cursor: grabbing; }
tr.clip-row[draggable="true"] .num-cell { /* la poignée seule initie le glisser */ }
.clip-edit .edit-form { margin: .4rem 0; background: var(--panel2); padding: 1rem; border-radius: 8px; }
.row-disabled { opacity: .5; }

.status-bar { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.5rem; }
.status-pill { display: inline-flex; align-items: center; gap: .55rem; padding: .45rem .85rem; border-radius: 999px; font-size: .88rem; font-weight: 600; border: 1px solid transparent; }
.status-dot { width: .55rem; height: .55rem; border-radius: 50%; flex-shrink: 0; }
.status-meta { font-weight: 500; font-size: .82rem; opacity: .9; padding-left: .35rem; border-left: 1px solid rgba(255,255,255,.15); }
.status-ok { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .35); color: #86efac; }
.status-ok .status-dot { background: var(--live); box-shadow: 0 0 6px rgba(34, 197, 94, .6); }
.status-err { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }
.status-err .status-dot { background: var(--danger); box-shadow: 0 0 6px rgba(239, 68, 68, .5); }

.upload-progress { grid-column: 1 / -1; display: flex; align-items: center; gap: .8rem; margin-top: .4rem; }
.upload-bar { flex: 1; height: 10px; background: var(--panel2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.upload-bar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .15s ease; }

.warn-box { margin: .8rem 0; padding: .7rem .9rem; border-radius: 8px; font-size: .88rem; background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .4); color: #fbbf24; }
.ok-box { margin: .8rem 0; padding: .7rem .9rem; border-radius: 8px; font-size: .88rem; background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .4); color: #4ade80; }
.error { color: var(--danger); }

.logbar { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; padding: .8rem 1rem; margin-bottom: 1rem; }
.logbar input[type="search"] { flex: 1; min-width: 180px; }
.logbox { height: calc(100vh - 240px); min-height: 280px; overflow-y: auto; background: #05080f; border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.45; }
.logline { display: none; padding: .02rem 0; color: #cbd5e1; }
.logline.nomatch { display: none !important; }
.logbox.lv-debug .l-debug, .logbox.lv-debug .l-info, .logbox.lv-debug .l-warn, .logbox.lv-debug .l-error { display: block; }
.logbox.lv-info .l-info, .logbox.lv-info .l-warn, .logbox.lv-info .l-error { display: block; }
.logbox.lv-warn .l-warn, .logbox.lv-warn .l-error { display: block; }
.logbox.lv-error .l-error { display: block; }
.l-debug { color: #64748b; } .l-info { color: #cbd5e1; } .l-warn { color: #fbbf24; } .l-error { color: #fca5a5; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; width: 320px; display: flex; flex-direction: column; gap: 1rem; }
.login-card h1 { text-align: center; font-size: 1.3rem; margin: 0 0 .5rem; }
.login-card button { margin-top: .5rem; justify-content: center; }
