/* ============================================================
   CARD PAYMENT — SANDBOX DEMO
   Чистый чекаут-UI: карта-превью, форма, 3DS OTP, результат.
   ============================================================ */

:root {
  --bg: #0f1225;
  --bg-2: #171a35;
  --surface: #ffffff;
  --ink: #1a1f36;
  --muted: #6b7189;
  --line: #e6e8f0;
  --primary: #635bff;         /* indigo — типичный чекаут-акцент */
  --primary-deep: #4f46e5;
  --ok: #12b76a;
  --fail: #f04438;
  --amber: #f59e0b;
  --radius: 16px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "Roboto Mono", ui-monospace, monospace;
}

* , *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(60% 50% at 15% 0%, #2a2f5c 0%, transparent 60%),
    radial-gradient(50% 50% at 100% 100%, #3a2260 0%, transparent 55%),
    var(--bg);
  padding: 0 16px 48px;
}
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }

/* ---------- test-mode ribbon ---------- */
.test-ribbon {
  text-align: center;
  background: repeating-linear-gradient(45deg, #3a2f00, #3a2f00 12px, #4a3d00 12px, #4a3d00 24px);
  color: #ffd666;
  font-size: .82rem;
  padding: 8px 12px;
  margin: 0 -16px 32px;
  letter-spacing: .01em;
}
.test-ribbon strong { color: #ffe9a6; }

/* ---------- layout ---------- */
.pay-wrap {
  max-width: 940px;
  margin: 0 auto;
  display: grid;
  gap: 24px;
  align-items: start;
}
@media (min-width: 820px) {
  .pay-wrap { grid-template-columns: 420px 1fr; padding-top: 24px; }
}

.pay-card {
  background: var(--surface);
  border-radius: 22px;
  padding: clamp(20px, 4vw, 30px);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .35);
}

/* ---------- header ---------- */
.pay-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.merchant { color: var(--muted); font-size: .82rem; font-weight: 600; }
.pay-amount { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.secure-badge {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--ok); font-size: .78rem; font-weight: 700;
  background: rgba(18, 183, 106, .1); padding: 5px 10px; border-radius: 999px;
}

/* ============================================================
   CARD PREVIEW (flip)
   ============================================================ */
.card-preview {
  position: relative;
  height: 210px;
  margin-bottom: 26px;
  perspective: 1200px;
}
.card-face {
  position: absolute; inset: 0;
  border-radius: 18px;
  padding: 20px 22px;
  color: #fff;
  backface-visibility: hidden;
  transition: transform .6s cubic-bezier(.4, .2, .2, 1);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .3);
  background: linear-gradient(135deg, #434a68, #23283f);
  overflow: hidden;
}
.card-preview[data-brand="visa"] .card-front,
.card-preview[data-brand="visa"] .card-back { background: linear-gradient(135deg, #2b4bd4, #1a2a6b); }
.card-preview[data-brand="mastercard"] .card-front,
.card-preview[data-brand="mastercard"] .card-back { background: linear-gradient(135deg, #d13b2f, #7a1e33); }
.card-preview[data-brand="amex"] .card-front,
.card-preview[data-brand="amex"] .card-back { background: linear-gradient(135deg, #1a9bd7, #0c5a8a); }
.card-preview[data-brand="discover"] .card-front,
.card-preview[data-brand="discover"] .card-back { background: linear-gradient(135deg, #e88a1a, #9c4d0a); }

.card-front { display: flex; flex-direction: column; }
.card-back { transform: rotateY(180deg); }
.card-preview.flipped .card-front { transform: rotateY(180deg); }
.card-preview.flipped .card-back { transform: rotateY(360deg); }

.card-shine {
  position: absolute; inset: 0;
  background: radial-gradient(70% 50% at 80% 0%, rgba(255,255,255,.22), transparent 60%);
  pointer-events: none;
}
.card-top { display: flex; align-items: center; justify-content: space-between; }
.card-chip {
  width: 42px; height: 32px; border-radius: 7px;
  background: linear-gradient(135deg, #f6d365, #c79a2e);
  position: relative;
}
.card-chip::after {
  content: ""; position: absolute; inset: 6px 8px;
  border: 1px solid rgba(0,0,0,.25); border-radius: 3px;
}
.card-brand { font-weight: 800; font-size: 1.05rem; letter-spacing: .04em; text-transform: uppercase; opacity: .95; }
.card-number {
  font-family: var(--mono); font-size: 1.4rem; letter-spacing: .06em;
  margin: auto 0; text-shadow: 0 1px 2px rgba(0,0,0,.3); word-spacing: 2px;
}
.card-bottom { display: flex; justify-content: space-between; gap: 16px; }
.card-cap { display: block; font-size: .58rem; text-transform: uppercase; letter-spacing: .12em; opacity: .6; }
.card-val { font-family: var(--mono); font-size: .9rem; margin-top: 3px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-magstripe { position: absolute; left: 0; right: 0; top: 22px; height: 40px; background: #111524; }
.card-cvv-row { position: absolute; left: 22px; right: 22px; top: 82px; display: flex; justify-content: flex-end; }
.card-cvv {
  font-family: var(--mono); background: #fff; color: #111;
  padding: 6px 14px; border-radius: 5px; font-size: .95rem; letter-spacing: .1em;
}

/* ============================================================
   FORM
   ============================================================ */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-wrap { position: relative; display: block; }
.field input, .field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fbfbfd;
  resize: vertical;
}
.field input::placeholder, .field textarea::placeholder { color: #b7bccb; }
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 91, 255, .14); background: #fff; }

#card-number { padding-right: 84px; font-family: var(--mono); letter-spacing: .04em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.brand-icon {
  position: absolute; top: 50%; right: 12px; transform: translateY(-50%);
  font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 8px; border-radius: 6px; color: #fff; pointer-events: none;
}
.brand-unknown { display: none; }
.brand-visa { background: #1a3fd4; }
.brand-mastercard { background: #d13b2f; }
.brand-amex { background: #1a9bd7; }
.brand-discover { background: #e88a1a; }
.brand-diners { background: #5b6270; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border-radius: 12px;
  padding: 15px 20px;
  font-weight: 700; font-size: 1rem;
  transition: transform .12s, box-shadow .15s, background .15s;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 20px rgba(99, 91, 255, .35); }
.btn-primary:hover:not(:disabled) { background: var(--primary-deep); transform: translateY(-1px); }
.btn-primary:active { transform: scale(.99); }
.btn:disabled { opacity: .85; cursor: default; }
.btn.is-loading::before {
  content: ""; width: 17px; height: 17px; border-radius: 50%;
  border: 2.4px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-error {
  display: none; color: var(--fail); font-size: .84rem; font-weight: 600;
  margin: 4px 0 12px; padding: 9px 12px; background: rgba(240, 68, 56, .08); border-radius: 9px;
}
.form-error.show { display: block; }

.pci-note { margin-top: 14px; color: var(--muted); font-size: .74rem; line-height: 1.5; text-align: center; }

/* ============================================================
   OTP STEP
   ============================================================ */
#step-otp { text-align: center; }
.link-back {
  color: var(--muted); font-weight: 600; font-size: .86rem;
  float: left; padding: 0; margin-bottom: 4px;
}
.otp-illus {
  display: inline-grid; place-items: center; width: 58px; height: 58px;
  border-radius: 16px; background: rgba(99, 91, 255, .1); color: var(--primary);
  margin: 8px auto 14px;
}
.otp-title { font-size: 1.3rem; font-weight: 800; }
.otp-sub { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.otp-sub b { color: var(--ink); font-family: var(--mono); }

.otp-resend-row { margin-top: 16px; color: var(--muted); font-size: .85rem; }
.link-btn { color: var(--primary); font-weight: 700; }
.link-btn:hover { text-decoration: underline; }

/* ============================================================
   RESULT
   ============================================================ */
.step-result { text-align: center; padding: 10px 0 6px; }
.result-icon {
  display: inline-grid; place-items: center; width: 76px; height: 76px;
  border-radius: 50%; color: #fff; margin: 6px auto 16px;
  animation: pop .45s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.result-ok { background: var(--ok); box-shadow: 0 12px 30px rgba(18, 183, 106, .4); }
.result-fail { background: var(--fail); box-shadow: 0 12px 30px rgba(240, 68, 56, .4); }
.result-title { font-size: 1.4rem; font-weight: 800; }
.result-sub { color: var(--muted); margin-top: 6px; margin-bottom: 20px; }
.receipt {
  text-align: left; background: #f7f8fc; border-radius: 12px; padding: 14px 16px; margin-bottom: 20px;
  display: grid; gap: 10px;
}
.receipt > div { display: flex; justify-content: space-between; gap: 12px; font-size: .85rem; }
.receipt span { color: var(--muted); }
.receipt b { font-family: var(--mono); font-weight: 600; }

/* ============================================================
   TEST PANEL
   ============================================================ */
.test-panel {
  color: #cfd3ee;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 18px;
  padding: 20px 22px;
}
.test-panel h3 { font-size: .95rem; color: #fff; margin-bottom: 12px; }
.test-panel ul { display: grid; gap: 8px; }
.test-panel li { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: .82rem; }
.test-panel code {
  font-family: var(--mono); background: rgba(255, 255, 255, .08);
  padding: 3px 8px; border-radius: 6px; color: #a5f3c9; font-size: .82rem;
}
.test-panel li span { color: #9aa0c4; }
.test-hint { margin-top: 14px; font-size: .78rem; color: #9aa0c4; line-height: 1.6; }
.test-hint code { color: #ffd666; }

/* ============================================================
   LOADING (inline, same page as payment-form)
   ============================================================ */
#loading { display: none; text-align: center; padding: 30px 0 10px; }
#loading.is-visible { display: block; }
.pay-loading__spinner {
  display: inline-block; width: 40px; height: 40px; margin-bottom: 14px;
  border-radius: 50%; border: 3.5px solid rgba(99, 91, 255, .16); border-top-color: var(--primary);
  animation: spin .75s linear infinite;
}
#loading p { color: var(--muted); font-weight: 600; font-size: .92rem; }

/* ============================================================
   SINGLE CODE INPUT (id contract: #code)
   ============================================================ */
.otp-single-field { max-width: 240px; margin: 22px auto 6px; }
.otp-single {
  text-align: center; letter-spacing: .55em; font-family: var(--mono);
  font-size: 1.4rem; font-weight: 700; padding-left: 1.4em !important;
}

/* ============================================================
   BLOCKED overlay (covers everything, all steps)
   ============================================================ */
.blocked-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(15, 18, 37, .88); backdrop-filter: blur(4px);
}
.blocked-overlay.is-visible { display: flex; }
.blocked-box {
  background: var(--surface); border-radius: 22px; padding: clamp(24px, 5vw, 34px);
  max-width: 380px; width: 100%; text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}

@media (max-width: 819px) { .test-panel { order: 2; } }
