/* =========================================================================
   RELY PAY — Checkout stylesheet
   Concept: the card reads like the display of a physical payment terminal —
   dim counter lighting behind it, a status LED that tells you the
   connection is live, and a progress ring around the brand mark that fills
   as you move through identify → verify → pay. No JS changes required:
   step progress is driven purely by :has() watching which panel is visible.
   ========================================================================= */

:root {
    /* --- Brand --- */
    --navy-950: #0E1826;
    --navy-900: #14233A;
    --navy-800: #1A2E4A;
    --navy-700: #24405F;
    --green-600: #0C7F4C;
    --green-500: #0F9B5E;
    --green-400: #33B279;
    --green-glow: rgba(15, 155, 94, 0.45);

    /* --- Surface / text --- */
    --paper: #F6F4EF;
    --card: #FFFFFF;
    --mint: #EAF5EF;
    --ink: #16212E;
    --slate: #5B6B7C;
    --slate-soft: #8493A3;
    --line: #E4E8EC;
    --line-soft: #EEF1F3;
    --error: #B8402B;
    --error-bg: #FBEDE9;

    /* --- Type --- */
    --f-display: 'Space Grotesk', 'Helvetica Neue', sans-serif;
    --f-body: 'Inter', 'Helvetica Neue', sans-serif;
    --f-mono: 'IBM Plex Mono', 'Courier New', monospace;

    /* --- Shape / motion --- */
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    position: relative;
    isolation: isolate;
    font-family: var(--f-body);
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

body::before,
body::after {
    content: "";
    position: fixed;
    left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 0;
}

body::before {
    top: 0;
    height: 205px;
    background:
        radial-gradient(65% 55% at 14% -12%, rgba(15, 155, 94, 0.20), transparent 62%),
        radial-gradient(75% 65% at 100% 0%, rgba(47, 78, 112, 0.58), transparent 58%),
        linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 42%, var(--navy-950) 100%);
}

body::after {
    top: 125px;
    left: -8%;
    width: 116%;
    height: 155px;
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    background:
        radial-gradient(70% 90% at 50% 0%, rgba(26, 46, 74, 0.9), transparent 75%),
        linear-gradient(180deg, var(--navy-900) 0%, #09131f 100%);
}

.hidden {
    display: none !important;
}

/* Ambient counter-light glow behind the terminal card */
.bg-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background:
        radial-gradient(38% 32% at 50% 8%, var(--green-glow), transparent 70%);
    opacity: 0.55;
    filter: blur(6px);
}

.shell {
    position: relative;
    z-index: 2;
    max-width: 880px;
    margin: 0 auto;
    padding: 40px 20px 56px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------------------------------------------------------------------
   Header / brand — the "R" sits in a progress ring that fills as the
   checkout advances. Driven by :has() against the step panels below,
   so no script changes are needed.
   --------------------------------------------------------------------- */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
    font-family: var(--f-display);
    color: #EAF0F6;
}

.brand-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-picker select {
    appearance: none;
    min-height: 34px;
    padding: 0 30px 0 11px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    color: #EAF0F6;
    background-color: rgba(255, 255, 255, 0.06);
    background-image: linear-gradient(45deg, transparent 50%, #B9C6D4 50%), linear-gradient(135deg, #B9C6D4 50%, transparent 50%);
    background-position: calc(100% - 14px) 14px, calc(100% - 10px) 14px;
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
    font: 500 12px var(--f-body);
    cursor: pointer;
}

.language-picker select:focus-visible {
    outline: 2px solid var(--green-400);
    outline-offset: 2px;
}

.language-picker option { color: var(--ink); background: #fff; }

.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-mark {
    --progress: 8%;
    overflow: hidden;
    position: relative;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 17px;
    color: var(--navy-900);
    background: var(--paper);
    background-image: conic-gradient(var(--green-400) var(--progress), rgba(255, 255, 255, 0.16) 0);
    padding: 3px;
    transition: background-image 0.6s var(--ease);
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--paper);
    z-index: 0;
}

.brand-mark img {
    position: relative;
    z-index: 1;
    width: 34px;
    height: 34px;
    max-width: 34px;
    max-height: 34px;
    display: block;
    border-radius: 50%;
    object-fit: contain;
}

.brand-mark {
    font-family: var(--f-display);
}

.brand>span:nth-child(2) {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.secure {
    margin-left: 0;
    display: inline-flex;
    align-items: center;
    font-family: var(--f-body);
    font-size: 12.5px;
    font-weight: 500;
    color: #B9C6D4;
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
}

/* ---------------------------------------------------------------------
   Cards & state screens (loading / error / completed)
   --------------------------------------------------------------------- */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: 0 1px 2px rgba(14, 24, 38, 0.04), 0 24px 48px -24px rgba(14, 24, 38, 0.35);
    animation: rise 0.5s var(--ease) both;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.state {
    margin: auto;
    width: 100%;
    max-width: 420px;
    padding: 44px 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.state h1 {
    font-family: var(--f-display);
    font-size: 20px;
    margin: 4px 0 2px;
}

.state p {
    color: var(--slate);
    font-size: 14.5px;
    line-height: 1.55;
    margin: 0 0 8px;
}

.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid var(--mint);
    border-top-color: var(--green-500);
    animation: spin 0.8s linear infinite;
    margin-bottom: 10px;
}

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

.state-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.error-icon {
    background: var(--error-bg);
    color: var(--error);
}

.success-icon {
    background: var(--mint);
    color: var(--green-600);
}

/* ---------------------------------------------------------------------
   Checkout grid — summary + payment terminal
   --------------------------------------------------------------------- */
.checkout-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}

/* --- Summary card --- */
.summary {
    padding: 28px 26px 24px;
    position: sticky;
    top: 24px;
}

.merchant-name {
    font-family: var(--f-display);
    font-size: 15px;
    font-weight: 600;
    color: var(--navy-800);
    margin: 0 0 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line-soft);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.merchant-name-label {
    display: block;
    font-family: var(--f-mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--slate-soft);
    font-weight: 500;
    margin-bottom: 4px;
}

.eyebrow {
    font-family: var(--f-mono);
    font-size: 11.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--slate-soft);
    margin: 0 0 6px;
}

