/* ---------- Backdrop ---------- */
.modal-backdrop {
    font-family: var(--font-main);
    position: fixed;
    inset: 0;
    background: transparent;
    /* بلور پس‌زمینه به pseudo-element منتقل شد تا backdrop-filter خودِ مودال (شیشه‌ای) کار کند */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    animation: none;
    padding: 20px;
    box-sizing: border-box;
}

    .modal-backdrop::before {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        background: radial-gradient(90% 60% at 50% 0%, rgba(34, 211, 238, .10), transparent 70%), rgba(2, 12, 32, .55);
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
        animation: fadeIn .25s ease;
    }

    .modal-backdrop.closing {
        animation: none;
    }

        .modal-backdrop.closing::before {
            animation: fadeOut .18s ease forwards;
        }

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ---------- Modal Box ---------- */
.modal-box {
    /* پالت شیشه‌ای آبی/فیروزه‌ای هماهنگ با سایدبار؛ هر چیزی که از این متغیرها استفاده کند خودکار تیره‌شیشه‌ای می‌شود */
    --primary: #22d3ee;
    --primary-dark: #67e8f9;
    --primary-light: rgba(34, 211, 238, .14);
    --accent: #38bdf8;
    --accent-light: #7dd3fc;
    --border: rgba(255, 255, 255, .20);
    --text: #e8f6ff;
    --text-muted: #a9c9dc;
    --bg-soft: rgba(255, 255, 255, .08);
    --danger: #fca5a5;
    --danger-light: rgba(239, 68, 68, .16);
    --shadow-lg: 0 24px 60px rgba(0, 10, 30, .55);
    --shadow-glow: 0 0 20px rgba(34, 211, 238, .35);
    color-scheme: dark;
    background: radial-gradient(120% 30% at 50% 0%, rgba(255, 255, 255, .16), transparent 65%), linear-gradient(180deg, rgba(2, 26, 64, .86) 0%, rgba(5, 61, 103, .78) 55%, rgba(7, 87, 123, .74) 100%);
    -webkit-backdrop-filter: blur(22px) saturate(150%);
    backdrop-filter: blur(22px) saturate(150%);
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 22px;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);   /* موبایل: ارتفاع واقعیِ دیده‌شده؛ با 100vh دکمه‌های پایین مودال زیر نوار آدرس می‌رفت */
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, .20);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalPop .35s cubic-bezier(.34, 1.56, .64, 1);
    position: relative;
}

    /* نوار گرادیانت بالای مودال */
    .modal-box::before {
        content: "";
        position: absolute;
        top: 0;
        inset-inline-start: 0;
        width: 100%;
        height: 4px;
        background: linear-gradient(90deg, #06b6d4 0%, #38bdf8 50%, #a5f3fc 100%);
        background-size: 200% 100%;
        animation: gradientShift 3s ease infinite;
        z-index: 1;
    }

@keyframes gradientShift {
    0%, 100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.modal-box.closing {
    animation: modalPopOut .18s ease forwards;
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(.9) translateY(24px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes modalPopOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }

    to {
        opacity: 0;
        transform: scale(.92) translateY(12px);
    }
}

/* ---------- Header ---------- */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, .16);
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, .16) 0%, rgba(34, 211, 238, .07) 100%);
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

    .modal-header:active {
        cursor: grabbing;
    }

    .modal-header h5 {
        margin: 0;
        font-size: 16px;
        font-weight: 700;
        color: #f0faff;
        font-family: var(--font-main);
        position: relative;
        padding-inline-start: 12px;
    }

        .modal-header h5::before {
            content: "";
            position: absolute;
            inset-inline-start: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 18px;
            background: linear-gradient(180deg, #22d3ee 0%, #38bdf8 100%);
            border-radius: 2px;
            box-shadow: 0 0 10px rgba(34, 211, 238, .6);
        }

.modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255, 255, 255, .20);
    border-radius: 10px;
    background: rgba(255, 255, 255, .12);
    color: #d7ecf7;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-base), color var(--transition-base), transform var(--transition-bounce), box-shadow var(--transition-base);
    flex-shrink: 0;
}

    .modal-close:hover {
        background: rgba(239, 68, 68, .28);
        border-color: rgba(252, 165, 165, .5);
        color: #fecaca;
        transform: rotate(90deg) scale(1.1);
        box-shadow: 0 4px 12px rgba(239, 68, 68, .25);
    }

    .modal-close:active {
        transform: rotate(90deg) scale(.95);
    }

