/**
 * Toast & Confirm Dialog System
 * RTL-first | Dark Mode | Glassmorphism | Premium Design
 */

/* ── Toast Container ─────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    right: auto;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.625rem;
    pointer-events: none;
    max-width: 380px;
    width: calc(100vw - 3rem);
}

/* ── Single Toast ─────────────────────────────────────────── */
.toast-item {
    pointer-events: all;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(255, 255, 255, 0.7);
    position: relative;
    overflow: hidden;
    transform: translateX(-120%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    direction: rtl;
    min-width: 0;
}

.toast-item.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-item.hide {
    transform: translateX(-120%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.25s ease;
}

/* Dark Mode */
[data-bs-theme="dark"] .toast-item {
    background: rgba(30, 30, 46, 0.95);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
}

/* ── Toast Icon ─────────────────────────────────────────── */
.toast-icon {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* ── Toast Content ──────────────────────────────────────── */
.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 700;
    font-size: 0.875rem;
    line-height: 1.3;
    margin-bottom: 0.2rem;
}

.toast-message {
    font-size: 0.8rem;
    line-height: 1.5;
    opacity: 0.8;
}

/* ── Toast Close Button ─────────────────────────────────── */
.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    opacity: 0.45;
    font-size: 1rem;
    line-height: 1;
    margin-top: 2px;
    transition: opacity 0.2s;
}

.toast-close:hover { opacity: 1; }

/* ── Progress Bar ───────────────────────────────────────── */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: auto;
    height: 3px;
    border-radius: 0 0 0 14px;
    width: 100%;
    transform-origin: right;
    animation: toastProgressRTL linear forwards;
}

@keyframes toastProgressRTL {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ── Toast Type Colors ──────────────────────────────────── */

/* Success */
.toast-success .toast-icon {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}
.toast-success .toast-title { color: #065f46; }
.toast-success .toast-progress { background: #10b981; }

[data-bs-theme="dark"] .toast-success .toast-icon { background: rgba(16, 185, 129, 0.18); color: #34d399; }
[data-bs-theme="dark"] .toast-success .toast-title { color: #6ee7b7; }

/* Error / Danger */
.toast-error .toast-icon {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}
.toast-error .toast-title { color: #991b1b; }
.toast-error .toast-progress { background: #ef4444; }

[data-bs-theme="dark"] .toast-error .toast-icon { background: rgba(239, 68, 68, 0.2); color: #f87171; }
[data-bs-theme="dark"] .toast-error .toast-title { color: #fca5a5; }

/* Warning */
.toast-warning .toast-icon {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}
.toast-warning .toast-title { color: #92400e; }
.toast-warning .toast-progress { background: #f59e0b; }

[data-bs-theme="dark"] .toast-warning .toast-icon { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
[data-bs-theme="dark"] .toast-warning .toast-title { color: #fde68a; }

/* Info */
.toast-info .toast-icon {
    background: rgba(59, 130, 246, 0.12);
    color: #2563eb;
}
.toast-info .toast-title { color: #1e40af; }
.toast-info .toast-progress { background: #3b82f6; }

[data-bs-theme="dark"] .toast-info .toast-icon { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
[data-bs-theme="dark"] .toast-info .toast-title { color: #93c5fd; }

/* Message text in dark mode */
[data-bs-theme="dark"] .toast-message { color: rgba(255,255,255,0.75); }
[data-bs-theme="dark"] .toast-close { color: rgba(255,255,255,0.6); }

/* ── Confirm Dialog Overlay ─────────────────────────────── */
#toast-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.25s ease;
    direction: rtl;
}

#toast-confirm-overlay.show { opacity: 1; }

/* ── Confirm Dialog Card ─────────────────────────────────── */
.toast-confirm-card {
    background: #fff;
    border-radius: 20px;
    padding: 2rem 1.75rem 1.5rem;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.08);
    transform: scale(0.85) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
    direction: rtl;
}

#toast-confirm-overlay.show .toast-confirm-card {
    transform: scale(1) translateY(0);
}

[data-bs-theme="dark"] .toast-confirm-card {
    background: #1e1e2e;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.toast-confirm-icon-wrap {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.toast-confirm-icon-wrap.danger {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.toast-confirm-icon-wrap.warning {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.toast-confirm-icon-wrap.info {
    background: rgba(59, 130, 246, 0.12);
    color: #2563eb;
}

.toast-confirm-title {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: #111827;
}

[data-bs-theme="dark"] .toast-confirm-title { color: #f9fafb; }

.toast-confirm-message {
    font-size: 0.875rem;
    color: #6b7280;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

[data-bs-theme="dark"] .toast-confirm-message { color: rgba(255,255,255,0.6); }

.toast-confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.toast-confirm-actions .btn {
    flex: 1;
    min-width: 110px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.6rem 1.25rem;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toast-btn-cancel {
    background: transparent;
    color: #6b7280;
    border-color: #e5e7eb !important;
}

.toast-btn-cancel:hover {
    background: #f3f4f6;
    border-color: #d1d5db !important;
}

[data-bs-theme="dark"] .toast-btn-cancel {
    color: rgba(255,255,255,0.65);
    border-color: rgba(255,255,255,0.12) !important;
}

[data-bs-theme="dark"] .toast-btn-cancel:hover {
    background: rgba(255,255,255,0.06);
}

.toast-btn-confirm-danger {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626 !important;
}

.toast-btn-confirm-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220,38,38,0.35);
}

.toast-btn-confirm-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb !important;
}

.toast-btn-confirm-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8 !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.toast-btn-confirm-warning {
    background: #d97706;
    color: #fff;
    border-color: #d97706 !important;
}

.toast-btn-confirm-warning:hover {
    background: #b45309;
    border-color: #b45309 !important;
    transform: translateY(-1px);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 480px) {
    #toast-container {
        bottom: 1rem;
        left: 0.75rem;
        right: 0.75rem;
        max-width: 100%;
        width: auto;
    }
    
    .toast-confirm-card {
        padding: 1.5rem 1.25rem 1.25rem;
    }
    
    .toast-confirm-actions {
        flex-direction: column;
    }
}
