 /* Basic resets + font */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      font-family: 'Poppins', sans-serif;
      background: #f9f9f9;
      color: #333;
    }
    a {
      color: inherit;
      text-decoration: none;
    }

    /* Container for the results page */
    .search-container {
      width: 100%;
      max-width: 1200px;
      margin: 0 auto;
      padding: 20px;
      background: #fff;  /* white bg + round corners as requested */
      border-radius: 8px;
    }

    /* Title area */
    .search-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      margin-bottom: 20px;
    }
    .search-header h1 {
      font-size: 1.5rem;
      font-weight: 600;
      margin-right: 10px;
    }

    /* sort form styling */
    .sort-form {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-left: auto; /* we keep the inline style, but also add a class for further styling if needed */
    }
    .sort-label {
      font-size: 0.9rem;
      font-weight: 500;
      color: #333;
    }
    .sort-select {
      border: 1px solid #ccc;
      border-radius: 4px;
      background: #fff;
      font-size: 0.9rem;
      padding: 4px 10px;
      cursor: pointer;
    }
    .sort-select:focus {
      outline: none;
      border-color: #66afe9;
      box-shadow: 0 0 0 3px rgba(102,175,233,0.2);
    }

    .results-info {
      font-size: 0.95rem;
      color: #555;
      margin-bottom: 20px;
    }

    /* Card grid: bigger min width on desktop; 2-per-row on mobile */
    .card-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 20px;
    }
    @media (max-width: 576px) {
      .card-grid {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    /* Product card */
    .product-card {
      background: #fff;
      border: 1px solid #eee;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 2px 4px rgba(0,0,0,0.08);
      position: relative;
      transition: box-shadow 0.3s ease;
    }
    .product-card:hover {
      box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }
    .product-card img {
      width: 100%;
      height: 180px;
      object-fit: cover;
      display: block;
    }
    @media (min-width: 992px) {
      .product-card img {
        height: 240px;
      }
    }

    .product-card-body {
      padding: 10px;
    }
    .product-title {
      font-size: 0.95rem;
      font-weight: 500;
      color: #222;
      margin-bottom: 8px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: block;
    }

    .price-row {
      font-size: 1rem;
      font-weight: 600;
      color: #222;
      margin-bottom: 4px;
    }
    .price-row s {
      color: #888;
      font-weight: normal;
      margin-left: 6px;
    }

    .discount-row {
      font-size: 0.85rem;
      color: #388e3c;
      margin-bottom: 8px;
    }

    .discount-badge {
      position: absolute;
      top: 10px;
      left: 10px;
      background: #ff8a00;
      color: #fff;
      font-weight: 600;
      font-size: 0.75rem;
      padding: 3px 6px;
      border-radius: 4px;
    }

    /* Size row with a dropdown to trigger popup */
    .size-row {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .size-label {
      font-size: 0.9rem;
      color: #555;
    }
    .size-button {
      padding: 4px 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      background: #fff;
      font-size: 0.9rem;
      cursor: pointer;
      position: relative;
      display: inline-flex;
      align-items: center;
    }
    .size-button:hover {
      background: #f5f5f5;
    }
    .size-button i {
      margin-left: 4px;
      font-size: 0.8rem;
    }

    /* The size overlay/popup */
    .size-overlay {
      display: none;
      position: fixed;
      top: 0; left: 0;
      width: 100%; height: 100%;
      background: rgba(0,0,0,0.4);
      z-index: 9999;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }
    .size-overlay.show {
      display: flex;
    }
    .size-popup {
      background: #fff;
      border-radius: 8px;
      padding: 20px;
      width: 380px;  /* slightly bigger width for the popup */
      max-height: 80vh;
      overflow-y: auto;
      position: relative;
    }

    .size-popup .popup-header {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      margin-bottom: 12px;
    }
    .size-popup .popup-header img {
      width: 60px; height: 60px;
      object-fit: cover;
      border-radius: 4px;
    }
    .popup-product-title {
      font-size: 1rem;
      font-weight: 600;
      margin-bottom: 4px;
    }
    .close-btn {
      position: absolute;
      top: 10px; right: 10px;
      background: none;
      border: none;
      font-size: 1.2rem;
      cursor: pointer;
      color: #333;
    }

    /* We'll place "Go to Cart" button here in the header. Initially hidden. */
    .go-cart-btn-header {
      display: none; /* shown once any item is added */
      margin-top: 6px;
      background: #008000;
      color: #fff;
      border: none;
      padding: 5px 10px;
      border-radius: 4px;
      font-size: 0.75rem;
      cursor: pointer;
    }
    .go-cart-btn-header:hover {
      background: #006400;
    }

    .size-popup h4 {
      font-size: 0.95rem;
      margin-bottom: 10px;
      font-weight: 600;
    }
    .size-popup ul {
      list-style: none;
      padding: 0;
      margin: 0;
    }
    .size-popup li {
      padding: 8px;
      border-bottom: 1px solid #eee;
      display: flex;
      flex-direction: column; 
      gap: 4px; 
    }
    .size-popup li .variant-top-line {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .variant-name {
      color: #333;
      font-weight: 500;
    }
    .variant-right {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: nowrap; /* keep them on one line on mobile */
    }
    .size-price-row {
      display: flex;
      align-items: center; 
      gap: 8px;
      flex-wrap: nowrap; /* single row for discount + add to cart */
    }
    .variant-price {
      font-weight: 600;
      font-size: 0.9rem;
    }
    .variant-price s {
      color: #888;
      margin-left: 6px;
      font-weight: normal;
      font-size: 0.85rem;
    }
    .variant-discount {
      background: #ff8a00;
      color: #fff;
      font-size: 0.7rem;
      font-weight: 600;
      padding: 2px 5px;
      border-radius: 4px;
    }
    .add-to-cart-btn {
      background: #008000;
      color: #fff;
      border: none;
      padding: 6px 14px;
      border-radius: 4px;
      font-size: 0.8rem;
      cursor: pointer;
    }
    .add-to-cart-btn:hover {
      background: #006400;
    }
    .sold-out-btn {
      background: #ccc;
      color: #666;
      cursor: not-allowed;
    }

    /* quantity container if user clicks "Add to Cart" */
    .qty-container {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .qty-btn {
      background: #eee;
      border: none;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 0.85rem;
    }
    .qty-btn:hover {
      background: #ddd;
    }
    .qty-label {
      font-weight: 600;
      min-width: 20px;
      text-align: center;
    }
    .trash-btn {
      background: #eee;
      border: none;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 0.85rem;
    }
    .trash-btn:hover {
      background: #ddd;
    }

    /* --- ONLY FOR MOBILE VIEW: keep Save % and Add to Cart on one line --- */
    @media (max-width: 576px) {
      .size-price-row {
        flex-wrap: nowrap !important;
      }
      .variant-discount,
      .cart-btn-slot {
        white-space: nowrap;
      }
    }
    
    
        /* =======================================================
       POPUP polish etc. (unchanged)
       ======================================================= */
    :root{
      --ks-green:#1b8f1a;
      --ks-green-dark:#157213;
      --ks-border:#ececec;
      --ks-filter-footer-h:72px; /* used for drawer body bottom padding */
    }
    .size-overlay{
      position:fixed; inset:0;
      background:rgba(0,0,0,.42);
      backdrop-filter:saturate(120%) blur(2px);
      display:none; align-items:center; justify-content:center;
      padding:16px; z-index:1000;
    }
    .size-overlay.show{ display:flex; }

    .size-popup{
      position:relative;
      width:min(700px,94vw);
      max-height:86vh;
      background:#fff; border-radius:16px;
      box-shadow:0 10px 30px rgba(0,0,0,.2);
      overflow:hidden; display:flex; flex-direction:column;
      animation:popIn .18s ease-out;
    }
    @keyframes popIn{ from{transform:scale(.96);opacity:0;} to{transform:scale(1);opacity:1;} }

    .close-btn{
      position:absolute; right:10px; top:10px;
      width:36px; height:36px; border:1px solid #eee; border-radius:999px;
      background:#fff; color:#333; cursor:pointer;
      display:flex; align-items:center; justify-content:center;
      z-index:5;
      box-shadow:0 2px 8px rgba(0,0,0,.08);
    }
    .close-btn:hover{ background:#f7f7f7; }

    .popup-header{
      position:sticky; top:0; z-index:2;
      display:grid; grid-template-columns:64px 1fr max-content;
      gap:12px; align-items:center;
      padding:16px 18px;
      padding-right:64px;
      border-bottom:1px solid var(--ks-border); background:#fff;
    }
    .popup-header img#popupImage{
      width:64px; height:64px; object-fit:cover; border-radius:10px; border:1px solid var(--ks-border);
    }
    .popup-product-title{ font-weight:600; font-size:1.02rem; line-height:1.3; }

    .go-cart-btn-header{
      height:36px; padding:0 14px; border:none; border-radius:10px; cursor:pointer;
      background:var(--ks-green); color:#fff; font-weight:600;
      white-space:nowrap;
    }
    .go-cart-btn-header:hover{ background:var(--ks-green-dark); }

    .size-popup h4{ margin:0; padding:12px 18px; font-size:.95rem; color:#111; border-bottom:1px solid var(--ks-border); }

    #variantList{ list-style:none; margin:0; padding:0; overflow:auto; flex:1; background:#fff; }
    #variantList li{
      display:grid; grid-template-columns:1fr auto;
      gap:10px; align-items:center;
      padding:14px 18px; border-bottom:1px solid #f3f4f6;
    }
    .variant-top-line{ display:flex; align-items:center; gap:8px; min-width:0; }
    .variant-name{ font-weight:600; color:#111; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
    .size-price-row{ display:flex; align-items:center; gap:12px; }
    .variant-price{ font-weight:700; font-size:1rem; color:#111; }
    .variant-price s{ margin-left:6px; color:#9aa3af; font-weight:500; font-size:.95rem; }
    .variant-discount{ font-size:.78rem; font-weight:700; padding:4px 8px; border-radius:999px; background:#fff7e6; color:#a35500; border:1px solid #ffe0b2; }
    .cart-btn-slot{ display:flex; align-items:center; }
    .add-to-cart-btn{ height:36px; padding:0 14px; border:none; border-radius:10px; cursor:pointer; background:var(--ks-green); color:#fff; font-weight:700; box-shadow:0 2px 0 rgba(0,0,0,.06); }
    .add-to-cart-btn:hover{ background:var(--ks-green-dark); }
    .add-to-cart-btn.sold-out-btn{ background:#e5e7eb; color:#6b7280; cursor:not-allowed; box-shadow:none; }
    .qty-container{ display:flex; align-items:center; gap:8px; background:#f6f8fa; border:1px solid #e5e7eb; border-radius:10px; height:36px; padding:0 8px; }
    .qty-btn, .trash-btn{ width:28px; height:28px; border:none; border-radius:8px; cursor:pointer; display:flex; align-items:center; justify-content:center; background:#fff; }
    .qty-btn:hover, .trash-btn:hover{ background:#f0f0f0; }
    .qty-label{ min-width:18px; text-align:center; font-weight:700; }

    /* ===================== HEADER + STICKY CONTROLS ===================== */

    /* Use grid: title block, then controls row spans full width below it */
    .search-header{
      display:grid;
      grid-template-columns: 1fr;
      align-items:center;
      gap:12px; /* default spacing between H1 and controls */
    }
    .search-header h1{ margin:0; }
    /* Make the controls row span full width of header grid */
    .ks-controls-row{ grid-column:1 / -1; }

    /* Controls row layout (Filter left, Sort right) */
.ks-controls-row{
  display:grid;
  align-items:center;
  gap:12px;
  background:#fff;
  /* no grid-template-columns here on purpose */
}

/* DESKTOP (>=769px): make left column only as wide as its content.
   This stops the Filter button from stretching full width. */
@media (min-width:769px){
  .ks-controls-row{
    grid-template-columns: max-content auto; /* left = content, right = flex */
  }
  .ks-controls-row > .ks-filter-toggle-btn{
    justify-self: start;  /* do not stretch the button */
    width: auto;          /* natural width */
  }
}

/* MOBILE (<=768px): keep two columns so Filter + Sort sit side-by-side.
   Sticky styles defined elsewhere will continue to work. */
@media (max-width:768px){
  .ks-controls-row{
    grid-template-columns: auto auto;
  }
}

    /* Sticky behavior + inner padding for edge breathing room */
    @media (max-width:768px){
      /* Reduce H1 → controls gap on mobile (user request) */
      .search-header{ gap:6px; }

      .ks-controls-row{
        position:-webkit-sticky; /* iOS */
        position:sticky;
        top:calc(var(--ks-sticky-top,56px) + env(safe-area-inset-top));

        /* LAYERING FIX:
           Lower z-index so this bar stays BEHIND popups/sheets (size overlay is z-index:1000).
           Previously 3600 caused it to float above everything. */
        z-index:600;

        padding:6px 12px;            /* space from left/right borders */
        box-shadow:0 2px 10px rgba(0,0,0,.08);
        box-sizing:border-box;       /* keep width including padding */
      }
      /* Fixed fallback when sticky is blocked by an ancestor */
      .ks-controls-row.is-fixed{
        position:fixed !important;
        left:var(--ks-fixed-left,0);
        width:var(--ks-fixed-width,100vw);
        right:auto;
        top:calc(var(--ks-sticky-top,56px) + env(safe-area-inset-top));

        /* LAYERING FIX (keep same lower layer here too) */
        z-index:600;

        padding:6px 12px;
        box-sizing:border-box;
      }
      /* Placeholder used only when fixed to prevent layout jump */
      .ks-sticky-ph{ display:block; height:0; }
    }

    /* Sort kept aligned to right side */
    .sort-form{ justify-self:end; margin-left:0 !important; display:flex; align-items:center; gap:8px; }
    .sort-form .sort-select{ height:36px; padding:8px 10px; border-radius:8px; border:1px solid #ddd; }

    .ks-filter-toggle-btn{
      height:36px; display:inline-flex; align-items:center; gap:8px;
      padding:8px 12px; border:1px solid #ddd; border-radius:8px; background:#fff;
      cursor:pointer; font-weight:600;
    }
    .ks-filter-toggle-btn i{ font-size:14px; }

    /* Drawer */
    .ks-filter-panel-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.35);display:none;z-index:3500}
    .ks-filter-panel-backdrop.show{display:block}
    .ks-filter-panel{
      position:fixed;top:0;left:-380px;height:100vh;height:100dvh;width:360px;background:#fff;
      box-shadow:8px 0 24px rgba(0,0,0,.15);transition:left .25s ease;z-index:4000;display:flex;flex-direction:column
    }
    .ks-filter-panel.show{left:0}
    .ks-filter-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid #eee;flex-shrink:0}
    .ks-filter-title{font-weight:700;font-size:16px}
    .ks-filter-close{background:none;border:none;font-size:18px;cursor:pointer}

    .ks-filter-body{
      padding:14px 16px;overflow:auto;flex:1;
      padding-bottom: calc(var(--ks-filter-footer-h) + 20px + env(safe-area-inset-bottom));
    }
    .ks-filter-group{margin-bottom:18px}
    .ks-filter-group h4{font-size:14px;margin:0 0 10px 0;font-weight:700;color:#222}
    .ks-checklist{display:flex;flex-direction:column;gap:8px;max-height:220px;overflow:auto}
    .ks-price-row{display:flex;gap:10px}
    .ks-price-row input{width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px}

    .ks-filter-footer{
      position:sticky;bottom:0;left:0;right:0;
      border-top:1px solid #eee;padding:12px 16px calc(12px + env(safe-area-inset-bottom));
      background:#fff;display:flex;gap:10px;flex-shrink:0;
      box-shadow:0 -8px 16px rgba(0,0,0,.08);
      min-height:var(--ks-filter-footer-h);
      z-index:1;
    }
    .ks-btn{display:inline-flex;align-items:center;justify-content:center;padding:10px 14px;border-radius:8px;cursor:pointer;text-decoration:none;border:1px solid transparent;font-weight:600;width:50%}
    .ks-btn-primary{background:#16a34a;color:#fff}.ks-btn-primary:hover{background:#128a3e}
    .ks-btn-ghost{background:#fff;color:#333;border-color:#ddd}.ks-btn-ghost:hover{background:#f8f8f8}

    /* Mobile drawer width */
    @media (max-width:768px){
      .ks-filter-panel{ width:92vw; left:-92vw; }
    }

    @media (max-width:480px){
      .size-popup{ width:96vw; }
      .popup-header{
        grid-template-columns:56px 1fr max-content;
        gap:10px; padding:12px 14px; padding-right:58px;
      }
      .go-cart-btn-header{ font-size:.85rem; height:34px; padding:0 12px; white-space:nowrap; }
      #variantList li{ grid-template-columns:1fr; align-items:flex-start; }
      .size-price-row{ justify-content:space-between; width:100%; }
      .close-btn{ right:8px; top:8px; width:34px; height:34px; }
    }