/* Academia Naval · compatibilidad iPhone/iPad · V48.63 */
:root{--academia-visual-height:100dvh;--academia-visual-width:100vw;--academia-visual-top:0px;--academia-visual-left:0px;color-scheme:light}
html[data-theme="dark"],body.dark{color-scheme:dark}
html.academia-ios{-webkit-text-size-adjust:100%;text-size-adjust:100%;-webkit-font-smoothing:antialiased}
html.academia-ios body{min-height:100svh;min-height:100dvh}
html.academia-ios button,html.academia-ios a,html.academia-ios [role="button"],html.academia-ios input,html.academia-ios textarea,html.academia-ios select{touch-action:manipulation}
@media(max-width:767px){
  html.academia-ios input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),html.academia-ios textarea,html.academia-ios select{font-size:16px!important}
  html.academia-ios .social-icon-action,html.academia-ios .social-attach-btn,html.academia-ios .social-voice-btn,html.academia-ios .social-inner-back{min-width:44px!important;min-height:44px!important}
  html.academia-ios .social-message-actions button{min-height:36px!important}
}
html.academia-ios #socialPanel{height:100svh;height:100dvh;max-height:100dvh;overscroll-behavior:none}
html.academia-ios .social-messages,html.academia-ios .social-message-search-results,html.academia-ios .social-notification-pending-list{-webkit-overflow-scrolling:touch;overscroll-behavior-y:contain}
html.academia-ios.academia-keyboard-open #socialPanel{top:var(--academia-visual-top)!important;bottom:auto!important;height:var(--academia-visual-height)!important;max-height:var(--academia-visual-height)!important;padding-bottom:0!important}
html.academia-ios.academia-keyboard-open .social-composer,html.academia-ios.academia-keyboard-open .social-section-composer{padding-bottom:8px!important}
html.academia-ios.academia-keyboard-open .social-primary-action{display:none!important}
html.academia-ios.academia-keyboard-open body{overscroll-behavior-y:none}
html.academia-ios .social-message-photo{-webkit-touch-callout:none}
html.academia-ios .social-message-photo img{-webkit-user-drag:none}
/* Los paneles a pantalla completa respetan la altura visual real al abrir teclado. */
html.academia-ios.academia-keyboard-open #perfilPanel,html.academia-ios.academia-keyboard-open #audiolibrosPanel,html.academia-ios.academia-keyboard-open #especialidadPanel,html.academia-ios.academia-keyboard-open #asistenteNavalPanel,html.academia-ios.academia-keyboard-open #quiz,html.academia-ios.academia-keyboard-open #mejorarPanel{max-height:var(--academia-visual-height)!important;scroll-padding-bottom:24px}
/* Evita que barras inferiores queden bajo el indicador Home. */
html.academia-ios .quiz-switcher,html.academia-ios .modo-guardia-panel{padding-bottom:max(8px,env(safe-area-inset-bottom))}

/* V48.63 · seguridad de layout global: evita elementos encimados entre módulos. */
:root{
  --academia-social-composer-height:0px;
  --academia-ai-composer-height:0px;
  --academia-bottom-composer-height:0px;
  --academia-audio-mini-height:0px;
}
html,body{max-width:100%;overflow-x:hidden}
:where(img,picture,video,canvas,svg,iframe){max-width:100%}
:where(
  .top,.barra-rapida,.acciones-duo,.accion-ruta,.tema-ruta,
  .social-head,.social-chat-head,.social-section-head,.social-list-head,.social-notification-panel-head,
  .social-search-row,.social-conversation-row,.social-section-row,.social-composer-row,.social-section-composer-row,
  .ai-naval-head,.ai-naval-head-actions,.ai-naval-controls,
  .audiolibros-head,.audiolibros-toolbar,.audiolibros-now,.audiolibros-referencia-head,.audiolibros-referencia-acciones,
  .perfil-identidad,.perfil-metrica,.selector-colores-head,.selector-colores-pie,
  .especificos-biblioteca-modal-head,.especificos-biblioteca-modal-pie
)>*{min-width:0}
:where(
  h1,h2,h3,h4,p,small,b,strong,span,
  .accion-ruta-info,.tema-ruta-info,.social-title,.social-chat-contact,.social-section-heading,
  .social-notification-panel-head>div,.ai-naval-title,.audiolibros-toolbar-copy,.audiolibros-head-copy,
  .perfil-identidad-principal,.especificos-biblioteca-modal-titulo
){max-width:100%;overflow-wrap:anywhere}

