* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Segoe UI, system-ui, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
}

.hidden { display: none !important; }

html[data-auto-auth="1"] #auth-screen {
  display: none !important;
}

html[data-auto-auth="1"] #viewer-screen.hidden {
  display: flex !important;
  flex-direction: column;
  height: 100vh;
}

.panel {
  max-width: 360px;
  margin: 80px auto;
  padding: 32px;
  background: #16213e;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.panel h1 { margin: 0 0 8px; font-size: 1.5rem; }
.panel p { color: #aaa; margin: 0 0 16px; }

.auth-control {
  margin-bottom: 12px;
}

.auth-control .control-label {
  display: block;
  font-size: 0.78rem;
  color: #99a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.auth-control .btn-group {
  width: 100%;
  justify-content: stretch;
}

.auth-control .btn-opt {
  flex: 1;
}

input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #334;
  border-radius: 6px;
  background: #0f0f23;
  color: #fff;
  font-size: 1rem;
  margin-bottom: 12px;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  background: #4361ee;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover:not(:disabled) { background: #3a56d4; }

.error { color: #ff6b6b; min-height: 1.2em; margin-top: 12px; }

#viewer-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 8px 12px;
  background: #16213e;
  border-bottom: 1px solid #334;
}

#viewer-screen.toolbar-hidden #toolbar {
  display: none;
}

.toolbar-restore {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 1000;
  padding: 8px 12px;
  border: 1px solid #334;
  border-radius: 6px;
  background: rgba(22, 33, 62, 0.92);
  color: #eee;
  font-size: 1rem;
  cursor: pointer;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

#viewer-screen.toolbar-hidden:not(.top-edge-hover) .toolbar-restore:not(.hidden),
#viewer-screen.toolbar-hidden:not(.top-edge-hover) .toolbar-layout-badge:not(.hidden) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.toolbar-restore:hover {
  background: #1a1a3a;
}

.toolbar-next-monitor {
  right: 52px;
  padding: 8px 10px;
  font-size: 0.95rem;
  line-height: 1;
}

#viewer-screen:not(.toolbar-hidden) .toolbar-next-monitor {
  display: none !important;
}

.toolbar-layout-badge {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  padding: 6px 10px;
  border: 1px solid #334;
  border-radius: 6px;
  background: rgba(22, 33, 62, 0.92);
  color: #eee;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

#viewer-screen:not(.toolbar-hidden) .toolbar-layout-badge {
  display: none !important;
}

.clipboard-paste-zone {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10, 10, 20, 0.82);
  color: #eee;
  text-align: center;
  padding: 24px;
}

.clipboard-paste-zone kbd {
  padding: 2px 6px;
  border: 1px solid #556;
  border-radius: 4px;
  background: #16213e;
  font-family: inherit;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.78rem;
  color: #99a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.btn-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: #0f0f23;
  border-radius: 8px;
  border: 1px solid #334;
}

.btn-opt {
  padding: 5px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #bbb;
  font-size: 0.82rem;
  line-height: 1.2;
  min-width: 2.2em;
}

.btn-opt:hover:not(:disabled):not(.active) {
  background: #1a1a3a;
  color: #eee;
}

.btn-opt.active {
  background: #4361ee;
  color: #fff;
}

.btn-opt:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tabs { display: flex; gap: 4px; margin-left: auto; }

.btn-toolbar {
  padding: 6px 10px;
  border: 1px solid #334;
  border-radius: 6px;
  background: #0f0f23;
  color: #ccc;
  font-size: 0.82rem;
  line-height: 1.2;
}

.btn-toolbar:hover:not(:disabled) {
  background: #1a1a3a;
  color: #fff;
}

.btn-toolbar:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tab {
  background: #0f0f23;
  padding: 6px 12px;
}

.tab.active { background: #4361ee; }

.status {
  font-size: 0.8rem;
  white-space: nowrap;
}

.status-ok { color: #6ee7a0; }
.status-error { color: #ff6b6b; font-weight: 600; }
.status-warn { color: #ffb347; }

.tab-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #000;
  cursor: crosshair;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

#scale-main {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

#viewport.mode-scale { cursor: default; }

#viewport.mode-scale #scale-main { cursor: crosshair; }

#magnifier {
  flex-shrink: 0;
  overflow: hidden;
  background: #0a0a12;
  border-left: 1px solid #334;
  pointer-events: none;
  user-select: none;
}

#magnifier-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#screen {
  display: block;
  image-rendering: auto;
  transform-origin: 0 0;
  position: absolute;
  top: 0;
  left: 0;
}

.webrtc-video {
  display: block;
  transform-origin: 0 0;
  position: absolute;
  top: 0;
  left: 0;
  background: #000;
  object-fit: fill;
}

#terminal-container {
  flex: 1;
  min-height: 200px;
  padding: 8px;
  background: #0c0c0c;
  display: flex;
  flex-direction: column;
}

#terminal-container .xterm {
  flex: 1;
  height: 100%;
}
