/* Reusable components: buttons, cards, pills, badges, plan cards, popups.
   Ported from the mini-app components.css + iOS Components.swift. */

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: var(--r-button);
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--sh-button);
}

.btn-secondary {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--sh-secondary);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}

/* solid dark action (mirrors the mini-app/iOS primary-dark) */
.btn-dark {
  background: #111111;
  color: #fff;
}

/* destructive action (delete/cancel-billing) */
.btn-danger {
  background: var(--danger-bg);
  color: var(--bad);
}

/* compact variant: smaller type + tighter vertical padding for inline actions */
.btn.compact {
  padding: 10px 14px;
  font-size: 14px;
}

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card);
  padding: 14px 16px;
}

/* a card that is itself a tappable button (opens a sheet): full-width row with
   a trailing chevron cue. iOS Safari otherwise renders button text link-blue. */
.card-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.card-btn:active {
  transform: scale(0.99);
}

.card-btn .chev {
  color: var(--sub);
  font-weight: 700;
}

/* ---- pills / badges ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--chip-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap; /* keep "от 449 ₽" on one line */
  flex-shrink: 0;      /* never let the flex row squeeze the price */
}

.pill-gift {
  background: var(--bonus-bg);
  color: var(--bonus-ink);
  border: 1px solid var(--bonus-border);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
}

.badge-ok {
  background: var(--chip-bg);
  color: var(--ok);
}

/* plan selection grid: one column on phones, two on wide screens */
.plan-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .plan-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* three-up row: promo · Friends · Unlimited (stacks to one column on phones) */
  .plan-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* ---- plan card (selection screen) ---- */
.plan {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name badge"
    "sell sell";
  align-items: start;
  column-gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-plan);
  box-shadow: var(--sh-card);
  padding: 16px;
  width: 100%;
  height: 100%;
  text-align: left;
  color: var(--ink); /* iOS Safari otherwise renders button text link-blue */
}

.plan:active {
  transform: scale(0.99);
}

.plan-name {
  grid-area: name;
  font-size: 18px;
  font-weight: 800;
}

.plan > .pill {
  grid-area: badge;
  align-self: start;
}

.plan-sell {
  grid-area: sell;
  font-size: 13.5px;
  color: var(--sub);
  margin-top: 4px;
}

/* ---- price chip ---- */
.price {
  font-size: 30px;
  font-weight: 800;
}

/* ---- referral info page (ported from mini-app ReferralInfo) ---- */
.ref-info-hero {
  text-align: center;
  padding: 6px 0 2px;
}

.ref-info-title {
  font-size: 25px;
  font-weight: 800;
  color: var(--ink);
  margin: 12px 0 6px;
}

.ref-info-lead {
  font-size: 14px;
  color: var(--sub);
  margin: 0 auto;
  max-width: 30em;
  line-height: 1.45;
}

/* one card, sections split by hairlines */
.ref-info {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card);
  padding: 0 16px;
}

.ref-info-sec {
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.ref-info-sec:first-child {
  border-top: none;
}

.ref-card__title {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 8px;
}

.ref-info-p {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--sub);
  margin: 7px 0 0;
  /* spread text evenly across the width instead of a ragged right edge */
  text-align: justify;
  -webkit-hyphens: auto;
  hyphens: auto;
}

.ref-info-p b {
  color: var(--ink);
  font-weight: 700;
}

.ref-info-rows {
  margin-top: 11px;
  display: grid;
  gap: 8px;
}

.ref-info-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--on-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-tier);
  font-size: 13.5px;
  color: var(--sub);
}

.ref-info-row b {
  margin-left: auto;
  text-align: right;
  color: var(--ink);
  font-weight: 800;
}

/* ---- popup (centered scrim sheet) ---- */
.popup-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}

