:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: #0f1b2d;
  --panel-2: #13233a;
  --border: #263a56;
  --text: #f4f7fb;
  --muted: #9db0c8;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 18px 45px rgba(0,0,0,.28);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(59,130,246,.16), transparent 34%),
    linear-gradient(180deg, #07111f 0%, #091522 100%);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #bfdbfe;
  overflow-wrap: anywhere;
}
.muted { color: var(--muted); margin: .25rem 0 0; }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(430px, 100%);
  padding: 34px;
  background: rgba(15,27,45,.94);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  font-size: 25px; font-weight: 800;
}
.login-card h1 { margin: 18px 0 0; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.stack-form label { display: grid; gap: 7px; color: #dbeafe; }
input {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #091522;
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.14); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 24px clamp(18px, 4vw, 58px);
  border-bottom: 1px solid rgba(38,58,86,.7);
  background: rgba(7,17,31,.83);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: clamp(22px, 3vw, 34px); }
.eyebrow { color: #60a5fa; font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.page-shell { width: min(1480px, calc(100% - 32px)); margin: 26px auto 70px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card, .panel {
  border: 1px solid var(--border);
  background: rgba(15,27,45,.92);
  box-shadow: var(--shadow);
}
.stat-card { border-radius: 15px; padding: 18px; display: grid; gap: 6px; }
.stat-card span { color: var(--muted); }
.stat-card strong { font-size: 30px; }
.stat-card .small-code { font-size: 17px; overflow-wrap: anywhere; }
.panel { margin-top: 18px; border-radius: 17px; padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 17px; }
.panel-head h2 { margin: 0; }
.panel-head-wrap { flex-wrap: wrap; }
.create-form { display: grid; grid-template-columns: minmax(220px, 420px) auto; gap: 10px; align-items: center; }
.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.toolbar input { width: 230px; }
.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
  color: white;
  background: #20324b;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.btn:hover:not(:disabled):not(.is-disabled) { transform: translateY(-1px); }
.btn:disabled, .is-disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary-2); }
.btn-secondary { background: #21344f; border-color: #385172; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-success { background: #166534; }
.btn-warning { background: #92400e; }
.btn-danger { background: #991b1b; }
.user-list { display: grid; gap: 14px; }
.user-card { border: 1px solid var(--border); background: #0a1627; border-radius: 15px; overflow: hidden; }
.user-card-main { padding: 18px; }
.user-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.user-title-row h3 { margin: 0 0 8px; font-size: 22px; }
.badges { display: flex; gap: 7px; flex-wrap: wrap; }
.badge { padding: 4px 8px; border-radius: 999px; background: #293a51; color: #c4d0df; font-size: 11px; font-weight: 850; letter-spacing: .04em; }
.badge-live { background: rgba(239,68,68,.17); color: #fca5a5; }
.badge-ok { background: rgba(34,197,94,.16); color: #86efac; }
.badge-danger { background: rgba(239,68,68,.16); color: #fca5a5; }
.info-grid { display: grid; grid-template-columns: 1fr 1.5fr .8fr; gap: 11px; margin-top: 17px; }
.info-box { min-width: 0; padding: 13px; border: 1px solid #203451; background: #0d1c30; border-radius: 11px; display: grid; gap: 6px; }
.info-box > span, .info-box small { color: var(--muted); }
.copy-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.copy-row code { min-width: 0; }
.icon-btn { flex: 0 0 auto; border: 1px solid #385172; background: #172a43; color: white; border-radius: 8px; padding: 6px 9px; }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; padding: 13px 18px; border-top: 1px solid var(--border); background: #0d1a2b; }
.actions-bar form { margin: 0; }
.alert { margin: 0 0 14px; border-radius: 11px; padding: 12px 14px; border: 1px solid transparent; }
.alert-success { background: rgba(34,197,94,.13); border-color: rgba(34,197,94,.35); color: #bbf7d0; }
.alert-error { background: rgba(239,68,68,.13); border-color: rgba(239,68,68,.35); color: #fecaca; }
.alert-warning { background: rgba(245,158,11,.13); border-color: rgba(245,158,11,.35); color: #fde68a; }
.empty-state { padding: 42px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 13px; }
.toast { position: fixed; right: 20px; bottom: 20px; padding: 11px 14px; border-radius: 10px; background: #172a43; border: 1px solid #385172; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; z-index: 100; }
.toast.show { opacity: 1; transform: translateY(0); }
.watch-shell { max-width: 1200px; }
.player-panel { padding: 0; overflow: hidden; }
.player-wrap { aspect-ratio: 16/9; background: black; position: relative; display: grid; place-items: center; }
.player-wrap video { width: 100%; height: 100%; object-fit: contain; background: black; }
.player-placeholder { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px; color: var(--muted); background: radial-gradient(circle, #14243a 0%, #05090f 70%); }
.player-placeholder strong { color: white; font-size: 21px; }
.player-controls { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 17px 20px; }
.status-dot { font-weight: 800; }
.status-dot.online { color: #86efac; }
.status-dot.connecting { color: #fde68a; }
.status-dot.offline { color: #fca5a5; }
@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .info-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .page-shell { width: min(100% - 20px, 1480px); }
  .topbar { padding: 16px; align-items: flex-start; }
  .stats-grid { grid-template-columns: 1fr; }
  .create-form { grid-template-columns: 1fr; }
  .user-title-row, .player-controls { flex-direction: column; align-items: stretch; }
  .actions-bar { display: grid; grid-template-columns: 1fr; }
  .actions-bar .btn, .actions-bar form { width: 100%; }
  .toolbar input { width: 100%; }
}

/* Live status auto-refresh */
.user-card.is-live {
  border-color: rgba(239, 68, 68, .55);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, .08), 0 14px 36px rgba(0, 0, 0, .18);
}

.stream-status-badge.badge-live::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 rgba(252, 165, 165, .6);
  animation: live-pulse 1.4s infinite;
}

.stream-status-badge.badge-live {
  display: inline-flex;
  align-items: center;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(252, 165, 165, .55); }
  70% { box-shadow: 0 0 0 7px rgba(252, 165, 165, 0); }
  100% { box-shadow: 0 0 0 0 rgba(252, 165, 165, 0); }
}

/* v2.2: account password and custom stream key */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.topbar-actions form { margin: 0; }
.password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}
.password-form label,
.create-form-wide label,
.inline-editor-form label {
  display: grid;
  gap: 7px;
  color: #dbeafe;
}
.create-form-wide {
  grid-template-columns: minmax(190px, .8fr) minmax(260px, 1.2fr) auto;
  align-items: end;
}
.create-form-wide label small { color: var(--muted); }
.field-note {
  margin: 12px 0 0;
  color: var(--muted);
}
.inline-editor {
  position: relative;
}
.inline-editor > summary {
  list-style: none;
  user-select: none;
}
.inline-editor > summary::-webkit-details-marker { display: none; }
.inline-editor[open] > summary {
  background: #2d4668;
}
.inline-editor-form {
  position: absolute;
  z-index: 30;
  left: 0;
  bottom: calc(100% + 9px);
  width: min(430px, calc(100vw - 48px));
  display: grid;
  gap: 11px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101f34;
  box-shadow: var(--shadow);
}
.inline-editor-form small { color: var(--muted); }
.inline-editor-form .btn { justify-self: start; }
@media (max-width: 1050px) {
  .password-form { grid-template-columns: 1fr 1fr; }
  .password-form .btn { width: 100%; }
  .create-form-wide { grid-template-columns: 1fr 1fr; }
  .create-form-wide .btn { width: 100%; }
}
@media (max-width: 620px) {
  .topbar-actions { width: 100%; }
  .topbar-actions .btn,
  .topbar-actions form { width: 100%; }
  .password-form,
  .create-form-wide { grid-template-columns: 1fr; }
  .inline-editor { width: 100%; }
  .inline-editor > summary { width: 100%; }
  .inline-editor-form {
    position: static;
    width: 100%;
    margin-top: 9px;
  }
}

/* v2.3: password modal */
.modal-dialog {
  width: min(560px, calc(100vw - 28px));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
.modal-dialog::backdrop {
  background: rgba(2, 8, 18, .78);
  backdrop-filter: blur(5px);
}
.modal-card {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #0f1b2d;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.modal-head h2 {
  margin: 4px 0 0;
  font-size: 25px;
}
.modal-close {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #172a43;
  color: white;
  font-size: 25px;
  line-height: 1;
}
.modal-form {
  display: grid;
  gap: 14px;
}
.modal-form label {
  display: grid;
  gap: 7px;
  color: #dbeafe;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
body:has(.modal-dialog[open]) {
  overflow: hidden;
}

/* v2.3: WebRTC player diagnostics */
.player-status-copy {
  min-width: 0;
}
.player-diagnostics {
  margin: 0 20px 20px;
  padding: 13px 15px;
  border: 1px solid rgba(245, 158, 11, .42);
  border-radius: 11px;
  background: rgba(245, 158, 11, .11);
  color: #fde68a;
}
.player-diagnostics-error {
  border-color: rgba(239, 68, 68, .45);
  background: rgba(239, 68, 68, .12);
  color: #fecaca;
}
.player-help h2 {
  margin-top: 0;
}
.help-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px;
  margin: 16px 0;
}
.help-grid > div {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid #203451;
  border-radius: 11px;
  background: #0d1c30;
}
.help-grid span {
  color: var(--muted);
}
.help-grid strong {
  font-size: 17px;
}
.player-wrap video {
  z-index: 1;
}
.player-placeholder {
  z-index: 2;
}
.player-placeholder[hidden] {
  display: none;
}
@media (max-width: 760px) {
  .help-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .modal-actions .btn {
    width: 100%;
  }
}

/* v2.4: brand assets, favicon companion UI and stream-link modal */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.topbar-brand-mark {
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  filter: drop-shadow(0 10px 18px rgba(37, 99, 235, .22));
}
.login-layout {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr);
  gap: 22px;
  align-items: stretch;
}
.login-visual {
  position: relative;
  min-height: 590px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(9, 21, 34, .88);
  box-shadow: var(--shadow);
}
.login-hero-image {
  width: 100%;
  height: 100%;
  min-height: 590px;
  display: block;
  object-fit: cover;
}
.login-visual-copy {
  position: absolute;
  left: 34px;
  right: 34px;
  bottom: 28px;
  padding: 20px;
  border: 1px solid rgba(96, 165, 250, .28);
  border-radius: 16px;
  background: rgba(5, 12, 22, .78);
  backdrop-filter: blur(12px);
}
.login-visual-copy .brand-logo {
  width: min(330px, 86%);
  height: auto;
  display: block;
}
.login-visual-copy p {
  margin: 12px 0 0;
  color: #cbd5e1;
}
.login-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-brand-mark {
  width: 62px;
  height: 62px;
}
.modal-dialog-wide {
  width: min(980px, calc(100vw - 28px));
}
.link-help {
  margin: -2px 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(59, 130, 246, .35);
  border-radius: 11px;
  background: rgba(37, 99, 235, .12);
  color: #dbeafe;
}
.link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.link-section {
  min-width: 0;
  padding: 16px;
  border: 1px solid #263a56;
  border-radius: 14px;
  background: #0a1627;
}
.link-section-full {
  grid-column: 1 / -1;
}
.link-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}
.link-section-head h3 {
  margin: 2px 0 0;
  font-size: 19px;
}
.link-kicker {
  color: #60a5fa;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .13em;
}
.copy-field {
  display: grid;
  gap: 7px;
  margin-top: 11px;
}
.copy-field > span {
  color: #cbd5e1;
  font-weight: 700;
}
.copy-field > span small,
.copy-field > small {
  color: var(--muted);
  font-weight: 500;
}
.copy-field-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid #203451;
  border-radius: 10px;
  background: #0d1c30;
}
.copy-field-row code {
  min-width: 0;
  overflow-wrap: anywhere;
  user-select: all;
}
.links-view-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
#external-link-box {
  padding-top: 11px;
  border-top: 1px solid rgba(38, 58, 86, .7);
}
@media (max-width: 900px) {
  .login-layout {
    grid-template-columns: 1fr;
    max-width: 560px;
  }
  .login-visual {
    min-height: 360px;
  }
  .login-hero-image {
    min-height: 360px;
  }
  .link-grid,
  .links-view-grid {
    grid-template-columns: 1fr;
  }
  .link-section-full {
    grid-column: auto;
  }
}
@media (max-width: 620px) {
  .topbar-brand-mark {
    width: 42px;
    height: 42px;
  }
  .login-shell {
    padding: 12px;
  }
  .login-visual {
    display: none;
  }
  .login-card {
    padding: 26px 22px;
  }
  .link-section-head,
  .copy-field-row {
    grid-template-columns: 1fr;
  }
  .link-section-head {
    flex-direction: column;
  }
  .copy-field-row .icon-btn,
  .link-section-head .btn {
    width: 100%;
  }
}
