/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 头部样式 */
.header {
    background-color: #2c3e50;
    color: white;
    padding: 20px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    font-size: 2rem;
    font-weight: bold;
}

/* 导航菜单 */
.nav-menu {
    background-color: #ecf0f1;
    position: sticky;
    top: 80px; /* 头部高度 */
    z-index: 999;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.nav-items {
    display: flex;
}

.nav-item {
    display: inline-block;
    padding: 15px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-item.active {
    background-color: #3498db;
    color: white;
    font-weight: bold;
}

/* 新增：导航控件容器 */
.nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 新增：导航栏中的分类选择器 */
.category-selector {
    position: relative;
}

.category-selector::after {
    content: "▼";
    font-size: 0.7rem;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #7f8c8d;
}

.category-select-nav {
    appearance: none;
    background-color: transparent;
    border: none;
    padding: 8px 25px 8px 10px;
    font-size: 1rem;
    color: #333;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.category-select-nav:hover {
    background-color: rgba(41, 128, 185, 0.1);
}

.category-select-nav:focus {
    outline: none;
}

/* 搜索切换按钮 */
.toggle-filters-btn {
    color: #2980b9;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.3s;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
}

.toggle-filters-btn.active {
    background-color: #2980b9;
    color: #ffffff;
}

.search-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    position: relative;
}

.search-icon::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    border: 2px solid #2980b9;
    border-radius: 50%;
    box-sizing: border-box;
}

.search-icon::after {
    content: "";
    position: absolute;
    top: 10px;
    left: 10px;
    width: 8px;
    height: 2px;
    background-color: #2980b9;
    transform: rotate(45deg);
    transform-origin: 0 0;
    box-sizing: border-box;
}

.search-icon.close-icon::before {
    content: "✕";
    border: none;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.search-icon.close-icon::after {
    display: none;
}

/* 主体内容 */
.main {
    min-height: calc(100vh - 160px); /* 减去头部和底部高度 */
}

/* 搜索和筛选区域 - 固定在顶部 */
.filters {
    background-color: white;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: sticky; /* Changed back to sticky */
    top: 140px; /* Adjusted to account for header and nav heights */
    z-index: 998;
    margin: 0 auto;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    display: none; /* 默认隐藏 */
}

.filters.show {
    display: block; /* 显示搜索区域 */
}

.search-box {
    display: flex;
    margin-bottom: 15px;
}

.search-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px 0 0 4px;
    font-size: 1rem;
}

.search-btn {
    padding: 10px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    font-size: 1rem;
}

.search-btn:hover {
    background-color: #2980b9;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
}

