* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --background: #070b14;
  --panel: rgba(15, 23, 42, .88);
  --panel-solid: #111827;
  --panel-light: #182235;
  --border: rgba(148, 163, 184, .16);
  --border-strong: rgba(96, 165, 250, .42);
  --text: #f8fafc;
  --muted: #94a3b8;
  --subtle: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --radius: 18px;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(37, 99, 235, .13), transparent 32%),
    radial-gradient(circle at 82% 22%, rgba(124, 58, 237, .10), transparent 30%),
    linear-gradient(180deg, #070b14 0%, #0a1020 100%);
  color: var(--text);
  padding-bottom: 126px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: .42;
}

.hidden {
  display: none !important;
}

.page-glow {
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: .18;
  pointer-events: none;
}

.glow-one {
  top: -180px;
  left: -160px;
  background: #2563eb;
}

.glow-two {
  right: -190px;
  bottom: -180px;
  background: #7c3aed;
}

.app {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 22px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  letter-spacing: -.025em;
}

.eyebrow,
.panel-kicker {
  color: #60a5fa;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-heading,
.viewer-header,
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h2,
.viewer-header h2,
.row h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

.status {
  min-height: 22px;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.5;
}

.primary-button,
.ghost-button,
.icon-button,
.viewer-controls button {
  cursor: pointer;
  border-radius: 11px;
  font-weight: 750;
  transition:
    transform .15s ease,
    background .15s ease,
    border-color .15s ease,
    opacity .15s ease;
}

.primary-button {
  min-height: 44px;
  padding: 0 17px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 12px 24px rgba(37, 99, 235, .22);
}

.primary-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #60a5fa, #2563eb);
}

.ghost-button,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, .75);
  color: #e2e8f0;
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: rgba(96, 165, 250, .45);
  background: #1e293b;
}


/* LOGIN */

.login-shell {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(340px, 470px);
  align-items: center;
  gap: 80px;
  width: min(1040px, 100%);
  min-height: calc(100vh - 44px);
  margin: auto;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 22px;
}

.login-brand h1 {
  margin: 5px 0 6px;
  font-size: clamp(42px, 7vw, 72px);
}

.login-brand p {
  max-width: 400px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
}

.brand-icon {
  display: grid;
  flex: 0 0 auto;
  width: 78px;
  height: 78px;
  place-items: center;
  border: 1px solid rgba(96, 165, 250, .42);
  border-radius: 23px;
  background:
    linear-gradient(145deg, rgba(59, 130, 246, .28), rgba(124, 58, 237, .18));
  box-shadow:
    0 20px 50px rgba(37, 99, 235, .25),
    inset 0 1px rgba(255,255,255,.16);
  color: white;
  font-size: 24px;
  font-weight: 900;
}

.brand-icon.small {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 15px;
}

.login-card {
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(15, 23, 42, .9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 24px;
}

.login-heading h2 {
  margin: 0 0 3px;
  font-size: 24px;
}

.login-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.login-lock {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: rgba(34, 197, 94, .12);
  color: var(--green);
}

.login-form {
  display: grid;
  gap: 16px;
}

.field-label {
  display: grid;
  gap: 8px;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 700;
}

.field-label input,
.join-form input,
.sessions-toolbar input,
.sessions-toolbar select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(2, 6, 23, .62);
  color: var(--text);
}

.field-label input {
  padding: 0 13px;
}

.field-label input::placeholder,
.join-form input::placeholder,
.sessions-toolbar input::placeholder {
  color: #526077;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 86px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  min-height: 32px;
  padding: 0 9px;
  transform: translateY(-50%);
  cursor: pointer;
  border-radius: 8px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}

.remember-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
  color: #e2e8f0;
}

.remember-row input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.remember-row span {
  display: grid;
  gap: 2px;
}

.remember-row small {
  color: var(--muted);
  font-weight: 400;
}

.login-button {
  width: 100%;
  margin-top: 2px;
}

.login-status {
  margin-top: 14px;
  color: #fca5a5;
}

.security-note {
  margin-top: 17px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
  color: var(--subtle);
  font-size: 12px;
  text-align: center;
}


/* ADMIN HEADER */

.topbar {
  position: sticky;
  top: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(7, 11, 20, .86);
  box-shadow: 0 16px 50px rgba(0,0,0,.24);
  backdrop-filter: blur(20px);
}

