/* ============================================
   Future-Action 載入系統樣式表
   ============================================ */

/* ========== 全站載入畫面 ========== */
#pagePreloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgb(43, 35, 56);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), 
                visibility 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

#pagePreloader.loaded {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* 主要載入內容 */
.preloader-content {
    text-align: center;
    position: relative;
}

/* Logo 動畫 */
.preloader-logo {
    width: 350px;
    height: 350px;
    margin-bottom: 40px;
    opacity: 0;
    animation: logoFadeIn 0.8s ease-out 0.2s forwards;
}

.preloader-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 20px rgba(105, 191, 151, 0.3));
}

@keyframes logoFadeIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0deg);
    }
}

/* 載入點動畫 */
.preloader-dots {
    display: flex;
    justify-content: center;
    gap: 20px;
    opacity: 0;
    animation: dotsFadeIn 0.5s ease-out 0.6s forwards;
}

.preloader-dot {
    width: 15px;
    height: 15px;
    background: #69BF97;
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(105, 191, 151, 0.5);
}

.preloader-dot:nth-child(1) {
    animation-delay: 0s;
    background: #69BF97;
}

.preloader-dot:nth-child(2) {
    animation-delay: 0.2s;
    background: #92ffc8;
}

.preloader-dot:nth-child(3) {
    animation-delay: 0.4s;
    background: #d7ffea;
}

@keyframes dotsFadeIn {
    to {
        opacity: 1;
    }
}

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    40% {
        transform: scale(1.5);
        opacity: 0.6;
    }
}

/* 載入文字 */
.preloader-text {
    margin-top: 30px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 2px;
    opacity: 0;
    animation: textFade 2s ease-in-out 0.8s infinite;
}

@keyframes textFade {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.8;
    }
}

/* ========== 圖片載入系統 ========== */

/* 圖片載入容器 */
.img-loader-wrapper {
    position: relative;
    overflow: hidden;
    background: rgb(43, 35, 56);
}

/* 圓形圖片載入器（專案預覽用） */
.image-cropper-project.with-loader {
    position: relative;
    background: linear-gradient(135deg, 
        rgba(43, 35, 56, 1) 0%, 
        rgba(105, 191, 151, 0.05) 100%);
}

/* 圖片載入遮罩 */
.img-loader-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(43, 35, 56, 0.95);
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease-out, visibility 0.4s ease-out;
    border-radius: inherit;
}

.img-loader-mask.loaded {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* 環形載入器 */
.spinner-circle {
    width: 50px;
    height: 50px;
    position: relative;
}

.spinner-circle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.spinner-circle::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top-color: #69BF97;
    border-right-color: #92ffc8;
    border-radius: 50%;
    animation: spinRotate 1s linear infinite;
}

@keyframes spinRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 波紋載入器 */
.ripple-loader {
    width: 60px;
    height: 60px;
    position: relative;
}

.ripple-loader span {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-radius: 50%;
    background: #69BF97;
    animation: ripple 1.5s ease-out infinite;
}

.ripple-loader span:nth-child(2) {
    animation-delay: 0.5s;
}

@keyframes ripple {
    0% {
        width: 20px;
        height: 20px;
        opacity: 1;
    }
    100% {
        width: 60px;
        height: 60px;
        margin: -30px 0 0 -30px;
        opacity: 0;
    }
}

/* 漸層載入動畫 */
.shimmer-loader {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(105, 191, 151, 0.2) 50%, 
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: inherit;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* 圖片淡入效果 */
.lazy-img {
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.lazy-img.img-loaded {
    opacity: 1;
}

/* 動畫 Logo 載入器 */
.animated-logo-loader {
    width: 80px;
    height: 80px;
    margin: 0 auto;
    position: relative;
    animation: logoFloat 2s ease-in-out infinite;
}

.animated-logo-loader img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.95;
    filter: drop-shadow(0 0 15px rgba(105, 191, 151, 0.4));
}

/* 浮動動畫效果 */
@keyframes logoFloat {
    0%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.8;
    }
    50% {
        transform: translateY(-10px) scale(1.05);
        opacity: 1;
    }
}

/* 旋轉動畫效果（備用） */
@keyframes logoSpin {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 0.6;
    }
    25% {
        transform: rotate(90deg) scale(1.1);
        opacity: 0.8;
    }
    50% {
        transform: rotate(180deg) scale(1);
        opacity: 1;
    }
    75% {
        transform: rotate(270deg) scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: rotate(360deg) scale(1);
        opacity: 0.6;
    }
}

/* GIF 預覽載入效果 */
.gif-preview-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    text-align: center;
    z-index: 5;
}

.gif-preview-loader .loader-text {
    margin-top: 15px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 1px;
    animation: textPulse 1.5s ease-in-out infinite;
}

@keyframes textPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ========== CSS Spinner（取代 video 載入指示器）========== */

.css-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: cssSpinnerRotate 0.8s linear infinite;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.css-spinner.large {
    width: 50px;
    height: 50px;
    border-width: 4px;
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    margin: 0 auto 20px;
}

@keyframes cssSpinnerRotate {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}
.css-spinner.large {
    animation-name: cssSpinnerRotateLarge;
}
@keyframes cssSpinnerRotateLarge {
    to { transform: rotate(360deg); }
}

/* ========== 內容載入動畫 ========== */

/* PJAX 頁面切換載入 */
.content-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(43, 35, 56, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.content-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* 內容載入指示器 */
.content-loader {
    text-align: center;
    position: relative;
}

.content-loader .animated-logo-loader {
    width: 100px;
    height: 100px;
    margin: 0 auto 20px;
}

.content-loader-text {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.9);
    letter-spacing: 2px;
    animation: textFadeInOut 1.5s ease-in-out infinite;
}

@keyframes textFadeInOut {
    0%, 100% {
        opacity: 0.5;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-5px);
    }
}

/* ========== 骨架屏效果 ========== */

.skeleton-screen {
    animation: skeletonLoading 1.5s ease-in-out infinite;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    border-radius: 4px;
}

@keyframes skeletonLoading {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 12px;
    width: 100%;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-title {
    height: 28px;
    margin-bottom: 20px;
    width: 40%;
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 12px;
    margin-bottom: 20px;
}

.skeleton-circle {
    width: 260px;
    height: 260px;
    border-radius: 50%;
    margin: 0 auto 20px;
}

/* ========== 響應式調整 ========== */

@media screen and (max-width: 768px) {
    .preloader-logo {
        width: 100px;
        height: 100px;
    }
    
    .animated-logo-loader {
        width: 60px;
        height: 60px;
    }
    
    .content-loader .animated-logo-loader {
        width: 80px;
        height: 80px;
    }
    
    .preloader-dots {
        gap: 15px;
    }
    
    .preloader-dot {
        width: 12px;
        height: 12px;
    }
    
    .spinner-circle {
        width: 40px;
        height: 40px;
    }
    
    .skeleton-circle {
        width: 180px;
        height: 180px;
    }
}

/* ========== 舊系統相容 ========== */

/* 隱藏舊的 LoadingBG */
#LoadingBG {
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

#LoadingBG.hide {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* ========== 效能優化 ========== */

/* 使用 GPU 加速 */
.img-loader-mask,
.lazy-img,
.spinner-circle::after,
.shimmer-loader {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 減少動畫對低效能裝置的影響 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}