/* =====================================================================
   تعمیرمن — mobile "app mode" shell (customer pages only)
   Everything is scoped to html.app-mode, which is set by partials/_pwa_head.html
   for phone-sized touch screens and installed apps. Desktop is untouched.
   Loaded after home.css so these rules win.
   ===================================================================== */

/* App-only shell pieces start hidden; the tab bar is also enabled for mobile below. */
.app-tabbar,
.app-scrim,
.app-install {
  display: none;
}

html.app-mode {
  --topbar-h: 56px;
  --tabbar-h: 68px;
  --tabbar-gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-space: calc(
    var(--tabbar-h) + var(--tabbar-gap) + var(--tabbar-gap) + var(--safe-bottom)
  );
  --header-h: calc(var(--topbar-h) + var(--safe-top));
  -webkit-tap-highlight-color: transparent;
}

html.app-mode body {
  padding-bottom: calc(var(--tabbar-space) + 12px);
  overscroll-behavior-y: none;
}
html.app-mode.sheet-open body {
  overflow: hidden;
}

/* Compact landing-page service choices for the installed/mobile app view. */
html.app-mode body.landing-page .landing-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: none;
}
html.app-mode body.landing-page .landing-card {
  min-width: 0;
  border-radius: 18px;
}
html.app-mode body.landing-page .landing-card .service-image {
  display: none;
}
html.app-mode body.landing-page .landing-card .service-body {
  min-height: 112px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 5px;
  text-align: center;
}
html.app-mode body.landing-page .landing-card .service-chip {
  position: static;
  flex: none;
  width: 38px;
  height: 38px;
  margin: 0;
  border-radius: 13px;
  transform: none;
}
html.app-mode body.landing-page .landing-card .service-chip .icon {
  width: 21px;
  height: 21px;
}
html.app-mode body.landing-page .landing-card .service-body h2 {
  justify-content: center;
  font-size: clamp(11px, 3.1vw, 15px);
  line-height: 1.4;
  overflow-wrap: anywhere;
}
html.app-mode body.landing-page .landing-card .service-body h2 .icon,
html.app-mode body.landing-page .landing-card .service-body p,
html.app-mode body.landing-page .landing-card .service-tags,
html.app-mode body.landing-page .landing-card:not(.svc-abi) .service-link {
  display: none;
}
html.app-mode body.landing-page .landing-card.svc-abi .service-link {
  align-self: center;
  margin: 0;
  padding: 3px 9px;
  border: 1px solid color-mix(in srgb, var(--blue) 28%, var(--border));
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--blue);
  font-size: 11px;
  line-height: 1.4;
}

/* ---------- Top bar (the existing site header, made solid and compact) ---------- */
html.app-mode body #siteHeader {
  height: var(--header-h);
  padding-top: var(--safe-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
/* On service pages the compact top bar overlays the dark hero until scroll. */
html.app-mode body:not(.landing-page) #siteHeader:not(.scrolled) {
  background: transparent;
  border-bottom-color: transparent;
  box-shadow: none;
}
html.app-mode body:not(.landing-page) #siteHeader:not(.scrolled) #headerHello {
  color: rgba(255, 255, 255, .9);
}
html.app-mode body:not(.landing-page) #siteHeader:not(.scrolled) .nav-toggle {
  background: var(--blue);
  border-color: rgba(255, 255, 255, .58);
  color: #fff;
  box-shadow: 0 3px 14px rgba(4, 12, 32, .38);
}
html.app-mode body:not(.landing-page) #siteHeader.scrolled {
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom-color: var(--border);
  box-shadow: 0 6px 24px -18px rgba(11, 27, 58, .3);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
}
html.app-mode body:not(.landing-page) #siteHeader.scrolled #headerHello {
  color: var(--muted);
}
html.app-mode body:not(.landing-page) #siteHeader.scrolled .nav-toggle {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
html.app-mode body.landing-page #siteHeader:not(.scrolled) {
  background: transparent;
  border-bottom-color: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html.app-mode body.landing-page #siteHeader.scrolled {
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom-color: var(--border);
  box-shadow: 0 6px 24px -18px rgba(11, 27, 58, .3);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
}
html.app-mode body.landing-page #siteHeader:not(.scrolled) #headerHello {
  color: rgba(255, 255, 255, .9);
}
html.app-mode body.landing-page #siteHeader.scrolled #headerHello {
  color: var(--muted);
}
html.app-mode body.landing-page #siteHeader:not(.scrolled) .nav-toggle {
  background: var(--blue);
  border-color: rgba(255, 255, 255, .58);
  color: #fff;
  box-shadow: 0 3px 14px rgba(4, 12, 32, .38);
}
html.app-mode body.landing-page #siteHeader.scrolled .nav-toggle {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: none;
}
html.app-mode body #siteHeader .nav-inner {
  gap: 10px;
}
html.app-mode body #siteHeader .brand {
  font-size: 19px;
  gap: 8px;
}
html.app-mode body #siteHeader .brand .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
}
html.app-mode body #siteHeader .brand-name {
  background: linear-gradient(135deg, var(--text), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
html.app-mode body #siteHeader #headerHello {
  color: var(--muted);
  font-size: 13px;
  max-width: 140px;
}
html.app-mode body #siteHeader .header-center {
  margin-inline-start: auto;
}
html.app-mode body #siteHeader .nav-toggle {
  display: grid;
}
html.app-mode body #siteHeader #loginBtn {
  min-height: 38px;
}

