*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg2: #1a1a1a;
  --bg3: #242424;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #f0f0f0;
  --text2: #888;
  --text3: #555;
  --red: #E24B4A;
  --red-bg: rgba(226,75,74,0.12);
  --blue: #378ADD;
  --blue-bg: rgba(55,138,221,0.12);
  --green: #52c41a;
  --green-bg: rgba(82,196,26,0.1);
  --amber: #faad14;
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
}

body { font-family: -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Login ── */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 340px; background: var(--bg2); border: 0.5px solid var(--border2); border-radius: var(--radius-lg); padding: 32px; }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-title { font-size: 18px; font-weight: 600; }
.login-sub { font-size: 12px; color: var(--text2); }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }

.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 0.5px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; position: fixed; top: 0; left: 0; bottom: 0; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 16px; border-bottom: 0.5px solid var(--border); }
.logo-name { font-size: 15px; font-weight: 600; }
.logo-sub { font-size: 11px; color: var(--text2); }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: var(--text2); text-decoration: none; border-radius: 0; transition: background 0.12s, color 0.12s; cursor: pointer; font-size: 13px; }
.nav-item svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--text); border-right: 2px solid var(--red); }

.sidebar-footer { padding: 12px 16px; border-top: 0.5px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.nginx-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-red { background: var(--red); }
.btn-logout { background: transparent; border: 0.5px solid var(--border2); color: var(--text2); border-radius: var(--radius); padding: 6px 10px; font-size: 12px; cursor: pointer; text-align: left; transition: color 0.12s, border-color 0.12s; }
.btn-logout:hover { color: var(--red); border-color: var(--red); }

.main { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; padding: 24px; }

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 20px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Stats ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 24px; }
.stat { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-val { font-size: 26px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-val.live { color: var(--red); }

/* ── Sections ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Stream Cards ── */
.stream-list { display: flex; flex-direction: column; gap: 8px; }
.stream-card { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; display: flex; align-items: center; gap: 14px; transition: border-color 0.12s; }
.stream-card:hover { border-color: var(--border2); }
.stream-card.is-live { border-left: 2.5px solid var(--red); }
.stream-card.is-error { border-left: 2.5px solid var(--amber); }

.stream-thumb { width: 52px; height: 36px; border-radius: 6px; background: var(--bg3); display: flex; align-items: center; justify-content: center; flex-shrink: 0; position: relative; }
.stream-thumb svg { width: 18px; height: 18px; fill: none; stroke: var(--text3); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); position: absolute; top: 4px; right: 4px; animation: blink 1.4s infinite; }
@keyframes blink { 0%,100%{opacity:1;} 50%{opacity:0.3;} }

.stream-info { flex: 1; min-width: 0; }
.stream-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stream-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

.badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-live { background: var(--red-bg); color: var(--red); }
.badge-loop { background: var(--blue-bg); color: var(--blue); }
.badge-obs  { background: var(--green-bg); color: var(--green); }
.badge-off  { background: var(--bg3); color: var(--text3); }
.badge-err  { background: rgba(250,173,20,0.12); color: var(--amber); }

.stream-uptime { font-size: 12px; color: var(--text2); font-variant-numeric: tabular-nums; }
.stream-key-display { font-size: 11px; color: var(--text3); font-family: monospace; }
.stream-video { font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

.stream-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn { width: 32px; height: 32px; border-radius: var(--radius); border: 0.5px solid var(--border); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.12s, border-color 0.12s; }
.icon-btn:hover { background: var(--bg3); border-color: var(--border2); }
.icon-btn svg { width: 14px; height: 14px; fill: none; stroke: var(--text2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.start:hover { border-color: var(--green); }
.icon-btn.start:hover svg { stroke: var(--green); }
.icon-btn.stop:hover { border-color: var(--red); }
.icon-btn.stop:hover svg { stroke: var(--red); }
.icon-btn.del:hover { border-color: var(--red); }
.icon-btn.del:hover svg { stroke: var(--red); }

/* ── Filters ── */
.filter-tabs { display: flex; gap: 4px; }
.ftab { background: transparent; border: 0.5px solid var(--border); color: var(--text2); border-radius: var(--radius); padding: 5px 12px; font-size: 12px; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.ftab:hover { border-color: var(--border2); color: var(--text); }
.ftab.active { border-color: var(--red); color: var(--red); }

/* ── Empty ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); border: 0.5px dashed var(--border2); border-radius: var(--radius-lg); }
.empty-state svg { width: 36px; height: 36px; fill: none; stroke: var(--text3); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 12px; }
.empty-state p { font-size: 13px; color: var(--text2); line-height: 1.8; }

/* ── Logs ── */
.log-table { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.log-row { display: flex; align-items: flex-start; gap: 12px; padding: 8px 14px; border-bottom: 0.5px solid var(--border); font-size: 12px; font-family: monospace; }
.log-row:last-child { border-bottom: none; }
.log-time { color: var(--text3); flex-shrink: 0; width: 80px; }
.log-stream { color: var(--blue); flex-shrink: 0; width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-level { flex-shrink: 0; width: 45px; font-weight: 600; }
.log-level.info  { color: var(--text2); }
.log-level.error { color: var(--red); }
.log-level.ok    { color: var(--green); }
.log-msg { color: var(--text); flex: 1; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.16s; padding: 20px; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--bg2); border: 0.5px solid var(--border2); border-radius: var(--radius-lg); padding: 0; width: 100%; max-width: 460px; transform: translateY(16px); transition: transform 0.16s; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 0.5px solid var(--border); font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal .field { padding: 0 20px; margin-bottom: 14px; }
.modal .field:first-of-type { margin-top: 16px; }
.modal .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 20px; margin-bottom: 14px; }
.modal .field-row .field { padding: 0; margin: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 0.5px solid var(--border); }

/* ── Forms ── */
.field label { display: block; font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
input[type=text], input[type=password], select, textarea {
  width: 100%; background: var(--bg3); border: 0.5px solid var(--border2); border-radius: var(--radius);
  color: var(--text); padding: 8px 10px; font-size: 13px; font-family: inherit;
  transition: border-color 0.12s; outline: none;
}
input:focus, select:focus { border-color: var(--red); }
select option { background: var(--bg2); }
small.muted { font-size: 11px; color: var(--text3); margin-top: 4px; display: block; }

/* ── Buttons ── */
.btn { background: transparent; border: 0.5px solid var(--border2); color: var(--text); border-radius: var(--radius); padding: 7px 14px; font-size: 13px; cursor: pointer; font-family: inherit; transition: background 0.12s, border-color 0.12s; }
.btn:hover { background: var(--bg3); border-color: var(--border2); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: #c93c3b; border-color: #c93c3b; }
.btn.w100 { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Logo icon ── */
.logo-icon { width: 30px; height: 30px; background: var(--red); border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.logo-icon svg { width: 14px; height: 14px; fill: white; }

/* ── Settings ── */
.settings-card { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px; max-width: 460px; }
.settings-card h2 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.settings-card .field { margin-bottom: 12px; }
.code-block { background: var(--bg3); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 10px 14px; font-family: monospace; font-size: 13px; color: var(--text2); }

/* ── Misc ── */
.muted { color: var(--text2); font-size: 12px; }
.error-msg { color: var(--red); font-size: 12px; padding: 6px 10px; background: var(--red-bg); border-radius: var(--radius); margin-bottom: 10px; }

/* ── Upload zone ── */
.stream-select { background: var(--bg3); border: 0.5px solid var(--border2); border-radius: var(--radius); color: var(--text); padding: 7px 12px; font-size: 13px; font-family: inherit; min-width: 220px; }
.upload-zone { margin-bottom: 0; }
.upload-drop { border: 1.5px dashed var(--border2); border-radius: var(--radius-lg); padding: 32px 20px; text-align: center; transition: border-color 0.15s, background 0.15s; }
.upload-drop.drag-over { border-color: var(--red); background: rgba(226,75,74,0.04); }
.upload-drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.upload-drop-inner svg { width: 36px; height: 36px; fill: none; stroke: var(--text3); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.upload-drop-inner p { font-size: 14px; color: var(--text2); }
.upload-drop-inner span { font-size: 12px; color: var(--text3); }
.upload-drop-inner small { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ── Upload queue ── */
.queue-item { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 6px; display: flex; align-items: center; gap: 12px; }
.queue-item-name { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item-size { font-size: 12px; color: var(--text2); flex-shrink: 0; }
.queue-item-status { font-size: 12px; flex-shrink: 0; min-width: 70px; text-align: right; }
.queue-item-status.pending  { color: var(--text3); }
.queue-item-status.uploading { color: var(--blue); }
.queue-item-status.done { color: var(--green); }
.queue-item-status.error { color: var(--red); }
.progress-bar-wrap { width: 100%; height: 3px; background: var(--bg3); border-radius: 2px; margin-top: 6px; }
.progress-bar { height: 100%; background: var(--blue); border-radius: 2px; width: 0%; transition: width 0.2s; }
.progress-bar.done { background: var(--green); }

/* ── File list ── */
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-row { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 10px 14px; display: flex; align-items: center; gap: 12px; transition: border-color 0.12s; }
.file-row:hover { border-color: var(--border2); }
.file-icon { width: 32px; height: 32px; background: var(--bg3); border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.file-icon svg { width: 15px; height: 15px; fill: none; stroke: var(--text2); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.file-name { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: monospace; }
.file-size { font-size: 12px; color: var(--text2); flex-shrink: 0; min-width: 65px; text-align: right; }
.file-date { font-size: 11px; color: var(--text3); flex-shrink: 0; min-width: 90px; text-align: right; }
.btn-danger-outline { border-color: var(--red); color: var(--red); }
.btn-danger-outline:hover { background: var(--red-bg); }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg2); border: 0.5px solid var(--border2); border-radius: var(--radius); padding: 10px 16px; font-size: 13px; color: var(--text); opacity: 0; transform: translateY(10px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 999; max-width: 300px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ── Chart ── */
.chart-wrap { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 8px; }

/* ── Settings grid ── */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.settings-card h2 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.tg-status-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 20px; }
.tg-on  { background: rgba(82,196,26,0.1); color: #52c41a; }
.tg-off { background: var(--bg3); color: var(--text3); }
.env-list { display: flex; flex-direction: column; gap: 6px; }
.env-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text2); padding: 6px 10px; background: var(--bg3); border-radius: var(--radius); }
.env-row code { font-family: monospace; color: var(--text); font-size: 12px; }
code { font-family: monospace; background: var(--bg3); padding: 1px 6px; border-radius: 4px; font-size: 12px; color: var(--text2); }

/* ── Drag-to-reorder ── */
.file-row.dragging      { opacity: 0.35; border-style: dashed; }
.file-row.drag-over-row { border-color: var(--red); background: rgba(226,75,74,0.05); }
.drag-handle { cursor: grab; display: flex; align-items: center; padding: 0 4px; color: var(--text3); flex-shrink: 0; }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.file-order-num { font-size: 11px; color: var(--text3); width: 20px; text-align: center; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.order-save-bar { display:flex; align-items:center; gap:10px; padding:10px 14px; background:rgba(226,75,74,0.08); border:0.5px solid var(--red); border-radius:var(--radius); margin-bottom:8px; font-size:13px; color:var(--red); }

/* ── Login log ── */
.login-success { color: #52c41a; font-weight: 500; }
.login-fail    { color: var(--red); font-weight: 500; }
