/* Mobile/PWA refinements loaded after the shared foundation styles.
   Keep accessibility intact: never disable pinch zoom or user scaling. */

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

/* Keep the installed application visually stable when repeated taps happen.
   manipulation preserves normal panning and pinch zoom while preventing the
   double-tap zoom gesture that can shift the workspace during navigation. */
.app-shell {
  touch-action: manipulation;
}

button,
a,
[role="button"],
.button,
input[type="button"],
input[type="submit"],
input[type="reset"],
summary {
  touch-action: manipulation;
}

/* The workspace owns its horizontal scrolling. Do not let an oversized child
   widen the document and make the installed PWA look zoomed or displaced. */
body:has(.app-shell) {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.app-shell,
.workspace,
.work-surface {
  min-width: 0;
  max-width: 100%;
}

/* Keep application update actions visually consistent with the lightweight
   version-check link instead of promoting the refresh to a primary CTA. */
.account-menu__update-apply {
  min-height: 2.25rem;
  padding: 0;
  border-radius: 0;
  color: var(--color-brand-primary);
  background: transparent;
  text-align: left;
}

.account-menu__update-apply:hover {
  color: var(--color-brand-primary-hover);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.account-menu__update-apply:focus-visible {
  border-radius: var(--radius-sm);
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

@media (max-width: 760px) {
  /* iOS zooms focused editable controls rendered below 16px. Keep the
     compact desktop density while giving phone inputs a stable 16px size. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea,
  .routine-search__field input,
  .routine-filter input,
  .audit-filter input,
  .audit-filter select {
    font-size: 1rem;
  }

  input,
  select,
  textarea {
    scroll-margin-block: 5rem;
  }

  html,
  body:has(.app-shell),
  .app-shell {
    overscroll-behavior: none;
  }

  /* Standalone PWAs may extend beneath device cutouts. The header and the
     horizontal activity strip remain fully tappable in portrait/landscape. */
  .app-header {
    padding-top: calc(var(--space-2) + env(safe-area-inset-top));
    padding-right: calc(var(--space-3) + env(safe-area-inset-right));
    padding-bottom: var(--space-2);
    padding-left: calc(var(--space-3) + env(safe-area-inset-left));
  }

  .activity-navigation {
    padding-right: calc(var(--space-3) + env(safe-area-inset-right));
    padding-left: calc(var(--space-3) + env(safe-area-inset-left));
  }

  .work-surface {
    padding-right: env(safe-area-inset-right);
    padding-left: env(safe-area-inset-left);
  }

  .routine-search__panel {
    inset:
      calc(4rem + env(safe-area-inset-top))
      calc(var(--space-3) + env(safe-area-inset-right))
      auto
      calc(var(--space-3) + env(safe-area-inset-left));
  }

  .account-menu__panel {
    inset:
      calc(3.75rem + env(safe-area-inset-top))
      calc(var(--space-3) + env(safe-area-inset-right))
      auto
      auto;
  }

  /* Login/logout can also be rendered inside the installed PWA. */
  .public-page__identity {
    padding-top: calc(var(--space-8) + env(safe-area-inset-top));
    padding-right: calc(var(--space-6) + env(safe-area-inset-right));
    padding-left: calc(var(--space-6) + env(safe-area-inset-left));
  }

  .login-panel {
    padding-right: calc(var(--space-6) + env(safe-area-inset-right));
    padding-bottom: calc(var(--space-10) + env(safe-area-inset-bottom));
    padding-left: calc(var(--space-6) + env(safe-area-inset-left));
  }
}

@media (max-width: 42rem) {
  .notification-push__actions {
    display: grid;
    gap: var(--space-2);
    width: 100%;
  }
}

@media (max-width: 640px) {
  .notification-panel {
    inset:
      calc(3.75rem + env(safe-area-inset-top))
      calc(0.5rem + env(safe-area-inset-right))
      auto
      calc(0.5rem + env(safe-area-inset-left));
    width: auto;
    max-height: calc(100dvh - 4.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

/* A download initiated inside the installed PWA keeps the current activity
   visible behind a small, explicit file action instead of navigating to an
   empty native preview for formats such as XLSX. */
.pwa-download-dialog {
  width: min(32rem, calc(100% - 2rem));
  max-width: none;
  padding: 0;
  border: 1px solid var(--color-border, #d9dee8);
  border-radius: 1rem;
  color: inherit;
  background: var(--color-surface, #fff);
  box-shadow: 0 1.5rem 4rem rgb(15 23 42 / 25%);
}

.pwa-download-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
  backdrop-filter: blur(2px);
}

.pwa-download-dialog > section {
  display: grid;
  gap: var(--space-5, 1.25rem);
  padding: var(--space-6, 1.5rem);
}

.pwa-download-dialog header,
.pwa-download-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 0.75rem);
}

.pwa-download-dialog h2,
.pwa-download-dialog p {
  margin: 0;
}

.pwa-download-dialog small {
  color: var(--color-text-muted, #64748b);
}

.pwa-download-dialog__close {
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
}

@media (max-width: 520px) {
  .pwa-download-dialog {
    width: calc(100% - 1rem);
    margin-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }

  .pwa-download-dialog footer {
    align-items: stretch;
    flex-direction: column;
  }
}
