/* ==========================================================================
   Rouhi — OTP Login / Signup (standalone full-screen page, no header/footer)
   Self-contained: does not rely on Tailwind utilities. Tokens reference the
   theme CSS vars (from dist.css) with hard fallbacks. RTL, sharp corners,
   brand-orange accent.
   ========================================================================== */

:root {
    --otp-accent:        var(--color-accent, #f07828);
    --otp-accent-dark:   #bb4711;
    --otp-accent-soft:   rgba(240, 120, 40, 0.08);
    --otp-accent-ring:   rgba(240, 120, 40, 0.16);
    --otp-dark:          var(--color-dark, #000000);
    --otp-body:          var(--color-body, #727272);
    --otp-muted:         #8a8f98;
    --otp-border:        var(--color-border, #d9d9d9);
    --otp-border-strong: #c9ccd1;
    --otp-bg:            #f6f6f6;
    --otp-card:          #ffffff;
    --otp-danger:        #d64545;
    --otp-success:       #1aa179;
    --otp-font:          "IRANSansX", Tahoma, sans-serif;
    --otp-font-title:    "Ravi", "IRANSansX", Tahoma, sans-serif;
}

/* ---- Page shell -------------------------------------------------------- */
html.otp-html,
body.otp-page {
    height: 100%;
    margin: 0;
}

body.otp-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    box-sizing: border-box;
    font-family: var(--otp-font);
    color: var(--otp-body);
    background-color: var(--otp-bg);
    background-image:
        radial-gradient(120% 90% at 100% 0%, var(--otp-accent-soft) 0%, transparent 42%),
        radial-gradient(110% 80% at 0% 100%, rgba(240, 120, 40, 0.05) 0%, transparent 45%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.otp-page * { box-sizing: border-box; }

/* faint grid behind the card */
body.otp-page::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(transparent 31px, rgba(0, 0, 0, 0.018) 32px),
        linear-gradient(90deg, transparent 31px, rgba(0, 0, 0, 0.018) 32px);
    background-size: 32px 32px;
    pointer-events: none;
    z-index: 0;
}

/* ---- Card -------------------------------------------------------------- */
.otp-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 430px;
    background: var(--otp-card);
    border: 1px solid var(--otp-border);
    box-shadow:
        0 1px 2px rgba(16, 24, 40, 0.04),
        0 12px 40px -12px rgba(16, 24, 40, 0.16);
    padding: 40px 34px 30px;
    overflow: hidden;
}

@media (max-width: 480px) {
    body.otp-page { padding: 0; align-items: stretch; }
    .otp-card {
        max-width: none;
        min-height: 100dvh;
        border: 0;
        box-shadow: none;
        padding: 40px 22px 28px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

/* ---- Brand ------------------------------------------------------------- */
.otp-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 26px;
}
.otp-brand img { height: 54px; width: auto; }

/* ---- Steps (animated swap) -------------------------------------------- */
.otp-step { display: none; }
.otp-step.is-active {
    display: block;
    animation: otp-step-in 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes otp-step-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Headings ---------------------------------------------------------- */
.otp-title {
    font-family: var(--otp-font-title);
    font-weight: 700;
    font-size: 1.32rem;
    color: var(--otp-dark);
    margin: 0 0 18px;
    text-align: center;
}
.otp-lead {
    font-size: 0.9rem;
    line-height: 1.9;
    color: var(--otp-body);
    margin: 0 0 24px;
    text-align: center;
}
.otp-lead strong { color: var(--otp-dark); font-weight: 700; }

/* ---- Step header (back + edit) ---------------------------------------- */
.otp-step-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.otp-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--otp-border);
    background: #fff;
    color: var(--otp-body);
    cursor: pointer;
    transition: color 0.18s, border-color 0.18s, background 0.18s;
    flex-shrink: 0;
}
.otp-back:hover { color: var(--otp-accent); border-color: var(--otp-accent); }
.otp-back svg { width: 18px; height: 18px; }
.otp-step-head .otp-title { margin: 0; flex: 1; text-align: start; font-size: 1.15rem; }

/* ---- Phone field ------------------------------------------------------- */
.otp-field { margin-bottom: 18px; }
.otp-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--otp-border-strong);
    background: #fff;
    transition: border-color 0.18s, box-shadow 0.18s;
    direction: ltr;
}
.otp-input-wrap:focus-within {
    border-color: var(--otp-accent);
    box-shadow: 0 0 0 4px var(--otp-accent-ring);
}
.otp-input-wrap.is-invalid {
    border-color: var(--otp-danger);
    box-shadow: 0 0 0 4px rgba(214, 69, 69, 0.12);
}
.otp-prefix {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px 0 14px;
    height: 54px;
    color: var(--otp-muted);
    font-size: 0.92rem;
    border-inline-end: 1px solid var(--otp-border);
    user-select: none;
    white-space: nowrap;
}
.otp-prefix svg { width: 18px; height: 18px; }
.otp-input-wrap input {
    flex: 1;
    height: 54px;
    border: 0;
    outline: 0;
    background: transparent;
    padding: 0 14px;
    font-size: 1.05rem;
    letter-spacing: 0.06em;
    color: var(--otp-dark);
    font-family: inherit;
    width: 100%;
    min-width: 0;
}
.otp-input-wrap input::placeholder { color: #b4b9c0; letter-spacing: 0.04em; }

/* ---- OTP segmented boxes ---------------------------------------------- */
.otp-code {
    display: flex;
    justify-content: center;
    gap: 10px;
    direction: ltr; /* code reads left→right; box 0 is leftmost */
    margin: 6px 0 14px;
}
.otp-code input {
    width: 48px;
    height: 58px;
    text-align: center;
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--otp-dark);
    border: 1px solid var(--otp-border-strong);
    background: #fff;
    outline: 0;
    transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
    font-family: inherit;
    -moz-appearance: textfield;
    padding: 0;
}
.otp-code input::-webkit-outer-spin-button,
.otp-code input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.otp-code input:focus {
    border-color: var(--otp-accent);
    box-shadow: 0 0 0 4px var(--otp-accent-ring);
}
.otp-code input.is-filled {
    border-color: var(--otp-accent);
    background: var(--otp-accent-soft);
}
.otp-code.is-invalid input {
    border-color: var(--otp-danger);
    background: rgba(214, 69, 69, 0.05);
}
@media (max-width: 360px) {
    .otp-code { gap: 7px; }
    .otp-code input { width: 42px; height: 52px; font-size: 1.35rem; }
}

.otp-code.is-invalid { animation: otp-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
@keyframes otp-shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}

/* ---- Resend ------------------------------------------------------------ */
.otp-resend {
    text-align: center;
    font-size: 0.84rem;
    color: var(--otp-muted);
    margin-bottom: 22px;
    min-height: 20px;
}
.otp-resend button {
    background: none;
    border: 0;
    color: var(--otp-accent);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}
.otp-resend button:hover { color: var(--otp-accent-dark); }
.otp-resend .otp-timer { color: var(--otp-dark); font-weight: 700; }

/* ---- Submit button ----------------------------------------------------- */
.otp-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 52px;
    border: 0;
    background: var(--otp-accent);
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s;
}
.otp-btn:hover { background: var(--otp-dark); }
.otp-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.otp-btn .otp-spinner { display: none; }
.otp-btn.is-loading .otp-btn-label { visibility: hidden; }
.otp-btn.is-loading .otp-spinner {
    display: block;
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: otp-spin 0.7s linear infinite;
}
@keyframes otp-spin { to { transform: rotate(360deg); } }

