/*
 * NiuNiuIDC — Apple iPhone Duo (iPhone19,4) Outer & Inner 4-Orientation Adaptation
 * Strictly scoped to foldable viewport envelopes & safe-area insets; zero impact on existing devices.
 */

html {
  -webkit-text-size-adjust: 100%;
}

/* Prevent iOS Safari auto-zoom when focusing inputs on coarse-pointer screens (incl. Inner Landscape >767px) */
@media (pointer: coarse) {
  body.lagom input.form-control,
  body.lagom select.form-control,
  body.lagom textarea.form-control {
    font-size: max(16px, 1rem);
  }
}

/* Safe-area edge & cutout protection for Duo 84pt side sensor rail and 34pt Home Indicator */
@supports (padding: max(0px)) {
  @media (max-width: 767.98px) {
    body.lagom #header.app-nav-header > .container,
    body.lagom .main-banner > .container,
    body.lagom .main-top > .container,
    body.lagom .main-header > .container,
    body.lagom .main-body > .container,
    body.lagom .app-footer .container {
      padding-left: max(24px, calc(env(safe-area-inset-left, 0px) + 16px));
      padding-right: max(24px, calc(env(safe-area-inset-right, 0px) + 16px));
    }

    body.lagom .panel-footer.summary-bottom.is-fixed {
      padding-left: env(safe-area-inset-left, 0px) !important;
      padding-right: env(safe-area-inset-right, 0px) !important;
      padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    }
  }

  @media (min-width: 768px) and (max-width: 991.98px) {
    body.lagom #header.app-nav-header > .container,
    body.lagom .main-banner > .container,
    body.lagom .main-top > .container,
    body.lagom .main-header > .container,
    body.lagom .main-body > .container,
    body.lagom .app-footer .container {
      padding-left: max(40px, calc(env(safe-area-inset-left, 0px) + 16px));
      padding-right: max(40px, calc(env(safe-area-inset-right, 0px) + 16px));
    }

    body.lagom .panel-footer.summary-bottom.is-fixed {
      padding-left: max(24px, env(safe-area-inset-left, 0px)) !important;
      padding-right: max(24px, env(safe-area-inset-right, 0px)) !important;
      padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    }
  }

  @media (max-width: 991.98px) {
    body.lagom #header.app-nav-header {
      box-sizing: content-box;
      padding-top: env(safe-area-inset-top, 0px);
    }

    body.lagom.lagom-layout-top {
      padding-top: calc(74px + env(safe-area-inset-top, 0px));
    }

    body.lagom #main-menu.app-nav-menu {
      height: 100vh;
      height: 100dvh;
      max-height: 100dvh;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      padding-top: env(safe-area-inset-top, 0px);
      padding-left: env(safe-area-inset-left, 0px);
      padding-right: env(safe-area-inset-right, 0px);
      padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    }

    body.lagom #orderSummary.order-summary-mob.is-fixed {
      padding-left: env(safe-area-inset-left, 0px);
      padding-right: env(safe-area-inset-right, 0px);
      padding-bottom: env(safe-area-inset-bottom, 0px);
      height: auto;
      min-height: 52px;
    }
  }

  body.lagom .app-footer {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.lagom #addToCartFloatingAlert.clientAlert {
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 12px));
    max-width: calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
}

/* ==========================================================================
   1. iPhone Duo Outer Portrait (382x580..644 Safari / 466x678 Raw)
   ========================================================================== */