/* ---------- Body ---------- */
.modal-body {
    padding: 22px;
    color: var(--text);
    overflow-y: auto;
    flex: 1;
    font-family: var(--font-main);
    min-height: 60px;
}

    .modal-body::-webkit-scrollbar {
        width: 8px;
    }

    .modal-body::-webkit-scrollbar-track {
        background: transparent;
    }

    .modal-body::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, rgba(34, 211, 238, .75), rgba(56, 189, 248, .55));
        border-radius: 4px;
    }

        .modal-body::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(135deg, #67e8f9, #38bdf8);
        }

    /* ---------- Shared form styles inside modal ---------- */
    .modal-body .form-group {
        margin-bottom: 16px;
    }

        .modal-body .form-group label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-muted);
            margin-bottom: 6px;
            transition: color var(--transition-fast);
        }

        .modal-body .form-group:focus-within label {
            color: var(--primary-dark);
        }

    .modal-body .form-control {
        width: 100%;
        padding: 10px 14px;
        border: 1.5px solid rgba(255, 255, 255, .22);
        border-radius: 12px;
        font-size: 15px;
        font-family: inherit;
        background: rgba(255, 255, 255, .08);
        transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
        box-sizing: border-box;
        color: #f1f9ff;
    }

        .modal-body .form-control::placeholder {
            color: rgba(232, 246, 255, .45);
        }

        .modal-body .form-control:hover {
            border-color: rgba(103, 232, 249, .55);
            background: rgba(255, 255, 255, .12);
        }

        .modal-body .form-control:focus {
            outline: none;
            border-color: #22d3ee;
            background: rgba(255, 255, 255, .14);
            box-shadow: 0 0 0 4px rgba(34, 211, 238, .20);
        }

        .modal-body .form-control[readonly] {
            background: rgba(255, 255, 255, .05);
            cursor: default;
        }

        .modal-body .form-control.invalid {
            border-color: #fca5a5;
            background: rgba(239, 68, 68, .14);
        }

        .modal-body .form-control::file-selector-button {
            margin-inline-end: 12px;
            padding: 6px 14px;
            border: 1px solid rgba(255, 255, 255, .25);
            border-radius: 8px;
            background: rgba(255, 255, 255, .14);
            color: #f0faff;
            font-family: inherit;
            cursor: pointer;
            transition: background .2s ease;
        }

            .modal-body .form-control::file-selector-button:hover {
                background: rgba(255, 255, 255, .24);
            }

    .modal-body .modal-footer-inline {
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        margin-top: 22px;
        padding-top: 16px;
        border-top: 1px solid var(--border);
    }

    .modal-body .btn {
        padding: 10px 20px;
        border-radius: 10px;
        border: none;
        font-family: inherit;
        font-weight: 600;
        font-size: 14px;
        cursor: pointer;
        transition: transform var(--transition-fast), box-shadow var(--transition-base), background var(--transition-base);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .modal-body .btn-secondary {
        background: rgba(255, 255, 255, .10);
        border: 1px solid rgba(255, 255, 255, .22);
        color: #e8f6ff;
    }

        .modal-body .btn-secondary:hover:not(:disabled) {
            background: rgba(255, 255, 255, .20);
            transform: translateY(-1px);
        }

    .modal-body .btn-primary {
        background: linear-gradient(135deg, #0e7490 0%, #06b6d4 100%);
        background-size: 200% 200%;
        border: 1px solid rgba(255, 255, 255, .25);
        color: #fff;
        box-shadow: 0 4px 14px rgba(6, 182, 212, .35);
    }

        .modal-body .btn-primary:hover:not(:disabled) {
            transform: translateY(-2px);
            background-position: 100% 100%;
            box-shadow: 0 8px 18px rgba(6, 182, 212, .5), var(--shadow-glow);
        }

    .modal-body .btn-danger {
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        background-size: 200% 200%;
        color: #fff;
        box-shadow: 0 4px 14px rgba(239, 68, 68, .3);
    }

        .modal-body .btn-danger:hover:not(:disabled) {
            transform: translateY(-2px);
            background-position: 100% 100%;
            box-shadow: 0 8px 18px rgba(239, 68, 68, .45), 0 0 20px rgba(239, 68, 68, .3);
        }

    .modal-body .btn:disabled {
        opacity: .7;
        cursor: not-allowed;
        transform: none !important;
    }

    .modal-body .btn-spinner {
        display: inline-block;
        width: 14px;
        height: 14px;
        border: 2px solid rgba(255, 255, 255, .4);
        border-top-color: #fff;
        border-radius: 50%;
        animation: spin .6s linear infinite;
        vertical-align: middle;
    }

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- هماهنگ‌سازی اجزای داخل مودال (کلاس‌هایی که در CrudPage.css / app.css رنگ روشن ثابت دارند) ---------- */
.modal-box .modal-icon-danger {
    background: rgba(239, 68, 68, .18);
    border: 1px solid rgba(252, 165, 165, .35);
    color: #fca5a5;
}

.modal-box .form-error-message {
    border: 1px solid rgba(252, 165, 165, .35);
}

.modal-box .field-error,
.modal-box .image-preview-size.too-large {
    color: #fca5a5;
}

.modal-box .up-muted {
    color: var(--text-muted);
}

.modal-box .image-preview-skeleton {
    background: linear-gradient(110deg, rgba(255, 255, 255, .08) 30%, rgba(255, 255, 255, .20) 50%, rgba(255, 255, 255, .08) 70%);
    background-size: 200% 100%;
}

.modal-box .image-preview-badge {
    color: #a5f3fc;
    background: rgba(34, 211, 238, .18);
}

    .modal-box .image-preview-badge.current {
        color: #cbd5e1;
        background: rgba(255, 255, 255, .14);
    }

.modal-box .save-progress-wrapper {
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .22);
}

.modal-box .save-progress-track {
    background: rgba(255, 255, 255, .14);
    box-shadow: inset 0 2px 4px rgba(0, 10, 30, .35);
}

.modal-box .save-progress-fill {
    box-shadow: 0 0 14px rgba(34, 211, 238, .55);
}

.modal-box .save-progress-wrapper.done {
    background: rgba(16, 185, 129, .14);
    border-color: rgba(52, 211, 153, .45);
}

    .modal-box .save-progress-wrapper.done .save-progress-stage {
        color: #6ee7b7;
    }

.modal-box .password-toggle {
    color: var(--text-muted);
}

    .modal-box .password-toggle:hover,
    .modal-box .password-toggle[aria-pressed="true"] {
        color: #67e8f9;
        background: rgba(34, 211, 238, .12);
    }

    .modal-box .password-toggle:focus-visible {
        outline: 2px solid #22d3ee;
    }

/* اگر مرورگر backdrop-filter را پشتیبانی نکند، مودال مات‌تر می‌شود */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .modal-box {
        background: linear-gradient(180deg, #021a40 0%, #053d67 55%, #07577b 100%);
    }
}

/* مودال عریض‌تر (فرم‌های دوستونه) */
.modal-box.modal-lg {
    max-width: 720px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    .modal-backdrop {
        padding: 14px;
    }

    .modal-box {
        width: 100%;
        max-width: 100%;
        border-radius: 18px;
        max-height: calc(100vh - 28px);
        max-height: calc(100dvh - 28px);
    }

    .modal-header {
        padding: 16px 18px;
    }

    .modal-body {
        padding: 18px;
    }
}

/* ---------- مودال ویرایش مشخصات کاربر (پنل کاربری) ---------- */
.profile-modal-avatar {
    position: relative;
    width: 88px;
    height: 88px;
    margin: 0 auto 18px;
    border-radius: 50%;
    overflow: hidden;
    background: #6d28d9;
    border: 3px solid rgba(255, 255, 255, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
}

    .profile-modal-avatar img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

/* پیام‌های اعتبارسنجی روی پس‌زمینه‌ی شیشه‌ای تیره خوانا باشند */
.modal-box .validation-message {
    color: #fca5a5;
    font-size: 12px;
    margin-top: 4px;
}

.profile-saved-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    background: rgba(34, 197, 94, .18);
    border: 1px solid rgba(134, 239, 172, .4);
    color: #86efac;
}

.profile-saved-text {
    text-align: center;
}