.topbar-brand,
.topbar-actions,
.user-chip {
  display: flex;
  align-items: center;
}

.topbar-brand {
  gap: 11px;
}

.topbar-brand h1 {
  margin: 2px 0 0;
  font-size: 20px;
}

.topbar-actions {
  gap: 10px;
}

.live-chip,
.user-chip {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(30, 41, 59, .6);
}

.live-chip {
  gap: 8px;
  padding: 0 13px;
  color: #bbf7d0;
  font-size: 13px;
  font-weight: 700;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(34,197,94,.10);
}

.user-chip {
  gap: 9px;
  padding: 5px 11px 5px 6px;
}

.user-chip small,
.user-chip strong {
  display: block;
}

.user-chip small {
  color: var(--muted);
  font-size: 10px;
}

.user-chip strong {
  max-width: 190px;
  overflow: hidden;
  color: #f8fafc;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 9px;
  background: rgba(59,130,246,.16);
  color: #93c5fd;
  font-weight: 900;
}


/* DASHBOARD */

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.sidebar,
.workspace {
  display: grid;
  gap: 18px;
}

.join-panel,
.sessions-panel,
.viewer-panel,
.logs-panel {
  padding: 18px;
}

.join-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  margin-top: 15px;
}

.join-form input {
  padding: 0 13px;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: .08em;
}

.sessions-panel {
  min-height: 520px;
}

.sessions-heading {
  margin-bottom: 14px;
}

.session-counter {
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.session-counter strong {
  color: #f8fafc;
  font-size: 22px;
}

.sessions-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px 42px;
  gap: 7px;
  margin-bottom: 12px;
}

.sessions-toolbar input,
.sessions-toolbar select {
  padding: 0 10px;
  font-size: 12px;
}

.sessions-toolbar select {
  cursor: pointer;
}

.sessions {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 310px);
  overflow-y: auto;
  padding-right: 3px;
}

.session {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(15, 23, 42, .72);
  transition:
    border-color .15s ease,
    background .15s ease,
    transform .15s ease;
}

.session:hover {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, .3);
  background: rgba(30, 41, 59, .82);
}

.session-code {
  display: grid;
  gap: 3px;
}

.session-code strong {
  font-size: 17px;
  letter-spacing: .04em;
}

.session-code span {
  color: #60a5fa;
  font-size: 10px;
  font-weight: 900;
}

.session-info {
  min-width: 0;
}

.session-info > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-info .muted {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.session button {
  min-height: 36px;
  padding: 0 11px;
  cursor: pointer;
  border-radius: 9px;
  background: #2563eb;
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.session-current {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, .12);
}

.session-mine {
  background: rgba(34, 197, 94, .07);
}

.session-busy {
  opacity: .6;
}

.geo {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: #cbd5e1;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(59,130,246,.14);
  color: #93c5fd;
  font-size: 10px;
  font-weight: 850;
}


/* VIEWER */

.viewer-panel {
  min-height: 620px;
}

.session-timer {
  min-height: 32px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(30, 41, 59, .62);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}

.current-session-meta {
  margin: 14px 0 11px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(2, 6, 23, .48);
  color: var(--muted);
  font-size: 12px;
}

.viewer-stage {
  position: relative;
  display: grid;
  min-height: 470px;
  overflow: hidden;
  place-items: center;
  border: 1px solid rgba(148, 163, 184, .14);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(15,23,42,.6), rgba(2,6,23,.9)),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 18px,
      rgba(255,255,255,.012) 18px,
      rgba(255,255,255,.012) 19px
    );
}

.viewer-stage video,
.fallback-image {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  background: #020617;
}

.viewer-stage video {
  min-height: 470px;
}

.viewer-stage video.hidden,
.fallback-image.hidden {
  display: none;
}

.fallback-image {
  min-height: 470px;
}

.viewer-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  padding: 11px;
  border-top: 1px solid var(--border);
  background: rgba(2, 6, 23, .88);
  flex-wrap: wrap;
}

.viewer-controls button {
  min-height: 37px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: #1e293b;
  color: #e2e8f0;
  font-size: 12px;
}

.viewer-controls button:hover {
  border-color: rgba(96,165,250,.45);
  background: #273449;
}

