/**
 * Cross-device polish — iOS, Android, tablet, desktop
 */

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

body {
  min-height: 100dvh;
}

html.psa-standalone,
html.psa-standalone body {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* Prevent iOS input zoom (requires ≥16px) */
@media (max-width: 1024px) {
  input,
  select,
  textarea,
  .btn {
    font-size: max(16px, 1rem);
  }

  .btn-sm {
    font-size: max(14px, 0.875rem);
    min-height: 44px;
  }
}

/* Touch-friendly controls site-wide */
a,
button,
[role="button"],
.btn,
.nav-link,
.hamburger,
.scroll-top {
  -webkit-tap-highlight-color: transparent;
}

@media (pointer: coarse) {
  .nav-link,
  .hamburger,
  .scroll-top,
  .footer-link,
  .footer-social {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .footer-social {
    min-width: 44px;
    justify-content: center;
  }

  .hamburger {
    min-width: 44px;
    justify-content: center;
  }
}

body.psa-mobile-menu-open {
  overflow: hidden;
  touch-action: none;
}

body.psa-mobile-menu-open .scroll-top {
  display: none !important;
}

/* PWA install banners — sit above portal tab bar on phone/tablet */
body.psa-portal #psaPwaBanners {
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  padding-bottom: 0.35rem;
}

@media (min-width: 1025px) {
  body.psa-portal #psaPwaBanners {
    bottom: 0;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

.psa-pwa-banner-inner {
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.psa-pwa-banner-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.psa-pwa-banner-btn {
  min-height: 44px;
  padding: 0.55rem 1rem;
}

/* Marketing site mobile menu */
@media (max-width: 768px) {
  .mobile-nav-link {
    min-height: 48px;
    font-size: 1rem;
  }

  .navbar {
    padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
  }

  .scroll-top {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    right: calc(1rem + env(safe-area-inset-right, 0px));
  }
}

/* Portal: hide redundant scroll-top when tab bar is present */
@media (max-width: 1024px) {
  body.psa-portal .scroll-top {
    display: none !important;
  }
}

/* Standalone / installed app */
html.psa-standalone body.psa-portal {
  overscroll-behavior-y: contain;
}

html.psa-standalone .psa-portal .dash-nav {
  transform: translateZ(0);
}

/* Desktop marketing + portal */
@media (min-width: 1025px) {
  .container {
    padding-left: clamp(1.5rem, 3vw, 2.5rem);
    padding-right: clamp(1.5rem, 3vw, 2.5rem);
  }

  .psa-portal .dashboard-main {
    padding-left: clamp(1.5rem, 2.5vw, 2.5rem);
    padding-right: clamp(1.5rem, 2.5vw, 2.5rem);
  }
}

.psa-contact-handoff {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(201, 168, 76, 0.12);
  border: 1px solid rgba(201, 168, 76, 0.35);
}

.psa-contact-handoff a {
  font-weight: 600;
  color: var(--primary);
}

/* Anchor scroll offset for fixed nav */
section[id] {
  scroll-margin-top: calc(var(--psa-marketing-nav-height) + 0.75rem);
}

/* Prevent awkward overflow from long headings */
.hero-title,
.page-hero-title,
.section-title {
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Form controls — touch-friendly height */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    min-height: 44px;
  }

  .service-link {
    min-height: 44px;
    align-items: center;
  }
}

/* No sticky hover lift on touch */
@media (hover: none) {
  .service-card:hover,
  .card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }

  .service-card:hover::before {
    transform: scaleX(0);
  }
}

/* Trust bar — respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .trust-bar-inner {
    animation: none;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    white-space: normal;
    gap: 1rem 2rem;
  }

  .trust-bar-duplicate {
    display: none;
  }
}

/* Stats grid — cleaner 2×2 on tablet, single column on phone */
@media (max-width: 768px) {
  .stats-grid {
    gap: 0;
  }

  .stat-item {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1.5rem 1rem;
  }

  .stat-item:nth-child(odd) {
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .stat-item:nth-last-child(-n+2) {
    border-bottom: none;
  }

  .stat-number {
    font-size: clamp(2rem, 8vw, 2.75rem);
  }

  .contact-form {
    padding: 1.5rem;
  }

  .footer-bottom-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem 1.25rem;
  }

  .footer-bottom-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 540px) {
  .about-values {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-item,
  .stat-item:nth-child(odd) {
    border-right: none;
  }

  .stat-item:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .stat-item:last-child {
    border-bottom: none;
  }

  .cta-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 22rem;
    margin: 0 auto;
  }

  .cta-actions .btn {
    width: 100%;
  }

  .hero-badge {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    padding: 0.4rem 0.85rem;
  }
}

/* Page hero — safe area under notch */
.page-hero {
  padding-top: calc(6rem + env(safe-area-inset-top, 0px));
}

@media (min-width: 769px) {
  .page-hero {
    padding-top: 8rem;
  }
}

/* Desktop spacing polish */
@media (min-width: 1280px) {
  .hero-grid {
    gap: 5rem;
  }

  .section-header.text-center .section-subtitle {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }

  .services-grid {
    gap: 2rem;
  }
}

.mobile-nav-link:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .psa-portal-sheet,
  .psa-portal-sheet-backdrop {
    transition: none;
  }

  .psa-advisor-messages {
    scroll-behavior: auto;
  }
}

/* Portal panels — anchor offset under fixed nav / tab bar */
body.psa-portal [id] {
  scroll-margin-top: calc(56px + env(safe-area-inset-top, 0px) + 0.5rem);
}

@media (min-width: 1025px) {
  body.psa-portal [id] {
    scroll-margin-top: calc(var(--psa-marketing-nav-height) + 0.5rem);
  }
}

@media (max-width: 1024px) {
  body.psa-portal [id] {
    scroll-margin-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* Advisory chat — empty state hint spacing */
.psa-advisor-messages:empty {
  min-height: 3rem;
}

@media (hover: none) {
  .support-option:hover {
    border-color: transparent;
    background: var(--off-white);
  }

  .support-option:active {
    border-color: var(--accent);
    background: var(--white);
  }
}
