/**
 * 全局公共样式
 * Hifoune 配件查询系统
 */

/* ==================== 全局防横向滚动条（安全兜底） ==================== */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ==================== 全局变量 ==================== */
:root {
    --primary-color: #1B7FE1;
    --primary-dark: #1568B8;
    --primary-light: #e6f2ff;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-600: #6c757d;
}

/* ==================== 顶部导航栏 ==================== */
.topbox {
    height: 60px;
    padding: 0 30px;
    overflow: visible;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%) !important;
    position: relative;
    box-shadow: 0 2px 12px rgba(27, 127, 225, 0.25);
}

.fl {
    float: left;
}

.topbox .fl img {
    max-height: 40px;
    width: auto;
    object-fit: contain;
    /* 蓝色logo → 先变纯黑 → 再反成纯白色 */
    filter: brightness(0) invert(1);
    image-rendering: auto;
    /* GPU加速，减少滤镜渲染模糊 */
    transform: translateZ(0);
    backface-visibility: hidden;
}

.topbox > ul > a {
    color: #ffffff !important;
}

.topbox > ul > a:hover {
    color: #e6f2ff !important;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* ==================== 导航按钮统一样式（替代内联onmouseover/onmouseout） ==================== */
.nav-btn {
    color: #ffffff;
    text-decoration: none;
    cursor: pointer;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    vertical-align: middle;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    border-radius: 6px;
    margin: 0 2px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    height: 40px;
    width: 40px;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 2px 8px rgba(27, 127, 225, 0.25);
}

.nav-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.nav-btn i {
    font-size: 20px;
    line-height: 1;
}

/* ==================== 徽章样式 ==================== */
.badge-count {
    position: absolute;
    top: -6px;
    right: -8px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #fff;
    font-size: 9px;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    height: 16px;
    line-height: 14px;
    text-align: center;
    display: none;
    box-shadow: 0 2px 6px rgba(27, 127, 225, 0.4);
    border: 1.5px solid #ffffff;
    letter-spacing: 0.3px;
}

/* ==================== 下拉菜单 ==================== */
.dropdown-menu-custom {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 120px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    list-style: none;
    padding: 6px 0;
    margin: 8px 0 0 0;
    z-index: 1000;
}

.dropdown-menu-custom li a {
    display: block;
    padding: 8px 16px;
    text-decoration: none;
    font-size: 13px;
    line-height: 1.5;
    transition: all 0.2s;
}

.dropdown-menu-custom li a:hover {
    background: #f5f5f5;
    color: #111111;
}

/* ==================== 卡片悬停效果 ==================== */
.card-hover {
    transition: transform 0.3s, box-shadow 0.3s;
}

.card-hover:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ==================== 搜索框 ==================== */
.search-box {
    max-width: 500px;
    margin: 30px auto;
    text-align: center;
}

/* ==================== 退出按钮 ==================== */
.logout-btn {
    color: #fff;
    background-color: var(--danger-color);
    padding: 6px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.3s;
}

.logout-btn:hover {
    background-color: #c82333;
    color: #fff;
}

/* ==================== 渐变背景 ==================== */
.bg-gradient-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.bg-gradient-light {
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
}

/* ==================== 通用按钮样式 ==================== */
.btn-primary-gradient {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(27, 127, 225, 0.3);
    transition: all 0.3s;
}

.btn-primary-gradient:hover {
    box-shadow: 0 4px 12px rgba(27, 127, 225, 0.4);
    transform: translateY(-1px);
    color: white;
}

.btn-success-gradient {
    background: linear-gradient(135deg, var(--success-color) 0%, #218838 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-danger-gradient {
    background: linear-gradient(135deg, var(--danger-color) 0%, #c82333 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

/* ==================== 模态框样式优化 ==================== */
.modal-header-gradient {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-bottom: none;
}

.modal-content-shadow {
    border: none;
    box-shadow: 0 8px 32px rgba(27, 127, 225, 0.2);
}

/* ==================== 表格样式 ==================== */
.table-header-gradient {
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
    color: var(--primary-color);
}

/* ==================== 移动端菜单按钮 ==================== */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    margin-right: 15px;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ==================== 空态图标样式（Bootstrap Icons 兼容） ==================== */
.empty-state-icon i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

/* ==================== 下拉菜单激活项样式 ==================== */
.dropdown-menu-custom li a.active-lang {
    background: var(--primary-color);
    color: #ffffff;
    font-weight: bold;
}

.dropdown-menu-custom li a.active-lang:hover {
    background: var(--primary-dark);
    color: #ffffff;
}

/* ==================== 响应式调整 ==================== */
@media (max-width: 768px) {
    .topbox {
        padding: 0 15px;
        height: auto;
        min-height: 60px;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
    }
    
    .topbox .fl {
        margin-top: 8px;
    }
    
    .topbox .fl img {
        max-height: 36px;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .topbox > ul.topbox-nav-menu {
        display: none !important;
        width: 100% !important;
        float: none !important;
        flex-direction: column !important;
        padding: 10px 15px !important;
        margin: 0 !important;
        gap: 8px !important;
        line-height: 1.5 !important;
        font-size: 14px !important;
        max-height: 80vh;
        overflow-y: auto;
        background: rgba(27, 127, 225, 0.95);
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
        border-radius: 0 0 8px 8px;
    }

    .topbox > ul.topbox-nav-menu.show {
        display: flex !important;
    }

    .topbox > ul.topbox-nav-menu.show > a,
    .topbox > ul.topbox-nav-menu.show > div {
        line-height: 1.5 !important;
    }

    .dropdown-menu-custom {
        position: static;
        box-shadow: none;
    }
}

/* ==================== 页脚样式 ==================== */
.foot {
    text-align: center;
    color: #525252;
    margin: 15px auto;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.foot a {
    color: #428bca;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.foot img {
    margin-right: 5px;
}

/* ==================== 筛选栏公共样式 ==================== */
.filter-section {
    background: linear-gradient(135deg, #f0f7ff 0%, var(--primary-light) 100%);
    border-radius: 8px;
    border: 1px solid #b3d9ff;
    box-sizing: border-box;
    overflow: hidden;
}

.filter-section .filter-section-label {
    color: var(--primary-color);
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 4px;
}

.filter-section .filter-btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 6px 16px;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(27, 127, 225, 0.3);
    transition: all 0.3s;
    white-space: nowrap;
}

.filter-section .filter-btn-primary:hover {
    box-shadow: 0 4px 12px rgba(27, 127, 225, 0.4);
    transform: translateY(-1px);
}

.filter-section .filter-btn-secondary {
    background: linear-gradient(135deg, var(--gray-600) 0%, #5a6268 100%);
    color: white;
    border: none;
    padding: 6px 16px;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
    transition: all 0.3s;
    white-space: nowrap;
}

.filter-section .filter-btn-secondary:hover {
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.5);
    transform: translateY(-1px);
}

/* ==================== 全局图片性能优化 ==================== */
/* 1. 防 CLS：图片有宽高属性时不被压缩 */
img {
    max-width: 100%;
    height: auto;
}

/* 2. 图片平滑渲染 */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* 3. 加载中图片骨架屏效果（lazy + 无 src 的） */
img[loading="lazy"]:not([src*=".svg"]):not(.loaded):not([src]) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: global-shimmer 1.5s ease-in-out infinite;
    min-height: 80px;
    min-width: 80px;
}
@keyframes global-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 4. 已加载图片淡入 */
img.loaded {
    animation: global-fade-in 0.4s ease-out;
}
@keyframes global-fade-in {
    from { opacity: 0.85; }
    to { opacity: 1; }
}

/* 5. 离屏卡片跳过渲染（桌面端第4个起） */
@media (min-width: 768px) {
    .card:nth-child(n+4),
    .category-card:nth-child(n+4) {
        content-visibility: auto;
        contain-intrinsic-size: 400px;
    }
}

/* ==================== 返回顶部按钮 ==================== */
/* Redesigned: subtle ghost style, right-aligned */
.back-to-top {
    position: fixed;
    right: 30px;
    bottom: 40px;
    width: 42px;
    height: 42px;
    border: 1px solid #e2e8f0;
    border-radius: 50%;
    background: #ffffff;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease, box-shadow 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    z-index: 999;
    padding: 0;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    color: #1B7FE1;
    border-color: #1B7FE1;
    box-shadow: 0 4px 16px rgba(27, 127, 225, 0.15);
}

.back-to-top:active {
    transform: translateY(0);
}

.back-to-top svg {
    width: 18px;
    height: 18px;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .back-to-top {
        right: 18px;
        bottom: 24px;
        width: 38px;
        height: 38px;
    }
    .back-to-top svg {
        width: 16px;
        height: 16px;
    }
}