/**
 * OREM Referencias de domicilio block — frontend styles.
 *
 * DOM model (verified live on staging via browser DOM inspection)
 * ---------------------------------------------------------------
 * The server emits a placeholder:
 *     <div data-block-name="orem/referencias-domicilio"
 *          class="wp-block-orem-referencias-domicilio"></div>
 * WC Blocks' inner-block hydrator CONSUMES that placeholder when it
 * mounts our React component. After hydration, the DOM has only the
 * React component's output:
 *     <div class="orem-referencias-domicilio is-collapsed|is-expanded">
 *       ...
 *     </div>
 * Therefore CSS selectors must target `.orem-referencias-domicilio`,
 * NOT `.wp-block-orem-referencias-domicilio` (a previous version did
 * the latter — dead code, removed).
 *
 * Final position after JS move (see checkout.js::initReferenciasIn
 * ShippingGroup) — INSIDE the shipping fieldset's step-content:
 *
 *   .wp-block-woocommerce-checkout-shipping-address-block
 *     └── .wc-block-components-checkout-step__content
 *           ├── .wc-block-components-notices
 *           ├── .wc-block-components-notices__snackbar
 *           ├── .wc-block-components-address-address-wrapper
 *           │     └── .wc-block-components-address-card-wrapper
 *           │           └── .wc-block-components-address-card  ← visible card
 *           ├── .orem-referencias-domicilio  ← us
 *           └── .wc-block-checkout__use-address-for-billing
 *
 * Visual nesting via :has()
 * -------------------------
 * Our block is NOT a direct sibling of `.wc-block-components-address-
 * card` (different depths). We strip the card's bottom border via the
 * grandparent path: target `.wc-block-components-address-address-
 * wrapper` when it has a `.orem-referencias-domicilio` sibling, then
 * cascade into the card to remove its bottom radius/border. ~92%
 * browser support for `:has()` as of 2026; older browsers see two
 * separate panels (graceful degradation, fully functional).
 */

/* ------------------------------------------------------------------ *
 * 1) Show/hide based on shipping address mode.
 *
 * WC Blocks toggles between "summary" mode (showing the saved address
 * card with an Editar link) and "edit" mode (showing the address form
 * fields) by adding/removing the `.is-editing` class on
 * `.wc-block-components-address-address-wrapper`. Verified live on
 * staging via browser DOM inspection:
 *
 *   Summary mode (collapsed):
 *     <div class="wc-block-components-address-address-wrapper">
 *
 *   Edit mode (expanded, after clicking Editar):
 *     <div class="wc-block-components-address-address-wrapper
 *                 is-editing is-animated">
 *
 * Referencias de domicilio is a piece of ADDRESS DETAIL. It belongs
 * with the form when the customer is actively typing their address —
 * not with the summary card when they're just reviewing it. So:
 *   - Default: hidden
 *   - Visible only when the address-wrapper carries .is-editing
 *
 * Our block is a sibling of `.wc-block-components-address-address-
 * wrapper` (both inside `.wc-block-components-checkout-step__content`),
 * so the general-sibling `~` selector hits cleanly.
 * ------------------------------------------------------------------ */
.orem-referencias-domicilio {
	display: none;
}

.wc-block-components-address-address-wrapper.is-editing
	~ .orem-referencias-domicilio {
	display: block;
}

/* ------------------------------------------------------------------ *
 * 2) Visual treatment when shown (edit mode).
 *
 * In edit mode, the address form-wrapper is showing the input fields.
 * Our block sits below those fields. We render as a quiet card with a
 * subtle border so it reads as "additional address info" rather than
 * a separate checkout step.
 * ------------------------------------------------------------------ */
.orem-referencias-domicilio {
	margin: 8px 0 16px 0;
	padding: 14px 20px 18px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	box-sizing: border-box;
}

/* Breathing room before the use-billing checkbox below us. */
.orem-referencias-domicilio + .wc-block-checkout__use-address-for-billing,
.orem-referencias-domicilio + .wc-block-components-checkbox {
	margin-top: 14px;
}

/* ------------------------------------------------------------------ *
 * 3) Collapsed state — just the trigger link.
 * ------------------------------------------------------------------ */
.orem-referencias-domicilio__toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 6px 0;
	background: transparent;
	border: 0;
	color: #b85c7f;
	font-size: 0.95rem;
	font-weight: 500;
	cursor: pointer;
	line-height: 1.4;
	transition: color 120ms ease;
}

.orem-referencias-domicilio__toggle:hover,
.orem-referencias-domicilio__toggle:focus-visible {
	color: #934763;
	outline: none;
}

.orem-referencias-domicilio__toggle:focus-visible .orem-referencias-domicilio__label {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.orem-referencias-domicilio__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: #b85c7f;
	color: #fff;
	font-weight: 600;
	font-size: 14px;
	line-height: 1;
	flex-shrink: 0;
}

.orem-referencias-domicilio__label {
	letter-spacing: 0.01em;
}

/* ------------------------------------------------------------------ *
 * 4) Expanded state — the labelled textarea. No toggle visible
 *    anymore (it's removed from the DOM once expanded — see
 *    frontend.js).
 * ------------------------------------------------------------------ */
.orem-referencias-domicilio__field {
	margin-top: 0;
}

.orem-referencias-domicilio__field-label {
	display: block;
	margin-bottom: 6px;
	color: #555;
	font-size: 0.875rem;
	font-weight: 500;
}

.orem-referencias-domicilio__optional {
	color: #888;
	font-weight: 400;
}

.orem-referencias-domicilio__textarea {
	width: 100%;
	min-height: 96px;
	padding: 12px 14px;
	border: 1px solid #cfcfcf;
	border-radius: 6px;
	background: #fff;
	color: #222;
	font-family: inherit;
	font-size: 1rem;
	line-height: 1.5;
	resize: vertical;
	box-sizing: border-box;
	transition: border-color 120ms ease, box-shadow 120ms ease;
}

.orem-referencias-domicilio__textarea:focus {
	outline: none;
	border-color: #b85c7f;
	box-shadow: 0 0 0 3px rgba( 184, 92, 127, 0.18 );
}

.orem-referencias-domicilio__textarea::placeholder {
	color: #aaa;
}

@media (max-width: 640px) {
	.orem-referencias-domicilio {
		padding: 12px 16px 16px;
		margin-bottom: 18px;
	}
	.orem-referencias-domicilio__toggle {
		font-size: 0.9rem;
	}
	.orem-referencias-domicilio__textarea {
		min-height: 80px;
		font-size: 0.95rem;
	}
}
