/*
 * Gravatar头像优化CSS - 中国地区专用
 * 解决头像加载失败和显示问题
 */

/* 基础头像样式优化 */
img.avatar {
    border-radius: 50%;
    display: block;
    position: absolute;
    left: 0;
    transition: all 0.5s ease;
    background-color: #e9e9e9;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 头像加载失败时的备用样式 */
img.avatar.fallback {
    background-color: #e9e9e9;
    background-image: url('../images/author.svg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 头像加载中的样式 */
img.avatar.loading {
    background-color: #f5f5f5;
    background-image: linear-gradient(90deg, #f5f5f5 25%, #e9e9e9 50%, #f5f5f5 75%);
    background-size: 200% 100%;
    animation: avatar-loading 1.5s infinite;
}

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

/* 头像悬停效果 */
.comment > .comment-body:hover img.avatar {
    transform: scale(0.8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 作者头像特殊样式 */
.about-author img.avatar {
    position: relative;
    float: left;
    margin-right: 20px;
    margin-bottom: 20px;
}

/* 移动端头像优化 */
@media (max-width: 768px) {
    img.avatar {
        width: 60px !important;
        height: 60px !important;
    }

    .comment > .comment-body:hover img.avatar {
        transform: scale(0.9);
    }
}

@media (max-width: 480px) {
    img.avatar {
        width: 50px !important;
        height: 50px !important;
    }

    .about-author img.avatar {
        float: none;
        display: block;
        margin: 0 auto 15px;
    }
}

/* 头像容器样式 */
.avatar-container {
    position: relative;
    display: inline-block;
}

.avatar-container .avatar-placeholder {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background-color: #e9e9e9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #999;
    font-weight: bold;
}

/* 头像错误处理 */
img.avatar[alt]:after {
    content: attr(alt);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #e9e9e9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #999;
    text-align: center;
}

/* 头像预加载指示器 */
.avatar-preloader {
    position: relative;
}

.avatar-preloader:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #e9e9e9;
    border-top: 2px solid #999;
    border-radius: 50%;
    animation: avatar-spin 1s linear infinite;
    z-index: 1;
}

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

/* 头像缓存状态指示 */
.avatar-cached {
    opacity: 1;
    transition: opacity 0.3s ease;
}

.avatar-not-cached {
    opacity: 0.8;
}

/* WooCommerce评论头像优化 */
.woocommerce #reviews #comments ol.commentlist li img.avatar,
.woocommerce-page #reviews #comments ol.commentlist li img.avatar {
    border-radius: 50%;
    background-color: #fff;
    border: 2px solid #e9e9e9;
}

/* 头像懒加载样式 */
img.avatar[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img.avatar[loading="lazy"].loaded {
    opacity: 1;
}