/*
Theme Name: Komestic Child 10
Theme URI: https://komestic.casethemes.net/
Description: Child theme for Komestic — keeps every WooCommerce template override current (tested with WooCommerce 11.2.1 on PHP 8.5), fixes Stripe payment gateway integration (including the Optimized Checkout "Invalid payment method" error), cart/product page and mobile menu issues, and storefront product search, and shows checkout errors on the invalid fields themselves.
Template: komestic
Version: 10.0.0
Tested up to: 7.1
WC tested up to: 11.2
Requires PHP: 7.4
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: komestic-child
*/

/* ==========================================================================
   Child theme styles go below this line.
   The parent theme's styles are enqueued via functions.php.
   ========================================================================== */

/* ==========================================================================
   CHECKOUT: PAYMENT ERROR / NOTICE DISPLAY
   --------------------------------------------------------------------------
   The parent theme deliberately hides two notice containers:
     • main.scss:     .woocommerce-notices-wrapper { display:none }
     • checkout.scss: form.checkout .woocommerce-NoticeGroup { display:none }

   This means payment errors from Stripe (and any other gateway) are silently
   swallowed — the customer sees no feedback after a declined card etc.

   Fix:
   1. Un-hide both containers on checkout pages only.
   2. Style error / info / success notices to match the site design.
   3. Show AJAX notices above both columns: WooCommerce prepends them inside
      the flex form.checkout at runtime, and assets/js/checkout-notices.js
      moves them to just above the form (Komestic Child 9).
   ========================================================================== */

/* 1 – Un-hide the static notices wrapper (renders before the form) */
.woocommerce-checkout .woocommerce-notices-wrapper {
  display: block;
}

/* ==========================================================================
   MOBILE SIDEBAR: LOGO WIDTH
   --------------------------------------------------------------------------
   The parent theme sets .site-logo img { width: auto; height: 36px } globally.
   In the mobile sidebar the content area is ~260px (320px sidebar minus 30px
   padding each side), so a logo image narrower than 36px tall renders tiny.

   Fix: make the sidebar logo image span the full available width with
   automatic height to preserve aspect ratio.
   ========================================================================== */

.mobile-sidebar .sidebar-inner .site-logo img {
  width: 100%;
  height: auto;
}

/* 2 – Un-hide the AJAX notice group WooCommerce prepends to form.checkout.
   The body.… form.checkout selector out-ranks the parent's display:none (also if a
   cache plugin reorders the stylesheets): WooCommerce scrolls to and focuses the
   notice while it is still inside the form.
   form.checkout is a no-wrap flex row on desktop, so a notice inside it squeezes
   the two columns off to the right. assets/js/checkout-notices.js then moves it
   to just above the form; the second selector keeps it shown there. */
body.woocommerce-checkout form.checkout .woocommerce-NoticeGroup,
.woocommerce-checkout .woocommerce-NoticeGroup {
  display: block;
  flex: 0 0 100%;
  width: 100%;
  order: -1;
}

/* ==========================================================================
   CHECKOUT: PAYMENT METHOD RADIO (Komestic Child 9)
   --------------------------------------------------------------------------
   woocommerce/checkout/payment-method.php moves the real payment_method radio
   out of the label (Stripe's Optimized Checkout rewrites the label text and
   used to delete it). Keep it hidden like the parent's in-label radio, and
   drive the parent's .radio dot from it instead of :has(input:checked).
   ========================================================================== */
.woocommerce-checkout .wc_payment_method > input.input-radio {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.woocommerce-checkout
  .wc_payment_method
  > input.input-radio:checked
  + .form-radio-control
  .radio {
  border-color: #fd5900;
}

.woocommerce-checkout
  .wc_payment_method
  > input.input-radio:checked
  + .form-radio-control
  .radio::before {
  background-color: #fd5900;
}

.woocommerce-checkout
  .wc_payment_method
  > input.input-radio:focus-visible
  + .form-radio-control {
  outline: 2px solid #fd5900;
  outline-offset: 2px;
}

/* With Optimized Checkout and more than one gateway, Stripe replaces the whole
   label content with "Payment options", .radio dot included. Draw the dot on
   the label itself then. */
.woocommerce-checkout
  .wc_payment_method
  > input.input-radio
  + .form-radio-control:not(:has(.radio))::before {
  content: "";
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: thin solid #9a9a9a;
  transition: background-color 0.3s linear;
}

.woocommerce-checkout
  .wc_payment_method
  > input.input-radio:checked
  + .form-radio-control:not(:has(.radio))::before {
  border-color: #fd5900;
  background-color: #fd5900;
  box-shadow: inset 0 0 0 1px #fff;
}

/* ==========================================================================
   CHECKOUT: SHIPPING ADDRESS SECTION (Komestic Child 9)
   --------------------------------------------------------------------------
   On live, the slide-down WooCommerce runs on page load for a ticked
   "Ship to a different address?" box ends with an inline display:none, so the
   shipping fields stayed hidden while still required. Show the section
   whenever the box is ticked (instantly, without the slide); unticking still
   hides it. Browsers without :has keep WooCommerce's JS-only behaviour.
   ========================================================================== */
.woocommerce-checkout
  #ship-to-different-address:has(#ship-to-different-address-checkbox:checked)
  .shipping_address {
  display: block !important;
  height: auto !important;
  overflow: visible !important;
}

/* ==========================================================================
   CHECKOUT: INLINE FIELD ERRORS (Komestic Child 10)
   --------------------------------------------------------------------------
   Only active with the komestic-inline-checkout-errors body class, i.e. when
   KOMESTIC_CHILD_CHECKOUT_INLINE_ERRORS is true (functions.php §11).
   WooCommerce marks invalid rows with .woocommerce-invalid and adds
   .checkout-inline-error-message under them (assets/js/checkout-inline-errors.js
   fills in the messages Stripe's browser-side check never produces). The
   script adds .komestic-inline-errors-armed to the form after the first
   failed Place Order, so fields only turn red from then on. The
   #customer_details selectors out-rank the parent's field styles; the parent
   draws the selectWoo border on .select2-selection__rendered.
   ========================================================================== */
body.komestic-inline-checkout-errors form.checkout.komestic-inline-errors-armed #customer_details .form-row.woocommerce-invalid .input-text,
body.komestic-inline-checkout-errors form.checkout.komestic-inline-errors-armed #customer_details .form-row.woocommerce-invalid select,
body.komestic-inline-checkout-errors form.checkout.komestic-inline-errors-armed #customer_details .form-row.woocommerce-invalid .select2-selection__rendered {
  border-color: #dc2626;
}

