/* Apple-inspired design tokens (from DESIGN.md) */
:root {
  --color-primary: #0071e3;
  --color-primary-hover: #0077ed;
  --color-ink: #1d1d1f;
  --color-ink-muted: #86868b;
  --color-ink-subtle: #6e6e73;
  --color-canvas: #ffffff;
  --color-parchment: #f5f5f7;
  --color-surface-pearl: #fafafc;
  --color-divider: #d2d2d7;
  --color-hairline: #e8e8ed;

  --font-display: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-text: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 18px;
  --radius-pill: 9999px;

  --shadow-product: 0 8px 32px rgba(0, 0, 0, 0.12);

  --photo-size: 88px;
  --page-pad-y: 10px;
  --page-pad-x: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #2997ff;
    --color-primary-hover: #40a9ff;
    --color-ink: #f5f5f7;
    --color-ink-muted: #a1a1a6;
    --color-ink-subtle: #d2d2d7;
    --color-canvas: #1d1d1f;
    --color-parchment: #000000;
    --color-surface-pearl: #2a2a2c;
    --color-divider: #424245;
    --color-hairline: #3a3a3c;

    --shadow-product: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-photo: 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

@media (min-height: 800px) {
  :root {
    --photo-size: 112px;
    --page-pad-y: 20px;
    --page-pad-x: 16px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: -0.24px;
  color: var(--color-ink);
  background: var(--color-parchment);
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page shell — fit one screen when possible, scroll when needed */
.page {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(var(--page-pad-y), env(safe-area-inset-top))
    max(var(--page-pad-x), env(safe-area-inset-right))
    max(var(--page-pad-y), env(safe-area-inset-bottom))
    max(var(--page-pad-x), env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.page::-webkit-scrollbar {
  display: none;
}

.page__inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* Hero card */
.card {
  background: var(--color-canvas);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-product);
  flex: 0 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.card__hero {
  background: var(--color-canvas);
  padding: 14px 18px 10px;
  text-align: center;
  flex-shrink: 0;
}

.card__photo-wrap {
  width: var(--photo-size);
  height: var(--photo-size);
  margin: 0 auto 10px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-parchment);
  box-shadow: var(--shadow-photo, 0 4px 20px rgba(0, 0, 0, 0.08));
}

.card__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card__company {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: 4px;
}

.card__name {
  font-family: var(--font-display);
  font-size: clamp(18px, 5.5vw, 28px);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.374px;
  color: var(--color-ink);
  margin-bottom: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.card__title {
  font-size: 14px;
  font-weight: 400;
  color: var(--color-ink-subtle);
  margin-bottom: 0;
  line-height: 1.25;
}

.card__tagline {
  display: none;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--color-ink-muted);
  max-width: 280px;
  margin: 6px auto 0;
}

/* Bio section */
.card__bio {
  padding: 8px 18px;
  background: var(--color-surface-pearl);
  border-top: 1px solid var(--color-hairline);
  flex-shrink: 0;
}

.card__bio-text {
  font-size: 13px;
  line-height: 1.35;
  color: var(--color-ink-subtle);
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Contact list */
.card__contacts {
  padding: 2px 18px 4px;
  border-top: 1px solid var(--color-hairline);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.card__contacts::-webkit-scrollbar {
  display: none;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  text-decoration: none;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-hairline);
  transition: color 0.2s ease;
}

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

.contact-item:hover,
.contact-item:focus-visible {
  color: var(--color-primary);
}

.contact-item__icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-parchment);
  border-radius: var(--radius-sm);
  color: var(--color-ink-subtle);
}

.contact-item__icon svg {
  width: 15px;
  height: 15px;
}

.contact-item__label {
  font-size: 10px;
  font-weight: 400;
  color: var(--color-ink-muted);
  letter-spacing: -0.12px;
  line-height: 1.1;
}

.contact-item__value {
  font-size: 13px;
  font-weight: 400;
  color: inherit;
  line-height: 1.2;
  word-break: break-word;
}

/* Action buttons — side by side */
.card__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--color-hairline);
  flex-shrink: 0;
}

.btn--full {
  grid-column: 1 / -1;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: 10px 10px;
  font-family: var(--font-text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.24px;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn--primary:hover,
.btn--primary:focus-visible {
  background: var(--color-primary-hover);
}

.btn--secondary {
  background: var(--color-canvas);
  color: var(--color-primary);
  border: 1px solid var(--color-divider);
}

.btn--secondary:hover,
.btn--secondary:focus-visible {
  background: var(--color-parchment);
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* Footer */
.page__footer {
  margin-top: 6px;
  text-align: center;
  flex-shrink: 0;
}

.page__footer-text {
  font-size: 10px;
  color: var(--color-ink-muted);
  letter-spacing: -0.08px;
  line-height: 1.2;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  font-size: 14px;
  line-height: 1.3;
  color: #ffffff;
  text-align: center;
  background: rgba(29, 29, 31, 0.92);
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: rgba(245, 245, 247, 0.95);
    color: #1d1d1f;
  }
}

/* QR modal */
body.modal-open {
  overflow: hidden;
}

.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.qr-modal[hidden] {
  display: none;
}

.qr-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.qr-modal__panel {
  position: relative;
  width: 100%;
  max-width: 320px;
  padding: 24px 22px 20px;
  text-align: center;
  background: var(--color-canvas);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-product);
}

.qr-modal__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--color-ink);
  margin-bottom: 4px;
}

