/**
 * Popup design — modals, pickers, overlays
 */

/* ── Overlay — همیشه وسط viewport ── */
.spicker-overlay,
.jalali-overlay,
.step-modal,
.admin-modal {
    visibility: hidden;
    opacity: 0;
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: none;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.spicker-overlay { z-index: 1150; }
.jalali-overlay { z-index: 1100; }
.step-modal { z-index: 1200; }
.admin-modal { z-index: 1300; }

.step-modal[hidden] {
    display: none !important;
}

.spicker-overlay.is-open,
.jalali-overlay.is-open,
.step-modal.active,
.admin-modal.is-open {
    visibility: visible;
    opacity: 1;
}

html.spicker-open,
body.spicker-open,
html.jalali-open,
body.jalali-open,
html.step-modal-open,
body.step-modal-open,
body.admin-modal-open {
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

/* ── Shell — مرکز صفحه در همه اندازه‌ها ── */
.spicker-popup,
.jalali-popup,
.admin-modal-shell {
    position: relative;
    width: min(100%, 440px);
    max-height: min(88dvh, 600px);
    margin: auto;
    display: flex;
    flex-direction: column;
    background: rgba(14, 14, 14, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    transform: scale(0.96);
    opacity: 0;
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
    overflow: hidden;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    direction: rtl;
    text-align: right;
}

/* مودال‌های تأیید مراحل — ارتفاع بر اساس محتوا، بدون اسکرول داخلی */
.step-modal-box {
    position: relative;
    width: min(100%, 440px);
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    margin: auto;
    display: flex;
    flex-direction: column;
    background: rgba(14, 14, 14, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    transform: scale(0.96);
    opacity: 0;
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
    overflow: visible;
    flex-shrink: 0;
    direction: rtl;
    text-align: right;
}

.step-modal-box--wide {
    width: min(100%, 480px);
}

.spicker-overlay.is-open .spicker-popup,
.jalali-overlay.is-open .jalali-popup,
.step-modal.active .step-modal-box,
.admin-modal.is-open .admin-modal-shell {
    transform: scale(1);
    opacity: 1;
}

.spicker-popup--wide { max-width: 480px; }

/* ── Handle — مخفی (مودال وسط صفحه) ── */
.spicker-handle,
.jalali-handle,
.step-modal-handle {
    display: none;
}

/* ── Header ── */
.spicker-head,
.jalali-bar,
.step-modal-head,
.admin-modal-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px 10px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: transparent;
}

.spicker-head-icon,
.jalali-head-icon,
.step-modal-head-icon {
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    background: transparent;
    border: none;
    color: var(--gold);
    flex-shrink: 0;
    opacity: 0.9;
}

.spicker-popup--map .spicker-head-icon,
.admin-modal-head .jalali-head-icon {
    background: transparent;
    border: none;
    color: var(--muted);
}

.spicker-head-icon svg,
.jalali-head-icon svg,
.step-modal-head-icon svg {
    width: 18px;
    height: 18px;
}

.spicker-head-text,
.jalali-head-text,
.step-modal-head-text {
    flex: 1;
    min-width: 0;
    text-align: right;
}

.spicker-head-text h3,
.jalali-head-text h3,
.step-modal-head-text h3 {
    margin: 0;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.4;
    text-align: right;
}

.popup-sub,
.spicker-head-text p,
.jalali-head-text p,
.step-modal-head-text p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.5;
    font-weight: 400;
    text-align: right;
}

.popup-sub[hidden],
.spicker-head-text p[hidden] {
    display: none;
}

/* ── Close ── */
.spicker-close,
.jalali-close,
.step-modal-close,
.admin-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.spicker-close svg,
.jalali-close svg,
.step-modal-close svg,
.admin-modal-close svg {
    width: 18px;
    height: 18px;
}

.spicker-close:hover,
.jalali-close:hover,
.step-modal-close:hover,
.admin-modal-close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

/* ── Body ── */
.admin-modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    text-align: right;
    direction: rtl;
}

.step-modal-body {
    flex: 0 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 10px 14px 12px;
    text-align: right;
    direction: rtl;
}

.step-modal-body .step-confirm-grid {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 14px;
}

@media (max-width: 420px) {
    .step-modal-body .step-confirm-grid {
        grid-template-columns: 1fr;
    }
}

.step-modal-note {
    margin: 12px 0 0;
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.55;
    text-align: right;
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
}

.step-confirm-declaration {
    font-size: 0.78rem;
    line-height: 1.65;
    color: var(--text);
    text-align: right;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    margin-bottom: 8px;
    overflow: visible;
}

.step-confirm-declaration p {
    margin: 0 0 6px;
}

.step-confirm-declaration p:last-child {
    margin-bottom: 0;
}

.step-confirm-declaration strong {
    color: var(--gold-light, #d4af37);
    font-weight: 800;
}

.step-confirm-nid {
    display: inline-block;
    direction: ltr;
    unicode-bidi: embed;
    letter-spacing: 0.03em;
}

.step-confirm-fee {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(212, 175, 55, 0.12) 0%, rgba(212, 175, 55, 0.04) 100%);
    border: 1px solid rgba(212, 175, 55, 0.28);
    text-align: center;
}

.step-confirm-fee__label {
    font-size: 0.76rem;
    color: var(--muted);
    font-weight: 600;
}

.step-confirm-fee__value {
    font-size: clamp(1.2rem, 4.5vw, 1.45rem);
    font-weight: 900;
    color: var(--gold-light, #d4af37);
    line-height: 1.15;
}

.step-confirm-fee__note {
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.5;
}

.step-modal-body--confirm {
    padding-top: 6px;
    padding-bottom: 8px;
}

.step-modal-box--confirm {
    max-width: min(100%, 460px);
}

.step-modal-foot--confirm {
    flex-direction: row-reverse;
    gap: 8px;
}

.step-modal-foot--confirm .btn-next,
.step-modal-foot--confirm .btn-prev {
    width: auto;
    flex: 1;
    min-height: 44px;
}

@media (max-width: 399px) {
    .step-modal-foot--confirm {
        flex-direction: column;
    }

    .step-modal-foot--confirm .btn-next,
    .step-modal-foot--confirm .btn-prev {
        width: 100%;
        flex: none;
        min-height: 44px;
    }
}

.step-modal-foot--confirm .btn-next {
    font-weight: 800;
}

.step-modal-foot--confirm .btn-next:disabled {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

.step-confirm-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-size: 0.78rem;
    line-height: 1.55;
    padding: 8px 10px;
    background: rgba(212, 175, 55, 0.05);
    border: 1px solid rgba(212, 175, 55, 0.22);
    border-radius: 10px;
    margin: 0;
    user-select: none;
}

.step-confirm-check input[type="checkbox"] {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: #d4af37;
    flex-shrink: 0;
}

.step-confirm-check span {
    flex: 1;
}

/* ── Footer ── */
.jalali-popup-foot,
.step-modal-foot {
    display: flex;
    gap: 8px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: transparent;
}

.jalali-popup-foot .jalali-btn,
.step-modal-foot .btn-prev,
.step-modal-foot .btn-next {
    flex: 1;
    min-width: 0;
    min-height: 44px;
}

@media (max-width: 639px) {
    .step-modal-foot,
    .jalali-popup-foot {
        flex-direction: column-reverse;
    }

    .step-modal-foot .btn-prev,
    .step-modal-foot .btn-next,
    .jalali-popup-foot .jalali-btn {
        width: 100%;
        flex: none;
    }
}

/* ── Step finalize summary ── */
.step-finalize-summary {
    display: grid;
    gap: 0;
    margin-top: 0;
}

.step-finalize-summary div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 11px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 0;
    font-size: 0.84rem;
}

.step-finalize-summary div:last-child {
    border-bottom: none;
}

.step-finalize-summary span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 500;
}