.amount {
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 38px;
    color: var(--navy-800);
    letter-spacing: -0.01em;
    line-height: 1.05;
    margin-bottom: 14px;
    position: relative;
    display: inline-block;
}

.amount::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -6px;
    height: 3px;
    width: 46px;
    background: var(--green-500);
    border-radius: 2px;
}

.summary h1 {
    font-family: var(--f-display);
    font-size: 16px;
    font-weight: 600;
    color: var(--slate);
    margin: 18px 0 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line-soft);
}

.summary dl {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.summary dl>div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.summary dt {
    font-size: 13px;
    color: var(--slate);
}

.summary dd {
    margin: 0;
    font-family: var(--f-mono);
    font-size: 13px;
    color: var(--ink);
    text-align: right;
}

.merchant-note {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--line-soft);
    font-size: 12px;
    line-height: 1.5;
    color: var(--slate-soft);
}

/* --- In-store payment QR --- */
.payment-qr {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line-soft);
    text-align: center;
}

.payment-qr h2 {
    margin: 0 0 5px;
    color: var(--ink);
    font-family: var(--f-display);
    font-size: 15px;
    font-weight: 600;
}

.payment-qr > p {
    margin: 0 auto 12px;
    color: var(--slate);
    font-size: 12px;
    line-height: 1.45;
}

.payment-qr-code {
    display: block;
    width: min(100%, 260px);
    height: auto;
    margin: 0 auto 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
}

.payment-url {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--green-500);
    border-radius: var(--radius-sm);
    background: var(--mint);
    color: var(--green-600);
    font-size: 12.5px;
    font-weight: 650;
    transition: background .15s var(--ease), color .15s var(--ease), transform .15s var(--ease);
}

.payment-url:hover { background: #dcf0e5; }
.payment-url:active { transform: translateY(1px); }
.payment-url.copied { background: var(--green-500); color: #fff; }

.download-qr {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    width: 100%; min-height: 42px; margin-top: 8px; padding: 10px 14px;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: #fff; color: var(--ink); font-size: 12.5px; font-weight: 650;
}
.download-qr:hover { border-color: var(--green-500); color: var(--green-600); background: var(--mint); }
.download-qr:active { transform: translateY(1px); }
.download-icon { width: 15px; height: 15px; position: relative; border-bottom: 1.5px solid currentColor; }
.download-icon::before { content: ""; position: absolute; left: 7px; top: 0; width: 1.5px; height: 10px; background: currentColor; }
.download-icon::after { content: ""; position: absolute; left: 4px; top: 5px; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }

.copy-icon { width: 15px; height: 15px; border: 1.5px solid currentColor; border-radius: 3px; position: relative; }
.copy-icon::before { content: ""; position: absolute; width: 10px; height: 10px; left: -5px; top: 3px; border: 1.5px solid currentColor; border-radius: 3px; background: inherit; }
.copy-status { display: block; min-height: 16px; margin-top: 4px; color: var(--slate-soft); font-size: 10.5px; }

.payment-url:focus-visible, .download-qr:focus-visible {
    border-radius: 3px;
    outline: 2px solid var(--green-500);
    outline-offset: 3px;
}

.qr-unavailable {
    margin-bottom: 0 !important;
    padding: 10px;
    border-radius: var(--radius-sm);
    color: var(--error) !important;
    background: var(--error-bg);
}

/* --- Payment panel --- */
.payment-panel {
    padding: 30px 30px 28px;
    min-height: 380px;
}

.step {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--mint);
    color: var(--green-600);
    font-family: var(--f-mono);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 10px;
}

.payment-panel h2 {
    font-family: var(--f-display);
    font-size: 19px;
    margin: 0 0 6px;
}

.payment-panel>div>p {
    color: var(--slate);
    font-size: 14px;
    margin: 0 0 20px;
    line-height: 1.5;
}

#payer {
    font-family: var(--f-mono);
    font-size: 13px;
    background: var(--mint);
    color: var(--green-600);
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    margin-bottom: 18px !important;
}