/* Los paneles y modales nunca deben crecer fuera del viewport visual. */
:where(
  #quiz,#pdfPanel,#especificosTomosPanel,#marinerosPanel,#doctrinaPanel,#legislacionPanel,#culturaPanel,
  #perfilPanel,#simulacroPanel,#tomosPanel,#retosPanel,#especialidadPanel,#socialPanel,#asistenteNavalPanel,#audiolibrosPanel
){max-width:100vw}
:where(
  #pay>div,#resultado>div,#mejorarPanel>div,#modalAreaProf>div,
  .perfil-modal-card,.selector-colores-card,.especificos-biblioteca-modal-card,.legal-viewer-card
){max-height:calc(var(--academia-visual-height,100dvh) - max(24px,env(safe-area-inset-top)) - max(24px,env(safe-area-inset-bottom)));overscroll-behavior:contain}

/* Chat: el contenido deja exactamente el espacio que ocupa el compositor fijo,
   incluso cuando aparecen respuesta, adjunto o grabación de voz. */
#socialPanel.social-chat-open .social-messages{
  padding-bottom:calc(var(--academia-social-composer-height) + 18px)!important;
  scroll-padding-bottom:calc(var(--academia-social-composer-height) + 18px)!important;
}
.social-composer,.social-composer-row,.social-section-composer,.social-section-composer-row{max-width:100%}
.social-compose-preview>span,.social-voice-recording>div{min-width:0}
.social-compose-preview b,.social-compose-preview small,.social-voice-recording b,.social-voice-recording small{overflow-wrap:anywhere}
.social-message-actions,.social-section-message .social-message-actions{flex-wrap:wrap!important;max-width:100%}
.social-message.selected .social-message-actions,.social-section-message.selected .social-message-actions,.social-message:focus-within .social-message-actions{
  max-height:96px!important;
}

/* Asistente: el historial no termina debajo del compositor fijo. */
.ai-naval-main{
  padding-bottom:calc(var(--academia-ai-composer-height) + 24px)!important;
  scroll-padding-bottom:calc(var(--academia-ai-composer-height) + 24px)!important;
}
.ai-naval-composer{max-width:calc(100vw - 20px)}

/* Audiolibros + otros controles inferiores: se apilan en vez de ocupar la misma zona. */
html.academia-bottom-composer-visible #audiolibroMiniPlayer:not([hidden]){
  bottom:calc(max(10px,env(safe-area-inset-bottom)) + var(--academia-bottom-composer-height) + 10px)!important;
}
html.academia-audio-mini-visible .social-primary-action{
  bottom:calc(max(22px,calc(env(safe-area-inset-bottom) + 18px)) + var(--academia-audio-mini-height) + 10px)!important;
}
html.academia-audio-mini-visible .ai-menu-fab{
  bottom:calc(max(88px,calc(env(safe-area-inset-bottom) + 80px)) + var(--academia-audio-mini-height) + 10px)!important;
}

@media(max-width:640px){
  :where(.social-message,.social-section-message,.ai-naval-message){max-width:calc(100vw - 38px)}
  .social-message-actions button{max-width:100%;white-space:normal!important}
  .social-action-label{white-space:normal!important;line-height:1.15}
  .social-voice-note{max-width:100%;min-width:0!important;width:min(100%,290px)}
  .social-voice-track{grid-template-columns:minmax(0,1fr) auto}
  .audiolibro-mini{max-width:calc(100vw - 16px)}
}
@media(max-width:380px){
  .social-voice-recording{grid-template-columns:9px minmax(0,1fr) auto!important;align-items:center}
  .social-voice-recording button{min-width:0!important}
  .social-voice-recording button.cancel{grid-column:2;justify-self:start}
  .social-voice-recording button:last-child{grid-column:3;grid-row:1 / span 2}
  .selector-colores-grid{grid-template-columns:repeat(4,minmax(44px,1fr))!important}
}

/* El mini reproductor estaba anclado en left:50% sin compensar su propio ancho. */
#audiolibroMiniPlayer.audiolibro-mini{
  left:50%!important;
  transform:translateX(-50%)!important;
  width:min(calc(100vw - 20px),520px)!important;
  max-width:calc(100vw - 20px)!important;
  box-sizing:border-box!important;
}