.qr-modal__hint {
  font-size: 13px;
  line-height: 1.35;
  color: var(--color-ink-muted);
  margin-bottom: 16px;
}

.qr-modal__code {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.qr-modal__code img,
.qr-modal__code canvas {
  display: block;
  width: 200px;
  height: 200px;
  padding: 10px;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.qr-modal__url {
  font-size: 12px;
  color: var(--color-primary);
  word-break: break-all;
  margin-bottom: 16px;
}

.qr-modal__close {
  max-width: 200px;
  margin: 0 auto;
}

/* Loading state */
.page--loading .card {
  opacity: 0;
}

.page--loading::after {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 2px solid var(--color-divider);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error state */
.error-banner {
  background: #fff3f3;
  color: #bf4800;
  padding: 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  text-align: center;
  margin-bottom: 8px;
  flex-shrink: 0;
}

@media (prefers-color-scheme: dark) {
  .error-banner {
    background: #3a2010;
    color: #ff9f0a;
  }

  .btn--secondary:hover,
  .btn--secondary:focus-visible {
    background: var(--color-surface-pearl);
  }
}

/* Taller screens — more breathing room */
@media (min-height: 800px) {
  body {
    font-size: 17px;
  }

  .card__hero {
    padding: 24px 24px 14px;
  }

  .card__photo-wrap {
    margin-bottom: 14px;
  }

  .card__company {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .card__name {
    margin-bottom: 4px;
  }

  .card__title {
    font-size: 16px;
    margin-bottom: 0;
  }

  .card__tagline {
    display: block;
    font-size: 14px;
    margin-top: 8px;
  }

  .card__bio {
    padding: 14px 24px;
  }

  .card__bio-text {
    font-size: 14px;
    line-height: 1.45;
    -webkit-line-clamp: 3;
  }

  .card__contacts {
    padding: 4px 24px 8px;
  }

  .contact-item {
    padding: 8px 0;
    gap: 12px;
  }

  .contact-item__icon {
    width: 34px;
    height: 34px;
  }

  .contact-item__icon svg {
    width: 17px;
    height: 17px;
  }

  .contact-item__label {
    font-size: 11px;
  }

  .contact-item__value {
    font-size: 15px;
  }

  .card__actions {
    padding: 14px 24px;
    gap: 10px;
  }

  .btn {
    padding: 12px 14px;
    font-size: 15px;
  }

  .page__footer {
    margin-top: 12px;
  }

  .page__footer-text {
    font-size: 11px;
  }
}

/* Very short screens — extra compact */
@media (max-height: 620px) {
  :root {
    --photo-size: 72px;
    --page-pad-y: 6px;
  }

  .card__bio-text {
    -webkit-line-clamp: 1;
  }

  .contact-item {
    padding: 4px 0;
  }

  .card__actions {
    padding: 8px 14px;
  }

  .btn {
    padding: 9px 8px;
    font-size: 13px;
  }

  .page__footer {
    margin-top: 4px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
