/* Mobile-first overrides for the real I-Net Fiber customer portal.
   Loaded only at <= 820px so desktop behavior and the staff portal are untouched. */

@media (max-width: 820px) {
  :root {
    --mobile-pad: 14px;
    --mobile-radius: 17px;
  }

  html {
    min-width: 0;
    background: var(--canvas);
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-width: 0;
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
  }

  button,
  a,
  input,
  select,
  textarea {
    touch-action: manipulation;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* Login / first password */
  .portal-youtube-bg::after {
    background:
      linear-gradient(180deg, rgba(2, 10, 19, .46), rgba(2, 10, 19, .82)),
      radial-gradient(circle at 50% 24%, rgba(38, 112, 217, .16), transparent 45%);
  }

  .portal-youtube-bg iframe {
    width: max(100vw, 177.78vh);
    height: max(56.25vw, 100vh);
    transform: translate(-50%, -50%) scale(1.07);
  }

  .floating-back {
    top: max(10px, env(safe-area-inset-top));
    right: 12px;
    min-height: 38px;
    padding: 0 13px;
    border-radius: 999px;
    font-size: 10px;
    background: rgba(4, 18, 34, .55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .login-layout,
  .force-password {
    min-height: 100svh;
    align-items: end;
    padding:
      max(66px, calc(env(safe-area-inset-top) + 56px))
      var(--mobile-pad)
      max(18px, env(safe-area-inset-bottom));
  }

  .login-shell {
    width: 100%;
    max-width: 520px;
  }

  .login-heading {
    margin: 0 3px 16px;
  }

  .login-heading h1 {
    max-width: 360px;
    margin: 7px 0 7px;
    font-size: clamp(27px, 8.5vw, 35px);
    line-height: 1.03;
  }

  .login-heading p {
    max-width: 360px;
    font-size: 12px;
    line-height: 1.5;
  }

  .login-card,
  .password-card {
    width: 100%;
    padding: 19px;
    border-radius: 20px;
    box-shadow: 0 22px 58px rgba(0, 0, 0, .28);
  }

  .login-brand {
    gap: 9px;
    padding-bottom: 14px;
    margin-bottom: 14px;
  }

  .login-brand img {
    width: 49px;
    height: 38px;
  }

  .login-brand strong {
    font-size: 13px;
  }

  label {
    margin-top: 14px;
    font-size: 12px;
  }

  input,
  select {
    min-height: 50px;
    height: 50px;
    border-radius: 12px;
  }

  textarea {
    min-height: 118px;
    border-radius: 12px;
  }

  .password-field input {
    padding-right: 54px;
  }

  .password-field button {
    top: 12px;
    right: 5px;
    width: 40px;
    height: 40px;
  }

  .login-submit,
  .password-card > .primary {
    min-height: 50px;
  }

  .support-copy {
    margin-bottom: 3px;
    font-size: 11px;
  }

  /* App shell */
  .customer-app {
    width: 100%;
    min-width: 0;
    min-height: 100svh;
  }

  .portal-sidebar {
    width: min(86vw, 310px);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: none;
    padding:
      max(14px, env(safe-area-inset-top))
      13px
      max(14px, env(safe-area-inset-bottom));
  }

  .portal-sidebar.open {
    transform: translateX(0);
    box-shadow: 18px 0 50px rgba(3, 14, 27, .34);
  }

  .sidebar-close {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .sidebar-nav {
    gap: 6px;
  }

  .nav-button {
    min-height: 48px;
    height: 48px;
    border-radius: 11px;
    font-size: 13px;
  }

  .sidebar-help button,
  .sidebar-logout {
    min-height: 44px;
  }

  .mobile-nav-shade {
    position: fixed;
    z-index: 45;
    inset: 0;
    background: rgba(4, 14, 26, .56);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .mobile-nav-shade.open {
    display: block;
  }

  .portal-main {
    min-width: 0;
    width: 100%;
    margin-left: 0;
  }

  .portal-topbar {
    height: calc(64px + env(safe-area-inset-top));
    min-height: 64px;
    padding: env(safe-area-inset-top) var(--mobile-pad) 0;
    background: rgba(255, 255, 255, .97);
  }

  .menu-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    margin-left: -6px;
    border-radius: 10px;
    font-size: 20px;
  }

  .topbar-eyebrow {
    display: none;
  }

  .topbar-left strong {
    font-size: 15px;
  }

  .topbar-user > div:last-child {
    display: none;
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .portal-content {
    width: 100%;
    max-width: none;
    padding: 18px var(--mobile-pad) calc(46px + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  /* Overview */
  .welcome-grid {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .welcome-card {
    min-height: 180px;
    padding: 22px 18px;
    border-radius: var(--mobile-radius);
  }

  .welcome-card h1 {
    margin-top: 6px;
    font-size: clamp(25px, 7.4vw, 31px);
    line-height: 1.06;
  }

  .welcome-card p {
    max-width: 90%;
    font-size: 11px;
  }

  .welcome-meta {
    left: 18px;
    right: 18px;
    bottom: 17px;
    gap: 10px 14px;
    font-size: 9px;
  }

  .payable-card {
    min-height: 152px;
    padding: 18px;
    border-radius: var(--mobile-radius);
  }

  .payable-card > strong {
    font-size: 29px;
  }

  .payable-card .primary {
    min-height: 45px;
  }

  .section-heading {
    align-items: center;
    gap: 10px;
    margin: 23px 0 10px;
  }

  .section-heading h2 {
    font-size: 17px;
  }

  .text-button {
    min-height: 40px;
    padding: 0 4px;
    white-space: nowrap;
  }

  .service-summary {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .service-summary article {
    min-height: 72px;
    padding: 0 10px;
    border-radius: 13px;
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .service-symbol {
    width: 29px;
    height: 29px;
    border-radius: 9px;
  }

  .service-summary small {
    font-size: 8px;
  }

  .service-summary strong {
    font-size: 13px;
  }

  .service-card {
    padding: 14px 12px 12px;
    border-radius: 15px;
  }

  .service-card-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .service-card-head > b {
    text-align: left;
    font-size: 12px;
  }

  .service-details {
    grid-template-columns: 1fr 1fr;
    gap: 12px 10px;
    padding: 14px 4px 9px;
  }

  .service-details > div {
    min-width: 0;
  }

  .service-details strong {
    overflow-wrap: anywhere;
  }

  .service-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .service-actions button {
    width: 100%;
    min-height: 44px;
  }

  .complaint-banner {
    align-items: flex-start;
    flex-direction: column;
    gap: 13px;
    padding: 15px;
    border-radius: 15px;
  }

  .complaint-banner > div {
    align-items: flex-start;
  }

  .complaint-banner button {
    width: 100%;
    min-height: 43px;
  }

  /* Page headers / records */
  .page-heading {
    margin-bottom: 18px;
  }

  .page-heading.row {
    display: block;
  }

  .page-heading h1 {
    margin-top: 4px;
    font-size: 24px;
    line-height: 1.1;
  }

  .page-heading p {
    max-width: 100%;
    font-size: 11px;
  }

  .page-heading.row > .primary {
    width: 100%;
    min-height: 44px;
    margin-top: 12px;
  }

  .record-stack {
    gap: 10px;
  }

  .record-card {
    border-radius: 14px;
  }

  .record-head {
    min-height: auto;
    padding: 12px;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .record-head span {
    align-self: auto;
  }

  .record-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px 10px;
    padding: 13px 12px;
  }

  .record-grid > div:first-child {
    grid-column: 1 / -1;
  }

  .record-grid strong {
    overflow-wrap: anywhere;
  }

  .record-foot {
    min-height: 0;
    padding: 11px 12px;
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }

  .download-button {
    width: 100%;
    min-height: 40px;
  }

  .empty-state {
    min-height: 165px;
    padding: 24px 16px;
    border-radius: 14px;
  }

  .ticket-item {
    grid-template-columns: 35px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 12px;
  }

  .ticket-copy {
    min-width: 0;
  }

  .ticket-copy strong,
  .ticket-copy p {
    overflow-wrap: anywhere;
  }

  .status-pill {
    grid-column: 2;
    justify-self: start;
    min-width: 70px;
  }

  /* Payments */
  .payment-layout {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .payment-panel,
  .billing-summary {
    padding: 14px;
    border-radius: 15px;
  }

  .payment-total {
    padding: 14px;
    border-radius: 12px;
  }

  .payment-total > strong {
    font-size: 25px;
  }

  .payment-options button {
    min-height: 60px;
    height: auto;
    padding: 9px 12px;
    grid-template-columns: 35px minmax(0, 1fr) 16px;
  }

  .payment-options strong {
    font-size: 11px;
  }

  .payment-options small {
    font-size: 9px;
  }

  .billing-summary > div {
    gap: 12px;
    padding: 10px 0;
  }

  .billing-summary strong {
    max-width: 62%;
    overflow-wrap: anywhere;
  }

  /* Dialogs become thumb-friendly bottom sheets */
  .portal-dialog {
    width: 100%;
    max-width: none;
    max-height: min(92svh, 760px);
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    overflow: auto;
  }

  .portal-dialog::backdrop {
    background: rgba(2, 10, 19, .68);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .dialog-card {
    min-height: 100%;
    padding: 0 var(--mobile-pad) max(16px, env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
  }

  .dialog-head {
    margin: 0 calc(var(--mobile-pad) * -1) 14px;
    padding: 14px var(--mobile-pad) 12px;
    border-radius: 22px 22px 0 0;
  }

  .dialog-head h2 {
    font-size: 19px;
  }

  .icon-close {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: .8fr 1.2fr;
    gap: 8px;
    margin: 16px calc(var(--mobile-pad) * -1) calc(max(0px, env(safe-area-inset-bottom)) * -1);
    padding: 10px var(--mobile-pad) max(10px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(255,255,255,.82), #fff 24%);
  }

  .dialog-actions button {
    width: 100%;
    min-height: 46px;
  }
}

@media (max-width: 420px) {
  :root { --mobile-pad: 12px; }

  .login-heading h1 {
    font-size: 27px;
  }

  .login-card,
  .password-card {
    padding: 17px;
  }

  .portal-content {
    padding-top: 14px;
  }

  .service-summary article {
    min-height: 68px;
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 0 8px;
  }

  .service-symbol {
    width: 27px;
    height: 27px;
  }

  .welcome-card {
    min-height: 188px;
  }

  .welcome-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .record-grid,
  .service-details {
    grid-template-columns: 1fr 1fr;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 350px) {
  .service-summary {
    grid-template-columns: 1fr;
  }

  .service-details,
  .record-grid {
    grid-template-columns: 1fr;
  }

  .record-grid > div:first-child {
    grid-column: auto;
  }

  .service-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) and (orientation: landscape) and (max-height: 520px) {
  .login-layout,
  .force-password {
    align-items: start;
    padding-top: 58px;
  }

  .portal-dialog {
    max-height: 96svh;
  }
}

@media (max-width: 820px) and (prefers-reduced-motion: reduce) {
  .portal-sidebar,
  .portal-page.active,
  .portal-youtube-bg {
    transition: none !important;
    animation: none !important;
  }
}
