* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100vh;
  overflow: hidden;
}

.screen {
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
}

/* LOGIN */
.login-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #16213e;
  padding: 40px;
  border-radius: 12px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.login-box h1 {
  text-align: center;
  color: #0f3460;
  background: linear-gradient(135deg, #e94560, #0f3460);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 28px;
  margin-bottom: 4px;
}

.subtitle {
  text-align: center;
  color: #888;
  margin-bottom: 30px;
  font-size: 14px;
}

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #aaa;
  font-size: 13px;
}

.field input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #0f0f23;
  color: #eee;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: #e94560;
}

button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #e94560, #c23152);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

button[type="submit"]:hover {
  opacity: 0.9;
}

.error {
  margin-top: 14px;
  padding: 10px;
  background: rgba(233, 69, 96, 0.2);
  border: 1px solid #e94560;
  border-radius: 6px;
  color: #e94560;
  text-align: center;
  font-size: 14px;
}

/* INFO PANEL (login footer) */
.info-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: #7e87a0;
  letter-spacing: 0.2px;
}

.info-brand {
  color: #e94560;
  font-weight: 600;
}

.info-link {
  color: #6fb1ff;
  text-decoration: none;
}

.info-link:hover {
  color: #9ccaff;
  text-decoration: underline;
}

.info-sep {
  color: #3a4566;
}

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.server-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #666;
  transition: background 0.3s;
}

.server-status.ok .dot { background: #4ad66d; }
.server-status.err .dot { background: #e94560; }

/* LAUNCHER */
.launcher-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 30px;
  background: #16213e;
  border-bottom: 1px solid #333;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #aaa;
}

.btn-small {
  padding: 6px 16px;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: #eee;
  cursor: pointer;
  font-size: 13px;
}

.btn-small:hover {
  background: #444;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  padding: 30px;
}

.app-card {
  background: #16213e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.app-card:hover {
  transform: translateY(-2px);
  border-color: #e94560;
}

.app-card .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.app-card .name {
  font-size: 15px;
  color: #ccc;
}

/* Subtitulo opcional bajo el nombre: distingue instalaciones del mismo
   sistema (distintas bases de datos). */
.app-card .subname {
  font-size: 12px;
  color: #8a94a8;
  margin-top: 3px;
}

#active-sessions {
  padding: 10px 30px 30px;
}

#active-sessions h3 {
  color: #888;
  font-size: 14px;
  margin-bottom: 10px;
}

.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #16213e;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid #333;
}

.session-item .btn-reconnect {
  padding: 4px 12px;
  background: #0f3460;
  border: none;
  border-radius: 4px;
  color: #eee;
  cursor: pointer;
  font-size: 12px;
}

.session-item .btn-close {
  padding: 4px 12px;
  background: #c23152;
  border: none;
  border-radius: 4px;
  color: #eee;
  cursor: pointer;
  font-size: 12px;
  margin-left: 6px;
}

/* VIEWER */
#viewer-screen {
  position: relative;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #16213e;
  border-bottom: 1px solid #333;
  height: 40px;
  transition: transform 0.18s ease-out;
}

/* Auto-hide: la toolbar se posiciona absoluta encima del canvas y se
   trasladea fuera de pantalla. Una zona-hover invisible la trae de vuelta. */
#viewer-screen.toolbar-autohide .viewer-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  transform: translateY(-100%);
}

#viewer-screen.toolbar-autohide.toolbar-peek .viewer-toolbar {
  transform: translateY(0);
}

/* La franja de hover de 5px quedo DESACTIVADA: disparaba el despliegue de la
   barra apenas el mouse rozaba el borde superior (molesto). Ahora la barra se
   abre solo con clic en el iconito #toolbar-reveal. Se deja el nodo por si se
   quiere reactivar, pero sin efecto. */
#toolbar-hover-zone {
  display: none;
}

/* Iconito revelador: esquina superior izquierda, chico y discreto. Visible
   SOLO en modo auto-ocultar y con la barra oculta (cuando esta desplegada
   —toolbar-peek— o fija, se esconde). Clic despliega la barra. */
#toolbar-reveal {
  display: none;
}

