/**
 * UX Enhancement Components
 * Loading states, skeletons, toasts, and animations
 * 
 * @package Silva_Customer_Portal
 * @since 2.6.0
 */

/* ================================
   LOADING STATES & SKELETONS
   ================================ */

/* Loading Overlay */
.silva-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    backdrop-filter: blur(4px);
}

.silva-loading-overlay.hidden {
    display: none;
}

/* Spinner Component */
.silva-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: silva-spin 0.8s linear infinite;
}

.silva-spinner-small {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.silva-spinner-large {
    width: 60px;
    height: 60px;
    border-width: 4px;
}

@keyframes silva-spin {
    to { transform: rotate(360deg); }
}

/* Button Loading State */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: silva-spin 0.6s linear infinite;
}

/* Skeleton Screens */
.silva-skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #e0e0e0 20%,
        #f0f0f0 40%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: silva-skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes silva-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton Card */
.silva-skeleton-card {
    padding: 20px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 16px;
}

.silva-skeleton-line {
    height: 16px;
    margin-bottom: 12px;
}

.silva-skeleton-line:last-child {
    margin-bottom: 0;
}

.silva-skeleton-line-short {
    width: 60%;
}

.silva-skeleton-line-medium {
    width: 80%;
}

.silva-skeleton-title {
    height: 24px;
    width: 40%;
    margin-bottom: 16px;
}

.silva-skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

/* Skeleton Grid */
.silva-skeleton-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* ================================
   TOAST NOTIFICATIONS
   ================================ */

.silva-toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    pointer-events: none;
}

.silva-toast {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15), 
                0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 16px 20px;
    display: flex;
    align-items: start;
    gap: 12px;
    min-width: 300px;
    pointer-events: all;
    animation: silva-toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-left: 4px solid #6b7280;
}

.silva-toast.toast-success {
    border-left-color: #10b981;
}

.silva-toast.toast-error {
    border-left-color: #ef4444;
}

.silva-toast.toast-warning {
    border-left-color: #f59e0b;
}

.silva-toast.toast-info {
    border-left-color: #3b82f6;
}

.silva-toast.hiding {
    animation: silva-toast-out 0.3s cubic-bezier(0.36, 0, 0.66, -0.56) forwards;
}

