/* Toast Notifications */
.toast-container {
    position: fixed;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    z-index: 10030;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    width: min(420px, calc(100% - 40px));
    align-items: flex-end;
}

.toast {
    background: linear-gradient(135deg, #2d5a2d 0%, #1a3a1a 100%);
    border: 1px solid #4ade80;
    border-radius: 12px;
    padding: 16px 20px;
    width: fit-content;
    min-width: min(320px, 100%);
    max-width: min(500px, 100%);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    position: relative;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

/* Neutralizzare le classi generiche (es. .error) anche se caricate dopo toast.css. */
.toast-container > .toast {
    margin: 0;
    text-align: left;
}

.toast.success {
    border-color: #4ade80;
    background: linear-gradient(135deg, #2d5a2d 0%, #1a3a1a 100%);
}

.toast.error {
    border-color: #ff4444;
    background: linear-gradient(135deg, #3a1a1a 0%, #1a0a0a 100%);
    box-shadow: 0 8px 25px rgba(255, 68, 68, 0.2);
}

.toast.warning {
    border-color: #ffc107;
    background: linear-gradient(135deg, #5a5a2d 0%, #3a3a1a 100%);
}

.toast-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.toast-title {
    color: #4ade80;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.error .toast-title {
    color: #ff4444;
}

.toast.warning .toast-title {
    color: #ffc107;
}

.toast-icon {
    flex-shrink: 0;
    font-size: 16px;
}

html body .toast .toast-close {
    --fs-button-size: 44px;
    --fs-glyph-size: 16px;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 20px;
    padding: 0;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    margin: -12px -12px -12px 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

html body .toast .toast-close:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: white;
}

.toast-close:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -4px;
}

.toast-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 4px;
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #4ade80;
    border-radius: 0 0 0 12px;
    animation: progress 3s linear forwards;
}

.toast.error .toast-progress {
    background: #ff4444;
}

.toast.warning .toast-progress {
    background: #ffc107;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes progress {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

.toast.removing {
    animation: slideOut 0.3s ease-in forwards;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .toast-container {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        left: auto;
        align-items: flex-end;
        width: min(380px, calc(100% - 24px));
    }
    
    .toast {
        min-width: min(280px, 100%);
        max-width: 100%;
        padding: 14px 16px;
    }
}

.toast { box-sizing: border-box; }
.toast-message, .toast-title { overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .toast, .toast.removing { animation-duration: 0.01ms; } }

.toast { touch-action:pan-y; }
