/* ==========================================================================
   RemoteDesk 控制端樣式
   ========================================================================== */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2a3240;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --accent: #2f81f7;
  --accent-hover: #4a93ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC",
    "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

/* ---------------------------------------------------------------- 檢視切換 */

.view {
  display: none;
  width: 100%;
  height: 100%;
}

.view.active {
  display: block;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------- 登入畫面 */

#loginView.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #17202e 0%, #0d1117 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 12px;
  background: rgba(47, 129, 247, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
  text-align: center;
  letter-spacing: 2px;
  font-weight: 600;
}

.subtitle {
  margin: 8px 0 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.login-card label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  background: #0b0f16;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  letter-spacing: 3px;
  font-family: "Consolas", "Menlo", monospace;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.18);
}

.login-card input::placeholder {
  color: #4a5567;
  letter-spacing: 1px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- 按鈕 */

.btn-primary {
  width: 100%;
  margin-top: 22px;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------------------------------------------------------------- 狀態與錯誤 */

.status-line {
  margin-top: 16px;
  min-height: 20px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.status-line.loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid rgba(47, 129, 247, 0.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-box {
  margin-top: 12px;
  padding: 0;
  font-size: 13px;
  color: var(--red);
  text-align: center;
  border-radius: 8px;
  line-height: 1.5;
}

.error-box:not(:empty) {
  padding: 10px 12px;
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.32);
}

.login-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: #5c687a;
}

/* ---------------------------------------------------------------- 遠端畫面 */

#controlView.active {
  display: block;
}

.screen-wrap {
  position: absolute;
  inset: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  touch-action: none;
  cursor: default;
}

#screen {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #000;
  image-rendering: auto;
  touch-action: none;
}

.waiting {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 1px;
}

/* 遠端游標指示點（本機滑鼠位置提示，被控端畫面不含游標） */
.pointer {
  position: fixed;
  left: 0;
  top: 0;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65), 0 0 8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 45;
}

.pointer::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 2px;
  margin: -1px 0 0 -1px;
  border-radius: 50%;
  background: #4cc2ff;
}

/* ---------------------------------------------------------------- 浮動狀態列 */

.status-pill {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
  z-index: 30;
  user-select: none;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.8);
}

.status-pill .dot.warn {
  background: var(--amber);
  box-shadow: 0 0 6px rgba(210, 153, 34, 0.8);
}

.status-pill .dot.bad {
  background: var(--red);
  box-shadow: 0 0 6px rgba(248, 81, 73, 0.8);
}

.status-pill .sep {
  width: 1px;
  height: 11px;
  background: var(--border);
}

#statusText {
  color: var(--text);
}

/* ---------------------------------------------------------------- 工具列 */

.toolbar {
  position: fixed;
  top: 58px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 40;
  opacity: 0.35;
  transition: opacity 0.2s;
}

.toolbar:hover,
.toolbar:focus-within {
  opacity: 1;
}

.tool-group {
  display: flex;
  flex-direction: row;
  gap: 4px;
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.tool {
  min-width: 74px;
  padding: 8px 12px;
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.tool:hover {
  background: var(--panel-2);
  border-color: var(--accent);
}

.tool-group .tool {
  min-width: 40px;
  padding: 6px 10px;
  border: 1px solid transparent;
  background: transparent;
  backdrop-filter: none;
}

.tool-group .tool:hover {
  background: rgba(47, 129, 247, 0.14);
}

.tool-group .tool.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#btnDisconnect:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ---------------------------------------------------------------- 虛擬按鍵 */

.virtual-keys {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px 12px;
  background: rgba(13, 17, 23, 0.92);
  border-top: 1px solid var(--border);
  z-index: 50;
  backdrop-filter: blur(10px);
}

.vkey {
  flex: 1 1 62px;
  min-height: 44px;
  padding: 8px 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.vkey:active {
  background: var(--accent);
  border-color: var(--accent);
}

.vkey.toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------------------------------------------------------------- 提示訊息 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 18px;
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 82vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------------- 觸控裝置適配 */

@media (hover: none) and (pointer: coarse) {
  .virtual-keys {
    display: flex;
  }

  .screen-wrap {
    bottom: 118px;
  }

  .toolbar {
    opacity: 1;
    top: 52px;
  }

  .tool {
    min-width: 60px;
    padding: 9px 10px;
  }

  .status-pill {
    top: 10px;
    right: 10px;
    font-size: 11px;
    padding: 6px 10px;
  }
}

@media (min-width: 820px) {
  .mobile-only {
    display: none;
  }
}

/* 全螢幕時的簡化介面 */
:fullscreen .toolbar {
  opacity: 0.3;
}

:fullscreen .toolbar:hover {
  opacity: 1;
}


/* ---------------------------------------------------------------- 角色權限（多控制端） */

/* 僅觀看標記 */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 196, 0, 0.16);
  border: 1px solid rgba(255, 196, 0, 0.5);
  color: #ffc400;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
}

/* 僅觀看模式下隱藏所有會改變被控端狀態的操作項 */
body.view-only .quality,
body.view-only #btnKeyboard,
body.view-only .virtual-keys {
  display: none !important;
}

/* 僅觀看模式：游標提示不顯示，畫面區域不顯示可點擊感 */
body.view-only #pointer {
  display: none !important;
}

body.view-only .screen-wrap {
  cursor: default;
}