.viewer-controls button.danger {
  margin-left: auto;
  border-color: rgba(239,68,68,.24);
  background: rgba(153, 27, 27, .82);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 37px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(59,130,246,.13);
  color: #93c5fd;
  font-size: 11px;
  font-weight: 850;
}

.viewer-status {
  margin-top: 10px;
}

.viewer-stage:fullscreen {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  background: #000;
}

.viewer-stage:fullscreen video,
.viewer-stage:fullscreen .fallback-image {
  flex: 1;
  width: 100%;
  max-height: calc(100vh - 60px);
  min-height: 0;
}

.viewer-stage:fullscreen .viewer-controls {
  flex: 0 0 auto;
}


/* LOGS */

.logs-panel {
  margin-bottom: 10px;
}

.logs-panel pre {
  max-height: 310px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #020617;
  color: #94a3b8;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.logs-hidden {
  display: none;
}


/* STATUS COLORS */

.status-waiting_admin {
  background: rgba(245, 158, 11, .13);
  color: #fcd34d;
}

.status-claimed,
.status-admin_connected {
  background: rgba(59, 130, 246, .13);
  color: #93c5fd;
}

.status-webrtc_connected,
.status-webrtc_connected_turn {
  background: rgba(34, 197, 94, .13);
  color: #86efac;
}

.status-turn_retry {
  background: rgba(245, 158, 11, .13);
  color: #fcd34d;
}

.status-screenshots_fallback {
  background: rgba(139, 92, 246, .15);
  color: #c4b5fd;
}

.status-webrtc_problem,
.status-client_disconnected,
.status-stale {
  background: rgba(239, 68, 68, .13);
  color: #fca5a5;
}


/* STICKY SESSION BAR */

.sticky-sessions {
  position: fixed;
  right: 18px;
  bottom: 16px;
  left: 18px;
  z-index: 60;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(7, 11, 20, .92);
  box-shadow: 0 20px 60px rgba(0,0,0,.42);
  backdrop-filter: blur(20px);
}

.sticky-title {
  margin: 0 0 7px 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.sticky-sessions-list {
  display: flex;
  gap: 7px;
  overflow-x: auto;
}

.sticky-session {
  display: grid;
  min-width: 145px;
  gap: 2px;
  padding: 9px 11px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #111827;
  color: white;
  text-align: left;
}

.sticky-session strong {
  font-size: 14px;
}

.sticky-session span,
.sticky-session small {
  overflow: hidden;
  font-size: 10px;
  opacity: .8;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sticky-current {
  border-color: #3b82f6;
  background: rgba(37, 99, 235, .18);
}

.sticky-busy {
  opacity: .46;
}


/* RESPONSIVE */

@media (max-width: 1050px) {
  .login-shell {
    grid-template-columns: 1fr;
    gap: 34px;
    width: min(520px, 100%);
    padding: 40px 0;
  }

  .dashboard-grid {
    grid-template-columns: 340px minmax(0, 1fr);
  }

  .sessions-toolbar {
    grid-template-columns: 1fr 42px;
  }

  .sessions-toolbar select {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 860px) {
  body {
    padding-bottom: 140px;
  }

  .app {
    padding: 12px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .sessions {
    max-height: 470px;
  }

  .viewer-stage,
  .viewer-stage video,
  .fallback-image {
    min-height: 330px;
  }

  .live-chip {
    display: none;
  }
}

@media (max-width: 560px) {
  .login-card {
    padding: 22px;
  }

  .login-brand {
    align-items: flex-start;
  }

  .brand-icon:not(.small) {
    width: 58px;
    height: 58px;
    border-radius: 18px;
  }

  .login-brand h1 {
    font-size: 38px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .user-chip {
    min-width: 0;
  }

  .join-form {
    grid-template-columns: 1fr;
  }

  .session {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .session button {
    grid-column: 1 / -1;
  }

  .viewer-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .viewer-controls button.danger {
    width: 100%;
    margin-left: 0;
  }

  .sticky-sessions {
    right: 7px;
    bottom: 7px;
    left: 7px;
  }
}


/* UI alignment fixes */

.live-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  white-space: nowrap;
}

.live-chip .live-dot {
  flex: 0 0 auto;
}

.logs-panel .row {
  align-items: center;
}

.logs-panel .row > button {
  margin-left: 8px;
}

.logs-panel .row > button:first-of-type {
  margin-left: auto;
}
