/**
 * 搜索抽屉样式
 * 从 Shopify search-drawer 和 predictive-search 迁移
 *
 * @package Laifen_Russia
 * @since 1.0.0
 */

/* ========== Side Panel 基础样式 ========== */
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    width: calc(100vw - 30px);
    max-width: 480px;
    background: #ffffff;
    overflow-x: hidden;
    transform: translateX(100%);
    will-change: transform;
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    box-shadow: none;
}

.side-panel.active {
    transform: translateX(0%);
}

.side-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: -1;
}

.side-panel.active .side-panel-overlay {
    opacity: 1;
    visibility: visible;
}

.side-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    background: #ffffff;
}

/* ========== Search Drawer 头部 ========== */
.side-panel-header {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 35;
    background: #ffffff;
    border-bottom: 1px solid #e5e5e5;
    padding: 16px 20px;
    min-height: 72px;
    box-sizing: border-box;
}

.side-panel-header > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    height: 100%;
}

.side-panel .searchform {
    flex: 1;
    min-width: 0;
}

.side-panel .searchform fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f5f5f5;
    border: none;
    border-radius: 24px;
    padding: 0 16px;
    height: 40px;
}

.search-input-wrapper .search-icon {
    flex-shrink: 0;
    color: #666;
    width: 16px;
    height: 16px;
}

.search-input-wrapper .search-icon svg {
    width: 100%;
    height: 100%;
}

.side-panel .search-field {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 40px;
    border: 0;
    padding: 0;
    font-size: 14px;
    line-height: 40px;
    outline: 0;
    background: transparent;
    color: #020202;
}

.side-panel .search-field::placeholder {
    color: #999;
}

.side-panel .search-field::-webkit-search-decoration,
.side-panel .search-field::-webkit-search-cancel-button,
.side-panel .search-field::-webkit-search-results-button,
.side-panel .search-field::-webkit-search-results-decoration {
    display: none;
}

.side-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #020202;
    transition: opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.side-panel-close svg {
    display: block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.side-panel-close:hover,
.side-panel-close:active,
.side-panel-close:focus {
    opacity: 1;
    background: transparent;
    outline: none;
    box-shadow: none;
}

.side-panel-close:focus-visible {
    outline: none;
    box-shadow: none;
}

.side-panel-close:hover svg,
.side-panel-close:active svg,
.side-panel-close:focus svg {
    color: #4a9eff;
}

/* ========== 搜索内容区域 ========== */
.side-panel-content {
    padding: 20px;
    background: #ffffff;
}

.side-panel-content--results {
    display: none;
}

.side-panel-content--results.active {
    display: block;
}

.side-panel-content--results.active + .side-panel-content--initial {
    display: none;
}

/* 加载状态 */
.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: #666;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e5e5;
    border-top-color: var(--laifen-primary, #2b00ff);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== 热门搜索 ========== */
.thb-predictive-search--popular {
    margin-bottom: 30px;
}

.thb-predictive-search--label {
    display: block;
    font-weight: 600;
    font-size: 0.75rem;
    line-height: 1;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 15px;
    color: #666;
}

.popular-terms-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.popular-term {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    font-size: 0.75rem;
    text-transform: uppercase;
    height: 32px;
    border-radius: 100px;
    padding: 0 14px;
    font-weight: 500;
    border: 1px solid var(--color-header-border, #e5e5e5);
    color: var(--color-header-text, #020202);
    text-decoration: none;
    transition: all 0.2s ease;
}

.popular-term:hover,
.popular-term:active,
.popular-term:focus {
    color: #4a9eff;
    background: transparent;
    border-color: #4a9eff;
    outline: none;
}

/* ========== 推荐产品 ========== */
.thb-predictive-search--products {
    margin-bottom: 20px;
}

.search-products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.search-product-item {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: #020202;
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.search-product-item:hover {
    transform: none;
    box-shadow: none;
}

.search-product-image {
    aspect-ratio: 1;
    overflow: hidden;
    background: #f9f9f9;
}

.search-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.search-product-item:hover .search-product-image img {
    transform: none;
}

.search-product-info {
    padding: 10px;
}

.search-product-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0 0 5px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-product-price {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--laifen-primary, #000);
}

.search-product-price del {
    color: #999;
    font-weight: 400;
    margin-right: 5px;
}

/* ========== 搜索结果列表 ========== */
.search-results-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.search-result-item {
    display: flex;
    gap: 15px;
    padding: 15px 0;
    border-bottom: 1px solid var(--color-header-border, #e5e5e5);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-image {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
}

.search-result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.search-result-info {
    flex: 1;
}

.search-result-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0 0 5px;
}

.search-result-title a {
    color: var(--color-header-text, #020202);
    text-decoration: none;
}

.search-result-title a:hover,
.search-result-title a:active,
.search-result-title a:focus {
    color: #4a9eff;
    outline: none;
}

.search-result-price {
    font-size: 0.875rem;
    color: #666;
}

/* 无结果提示 */
.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.no-results h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.no-results p {
    margin: 0;
    font-size: 0.875rem;
}

/* 查看全部按钮 */
.view-all-results {
    display: block;
    text-align: center;
    padding: 15px;
    margin-top: 20px;
    background: var(--laifen-primary, #000);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.view-all-results:hover,
.view-all-results:active,
.view-all-results:focus {
    opacity: 1;
    color: #fff;
    background: var(--laifen-primary, #000);
    outline: none;
}

/* ========== Body 状态 ========== */
body.search-open {
    overflow: hidden;
}

/* ========== 响应式 ========== */
@media only screen and (max-width: 520px) {
    .side-panel {
        width: 100vw;
        max-width: none;
    }
}

@media only screen and (min-width: 768px) {
    .side-panel-header {
        padding: 20px 30px;
    }

    .side-panel-content {
        padding: 25px 30px;
    }
}
