:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef3f8;
  --line: #d8e1ea;
  --text: #17202a;
  --muted: #667586;
  --accent: #1677ff;
  --accent-2: #1f9d63;
  --danger: #d64545;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  background: var(--accent);
  color: #fff;
  height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(25, 38, 52, .12);
  display: grid;
  gap: 22px;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

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

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

.panel-section {
  display: grid;
  gap: 10px;
}

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

.stack-form label,
.section-title {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--panel-2);
  padding: 4px;
  border-radius: 8px;
}

.seg {
  background: transparent;
  color: var(--muted);
}

.seg.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(20, 31, 43, .12);
}

input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

select:focus {
  border-color: var(--accent);
}

input[type="file"] {
  height: auto;
  min-height: 38px;
  padding: 7px 10px;
  background: #fff;
}

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

.file-transfer-log {
  display: grid;
  gap: 8px;
  max-height: 146px;
  overflow: auto;
}

.file-transfer-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #f8fafc;
  display: grid;
  gap: 3px;
}

.file-transfer-row strong {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-transfer-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.file-transfer-row.saved {
  border-color: #b9e6c9;
  background: #f0fbf4;
}

.file-transfer-row.failed {
  border-color: #f0c5c5;
  background: #fff5f5;
}

.secondary-btn {
  background: #526170;
}

.stage {
  display: grid;
  grid-template-rows: 72px 1fr;
  min-width: 0;
}

.toolbar {
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-menu {
  position: relative;
  margin-left: auto;
}

.stage-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: var(--panel-2);
}

.stage-tab {
  height: 34px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
}

.stage-tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(20, 31, 43, .12);
}

.avatar-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 999px;
  background: #17202a;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.account-dropdown {
  position: absolute;
  right: 0;
  top: 50px;
  width: 238px;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(25, 38, 52, .18);
  padding: 8px;
  display: grid;
  gap: 4px;
}

.account-summary {
  display: grid;
  gap: 3px;
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

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

.account-dropdown a,
.account-dropdown button {
  min-height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  text-align: left;
}

.account-dropdown a:hover,
.account-dropdown button:hover {
  background: #f1f6ff;
}

.account-dropdown .menu-danger {
  color: var(--danger);
}

.active-title {
  font-size: 18px;
  font-weight: 700;
}

.active-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.stage-body {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.stage-body.wall-mode {
  grid-template-rows: auto 1fr;
}

.stage-body.files-mode {
  grid-template-rows: 1fr;
}

.stage-body.files-mode .device-shelf {
  display: none;
}

.device-shelf {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 18px 22px 10px;
  min-height: 224px;
  align-items: stretch;
}

/* When opened from the main admin console with ?device=..., go straight to
   the selected controller instead of presenting a second device-selection UI.
   The admin console already owns device binding; keep the remote page's
   control/wall/file tabs available in the embedded view. */
body.direct-control .sidebar {
  display: none;
}

body.direct-control .shell {
  grid-template-columns: 1fr;
}

body.direct-control .stage-tabs {
  display: flex;
}

body.direct-control .account-menu {
  display: none;
}

body.direct-control #openAddDeviceBtn {
  display: inline-flex !important;
  margin-left: auto;
}

body.direct-control .toolbar > div:first-child { display: none; }
body.direct-control .toolbar { justify-content: flex-start; }
body.direct-control .stage-tabs { order: 0; }

/* 只嵌「远程窗口」（manage.bhzn.top 用）：设备列表 / 添加设备 / 页签 / 页头都不需要，
   管理后台那边另做了这些入口。这里只保留远程画面本身（画面右侧自带工具条）。 */
body.viewer-only .sidebar,
body.viewer-only .toolbar,
body.viewer-only .device-shelf,
body.viewer-only .stage-tabs,
body.viewer-only .account-menu,
body.viewer-only #openAddDeviceBtn {
  display: none !important;
}

