/* ==========================================================================
   CritterSearch – Frontend Styles
   BEM: .cs-search, .cs-search__input, .cs-search__results, .cs-search__item
   ========================================================================== */

/* ---- CSS Custom Properties -------------------------------------------- */

:root {
    --cs-border-color: #ddd;
    --cs-icon-color: #333;
    --cs-btn-bg: #333;
    --cs-btn-text: #ffffff;
    --cs-max-width: 600px;
    --cs-bg: #fff;
    --cs-bg-hover: #f5f5f5;
    --cs-text: #333;
    --cs-text-secondary: #777;
    --cs-radius-pill: 24px;
    --cs-radius-rect: 4px;
    --cs-shadow: 0 4px 20px rgba(0,0,0,0.12);
    --cs-transition: 0.2s ease;
}

/* ---- Base search wrapper --------------------------------------------- */

.cs-search {
    position: relative;
    width: 100%;
    max-width: var(--cs-max-width);
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
    z-index: 999;
    overflow: visible;
}

.cs-search *,
.cs-search *::before,
.cs-search *::after {
    box-sizing: border-box;
}

/* ---- Search form ----------------------------------------------------- */

.cs-search__form {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    background: var(--cs-bg);
    border: 1px solid var(--cs-border-color);
    transition: border-color var(--cs-transition), box-shadow var(--cs-transition);
}

.cs-search__form:focus-within {
    border-color: #999;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

/* ---- Search icon ----------------------------------------------------- */

.cs-search__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    color: var(--cs-icon-color);
    cursor: pointer;
    flex-shrink: 0;
}

.cs-search__icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---- Input ----------------------------------------------------------- */

.cs-search__input {
    flex: 1;
    width: 100%;
    height: 44px;
    padding: 0 12px 0 0;
    margin: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: var(--cs-text);
    -webkit-appearance: none;
    appearance: none;
}

.cs-search__input::placeholder {
    color: #999;
}

.cs-search__input::-webkit-search-decoration,
.cs-search__input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

/* ---- Submit button --------------------------------------------------- */

.cs-search__submit {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    border: none;
    background: var(--cs-btn-bg);
    color: var(--cs-btn-text);
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity var(--cs-transition);
}

.cs-search__submit:hover {
    opacity: 0.85;
}

.cs-search__submit svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cs-search--show-submit .cs-search__submit {
    display: flex;
}

/* Submit button with text label */
.cs-search__submit--labeled {
    width: auto;
    min-width: auto;
    padding: 0 16px;
    gap: 6px;
}