#viewer-screen.toolbar-autohide #toolbar-reveal {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  z-index: 18;
  border: none;
  border-radius: 4px;
  background: rgba(22, 33, 62, 0.55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s ease-out, background 0.15s ease-out;
}

#viewer-screen.toolbar-autohide #toolbar-reveal:hover {
  opacity: 0.95;
  background: rgba(22, 33, 62, 0.9);
}

/* Con la barra ya desplegada (peek), el iconito se esconde: la barra lo tapa
   y no aporta nada mientras esta visible. */
#viewer-screen.toolbar-autohide.toolbar-peek #toolbar-reveal {
  display: none;
}

#viewer-screen.toolbar-autohide #canvas-container {
  height: 100vh;
}

.transfer-info {
  font-size: 12px;
  padding: 2px 10px;
  color: #aaa;
  font-family: monospace;
}

.status-badge {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  background: #333;
}

.viewer-toolbar #viewer-status {
  margin-left: auto;
}

.status-badge.connected {
  background: #1b5e20;
  color: #81c784;
}

#canvas-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 40px);
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#viewer-canvas {
  max-width: 100%;
  max-height: 100%;
  cursor: default;
  /* Nitidez del texto cuando el canvas se muestra escalado (HiDPI con
     zoom de Windows, o el instante entre resize y el ajuste del form
     remoto). En 1:1 — el caso normal, el form se ajusta al viewport —
     no tiene ningun efecto. Sin esto el escalado bilinear ablanda el
     texto de las grillas. */
  /* OJO: viewer.js (_applyCanvasScale) pisa esto por estilo inline: deja
     'pixelated' solo a escala entera y pasa a 'auto' cuando la escala es
     fraccionaria (Windows al 125/150%), donde 'pixelated' deforma las
     letras. Este valor es el de arranque, antes del primer frame. */
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  gap: 16px;
}

.overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #333;
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* App que no se puede abrir porque se esta actualizando. Se ve apagada y
   con una etiqueta, en vez de parecer disponible y fallar al tocarla. */
.app-card.updating {
  opacity: 0.55;
  cursor: not-allowed;
  border-color: #3a3a4e;
}

.app-card.updating:hover {
  transform: none;
}

.card-badge {
  margin-top: 6px;
  font-size: 12px;
  color: #e94560;
}

.session-item button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Progreso de actualizacion de la app (overlay del viewer). Ancho fijo para
   que la barra no salte de tamaño cuando cambia el texto de abajo. */
.update-progress {
  width: 380px;
  max-width: 80vw;
  text-align: center;
  color: #eee;
  font-size: 14px;
}

.update-progress.hidden {
  display: none;
}

.up-title {
  font-weight: 600;
  margin-bottom: 10px;
}

.up-bar {
  height: 8px;
  background: #2b2b3d;
  border-radius: 4px;
  overflow: hidden;
}

.up-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #e94560, #ff7a8f);
  border-radius: 4px;
  /* La descarga avanza a los saltos; la transicion la hace ver continua. */
  transition: width 0.25s ease-out;
}

.up-detail {
  margin-top: 8px;
  color: #bbb;
  font-size: 13px;
  min-height: 18px;
}

.up-step {
  margin-top: 2px;
  color: #777;
  font-size: 12px;
  min-height: 16px;
}

/* LAUNCHER con mas contenido que alto de pantalla (muchas apps o sesiones en
   un notebook 1366x768): body tiene overflow:hidden y .screen mide 100vh, asi
   que lo que no entraba quedaba inalcanzable (las Sesiones Activas con sus
   botones Conectar/Cerrar) o tapado por el pie absoluto. La pantalla scrollea
   por si sola y el pie pasa a ser el ultimo elemento del flujo: queda abajo
   de todo cuando sobra lugar (margin-top:auto) y despues del contenido cuando
   no. El :not([hidden]) es clave — un display:flex pelado le ganaria al
   atributo hidden y el launcher se veria siempre. */
#launcher-screen:not([hidden]) {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
#launcher-screen > * {
  flex-shrink: 0;
}
#launcher-screen .info-panel {
  position: static;
  margin-top: auto;
  padding: 24px 0 18px;
}
