:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222c38;
  --border: #2c3744;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

html, body, #app {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; flex-shrink: 0; }
.status {
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.ok { color: var(--accent-2); }
.badges { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.on { background: rgba(34,197,94,.15); color: var(--accent-2); border-color: rgba(34,197,94,.4); }

/* 顶栏右侧用户区：与 badges 之间用分隔线区隔，避免视觉上和状态徽标混作一团 */
.user {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-left: 16px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
}
/* 名字与退出按钮之间留出更明显的间距，避免误点 */
.user .btn.ghost { margin-left: 5px; }
/* 在线小圆点独立于文本容器，避免用户名过长时被 overflow:hidden 裁掉 */
.user::before {
  content: '';
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(34,197,94,.16);
}
.user-name {
  max-width: 160px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 窄屏下优先保住用户区与徽标，隐藏次要的状态文案 */
@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 10px 12px; }
  .status { display: none; }
  .user { padding-left: 10px; }
  .user-name { max-width: 92px; }
}

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
}
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input, .select {
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--accent); }

.btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--danger); }

/* 幽灵按钮：用于顶栏等行内场景，需覆盖 .btn 的 width:100% 与实心背景 */
.btn.ghost {
  width: auto;
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.btn.ghost:hover {
  filter: none;
  color: var(--danger);
  background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.45);
}
.btn.ghost:active { background: rgba(239,68,68,.18); }
.btn.ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.section-title { font-size: 13px; font-weight: 600; margin: 18px 0 10px; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.error { color: var(--danger); font-size: 12px; margin-top: 8px; }

.device-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 11px; margin-bottom: 8px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px;
}
.device-item.active { border-color: var(--accent); }

.screen-wrap {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.remote-video {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.touch-overlay {
  position: absolute;
  inset: 0;
  touch-action: none;
}
.touch-overlay.active { cursor: crosshair; }
.placeholder {
  position: absolute;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 24px;
}
.placeholder .big { font-size: 40px; margin-bottom: 10px; }

.control-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  /* min-width:0 允许在窄容器下真正收缩，避免内容溢出盖住左侧 ConnectionPanel */
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}
.key-btn {
  /* 用 flex 基准替代固定 min-width，空间不足时可等比收缩而不是撑破容器 */
  flex: 0 1 auto;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.key-btn:hover { border-color: var(--accent); }
.key-btn:active { background: var(--accent); }

.resolution-row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* 作为 .control-bar 的 flex 子项，默认 min-width:auto 会拒绝收缩导致溢出 */
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  row-gap: 8px;
}
.resolution-label {
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.resolution-select {
  /* 允许收缩到 72px，超出部分由 text-overflow 处理，避免把整行撑破 */
  flex: 0 1 auto;
  min-width: 72px;
  max-width: 100%;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  text-overflow: ellipsis;
}
.resolution-select:focus { border-color: var(--accent); }
.resolution-select:disabled { opacity: .5; cursor: not-allowed; }
.resolution-current {
  /* 始终保留可见：空间不足时靠自身收缩+省略号，而不是整体隐藏 */
  flex: 0 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 窄屏渐进降级：所有元素保持可见，仅通过收紧间距/字号与
   文本省略来适配，必要时换行，绝不隐藏内容。 */
@media (max-width: 1100px) {
  .control-bar { gap: 6px; padding: 10px; }
  .key-btn { padding: 9px 11px; }
}
@media (max-width: 900px) {
  .key-btn { padding: 8px 10px; font-size: 12px; }
  .resolution-current { font-size: 11px; }
}
@media (max-width: 640px) {
  .control-bar { justify-content: flex-start; }
  .resolution-row { width: 100%; }
  .key-btn { flex: 1 1 auto; min-width: 64px; }
}

.footer { background: var(--panel); border-top: 1px solid var(--border); }
.stats-bar {
  display: flex;
  gap: 18px;
  padding: 10px 18px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.stats-bar b { color: var(--text); font-weight: 600; }
