:root {
  --bg: #0d0f14; --panel: #151922; --panel2: #1c2130; --line: #262c3b; --text: #e6e9f0; --muted: #8a93a8;
  --accent: #ff7a1a; --accent2: #ffa54d; --live: #ff3b3b; --ok: #2ecc71; --warn: #f1c40f; --err: #ff5f5f;
  --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; padding: 0 8px 18px; }
.logo b { color: var(--accent); margin-left: 2px; }
.logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 10px var(--live); }
.nav { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; user-select: none; }
.nav:hover { background: var(--panel2); color: var(--text); }
.nav.active { background: rgba(255,122,26,.12); color: var(--accent2); }
.nav .ico { width: 18px; text-align: center; }
.side .spacer { flex: 1; }
.main { padding: 22px 28px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top h1 { font-size: 22px; margin: 0 auto 0 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* buttons & forms */
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #3a4256; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d00; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.go { background: rgba(46,204,113,.15); border-color: rgba(46,204,113,.4); color: var(--ok); }
.btn.stop { background: rgba(255,59,59,.15); border-color: rgba(255,59,59,.4); color: var(--live); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); flex: none; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }

/* stream cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; }
.card.is-live { border-color: rgba(255,59,59,.45); }
.thumb { aspect-ratio: 16/9; background: #0a0b10 center/cover no-repeat; position: relative; }
.thumb .badge { position: absolute; top: 10px; left: 10px; }
.thumb .up { position: absolute; bottom: 8px; right: 10px; background: rgba(0,0,0,.65); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .04em; background: rgba(0,0,0,.6); color: var(--muted); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.live { background: var(--live); color: #fff; }
.badge.live::before { background: #fff; animation: pulse 1.2s infinite; }
.badge.starting, .badge.reconnecting { color: var(--warn); }
.badge.error { color: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }
.card .body { padding: 12px 14px; flex: 1; }
.card h3 { margin: 0 0 4px; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metrics { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.metrics b { color: var(--text); font-weight: 600; }
.card .err-line { color: var(--err); font-size: 12px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .actions { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.card .actions .grow { flex: 1; }
.empty { text-align: center; padding: 60px 20px; border: 1px dashed var(--line); border-radius: var(--r); color: var(--muted); }

/* media */
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 22px; text-align: center; color: var(--muted); margin-bottom: 16px; cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--accent); background: rgba(255,122,26,.06); }
.uploads { margin-bottom: 14px; }
.up-item { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: 13px; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.mcard .thumb { aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; font-size: 34px; color: var(--muted); }
.mcard .body { padding: 10px 12px; }
.mcard .name { font-weight: 600; font-size: 13px; word-break: break-all; }
.mcard .actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel2); color: var(--muted); margin-right: 4px; }
.tag.gen { color: var(--accent2); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 760px; }
.modal.wide { max-width: 980px; }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .content { padding: 18px 20px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.section { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent2); margin: 18px 0 10px; }
.section:first-child { margin-top: 0; }
.picklist { border: 1px solid var(--line); border-radius: 8px; max-height: 210px; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.pick:last-child { border-bottom: 0; }
.pick:hover { background: var(--panel2); }
.pick img, .pick .ph { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; background: var(--bg); flex: none; display: flex; align-items: center; justify-content: center; }
.pick .n { flex: 1; word-break: break-all; }
.pick .ord { color: var(--accent2); font-weight: 700; min-width: 18px; }
.dest { display: grid; grid-template-columns: 150px 1fr 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.logs { background: #07080b; border-radius: 8px; padding: 12px; font: 12px/1.5 ui-monospace, Menlo, monospace; height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-all; color: #b8c0d4; }
pre.meta { background: var(--bg); padding: 12px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; max-height: 60vh; overflow: auto; }
.hint { background: rgba(255,122,26,.08); border: 1px solid rgba(255,122,26,.25); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #f3cfa9; margin: 10px 0; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; }
.job pre { font-size: 11px; color: var(--muted); margin: 8px 0 0; white-space: pre-wrap; max-height: 90px; overflow: auto; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 99; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast.bad { border-color: var(--err); color: var(--err); }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 30px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card .logo { padding: 0; }
.login-card p { margin: 0 0 6px; }
.err { color: var(--err); min-height: 18px; font-size: 13px; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .side .logo { width: 100%; padding-bottom: 8px; }
  .side .spacer { display: none; }
  .nav { padding: 8px 10px; }
  .main { padding: 16px; }
  .dest { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr; }
}