@media (max-width: 480px) and (max-height: 650px) and (orientation: portrait),
       (min-width: 445px) and (max-width: 480px) and (max-height: 700px) and (orientation: portrait) {
  body.lagom.page-homepage .main-banner.banner-home {
    padding-top: 24px;
    padding-bottom: 20px;
    min-height: 0;
  }

  body.lagom.page-homepage .main-banner .banner-title {
    font-size: 26px;
    line-height: 1.32;
    margin-bottom: 0;
    text-wrap: balance;
  }

  body.lagom.page-homepage .main-body {
    padding-top: 20px;
  }

  body.lagom.page-homepage .main-body .section-header {
    margin-bottom: 12px;
  }

  body.lagom.page-homepage .tiles.row > [class*="col-"] {
    margin-bottom: 10px;
  }

  body.lagom.page-homepage .tile.tile-home {
    padding: 14px 16px;
    min-height: 68px;
  }

  /* Order billing cycles: 2x2 compact grid instead of 4 tall vertical cards */
  body.lagom .section--billing-cycles .row.row-eq-height {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height::before,
  body.lagom .section--billing-cycles .row.row-eq-height::after {
    display: none !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle {
    margin-bottom: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle .panel-body {
    padding: 12px 8px;
  }

  /* Keep Add-to-Cart & Buy-Now side-by-side on one row to save 52px of vertical space */
  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px;
    padding-top: 8px !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions > .btn {
    flex: 1 1 0;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* ==========================================================================
   2. iPhone Duo Outer Landscape (594x368..432 Safari / 678x466 Raw)
   ========================================================================== */
@media (min-width: 480px) and (max-width: 743.98px) and (max-height: 480px) and (orientation: landscape) {
  body.lagom.lagom-layout-top {
    padding-top: calc(54px + env(safe-area-inset-top, 0px));
  }

  body.lagom #header.app-nav-header,
  body.lagom #header.app-nav-header > .container {
    height: 54px;
    min-height: 54px;
  }

  body.lagom.page-homepage .main-banner.banner-home {
    padding-top: 14px;
    padding-bottom: 12px;
    min-height: 0;
  }

  body.lagom.page-homepage .main-banner .banner-title {
    font-size: 22px;
    line-height: 1.25;
    margin-bottom: 0;
  }

  body.lagom.page-homepage .main-body {
    padding-top: 14px;
  }

  body.lagom.page-homepage .main-body .section-header {
    margin-bottom: 10px;
  }

  body.lagom.page-homepage .tiles.row {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tiles.row::before,
  body.lagom.page-homepage .tiles.row::after {
    display: none !important;
  }

  body.lagom.page-homepage .tiles.row > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tile.tile-home {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 8px;
    gap: 6px;
    height: 100%;
    margin-bottom: 0 !important;
  }

  body.lagom.page-homepage .tile.tile-home .tile-icon {
    margin: 0 !important;
    transform: scale(0.78);
    transform-origin: center;
  }

  /* Order page: 4-column single-row cycles + slim 60px single-row bottom action bar */
  body.lagom .app-main-order .main-top,
  body.lagom .app-main-order .main-header,
  body.lagom.page-order .main-top,
  body.lagom.page-order .main-header,
  body.lagom .main-banner {
    padding-top: 10px;
    padding-bottom: 8px;
  }

  body.lagom .main-header .header-title,
  body.lagom .main-top h1,
  body.lagom h1.banner-title {
    font-size: 22px;
    line-height: 1.28;
    margin-bottom: 4px;
  }

  body.lagom .section-top-nav {
    margin-bottom: 10px;
  }

  body.lagom .section--billing-cycles .row.row-eq-height {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height::before,
  body.lagom .section--billing-cycles .row.row-eq-height::after {
    display: none !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle {
    margin-bottom: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle .panel-body {
    padding: 10px 6px;
  }

  body.lagom .section--billing-cycles .panel-billingcycle .price-sm {
    font-size: 17px;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed {
    padding-top: 8px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed > .bottom-content.container {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .price.price-left {
    display: flex !important;
    flex-direction: column;
    margin: 0 !important;
    width: auto !important;
    flex-shrink: 0;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .price .price-total {
    font-size: 11px;
    line-height: 1.2;
    margin-bottom: 2px !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .price .price-amount-total {
    font-size: 20px;
    line-height: 1.1;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions {
    display: flex !important;
    flex-direction: row-reverse !important;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding-top: 0 !important;
    margin: 0 !important;
    width: auto !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions > .btn {
    width: auto !important;
    min-width: 116px !important;
    height: 38px;
    padding: 0 12px;
    margin: 0 !important;
  }

  body.lagom.page-login .login-wrapper,
  body.lagom.page-clientregister .login-wrapper {
    padding-top: 12px;
    padding-bottom: 16px;
  }

  body.lagom.page-login .login-body,
  body.lagom.page-clientregister .login-body {
    padding: 18px 20px;
  }
}

/* ==========================================================================
   3. iPhone Duo Inner Portrait (669x835..951 Unfolded)
      Exclusive envelope: > regular phones (<=440px) and < iPad mini (>=744px)
   ========================================================================== */
@media (min-width: 600px) and (max-width: 743.98px) and (orientation: portrait) {
  body.lagom.page-homepage .main-banner.banner-home {
    padding-top: 34px;
    padding-bottom: 30px;
    min-height: 0;
  }

  body.lagom.page-homepage .tiles.row {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tiles.row::before,
  body.lagom.page-homepage .tiles.row::after {
    display: none !important;
  }

  body.lagom.page-homepage .tiles.row > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tile.tile-home {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 14px;
    gap: 12px;
    height: 100%;
    margin-bottom: 0 !important;
  }

  body.lagom.page-homepage .tile.tile-home .tile-icon {
    margin: 0 0 4px 0 !important;
  }

  /* Order billing cycles: 2x2 balanced grid instead of 4 full-width stacked boxes */
  body.lagom .section--billing-cycles .row.row-eq-height {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height::before,
  body.lagom .section--billing-cycles .row.row-eq-height::after {
    display: none !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle {
    margin-bottom: 0 !important;
  }

  /* Single-row sticky order summary bar on 669px Inner Portrait */
  body.lagom .panel-footer.summary-bottom.is-fixed {
    padding-top: 12px !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed > .bottom-content.container {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 16px;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .price.price-left {
    display: flex !important;
    flex-direction: column;
    margin: 0 !important;
    width: auto !important;
    flex-shrink: 0;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .price .price-total {
    margin-bottom: 2px !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions {
    display: flex !important;
    flex-direction: row-reverse !important;
    align-items: center;
    gap: 10px;
    padding-top: 0 !important;
    margin: 0 !important;
    width: auto !important;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed .summary-actions > .btn {
    width: auto !important;
    min-width: 148px !important;
    margin: 0 !important;
  }
}

/* ==========================================================================
   4. iPhone Duo Inner Landscape (867..951 x 585..669 Unfolded)
      Exclusive envelope: 744..991px width AND <=700px height in landscape
      (iPads in landscape are >=1024x744; regular phones in landscape are <=440px tall)
   ========================================================================== */
@media (min-width: 744px) and (max-width: 991.98px) and (max-height: 700px) and (orientation: landscape) {
  body.lagom.lagom-layout-top {
    padding-top: calc(62px + env(safe-area-inset-top, 0px));
  }

  body.lagom #header.app-nav-header,
  body.lagom #header.app-nav-header > .container {
    height: 62px;
    min-height: 62px;
  }

  body.lagom.page-homepage .main-banner.banner-home {
    padding-top: 26px;
    padding-bottom: 24px;
    min-height: 0;
  }

  body.lagom.page-homepage .main-banner .banner-title {
    font-size: 30px;
    line-height: 1.3;
    margin-bottom: 0;
  }

  body.lagom.page-homepage .main-body {
    padding-top: 22px;
  }

  /* Expand 3 homepage action tiles to fill the row evenly without a 25% right gap */
  body.lagom.page-homepage .tiles.row:not(:has(> :nth-child(4))) {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tiles.row:not(:has(> :nth-child(4)))::before,
  body.lagom.page-homepage .tiles.row:not(:has(> :nth-child(4)))::after {
    display: none !important;
  }

  body.lagom.page-homepage .tiles.row:not(:has(> :nth-child(4))) > .col-md-3 {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom.page-homepage .tile.tile-home {
    padding: 20px 16px;
    height: 100%;
    margin-bottom: 0 !important;
  }

  /* Order page: 4-column single-row billing cycles so VPS packages sit above the fold */
  body.lagom .app-main-order .main-top,
  body.lagom .app-main-order .main-header,
  body.lagom.page-order .main-top,
  body.lagom.page-order .main-header {
    padding-top: 14px;
    padding-bottom: 10px;
  }

  body.lagom .section--billing-cycles .row.row-eq-height {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height::before,
  body.lagom .section--billing-cycles .row.row-eq-height::after {
    display: none !important;
  }

  body.lagom .section--billing-cycles .row.row-eq-height > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle {
    margin-bottom: 0 !important;
  }

  body.lagom .section--billing-cycles .panel-billingcycle .panel-body {
    padding: 14px 10px;
  }

  body.lagom .panel-footer.summary-bottom.is-fixed {
    padding-top: 10px !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Short-height landscape modal scroll safety (Outer Landscape & Inner Landscape) */
@media (max-height: 700px) and (orientation: landscape) {
  body.lagom .modal .modal-dialog {
    margin: 12px auto;
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }

  body.lagom .modal .modal-content {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
  }

  body.lagom .modal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}