.cs-search__submit-label {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* ---- Spinner (loading state) ----------------------------------------- */

.cs-search--loading .cs-search__icon svg {
    animation: cs-spin 0.8s linear infinite;
}

@keyframes cs-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Bar Styles
   ========================================================================== */

/* Rounded (pill) */
.cs-search--rounded .cs-search__form {
    border-radius: var(--cs-radius-pill);
}
.cs-search--rounded .cs-search__icon {
    border-radius: var(--cs-radius-pill) 0 0 var(--cs-radius-pill);
}
.cs-search--rounded .cs-search__submit {
    border-radius: 0 var(--cs-radius-pill) var(--cs-radius-pill) 0;
}

/* Compact (smaller pill) */
.cs-search--compact .cs-search__form {
    border-radius: var(--cs-radius-pill);
}
.cs-search--compact .cs-search__icon {
    width: 36px;
    min-width: 36px;
    height: 36px;
    border-radius: var(--cs-radius-pill) 0 0 var(--cs-radius-pill);
}
.cs-search--compact .cs-search__input {
    height: 36px;
    font-size: 13px;
}
.cs-search--compact .cs-search__submit {
    width: 36px;
    min-width: 36px;
    height: 36px;
    border-radius: 0 var(--cs-radius-pill) var(--cs-radius-pill) 0;
}

/* Rectangular */
.cs-search--rect .cs-search__form {
    border-radius: var(--cs-radius-rect);
}
.cs-search--rect .cs-search__icon {
    border-radius: var(--cs-radius-rect) 0 0 var(--cs-radius-rect);
}
.cs-search--rect .cs-search__submit {
    border-radius: 0 var(--cs-radius-rect) var(--cs-radius-rect) 0;
}

/* ==========================================================================
   Layouts
   ========================================================================== */

/* Classic: always-visible bar (default — no extra rules needed) */

/* Icon: collapsed to icon, expand on click */
.cs-search--icon .cs-search__form {
    width: 44px;
    overflow: hidden;
    transition: width 0.3s ease;
}
.cs-search--icon .cs-search__input {
    opacity: 0;
    width: 0;
    padding: 0;
    transition: opacity 0.2s ease, width 0.3s ease;
}
.cs-search--icon.cs-search--expanded .cs-search__form {
    width: 100%;
}
.cs-search--icon.cs-search--expanded .cs-search__input {
    opacity: 1;
    width: 100%;
    padding: 0 12px 0 0;
}

/* Icon-responsive: icon on mobile, bar on desktop */
.cs-search--icon-responsive .cs-search__form {
    transition: width 0.3s ease;
}

@media (max-width: 991px) {
    .cs-search--icon-responsive .cs-search__form {
        width: 44px;
        overflow: hidden;
    }
    .cs-search--icon-responsive .cs-search__input {
        opacity: 0;
        width: 0;
        padding: 0;
    }
    .cs-search--icon-responsive.cs-search--expanded .cs-search__form {
        width: 100%;
    }
    .cs-search--icon-responsive.cs-search--expanded .cs-search__input {
        opacity: 1;
        width: 100%;
        padding: 0 12px 0 0;
    }
}

/* ==========================================================================
   Results dropdown
   ========================================================================== */

.cs-search__results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--cs-bg);
    border: 1px solid var(--cs-border-color);
    border-radius: 8px;
    box-shadow: var(--cs-shadow);
    max-height: 460px;
    overflow-y: auto;
    z-index: 1000;
    -webkit-overflow-scrolling: touch;
}

/* Taller results when detail panel is active */
@media (min-width: 992px) {
    .cs-search--has-panel .cs-search__results {
        max-height: 600px;
    }
}

.cs-search__results--open {
    display: block;
}

/* Scrollbar styling */
.cs-search__results::-webkit-scrollbar {
    width: 6px;
}
.cs-search__results::-webkit-scrollbar-track {
    background: transparent;
}
.cs-search__results::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ---- Group headers --------------------------------------------------- */

.cs-search__group {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cs-text-secondary);
    border-bottom: 1px solid #eee;
}

/* ---- Result items ---------------------------------------------------- */

.cs-search__item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    transition: background var(--cs-transition);
    border-bottom: 1px solid #f5f5f5;
}

.cs-search__item:last-child {
    border-bottom: none;
}

.cs-search__item:hover,
.cs-search__item--active {
    background: var(--cs-bg-hover);
}

/* Product item */
.cs-search__item--product {
    gap: 12px;
}

.cs-search__item-thumb {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 4px;
    overflow: hidden;
    background: #f9f9f9;
}

