/*
 * PetCare+ mobile web compatibility
 * Loaded after the page-specific styles so the same PHP pages remain usable
 * in mobile Chrome on Android and iOS (including notched devices).
 */

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

body {
  max-width: 100%;
  overflow-x: hidden;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  :root {
    --mobile-gutter: max(1rem, env(safe-area-inset-left));
    --mobile-gutter-right: max(1rem, env(safe-area-inset-right));
  }

  body {
    min-width: 0;
  }

  /* Keep every shared container inside the viewport, including pages that
     currently add desktop padding inline. */
  .container {
    width: 100%;
    max-width: 100%;
    padding-left: var(--mobile-gutter) !important;
    padding-right: var(--mobile-gutter-right) !important;
  }

  /* Shared navbar ------------------------------------------------------- */
  .nav-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 60px;
    padding-left: var(--mobile-gutter) !important;
    padding-right: var(--mobile-gutter-right) !important;
    gap: .25rem;
  }

  .nav-logo {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    gap: .4rem;
  }

  .nav-logo-img {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .nav-logo .logo-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.1rem;
  }

  .nav-actions {
    min-width: 0;
    flex: 0 0 auto;
    gap: .25rem !important;
  }

  .nav-actions .theme-toggle,
  .nav-actions .notif-bell {
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Logged-in users must still be able to open the account sheet on a phone. */
  .nav-user-menu {
    display: flex !important;
    flex: 0 0 auto;
  }

  .user-avatar-wrap {
    min-width: 40px;
    min-height: 40px;
    justify-content: center;
    cursor: pointer;
  }

  .user-avatar-name,
  .user-avatar-chevron {
    display: none !important;
  }

  .user-avatar,
  .user-avatar-placeholder {
    width: 34px;
    height: 34px;
  }

  .nav-toggle,
  .nav-sidebar-toggle {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: .5rem;
    flex: 0 0 40px;
  }

  /* Do not let the public mobile menu exceed the visual viewport. */
  .mobile-menu {
    top: calc(60px + env(safe-area-inset-top, 0px)) !important;
    right: var(--mobile-gutter-right) !important;
    left: var(--mobile-gutter) !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100svh - 72px - env(safe-area-inset-top, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-menu-auth .mobile-menu-row {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard shell ---------------------------------------------------- */
  body.is-dashboard .dash-layout {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-top: 60px;
  }

  body.is-dashboard .sidebar {
    top: 60px !important;
    height: calc(100vh - 60px) !important;
    height: calc(100svh - 60px) !important;
  }

  body.is-dashboard .dash-main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-left: 0 !important;
    padding-left: var(--mobile-gutter) !important;
    padding-right: var(--mobile-gutter-right) !important;
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-x: hidden;
  }

  body.is-dashboard .dash-main > *,
  body.is-dashboard .dash-main .card,
  body.is-dashboard .dash-main .card-body,
  body.is-dashboard .dash-main .card-header {
    min-width: 0;
    max-width: 100%;
  }

  /* Inline desktop grids are used throughout the role dashboards. */
  body.is-dashboard .dash-main > div[style*="grid-template-columns"],
  body.is-dashboard .dash-main > div[style*="display:grid"],
  body.is-dashboard .dash-main > div[style*="display: grid"] {
    display: block !important;
  }

  body.is-dashboard .dash-main > div[style*="grid-template-columns"] > *,
  body.is-dashboard .dash-main > div[style*="display:grid"] > *,
  body.is-dashboard .dash-main > div[style*="display: grid"] > * {
    width: 100% !important;
    max-width: 100%;
    min-width: 0 !important;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap table {
    min-width: 560px;
  }

  /* Public filters and other inline grid forms ----------------------- */
  form[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    align-items: stretch !important;
  }

  form[style*="grid-template-columns"] .btn,
  form[style*="grid-template-columns"] button {
    width: 100%;
    justify-content: center;
  }

  input,
  select,
  textarea,
  .form-control {
    max-width: 100%;
    font-size: 16px; /* prevents automatic iOS zoom on focus */
  }

  input,
  select,
  .form-control,
  button,
  .btn {
    min-height: 44px; /* iOS minimum, also acceptable for Android (48px recommended) */
  }

  textarea {
    min-height: 110px;
  }

  /* Hero, cards, maps, and detail pages ------------------------------- */
  .hero,
  .hero-premium {
    min-height: 100vh;
    min-height: 100svh;
  }

  .hero-container,
  .hero-premium-container {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    gap: 2rem;
    padding-left: var(--mobile-gutter) !important;
    padding-right: var(--mobile-gutter-right) !important;
  }

  .hero h1,
  .hero-premium h1 {
    font-size: clamp(2rem, 9vw, 3rem);
    overflow-wrap: anywhere;
  }

  .hero-actions,
  .cta-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: .75rem;
  }

  .hero-actions .btn,
  .cta-actions .btn {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .clinics-grid,
  .features-grid,
  .testimonials-grid,
  .steps-grid,
  .pets-grid,
  .services-grid,
  .profile-grid {
    grid-template-columns: 1fr !important;
    min-width: 0;
  }

  .clinic-card,
  .clinic-card-body,
  .card {
    min-width: 0;
    max-width: 100%;
  }

  #clinicMap,
  .map-container,
  .map-section-inner {
    max-width: 100%;
  }

  /* Prevent fixed desktop cover/header heights from cropping detail pages. */
  [style*="height:280px"] {
    height: clamp(200px, 48vw, 280px) !important;
  }

  /* Dialogs and overlays need room for the mobile browser chrome. */
  .modal-overlay {
    padding: max(1rem, env(safe-area-inset-top)) var(--mobile-gutter-right)
      max(1rem, env(safe-area-inset-bottom)) var(--mobile-gutter);
    align-items: flex-start;
    overflow-y: auto;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 2rem);
    max-height: calc(100svh - 2rem);
    margin: 0;
  }

  /* Dashboard bottom navigation must clear the iOS home indicator. */
  .mobile-bottom-nav {
    padding-bottom: calc(.4rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 480px) {
  .nav-logo .logo-text {
    font-size: 1rem;
  }

  .nav-actions .theme-toggle,
  .nav-actions .notif-bell,
  .nav-toggle,
  .nav-sidebar-toggle {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .nav-toggle,
  .nav-sidebar-toggle {
    flex-basis: 36px;
    padding: .4rem;
  }

  .user-avatar-wrap {
    min-width: 36px;
    min-height: 36px;
  }

  .user-avatar,
  .user-avatar-placeholder {
    width: 32px;
    height: 32px;
  }

  .card-body {
    padding: 1rem;
  }

  .card-header {
    padding: .85rem 1rem;
  }
}

@media (max-width: 360px) {
  .nav-logo .logo-text {
    display: none;
  }

  body.is-dashboard .stats-row,
  body.is-dashboard .stats-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