/* --- Forms --- */
form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 18px;
}

form input {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 13px 14px;
    font-family: var(--f-body);
    font-size: 15px;
    color: var(--ink);
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}

form input::placeholder {
    color: var(--slate-soft);
}

form input:hover {
    border-color: #C9D3DC;
}

form input:focus-visible {
    border-color: var(--green-500);
    background: var(--card);
    box-shadow: 0 0 0 4px rgba(15, 155, 94, 0.14);
}

#otp {
    letter-spacing: 0.35em;
    font-family: var(--f-mono);
    font-size: 20px;
    text-align: center;
}

#otp-hint {
    font-family: var(--f-body) !important;
    letter-spacing: normal !important;
}

.otp-countdown {
    display: inline-block;
    margin: -10px 0 18px !important;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--mint);
    color: var(--green-600) !important;
    font-family: var(--f-mono) !important;
    font-size: 12.5px !important;
    line-height: 1.3 !important;
}

/* --- Buttons --- */
button {
    font-family: var(--f-body);
    font-weight: 600;
    font-size: 15px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), opacity 0.15s var(--ease);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--green-500);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.primary {
    width: 100%;
    padding: 14px 18px;
    color: #fff;
    background: linear-gradient(180deg, var(--green-500), var(--green-600));
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 10px 22px -10px rgba(15, 155, 94, 0.65);
}

.primary:hover {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 14px 26px -10px rgba(15, 155, 94, 0.75);
}

.secondary {
    padding: 11px 22px;
    color: var(--navy-800);
    background: var(--mint);
}

.secondary:hover {
    background: #DCF0E5;
}

.link-button {
    display: block;
    margin: 14px auto 0;
    padding: 4px;
    background: none;
    color: var(--slate);
    font-size: 13px;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--line);
}

.link-button:hover {
    color: var(--green-600);
    text-decoration-color: var(--green-500);
}

/* --- Wallet selection ---
   Matches the real app.js markup:
   <label class="wallet">
     <input type="radio" name="wallet" value="...">
     <span class="wallet-copy">
       <span class="wallet-title">Portefeuille HTG</span><br>
       <span class="wallet-balance">Disponible : HTG 4 250,00</span>
     </span>
   </label> */
.wallets {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.wallet {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--paper);
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.wallet:hover {
    border-color: var(--green-400);
}

.wallet:has(input:checked) {
    border-color: var(--green-500);
    background: var(--mint);
    box-shadow: 0 0 0 3px rgba(15, 155, 94, 0.12);
}

.wallet input[type="radio"] {
    width: 17px;
    height: 17px;
    accent-color: var(--green-500);
    margin: 0;
    flex-shrink: 0;
}

.wallet-copy {
    display: block;
    line-height: 1.5;
}

.wallet-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.wallet-balance {
    font-family: var(--f-mono);
    font-size: 12.5px;
    color: var(--slate);
}

/* --- Errors --- */
.form-error {
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--error-bg);
    color: var(--error);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    line-height: 1.45;
}

footer {
    text-align: center;
    color: #A9B7C4;
    font-size: 12px;
    margin-top: 32px;
}

/* ---------------------------------------------------------------------
   Progress ring logic — no JS required. As each step panel becomes
   visible, :has() drives the conic-gradient fill on the brand mark.
   --------------------------------------------------------------------- */
body:has(#otp-step:not(.hidden)) .brand-mark {
    --progress: 50%;
}

body:has(#wallet-step:not(.hidden)) .brand-mark {
    --progress: 82%;
}

body:has(#completed:not(.hidden)) .brand-mark {
    --progress: 100%;
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 760px) {
    .shell {
        padding: 24px 16px 40px;
    }

    .checkout-grid {
        grid-template-columns: 1fr;
    }

    .summary {
        position: static;
        padding: 24px 22px;
    }

    .payment-panel {
        padding: 26px 22px;
    }

    .amount {
        font-size: 32px;
    }

    .secure {
        font-size: 11.5px;
        padding: 5px 10px 5px 9px;
    }

    .brand { flex-wrap: wrap; }
    .brand-actions { gap: 6px; }
    .language-picker select { max-width: 130px; }
}

@media (max-width: 420px) {
    .brand>span:nth-child(2) {
        display: none;
    }

    .secure { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

@media print {
    body,
    body::before,
    body::after {
        background: #fff !important;
    }

    .bg-glow,
    .brand-actions,
    .payment-panel,
    footer {
        display: none !important;
    }

    .shell {
        max-width: 420px;
        padding: 16px;
    }

    .brand {
        color: var(--ink);
        margin-bottom: 16px;
    }

    .checkout-grid {
        display: block;
    }

    .summary {
        position: static;
        box-shadow: none;
    }

    .payment-qr-code {
        width: 260px;
    }
}
