:root {
  --bg: #05060a;
  --card: rgba(255, 255, 255, 0.035);
  --border: rgba(255, 255, 255, 0.09);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: #e7e9f2;
  --muted: #98a0b8;
  --blue: #4f8cff;
  --blue-2: #7aa9ff;
  --lilac: #a78bfa;
  --lilac-2: #c4b0ff;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 700px at 15% -10%, #10132b 0%, var(--bg) 55%),
    radial-gradient(1000px 600px at 110% 110%, #1a0f2e 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(79, 140, 255, 0.08), transparent 70%),
    radial-gradient(500px 300px at 80% 20%, rgba(167, 139, 250, 0.08), transparent 70%);
}

/* ---------- svg sprite & icons ---------- */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon.lg {
  width: 22px;
  height: 22px;
}

.icon.xl {
  width: 26px;
  height: 26px;
}

.icon.huge {
  width: 46px;
  height: 46px;
  opacity: 0.55;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  padding: 9px;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 28px;
  background: rgba(5, 6, 10, 0.78);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--lilac));
  box-shadow: 0 0 24px rgba(79, 140, 255, 0.45);
}

.logo.big {
  width: 56px;
  height: 56px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-item:hover {
  color: var(--text);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--lilac));
  box-shadow: 0 4px 16px rgba(79, 140, 255, 0.35);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--lilac-2);
  background: rgba(167, 139, 250, 0.08);
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 14px;
  }
  .nav-item span {
    display: none;
  }
  .nav-item {
    padding: 9px;
  }
}

/* ---------- layout ---------- */
main {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.view {
  animation: fade 0.25s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.card-head h2 {
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.card-head h2 .icon {
  color: var(--lilac-2);
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- buttons ---------- */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--lilac));
  box-shadow: 0 6px 24px rgba(79, 140, 255, 0.35);
}

.btn.primary:hover {
  box-shadow: 0 8px 30px rgba(167, 139, 250, 0.45);
}

.btn.outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.outline:hover {
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.04);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.btn.ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.btn.ghost.sm,
.btn.outline.sm {
  padding: 7px 12px;
  font-size: 13px;
}

.btn.wide {
  width: 100%;
  justify-content: center;
}

.btn.danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.btn.danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ---------- forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.field input[readonly] {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  letter-spacing: 0.4px;
  cursor: default;
  color: var(--blue-2);
}

.copy-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}

.grow {
  flex: 1;
}

.target-form {
  display: grid;
  grid-template-columns: 1fr 2fr 1.5fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}

@media (max-width: 860px) {
  .target-form {
    grid-template-columns: 1fr;
  }
}

.stack-form {
  display: grid;
  gap: 14px;
}

/* ---------- steps ---------- */
.steps {
  margin-top: 18px;
  padding-left: 22px;
  display: grid;
  gap: 8px;
}

.steps li {
  color: var(--muted);
  font-size: 13.5px;
}

.steps b {
  color: var(--text);
}

/* ---------- targets ---------- */
.target-list {
  list-style: none;
  display: grid;
  gap: 10px;
}

.target-list .empty,
.history-list .empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 22px 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.target-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.target-item .info {
  flex: 1;
  min-width: 0;
}

.target-item .name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.target-item .url {
  font-family: Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}

.badge.offline {
  background: rgba(152, 160, 184, 0.12);
  color: var(--muted);
}

.badge.starting,
.badge.retry {
  background: rgba(251, 191, 36, 0.14);
  color: var(--amber);
}

.badge.forwarding {
  background: rgba(52, 211, 153, 0.14);
  color: var(--green);
}

.badge.stopped {
  background: rgba(248, 113, 113, 0.14);
  color: var(--red);
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.toggle .slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle input:checked + .slider {
  background: linear-gradient(135deg, var(--blue), var(--lilac));
}

.toggle input:checked + .slider::before {
  transform: translateX(18px);
}

.msg {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-word;
}

.msg.error {
  color: var(--red);
}

/* ---------- status banner ---------- */
.status-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.status-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(152, 160, 184, 0.12);
  color: var(--muted);
}