/* ---------- Menu as a bottom sheet ---------- */
html.app-mode body #siteHeader .nav-links {
  position: fixed;
  inset-inline: 0;
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  max-height: 82dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 12px calc(14px + var(--safe-bottom));
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -18px 50px -20px rgba(4, 12, 32, 0.55);
  z-index: 600;
  opacity: 1;
  visibility: hidden;
  transform: translateY(100%);
  transform-origin: bottom center;
  transition:
    transform 0.35s var(--ease),
    visibility 0.35s;
}
html.app-mode body #siteHeader .nav-links.open {
  visibility: visible;
  transform: none;
}
html.app-mode body #siteHeader .nav-links::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 4px;
  background: var(--border-strong);
}
html.app-mode body #siteHeader .nav-links .nav-item {
  min-height: 52px;
  font-size: 16px;
}
html.app-mode body #siteHeader .nav-more-menu {
  padding-inline-start: 6px;
}

/* The sheet lives inside the header's stacking context, so the header must rise
   above the scrim while the sheet is open; its own bar is dimmed to match. */
html.app-mode.sheet-open body #siteHeader {
  z-index: 650;
}
html.app-mode.sheet-open body #siteHeader.scrolled {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html.app-mode body #siteHeader .brand,
html.app-mode body #siteHeader .header-center {
  transition: opacity 0.3s var(--ease);
}
html.app-mode.sheet-open body #siteHeader .brand,
html.app-mode.sheet-open body #siteHeader .header-center {
  opacity: 0.35;
  pointer-events: none;
}

html.app-mode .app-scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 550;
  background: rgba(4, 12, 32, 0.5);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s var(--ease),
    visibility 0.3s;
}
html.app-mode.sheet-open .app-scrim {
  opacity: 1;
  visibility: visible;
}

/* ---------- Floating bottom tab bar ---------- */
.app-tabbar {
  position: fixed;
  inset-inline: var(--tabbar-gap);
  bottom: calc(var(--tabbar-gap) + var(--safe-bottom));
  z-index: 400;
  grid-template-columns: 1fr 1fr 1.3fr 1fr 1fr;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  height: var(--tabbar-h);
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 32px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  box-shadow:
    0 20px 40px -14px rgba(11, 27, 58, 0.42),
    0 4px 12px -6px rgba(11, 27, 58, 0.2);
  transition: transform 0.25s var(--ease);
}
.app-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 48px;
  padding: 4px 2px;
  border: 0;
  border-radius: 22px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: clamp(9px, 2.8vw, 11.5px);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
  transition:
    color 0.2s,
    background-color 0.2s;
}
.app-tab .icon {
  width: 23px;
  height: 23px;
  transition: transform 0.3s var(--ease);
}
.app-tab:active {
  background: var(--surface-2);
}
.app-tab[aria-current="page"] {
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 12%, transparent);
}
.app-tab[aria-current="page"] .icon {
  transform: translateY(-1px) scale(1.08);
}
.app-tab:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

