:root {
    --ts-search-border: #e5e7eb;
    --ts-search-muted: #6b7280;
    --ts-search-text: #111827;
    --ts-search-soft: #f7f7f8;
    --ts-search-card: #ffffff;
}

body.ts-search-open {
    overflow: hidden;
}

.ts-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
    background: #fff;
    color: var(--ts-search-text);
    opacity: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/*
   Author display rules such as display:flex/grid can override the browser's
   default [hidden] rule. Search state visibility must always win.
*/
.ts-search-overlay [hidden] {
    display: none !important;
}

.ts-search-overlay.is-open {
    display: block;
    animation: ts-search-fade-in 160ms ease-out forwards;
}

.ts-search-shell {
    min-height: 100dvh;
    background: #fff;
}

.ts-search-header {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 24px 24px 18px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--ts-search-border);
    backdrop-filter: blur(10px);
}

.ts-search-header-inner,
.ts-search-content {
    width: min(100%, 1160px);
    margin: 0 auto;
}

.ts-search-header-inner {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
}

.ts-search-close,
.ts-search-input-clear,
.ts-search-section-head button {
    border: 0;
    background: transparent;
    cursor: pointer;
    color: inherit;
}

.ts-search-close {
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ts-search-border);
    border-radius: 14px;
    font-size: 20px;
    transition: background 140ms ease, border-color 140ms ease;
}

.ts-search-close:hover {
    background: var(--ts-search-soft);
    border-color: #d1d5db;
}

.ts-search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
}

.ts-search-input-wrap > .icon-search {
    position: absolute;
    inset-inline-start: 18px;
    z-index: 1;
    color: var(--ts-search-muted);
    font-size: 21px;
    pointer-events: none;
}

.ts-search-input {
    width: 100%;
    height: 58px;
    padding: 0 54px 0 50px;
    border: 1px solid #d9dde3;
    border-radius: 18px;
    outline: none;
    background: #fff;
    color: var(--ts-search-text);
    font: inherit;
    font-size: 18px;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    appearance: none;
    -webkit-appearance: none;
}

.ts-search-input::-webkit-search-cancel-button {
    display: none;
}

.ts-search-input:focus {
    border-color: #9ca3af;
    box-shadow: 0 0 0 4px rgba(17, 24, 39, 0.05);
}

.ts-search-input::placeholder {
    color: #9ca3af;
}

.ts-search-input-clear {
    position: absolute;
    inset-inline-end: 14px;
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--ts-search-muted);
    font-size: 16px;
}

.ts-search-input-clear:hover {
    background: var(--ts-search-soft);
}

.ts-search-content {
    padding: 34px 24px 72px;
}

.ts-search-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.ts-search-section-head h3,
.ts-search-group-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.ts-search-section-head button {
    color: #8b8f98;
    font: inherit;
    font-size: 13px;
}

.ts-search-section-head button:hover {
    color: var(--ts-search-text);
}

.ts-search-recent-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.ts-search-recent-chip {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border: 1px solid #d8dce2;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.ts-search-recent-chip:hover {
    background: var(--ts-search-soft);
    border-color: #c6cbd2;
    transform: translateY(-1px);
}

.ts-search-recent-empty,
.ts-search-message {
    padding: 34px 20px;
    border: 1px dashed #d8dce2;
    border-radius: 18px;
    color: var(--ts-search-muted);
    text-align: center;
}

.ts-search-spinner-wrap {
    display: flex;
    min-height: 180px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--ts-search-muted);
    font-size: 14px;
}

.ts-search-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid #d1d5db;
    border-top-color: #111827;
    border-radius: 50%;
    animation: ts-search-spin 650ms linear infinite;
}

.ts-search-groups {
    display: grid;
    gap: 32px;
}

.ts-search-group {
    display: grid;
    gap: 14px;
}

.ts-search-group-title {
    padding-bottom: 10px;
    border-bottom: 1px solid #eceef1;
}

.ts-search-simple-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.ts-search-simple-item {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border: 1px solid var(--ts-search-border);
    border-radius: 16px;
    background: var(--ts-search-card);
    color: inherit;
    text-decoration: none;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.ts-search-simple-item:hover {
    background: var(--ts-search-soft);
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.ts-search-simple-copy {
    min-width: 0;
}

.ts-search-simple-title {
    overflow: hidden;
    color: var(--ts-search-text);
    font-size: 15px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ts-search-simple-subtitle {
    overflow: hidden;
    margin-top: 4px;
    color: var(--ts-search-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ts-search-simple-item::after {
    content: "←";
    flex: 0 0 auto;
    color: #9ca3af;
}

.ts-search-product-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.ts-search-product-item {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 14px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--ts-search-border);
    border-radius: 18px;
    background: var(--ts-search-card);
    color: inherit;
    text-decoration: none;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.ts-search-product-item:hover {
    background: var(--ts-search-soft);
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.ts-search-product-image-wrap {
    position: relative;
    width: 86px;
    height: 86px;
    overflow: hidden;
    border-radius: 14px;
    background: #f3f4f6;
}

.ts-search-product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ts-search-product-item.is-unavailable .ts-search-product-image {
    filter: grayscale(1);
    opacity: 0.58;
}

.ts-search-product-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
}

.ts-search-product-title {
    display: -webkit-box;
    overflow: hidden;
    color: var(--ts-search-text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.8;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.ts-search-product-subtitle {
    overflow: hidden;
    margin-top: 3px;
    color: var(--ts-search-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ts-search-product-price {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    margin-top: 8px;
    color: var(--ts-search-text);
    font-size: 14px;
    font-weight: 700;
}

.ts-search-product-old-price {
    color: #9ca3af;
    font-size: 12px;
    font-weight: 400;
    text-decoration: line-through;
}

.ts-search-product-unavailable {
    margin-top: 8px;
    color: #9ca3af;
    font-size: 12px;
}

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

@keyframes ts-search-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 640px) {
    .ts-search-header {
        padding: 14px 14px 12px;
    }

    .ts-search-header-inner {
        grid-template-columns: 40px minmax(0, 1fr);
        gap: 10px;
    }

    .ts-search-close {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }

    .ts-search-input {
        height: 50px;
        padding-inline-start: 46px;
        padding-inline-end: 46px;
        border-radius: 15px;
        font-size: 15px;
    }

    .ts-search-input-wrap > .icon-search {
        inset-inline-start: 16px;
        font-size: 18px;
    }

    .ts-search-content {
        padding: 24px 14px 96px;
    }

    .ts-search-simple-list,
    .ts-search-product-list {
        grid-template-columns: minmax(0, 1fr);
    }

    .ts-search-product-item {
        grid-template-columns: 76px minmax(0, 1fr);
    }

    .ts-search-product-image-wrap {
        width: 76px;
        height: 76px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ts-search-overlay.is-open,
    .ts-search-spinner,
    .ts-search-recent-chip,
    .ts-search-simple-item,
    .ts-search-product-item {
        animation: none;
        transition: none;
    }
}
