/* ========================================================================
   Iglesia Ríos de Agua Viva · Hotfix móvil/app V12.2
   Alcance deliberado: interfaz pública de 0 a 720 px.
   Escritorio, administrador, API, base de datos y contenido quedan intactos.
   ======================================================================== */

@media (max-width: 720px) {
  html {
    scroll-padding-top: 112px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    overflow-x: clip;
  }

  .container {
    width: min(calc(100% - 28px), var(--max));
  }

  /* Barra superior compacta y estable */
  .topbar {
    padding-top: env(safe-area-inset-top, 0px);
    font-size: .78rem;
  }

  .topbar .container {
    min-height: 38px;
    justify-content: flex-start;
    gap: 0;
  }

  .topbar .container > span:first-child {
    display: block;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .container > span:nth-child(n + 2),
  .topbar .top-socials {
    display: none !important;
  }

  /* Encabezado móvil propio: marca flexible + dos acciones táctiles */
  .site-header {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  .header-inner {
    height: auto !important;
    min-height: 74px;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding-block: 8px;
  }

  .brand {
    min-width: 0;
    display: flex;
    align-items: center;
  }

  .site-header .brand img {
    width: clamp(146px, 44vw, 178px) !important;
    height: auto !important;
    max-height: 58px;
    object-fit: contain;
    object-position: left center;
  }

  .header-actions {
    min-width: max-content;
    gap: 8px;
  }

  .header-actions > .lang-switch,
  .header-actions > .compact {
    display: none !important;
  }

  .theme-switch,
  .menu-btn {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px;
    min-height: 46px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    font-size: 1.08rem;
    touch-action: manipulation;
  }

  .menu-btn {
    font-size: 1.22rem;
  }

  /* Menú lateral con áreas seguras de iPhone/PWA */
  .mobile-panel {
    width: min(390px, 100vw);
    max-width: 100%;
    padding:
      max(22px, env(safe-area-inset-top, 0px))
      max(20px, env(safe-area-inset-right, 0px))
      max(24px, env(safe-area-inset-bottom, 0px))
      max(20px, env(safe-area-inset-left, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: -24px 0 60px rgba(0, 0, 0, .34);
  }

  .mobile-panel a {
    min-height: 46px;
    display: flex;
    align-items: center;
  }

  .mobile-panel .btn {
    justify-content: center;
    margin-top: 10px;
  }

  body:has(.mobile-panel.open) {
    overflow: hidden;
  }

  /* Hero: jerarquía compacta, legible y con espacio real para controles */
  .hero-layout {
    min-height: calc(100vh - 112px);
    min-height: calc(100svh - 112px);
    grid-template-columns: 1fr !important;
    align-items: center;
    gap: 0;
    padding: 48px 0 96px !important;
    padding: clamp(40px, 7svh, 58px) 0 96px !important;
  }

  .hero-copy {
    max-width: 100%;
    min-width: 0;
  }

  .hero-bg {
    background-position: center center !important;
  }

  .hero .eyebrow {
    display: block;
    max-width: 100%;
    font-size: .7rem;
    line-height: 1.65;
    letter-spacing: .16em;
    overflow-wrap: anywhere;
  }

  .hero h1 {
    max-width: 100%;
    margin: 12px 0 18px;
    font-size: clamp(2.55rem, 11.7vw, 3.5rem) !important;
    line-height: .97;
    letter-spacing: -.032em;
    text-wrap: balance;
    overflow-wrap: normal;
    word-break: normal;
  }

  .hero p {
    max-width: 100%;
    margin: 0;
    font-size: clamp(.98rem, 4.1vw, 1.06rem) !important;
    line-height: 1.56;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 24px;
  }

  .hero-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 50px;
    padding: 11px 13px;
    line-height: 1.2;
    text-align: center;
  }

  .hero-meta {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 9px !important;
    margin-top: 22px;
    font-size: .9rem;
  }

  .hero-meta > span {
    min-width: 0;
  }

  .carousel-controls {
    bottom: 26px !important;
    gap: 10px;
    min-height: 46px;
  }

  .carousel-controls > button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  .hero-dots {
    min-height: 44px;
    align-items: center;
  }

  .hero-dots button {
    min-width: 10px;
    min-height: 10px;
  }

  .hero-dots button.active {
    min-width: 28px;
  }

  /* Accesos rápidos: dos tarjetas tipo app, siempre con foto arriba */
  .image-nav {
    padding: 22px 0 58px !important;
  }

  .image-nav-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 14px !important;
    align-items: stretch;
  }

  .image-nav-card {
    display: flex !important;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    border-radius: 18px;
  }

  .image-nav-card img {
    width: 100%;
    height: clamp(112px, 31vw, 132px) !important;
    min-height: 0 !important;
    flex: 0 0 auto;
    object-fit: cover;
    object-position: center 40%;
  }

  .image-nav-card > div {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 14px 14px 16px !important;
  }

  .image-nav-card h3 {
    margin: 0 0 7px;
    font-size: clamp(1.04rem, 4.7vw, 1.2rem);
    line-height: 1.14;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
  }

  .image-nav-card p {
    min-height: 0 !important;
    margin: 0 0 12px;
    font-size: .82rem;
    line-height: 1.46;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
  }

  .image-nav-card span {
    display: inline-block;
    margin-top: auto;
    font-size: .8rem;
    line-height: 1.3;
    overflow-wrap: normal;
    word-break: normal;
  }

  /* Ritmo vertical y títulos en toda la interfaz pública móvil */
  .section {
    padding: 56px 0 !important;
  }

  .section-sm {
    padding: 40px 0;
  }

  .section-head,
  .section-head.centered {
    gap: 10px;
    margin-bottom: 26px;
  }

  .section-head h2,
  .location-copy h2,
  .prayer-banner h2,
  .display-title {
    font-size: clamp(2.05rem, 9.5vw, 2.85rem) !important;
    line-height: 1.04;
    text-wrap: balance;
  }

  .section-head p,
  .location-copy p,
  .prayer-banner p {
    margin-bottom: 0;
  }

  .foundation-grid,
  .photo-card-grid,
  .content-card-grid,
  .event-grid,
  .split-feature,
  .message-feature,
  .form-shell,
  .contact-cards,
  .faq-grid,
  .footer-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .foundation-grid article,
  .content-card-body,
  .contact-card,
  .faq-item {
    padding: 22px;
  }

  .value-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .photo-card {
    height: 250px;
  }

  .photo-card h3 {
    font-size: 1.65rem;
  }

  /* Secciones dinámicas del Home */
  .home-events-grid,
  .events-live-grid,
  .messages-live-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .home-gallery-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-auto-rows: 190px !important;
  }

  .gallery-feature {
    grid-column: auto !important;
    grid-row: span 1 !important;
  }

  .home-message .featured-message-live,
  .featured-message-live,
  .event-sunday-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .featured-message-media,
  .home-message .featured-message-media {
    min-height: 260px;
  }

  /* Ubicación y navegación */
  .location-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 28px;
  }

  .location-copy {
    padding: 0;
  }

  .location-facts {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .location-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .location-actions .btn {
    width: 100%;
    min-width: 0;
    padding-inline: 12px;
  }

  .map-panel {
    min-height: 0 !important;
  }

  .church-map {
    height: 270px !important;
    min-height: 270px !important;
    flex-basis: 270px !important;
  }

  .map-address {
    position: static !important;
    border-radius: 0;
    border-bottom: 1px solid #d9e3e7;
    box-shadow: none;
  }

  .map-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    padding: 10px;
  }

  .map-button,
  .map-button.main {
    min-width: 0;
    min-height: 70px;
  }

  .map-button.main {
    grid-column: 1 / -1 !important;
  }

  .prayer-banner .container,
  .ministry-cta .container,
  .about-verse-grid,
  .message-scripture-grid {
    align-items: flex-start !important;
    flex-direction: column !important;
  }

  .prayer-banner .btn,
  .ministry-cta .btn {
    width: 100%;
  }

  /* Páginas interiores */
  .page-hero {
    min-height: 260px;
  }

  .page-hero .container {
    padding-block: 52px 44px !important;
  }

  .page-hero h1,
  .about-hero-copy h1,
  .ministries-hero h1,
  .events-hero h1,
  .messages-hero h1 {
    font-size: clamp(2.4rem, 11vw, 3.45rem) !important;
    line-height: .99;
    text-wrap: balance;
  }

  .page-hero p {
    font-size: 1rem;
    line-height: 1.55;
  }

  .page-content {
    padding: 54px 0 70px;
  }

  .feature-image,
  .feature-image img {
    min-height: 290px;
  }

  .content-card img,
  .event-card-premium img {
    height: 205px;
  }

  .message-list article {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
  }

  .message-list img {
    width: 88px;
    height: 82px;
  }

  .about-hero-layout,
  .ministries-hero-layout,
  .events-hero-layout,
  .messages-hero-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    min-height: auto !important;
    padding: 54px 0 62px !important;
  }

  .about-founded-card,
  .ministries-hero-layout aside,
  .events-hero-note,
  .messages-hero-note {
    display: none !important;
  }

  .about-story-grid,
  .ministry-path-grid,
  .about-foundation-grid,
  .about-beliefs-grid,
  .leadership-grid,
  .ministries-premium-grid,
  .ministry-premium-card {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .about-story-media,
  .about-story-media > img {
    min-height: 330px !important;
    height: 330px !important;
  }

  .about-story-badge {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .ministry-photo {
    height: 220px;
  }

  .ministry-body,
  .featured-message-copy,
  .event-live-body,
  .message-live-body,
  .dialog-body {
    padding: 22px;
  }

  .gallery-grid {
    grid-auto-rows: 150px;
  }

  .gallery-item:nth-child(n) {
    grid-column: span 12 !important;
  }

  .form-side {
    min-height: 360px;
  }

  .form-card {
    padding: 21px;
  }

  .field input,
  .field textarea,
  .field select {
    min-height: 48px;
    font-size: 16px;
  }

  .field textarea {
    min-height: 140px;
  }

  .form-card .btn,
  .dialog-actions .btn {
    width: 100%;
  }

  /* Redes y footer */
  .contact-social-shell {
    align-items: flex-start;
    flex-direction: column;
  }

  .contact-socials {
    width: 100%;
  }

  .contact-socials a,
  .contact-socials span {
    flex: 1;
    min-width: 52px;
    min-height: 54px;
  }

  .site-footer {
    padding: 48px 0 max(22px, env(safe-area-inset-bottom, 0px));
  }

  .footer-grid {
    gap: 30px !important;
  }

  .footer-grid > div {
    gap: 8px;
    min-width: 0;
  }

  .footer-grid img[data-logo-footer] {
    width: min(230px, 76vw);
    height: auto;
    max-height: 80px;
    object-position: left center;
  }

  .footer-bottom {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-top: 30px;
    font-size: .82rem;
  }

  /* Controles táctiles y prevención de desbordamientos */
  a,
  button,
  input,
  select,
  textarea {
    touch-action: manipulation;
  }

  main,
  section,
  .section,
  .page-content,
  .image-nav-card,
  .content-card,
  .event-card-premium,
  .photo-card,
  .form-card,
  .map-panel,
  .footer-grid > div {
    min-width: 0;
  }
}

@media (max-width: 480px) {
  .container {
    width: min(calc(100% - 24px), var(--max));
  }

  .topbar {
    font-size: .75rem;
  }

  .header-inner {
    gap: 8px;
  }

  .site-header .brand img {
    width: clamp(140px, 43vw, 164px) !important;
  }

  .hero-layout {
    padding-top: 38px !important;
  }

  .hero h1 {
    font-size: clamp(2.42rem, 11.5vw, 3.25rem) !important;
  }

  .image-nav-grid {
    gap: 12px !important;
  }

  .image-nav-card > div {
    padding: 13px 12px 15px !important;
  }

  .image-nav-card h3 {
    font-size: 1.04rem;
  }

  .image-nav-card p {
    font-size: .79rem;
  }

  .section {
    padding: 50px 0 !important;
  }
}

@media (max-width: 374px) {
  .topbar .container {
    min-height: 36px;
  }

  .site-header .brand img {
    width: clamp(132px, 42vw, 148px) !important;
  }

  .theme-switch,
  .menu-btn {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px;
    min-height: 42px;
  }

  .hero-layout {
    min-height: auto;
    padding: 36px 0 90px !important;
  }

  .hero h1 {
    font-size: clamp(2.3rem, 12vw, 2.8rem) !important;
  }

  .hero-actions,
  .location-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .image-nav-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .image-nav-card img {
    height: 154px !important;
  }

  .image-nav-card > div {
    padding: 16px !important;
  }

  .image-nav-card h3 {
    font-size: 1.18rem;
  }

  .image-nav-card p {
    font-size: .84rem;
  }

  .value-grid,
  .map-actions {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .map-button.main {
    grid-column: auto !important;
  }

  .message-list article {
    grid-template-columns: minmax(0, 1fr);
  }

  .message-list img {
    width: 100%;
    height: 170px;
  }
}

@media (max-width: 720px) and (orientation: landscape) and (max-height: 520px) {
  .topbar {
    display: none;
  }

  .hero-layout {
    min-height: auto;
    padding: 34px 0 82px !important;
  }

  .hero h1 {
    font-size: clamp(2.3rem, 8vw, 3rem) !important;
  }

  .hero-meta {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
