/* =============================================================================
   vCard responsive viewport adaptation
   Overrides production bundle styles. Scoped to person cards via :has().
   ============================================================================= */

:root {
  --vcard-safe-top: env(safe-area-inset-top, 0px);
  --vcard-safe-right: env(safe-area-inset-right, 0px);
  --vcard-safe-bottom: env(safe-area-inset-bottom, 0px);
  --vcard-safe-left: env(safe-area-inset-left, 0px);
  --vcard-space-xs: clamp(0.35rem, 1.2vh, 0.65rem);
  --vcard-space-sm: clamp(0.5rem, 1.6vh, 0.9rem);
  --vcard-space-md: clamp(0.75rem, 2.2vh, 1.25rem);
  --vcard-space-lg: clamp(1rem, 3vh, 1.75rem);
  --vcard-pad-x: clamp(1rem, 4.5vw, 1.75rem);
  --vcard-pad-y: clamp(0.85rem, 2.5vh, 1.5rem);
  --vcard-avatar: clamp(5.5rem, 18vmin, 7.5rem);
  --vcard-btn: clamp(3rem, 12vmin, 3.75rem);
  --vcard-qr: clamp(9.5rem, 38vmin, 13.5rem);
}

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

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

body {
  display: block;
  place-items: unset;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  background-color: #f5f5f5;
}

#root {
  width: 100%;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0;
  text-align: center;
}

.App {
  min-height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  box-sizing: border-box;
  padding: max(0.75rem, var(--vcard-safe-top))
    max(0.75rem, var(--vcard-safe-right))
    max(0.75rem, var(--vcard-safe-bottom))
    max(0.75rem, var(--vcard-safe-left));
  -webkit-overflow-scrolling: touch;
}

/* ---------- Person vCard (not admin/forms) ---------- */
.business-card:has(.profile-section) {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto minmax(0, 1fr) auto;
  align-content: stretch;
  box-sizing: border-box;
  width: 100%;
  max-width: 26.25rem;
  margin: 0 auto;
  padding: var(--vcard-pad-y) var(--vcard-pad-x);
  padding-top: calc(var(--vcard-pad-y) + var(--vcard-safe-top));
  padding-bottom: calc(var(--vcard-pad-y) + var(--vcard-safe-bottom));
  padding-left: calc(var(--vcard-pad-x) + var(--vcard-safe-left));
  padding-right: calc(var(--vcard-pad-x) + var(--vcard-safe-right));
  min-height: calc(100vh - max(0.75rem, var(--vcard-safe-top)) - max(0.75rem, var(--vcard-safe-bottom)));
  min-height: calc(100svh - max(0.75rem, var(--vcard-safe-top)) - max(0.75rem, var(--vcard-safe-bottom)));
  min-height: calc(100dvh - max(0.75rem, var(--vcard-safe-top)) - max(0.75rem, var(--vcard-safe-bottom)));
  border-radius: 1.25rem;
  overflow: visible;
}

.business-card:has(.profile-section) > .header,
.business-card:has(.profile-section) > .profile-section,
.business-card:has(.profile-section) > .save-contact-btn,
.business-card:has(.profile-section) > .contact-buttons,
.business-card:has(.profile-section) > .separator,
.business-card:has(.profile-section) > div:last-child {
  min-width: 0;
}

.business-card:has(.profile-section) > .header {
  height: auto;
  min-height: 2.75rem;
  margin-bottom: 0;
  padding: 0;
}

.business-card:has(.profile-section) .logo {
  height: clamp(2rem, 6vmin, 2.75rem);
}

.business-card:has(.profile-section) .share-btn {
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
}

.business-card:has(.profile-section) > .profile-section {
  margin-bottom: 0;
}

.business-card:has(.profile-section) .profile-image-container {
  margin-bottom: var(--vcard-space-sm);
}

.business-card:has(.profile-section) .profile-image {
  width: var(--vcard-avatar);
  height: var(--vcard-avatar);
  border-width: clamp(2px, 0.5vw, 4px);
}

.business-card:has(.profile-section) .name {
  font-size: clamp(1.25rem, 5.2vw, 1.5rem);
  margin-bottom: var(--vcard-space-xs);
}

.business-card:has(.profile-section) .title {
  font-size: clamp(1rem, 4.2vw, 1.25rem);
  margin-bottom: var(--vcard-space-sm);
}

.business-card:has(.profile-section) .address {
  font-size: clamp(0.8rem, 3.4vw, 0.9375rem);
}

.business-card:has(.profile-section) > .separator {
  width: 60%;
  height: 1px;
  margin: var(--vcard-space-sm) auto;
  align-self: center;
}