@keyframes silva-toast-in {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes silva-toast-out {
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.silva-toast-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

.toast-success .silva-toast-icon { color: #10b981; }
.toast-error .silva-toast-icon { color: #ef4444; }
.toast-warning .silva-toast-icon { color: #f59e0b; }
.toast-info .silva-toast-icon { color: #3b82f6; }

.silva-toast-content {
    flex: 1;
    min-width: 0;
}

.silva-toast-title {
    font-weight: 600;
    font-size: 14px;
    color: #111827;
    margin: 0 0 4px 0;
}

.silva-toast-message {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.silva-toast-close {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.silva-toast-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

/* Mobile Toast Adjustments */
@media (max-width: 768px) {
    .silva-toast-container {
        top: auto;
        bottom: 80px;
        left: 12px;
        right: 12px;
        max-width: none;
    }
    
    .silva-toast {
        min-width: 0;
    }
    
    @keyframes silva-toast-in {
        from {
            transform: translateY(100px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    @keyframes silva-toast-out {
        to {
            transform: translateY(100px);
            opacity: 0;
        }
    }
}

/* ================================
   BACK TO TOP BUTTON
   ================================ */

.silva-back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(1, 67, 133, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    z-index: var(--z-sticky);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.silva-back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.silva-back-to-top:hover {
    background: var(--primary-dark);
    transform: translateY(-4px);
    box-shadow: 0 6px 20px rgba(1, 67, 133, 0.4);
}

.silva-back-to-top:active {
    transform: translateY(-2px);
}

/* Mobile adjustment */
@media (max-width: 768px) {
    .silva-back-to-top {
        bottom: 88px; /* Above bottom nav */
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

/* ================================
   BREADCRUMBS
   ================================ */

.silva-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 16px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.silva-breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.silva-breadcrumb-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

.silva-breadcrumb-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.silva-breadcrumb-separator {
    color: #d1d5db;
    user-select: none;
}

.silva-breadcrumb-current {
    color: #111827;
    font-weight: 500;
}

/* ================================
   HELP TOOLTIPS
   ================================ */

.silva-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
    cursor: help;
    position: relative;
    margin-left: 6px;
    transition: all 0.2s;
}

.silva-help-icon:hover {
    background: var(--primary-color);
    color: white;
}

.silva-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
    white-space: nowrap;
    max-width: 280px;
    white-space: normal;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: var(--z-tooltip);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    pointer-events: none;
}

.silva-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1f2937;
}

.silva-help-icon:hover .silva-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Mobile tooltip adjustments */
@media (max-width: 768px) {
    .silva-tooltip {
        max-width: 200px;
        font-size: 12px;
    }
}

/* ================================
   ONBOARDING CHECKLIST
   ================================ */

.silva-onboarding-card {
    background: linear-gradient(135deg, #014385 0%, #0369a1 100%);
    color: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 12px rgba(1, 67, 133, 0.15);
}

.silva-onboarding-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 8px 0;
}

.silva-onboarding-subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin: 0 0 20px 0;
}

.silva-onboarding-checklist {
    list-style: none;
    padding: 0;
    margin: 0;
}

.silva-onboarding-item {
    display: flex;
    align-items: start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.silva-onboarding-item:last-child {
    border-bottom: none;
}

.silva-onboarding-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    transition: all 0.2s;
}

.silva-onboarding-item.completed .silva-onboarding-checkbox {
    background: white;
    border-color: white;
    color: var(--primary-color);
}

.silva-onboarding-item-content {
    flex: 1;
}

.silva-onboarding-item-title {
    font-weight: 600;
    margin: 0 0 4px 0;
}

.silva-onboarding-item-desc {
    font-size: 13px;
    opacity: 0.85;
    margin: 0;
}

.silva-onboarding-item.completed .silva-onboarding-item-title {
    opacity: 0.7;
    text-decoration: line-through;
}

.silva-onboarding-progress {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.silva-onboarding-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.silva-onboarding-progress-fill {
    height: 100%;
    background: white;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.silva-onboarding-progress-text {
    font-size: 13px;
    opacity: 0.9;
    text-align: center;
}

.silva-onboarding-dismiss {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    margin-top: 16px;
    transition: all 0.2s;
}

.silva-onboarding-dismiss:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ================================
   FADE IN ANIMATIONS
   ================================ */

.silva-fade-in {
    animation: silva-fade-in 0.3s ease-out;
}

@keyframes silva-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.silva-slide-in-right {
    animation: silva-slide-in-right 0.3s ease-out;
}

@keyframes silva-slide-in-right {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ================================
   SMOOTH TRANSITIONS & MICRO-INTERACTIONS
   ================================ */

/* Global smooth transitions */
.silva-customer-dashboard .tab-panel {
    transition: opacity 0.2s ease-in-out;
}

.silva-customer-dashboard .tab-panel[hidden] {
    opacity: 0;
}

.silva-customer-dashboard .tab-panel:not([hidden]) {
    animation: silva-fade-in 0.3s ease-in-out;
}

/* Button press effect */
.silva-customer-dashboard button:not(:disabled):active,
.silva-customer-dashboard .btn:not(:disabled):active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* Card hover lift effect */
.silva-customer-dashboard .project-card,
.silva-customer-dashboard .silva-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.silva-customer-dashboard .project-card:hover,
.silva-customer-dashboard .silva-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

/* Checkbox animation */
.silva-customer-dashboard input[type="checkbox"] {
    transition: all 0.2s ease;
}

.silva-customer-dashboard input[type="checkbox"]:checked {
    animation: silva-checkbox-bounce 0.3s ease;
}

@keyframes silva-checkbox-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Focus ring animation */
.silva-customer-dashboard *:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    animation: silva-focus-ring 0.3s ease;
}

@keyframes silva-focus-ring {
    from {
        outline-offset: 0;
    }
    to {
        outline-offset: 2px;
    }
}

/* Loading shimmer effect */
@keyframes silva-shimmer {
    0% {
        background-position: -200% center;
    }
    100% {
        background-position: 200% center;
    }
}

/* Badge pulse on update */
.silva-badge-new {
    animation: silva-badge-pulse 2s ease-in-out infinite;
}

@keyframes silva-badge-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(59, 130, 246, 0);
    }
}

/* Smooth scrolling for internal links */
html {
    scroll-behavior: smooth;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