.category-filter, .price-filter {
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-select, .price-input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.filter-btn {
    padding: 8px 15px;
    background-color: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.filter-btn:hover {
    background-color: #219653;
}

/* 遮罩层样式 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色 */
    z-index: 997; /* 低于搜索框但高于其他内容 */
    display: block;
}

.overlay.show {
    display: block;
}

/* 商品列表 */
.products-container {
    padding: 20px 0;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.product-card {
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    background: white;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.product-image {
    width: 100%;
    height: 200px;
    object-fit: contain;
}

.product-info {
    padding: 15px;
}

.product-name {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1rem;
}

.product-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.product-price {
    font-size: 1.1rem;
    color: #e74c3c;
    font-weight: bold;
}

.favorite-btn-list-inline {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: #bdc3c7;
}

.favorite-btn-list-inline.favorited {
    color: #e74c3c;
}

.product-category {
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* 加载更多 */
.load-more {
    text-align: center;
    margin-top: 30px;
}

.load-more-btn {
    padding: 12px 30px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.load-more-btn:hover {
    background-color: #2980b9;
}

.loading, .no-products {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

/* 商品详情 */
.breadcrumb {
    padding: 5px 0;
}

.back-button {
    padding: 10px 15px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.back-button:hover {
    background-color: #2980b9;
}

/* 修改: 让商品详情页占满整个页面 */
.product-detail {
    display: flex;
    gap: 30px;
    padding: 20px 0;
    flex-wrap: wrap;
    min-height: calc(100vh - 160px); /* 减去头部和底部高度 */
    width: 100%;
    margin: 0 auto;
}

.product-image-section {
    flex: 1;
    min-width: 300px;
}

.product-detail-image {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
}

.product-info-section {
    flex: 1;
    min-width: 300px;
}

.product-info-section .product-name {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

/* 修改: 创建新的容器用于价格和收藏按钮同行显示 */
.product-price-fav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.product-category {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #7f8c8d;
}

.product-price {
    font-size: 1.3rem;
    color: #e74c3c;
}

.product-description h3, .product-keywords h3 {
    margin: 20px 0 10px 0;
    font-size: 1.1rem;
}

.keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.keyword-tag {
    background-color: #ecf0f1;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.9rem;
}

.product-actions {
    margin-top: 30px;
}

/* 修改: 调整收藏按钮样式以适应新位置 */
.favorite-btn {
    padding: 8px 15px;
    font-size: 0.9rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background-color: #ecf0f1;
    white-space: nowrap;
}

.favorite-btn.favorited {
    background-color: #e74c3c;
    color: white;
}

/* 我的收藏 */
.favorites-container {
    padding: 20px 0;
}

.favorites-container h2 {
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.favorite-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #eee;
    gap: 15px;
    transition: background-color 0.3s;
}

.favorite-item:hover {
    background-color: #f9f9f9;
}

.favorite-image {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 8px;
    cursor: pointer;
}

.favorite-info {
    flex: 1;
    cursor: pointer;
}

.favorite-name {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 1rem;
}

.favorite-price {
    color: #e74c3c;
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 1.1rem;
}

.favorite-category {
    color: #7f8c8d;
    font-size: 0.9rem;
}

.remove-favorite-btn {
    background: none;
    border: 1px solid #e74c3c;
    color: #e74c3c;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.remove-favorite-btn:hover {
    background: #e74c3c;
    color: white;
}

.no-favorites {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

/* 图片模态框 */
.modal {
    display: block;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
}

.modal-content {
    display: block;
    margin: auto;
    max-width: 90%;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #bbb;
}

/* 底部 */
.footer {
    background-color: #34495e;
    color: white;
    text-align: center;
    padding: 20px 0;
    margin-top: 40px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 0 10px;
    }
    
    .header {
        /* padding: 15px 0; */
        display: none;
    }
    
    .logo {
        font-size: 1.5rem;
    }
    
    .nav-menu {
        top: 0;
        height: 56px;
        line-height: 56px;
    }
    
    .nav-container {
        flex-direction: row;
        padding: 0;
    }
    
    .nav-items {
        flex: 1;
    }

    .nav-item {
        padding: 0 15px;
    }
    
    /* 修改：移动端适配导航控件 */
    .nav-controls {
        margin-left: 10px;
    }
    
    .category-select-nav {
        padding: 0 20px 0 10px;
        font-size: 1rem;
    }
    
    .toggle-filters-btn {
        padding: 0 20px;
        font-size: 1.5rem;
        line-height: 56px;
        height: 56px;
    }
    
    .filters {
        top: 56px; /* Adjusted for mobile */
        padding: 15px;
        position: fixed;
        margin: 0;
    }
    
    .filter-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .search-box {
        margin-bottom: 10px;
    }
    
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }
    
    .product-image {
        height: 150px;
    }
    
    .product-detail-container {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow-y: scroll;
        z-index: 1000;
        top: 0;
        background: #fff;
        padding: 20px 20px;
    }

    .product-detail {
        flex-direction: column;
        min-height: auto; /* 移动端不需要最小高度限制 */
    }
    
    .product-info-section .product-name {
        font-size: 1.3rem;
    }
    
    /* 修改: 移动端适配价格和收藏按钮容器 */
    .product-price-fav-container {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .product-price {
        font-size: 1.2rem;
    }
    
    .favorites-container h2 {
        font-size: 1.3rem;
    }
}

/* Add specific styles for small screens to handle price filter better */
@media (max-width: 480px) {
    .filter-row {
        gap: 10px;
    }
    
    .category-filter, .price-filter {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }
    
    .category-select, .price-input {
        width: 100%;
    }
    
    .filter-btn {
        width: 100%;
    }
    
    .price-filter {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .price-input {
        flex: 1;
        min-width: 80px;
    }
}