body.viewer-only .shell {
  grid-template-columns: 1fr;
}

body.viewer-only .stage {
  grid-template-rows: 1fr;
}

body.viewer-only .stage-body {
  grid-template-rows: 1fr;
}

.toolbar-primary {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  background: #4f46e5;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.workspace-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.workspace-modal.hidden { display: none; }

.workspace-modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(15, 23, 42, .48);
  cursor: default;
}

.workspace-modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 72px rgba(15, 23, 42, .28);
  padding: 20px;
}

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

.workspace-modal-head strong { font-size: 16px; }
.workspace-modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.workspace-modal-card #bindPanel {
  margin: 0;
  padding: 0;
  border: 0;
  box-shadow: none;
}

.workspace-modal-card #bindPanel .section-title { display: none; }

/* Direct sessions are already authenticated by the main admin console.  Keep
   the login view from flashing while the controller validates the token. */
body.direct-control .login-view {
  display: none !important;
}

body.direct-control .stage-body {
  grid-template-rows: auto 1fr;
}

body.direct-control .screen-workspace {
  padding-top: 12px;
}

/* In the embedded workspace the three stage tabs stay at the top and the
   device shelf belongs underneath them, matching the standalone console. */

.placeholder-card {
  width: 100%;
  min-height: 96px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
}

.phone-card {
  position: relative;
  width: 206px;
  min-width: 206px;
  height: 196px;
  border-radius: 9px;
  border: 2px solid #2f7df1;
  background: #ffffff;
  color: var(--text);
  padding: 22px 12px 12px;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  align-content: start;
  gap: 7px;
  text-align: center;
  box-shadow: 0 8px 18px rgba(20, 52, 92, .08);
  overflow: hidden;
  cursor: pointer;
}

.phone-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, .13), 0 10px 22px rgba(20, 52, 92, .10);
}

.phone-card.offline {
  opacity: .72;
  border-style: dashed;
  border-color: #6e7d8e;
  background: #f8fafc;
  box-shadow: none;
}

.desktop-card {
  width: 206px;
  min-width: 206px;
  height: 196px;
  border-radius: 9px;
  padding-top: 22px;
}

.desktop-card .phone-top {
  top: 9px;
  bottom: auto;
  width: 34px;
  height: 4px;
}

.phone-top {
  position: absolute;
  top: 9px;
  left: 50%;
  width: 34px;
  height: 4px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #243344;
}

.phone-delete {
  position: absolute;
  right: 7px;
  top: 6px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #eef3f8;
  color: #7a8794;
  font-size: 16px;
  line-height: 1;
}

.phone-delete:hover {
  background: #ffe1e1;
  color: var(--danger);
}

.phone-card strong {
  font-size: 15px;
  line-height: 20px;
  min-width: 0;
  padding: 0 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-label-input {
  height: 30px;
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--text);
  background: #f8fafc;
  padding: 0 8px;
}

.phone-card small {
  color: #3f4b58;
  font-size: 12px;
  line-height: 18px;
}

.device-status {
  justify-self: center;
  min-width: 38px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef3f8;
}

.device-status.online {
  color: #14713e;
  background: #e8f6ee;
}

.device-status.offline {
  color: #7b5b24;
  background: #f2eadc;
}

.badges,
.mini-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  align-content: end;
  align-self: end;
  max-height: 58px;
  overflow: hidden;
}