.business-card:has(.profile-section) > .save-contact-btn {
  margin: 0;
  padding: clamp(0.75rem, 2vh, 1rem) 1.25rem;
  font-size: clamp(0.875rem, 3.6vw, 1rem);
  min-height: 2.75rem;
}

.business-card:has(.profile-section) > .contact-buttons {
  margin: var(--vcard-space-md) 0 0;
}

.business-card:has(.profile-section) .contact-row {
  gap: clamp(0.65rem, 3vw, 1rem);
  margin-bottom: var(--vcard-space-sm);
  flex-wrap: wrap;
}

.business-card:has(.profile-section) .contact-btn {
  width: var(--vcard-btn);
  height: var(--vcard-btn);
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.5rem;
  flex: 0 0 auto;
}

.business-card:has(.profile-section) .material-symbols-rounded.icon-lg {
  font-size: clamp(1.5rem, 7vmin, 2.2rem);
}

/* QR block (last child of person card) */
.business-card:has(.profile-section) > div:last-child {
  margin-top: 0;
  padding-bottom: var(--vcard-space-xs);
}

.business-card:has(.profile-section) > div:last-child svg {
  width: var(--vcard-qr) !important;
  height: auto !important;
  max-width: min(100%, 13.5rem);
  display: block;
  margin: 0 auto;
}

.business-card:has(.profile-section) > div:last-child > div:last-child {
  margin-top: var(--vcard-space-sm) !important;
  font-size: clamp(0.875rem, 3.5vw, 1rem);
}

/* ---------- Narrow phones: full-bleed card ---------- */
@media (max-width: 480px) {
  .App {
    padding: 0;
    align-items: stretch;
  }

  .App > .business-card:has(.profile-section),
  .business-card:has(.profile-section) {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    padding-top: calc(var(--vcard-pad-y) + var(--vcard-safe-top));
    padding-bottom: calc(var(--vcard-pad-y) + var(--vcard-safe-bottom));
    padding-left: calc(var(--vcard-pad-x) + var(--vcard-safe-left));
    padding-right: calc(var(--vcard-pad-x) + var(--vcard-safe-right));
  }

  /* Forms / other cards keep readable full width without 100vw overflow */
  .business-card:not(:has(.profile-section)) {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 0;
    min-height: auto;
  }
}

/* ---------- Short / landscape viewports: compact + natural scroll ---------- */
@media (max-height: 700px) {
  :root {
    --vcard-avatar: clamp(4.75rem, 16vmin, 6.25rem);
    --vcard-qr: clamp(8rem, 32vmin, 11rem);
    --vcard-btn: clamp(2.75rem, 11vmin, 3.25rem);
  }

  .business-card:has(.profile-section) {
    grid-template-rows: auto auto minmax(0, 0.6fr) auto auto minmax(0, 0.6fr) auto;
  }
}

@media (max-height: 600px), (orientation: landscape) and (max-height: 500px) {
  :root {
    --vcard-space-xs: 0.3rem;
    --vcard-space-sm: 0.4rem;
    --vcard-space-md: 0.55rem;
    --vcard-space-lg: 0.75rem;
    --vcard-pad-y: 0.65rem;
    --vcard-avatar: 4.25rem;
    --vcard-qr: 7.5rem;
    --vcard-btn: 2.75rem;
  }

  .App {
    align-items: flex-start;
  }

  .business-card:has(.profile-section) {
    min-height: auto;
    grid-template-rows: none;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .business-card:has(.profile-section) > .separator {
    margin: 0.4rem auto;
    flex: 0 0 auto;
  }
}

/* Very small width (iPhone SE / 320) */
@media (max-width: 360px) {
  :root {
    --vcard-pad-x: 0.85rem;
    --vcard-btn: 2.75rem;
  }

  .business-card:has(.profile-section) .contact-row {
    gap: 0.55rem;
  }
}

/* Tall phones: breathe a bit more between blocks */
@media (min-height: 800px) and (max-width: 480px) {
  :root {
    --vcard-space-sm: clamp(0.65rem, 2vh, 1.1rem);
    --vcard-space-md: clamp(0.9rem, 2.6vh, 1.4rem);
    --vcard-avatar: clamp(6rem, 20vmin, 7.75rem);
    --vcard-qr: clamp(10.5rem, 40vmin, 14rem);
  }
}

/* Not-found pages: use dynamic viewport too */
.not-found {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  padding: max(1.25rem, var(--vcard-safe-top))
    max(1.25rem, var(--vcard-safe-right))
    max(1.25rem, var(--vcard-safe-bottom))
    max(1.25rem, var(--vcard-safe-left));
  box-sizing: border-box;
}
