/* ============================================================
   mobile-frame.css
   Fuerza el formato móvil en pantallas grandes (PC / tablet).
   En móvil (< 768px) no cambia absolutamente nada.

   Cómo funciona:
   - El <body> se limita a un ancho tipo teléfono y se centra.
   - `transform: translateZ(0)` en el body lo convierte en el bloque
     contenedor de los elementos `position: fixed`, así los headers,
     barras inferiores y modales quedan dentro del "teléfono" y no
     se escapan al ancho completo de la pantalla.
   - El scroll pasa del body a #kp-viewport (lo crea pwa.js), para que
     los elementos fijos sigan fijos dentro del marco.
   ============================================================ */

:root {
  --kp-frame-width: 430px;
}

/* Barra de instalación / botón flotante (todas las pantallas) */
#kpInstallBanner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  border: 1px solid #E3F2FD;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  transform: translateY(160%);
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
  pointer-events: none;
}

#kpInstallBanner.kp-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

#kpInstallBanner .kp-install-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
  object-fit: cover;
}

#kpInstallBanner .kp-install-texts {
  flex: 1;
  min-width: 0;
}

#kpInstallBanner .kp-install-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #0D47A1;
  line-height: 1.2;
}

#kpInstallBanner .kp-install-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: #607D8B;
  line-height: 1.3;
}

#kpInstallBanner .kp-install-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#kpInstallBanner button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-weight: 700;
}

#kpInstallBanner .kp-install-btn {
  background: #1565C0;
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
}

#kpInstallBanner .kp-install-btn:hover {
  background: #0D47A1;
}

#kpInstallBanner .kp-dismiss-btn {
  background: transparent;
  color: #90A4AE;
  font-size: 18px;
  line-height: 1;
  padding: 6px 8px;
}

/* Instrucciones manuales (iOS / navegadores sin prompt nativo) */
#kpInstallHelp {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#kpInstallHelp.kp-visible {
  display: flex;
}

#kpInstallHelp .kp-help-card {
  background: #fff;
  border-radius: 18px;
  padding: 22px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

#kpInstallHelp h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #0D47A1;
}

#kpInstallHelp ol {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: 13px;
  color: #455A64;
  line-height: 1.7;
}

#kpInstallHelp .kp-help-close {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: #1565C0;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  cursor: pointer;
  font-family: inherit;
}

/* ============================================================
   MARCO MÓVIL EN PANTALLAS GRANDES
   ============================================================ */
@media (min-width: 768px) {
  html {
    height: 100%;
    background: #0B1B2B;
  }

  body {
    width: var(--kp-frame-width);
    max-width: var(--kp-frame-width);
    min-width: 0;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    margin: 0 auto !important;
    overflow: hidden !important;
    position: relative;
    /* Convierte al body en contenedor de los elementos fixed */
    transform: translateZ(0);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 24px 60px rgba(0, 0, 0, 0.55);
  }

  /* Contenedor de scroll creado por pwa.js */
  #kp-viewport {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #kp-viewport::-webkit-scrollbar {
    width: 0;
  }

  /* El body de index/login usa flex para centrar: se respeta */
  body.kp-flex-body > #kp-viewport {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  /* Nada debe exceder el ancho del marco */
  #kp-viewport img,
  #kp-viewport video,
  #kp-viewport canvas {
    max-width: 100%;
  }

  /* Anchos basados en el viewport rompen el marco */
  .webrtc-camera-overlay,
  .attachment-modal-overlay {
    width: 100% !important;
    max-width: 100% !important;
  }
}
