:root {
  color-scheme: dark;
  --bg: #101317;
  --panel: #171d24;
  --panel-2: #202832;
  --panel-3: #12171d;
  --text: #edf2f7;
  --muted: #9aa7b5;
  --line: #344150;
  --accent: #3fcf8e;
  --accent-2: #f2b84b;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
  min-width: 0;
}

.authView {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.loginPanel {
  width: min(100%, 380px);
  display: grid;
  gap: 10px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.loginPanel h1 {
  margin-bottom: 8px;
}

label,
.sliderLabel {
  color: var(--muted);
  font-size: 12px;
}

.shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #151a20;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 15px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.errorText {
  min-height: 18px;
  color: var(--danger);
}

input,
select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  padding: 0 10px;
}

input[readonly] {
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  padding: 9px 10px;
}

input[type="range"] {
  width: 100%;
  height: 24px;
  padding: 0;
}

button,
.buttonLink {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover:not(:disabled),
.buttonLink:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.logoutButton {
  border-color: rgba(242, 184, 75, 0.55);
}

.downloadPanel {
  width: min(100%, 720px);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
  padding: 22px;
}

.downloadPanel label,
.downloadPanel input {
  grid-column: 1 / -1;
}

.adminWorkspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 300px minmax(0, 1fr);
  overflow: hidden;
}

.clientRail,
.controls {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--panel);
}

.clientRail {
  border-right: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
}

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

.railActions {
  display: flex;
  gap: 8px;
}

.railActions button {
  min-height: 30px;
}

.clientTools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}

.clientListSummary {
  margin: 10px 0 8px;
}

.clientList {
  display: grid;
  gap: 8px;
  align-content: start;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.clientItem {
  width: 100%;
  min-height: 54px;
  display: grid;
  gap: 4px;
  justify-items: start;
  align-content: center;
  padding: 10px;
  text-align: left;
  border-color: var(--line);
}

.clientItem.isSelected {
  border-color: var(--accent);
}

.clientItem.isOnline .clientName::before {
  background: var(--accent);
}

.clientName {
  font-size: 14px;
  font-weight: 650;
}

.clientName::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.clientMeta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.emptyList {
  padding: 12px 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
}

.clientEditor,
.streamPanel,
.clientEditorForm {
  display: grid;
  gap: 8px;
}

.clientEditor {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.panelTitleRow,
.editorActions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.secondaryButton {
  min-height: 30px;
}

.dangerButton {
  border-color: rgba(255, 107, 107, 0.65);
  color: #ffd7d7;
}

.tokenEditRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.controls {
  border-right: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#selectedClientLabel {
  min-height: 18px;
  overflow-wrap: anywhere;
}

.checkLabel {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.checkLabel input {
  width: 16px;
  height: 16px;
  padding: 0;
}

#streamToggleButton {
  border-color: rgba(63, 207, 142, 0.55);
}

#streamToggleButton.isStreaming {
  border-color: rgba(255, 107, 107, 0.55);
}

.statusGrid {
  margin: 10px 0 0;
  display: grid;
  gap: 10px;
}

.statusGrid div {
  padding: 10px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
}

dt {
  color: var(--muted);
  font-size: 12px;
}

dd {
  margin: 4px 0 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.screenStage {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #07090c;
}

.screenSurface {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  background: #07090c;
}

.overlayEditor {
  position: absolute;
  z-index: 4;
  min-width: 56px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(63, 207, 142, 0.9);
  border-radius: 6px;
  background: rgba(22, 24, 28, 0.78);
  color: white;
  cursor: move;
  user-select: none;
  touch-action: none;
  overflow: hidden;
}

.overlayEditorText {
  width: 100%;
  text-align: center;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
  padding: 0;
  display: none;
}

.overlayEditorImage {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  pointer-events: none;
}

.overlayResizeHandle {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  cursor: nwse-resize;
}

#screenImage,
#webrtcVideo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

#screenImage:not([src]) {
  display: none;
}

.emptyState {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 18px;
}

.screenStage.hasFrame .emptyState {
  display: none;
}

@media (max-width: 1180px) {
  .adminWorkspace {
    grid-template-columns: 280px 280px minmax(0, 1fr);
  }
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .adminWorkspace {
    min-height: 0;
    display: block;
    overflow: visible;
  }

  .clientRail,
  .controls {
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .clientList {
    max-height: 45vh;
  }

  .screenStage {
    min-height: 56vh;
  }

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