.cs-search__item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cs-search__item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.cs-search__item-title {
    font-weight: 500;
    color: var(--cs-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-search__item-title strong {
    font-weight: 700;
    color: #000;
}

.cs-search__item-sku {
    font-size: 11px;
    color: var(--cs-text-secondary);
}

.cs-search__item-desc {
    font-size: 12px;
    color: var(--cs-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-search__item-price {
    font-size: 13px;
    font-weight: 600;
    color: var(--cs-text);
}

.cs-search__item-price del {
    color: #aaa;
    font-weight: 400;
    margin-right: 4px;
}

.cs-search__item-price ins {
    text-decoration: none;
    color: #c00;
}

/* Category / tag item */
.cs-search__item--category,
.cs-search__item--tag {
    gap: 8px;
}

.cs-search__item--category .cs-search__item-title,
.cs-search__item--tag .cs-search__item-title {
    font-weight: 500;
}

.cs-search__item-count {
    font-size: 12px;
    color: var(--cs-text-secondary);
    margin-left: auto;
}

/* "See all" item */
.cs-search__item--more {
    justify-content: center;
    padding: 12px 14px;
    border-top: 1px solid #eee;
}

.cs-search__item-more {
    font-weight: 600;
    font-size: 13px;
    color: #0066cc;
}

.cs-search__item--more:hover .cs-search__item-more {
    text-decoration: underline;
}

/* No results */
.cs-search__no-results {
    padding: 20px 14px;
    text-align: center;
    color: var(--cs-text-secondary);
    font-size: 14px;
}

/* ==========================================================================
   Dark overlay / backdrop
   ========================================================================== */

.cs-search__backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 998;
    transition: opacity var(--cs-transition);
    opacity: 0;
}

.cs-search__backdrop--visible {
    display: block;
    opacity: 1;
}

/* ==========================================================================
   Mobile overlay
   ========================================================================== */

.cs-search--mobile-open {
    position: fixed;
    inset: 0;
    max-width: none;
    z-index: 99999;
    background: var(--cs-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.cs-search--mobile-open .cs-search__form {
    width: 100%;
    border-radius: var(--cs-radius-rect);
}

.cs-search--mobile-open .cs-search__input {
    opacity: 1 !important;
    width: 100% !important;
    padding: 0 12px 0 0 !important;
}

.cs-search--mobile-open .cs-search__results {
    position: relative;
    top: 8px;
    max-height: none;
    flex: 1;
    overflow-y: auto;
    border-radius: 8px;
}

/* Close button */
.cs-search__mobile-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: var(--cs-btn-bg);
    border: none;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    color: var(--cs-btn-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity var(--cs-transition);
}

.cs-search__mobile-close:hover {
    opacity: 0.85;
}

/* Hide mobile close button by default */
.cs-search .cs-search__mobile-close {
    display: none;
}
.cs-search--mobile-open .cs-search__mobile-close {
    display: flex;
}

/* Body class to prevent scrolling when mobile overlay is open */
.cs-search-body--overlay {
    overflow: hidden;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    .cs-search {
        max-width: 100%;
    }

    .cs-search__results {
        max-height: 350px;
    }
}

/* ==========================================================================
   RTL support
   ========================================================================== */

[dir="rtl"] .cs-search__icon {
    order: 1;
}

[dir="rtl"] .cs-search__input {
    padding: 0 0 0 12px;
    text-align: right;
}

[dir="rtl"] .cs-search__submit {
    order: -1;
}

[dir="rtl"] .cs-search__item-count {
    margin-left: 0;
    margin-right: auto;
}

/* ==========================================================================
   Product Detail Preview Panel
   ========================================================================== */

.cs-search__preview {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 100%;
    margin-left: 8px;
    width: 300px;
    max-height: 600px;
    overflow-y: auto;
    background: var(--cs-bg);
    border: 1px solid var(--cs-border-color);
    border-radius: 8px;
    box-shadow: var(--cs-shadow);
    z-index: 1000;
    -webkit-overflow-scrolling: touch;
}

.cs-search__preview.cs-preview--visible {
    display: block;
}

/* Flip to left side when overflowing viewport right */
.cs-search__preview--left {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 8px;
}

.cs-preview__inner {
    padding: 16px;
}

/* Image */
.cs-preview__image-link {
    display: block;
    margin-bottom: 12px;
}

.cs-preview__image {
    width: 100%;
    height: auto;
    border-radius: 6px;
    object-fit: contain;
    display: block;
}

/* Title */
.cs-preview__title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: var(--cs-text);
    text-decoration: none;
    margin-bottom: 6px;
    line-height: 1.3;
}

.cs-preview__title:hover {
    color: var(--cs-icon-color);
    text-decoration: underline;
}

/* Price */
.cs-preview__price {
    font-size: 16px;
    font-weight: 700;
    color: var(--cs-text);
    margin-bottom: 8px;
}

.cs-preview__price del {
    color: #aaa;
    font-weight: 400;
    margin-right: 4px;
}

.cs-preview__price ins {
    text-decoration: none;
    color: #c00;
}

/* Description */
.cs-preview__desc {
    font-size: 13px;
    color: var(--cs-text-secondary);
    line-height: 1.5;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Stock badge */
.cs-preview__stock {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    margin-bottom: 12px;
}

.cs-preview__stock--instock {
    background: #e8f5e9;
    color: #2e7d32;
}

.cs-preview__stock--outofstock {
    background: #ffebee;
    color: #c62828;
}

.cs-preview__stock--onbackorder {
    background: #fff3e0;
    color: #e65100;
}

/* Cart section */
.cs-preview__cart {
    border-top: 1px solid #eee;
    padding-top: 12px;
    margin-top: 4px;
}

/* Qty row */
.cs-preview__qty-row {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 10px;
}

.cs-preview__qty-minus,
.cs-preview__qty-plus {
    width: 36px;
    height: 36px;
    border: 1px solid var(--cs-border-color);
    background: var(--cs-bg);
    color: var(--cs-text);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--cs-transition);
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
}

.cs-preview__qty-minus {
    border-radius: 4px 0 0 4px;
}

.cs-preview__qty-plus {
    border-radius: 0 4px 4px 0;
}

.cs-preview__qty-minus:hover,
.cs-preview__qty-plus:hover {
    background: var(--cs-bg-hover);
}

.cs-preview__qty-input {
    width: 48px;
    height: 36px;
    text-align: center;
    border: 1px solid var(--cs-border-color);
    border-left: none;
    border-right: none;
    font-size: 14px;
    color: var(--cs-text);
    background: var(--cs-bg);
    -moz-appearance: textfield;
    margin: 0;
    padding: 0;
}

.cs-preview__qty-input::-webkit-outer-spin-button,
.cs-preview__qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Add to cart button */
.cs-preview__add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 42px;
    padding: 0 16px;
    margin: 0;
    border: none;
    border-radius: 4px;
    background: var(--cs-btn-bg);
    color: var(--cs-btn-text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-align: center;
    transition: opacity var(--cs-transition);
    box-sizing: border-box;
}

.cs-preview__add-btn:hover {
    opacity: 0.85;
}

.cs-preview__add-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* View product link */
.cs-preview__view-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: 2px solid var(--cs-btn-bg);
    border-radius: 4px;
    background: transparent;
    color: var(--cs-btn-bg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background var(--cs-transition), color var(--cs-transition);
    box-sizing: border-box;
}

.cs-preview__view-btn:hover {
    background: var(--cs-btn-bg);
    color: var(--cs-btn-text);
}

/* Scrollbar styling for preview */
.cs-search__preview::-webkit-scrollbar {
    width: 6px;
}
.cs-search__preview::-webkit-scrollbar-track {
    background: transparent;
}
.cs-search__preview::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Hide preview on mobile */
@media (max-width: 991px) {
    .cs-search__preview {
        display: none !important;
    }
}

/* Hide preview when mobile overlay is open */
.cs-search--mobile-open .cs-search__preview {
    display: none !important;
}

/* RTL support for preview panel */
[dir="rtl"] .cs-search__preview {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 8px;
}

[dir="rtl"] .cs-search__preview--left {
    right: auto;
    left: 100%;
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .cs-preview__price del {
    margin-right: 0;
    margin-left: 4px;
}

[dir="rtl"] .cs-preview__qty-minus {
    border-radius: 0 4px 4px 0;
}

[dir="rtl"] .cs-preview__qty-plus {
    border-radius: 4px 0 0 4px;
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
    .cs-search__results,
    .cs-search__backdrop,
    .cs-search__preview {
        display: none !important;
    }
}
