/* Custom Alert System Styles */

/* Overlay Styles */
.custom-alert-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.custom-alert-overlay.active {
    opacity: 1;
    visibility: visible;
}

.custom-alert-container {
    background: white;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow: visible;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.custom-alert-overlay.active .custom-alert-container {
    transform: scale(1) translateY(0);
}

.custom-alert-header {
    display: flex;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid #e5e7eb;
    background: var(--bg-blue-squarepancake);
}

.custom-alert-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    flex-shrink: 0;
}

.custom-alert-icon svg {
    width: 24px;
    height: 24px;
}

.custom-alert-icon.success {
    background: #dcfce7;
    color: #16a34a;
}

.custom-alert-icon.error {
    background: #fef2f2;
    color: #dc2626;
}

.custom-alert-icon.warning {
    background: #fefce8;
    color: #ca8a04;
}

.custom-alert-icon.info {
    background: #eff6ff;
    color: #2563eb;
}

.custom-alert-icon.confirm {
    background: #f0f9ff;
    color: #0284c7;
}

.custom-alert-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
    flex: 1;
}

/* Content Styles */
.custom-alert-content {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    max-height: calc(90vh - 140px);
}

/* Custom Scrollbar for Content */
.custom-alert-content::-webkit-scrollbar {
    width: 6px;
}

.custom-alert-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.custom-alert-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.custom-alert-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.custom-alert-message {
    font-size: 1rem;
    color: #4b5563;
    line-height: 1.6;
    margin: 0;
}

/* Actions Styles */
.custom-alert-actions {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
    justify-content: flex-end;
}

.custom-alert-loading {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Styles */
.custom-alert-toast {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    margin-bottom: 12px;
    max-width: 400px;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    border-left: 4px solid #e5e7eb;
}

.custom-alert-toast.active {
    transform: translateX(0);
}

.custom-alert-toast-header {
    display: flex;
    align-items: flex-start;
    padding: 16px;
    position: relative;
}

.custom-alert-toast-header.success {
    border-left-color: #16a34a;
}

.custom-alert-toast-header.error {
    border-left-color: #dc2626;
}

.custom-alert-toast-header.warning {
    border-left-color: #ca8a04;
}

.custom-alert-toast-header.info {
    border-left-color: #2563eb;
}

.custom-alert-toast-icon {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    flex-shrink: 0;
    margin-top: 2px;
}

.custom-alert-toast-icon svg {
    width: 20px;
    height: 20px;
}

.custom-alert-toast-icon.success {
    color: #16a34a;
}

.custom-alert-toast-icon.error {
    color: #dc2626;
}

.custom-alert-toast-icon.warning {
    color: #ca8a04;
}

.custom-alert-toast-icon.info {
    color: #2563eb;
}

.custom-alert-toast-content {
    flex: 1;
    min-width: 0;
}

.custom-alert-toast-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    font-size: 0.875rem;
}

.custom-alert-toast-message {
    color: #4b5563;
    font-size: 0.875rem;
    line-height: 1.4;
}

.custom-alert-toast-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #9ca3af;
    transition: all 0.2s ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.custom-alert-toast-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

.custom-alert-toast-close svg {
    width: 16px;
    height: 16px;
}

/* Progress Bar */
.custom-alert-toast-progress {
    height: 3px;
    background: #f3f4f6;
    overflow: hidden;
}

.custom-alert-toast-progress-bar {
    height: 100%;
    transition: width linear;
    transform-origin: left;
}

.custom-alert-toast-progress-bar.success {
    background: #16a34a;
}

.custom-alert-toast-progress-bar.error {
    background: #dc2626;
}

.custom-alert-toast-progress-bar.warning {
    background: #ca8a04;
}

.custom-alert-toast-progress-bar.info {
    background: #2563eb;
}

