/**
 * Nasher Telegram SaaS — Mobile Shell Styles (Spec 031)
 * Enforces 44px minimum touch targets, safe area insets, focus-visible, and scoped table overflow.
 */

:root {
  --touch-target-min: 44px;
}

/* Ensure no whole-page horizontal blowout on small viewports without breaking position: sticky */
html {
  -webkit-text-size-adjust: 100%;
}
body {
  overflow-x: clip;
}

/* Reflow dashboard actions instead of clipping them outside the RTL viewport. */
.dashboard-header-row,
.dashboard-store-identity,
.dashboard-store-heading,
.dashboard-channel-switcher,
.dashboard-account-actions,
.dashboard-catalog-links {
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}
.dashboard-store-identity > a {
  flex-shrink: 0;
}
.dashboard-store-heading > div {
  min-width: 0;
}
.dashboard-store-heading h1 {
  overflow-wrap: anywhere;
}
.dashboard-account-actions a {
  min-height: var(--touch-target-min, 44px);
  min-width: var(--touch-target-min, 44px);
}

/* 44×44px Minimum Tap Targets for all Interactive Controls (FR-005) */
.touch-target,
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
select,
[role="button"],
.btn {
  min-height: var(--touch-target-min, 44px);
  min-width: var(--touch-target-min, 44px);
}

/* Text inputs, selects and textareas must have comfortable touch height and avoid auto-zoom on iOS */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="url"],
select,
textarea {
  min-height: var(--touch-target-min, 44px);
  font-size: 1rem; /* >= 16px prevents iOS Safari from automatically zooming in */
}

/* Accessible Focus States (FR-005) */
:focus-visible {
  outline: 2px solid var(--color-brand-600, #4f46e5);
  outline-offset: 2px;
}

/* Safe Area Insets (FR-007) */
.safe-area-top {
  padding-top: env(safe-area-inset-top, 0px);
}

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

.safe-area-p {
  padding-top: max(1rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

/* Scoped Horizontal Scrolling for Data Tables (FR-006) */
.table-responsive,
.overflow-x-auto,
.data-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Phones and short landscape windows need one preparation-dialog scroller. */
@media (max-width: 640px), (max-height: 600px) {
  #prepWorkspaceBody {
    flex: none;
    overflow: visible;
  }
}

/* Mobile Dialog & Sheet Adaptations */
@media (max-width: 640px) {
  .modal-dialog,
  .dialog-content {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh;
    margin: auto;
    overflow-y: auto;
  }

  /* Form actions stack vertically on narrow screens */
  .form-actions-stack {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.75rem;
  }
  .form-actions-stack > * {
    width: 100%;
  }
}

/* Body bottom compensation when fixed mobile navigation is present */
body.has-mobile-nav {
  padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
}

/* Quiet body fallback; the same notice moves into the top native modal. */
body > #pwa-update-banner {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  left: max(1rem, env(safe-area-inset-left, 0px));
  right: max(1rem, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  max-width: 42rem;
  max-height: calc(100dvh - 2rem - env(safe-area-inset-bottom, 0px));
  margin: 0 auto;
  overflow: auto;
  z-index: 10000;
  padding: 12px;
  border: 1px solid #6547cc;
  border-radius: 16px;
  background: #f5f1ff;
  color: #392766;
  box-shadow: 0 4px 18px #39276612;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  text-align: start;
  direction: rtl;
}
body.has-mobile-nav > #pwa-update-banner {
  bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
}
/* Direct child of the dialog, outside its scrolling work-content region. */
dialog > #pwa-update-banner {
  position: static;
  z-index: auto;
  box-sizing: border-box;
  max-width: none;
  max-height: 16rem;
  max-height: min(40dvh, 16rem);
  margin: 0 0 8px;
  flex: none;
  overflow: auto;
  padding: 12px;
  border: 1px solid #6547cc;
  border-radius: 16px;
  background: #f5f1ff;
  color: #392766;
  box-shadow: 0 4px 18px #39276612;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  text-align: start;
  direction: rtl;
}
dialog > #pwa-update-banner .pwa-update-tip {display: none;}
#pwa-update-banner[hidden],
#pwa-update-banner [hidden],
body[data-nasher-authority-pending="true"] #pwa-update-banner {
  display: none !important;
}
#pwa-update-banner .pwa-update-main,
#pwa-update-banner .pwa-update-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
#pwa-update-status {
  flex: 1 1 16rem;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}
#pwa-update-banner .pwa-update-actions {flex: 0 1 auto;}
#pwa-update-banner button {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #50349e;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
#pwa-update-banner :is(#pwa-consent-btn, #pwa-refresh-btn) {
  background: #6547cc;
  color: #fff;
}
#pwa-update-banner button:hover {border-color: #6547cc;}
#pwa-update-banner button:focus-visible,
#pwa-update-status:focus-visible {
  outline: 3px solid #6547cc;
  outline-offset: 3px;
}
#pwa-update-banner .pwa-update-tip {
  margin: 8px 0 0;
  color: #5c4d7b;
  font-size: 12px;
}
#pwa-update-banner .pwa-update-details {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #dcd2f5;
  color: #5c4d7b;
}
#pwa-update-banner .pwa-update-details p {margin: 0 0 8px;}
@media (prefers-reduced-motion: reduce) {
  #pwa-update-banner, #pwa-update-banner * {
    animation: none !important;
    transition: none !important;
  }
}
