/* ============================================================
   Custom WooCommerce Product Search — search.css  v1.3
   Responsive: iPhone SE → large desktop (Mac/Windows/Android)
   ============================================================ */

/* ── Wrapper ─────────────────────────────────────────────── */
.giva-search-wrap {
    position: relative;
    width: 100%;
    max-width: 700px;
    /* Centre the widget when placed in a wide column */
    margin-left: auto;
    margin-right: auto;
}

/* ── Search icon (left) ──────────────────────────────────── */
.cwps-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    color: #777;
    font-size: 16px;
    pointer-events: none;
    line-height: 1;
}

/* ── Clear icon (right) ──────────────────────────────────── */
.cwps-clear-icon {
    position: absolute;
    right: 14px;
    top: 64%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #777;
    font-size: 14px;
    z-index: 100;
    display: none;          /* shown via JS when input has value */
    line-height: 1;
    /* Larger tap target for mobile (iOS / Android) */
    padding: 8px;
    margin: -8px;
    -webkit-tap-highlight-color: transparent;
}
.cwps-clear-icon:hover {
    color: #000;
}

/* ── Input field ─────────────────────────────────────────── */
#giva-search {
    width: 100%;
    height: 52px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 42px !important;
    padding-right: 42px !important;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
    font-size: 16px;        /* prevents iOS auto-zoom on focus */
    line-height: normal;
    background: #fff;
    color: #222;
    outline: none;
    -webkit-appearance: none; /* removes iOS inner shadow */
    appearance: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#giva-search:focus {
    border-color: #999;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

/* ── Dropdown results ────────────────────────────────────── */
/* Position is set via JS (getBoundingClientRect → position:fixed)
   so the dropdown escapes any parent overflow:hidden containers. */
#giva-results {
    display: none;
    position: fixed;
    background: #fff;
    z-index: 999999;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    max-height: 70vh;
    overflow-y: auto;
    /* Smooth scroll on iOS */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ── Individual product row ──────────────────────────────── */
.cwps-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    text-decoration: none;
    color: #222;
    border-bottom: 1px solid #eee;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease;
}
.cwps-item:last-of-type {
    border-bottom: none;
}
.cwps-item:hover,
.cwps-item:focus-visible {
    background: #f7f7f7;
}
.cwps-item:active {
    background: #f0f0f0;
}

/* ── Thumbnail ───────────────────────────────────────────── */
.cwps-img {
    flex-shrink: 0;
}
.cwps-img img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    display: block;
    border-radius: 4px;
}

/* ── Text info ───────────────────────────────────────────── */
.cwps-info {
    flex: 1;
    min-width: 0;   /* prevents text overflow breaking flex */
}
.cwps-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cwps-sku {
    font-size: 12px;
    color: #777;
    margin-bottom: 4px;
}
.cwps-price {
    font-size: 14px;
    font-weight: 600;
}

/* ── Empty state ─────────────────────────────────────────── */
.cwps-empty {
    padding: 20px 15px;
    text-align: center;
    color: #777;
    font-size: 14px;
}

/* ── "View All Results" footer ───────────────────────────── */
.cwps-viewall {
    text-align: center;
    padding: 14px 15px;
    border-top: 1px solid #eee;
    background: #fafafa;
    border-radius: 0 0 8px 8px;
}
.cwps-viewall a {
    display: block;
    text-decoration: none;
    font-weight: 600;
    color: #000;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}
.cwps-viewall a:hover {
    text-decoration: underline;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ── Large desktop / Mac (1200 px +) ────────────────────── */
@media (min-width: 1200px) {
    .giva-search-wrap {
        max-width: 700px;
    }
    #giva-search {
        height: 54px;
        font-size: 16px;
    }
}

/* ── Standard desktop / laptop (1024 px – 1199 px) ──────── */
@media (min-width: 1024px) and (max-width: 1199px) {
    .giva-search-wrap {
        max-width: 640px;
    }
}

/* ── Tablet landscape (768 px – 1023 px) ────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    .giva-search-wrap {
        max-width: 100%;
    }
    #giva-search {
        height: 50px;
    }
    .cwps-img img {
        width: 56px;
        height: 56px;
    }
}

/* ── Tablet portrait / large phone (600 px – 767 px) ────── */
@media (min-width: 600px) and (max-width: 767px) {
    .giva-search-wrap {
        max-width: 100%;
    }
    #giva-search {
        height: 48px;
    }
    .cwps-img img {
        width: 52px;
        height: 52px;
    }
    .cwps-title {
        font-size: 13px;
    }
}

/* ── Mobile (up to 599 px) — Android / iPhone ───────────── */
@media (max-width: 599px) {
    .giva-search-wrap {
        max-width: 100%;
    }

    #giva-search {
        height: 46px;
        font-size: 16px; /* keep at 16 px — prevents iOS zoom */
        border-radius: 6px;
        margin-left: 7px;
    }

    /* Slightly tighter icon positions on small screens */
    .cwps-search-icon {
        left: 12px;
        font-size: 15px;
        margin-left: 9px;
    }
    .cwps-clear-icon {
        right: 12px;
    }

    #giva-results {
        border-radius: 6px;
        max-height: 65vh;
    }

    .cwps-item {
        gap: 10px;
        padding: 10px;
    }
    .cwps-img img {
        width: 48px;
        height: 48px;
    }
    .cwps-title {
        font-size: 13px;
    }
    .cwps-sku {
        font-size: 11px;
    }
    .cwps-price {
        font-size: 13px;
    }
    .cwps-viewall {
        padding: 12px;
    }
    .cwps-viewall a {
        font-size: 13px;
    }
}

/* ── iPhone SE / very small phones (up to 375 px) ───────── */
@media (max-width: 375px) {
    #giva-search {
        height: 44px;
        padding-left: 38px !important;
        padding-right: 38px !important;
    }
    .cwps-search-icon {
        left: 11px;
        font-size: 14px;
    }
    .cwps-clear-icon {
        right: 11px;
    }
    .cwps-img img {
        width: 44px;
        height: 44px;
    }
    .cwps-item {
        gap: 8px;
        padding: 9px 10px;
    }
}

/* ── Reduced-motion preference ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #giva-search,
    .cwps-item {
        transition: none;
    }
}

/* ── Dark-mode support (optional — remove if not needed) ─── */
@media (prefers-color-scheme: dark) {
    #giva-search {
        background: #1e1e1e;
        color: #f0f0f0;
        border-color: #444;
    }
    #giva-results {
        background: #1e1e1e;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    }
    .cwps-item {
        color: #f0f0f0;
        border-bottom-color: #333;
    }
    .cwps-item:hover,
    .cwps-item:focus-visible {
        background: #2a2a2a;
    }
    .cwps-title {
        color: #f0f0f0;
    }
    .cwps-sku {
        color: #aaa;
    }
    .cwps-empty {
        color: #aaa;
    }
    .cwps-viewall {
        background: #161616;
        border-top-color: #333;
    }
    .cwps-viewall a {
        color: #f0f0f0;
    }
    #giva-search:focus {
        border-color: #777;
        box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.07);
    }
}