/* ==========================================================================
   MestiDelivery — Referral programme
   Uses the app's premium modal material (index.css .premium-modal-content-global):
   near-black radial gradient, top light edge, green close, Archivo 800 heading,
   glass inner blocks. Mobile: bottom sheet. ≥600px: centered card.
   ========================================================================== */

.mesti-ref-overlay {
  --rf-glass: rgba(255, 255, 255, 0.045);
  --rf-stroke: rgba(255, 255, 255, 0.1);
  --rf-stroke-top: rgba(255, 255, 255, 0.14);
  --rf-hairline: rgba(255, 255, 255, 0.08);
  --rf-text: #ffffff;
  --rf-muted: rgba(255, 255, 255, 0.55);
  --rf-faint: rgba(255, 255, 255, 0.32);
  --rf-green: var(--color-accent, #21ea7c);
  --rf-ease-out: var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1));
  --rf-ease-drawer: var(--ease-drawer, cubic-bezier(0.32, 0.72, 0, 1));
  --rf-display: 'Archivo', 'Inter', -apple-system, 'Noto Sans Georgian', sans-serif;

  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  /* exit */
  transition: opacity 260ms ease, visibility 0s linear 280ms;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Noto Sans Georgian', sans-serif;
  color: var(--rf-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.mesti-ref-overlay *,
.mesti-ref-overlay *::before,
.mesti-ref-overlay *::after {
  box-sizing: border-box;
}

.mesti-ref-overlay.mesti-ref-active {
  opacity: 1;
  visibility: visible;
  /* enter */
  transition: opacity 400ms var(--rf-ease-drawer), visibility 0s;
}

/* ---------- Sheet (premium modal material) ---------- */
.mesti-ref-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--material-sheet-bg, #141416);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 32px 32px 0 0;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom, 0px));
  color: var(--rf-text);
  transform: translateY(100%);
  transition: transform 280ms var(--rf-ease-out);
}

.mesti-ref-overlay.mesti-ref-active .mesti-ref-modal {
  transform: translateY(0);
  transition: transform 420ms var(--rf-ease-drawer);
}

/* Green close — same circle button as .ui-circle-btn on the restaurant page */
.mesti-ref-btn-close {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--rf-green);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 120ms var(--rf-ease-out), background-color 160ms ease;
}

.mesti-ref-btn-close svg {
  width: 18px;
  height: 18px;
}

.mesti-ref-btn-close:active {
  transform: scale(0.92);
}

/* ---------- Heading ---------- */
.mesti-ref-badge-wrap {
  margin: 0 56px 10px 0;
}

.mesti-ref-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--rf-green);
}

.mesti-ref-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rf-green);
}

.mesti-ref-title {
  margin: 0 52px 0 0;
  font-family: var(--rf-display);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-transform: none;
  color: var(--rf-text);
  text-wrap: balance;
}

.mesti-ref-subtitle {
  margin: 12px 0 28px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--rf-muted);
  text-wrap: pretty;
}

.mesti-ref-subtitle b,
.mesti-ref-subtitle .mesti-bonus-val {
  color: var(--rf-green);
  font-weight: 700;
}

/* ---------- Glass blocks ---------- */
.mesti-ref-stat-card,
.mesti-ref-link-box,
.mesti-ref-messenger-btn,
.mesti-ref-guest-card {
  background: var(--field-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--field-border, rgba(255, 255, 255, 0.08));
}

/* ---------- Stats ---------- */
.mesti-ref-stat-card {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 16px;
  padding: 22px 20px;
  border-radius: 20px;
}

.mesti-ref-stat-balance {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.mesti-ref-stat-label,
.mesti-ref-meta-text {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--rf-muted);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.mesti-ref-stat-amount {
  font-family: var(--rf-display);
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--rf-green);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mesti-ref-stat-divider {
  align-self: stretch;
  width: 1px;
  background: var(--rf-hairline);
}

.mesti-ref-stat-meta {
  display: flex;
  gap: 20px;
}

.mesti-ref-meta-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mesti-ref-meta-num {
  font-family: var(--rf-display);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--rf-text);
  font-variant-numeric: tabular-nums;
}

/* ---------- Link ---------- */
.mesti-ref-link-group {
  margin-bottom: 16px;
}

.mesti-ref-link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--control-height, 54px);
  padding: 0 6px 0 16px;
  border-radius: var(--control-radius, 16px);
  transition: border-color 200ms ease, background-color 200ms ease, box-shadow 200ms ease;
}

.mesti-ref-link-box:focus-within {
  border-color: var(--field-border-focus, rgba(33, 234, 124, 0.55));
  background: var(--field-bg-focus, rgba(255, 255, 255, 0.07));
  box-shadow: var(--field-ring-focus, 0 0 0 3px rgba(33, 234, 124, 0.12));
}

