/* ==========================================================================
   App Modal — کامپوننت مودال مشترک
   نام‌گذاری BEM با پیشوند app-modal تا با استایل‌های موجود تداخل نکند.
   ========================================================================== */

/* --------------------------------------------------------------------------
   لایهٔ پوششی
   -------------------------------------------------------------------------- */
.app-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1300;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.55);
    place-items: center;
}

.app-modal.is-open {
    display: grid;
}

/* letter-spacing ارثی بدنه، گلیف‌های فارسی را از هم جدا می‌کند و
   overflow-wrap/word-break ارثی، عرض min-content را تا یک حرف پایین می‌آورد. */
.app-modal {
    letter-spacing: normal;
    overflow-wrap: normal;
    word-break: normal;
    line-height: 1.7;
}

/* قفل اسکرول پس‌زمینه روی html اعمال می‌شود تا موقعیت عناصر sticky صفحه نپرد. */
html.app-modal-lock,
html.app-modal-lock body {
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   دیالوگ
   -------------------------------------------------------------------------- */
.app-modal__dialog {
    --app-modal-width: 520px;
    display: flex;
    flex-direction: column;
    width: min(100%, var(--app-modal-width));
    max-height: min(88vh, calc(100dvh - 2rem));
    overflow: hidden;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(15, 23, 42, 0.25);
}

.app-modal--sm .app-modal__dialog { --app-modal-width: 420px; }
.app-modal--md .app-modal__dialog { --app-modal-width: 520px; }
.app-modal--lg .app-modal__dialog { --app-modal-width: 640px; }

/* --------------------------------------------------------------------------
   هدر / بدنه / فوتر — تنها بدنه اسکرول دارد
   -------------------------------------------------------------------------- */
.app-modal__header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex: 0 0 auto;
    padding: 1.5rem 1.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.app-modal__heading {
    flex: 1 1 auto;
    min-width: 0;
}

.app-modal__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
    color: #1e293b;
    line-height: 1.6;
}

.app-modal__subtitle {
    margin: 0.35rem 0 0;
    font-size: 0.85rem;
    color: #64748b;
    line-height: 1.6;
}

.app-modal__close {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: #f1f5f9;
    color: #475569;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.app-modal__close:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.app-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.5rem 1.75rem;
}

.app-modal__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
    align-items: center;
    flex: 0 0 auto;
    padding: 1rem 1.75rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

.app-modal__footer-spacer {
    margin-inline-end: auto;
}

/* --------------------------------------------------------------------------
   ریست ایزوله
   استایل‌های سراسری (label سراسری، Tailwind preflight، ‎* { margin: 0 }‎)
   نباید داخل مودال نشت کنند.
   -------------------------------------------------------------------------- */
.app-modal :where(label) {
    margin: 0;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    display: initial;
}

.app-modal :where(p) {
    margin: 0;
}

/* هر آیتم متنی داخل ردیف flex باید با flex-basis: auto رشد کند؛
   flex: 1 1 0% باعث سقوط عرض تا min-content می‌شود. */
.app-modal :where(.app-modal__grow) {
    flex: 1 1 auto;
    min-width: 0;
}

/* --------------------------------------------------------------------------
   فیلدهای فرم
   -------------------------------------------------------------------------- */
.app-modal__field {
    margin-bottom: 1.15rem;
}

.app-modal__field:last-child {
    margin-bottom: 0;
}

.app-modal__label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.92rem;
    color: #475569;
}

.app-modal__input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    color: #0f172a;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.app-modal__input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.app-modal__input[readonly] {
    background: #f8fafc;
}

.app-modal__hint {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: #94a3b8;
}

/* چک‌باکس / رادیو در یک ردیف با متن چندخطی */
.app-modal__check {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    line-height: 1.7;
}

.app-modal__check input {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    margin-top: 0.28rem;
    accent-color: #6366f1;
    cursor: pointer;
}

.app-modal__check span {
    flex: 1 1 auto;
    min-width: 0;
}

.app-modal__check-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* --------------------------------------------------------------------------
   دکمه‌ها
   -------------------------------------------------------------------------- */
.app-modal__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.7rem 1.3rem;
    border: 2px solid transparent;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.app-modal__btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* display صریح بالاتر از قاعدهٔ پیش‌فرض [hidden] مرورگر است. */
.app-modal__btn[hidden] {
    display: none;
}

.app-modal__btn--ghost {
    background: #fff;
    border-color: #e2e8f0;
    color: #475569;
}

.app-modal__btn--ghost:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.app-modal__btn--primary {
    background: #6366f1;
    color: #fff;
}

.app-modal__btn--primary:hover:not(:disabled) {
    background: #4f46e5;
}

.app-modal__btn--success {
    background: #10b981;
    color: #fff;
}

.app-modal__btn--success:hover:not(:disabled) {
    background: #059669;
}

/* --------------------------------------------------------------------------
   ویزارد چندمرحله‌ای
   -------------------------------------------------------------------------- */
.app-wizard__step {
    display: none;
}

.app-wizard__step.is-active {
    display: block;
}

.app-wizard__progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.app-wizard__dot {
    height: 4px;
    flex: 1 1 auto;
    border-radius: 999px;
    background: #e2e8f0;
    transition: background 0.25s ease;
}

.app-wizard__dot.is-active {
    background: #6366f1;
}

/* --------------------------------------------------------------------------
   ریسپانسیو — روی موبایل به شیت پایین‌چسبان تبدیل می‌شود
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .app-modal {
        padding: 0;
        place-items: end stretch;
    }

    .app-modal__dialog {
        --app-modal-width: 100%;
        max-height: min(94vh, calc(100dvh - 1rem));
        border-radius: 20px 20px 0 0;
    }

    .app-modal__header {
        padding: 1.25rem 1.25rem 0.85rem;
    }

    .app-modal__body {
        padding: 1.25rem;
    }

    .app-modal__footer {
        padding: 0.85rem 1.25rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
    }

    .app-modal__footer .app-modal__btn {
        flex: 1 1 auto;
    }
}