body.komestic-inline-checkout-errors form.checkout.komestic-inline-errors-armed #customer_details .form-row.woocommerce-invalid > label {
  color: #dc2626;
}

body.komestic-inline-checkout-errors.woocommerce-checkout
  form.checkout
  .form-row
  p.checkout-inline-error-message,
body.komestic-inline-checkout-errors.woocommerce-checkout
  form.checkout
  #customer_details
  .form-row
  p.checkout-inline-error-message {
  margin: 6px 0 0;
  color: #dc2626;
  font-family: var(--font-primary);
  font-size: 13px;
  line-height: 1.4;
}

/* The parent centres an empty field's label in the row (top: 50%). A message
   makes the row taller, so keep the label centred on the 50px input. */
body.komestic-inline-checkout-errors
  form.checkout
  #customer_details
  .form-row:has(> .checkout-inline-error-message):not(:has(input:is(:focus, :not(:placeholder-shown))))
  > label {
  top: 25px;
}

/* 3a – Error notices (declined card, Stripe API errors, validation failures) */
.woocommerce-checkout .woocommerce-error,
.woocommerce-checkout
  form.checkout
  .woocommerce-NoticeGroup
  .woocommerce-error {
  background-color: #fff5f5;
  border: 1px solid #fca5a5;
  border-left: 4px solid #dc2626;
  border-radius: 6px;
  padding: 14px 18px;
  margin: 0 0 20px 0;
  list-style: none;
  color: #dc2626;
  font-family: var(--font-primary);
  font-size: 14px;
  line-height: 1.6;
}

.woocommerce-checkout .woocommerce-error li,
.woocommerce-checkout
  form.checkout
  .woocommerce-NoticeGroup
  .woocommerce-error
  li {
  margin: 0;
  padding: 0;
}

.woocommerce-checkout .woocommerce-error li + li {
  margin-top: 5px;
}

/* Hide the icon pseudo-elements WooCommerce normally injects */
.woocommerce-checkout .woocommerce-error::before,
.woocommerce-checkout .woocommerce-error li::before {
  display: none;
}

/* 3b – Info notices (e.g. login prompts, coupon info) */
.woocommerce-checkout .woocommerce-info,
.woocommerce-checkout form.checkout .woocommerce-NoticeGroup .woocommerce-info {
  background-color: #eff6ff;
  border: 1px solid #93c5fd;
  border-left: 4px solid #2563eb;
  border-radius: 6px;
  padding: 14px 18px;
  margin: 0 0 20px 0;
  list-style: none;
  color: #1e40af;
  font-family: var(--font-primary);
  font-size: 14px;
  line-height: 1.6;
}

.woocommerce-checkout .woocommerce-info::before {
  display: none;
}

/* 3c – Success notices */
.woocommerce-checkout .woocommerce-message,
.woocommerce-checkout
  form.checkout
  .woocommerce-NoticeGroup
  .woocommerce-message {
  background-color: #f0fdf4;
  border: 1px solid #86efac;
  border-left: 4px solid #16a34a;
  border-radius: 6px;
  padding: 14px 18px;
  margin: 0 0 20px 0;
  list-style: none;
  color: #15803d;
  font-family: var(--font-primary);
  font-size: 14px;
  line-height: 1.6;
}

.woocommerce-checkout .woocommerce-message::before {
  display: none;
}

/* --------------------------------------------------------------------------
   Search results
   Product searches render through the parent's woocommerce.php (same cards,
   filter / sort bar and pagination as the shop).  These rules only tidy the
   spacing on search pages; the shop page itself is untouched.
   -------------------------------------------------------------------------- */

/* Compact title banner (parent: 120px desktop / 100px mobile). */
body.search #pxl-post-title .post-title__inner {
	padding-block: 56px;
}

body.search.woocommerce-shop .wrapper .main-content {
	padding-block: 40px 64px;
}

@media screen and (max-width: 767px) {
	body.search #pxl-post-title .post-title__inner {
		padding-block: 32px;
	}

	body.search #pxl-post-title .post-title__inner > h3 {
		font-size: 22px;
		line-height: 1.3;
	}

	body.search.woocommerce-shop .wrapper .main-content {
		padding-block: 24px 48px;
	}

	/* Filter / grid / sort bar has no mobile layout in the parent and runs
	   off-screen at phone width.  Column toggles do nothing on a phone. */
	body.search .woocommerce-topbar {
		flex-wrap: wrap;
		gap: 12px;
		margin-bottom: 20px;
	}

	body.search .woocommerce-topbar .buttons {
		display: none;
	}

	body.search .woocommerce-topbar .product-orderby {
		flex: 1 1 auto;
		min-width: 0;
	}

	body.search .woocommerce-topbar .product-orderby .pxl-nice-select {
		width: 100%;
	}

	body.search .woocommerce-result {
		margin-bottom: 20px;
	}
}