.popup {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto; /* long sheets (referral rules) scroll inside the popup */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* hide the scrollbar track (Firefox) */
  background: var(--bg); /* popups render on cream, not white */
  border-radius: var(--r-sheet);
  box-shadow: var(--sh-popup);
  padding: 20px;
}

/* hide the scrollbar track on WebKit too; the sheet still scrolls */
.popup::-webkit-scrollbar {
  display: none;
}

/* wide variant for text-heavy sheets (referral rules) so lines fill out */
.popup-wide {
  max-width: 640px;
}

/* scroll cue: a bouncing down-chevron pinned to the bottom of a long popup,
   hinting there is more to scroll. JS fades it out once scrolled to the end. */
.scroll-cue {
  position: sticky;
  bottom: 4px;
  display: flex;
  justify-content: center;
  margin-top: 6px;
  pointer-events: none; /* clicks pass through to the content underneath */
  transition: opacity 0.25s ease;
}

.scroll-cue.is-hidden {
  opacity: 0;
}

.scroll-cue span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  box-shadow: var(--sh-button);
  animation: cue-bounce 1.4s ease-in-out infinite;
}

@keyframes cue-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-cue span { animation: none; }
}

/* ---- global waiting overlay (mirrors iOS WaitingPaymentView) ---- */
.sn-waiting {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 100; /* above .popup-scrim (50) so it covers any open sheet */
}

.sn-waiting .popup {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 320px;
  text-align: center;
}

.sn-waiting-chip {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: var(--r-card);
  background: var(--chip-bg);
}

.sn-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--sel-bg);
  border-top-color: var(--accent);
  border-radius: var(--r-pill);
  animation: sn-spin 0.8s linear infinite;
}

.sn-waiting-sub {
  color: var(--sub);
  font-size: 14px;
}

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

@media (prefers-reduced-motion: reduce) {
  .sn-spinner { animation-duration: 1.6s; }
}

/* the ported referral card renders flush inside a popup (the sheet is the card) */
.popup .ref-info {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

/* ---- Unlimited period rows (popup): emoji · title · price chip · best badge ---- */
.per-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-tier);
  text-align: left;
}

.per-row:active {
  transform: scale(0.99);
  background: var(--on-bg);
}

.per-emoji {
  font-size: 22px;
  line-height: 1;
}

.per-main {
  display: flex;
  flex-direction: column;
  margin-right: auto; /* push the price chip to the right edge */
}

.per-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.per-len {
  font-size: 12.5px;
  color: var(--sub);
  margin-top: 1px;
}

.per-price {
  padding: 6px 12px;
  background: var(--chip-bg);
  color: var(--accent);
  border-radius: var(--r-chip);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

.per-best {
  position: absolute;
  top: -9px;
  right: 12px;
  padding: 3px 9px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 800;
  box-shadow: var(--sh-secondary);
}

.popup-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 6px;
}

.popup-body {
  font-size: 14px;
  color: var(--sub);
}

/* every popup's cancel/close is a bounded button set apart from the content */
.popup [data-popup-close] {
  margin-top: 10px;
}

/* hidden until an island toggles it */
[hidden] {
  display: none !important;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--sh-button);
  z-index: 60;
}

/* ---- feature chips row (welcome) ---- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* ---- OTP / code field ---- */
.code-field {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.code-cell {
  width: 46px;
  height: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--r-field);
  outline: none;
}

.code-cell:focus {
  border-color: var(--accent);
}

/* ---- support chat ---- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 300px;
  max-height: 56vh;
  overflow-y: auto;
}

.bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: var(--r-card);
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble-bot {
  align-self: flex-start;
  background: var(--chip-bg);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* ---- tier row (period picker) ---- */
.tier-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 13px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-tier);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.tier-row:active {
  transform: scale(0.99);
  background: var(--on-bg);
}

/* ---- text field ---- */
.field {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-field);
  outline: none;
}

.field:focus {
  border-color: var(--accent);
}

.field::placeholder {
  color: var(--ph);
}