/* Mobile Responsive - Enhanced Performance Optimizations */
@media (max-width: 640px) {
    /* Mobile Performance: Reduce blur effects for better performance */
    .custom-alert-overlay {
        backdrop-filter: none; /* Remove blur on mobile for better performance */
        background: rgba(0, 0, 0, 0.7); /* Solid fallback instead */
    }
    
    /* Mobile Performance: Optimize container for smaller screens */
    .custom-alert-container {
        width: 95%;
        margin: 10px; /* Reduced margin for more space */
        max-height: 85vh; /* Slightly reduced max height for better mobile UX */
        /* Mobile Performance: Disable complex shadows on mobile */
        box-shadow: 0 10px 25px -12px rgba(0, 0, 0, 0.15);
    }
    
    /* Mobile Performance: Reduced padding for better space utilization */
    .custom-alert-header,
    .custom-alert-content,
    .custom-alert-actions {
        padding: 12px; /* Reduced from 16px for more compact mobile layout */
    }
    
    /* Mobile Performance: Simplified icon sizing */
    .custom-alert-icon {
        width: 40px; /* Reduced from 48px */
        height: 40px; /* Reduced from 48px */
        margin-right: 12px; /* Reduced from 16px */
    }
    
    .custom-alert-icon svg {
        width: 20px; /* Reduced from 24px */
        height: 20px; /* Reduced from 24px */
    }
    
    .custom-alert-actions {
        flex-direction: column;
        gap: 8px; /* Reduced gap for mobile */
    }
    
    .custom-alert-btn {
        width: 100%;
        justify-content: center;
        /* Mobile Performance: Simplified hover effects */
        transform: none !important; /* Disable scale transforms on mobile */
        transition: background-color 0.2s ease; /* Only transition background color */
    }
    
    /* Mobile Performance: Optimized toast positioning */
    .custom-alert-toast {
        max-width: calc(100vw - 20px); /* Reduced margins */
        margin-left: 10px;
        margin-right: 10px;
        /* Mobile Performance: Simplified shadows */
        box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
    }
    
    .custom-alert-toast-header {
        padding: 10px; /* Reduced from 12px */
    }
    
    /* Mobile Performance: Reduced font sizes for better readability */
    .custom-alert-title {
        font-size: 1.1rem; /* Reduced from 1.25rem */
    }
    
    .custom-alert-message {
        font-size: 0.9rem; /* Reduced from 1rem */
    }
    
    /* Mobile Performance: Disable hover effects on touch devices */
    .custom-alert-toast:hover {
        transform: none;
        box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
    }
    
    /* Mobile Performance: Simplified close button */
    .custom-alert-toast-close {
        padding: 8px; /* Larger touch target */
        min-width: 44px; /* Minimum touch target size */
        min-height: 44px; /* Minimum touch target size */
    }
}

/* Mobile Performance: Extra small devices (phones in portrait) */
@media (max-width: 375px) {
    .custom-alert-container {
        width: 98%;
        margin: 5px;
    }
    
    .custom-alert-header,
    .custom-alert-content,
    .custom-alert-actions {
        padding: 10px;
    }
    
    .custom-alert-icon {
        width: 36px;
        height: 36px;
        margin-right: 10px;
    }
    
    .custom-alert-title {
        font-size: 1rem;
    }
    
    .custom-alert-message {
        font-size: 0.85rem;
    }
    
    .custom-alert-toast {
        max-width: calc(100vw - 10px);
        margin-left: 5px;
        margin-right: 5px;
    }
}

/* Mobile Performance: Landscape orientation optimizations */
@media (max-width: 640px) and (orientation: landscape) {
    .custom-alert-container {
        max-height: 95vh; /* Use more height in landscape */
        max-width: 90%; /* Limit width in landscape */
    }
    
    .custom-alert-content {
        max-height: calc(95vh - 120px); /* Adjust content height for landscape */
    }
}

/* Mobile Performance: High DPI displays optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Use border instead of box-shadow on high DPI for better performance */
    .custom-alert-container {
        border: 1px solid rgba(0, 0, 0, 0.1);
        box-shadow: 0 4px 12px -8px rgba(0, 0, 0, 0.1);
    }
    
    .custom-alert-toast {
        border: 1px solid rgba(0, 0, 0, 0.05);
        box-shadow: 0 2px 8px -4px rgba(0, 0, 0, 0.08);
    }
}

/* Mobile Performance: Reduced motion for better battery life */
@media (prefers-reduced-motion: reduce) {
    .custom-alert-overlay,
    .custom-alert-container,
    .custom-alert-toast,
    .custom-alert-toast-progress-bar {
        transition: none !important;
        animation: none !important;
    }
    
    /* Show notifications immediately without animation */
    .custom-alert-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .custom-alert-overlay.active .custom-alert-container {
        transform: scale(1) translateY(0);
    }
    
    .custom-alert-toast.active {
        transform: translateX(0);
    }
}

/* Mobile Performance: Low-end device optimizations */
@media (max-width: 640px) and (max-height: 667px) {
    /* Optimize for smaller phone screens */
    .custom-alert-container {
        max-height: 80vh;
    }
    
    .custom-alert-content {
        max-height: calc(80vh - 100px);
    }
    
    /* Simplified progress bar */
    .custom-alert-toast-progress {
        height: 2px; /* Reduced from 3px */
    }
}