.status-banner.live .status-icon {
  color: var(--green);
  background: rgba(52, 211, 153, 0.12);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.status-banner.live {
  border-color: rgba(52, 211, 153, 0.4);
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.08), rgba(79, 140, 255, 0.08));
}

.status-banner.live .status-dot {
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.status-text {
  font-weight: 700;
  font-size: 15px;
}

.status-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

/* ---------- stat chips ---------- */
.stat-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.chip .icon {
  color: var(--lilac-2);
}

.chip-label {
  color: var(--muted);
  font-size: 12px;
  margin-right: auto;
}

.chip b {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* ---------- preview ---------- */
.preview-card {
  padding: 10px;
  margin-bottom: 20px;
}

.preview-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}

.preview-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  background: radial-gradient(600px 300px at 50% 0%, rgba(79, 140, 255, 0.05), transparent 70%);
}

/* ---------- kv (settings) ---------- */
.kv {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  padding-top: 4px;
}

.kv > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.kv span {
  color: var(--muted);
  font-size: 13px;
}

.kv b {
  font-size: 14px;
  text-align: right;
  word-break: break-all;
}

.kv .mono {
  font-family: Consolas, monospace;
  color: var(--blue-2);
}

/* ---------- history ---------- */
.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.history-date {
  min-width: 130px;
}

.history-date b {
  display: block;
  font-size: 14px;
}

.history-date span {
  color: var(--muted);
  font-size: 12px;
}

.history-stats {
  display: flex;
  gap: 16px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}

.history-targets {
  max-width: 220px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .history-item {
    flex-wrap: wrap;
    gap: 8px;
  }
  .history-stats {
    margin-left: 0;
  }
}

/* ---------- admin ---------- */
.health-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 20px;
}

@media (max-width: 860px) {
  .health-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.health-card {
  text-align: center;
  padding: 18px 12px;
}

.health-val {
  display: block;
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--blue-2), var(--lilac-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.health-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table .mono {
  font-family: Consolas, monospace;
  font-size: 12px;
  color: var(--blue-2);
}

.table .live-cell {
  color: var(--green);
  font-weight: 600;
}

.table .offline-cell {
  color: var(--muted);
}

/* ---------- auth ---------- */
.auth-wrap {
  display: grid;
  place-items: center;
  padding-top: 6vh;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.auth-logo {
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}

.auth-title {
  text-align: center;
  font-size: 26px;
  background: linear-gradient(135deg, var(--blue-2), var(--lilac-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0 24px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab.active {
  background: linear-gradient(135deg, var(--blue), var(--lilac));
  color: #fff;
}

#authForm,
#auth2faForm,
#authResetForm {
  display: grid;
  gap: 14px;
}

.auth-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

.auth-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.link {
  background: none;
  border: none;
  color: var(--blue-2);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
}

.link:hover {
  text-decoration: underline;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(20, 22, 34, 0.95);
  border: 1px solid var(--border-hover);
  color: var(--text);
  font-size: 13.5px;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.5);
  color: var(--red);
}

/* ---------- watch / embed (public viewer) ---------- */
.watch-body {
  background: radial-gradient(1200px 700px at 15% -10%, #10132b 0%, var(--bg) 55%),
    radial-gradient(1000px 600px at 110% 110%, #1a0f2e 0%, var(--bg) 55%);
}

.watch-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.watch-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  word-break: break-word;
}

.watch-player-card {
  padding: 10px;
}

.watch-footer {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.pass-card {
  max-width: 380px;
  margin: 18px auto 0;
  display: grid;
  gap: 14px;
}

.pass-card h2 {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#statusBox[data-state="live"] {
  background: rgba(52, 211, 153, 0.14);
  color: var(--green);
}

#statusBox[data-state="locked"] {
  background: rgba(251, 191, 36, 0.14);
  color: var(--amber);
}

/* embed: full-bleed minimal player */
.embed-body {
  margin: 0;
  background: #000;
  overflow: hidden;
}

.embed-frame {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #000;
}

.embed-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: #000;
}

.embed-frame .preview-placeholder {
  background: transparent;
}

.embed-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
}

.live-badge {
  background: rgba(248, 113, 113, 0.85) !important;
  color: #fff !important;
}

.embed-title {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.embed-pass {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, 90vw);
  background: rgba(15, 17, 26, 0.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}