.badge {
  color: #1d6b43;
  background: #e5f5ed;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  line-height: 15px;
  font-style: normal;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-badge {
  max-width: 170px;
}

.monitor-toggle {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.monitor-toggle input {
  width: 15px;
  height: 15px;
  border: 0;
  padding: 0;
  accent-color: var(--accent);
}

.badge.warn {
  color: #7b5b24;
  background: #f5ead6;
}

.screen-workspace {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 22px 28px 28px;
}

.screen-wall {
  min-height: 0;
  padding: 22px 28px 28px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.file-transfer-workspace {
  min-height: 0;
  padding: 22px 28px 28px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
}

body.direct-control .file-transfer-workspace {
  grid-template-rows: auto auto minmax(0, 1fr);
}

/* The direct admin view moves the existing upload form into the Files tab so
   file transfer remains usable after the duplicate left sidebar is removed. */
.file-transfer-workspace .direct-file-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.wall-toolbar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.file-transfer-toolbar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.wall-toolbar strong,
.wall-toolbar span,
.file-transfer-toolbar strong,
.file-transfer-toolbar span {
  display: block;
}

.wall-toolbar span,
.file-transfer-toolbar span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.file-transfer-table {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.file-transfer-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  box-shadow: 0 8px 18px rgba(20, 52, 92, .06);
}

.file-transfer-card.saved {
  border-color: #b9e6c9;
}

.file-transfer-card.failed {
  border-color: #f0c5c5;
}

.file-transfer-card.downloading {
  border-color: #b8d7ff;
}

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

.file-transfer-card-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-transfer-status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eef3f8;
  color: #526170;
  font-size: 12px;
}

.file-transfer-card.saved .file-transfer-status {
  background: #e8f6ee;
  color: #14713e;
}

.file-transfer-card.failed .file-transfer-status {
  background: #fff0f0;
  color: var(--danger);
}

.file-transfer-card.downloading .file-transfer-status {
  background: #eaf3ff;
  color: #1f65d6;
}

.file-transfer-fields {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
}

.file-transfer-fields span {
  color: var(--muted);
}

.file-transfer-fields b {
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.file-transfer-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  min-height: 220px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.file-transfer-empty strong {
  color: var(--text);
}

.screen-wall-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: flex-start;
  gap: 16px;
  min-height: 0;
  overflow: auto;
}

.wall-tile {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 300px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
  box-shadow: 0 10px 28px rgba(20, 52, 92, .08);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.wall-tile:fullscreen {
  border-radius: 0;
  border: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #0b1118;
}

.wall-tile:fullscreen header {
  background: #ffffff;
}

.wall-tile:fullscreen .wall-screen {
  aspect-ratio: auto;
  min-height: 0;
}

.wall-tile.offline {
  opacity: .68;
}

.wall-tile header {
  padding: 10px 56px 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.wall-tile header > div {
  min-width: 0;
}

.wall-tile header strong,
.wall-tile header span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wall-tile header span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.wall-fullscreen-icon {
  position: relative;
  z-index: 6;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  flex: 0 0 auto;
  border-radius: 6px;
  background: #eef5ff;
  color: #1f65d6;
  font-size: 16px;
  line-height: 1;
}

.wall-screen {
  position: relative;
  min-height: 0;
  background: #111820;
  overflow: hidden;
}

.wall-screen canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.wall-screen-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #dce7f3;
  font-size: 13px;
}

.wall-screen.has-frame .wall-screen-empty {
  display: none;
}

.wall-tile-resize {
  position: absolute;
  width: 44px;
  height: 44px;
  z-index: 8;
  pointer-events: auto;
  touch-action: none;
}

.wall-tile-resize::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(72, 103, 138, .42);
  opacity: .72;
  transition: border-color .16s ease, opacity .16s ease, transform .16s ease;
}

.wall-tile-resize:hover::after,
.wall-tile-resize.resizing::after {
  border-color: rgba(22, 119, 255, .92);
  opacity: 1;
  transform: scale(1.08);
}

.wall-tile-resize-nw {
  left: 0;
  top: 0;
  cursor: nwse-resize;
}

.wall-tile-resize-nw::after {
  left: 9px;
  top: 9px;
  border-right: 0;
  border-bottom: 0;
}

.wall-tile-resize-ne {
  right: 0;
  top: 0;
  cursor: nesw-resize;
}

.wall-tile-resize-ne::after {
  right: 9px;
  top: 9px;
  border-left: 0;
  border-bottom: 0;
}

.wall-tile-resize-sw {
  left: 0;
  bottom: 0;
  cursor: nesw-resize;
}

.wall-tile-resize-sw::after {
  left: 9px;
  bottom: 9px;
  border-right: 0;
  border-top: 0;
}

.wall-tile-resize-se {
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
}

.wall-tile-resize-se::after {
  right: 9px;
  bottom: 9px;
  border-left: 0;
  border-top: 0;
}

.wall-tile:fullscreen .wall-tile-resize {
  display: none;
}

.wall-control-window {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 30;
  width: min(560px, calc(100vw - 56px));
  height: min(760px, calc(100vh - 112px));
  min-width: 360px;
  min-height: 460px;
  max-width: calc(100vw - 28px);
  max-height: calc(100vh - 28px);
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #bfcede;
  border-radius: 8px;
  box-shadow: 0 26px 76px rgba(17, 31, 45, .26);
  display: grid;
  grid-template-rows: auto 1fr;
  user-select: none;
}

.wall-control-window:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
}

.wall-resize-handle {
  position: absolute;
  width: 44px;
  height: 44px;
  z-index: 12;
  pointer-events: auto;
  touch-action: none;
}

.wall-resize-handle::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(72, 103, 138, .42);
  opacity: .72;
  transition: border-color .16s ease, opacity .16s ease, transform .16s ease;
}