@media (prefers-color-scheme: dark) {
    .custom-alert-container {
        background: var(--white-background);
        color: var(--primary-color);
    }
    
    .custom-alert-header {
        background: var(--bg-blue-squarepancake);
        border-bottom-color: #374151;
    }
    
    .custom-alert-title {
        color: var(--white-text);
    }
    
    .custom-alert-message {
        color: var(--primary-color);
    }
    
    .custom-alert-actions {
        border-top-color: #4b5563;
    }
    
    .custom-alert-btn.secondary {
        background: #4b5563;
        color: #f9fafb;
        border-color: #6b7280;
    }
    
    .custom-alert-btn.secondary:hover {
        background: #6b7280;
        border-color: #9ca3af;
    }
    
    .custom-alert-toast {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .custom-alert-toast-title {
        color: #f9fafb;
    }
    
    .custom-alert-toast-message {
        color: #d1d5db;
    }
    
    .custom-alert-toast-close {
        color: #9ca3af;
    }
    
    .custom-alert-toast-close:hover {
        background: #374151;
        color: #d1d5db;
    }
    
    .custom-alert-toast-progress {
        background: #374151;
    }
}

/* Accessibility */
.custom-alert-overlay {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.custom-alert-btn:focus {
    outline: 2px solid #f67280;
    outline-offset: 2px;
}

.custom-alert-toast-close:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Animation improvements */
.custom-alert-toast:hover {
    transform: translateX(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.custom-alert-btn:active {
    transform: translateY(0);
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .custom-alert-container {
        border: 2px solid #000;
    }
    
    .custom-alert-btn {
        border: 2px solid currentColor;
    }
    
    .custom-alert-toast {
        border: 1px solid #000;
    }
}

/* Mobile Performance: Mobile-specific toast styles */
.custom-alert-toast.mobile-toast {
    /* Mobile Performance: Simplified styling for better performance */
    border-radius: 6px; /* Slightly reduced border radius */
    margin-bottom: 8px; /* Reduced margin for compact layout */
    /* Mobile Performance: Simplified shadow */
    box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.08);
    /* Mobile Performance: Disable complex hover effects */
    transform: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.custom-alert-toast.mobile-toast:hover {
    /* Mobile Performance: Simplified hover state */
    transform: translateX(-2px);
    box-shadow: 0 3px 10px -2px rgba(0, 0, 0, 0.1);
}

/* Mobile Performance: Touch-optimized close button */
.custom-alert-toast.mobile-toast .custom-alert-toast-close {
    /* Mobile Performance: Larger touch target */
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Mobile Performance: Simplified hover effect */
    transition: background-color 0.2s ease;
}

.custom-alert-toast.mobile-toast .custom-alert-toast-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: none;
}

/* Mobile Performance: Optimized progress bar for mobile */
.custom-alert-toast.mobile-toast .custom-alert-toast-progress {
    height: 2px; /* Reduced height for mobile */
    background: rgba(0, 0, 0, 0.05);
}

/* Mobile Performance: Swipe indicator */
.custom-alert-toast.mobile-toast::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0 3px 3px 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.custom-alert-toast.mobile-toast:hover::after {
    opacity: 1;
}

/* Mobile Performance: Reduced animations for better performance */
@media (max-width: 640px) {
    .custom-alert-toast.mobile-toast {
        /* Disable GPU-intensive effects */
        will-change: auto;
        /* Use simpler transitions */
        transition: opacity 0.15s ease;
    }
    
    .custom-alert-toast.mobile-toast.active {
        /* Simplified animation */
        opacity: 1;
        transform: translateX(0);
    }
}

/* Mobile Performance: Landscape orientation optimizations */
@media (max-width: 640px) and (orientation: landscape) {
    .custom-alert-toast.mobile-toast {
        max-height: 100px; /* Limit height in landscape */
        overflow: hidden;
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-message {
        /* Limit lines in landscape */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}

/* Mobile Performance: Small screen optimizations */
@media (max-width: 375px) {
    .custom-alert-toast.mobile-toast {
        margin-bottom: 6px;
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-header {
        padding: 8px;
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-icon {
        width: 18px;
        height: 18px;
        margin-right: 8px;
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-title {
        font-size: 0.8rem;
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-message {
        font-size: 0.75rem;
    }
}

/* Mobile Performance: Touch device specific styles */
@media (hover: none) and (pointer: coarse) {
    .custom-alert-toast.mobile-toast:hover {
        transform: none;
        box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.08);
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-close:hover {
        background-color: transparent;
    }
    
    /* Add active state for touch feedback */
    .custom-alert-toast.mobile-toast:active {
        transform: scale(0.98);
    }
    
    .custom-alert-toast.mobile-toast .custom-alert-toast-close:active {
        background-color: rgba(0, 0, 0, 0.1);
    }
}