/* =========================================
   ETCO Search - Frontend Styles
   Default variables below are fallbacks only;
   the real values are injected inline from the
   ETCO Search admin settings page (colors, sizes, layout).
   ========================================= */

:root {
    --etcos-icon-color: #1a1a2e;
    --etcos-icon-hover-color: #9f0114;
    --etcos-icon-size: 24px;

    --etcos-modal-bg: #ffffff;
    --etcos-item-bg: #f8f7f5;
    --etcos-text-color: #1a1a2e;
    --etcos-accent: #9f0114;
    --etcos-overlay-bg: rgba(26, 26, 46, 0.92);

    --etcos-columns: 3;
    --etcos-image-size: 90px;
    --etcos-font-size: 15px;
}

/* Everything inside the modal uses border-box so padding/borders never
   push an element past its allotted width - this, plus minmax(0,1fr)
   on the grid tracks below, is what fixes the "boxes overflow / text
   wraps weirdly / horizontal scrollbar" issue. */
.etco-search-modal,
.etco-search-modal *,
.etco-search-modal *::before,
.etco-search-modal *::after {
    box-sizing: border-box;
}

/* ---- Trigger Icon ---- */
.etco-search-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 6px;
    margin: 0;
    cursor: pointer;
    color: var(--etcos-icon-color);
    transition: color 0.25s ease, transform 0.25s ease;
    line-height: 0;
}
.etco-search-trigger:hover,
.etco-search-trigger:focus-visible {
    color: var(--etcos-icon-hover-color);
    transform: scale(1.08);
    outline: none;
}
.etco-search-trigger-icon {
    width: var(--etcos-icon-size);
    height: var(--etcos-icon-size);
    display: block;
}

/* ---- Modal ---- */
.etco-search-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
}
.etco-search-modal.is-open {
    display: block;
}
body.etco-search-lock {
    overflow: hidden;
}

.etco-search-overlay {
    position: absolute;
    inset: 0;
    background: var(--etcos-overlay-bg);
    cursor: zoom-out;
    animation: etcosFadeIn 0.25s ease;
}
@keyframes etcosFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.etco-search-box {
    position: relative;
    z-index: 2;
    max-width: 960px;
    width: 92%;
    margin: 6vh auto 0;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    background: var(--etcos-modal-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
    animation: etcosSlideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
}
@keyframes etcosSlideDown {
    from { opacity: 0; transform: translateY(-24px); }
    to   { opacity: 1; transform: translateY(0); }
}

.etco-search-close {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 3;
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--etcos-text-color);
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 6px 10px;
}
.etco-search-close:hover {
    opacity: 1;
    transform: rotate(90deg);
}

/* ---- Search Head (input row) ---- */
.etco-search-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 56px 18px 22px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}
.etco-search-head-icon {
    width: 22px;
    height: 22px;
    color: var(--etcos-accent);
    flex-shrink: 0;
}
.etco-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    font-size: calc(var(--etcos-font-size) + 3px);
    color: var(--etcos-text-color);
    background: transparent;
    font-family: inherit;
}
.etco-search-input::placeholder {
    color: #9ca3af;
}
.etco-search-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--etcos-accent);
    flex-shrink: 0;
    opacity: 0;
    animation: etcosSpin 0.7s linear infinite;
}
.etco-search-spinner.is-active {
    opacity: 1;
}
@keyframes etcosSpin {
    to { transform: rotate(360deg); }
}

/* ---- Search Body ---- */
.etco-search-body {
    padding: 18px 22px 26px;
    overflow-y: auto;
    overflow-x: hidden;
}
.etco-search-section-title {
    font-size: calc(var(--etcos-font-size) - 2px);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #9ca3af;
    margin: 0 0 14px;
}

/* ---- Results grid/list container ----
   minmax(0,1fr) is the key fix: without it, a grid track will grow to
   fit its content's minimum intrinsic width (e.g. an un-wrapping price
   like "Call for Price"), which pushes the whole grid wider than the
   modal and causes horizontal scrolling + squashed, broken-looking cards. */
.etco-search-results {
    display: grid;
    gap: 14px;
    width: 100%;
}
.etco-search-results.etco-layout-grid {
    grid-template-columns: repeat(var(--etcos-columns), minmax(0, 1fr));
}
.etco-search-results.etco-layout-list {
    grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 700px) {
    .etco-search-results.etco-layout-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 460px) {
    .etco-search-results.etco-layout-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---- Product item ---- */
.etco-search-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    min-width: 0;
    border-radius: 10px;
    text-decoration: none;
    background: var(--etcos-item-bg);
    transition: background 0.2s ease, transform 0.2s ease;
}
.etco-search-item:hover {
    transform: translateY(-2px);
    filter: brightness(0.97);
}

/* List layout: image on the left, text on the right, one item per row. */
.etco-layout-list .etco-search-item {
    flex-direction: row;
    align-items: center;
}
.etco-layout-list .etco-search-item-img {
    width: var(--etcos-image-size);
    height: var(--etcos-image-size);
}

/* Grid layout: image on top, text below - a proper card. */
.etco-layout-grid .etco-search-item {
    flex-direction: column;
    align-items: stretch;
}
.etco-layout-grid .etco-search-item-img {
    width: 100%;
    height: var(--etcos-image-size);
}

.etco-search-item-img {
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #eceae6;
    display: flex;
    align-items: center;
    justify-content: center;
}
.etco-search-item-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.etco-search-item-noimg {
    font-size: 20px;
}

.etco-search-item-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.etco-search-item-title {
    font-size: var(--etcos-font-size);
    font-weight: 600;
    color: var(--etcos-text-color);
    overflow: hidden;
    text-overflow: ellipsis;
}
/* List: single line with ellipsis. Grid: allow up to 2 lines. */
.etco-layout-list .etco-search-item-title {
    white-space: nowrap;
}
.etco-layout-grid .etco-search-item-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    line-height: 1.3;
}

.etco-search-item-desc {
    font-size: calc(var(--etcos-font-size) - 3px);
    color: #6b7280;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.etco-search-item-price {
    font-size: calc(var(--etcos-font-size) - 3px);
    font-weight: 700;
    color: var(--etcos-accent);
    margin-top: auto;
}

.etco-search-no-results,
.etco-search-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 10px;
    color: #9ca3af;
    font-size: var(--etcos-font-size);
}

/* template tag must never render on its own if CSS loads before JS hides it */
#etcos-latest-template {
    display: none;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .etco-search-box {
        margin-top: 0;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        width: 100%;
    }
    .etco-search-head {
        padding: 18px 50px 14px 16px;
    }
    .etco-search-body {
        padding: 14px 16px 20px;
    }
}