/* Keep the existing submit link, but give its icon the raised circular treatment. */
.app-tab-submit,
.app-tab-submit:active {
  position: relative;
  overflow: visible;
  min-height: 0;
  margin: 0 3px;
  justify-content: flex-end;
  gap: 2px;
  padding: 0 2px 3px;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--blue);
  font-size: clamp(9px, 2.8vw, 11px);
  font-weight: 800;
  line-height: 1.2;
}
.app-tab-submit::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: -22px;
  left: 50%;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--sky), var(--blue) 55%, var(--blue-700));
  box-shadow:
    0 0 0 5px var(--surface),
    0 14px 26px -8px var(--glow);
  transform: translateX(-50%);
  transition: transform 0.25s var(--ease);
}
.app-tab-submit .icon {
  position: absolute;
  z-index: 1;
  top: -6px;
  left: 50%;
  flex: none;
  width: 28px;
  height: 28px;
  margin: 0;
  object-fit: contain;
  filter: brightness(0) invert(1);
  transform: translateX(-50%);
}
.app-tab-submit span {
  position: relative;
  z-index: 1;
  margin-top: auto;
}
.app-tab-submit:active::before {
  transform: translateX(-50%) scale(0.93);
}
.app-tab-submit:focus-visible {
  outline-offset: 0;
}

/* Use the same bottom navigation on responsive mobile layouts, including
   browsers that are not running in installed-app mode. */
@media (max-width: 1023px) {
  html:not(.app-mode) {
    --tabbar-h: 68px;
    --tabbar-gap: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tabbar-space: calc(
      var(--tabbar-h) + var(--tabbar-gap) + var(--tabbar-gap) + var(--safe-bottom)
    );
  }
  html:not(.app-mode) body {
    padding-bottom: calc(var(--tabbar-space) + 12px);
  }
  html:not(.app-mode) .app-tabbar {
    display: grid;
  }
  html.kb-open .app-tabbar {
    transform: translateY(110%);
  }
  html.kb-open body {
    padding-bottom: 0;
  }
  #toast {
    bottom: calc(var(--tabbar-space) + 14px);
  }
}

/* Hide the tab bar only while the on-screen keyboard is open. */
html.app-mode.kb-open .app-tabbar {
  transform: translateY(110%);
}
html.app-mode.kb-open body {
  padding-bottom: 0;
}
html.app-mode .app-tabbar {
  display: grid;
}

/* ---------- Toast sits above the tab bar ---------- */
html.app-mode #toast {
  bottom: calc(var(--tabbar-space) + 14px);
}

/* ---------- Install card ---------- */
html.app-mode .app-install {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(var(--tabbar-space) + 12px);
  z-index: 450;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 8px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: appInstallIn 0.4s var(--ease) both;
}
html.app-mode .app-install[hidden] {
  display: none;
}
html.app-mode.kb-open .app-install {
  display: none;
}
html.app-mode .app-install-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(
    145deg,
    var(--sky),
    var(--blue) 60%,
    var(--blue-700)
  );
}
html.app-mode .app-install-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
html.app-mode .app-install-copy strong {
  font-size: 14px;
  font-weight: 800;
}
html.app-mode .app-install-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
html.app-mode .app-install-btn {
  flex: none;
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}
html.app-mode .app-install-btn[hidden] {
  display: none;
}
html.app-mode .app-install-close {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
@keyframes appInstallIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Dialogs and the loader stay above the shell. */
html.app-mode .modal-back {
  z-index: 700;
}
html.app-mode .app-loader {
  z-index: 1000;
}

@media (prefers-reduced-motion: reduce) {
  html.app-mode .app-tabbar,
  html.app-mode body #siteHeader .nav-links,
  html.app-mode .app-scrim,
  html.app-mode .app-install {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
