:root {
  --bg: #0b0e13;
  --bg-2: #10141b;
  --card: #141a23;
  --card-2: #1a212c;
  --line: #232c39;
  --line-2: #2e3949;
  --text: #e6ebf2;
  --muted: #8b97a8;
  --dim: #5d6879;
  --accent: #ff4d3d;
  --accent-2: #ff7a5c;
  --live: #ff3b30;
  --ok: #2fd17a;
  --warn: #f5b83d;
  --err: #ff5a5f;
  --info: #4fa3ff;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a1210 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ------------------------------------------------ login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--live);
  box-shadow: 0 0 0 4px rgba(255,59,48,.18), 0 0 18px rgba(255,59,48,.6);
  animation: pulse 2s infinite;
}
.login-card .brand { font-size: 20px; margin-bottom: 6px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }

/* ------------------------------------------------ layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .brand { padding: 4px 10px 18px; font-size: 16px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 9px 12px; border-radius: 10px; color: var(--muted);
  cursor: pointer; font-weight: 500;
}
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-btn:hover { background: var(--card); color: var(--text); }
.nav-btn.active { background: var(--card-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-sep { height: 1px; background: var(--line); margin: 10px 6px; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.sidebar-foot .who { font-weight: 600; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
.topbar .spacer { flex: 1; }
.btn.menu-toggle { display: none; }

/* ------------------------------------------------ stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.bar { height: 4px; background: var(--line); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .4s; }
.bar > i.warn { background: var(--warn); }
.bar > i.err { background: var(--err); }

/* ------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13px;
  white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #222b38; border-color: #3a4759; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff6152; }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: rgba(255,90,95,.12); border-color: rgba(255,90,95,.4); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--card-2); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.icon { padding: 7px; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 12px; color: var(--dim); }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 9px 12px; outline: none; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,77,61,.15); }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.search { max-width: 260px; min-width: 160px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: 22px; background: var(--line-2); position: relative; transition: background .2s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(47,209,122,.3); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line-2); font-size: 11px; font-weight: 600; color: var(--muted);
}
.chip.ok { color: var(--ok); border-color: rgba(47,209,122,.35); background: rgba(47,209,122,.08); }
.chip.err { color: var(--err); border-color: rgba(255,90,95,.35); background: rgba(255,90,95,.08); }
.chip.warn { color: var(--warn); border-color: rgba(245,184,61,.35); background: rgba(245,184,61,.08); }
.chip.info { color: var(--info); border-color: rgba(79,163,255,.35); background: rgba(79,163,255,.08); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------ channel cards */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: border-color .2s, transform .2s;
}
.card:hover { border-color: var(--line-2); }
.card.offline { opacity: .6; }
.thumb {
  position: relative; aspect-ratio: 16/9; background:
    repeating-linear-gradient(135deg, #10151d 0 12px, #121821 12px 24px);
  display: grid; place-items: center; overflow: hidden;
}
.thumb video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; object-fit: contain; }
.thumb .play {
  position: relative; z-index: 1; width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.12); backdrop-filter: blur(6px); display: grid; place-items: center;
  transition: transform .15s, background .15s;
}
.thumb .play:hover { transform: scale(1.06); background: var(--accent); }
.thumb .play svg { width: 22px; height: 22px; margin-left: 3px; }
.thumb .res {
  position: absolute; z-index: 2; right: 10px; bottom: 10px; font: 600 11px var(--mono);
  background: rgba(0,0,0,.6); padding: 3px 7px; border-radius: 6px;
}
.badge-live {
  position: absolute; z-index: 2; left: 10px; top: 10px; display: inline-flex; align-items: center; gap: 6px;
  background: var(--live); color: #fff; font-weight: 800; font-size: 11px; letter-spacing: .8px;
  padding: 3px 8px; border-radius: 6px;
}
.badge-live .dot { background: #fff; animation: pulse 1.4s infinite; }
.badge-off { background: #3a4252; }
.badge-off .dot { animation: none; }
.thumb .close-video {
  position: absolute; z-index: 3; right: 8px; top: 8px; background: rgba(0,0,0,.6); border: 0;
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; display: grid; place-items: center;
}
.card-body { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.card-title h3 { margin: 0; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .app { color: var(--muted); font: 500 12px var(--mono); }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.meta div { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; min-width: 0; }
.meta b { display: block; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta span { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); }
.spark { display: flex; align-items: center; gap: 10px; }
.spark svg { flex: 1; height: 34px; }
.spark .kbps { font: 700 15px var(--mono); min-width: 88px; text-align: right; }
.spark .kbps small { color: var(--muted); font-weight: 500; font-size: 11px; }
.card-info { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; border-top: 1px solid var(--line); padding: 10px 12px; flex-wrap: wrap; }
.card-actions .spacer { flex: 1; }

/* ------------------------------------------------ panels / tables */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--dim); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.015); }
td .actions { display: flex; gap: 6px; justify-content: flex-end; }
.secret { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 8px; }
pre.log {
  margin: 0; background: #07090d; border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font: 12px/1.55 var(--mono); color: #c8d1dd; max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.tabs { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { background: none; border: 0; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs button.active { background: var(--card-2); color: var(--text); }

/* ------------------------------------------------ restream cards */
.rs-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.rs-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.rs-head h3 { margin: 0; font-size: 15px; }
.rs-route { font: 12px var(--mono); color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rs-route .arrow { color: var(--accent); }
.rs-jobs { border-top: 1px solid var(--line); }
.rs-job { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.rs-job:last-child { border-bottom: 0; }
.rs-job details { grid-column: 1 / -1; }
.rs-job summary { cursor: pointer; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------ services */
.svc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 18px; }
.svc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.svc h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------ modal / toast */
.modal-back {
  position: fixed; inset: 0; background: rgba(3,5,8,.7); backdrop-filter: blur(3px); z-index: 50;
  display: grid; place-items: center; padding: 16px; animation: fade .15s;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: 0 40px 100px rgba(0,0,0,.6);
  animation: rise .18s;
}
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 18px 20px 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast {
  background: var(--card-2); border: 1px solid var(--line-2); border-left: 3px solid var(--ok);
  padding: 10px 14px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: rise .2s;
  max-width: 420px; white-space: pre-wrap;
}
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.alert { padding: 10px 14px; border-radius: 10px; border: 1px solid; margin-bottom: 16px; font-size: 13px; }
.alert.warn { color: var(--warn); border-color: rgba(245,184,61,.35); background: rgba(245,184,61,.07); }
.alert.info { color: #a9cdf7; border-color: rgba(79,163,255,.3); background: rgba(79,163,255,.06); }
.alert.err { color: var(--err); border-color: rgba(255,90,95,.35); background: rgba(255,90,95,.07); }
.copy-row { display: flex; gap: 6px; margin-bottom: 8px; }
.copy-row input { font-family: var(--mono); font-size: 12px; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------ responsive */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.5); }
  .btn.menu-toggle { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .search { max-width: none; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
