/** Shopify CDN: Minification failed

Line 10:0 Comments in CSS use "/* ... */" instead of "//"
Line 11:0 Comments in CSS use "/* ... */" instead of "//"
Line 69:6 Comments in CSS use "/* ... */" instead of "//"
Line 79:10 Comments in CSS use "/* ... */" instead of "//"
Line 82:65 Expected "}" to go with "{"

**/
// trust-upsells.js
// Cart-integrated upsell toggles for Dawn theme

(function () {
  'use strict';

  const CART_ADD_URL    = '/cart/add.js';
  const CART_UPDATE_URL = '/cart/update.js';
  const CART_GET_URL    = '/cart.js';

  async function getCart() {
    const res = await fetch(CART_GET_URL, {
      headers: { 'Content-Type': 'application/json' }
    });
    if (!res.ok) throw new Error(`Cart fetch failed: ${res.status}`);
    return res.json();
  }

  async function isVariantInCart(variantId) {
    const cart = await getCart();
    return cart.items.some(item => String(item.variant_id) === String(variantId));
  }

  async function addVariantToCart(variantId) {
    const res = await fetch(CART_ADD_URL, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ id: String(variantId), quantity: 1 })
    });
    if (!res.ok) throw new Error(`Cart add failed: ${res.status}`);
    return res.json();
  }

  async function removeVariantFromCart(variantId) {
    const cart = await getCart();
    const updates = {};

    cart.items.forEach(item => {
      if (String(item.variant_id) === String(variantId)) {
        updates[item.key] = 0;
      }
    });

    if (Object.keys(updates).length === 0) return null;

    const res = await fetch(CART_UPDATE_URL, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ updates })
    });
    if (!res.ok) throw new Error(`Cart update failed: ${res.status}`);
    return res.json();
  }

  async function refreshCartCount() {
    try {
      const cart = await getCart();
      const count = cart.item_count;

      // Dawn-specific cart count selectors
      const selectors = [
        '#cart-icon-bubble .visually-hidden',
        '[data-cart-count]',
        '.cart-count-bubble span:first-child',
        'cart-notification-button .cart-count-bubble span'
      ];

      selectors.forEach(sel => {
        document.querySelectorAll(sel).forEach(el => {
          // Dawn uses visually-hidden spans with item count
          if (el.classList.contains('visually-hidden') && el.textContent.match(/\d/)) {
            el.textContent = count;
          } else if (!el.classList.contains('visually-hidden')) {