.step-finalize-summary strong {
    color: var(--text);
    text-align: left;
    font-size: 0.86rem;
    font-weight: 600;
}

@media (min-width: 640px) {
    .step-modal-handle {
        display: none;
    }
}

/* ── Contract card modal (dashboard / contract flow) ── */
.contract-card-modal-box {
    width: min(100%, 440px);
    max-height: min(88dvh, 560px);
}

.contract-card-modal-body {
    padding-top: 8px;
}

.contract-card-modal-body .step-pay-card-frame {
    margin-bottom: 14px;
}

.contract-card-modal-body .step-pay-info-list {
    gap: 8px;
}

.contract-card-modal-body .step-pay-info-item {
    padding: 10px 12px;
}

/* ── Admin receipt modal ── */
.admin-modal-shell {
    max-width: min(100%, 560px);
}

.admin-modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.admin-modal-body img {
    max-width: 100%;
    max-height: min(62dvh, 520px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.35);
}

/* ── Desktop — centered modal dialog ── */
@media (min-width: 640px) {
    .spicker-overlay,
    .jalali-overlay,
    .step-modal,
    .admin-modal {
        align-items: center;
        justify-content: center;
        padding: 32px 24px;
        padding-top: max(32px, env(safe-area-inset-top));
        padding-bottom: max(32px, env(safe-area-inset-bottom));
    }

    .spicker-popup,
    .jalali-popup,
    .step-modal-box,
    .admin-modal-shell {
        width: min(100%, 440px);
        max-height: min(80dvh, 580px);
        margin: 0 auto;
        border-radius: 18px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow:
            0 0 0 1px rgba(212, 175, 55, 0.06),
            0 24px 64px rgba(0, 0, 0, 0.55),
            0 8px 24px rgba(0, 0, 0, 0.35);
        transform: scale(0.94) translateY(8px);
        opacity: 0;
        transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
    }

    .spicker-popup::before,
    .jalali-popup::before,
    .step-modal-box::before,
    .admin-modal-shell::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.55), transparent);
        border-radius: 18px 18px 0 0;
        pointer-events: none;
    }

    .spicker-popup--wide { width: min(100%, 480px); }

    .spicker-overlay.is-open .spicker-popup,
    .jalali-overlay.is-open .jalali-popup,
    .step-modal.active .step-modal-box,
    .admin-modal.is-open .admin-modal-shell {
        transform: scale(1) translateY(0);
        opacity: 1;
    }

    .spicker-handle,
    .jalali-handle,
    .step-modal-handle { display: none; }

    .step-modal-box--wide,
    .contract-card-modal-box { width: min(100%, 480px); }

    .admin-modal-shell { width: min(100%, 620px); }

    .spicker-head,
    .jalali-bar,
    .step-modal-head,
    .admin-modal-head {
        padding: 20px 22px 14px;
    }

    .spicker-head-text h3,
    .jalali-head-text h3,
    .step-modal-head-text h3 {
        font-size: 0.95rem;
    }

    .step-modal-body,
    .admin-modal-body {
        padding: 18px 22px 22px;
    }

    .step-modal-foot,
    .jalali-popup-foot {
        padding: 14px 22px calc(14px + env(safe-area-inset-bottom, 0px));
    }
}

/* ── Small phones ── */
@media (max-width: 399px) {
    .spicker-popup,
    .jalali-popup,
    .step-modal-box,
    .admin-modal-shell {
        max-height: min(92dvh, 640px);
        width: min(100%, 100%);
        border-radius: 16px;
    }

    .step-modal-head-text h3,
    .spicker-head-text h3,
    .jalali-head-text h3 {
        font-size: 0.86rem;
    }

    .step-modal-close,
    .admin-modal-close,
    .spicker-close,
    .jalali-close {
        width: 36px;
        height: 36px;
    }
}
