/**
 * Modern Modal System for Nihongo Grammar Learning
 * Beautiful, accessible modals with animations
 */

/* Modal Overlay */
.ngl-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ngl-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Modal Container */
.ngl-modal {
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.95) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
}

.ngl-modal-overlay.active .ngl-modal {
    transform: scale(1) translateY(0);
}

/* Modal Header */
.ngl-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 24px 0 24px;
    margin-bottom: 16px;
}

.ngl-modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

/* Icon types */
.ngl-modal-icon.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.ngl-modal-icon.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.ngl-modal-icon.warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.ngl-modal-icon.info {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.ngl-modal-icon.question {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
}

/* Modal Title */
.ngl-modal-title {
    font-size: 20px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
    line-height: 1.3;
}

/* Modal Content */
.ngl-modal-content {
    padding: 0 24px;
    margin-bottom: 24px;
}

.ngl-modal-message {
    font-size: 16px;
    color: #4b5563;
    line-height: 1.6;
    margin: 0;
}

/* Modal Actions */
.ngl-modal-actions {
    padding: 24px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: #f9fafb;
}

/* Modal Buttons */
.ngl-modal-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
    justify-content: center;
}

.ngl-modal-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

/* Primary button */
.ngl-modal-btn.primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.ngl-modal-btn.primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Success button */
.ngl-modal-btn.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.ngl-modal-btn.success:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

/* Danger button */
.ngl-modal-btn.danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.ngl-modal-btn.danger:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Secondary button */
.ngl-modal-btn.secondary {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.ngl-modal-btn.secondary:hover {
    background: #e5e7eb;
    color: #4b5563;
    transform: translateY(-1px);
}

/* Close button */
.ngl-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f3f4f6;
    border: none;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 18px;
}

.ngl-modal-close:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Loading state */
.ngl-modal-loading {
    pointer-events: none;
    opacity: 0.7;
}

.ngl-modal-loading .ngl-modal-btn {
    pointer-events: none;
}

.ngl-modal-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.ngl-modal-icon.pulse {
    animation: pulse 2s infinite;
}

/* Toast Notifications - removed duplicate, handled below */

.ngl-toast {
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
    padding: 16px 20px !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    transform: translateX(calc(100% + 30px)) !important;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    border-left: 4px solid #e5e7eb !important;
    pointer-events: auto !important; /* Enable clicking on toast */
    position: relative !important;
    backdrop-filter: blur(8px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    z-index: 999999 !important;
    min-width: 300px !important;
    max-width: 400px !important;
}

.ngl-toast.show {
    transform: translateX(0) !important;
}

.ngl-toast.hide {
    transform: translateX(calc(100% + 30px)) scale(0.95);
    opacity: 0;
}

/* Toast types */
.ngl-toast.success {
    border-left-color: #10b981;
}

.ngl-toast.error {
    border-left-color: #ef4444;
}

.ngl-toast.warning {
    border-left-color: #f59e0b;
}

.ngl-toast.info {
    border-left-color: #3b82f6;
}

.ngl-toast-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.ngl-toast.success .ngl-toast-icon {
    background: #dcfce7;
    color: #166534;
}

.ngl-toast.error .ngl-toast-icon {
    background: #fef2f2;
    color: #991b1b;
}

.ngl-toast.warning .ngl-toast-icon {
    background: #fef3c7;
    color: #92400e;
}

.ngl-toast.info .ngl-toast-icon {
    background: #dbeafe;
    color: #1e40af;
}

.ngl-toast-content {
    flex: 1;
}

.ngl-toast-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 2px;
    font-size: 14px;
}

.ngl-toast-message {
    color: #6b7280;
    font-size: 13px;
    line-height: 1.4;
}

.ngl-toast-close {
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    color: #9ca3af;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.ngl-toast-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

/* Progress bar for auto-dismiss */
.ngl-toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #e5e7eb;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.ngl-toast-progress-bar {
    height: 100%;
    background: currentColor;
    transform-origin: left;
    animation: progressBar var(--duration, 5s) linear forwards;
}

@keyframes progressBar {
    0% { transform: scaleX(1); }
    100% { transform: scaleX(0); }
}

/* Enhanced Toast Styles for Better UX */
.ngl-toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, currentColor, transparent);
    border-radius: 12px 12px 0 0;
    opacity: 0.3;
}

.ngl-toast:hover {
    transform: translateX(-5px) scale(1.02);
    box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.2), 0 10px 15px -8px rgba(0, 0, 0, 0.15);
}

/* Smooth transitions for toast positioning */
.ngl-toast {
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.3s ease-out !important;
}

/* Staggered animation for multiple toasts */
.ngl-toast:nth-child(1) { animation-delay: 0ms; }
.ngl-toast:nth-child(2) { animation-delay: 100ms; }
.ngl-toast:nth-child(3) { animation-delay: 200ms; }
.ngl-toast:nth-child(4) { animation-delay: 300ms; }
.ngl-toast:nth-child(5) { animation-delay: 400ms; }

/* Responsive */
@media (max-width: 640px) {
    .ngl-modal {
        width: 95%;
        margin: 20px;
    }

    .ngl-modal-header {
        padding: 20px 20px 0 20px;
    }

    .ngl-modal-content {
        padding: 0 20px;
    }

    .ngl-modal-actions {
        padding: 20px;
        flex-direction: column-reverse;
    }

    .ngl-modal-btn {
        width: 100%;
    }

    .ngl-toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    /* Admin bar offset for mobile */
    body.admin-bar .ngl-toast-container {
        top: 56px; /* Mobile admin bar height */
    }
}

/* Accessibility */
.ngl-modal-overlay[aria-hidden="true"] {
    display: none;
}

.ngl-modal:focus {
    outline: none;
}

/* Hide WordPress notices that cause layout shifts */
.ngl-admin .notice,
.ngl-admin .updated,
.ngl-admin .error {
    display: none !important;
}

/* Prevent layout shifts by ensuring consistent scrollbar */
html {
    overflow-y: scroll !important;
}

/* Prevent content shift when toast appears */
body {
    overflow-y: scroll !important;
    scrollbar-gutter: stable !important;
}

/* Toast container positioning - consolidated */
.ngl-toast-container {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 999999 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    max-width: 400px !important;
    width: auto !important;
    pointer-events: none !important;
    transform: translateZ(0) !important; /* Force hardware acceleration */
}

/* Admin bar offset for toast notifications in WordPress */
body.admin-bar .ngl-toast-container,
.wp-admin .ngl-toast-container {
    top: 52px !important; /* Offset for WordPress admin bar */
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .ngl-modal-overlay,
    .ngl-modal,
    .ngl-modal-btn,
    .ngl-toast {
        transition: none;
        animation: none;
    }

    .ngl-toast:hover {
        transform: none;
    }
}