:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111418;
  color: #e8edf2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #111418;
}

button,
input,
select {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-rows: max-content max-content max-content max-content max-content minmax(0, 1fr) max-content max-content;
  min-height: 100vh;
}

.topbar {
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid #29313a;
  background: #171b21;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

p {
  margin: 4px 0 0;
  color: #9ba8b5;
  font-size: 13px;
}

.connect {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.account span {
  max-width: 180px;
  overflow: hidden;
  color: #cbd5df;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account input {
  width: 150px;
  max-width: 100%;
}

.account button {
  min-width: max-content;
}

.dangerButton {
  border-color: #7a4f57;
  background: #3a2228;
  color: #f1c2c2;
}

.dangerButton:disabled {
  opacity: 0.46;
}

.devices {
  grid-row: 2;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #29313a;
  background: #12161b;
}

.devicesHeader {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #cbd5df;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.devicesHeader button {
  min-height: 30px;
  border-color: #3d4956;
  background: #202832;
  color: #dce5ee;
  padding: 0 10px;
  font-size: 12px;
}

.devicesHeader select {
  width: 220px;
  min-height: 30px;
  border-color: #3d4956;
  background: #0e1115;
  color: #dce5ee;
  padding: 0 8px;
  font-size: 12px;
}

.deviceList {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.deviceItem {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) repeat(6, auto);
  align-items: center;
  gap: 8px;
  min-width: 620px;
  max-width: 840px;
}

.deviceConnect {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 52px;
  border-color: #33404d;
  background: #1b222b;
  color: #e8edf2;
  text-align: left;
}

.deviceConnect:hover {
  background: #25303b;
}

.deviceItem.isOffline {
  opacity: 0.62;
}

.deviceConnect:disabled {
  cursor: default;
}

.deviceConnect:disabled:hover {
  background: #1b222b;
}

.devicePolicy,
.deviceClaim,
.deviceLink,
.deviceQr,
.deviceAccess,
.deviceRevoke {
  min-height: 52px;
  border-color: #3d4956;
  background: #202832;
  color: #dce5ee;
  padding: 0 10px;
  font-size: 12px;
}

.deviceRevoke:disabled {
  opacity: 0.46;
}

.deviceClaim:disabled {
  opacity: 0.46;
}

.deviceLink:disabled {
  opacity: 0.46;
}

.deviceQr:disabled {
  opacity: 0.46;
}

.isBlocked .devicePolicy {
  border-color: #7a4f57;
  background: #3a2228;
}

.deviceMain {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.deviceName,
.deviceMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deviceName {
  font-size: 13px;
  font-weight: 650;
}

.deviceMeta,
.deviceEmpty {
  color: #91a0af;
  font-size: 12px;
}

.deviceCode {
  color: #9fd27d;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.isOffline .deviceCode {
  color: #748292;
}

.isBlocked .deviceCode {
  color: #e08b8b;
}

.audit {
  grid-row: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 38px;
  padding: 8px 16px;
  border-bottom: 1px solid #29313a;
  background: #101419;
}

.auditHeader {
  color: #cbd5df;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.auditList {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.auditItem,
.auditEmpty {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  white-space: nowrap;
  border: 1px solid #2d3742;
  border-radius: 6px;
  color: #aebbc8;
  background: #171d24;
  padding: 0 8px;
  font-size: 12px;
}

.sessions {
  grid-row: 4;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 38px;
  padding: 8px 16px;
  border-bottom: 1px solid #29313a;
  background: #101419;
}

.sessionsHeader {
  color: #cbd5df;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.sessionList {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.sessionItem,
.sessionEmpty {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  white-space: nowrap;
  border: 1px solid #2d3742;
  border-radius: 6px;
  color: #aebbc8;
  background: #171d24;
  padding: 0 6px 0 8px;
  font-size: 12px;
}

.sessionDisconnect {
  min-height: 22px;
  border-color: #7a4f57;
  background: #3a2228;
  color: #f1c2c2;
  padding: 0 8px;
  font-size: 12px;
}

.quality {
  grid-row: 5;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
  padding: 8px 16px;
  border-bottom: 1px solid #29313a;
  background: #11161c;
  scrollbar-width: thin;
}

.quality span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  white-space: nowrap;
  border: 1px solid #2d3742;
  border-radius: 6px;
  color: #cbd5df;
  background: #171d24;
  padding: 0 8px;
  font-size: 12px;
}

.qualityPreset {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid #2d3742;
  border-radius: 6px;
  background: #171d24;
  flex: 0 0 auto;
}

.qualityPreset button {
  min-height: 26px;
  border: 0;
  border-right: 1px solid #2d3742;
  border-radius: 0;
  background: transparent;
  color: #aebbc8;
  padding: 0 9px;
  font-size: 12px;
}

.qualityPreset button:last-child {
  border-right: 0;
}

.qualityPreset button:hover,
.qualityPreset button.isActive {
  background: #dce8f5;
  color: #111418;
}

.qualityAction {
  min-height: 26px;
  border-color: #2d3742;
  background: #202832;
  color: #dce5ee;
  padding: 0 10px;
  font-size: 12px;
  flex: 0 0 auto;
}

.qualityAction:hover {
  background: #2b3440;
}

.qualityAction:disabled {
  cursor: default;
  opacity: 0.55;
}

input,
select {
  width: 160px;
  min-height: 38px;
  border: 1px solid #3a4652;
  border-radius: 6px;
  background: #0e1115;
  color: #f7fafc;
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: #6aa9ff;
}

button {
  min-height: 38px;
  border: 1px solid #4d5a68;
  border-radius: 6px;
  background: #e9eef5;
  color: #111418;
  padding: 0 13px;
  cursor: pointer;
}

button:hover {
  background: #ffffff;
}

.devicePolicy:hover,
.deviceQr:hover,
.deviceAccess:hover,
.deviceRevoke:hover {
  background: #2b3440;
}

.isBlocked .devicePolicy:hover {
  background: #472a30;
}

.viewer {
  grid-row: 6;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  background: #050608;
  outline: none;
  touch-action: none;
}

.viewer:focus {
  box-shadow: inset 0 0 0 2px #6aa9ff;
}

#screen {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

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

#remoteVideo {
  display: none;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #050608;
}

.viewer.hasVideo #remoteVideo {
  display: block;
}

.viewer.hasVideo #screen {
  display: none;
}

.empty {
  position: absolute;
  color: #7d8996;
  font-size: 15px;
}

.controls {
  grid-row: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #29313a;
  background: #171b21;
}

.mobileRemoteBar {
  grid-row: 7;
  display: none;
  align-items: center;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #29313a;
  background: #101419;
}

.qrModal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 6, 8, 0.72);
}

