/* Modern toast notifications — RTL/LTR, order-success layout */
.notification-container,
.toast-container {
    position: fixed;
    inset-block-start: max(1rem, env(safe-area-inset-top, 0px));
    inset-inline-end: max(1rem, env(safe-area-inset-right, 0px));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: min(22.5rem, calc(100vw - 1.5rem));
    pointer-events: none;
}

.notification,
.toast {
    pointer-events: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "icon content close";
    align-items: start;
    gap: 0.75rem 0.875rem;
    padding: 1rem 0.875rem 1.125rem 1rem;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow:
        0 12px 40px rgba(15, 23, 42, 0.12),
        0 2px 8px rgba(15, 23, 42, 0.05);
    position: relative;
    overflow: hidden;
    animation: toast-slide-in 0.45s cubic-bezier(0.21, 1, 0.32, 1) both;
}

.toast::before,
.notification::before {
    content: "";
    position: absolute;
    inset-block: 0;
    /* Outer edge of toast (top-right in LTR, top-left in RTL) */
    inset-inline-end: 0;
    width: 4px;
    border-radius: 0 14px 14px 0;
}

html[dir="rtl"] .toast::before,
html[dir="rtl"] .notification::before {
    border-radius: 14px 0 0 14px;
}

.toast--success,
.notification.success {
    background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 58%);
}

.toast--success::before,
.notification.success::before {
    background: linear-gradient(180deg, #22c55e, #16a34a);
}

.toast--error,
.notification.error {
    background: linear-gradient(135deg, #fef2f2 0%, #ffffff 58%);
}

.toast--error::before,
.notification.error::before {
    background: linear-gradient(180deg, #ef4444, #dc2626);
}

.toast--warning,
.notification.warning {
    background: linear-gradient(135deg, #fffbeb 0%, #ffffff 58%);
}

.toast--warning::before,
.notification.warning::before {
    background: linear-gradient(180deg, #f59e0b, #d97706);
}

.toast--info,
.notification.info {
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 58%);
}

.toast--info::before,
.notification.info::before {
    background: linear-gradient(180deg, #3b82f6, #2563eb);
}

.toast__icon,
.notification-icon {
    grid-area: icon;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-inline-start: 4px;
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1;
}

.toast--success .toast__icon,
.notification.success .notification-icon {
    background: #22c55e;
    color: #fff;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
}

.toast--error .toast__icon,
.notification.error .notification-icon {
    background: #ef4444;
    color: #fff;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}

.toast--warning .toast__icon,
.notification.warning .notification-icon {
    background: #f59e0b;
    color: #fff;
}

.toast--info .toast__icon,
.notification.info .notification-icon {
    background: #3b82f6;
    color: #fff;
}

.toast__content,
.notification-content {
    grid-area: content;
    min-width: 0;
    padding-inline-end: 0.25rem;
}

.toast__title,
.notification-title {
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: #0f172a;
    margin: 0;
}

.toast--success .toast__title,
.notification.success .notification-title {
    color: #14532d;
}

.toast__message,
.notification-message {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: #64748b;
}

.toast__label {
    font-size: 0.8125rem;
    color: #64748b;
}

.toast__subtitle {
    margin: 0.5rem 0 0;
    padding: 0.5rem 0.65rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: #166534;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.15);
    border-radius: 8px;
}

.toast--error .toast__subtitle {
    color: #991b1b;
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.12);
}

.toast--warning .toast__subtitle {
    color: #92400e;
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.15);
}

.toast__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-top: 0.4rem;
}

.toast__badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 700;
    color: #15803d;
    background: #dcfce7;
    border: 1px solid #bbf7d0;
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.toast__close,
.notification-close {
    grid-area: close;
    align-self: start;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.toast__close:hover,
.notification-close:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #475569;
}

.toast__progress,
.notification-progress {
    position: absolute;
    inset-block-end: 0;
    inset-inline: 0;
    height: 3px;
    background: rgba(15, 23, 42, 0.06);
}

.toast__progress-bar,
.notification-progress-bar {
    display: block;
    height: 100%;
    width: 100%;
    transform-origin: inline-start;
    animation: toast-progress 6s linear forwards;
}

.toast--success .toast__progress-bar,
.notification.success .notification-progress-bar {
    background: linear-gradient(90deg, #22c55e, #4ade80);
}

.toast--error .toast__progress-bar,
.notification.error .notification-progress-bar {
    background: #ef4444;
}

.toast--warning .toast__progress-bar,
.notification.warning .notification-progress-bar {
    background: #f59e0b;
}

.toast--info .toast__progress-bar,
.notification.info .notification-progress-bar {
    background: #3b82f6;
}

.toast.is-hiding,
.notification.hide {
    animation: toast-slide-out 0.35s ease forwards;
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(1.25rem) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

html[dir="rtl"] .toast,
html[dir="rtl"] .notification {
    animation-name: toast-slide-in-rtl;
}

@keyframes toast-slide-in-rtl {
    from {
        opacity: 0;
        transform: translateX(-1.25rem) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toast-slide-out {
    to {
        opacity: 0;
        transform: translateX(1.25rem) scale(0.96);
    }
}

html[dir="rtl"] .toast.is-hiding,
html[dir="rtl"] .notification.hide {
    animation-name: toast-slide-out-rtl;
}

@keyframes toast-slide-out-rtl {
    to {
        opacity: 0;
        transform: translateX(-1.25rem) scale(0.96);
    }
}

@keyframes toast-progress {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}

@media (max-width: 640px) {
    .notification-container,
    .toast-container {
        inset-inline: max(0.75rem, env(safe-area-inset-left, 0px));
        width: auto;
    }

    .toast,
    .notification {
        padding: 0.875rem 0.75rem 1rem 0.875rem;
    }
}

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

    .toast__progress-bar,
    .notification-progress-bar {
        animation: none;
        transform: scaleX(0);
    }
}
