/**
 * PS Tactical Membership — Shared Stylesheet
 *
 * Covers three UI areas:
 *   1. Checkout notices (existing-account guard, registration required)
 *   2. Points redemption box on the checkout page
 *   3. Membership summary panel on My Account dashboard
 *
 * Design principles:
 *   - !important is avoided in general; specificity is managed via class nesting.
 *     The exceptions are deliberate: the guest-gate security-boundary hide/show
 *     rules (section 1b) must beat Flatsome/WooCommerce theme CSS to keep the
 *     order form hidden, and a few WooCommerce link-colour overrides force #fff
 *     on branded buttons. These are intentional and documented inline.
 *   - Colour variables use CSS custom properties so themes can override them.
 *   - Fully responsive; no fixed pixel widths.
 *   - RTL-agnostic (Thai is LTR, but we use logical properties where feasible).
 *
 * Text domain: ps-tactical-membership
 * Minimum browser support: any browser shipped with WP 6.x target audience.
 */

/* ============================================================================
   CSS Custom Properties (theme override tokens)
   ============================================================================ */

:root {
	/* Brand colours — override in child-theme or Customizer additional CSS */
	--pstm-primary:        #1a3a5c;   /* dark navy, PS Tactical brand  */
	--pstm-primary-light:  #2a5080;
	--pstm-accent:         #e8a020;   /* amber/gold accent             */
	--pstm-success:        #2e7d32;
	--pstm-error:          #c62828;
	--pstm-warning-bg:     #fff8e1;
	--pstm-warning-border: #f9a825;
	--pstm-info-bg:        #e3f2fd;
	--pstm-info-border:    #1976d2;
	--pstm-surface:        #f5f7fa;
	--pstm-border:         #d0d7de;
	--pstm-text:           #1a1a2e;
	--pstm-text-muted:     #6b7280;
	--pstm-radius:         6px;
	--pstm-radius-lg:      10px;
	--pstm-shadow-sm:      0 1px 3px rgba(0, 0, 0, 0.08);
	--pstm-shadow:         0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ============================================================================
   1. CHECKOUT NOTICES
   Rendered by PSTM_Checkout for the existing-account guard and the mandatory-
   registration message.  These appear near the billing email field.
   ============================================================================ */

/* Container injected by pstm-checkout.js below the email field */
.pstm-notice {
	display:       flex;
	align-items:   flex-start;
	gap:           10px;
	margin:        10px 0 14px;
	padding:       12px 16px;
	border-radius: var(--pstm-radius);
	font-size:     0.9em;
	line-height:   1.5;
}

/* ── Existing-account / login prompt ───────────────────────────────────────── */
.pstm-notice--existing-account {
	background:  var(--pstm-warning-bg);
	border:      1px solid var(--pstm-warning-border);
	color:       var(--pstm-text);
}

.pstm-notice--existing-account::before {
	content:     "⚠";
	flex-shrink: 0;
	font-size:   1.1em;
	color:       var(--pstm-warning-border);
}

/* Login link inside the notice */
.pstm-notice__login-link {
	display:       inline-block;
	margin-top:    6px;
	padding:       5px 14px;
	border-radius: var(--pstm-radius);
	background:    var(--pstm-primary);
	color:         #fff !important;  /* override WooCommerce link colour */
	font-size:     0.88em;
	font-weight:   600;
	text-decoration: none;
	transition:    background 0.18s ease;
}

.pstm-notice__login-link:hover,
.pstm-notice__login-link:focus {
	background: var(--pstm-primary-light);
	color:      #fff !important;
}

/* ── Registration required (server-side woocommerce error, styled via class) ── */
.woocommerce-error li[data-code="pstm_existing_account"],
.woocommerce-error li[data-code="pstm_registration_required"] {
	/* WooCommerce natively wraps these in .woocommerce-error > ul > li;
	   we just ensure our codes are visually distinct. */
	font-weight: 500;
}

/* ── Generic info notice (used by JS for neutral feedback) ─────────────────── */
.pstm-notice--info {
	background: var(--pstm-info-bg);
	border:     1px solid var(--pstm-info-border);
	color:      var(--pstm-text);
}

/* ── Error / blocking notice ───────────────────────────────────────────────── */
.pstm-notice--error {
	background: #ffebee;
	border:     1px solid var(--pstm-error);
	color:      var(--pstm-error);
}

/* Spinner shown during AJAX email check */
.pstm-notice--loading {
	background:  var(--pstm-surface);
	border:      1px solid var(--pstm-border);
	color:       var(--pstm-text-muted);
	font-style:  italic;
}

/* ============================================================================
   1b. CHECKOUT LOGIN / REGISTER GATE
   Rendered by PSTM_Checkout::render_auth_gate() on woocommerce_before_checkout_form
   for not-logged-in guests when registration is required. When the gate is
   active, <body> carries .pstm-guest-gate (added via the body_class filter) so
   the real order form is hidden until the shopper logs in or registers.
   ============================================================================ */

/* When the guest gate is active, hide the actual order form entirely so the
   shopper cannot bypass it, while keeping our gate (and WooCommerce notices)
   fully visible. !important is used deliberately here: Flatsome and WooCommerce
   set their own display rules on these containers, and the gate is a hard
   security boundary on a live store — it must win regardless of theme CSS. */
body.pstm-guest-gate form.woocommerce-checkout,
body.pstm-guest-gate form.checkout,
body.pstm-guest-gate #customer_details,
body.pstm-guest-gate #order_review,
body.pstm-guest-gate #order_review_heading,
body.pstm-guest-gate .woocommerce-checkout-review-order,
body.pstm-guest-gate .woocommerce-checkout-payment {
	display: none !important;
}

/* WooCommerce prints its OWN "Returning customer? Click here to login" and
   "Have a coupon?" toggles on woocommerce_before_checkout_form, OUTSIDE the
   <form class="checkout"> hidden above — so they survive the rule above and
   would show a confusing second login/coupon box next to our gate. Hide them
   too while the gate is active. The shopper logs in via our gate's login
   column instead; coupons are irrelevant until they are past the gate.

   IMPORTANT: our own gate login column is rendered by woocommerce_login_form(),
   which outputs <form class="woocommerce-form-login ...">. We must NOT hide that
   one — the form rules below hide all .woocommerce-form-login then re-show the
   one inside .pstm-auth-gate. The toggle classes here are native-checkout only
   and never appear inside our gate, so they are safe to hide outright. */
body.pstm-guest-gate .woocommerce-form-login-toggle,
body.pstm-guest-gate .woocommerce-form-coupon-toggle {
	display: none !important;
}

/* Also hide the native login & coupon FORMS themselves (in case a theme or a
   no-JS render leaves them expanded). The native coupon form carries the
   .checkout_coupon class, which never appears inside our gate, so it is safe to
   hide outright. The native login form shares .woocommerce-form-login with our
   OWN gate login form, so we hide all of them here and then re-show the one
   inside .pstm-auth-gate with a higher-specificity rule below. This avoids
   Level-4 :not() descendant selectors that some browsers fail to parse. */
body.pstm-guest-gate .checkout_coupon,
body.pstm-guest-gate .woocommerce-form-login {
	display: none !important;
}

/* Re-show our gate's own login form (a descendant of .pstm-auth-gate). Higher
   specificity than the hide rule above, so the gate login column stays visible
   while the native checkout login form remains hidden. */
body.pstm-guest-gate .pstm-auth-gate .woocommerce-form-login {
	display: block !important;
}

/* The gate itself and WooCommerce notices/messages must always remain visible
   (e.g. WC login/registration errors surfaced after a failed submit). */
body.pstm-guest-gate .pstm-auth-gate,
body.pstm-guest-gate .woocommerce-notices-wrapper,
body.pstm-guest-gate .woocommerce-error,
body.pstm-guest-gate .woocommerce-message,
body.pstm-guest-gate .woocommerce-info {
	display: block !important;
}

/* Gate container */
.pstm-auth-gate {
	margin:        0 0 28px;
	padding:       0;
}

/* Intro / instruction message above the two columns */
.pstm-auth-gate__intro {
	margin:        0 0 18px;
	padding:       14px 18px;
	background:    var(--pstm-info-bg);
	border:        1px solid var(--pstm-info-border);
	border-radius: var(--pstm-radius);
	font-size:     1em;
	font-weight:   600;
	color:         var(--pstm-text);
	text-align:    center;
}

/* Two-column layout: login | register */
.pstm-auth-gate__cols {
	display:               grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap:                   20px;
	align-items:           start;
}

/* Individual card */
.pstm-auth-gate__col {
	padding:       22px 24px;
	background:    #fff;
	border:        1px solid var(--pstm-border);
	border-radius: var(--pstm-radius-lg);
	box-shadow:    var(--pstm-shadow-sm);
}

/* Accent the register column so the primary CTA stands out */
.pstm-auth-gate__col--register {
	border-top: 3px solid var(--pstm-accent);
}

.pstm-auth-gate__col--login {
	border-top: 3px solid var(--pstm-primary);
}

/* Column heading */
.pstm-auth-gate__heading {
	margin:      0 0 16px;
	font-size:   1.15em;
	font-weight: 700;
	color:       var(--pstm-primary);
}

/* Normalise inputs inside the gate forms (both WC login form and our register
   form) so the two columns look consistent regardless of theme defaults. */
.pstm-auth-gate__col .input-text,
.pstm-auth-gate__col input[type="text"],
.pstm-auth-gate__col input[type="email"],
.pstm-auth-gate__col input[type="password"] {
	width:         100%;
	padding:       9px 12px;
	border:        1px solid var(--pstm-border);
	border-radius: var(--pstm-radius);
	font-size:     0.95em;
	background:    #fff;
	box-sizing:    border-box;
}

.pstm-auth-gate__col .input-text:focus,
.pstm-auth-gate__col input[type="text"]:focus,
.pstm-auth-gate__col input[type="email"]:focus,
.pstm-auth-gate__col input[type="password"]:focus {
	outline:      none;
	border-color: var(--pstm-primary);
	box-shadow:   0 0 0 3px rgba(26, 58, 92, 0.12);
}

.pstm-auth-gate__col label {
	display:     block;
	margin:      0 0 6px;
	font-size:   0.9em;
	font-weight: 600;
	color:       var(--pstm-text);
}

.pstm-auth-gate__col .form-row {
	margin-bottom: 14px;
}

/* Submit buttons in both columns */
.pstm-auth-gate__col button[type="submit"],
.pstm-auth-gate__col .button {
	display:       inline-block;
	padding:       10px 22px;
	border:        none;
	border-radius: var(--pstm-radius);
	background:    var(--pstm-primary);
	color:         #fff;
	font-size:     0.95em;
	font-weight:   600;
	cursor:        pointer;
	transition:    background 0.18s ease;
}

.pstm-auth-gate__col button[type="submit"]:hover,
.pstm-auth-gate__col button[type="submit"]:focus,
.pstm-auth-gate__col .button:hover,
.pstm-auth-gate__col .button:focus {
	background: var(--pstm-primary-light);
	outline:    none;
}

/* Make the register CTA use the accent colour to draw new customers in */
.pstm-auth-gate__col--register .pstm-auth-gate__submit {
	background: var(--pstm-accent);
	color:      var(--pstm-text);
}

.pstm-auth-gate__col--register .pstm-auth-gate__submit:hover,
.pstm-auth-gate__col--register .pstm-auth-gate__submit:focus {
	background: var(--pstm-warning-border);
}

/* "Remember me" row in the WC login form */
.pstm-auth-gate__col .woocommerce-form-login__rememberme {
	display:     block;
	margin:      4px 0 14px;
	font-weight: 400;
}

/* ============================================================================
   2. POINTS REDEMPTION BOX
   Rendered on the checkout page by PSTM_Points / pstm-points.js.
   Appears in the order review section or after shipping methods.
   ============================================================================ */

/* Outer card */
.pstm-points-box {
	margin:        24px 0 16px;
	padding:       18px 20px;
	background:    var(--pstm-surface);
	border:        1px solid var(--pstm-border);
	border-left:   4px solid var(--pstm-accent);
	border-radius: var(--pstm-radius-lg);
	box-shadow:    var(--pstm-shadow-sm);
}

.pstm-points-box__heading {
	margin:      0 0 12px;
	font-size:   1em;
	font-weight: 700;
	color:       var(--pstm-primary);
	display:     flex;
	align-items: center;
	gap:         8px;
}

/* Coin / star icon before heading */
.pstm-points-box__heading::before {
	content:   "⭐";
	font-size: 1.1em;
}

/* Available balance line */
.pstm-points-balance {
	margin:      0 0 14px;
	font-size:   0.9em;
	color:       var(--pstm-text-muted);
}

.pstm-points-balance strong {
	color:      var(--pstm-primary);
	font-size:  1.05em;
}

/* Inline form: number input + apply button side by side */
.pstm-points-form {
	display:   flex;
	gap:       8px;
	flex-wrap: wrap;
	align-items: center;
}

.pstm-points-form__input {
	flex:          1 1 120px;
	max-width:     160px;
	padding:       8px 12px;
	border:        1px solid var(--pstm-border);
	border-radius: var(--pstm-radius);
	font-size:     0.95em;
	color:         var(--pstm-text);
	background:    #fff;
	transition:    border-color 0.15s;
}

.pstm-points-form__input:focus {
	outline:      none;
	border-color: var(--pstm-primary);
	box-shadow:   0 0 0 3px rgba(26, 58, 92, 0.12);
}

/* Disable spin arrows on number inputs (cosmetic preference) */
.pstm-points-form__input[type="number"]::-webkit-outer-spin-button,
.pstm-points-form__input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
.pstm-points-form__input[type="number"] {
	-moz-appearance: textfield;
}

.pstm-points-form__btn {
	flex:          0 0 auto;
	padding:       8px 18px;
	border:        none;
	border-radius: var(--pstm-radius);
	background:    var(--pstm-primary);
	color:         #fff;
	font-size:     0.9em;
	font-weight:   600;
	cursor:        pointer;
	transition:    background 0.18s ease, opacity 0.18s ease;
}

.pstm-points-form__btn:hover,
.pstm-points-form__btn:focus {
	background: var(--pstm-primary-light);
	outline:    none;
}

.pstm-points-form__btn:disabled {
	opacity: 0.55;
	cursor:  not-allowed;
}

/* Remove / clear applied redemption link */
.pstm-points-form__remove {
	font-size:       0.85em;
	color:           var(--pstm-text-muted);
	text-decoration: underline;
	cursor:          pointer;
	background:      none;
	border:          none;
	padding:         0;
}

.pstm-points-form__remove:hover {
	color: var(--pstm-error);
}

/* Feedback message below form (validation errors, success) */
.pstm-points-msg {
	margin-top: 8px;
	font-size:  0.85em;
	min-height: 1.3em; /* reserve space to prevent layout shift */
}

.pstm-points-msg--error {
	color: var(--pstm-error);
}

.pstm-points-msg--success {
	color: var(--pstm-success);
}

/* Applied redemption summary (replaces form after successful apply) */
.pstm-points-applied {
	display:     flex;
	align-items: center;
	gap:         10px;
	margin-top:  8px;
	font-size:   0.9em;
	color:       var(--pstm-success);
	font-weight: 600;
}

.pstm-points-applied::before {
	content: "✓";
}

/* ============================================================================
   3. MY ACCOUNT — MEMBERSHIP SUMMARY PANEL
   Rendered on the WooCommerce My Account dashboard by PSTM_Account.
   Sits above the default order list.
   ============================================================================ */

.pstm-account-summary {
	display:        grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap:            16px;
	margin:         0 0 28px;
}

/* Individual stat card */
.pstm-account-summary__card {
	padding:       18px 20px;
	background:    #fff;
	border:        1px solid var(--pstm-border);
	border-top:    3px solid var(--pstm-primary);
	border-radius: var(--pstm-radius-lg);
	box-shadow:    var(--pstm-shadow-sm);
	text-align:    center;
}

.pstm-account-summary__card--accent {
	border-top-color: var(--pstm-accent);
}

/* Icon above card value */
.pstm-account-summary__icon {
	display:     block;
	font-size:   2em;
	margin-bottom: 6px;
}

/* Large value (e.g. "1,250 แต้ม") */
.pstm-account-summary__value {
	display:     block;
	font-size:   1.7em;
	font-weight: 700;
	color:       var(--pstm-primary);
	line-height: 1.2;
}

.pstm-account-summary__card--accent .pstm-account-summary__value {
	color: var(--pstm-accent);
}

/* Label beneath the value (e.g. "คะแนนสะสม") */
.pstm-account-summary__label {
	display:   block;
	margin-top: 4px;
	font-size:  0.85em;
	color:      var(--pstm-text-muted);
}

/* ── Points ledger table on the My Account /pstm-points/ endpoint ───────────── */

.pstm-points-ledger {
	width:           100%;
	border-collapse: collapse;
	font-size:       0.9em;
	margin-top:      20px;
}

.pstm-points-ledger th,
.pstm-points-ledger td {
	padding:     10px 12px;
	text-align:  left;
	border-bottom: 1px solid var(--pstm-border);
}

.pstm-points-ledger thead th {
	background:  var(--pstm-surface);
	font-weight: 600;
	color:       var(--pstm-text);
	font-size:   0.85em;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

/* Positive delta (earn / refund) */
.pstm-points-ledger .pstm-delta--positive {
	color:       var(--pstm-success);
	font-weight: 600;
}

/* Negative delta (redeem / reverse) */
.pstm-points-ledger .pstm-delta--negative {
	color:       var(--pstm-error);
	font-weight: 600;
}

/* Empty state row */
.pstm-points-ledger .pstm-empty-row td {
	text-align:  center;
	color:       var(--pstm-text-muted);
	padding:     24px;
	font-style:  italic;
}

/* ── Points page heading and redemption link ────────────────────────────────── */

.pstm-points-page__balance-hero {
	padding:       20px 24px;
	margin-bottom: 24px;
	background:    linear-gradient(135deg, var(--pstm-primary) 0%, var(--pstm-primary-light) 100%);
	border-radius: var(--pstm-radius-lg);
	color:         #fff;
	text-align:    center;
	box-shadow:    var(--pstm-shadow);
}

.pstm-points-page__balance-hero .pstm-account-summary__value {
	color:     #fff;
	font-size: 3em;
}

.pstm-points-page__balance-hero .pstm-account-summary__label {
	color:     rgba(255, 255, 255, 0.8);
	font-size: 1em;
}

/* ============================================================================
   4. MY ACCOUNT — NEWSLETTER PREFERENCE PANEL
   Rendered by PSTM_Account on the WooCommerce My Account dashboard.
   Appears below the membership summary stat cards.
   ============================================================================ */

.pstm-newsletter-pref {
	margin:        0 0 28px;
	padding:       18px 20px;
	background:    #fff;
	border:        1px solid var(--pstm-border);
	border-radius: var(--pstm-radius-lg);
	box-shadow:    var(--pstm-shadow-sm);
}

.pstm-newsletter-pref__heading {
	margin:      0 0 14px;
	font-size:   1em;
	font-weight: 700;
	color:       var(--pstm-primary);
}

.pstm-newsletter-pref__form {
	display:     flex;
	flex-wrap:   wrap;
	align-items: center;
	gap:         12px;
}

.pstm-newsletter-pref__label {
	display:     flex;
	align-items: center;
	gap:         8px;
	flex:        1 1 260px;
	font-size:   0.92em;
	cursor:      pointer;
	color:       var(--pstm-text);
}

.pstm-newsletter-pref__checkbox {
	width:  16px;
	height: 16px;
	flex-shrink: 0;
	cursor:      pointer;
	accent-color: var(--pstm-primary); /* modern browsers only; degrades gracefully */
}

.pstm-newsletter-pref__submit {
	flex:          0 0 auto;
	padding:       7px 20px;
	border:        none;
	border-radius: var(--pstm-radius);
	background:    var(--pstm-primary);
	color:         #fff;
	font-size:     0.88em;
	font-weight:   600;
	cursor:        pointer;
	transition:    background 0.18s ease;
}

.pstm-newsletter-pref__submit:hover,
.pstm-newsletter-pref__submit:focus {
	background: var(--pstm-primary-light);
	outline:    none;
}

.pstm-newsletter-pref__submit:disabled {
	opacity: 0.55;
	cursor:  not-allowed;
}

/* Status message shown by the AJAX handler */
.pstm-newsletter-pref__msg {
	flex:      1 1 100%;  /* own row below the checkbox + button */
	font-size: 0.85em;
	min-height: 1.3em;   /* reserve space to prevent layout shift */
}

.pstm-newsletter-msg--success {
	color: var(--pstm-success);
}

.pstm-newsletter-msg--error {
	color: var(--pstm-error);
}

/* ── Link to the points ledger page from the summary card ───────────────────── */

.pstm-account-summary__details-link {
	color:           var(--pstm-primary) !important;
	text-decoration: underline;
	font-weight:     500;
}

.pstm-account-summary__details-link:hover {
	color: var(--pstm-primary-light) !important;
}

/* ============================================================================
   5. UTILITY / ACCESSIBILITY
   ============================================================================ */

/* Screen-reader only text helper (accessible hiding) */
.pstm-sr-only {
	position: absolute;
	width:    1px;
	height:   1px;
	padding:  0;
	margin:   -1px;
	overflow: hidden;
	clip:     rect(0, 0, 0, 0);
	white-space: nowrap;
	border:   0;
}

/* Loading spinner animation used in AJAX states */
@keyframes pstm-spin {
	to { transform: rotate(360deg); }
}

.pstm-spinner {
	display:           inline-block;
	width:             16px;
	height:            16px;
	border:            2px solid var(--pstm-border);
	border-top-color:  var(--pstm-primary);
	border-radius:     50%;
	animation:         pstm-spin 0.7s linear infinite;
	vertical-align:    middle;
	margin-right:      6px;
}

/* ============================================================================
   6. RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 600px) {
	/* Stack the login/register gate columns on small screens */
	.pstm-auth-gate__cols {
		grid-template-columns: 1fr;
	}

	/* Stack points form vertically on small screens */
	.pstm-points-form {
		flex-direction: column;
		align-items:    stretch;
	}

	.pstm-points-form__input {
		max-width: 100%;
	}

	/* Single-column summary on mobile */
	.pstm-account-summary {
		grid-template-columns: 1fr;
	}

	/* Smaller hero balance on mobile */
	.pstm-points-page__balance-hero .pstm-account-summary__value {
		font-size: 2.2em;
	}

	/* Ledger table: allow horizontal scroll */
	.pstm-points-ledger-wrapper {
		overflow-x: auto;
	}
}