.qrModal[hidden] {
  display: none;
}

.qrPanel {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  border: 1px solid #33404d;
  border-radius: 8px;
  background: #151a20;
  padding: 14px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
}

.qrHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #e8edf2;
  font-size: 14px;
  font-weight: 650;
}

#qrCloseButton {
  min-width: 34px;
  min-height: 34px;
  border-color: #394653;
  background: #202832;
  color: #e8edf2;
  padding: 0;
  font-size: 20px;
}

#qrImage {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #ffffff;
}

#qrUrlInput {
  width: 100%;
  font-size: 12px;
}

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

.qrActions button {
  min-width: 0;
}

.mobileRemoteBar button {
  min-height: 42px;
  border-color: #394653;
  background: #202832;
  color: #e8edf2;
  font-size: 18px;
}

.controls button {
  background: #2a333d;
  color: #e8edf2;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 8px;
  color: #cbd5df;
  font-size: 14px;
}

.toggle input {
  width: auto;
  min-height: auto;
}

.paste {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.paste input {
  width: min(360px, 36vw);
}

#accessKeyInput {
  width: 190px;
}

.hostShell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.hostMain {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
}

.hostPanel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border-right: 1px solid #29313a;
  background: #12161b;
}

.hostPanelHeader {
  color: #cbd5df;
  font-size: 13px;
  font-weight: 650;
}

.hostCode {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 34px;
  font-weight: 750;
  color: #9fd27d;
}

.hostLink {
  color: #7db7ff;
  font-size: 13px;
  text-decoration: none;
}

.requestList {
  display: grid;
  gap: 8px;
}

.requestItem {
  display: grid;
  gap: 8px;
  border: 1px solid #33404d;
  border-radius: 6px;
  background: #1b222b;
  padding: 10px;
}

.requestText {
  color: #dce5ee;
  font-size: 13px;
}

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

.requestActions button {
  min-height: 32px;
  background: #2a333d;
  color: #e8edf2;
}

.hostPreviewWrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  background: #050608;
  overflow: hidden;
}

#hostPreview {
  max-width: 100%;
  max-height: 100%;
  background: #050608;
}

.remotePointer {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #9fd27d;
  border-radius: 50%;
  background: rgba(159, 210, 125, 0.16);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: left 80ms linear, top 80ms linear, transform 120ms ease, background 120ms ease;
}

.remotePointer.isClicking {
  transform: translate(-50%, -50%) scale(1.8);
  background: rgba(159, 210, 125, 0.3);
}

.inputLog {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 4px;
  max-width: min(360px, 70%);
  color: #cbd5df;
  font-size: 12px;
  pointer-events: none;
}

.inputLog div {
  border: 1px solid #33404d;
  border-radius: 6px;
  background: rgba(17, 20, 24, 0.84);
  padding: 5px 8px;
}

@media (max-width: 760px) {
  .shell {
    min-height: 100dvh;
  }

  .topbar {
    display: grid;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  h1 {
    font-size: 17px;
  }

  p {
    font-size: 12px;
  }

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

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

  .account span {
    grid-column: 1 / -1;
    max-width: none;
  }

  .connect,
  .account,
  .account input,
  .account button,
  .connect input,
  .connect button,
  .devices,
  .devicesHeader,
  .devicesHeader select,
  .audit,
  .paste,
  .paste input,
  .paste button {
    width: 100%;
  }

  #accessKeyInput,
  #accountNameInput,
  .connect button {
    grid-column: 1 / -1;
  }

  input,
  button {
    min-height: 36px;
  }

  .devices {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  .devicesHeader {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .devicesHeader button {
    width: 100%;
  }

  .audit {
    display: none;
  }

  .quality {
    padding: 7px 12px;
  }

  .deviceList {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
    overflow: visible;
  }

  .deviceItem {
    min-width: 0;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }

  .devicePolicy,
  .deviceClaim,
  .deviceLink,
  .deviceQr,
  .deviceAccess,
  .deviceRevoke {
    min-height: 34px;
    width: 100%;
  }

  .controls {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    padding: 8px 10px;
    scrollbar-width: thin;
  }

  .controls button,
  .toggle,
  .paste {
    flex: 0 0 auto;
  }

  .paste {
    display: flex;
    margin-left: 0;
  }

  .paste input {
    width: min(220px, 58vw);
  }

  .mobileRemoteBar {
    display: grid;
  }

  .hostMain {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(45vh, 1fr);
  }

  .toggle,
  .paste {
    grid-column: 1 / -1;
  }
}