/* ---- Feedback message -------------------------------------------------- */
.otp-msg {
    font-size: 0.82rem;
    line-height: 1.7;
    margin: 14px 0 0;
    text-align: center;
    min-height: 18px;
}
.otp-msg.is-error { color: var(--otp-danger); }
.otp-msg.is-success { color: var(--otp-success); }

/* ---- Terms ------------------------------------------------------------- */
.otp-terms {
    margin: 22px 0 0;
    font-size: 0.76rem;
    line-height: 1.9;
    color: var(--otp-muted);
    text-align: center;
}
.otp-terms a { color: var(--otp-accent); text-decoration: none; }
.otp-terms a:hover { color: var(--otp-accent-dark); }

/* ---- Success overlay (post-verify) ------------------------------------ */
.otp-done {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 18px 0 8px;
}
.otp-done.is-active { display: flex; animation: otp-step-in 0.3s both; }
.otp-done-mark {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(26, 161, 121, 0.1);
    color: var(--otp-success);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.otp-done-mark svg { width: 32px; height: 32px; }
.otp-done-mark svg path {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    animation: otp-check 0.5s 0.1s forwards cubic-bezier(0.65, 0, 0.45, 1);
}
@keyframes otp-check { to { stroke-dashoffset: 0; } }
.otp-done p { font-size: 0.92rem; color: var(--otp-dark); font-weight: 700; margin: 0; }

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .otp-step.is-active,
    .otp-done.is-active,
    .otp-code.is-invalid,
    .otp-done-mark svg path { animation: none; }
    .otp-done-mark svg path { stroke-dashoffset: 0; }
}