.mesti-ref-link-url {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 500;
  color: var(--rf-muted);
  -webkit-user-select: all;
  user-select: all;
}

.mesti-ref-copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--btn-secondary-border, rgba(255, 255, 255, 0.12));
  /* concentric with the 16px field and its 6px inset */
  border-radius: 10px;
  background: var(--btn-secondary-bg, rgba(255, 255, 255, 0.06));
  color: #ffffff;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 160ms var(--rf-ease-out), background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}

.mesti-ref-copy-btn:active {
  transform: scale(0.96);
}

.mesti-ref-copy-btn.mesti-copied {
  border-color: rgba(33, 234, 124, 0.35);
  background: rgba(33, 234, 124, 0.1);
  color: var(--rf-green);
}

/* ---------- Actions ---------- */
.mesti-ref-share-primary,
.mesti-ref-guest-btn {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: var(--control-height, 54px);
  padding: 0 20px;
  border: 0;
  border-radius: var(--control-radius, 16px);
  background: var(--btn-primary-bg, #21ea7c);
  color: var(--btn-primary-text, #0a0a0a);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: var(--btn-primary-shadow, inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 6px 18px rgba(33, 234, 124, 0.18));
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 160ms var(--rf-ease-out), filter 200ms ease, box-shadow 200ms ease;
}

.mesti-ref-share-primary::before,
.mesti-ref-guest-btn::before {
  content: '';
  position: absolute;
  z-index: -1;
  left: 18%;
  right: 18%;
  bottom: -6px;
  height: 16px;
  border-radius: 50%;
  background: var(--btn-primary-glow, rgba(33, 234, 124, 0.22));
  filter: blur(14px);
  pointer-events: none;
}

.mesti-ref-share-primary:active,
.mesti-ref-guest-btn:active {
  transform: scale(0.98);
}

.mesti-ref-messengers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.mesti-ref-messenger-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: var(--btn-secondary-height, 52px);
  border-radius: var(--control-radius, 16px);
  background: var(--btn-secondary-bg, rgba(255, 255, 255, 0.06)) !important;
  border: 1px solid var(--btn-secondary-border, rgba(255, 255, 255, 0.12)) !important;
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform 160ms var(--rf-ease-out), background-color 200ms ease, border-color 200ms ease;
}

.mesti-ref-messenger-btn:active {
  transform: scale(0.97);
}

.mesti-ref-messenger-btn svg {
  width: 18px;
  height: 18px;
  color: var(--rf-muted);
}

/* ---------- Guest ---------- */
.mesti-ref-guest-card {
  padding: 22px 20px;
  border-radius: 20px;
}

.mesti-ref-guest-text {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--rf-muted);
  text-wrap: pretty;
}

/* ---------- Rules ---------- */
.mesti-ref-terms {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--rf-hairline);
}

.mesti-ref-term-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--rf-muted);
  text-wrap: pretty;
}

.mesti-ref-term-bullet {
  flex-shrink: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--rf-green);
  transform: translateY(-2px);
}

.mesti-ref-term-item b {
  color: var(--rf-text);
  font-weight: 600;
}

/* ---------- Toast ("Скопировано") ---------- */
.mesti-ref-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  z-index: 1000000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 16px;
  background: #1a1a1d;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 200ms ease, transform 200ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1));
}

.mesti-ref-toast svg {
  color: var(--color-accent, #21ea7c);
}

.mesti-ref-toast.mesti-toast-show {
  opacity: 1;
  transform: translate(-50%, 0);
  transition-duration: 260ms;
}

/* ---------- Pointer devices ---------- */
@media (hover: hover) and (pointer: fine) {
  .mesti-ref-btn-close:hover,
  .mesti-ref-copy-btn:hover:not(.mesti-copied) {
    background: rgba(255, 255, 255, 0.1);
  }

  .mesti-ref-messenger-btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
  }

  .mesti-ref-share-primary:hover,
  .mesti-ref-guest-btn:hover {
    filter: brightness(1.04);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 8px 22px rgba(33, 234, 124, 0.24);
  }
}

/* ---------- Larger screens: centered card ---------- */
@media (min-width: 600px) {
  .mesti-ref-overlay {
    align-items: center;
    padding: 24px;
  }

  .mesti-ref-modal {
    max-width: 440px;
    border-radius: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-top-color: rgba(255, 255, 255, 0.08);
    padding: 36px 28px 32px;
    transform: translateY(16px) scale(0.98);
  }

  .mesti-ref-overlay.mesti-ref-active .mesti-ref-modal {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mesti-ref-modal,
  .mesti-ref-overlay.mesti-ref-active .mesti-ref-modal {
    transform: none;
    transition: none;
  }

  .mesti-ref-toast,
  .mesti-ref-toast.mesti-toast-show {
    transform: translate(-50%, 0);
    transition: opacity 200ms ease;
  }
}