.wall-resize-handle:hover::after,
.wall-resize-handle.resizing::after {
  border-color: rgba(22, 119, 255, .92);
  opacity: 1;
  transform: scale(1.08);
}

.wall-resize-nw {
  left: 0;
  top: 0;
  cursor: nwse-resize;
}

.wall-resize-nw::after {
  left: 9px;
  top: 9px;
  border-right: 0;
  border-bottom: 0;
}

.wall-resize-ne {
  right: 0;
  top: 0;
  cursor: nesw-resize;
}

.wall-resize-ne::after {
  right: 9px;
  top: 9px;
  border-left: 0;
  border-bottom: 0;
}

.wall-resize-sw {
  left: 0;
  bottom: 0;
  cursor: nesw-resize;
}

.wall-resize-sw::after {
  left: 9px;
  bottom: 9px;
  border-right: 0;
  border-top: 0;
}

.wall-resize-se {
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
}

.wall-resize-se::after {
  right: 9px;
  bottom: 9px;
  border-left: 0;
  border-top: 0;
}

.wall-control-window:fullscreen .wall-resize-handle {
  display: none;
}

body.wall-resizing {
  cursor: inherit;
  user-select: none;
}

.wall-control-titlebar {
  min-height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8fbfe;
}

.wall-control-titlebar strong,
.wall-control-titlebar span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wall-control-titlebar span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.wall-control-title-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.wall-control-title-actions button {
  height: 32px;
  padding: 0 12px;
}

.wall-control-title-actions #wallControlCloseBtn {
  background: #526170;
}

.wall-control-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  padding: 10px;
}

.wall-control-viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #101820;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.wall-control-viewer canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.wall-control-viewer canvas:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.wall-control-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #dce7f3;
  font-size: 13px;
  pointer-events: none;
}

.wall-control-viewer.has-frame .wall-control-empty {
  display: none;
}

.wall-control-actions {
  width: 112px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.wall-control-actions button {
  width: 100%;
}

.wall-control-actions #wallControlBackBtn,
.wall-control-actions #wallControlHomeBtn,
.wall-control-actions #wallControlHomeSwipeBtn {
  background: #26384d;
}

.screen-wall-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  min-height: 220px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.screen-wall-empty strong {
  color: var(--text);
}

.screen-placeholder {
  width: min(620px, 100%);
  min-height: 220px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  border-radius: 8px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
}

.screen-placeholder strong {
  color: var(--text);
  font-size: 18px;
}

