/* ==========================================================================
   Toast — پیام‌های سرور و فهرست خطای فرم‌ها
   --------------------------------------------------------------------------
   یک ظاهرِ واحد برای هر دو مسیر:
       ۱) پیام‌های جنگو (django.contrib.messages) در base.html
       ۲) فهرست خطای اعتبارسنجی سمت کلاینت (form-guard.js)

   قبلاً استایلِ توست به‌صورت inline داخل base.html بود و رنگش هگزِ ثابت
   داشت؛ در تم روشن روی پس‌زمینه‌ی سفید تقریباً ناخوانا می‌شد. اینجا
   همه‌چیز از توکن‌های design-system می‌آید.
   ========================================================================== */

.toast-stack {
    position: fixed;
    top: max(1rem, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    width: calc(100% - 2rem);
    max-width: 26rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    direction: rtl;
    text-align: right;
    padding: 0.875rem 0.875rem 0.875rem 0.5rem;
    border-radius: var(--r-card, 1.25rem);
    background: var(--panel);
    border: 1px solid var(--border);
    border-right: 4px solid var(--muted);
    box-shadow: 0 18px 38px -16px rgba(0, 0, 0, 0.35);
    animation: toastIn 0.32s cubic-bezier(.22,.61,.36,1) both;
}

.toast--leaving { animation: toastOut 0.3s ease forwards; }

.toast--error   { border-right-color: var(--red); }
.toast--success { border-right-color: var(--mint); }
.toast--warning { border-right-color: var(--amber); }
.toast--info    { border-right-color: var(--blue); }

.toast__icon { font-size: 1.25rem; line-height: 1.4; flex: 0 0 auto; }
.toast--error   .toast__icon { color: var(--red); }
.toast--success .toast__icon { color: var(--mint); }
.toast--warning .toast__icon { color: var(--amber); }
.toast--info    .toast__icon { color: var(--blue); }

.toast__body { flex: 1 1 auto; min-width: 0; }

.toast__title {
    font-size: 0.8125rem;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 0.375rem;
}

.toast__text {
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.65;
    color: var(--text);
    margin: 0;
}

.toast__list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.3125rem;
    counter-reset: toast-item;
}

.toast__list li {
    position: relative;
    counter-increment: toast-item;
    padding-right: 1.375rem;
    font-size: 0.78125rem;
    font-weight: 600;
    line-height: 1.6;
    color: var(--text);
}

.toast__list li::before {
    content: counter(toast-item);
    position: absolute;
    right: 0;
    top: 0.1875rem;
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    font-size: 0.625rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--red);
}

.toast--success .toast__list li::before { background: var(--mint); }
.toast--warning .toast__list li::before { background: var(--amber); }
.toast--info    .toast__list li::before { background: var(--blue); }

.toast__close {
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.toast__close:hover { background: var(--panel-2); color: var(--text); }
.toast__close .material-icons { font-size: 1rem; }

@keyframes toastIn {
    from { transform: translateY(-1rem); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
@keyframes toastOut {
    from { transform: translateY(0);        opacity: 1; }
    to   { transform: translateY(-0.75rem); opacity: 0; }
}

/* فیلدی که اعتبارسنجی ردش کرده */
.is-invalid,
.is-invalid input,
.is-invalid select,
.is-invalid textarea {
    border-color: var(--red) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent) !important;
}

@media (prefers-reduced-motion: reduce) {
    .toast, .toast--leaving { animation: none; }
}

/* ==========================================================================
   نشانگرِ «در حال ارسال» روی دکمه
   --------------------------------------------------------------------------
   بدون این، کاربر روی «ثبت» می‌زند و هیچ اتفاقِ دیداری نمی‌افتد تا وقتی
   پاسخ برسد. روی اینترنتِ کند یعنی چند بار زدنِ دکمه و چند بار ارسالِ
   همان فرم.
   ========================================================================== */

.guard-spinner {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
    border-radius: 999px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    margin-inline-end: 0.5rem;
    animation: guardSpin .7s linear infinite;
    vertical-align: -0.15em;
    display: inline-block;
}

button.is-submitting,
.is-submitting {
    opacity: 0.75;
    cursor: progress;
}

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

@media (prefers-reduced-motion: reduce) {
    .guard-spinner { animation-duration: 2s; }
}
