/* HRAI Dashboard - Remote Desktop */

.desktop-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.desktop-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.desktop-controls .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.875rem;
  transition: opacity 0.2s;
}

.desktop-controls .btn:hover {
  opacity: 0.9;
}

.desktop-controls .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.desktop-controls .btn-primary {
  background: var(--accent);
  color: #000;
}

.desktop-controls .btn-danger {
  background: var(--danger);
  color: #fff;
}

.desktop-controls .btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.desktop-controls .btn-warning {
  background: transparent;
  color: var(--text-muted);
  padding: 0.5rem;
}

.desktop-controls .btn-warning:hover {
  color: var(--danger);
}

.desktop-controls .desktop-controls-end {
  margin-left: auto;
}

.desktop-scale-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.btn-icon {
  font-size: 1rem;
}

.desktop-status {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.desktop-status-connecting {
  color: #d29922;
}

.desktop-status-connected {
  color: #3fb950;
}

.desktop-status-disconnected {
  color: var(--text-muted);
}

.desktop-status-error {
  color: #f85149;
}

.desktop-main {
  position: relative;
  flex: 1;
  min-height: 400px;
  display: block;
}

/* Область видео занимает весь контейнер — пропорции сохраняются (object-fit: contain) */
.desktop-video-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 400px;
  background: #0a0a0a;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Fullscreen mode: клики и скролл должны попадать в canvas/video, а не в контейнер */
.desktop-video-wrapper:fullscreen {
  background: #000;
  border-radius: 0;
  border: none;
  pointer-events: none;
}

.desktop-video-wrapper:fullscreen video,
.desktop-video-wrapper:fullscreen #desktop-canvas {
  pointer-events: auto;
}

.desktop-video-wrapper:fullscreen video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* HRCodec: canvas заполняет контейнер так же, как video */
#desktop-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Video overlay with fullscreen button */
.desktop-overlay {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.5rem;
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}

.desktop-video-wrapper:hover .desktop-overlay {
  opacity: 1;
}

.overlay-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.overlay-btn:hover {
  background: rgba(0, 0, 0, 0.9);
}

/* Hide overlay in fullscreen - button not needed */
.desktop-video-wrapper:fullscreen .desktop-overlay {
  display: none;
}

/* Play overlay for autoplay blocked */
.play-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 20;
  cursor: pointer;
}

.play-overlay-btn {
  padding: 1rem 2rem;
  background: var(--accent);
  color: #000;
  font-size: 1.25rem;
  font-weight: 600;
  border-radius: 8px;
  transition: transform 0.2s;
}

.play-overlay:hover .play-overlay-btn {
  transform: scale(1.05);
}

#desktop-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: none;
}

.desktop-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

.placeholder-icon {
  font-size: 4rem;
  opacity: 0.5;
}

.placeholder-text {
  font-size: 0.9rem;
  max-width: 300px;
}

/* Fullscreen support */
.desktop-video-wrapper:fullscreen {
  background: #000;
  border-radius: 0;
}

.desktop-video-wrapper:fullscreen #desktop-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (max-width: 768px) {
  .desktop-controls {
    flex-wrap: wrap;
  }
  
  .desktop-video-wrapper {
    min-height: 300px;
  }
}

/* === Cursor Overlay ===
 * Курсор передаётся метаданными (~6 байт) и рисуется CSS div поверх canvas/video.
 * Это даёт <5ms latency вместо 33ms (1 frame) при пиксельном кодировании.
 */
.cursor-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.cursor-sprite {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  will-change: transform;
}

/* Стандартная стрелка (Windows arrow cursor) */
.cursor-arrow {
  width: 12px;
  height: 19px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='19' viewBox='0 0 12 19'%3E%3Cpath fill='%23fff' stroke='%23000' stroke-width='1' d='M1 1l10 8.5-4.5.5 2 5.5-2.5 1-2-5.5-3 3z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* Рука/pointer (для ссылок) */
.cursor-hand {
  width: 16px;
  height: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='20' viewBox='0 0 16 20'%3E%3Cpath fill='%23fff' stroke='%23000' stroke-width='1' d='M6 6V2a1 1 0 012 0v4h2V3a1 1 0 012 0v3h2V5a1 1 0 012 0v9c0 3-2 5-5 5H8c-3 0-5-2-5-5V9a1 1 0 012 0v-1a1 1 0 012 0v-2h-1z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* I-beam (для текста) */
.cursor-ibeam {
  width: 8px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='18' viewBox='0 0 8 18'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M1 1h6M4 1v16M1 17h6'/%3E%3Cpath fill='none' stroke='%23fff' stroke-width='1' d='M1 1h6M4 1v16M1 17h6'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* Ожидание/загрузка */
.cursor-wait {
  width: 22px;
  height: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'%3E%3Ccircle cx='11' cy='11' r='9' fill='%23fff' stroke='%23000' stroke-width='1'/%3E%3Ccircle cx='11' cy='11' r='6' fill='none' stroke='%23000' stroke-width='1'/%3E%3Cpath fill='%23000' d='M11 5v6l4 2' stroke='%23000' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* --- Кнопка Отладка в тулбаре --- */
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--surface-hover, rgba(255,255,255,0.05)); }
.btn-outline.btn-active {
  background: var(--primary, #4a9eff);
  color: #fff;
  border-color: var(--primary, #4a9eff);
}

/* --- Debug overlay поверх видео --- */
.desktop-debug-overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.85);
  color: #e0e0e0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  overflow: hidden;
}
.desktop-debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.desktop-debug-header > div {
  display: flex;
  gap: 6px;
}
.desktop-debug-btn {
  padding: 4px 10px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
}
.desktop-debug-btn:hover { background: rgba(255,255,255,0.2); }
.desktop-debug-text {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
  color: #c8ffc8;
}

/* Скрываем нативный курсор поверх canvas/video когда overlay активен */
.desktop-video-wrapper:has(.cursor-overlay[style*="display: block"]) #desktop-canvas,
.desktop-video-wrapper:has(.cursor-overlay[style*="display: block"]) #desktop-video {
  cursor: none;
}

/* === Нижняя панель: макросы + экранная клавиатура === */
.rd-toolbar-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.5rem;
}

.rd-macros {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rd-macros-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.rd-macro-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.rd-macro-btn:hover {
  background: var(--border);
}

.rd-osk {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.rd-osk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rd-osk-toggle {
  padding: 0.2rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
}

.rd-osk-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.rd-osk-body {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rd-osk-row {
  display: flex;
  justify-content: center;
  gap: 2px;
  flex-wrap: nowrap;
}

.rd-osk-key {
  min-width: 28px;
  height: 28px;
  padding: 0 4px;
  font-size: 0.7rem;
  font-family: inherit;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.rd-osk-key:hover {
  background: var(--border);
}

.rd-osk-key:active {
  transform: scale(0.97);
}