.viewer-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 0;
}

.viewer-wrap:fullscreen {
  background: #0b1118;
  padding: 20px;
}

.viewer-wrap:fullscreen .viewer {
  height: min(94vh, 94vw);
  max-height: 94vh;
}

.viewer-wrap:fullscreen .viewer.desktop-viewer {
  width: min(86vw, 1500px);
}

.viewer-wrap.closed {
  display: none;
}

.viewer {
  position: relative;
  height: min(72vh, 760px);
  aspect-ratio: 9 / 18.5;
  background: #111820;
  border-radius: 8px;
  border: 1px solid #0a0f14;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(25, 38, 52, .24);
}

.viewer.desktop-viewer {
  width: min(78vw, 1180px);
  height: auto;
  max-height: 72vh;
  aspect-ratio: 16 / 9;
}

.viewer.phone-viewer {
  width: auto;
  height: min(72vh, 760px);
  aspect-ratio: 9 / 18.5;
}

.screen-actions {
  width: 172px;
  display: grid;
  gap: 8px;
  align-self: center;
}

.screen-actions button,
.screen-actions select {
  width: 100%;
}

.screen-actions select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.screen-actions #backBtn,
.screen-actions #homeBtn,
.screen-actions #homeSwipeBtn {
  background: #26384d;
}

#stopBtn {
  background: var(--danger);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.rtc-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #111820;
}

.viewer.rtc-active .rtc-video,
.viewer.rtc-active #screenCanvas {
  position: absolute;
  inset: 0;
}

.viewer.rtc-video-active #screenCanvas {
  opacity: 0;
  z-index: 2;
}

.remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 14px;
  height: 14px;
  border: 2px solid #39ff88;
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
  transform: translate(-999px, -999px);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .35);
}

.remote-cursor::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 2px;
  height: 2px;
  background: #39ff88;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: #dce7f3;
  padding: 24px;
}

.empty-state span {
  color: #9fb0c2;
  line-height: 1.5;
}

.viewer.has-frame .empty-state {
  display: none;
}

.cms-shell {
  min-height: 100vh;
  padding: 24px;
}

.cms-header {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.admin-form {
  width: min(440px, 100%);
  display: flex;
  gap: 8px;
}

.cms-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.cms-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.cms-panel-wide {
  grid-column: 1 / -1;
}

.panel-title {
  font-weight: 700;
  margin-bottom: 12px;
}

.table-list {
  display: grid;
  gap: 10px;
}

.table-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.table-row strong,
.table-row span {
  display: block;
}

.table-row span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.link-row {
  align-items: flex-start;
}

.link-fields {
  min-width: min(520px, 100%);
  display: grid;
  gap: 5px;
  justify-items: end;
  text-align: right;
}

.link-fields b,
.link-fields span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.account-connection-row {
  display: grid;
  gap: 12px;
  align-items: stretch;
}

.account-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.account-summary > div:first-child {
  min-width: 180px;
}

.account-devices {
  display: grid;
  gap: 8px;
}

.account-device-line {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(260px, 1.2fr);
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.account-device-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.placeholder-card.compact {
  min-height: auto;
  padding: 10px 12px;
}

.badge.good {
  color: #126339;
  background: #ddf7e8;
}

.badge.danger {
  color: #8e2a2a;
  background: #ffe2e2;
}

.danger-small {
  background: var(--danger);
}

@media (max-width: 900px) {
  .shell,
  .cms-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    grid-template-rows: auto 1fr;
  }

  .toolbar,
  .cms-header,
  .table-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-summary,
  .account-device-line {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .account-device-meta {
    justify-content: flex-start;
  }

  .actions,
  .admin-form {
    width: 100%;
  }

  .viewer-wrap {
    flex-direction: column;
  }

  .screen-actions {
    width: min(360px, 100%);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .viewer {
    height: min(68vh, 680px);
  }
}
