/*
 Theme Name:   Boozniak Child
 Theme URI:    https://boozniak.pl
 Description:  Child theme dla Blocksy — platforma edukacyjna Boozniak Digital Education
 Author:       Boozniak
 Author URI:   https://boozniak.pl
 Template:     blocksy
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain:  boozniak-child
*/

/* ═══════════════════════════════════════════════
   BOOZNIAK — GLOBAL CSS VARIABLES
   ═══════════════════════════════════════════════ */

:root {
  /* Brand Colors */
  --boo-orange: #fdb21a;
  --boo-orange-hover: #e8a010;
  --boo-graphite: #3d4e5c;
  --boo-graphite-light: #506575;
  --boo-burgundy: #a0354a;
  --boo-purple: #673AB7;
  --boo-teal: #009688;

  /* Light Theme */
  --boo-bg: #f6f7f9;
  --boo-bg-white: #ffffff;
  --boo-text: #2a3640;
  --boo-text-dim: #6b7d8d;
  --boo-text-light: #95a3af;

  /* Cards & Borders */
  --boo-card-shadow: 0 2px 16px rgba(61, 78, 92, 0.06);
  --boo-card-shadow-hover: 0 12px 40px rgba(61, 78, 92, 0.1);
  --boo-border: rgba(61, 78, 92, 0.08);

  /* Product Type Colors (thumbnails) */
  --boo-quiz-color: #a0354a;
  --boo-flashcard-color: #009688;
  --boo-pwa-color: #3d4e5c;
  --boo-pdf-color: #673AB7;
  --boo-infographic-color: #fdb21a;
}


/* ═══════════════════════════════════════════════
   WOOCOMMERCE — PRODUCT CARDS
   ═══════════════════════════════════════════════ */

/* Badge DARMOWE / PREMIUM na karcie produktu */
.wc-block-grid__product .onsale,
.products .product .onsale,
span.onsale {
  background-color: var(--boo-teal) !important;
  color: #ffffff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: 0.5px;
  border-radius: 20px !important;
  padding: 4px 14px !important;
  text-transform: uppercase;
}

/* Przycisk "Dodaj do koszyka" / "Pobierz" */
.products .product .button,
.woocommerce .product .single_add_to_cart_button {
  background-color: var(--boo-orange) !important;
  color: var(--boo-text) !important;
  border: none !important;
  border-radius: 10px !important;
  font-weight: 600 !important;
  transition: all 0.3s ease !important;
}

.products .product .button:hover,
.woocommerce .product .single_add_to_cart_button:hover {
  background-color: var(--boo-orange-hover) !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(253, 178, 26, 0.3);
}

/* Cena — styl */
.woocommerce .product .price,
.woocommerce .products .price {
  color: var(--boo-graphite) !important;
  font-weight: 700;
}

/* Darmowe produkty — cena 0 zł */
.woocommerce .product .price ins,
.woocommerce .product .price .woocommerce-Price-amount {
  font-weight: 700;
}


/* ═══════════════════════════════════════════════
   WOOCOMMERCE — CHECKOUT
   ═══════════════════════════════════════════════ */

/* Przycisk "Kupuję i płacę" */
.woocommerce #place_order,
.wc-block-components-checkout-place-order-button,
.wc-block-checkout__actions_row .wc-block-components-button {
  background-color: var(--boo-orange) !important;
  color: var(--boo-text) !important;
  border: none !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
  font-size: 16px !important;
  padding: 14px 32px !important;
  transition: all 0.3s ease !important;
}

.woocommerce #place_order:hover,
.wc-block-components-checkout-place-order-button:hover {
  background-color: var(--boo-orange-hover) !important;
  box-shadow: 0 8px 24px rgba(253, 178, 26, 0.3);
}

/* Przycisk "Przejdź do płatności" (koszyk) */
.wc-block-cart__submit-button,
.woocommerce .cart .button,
.checkout-button {
  background-color: var(--boo-orange) !important;
  color: var(--boo-text) !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
}


/* ═══════════════════════════════════════════════
   GENERAL UI ELEMENTS
   ═══════════════════════════════════════════════ */

/* Linki */
a {
  color: var(--boo-graphite);
  transition: color 0.3s ease;
}

a:hover {
  color: var(--boo-orange);
}

/* Przyciski ogólne */
.wp-element-button,
.wp-block-button__link {
  border-radius: 10px !important;
}

/* Inputy / formularze */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
textarea,
select {
  border-radius: 8px !important;
  border-color: var(--boo-border) !important;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-color: var(--boo-orange) !important;
  box-shadow: 0 0 0 2px rgba(253, 178, 26, 0.15) !important;
}


/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */

@media (max-width: 768px) {
  .woocommerce #place_order,
  .wc-block-components-checkout-place-order-button {
    width: 100% !important;
    font-size: 15px !important;
    padding: 16px !important;
  }
}

// Ukryj adres na blokowym checkout dla darmowych zamówień
add_action('wp_footer', function() {
    if (is_checkout()) {
        ?>
        <script>
        (function(){
            function checkAndHide() {
                var totalEl = document.querySelector('.wc-block-components-totals-footer-item .wc-block-components-totals-item__value');
                if (totalEl && (totalEl.textContent.indexOf('0,00') !== -1 || totalEl.textContent.indexOf('0.00') !== -1)) {
                    var billing = document.querySelector('.wc-block-checkout__billing-fields .wc-block-components-address-form');
                    if (billing) billing.style.display = 'none';
                    var billingTitle = document.querySelector('.wp-block-woocommerce-checkout-billing-address-block .wc-block-components-checkout-step__heading');
                    if (billingTitle) billingTitle.style.display = 'none';
                    var shipping = document.querySelector('.wc-block-checkout__shipping-fields');
                    if (shipping) shipping.style.display = 'none';
                    var notes = document.querySelector('.wc-block-checkout__add-note');
                    if (notes) notes.style.display = 'none';
                }
            }
            setInterval(checkAndHide, 1000);
            checkAndHide();
        })();
        </script>
        <?php
    }
});

// Wyłącz wymagane pola adresowe dla darmowych zamówień
add_action('woocommerce_store_api_checkout_update_order_from_request', function($order) {
    if ($order->get_total() == 0) {
        $order->set_billing_first_name($order->get_billing_first_name() ?: '-');
        $order->set_billing_last_name($order->get_billing_last_name() ?: '-');
        $order->set_billing_address_1($order->get_billing_address_1() ?: '-');
        $order->set_billing_city($order->get_billing_city() ?: '-');
        $order->set_billing_postcode($order->get_billing_postcode() ?: '-');
        $order->set_billing_country($order->get_billing_country() ?: 'PL');
    }
}, 10, 1);

// Wyłącz walidację Store API dla darmowych zamówień
add_filter('woocommerce_store_api_checkout_order_processed', function($order) {
    if ($order->get_total() == 0) {
        return $order;
    }
}, 10, 1);
