/**
 * Base layer — RTL reset, typography, accessibility foundation.
 *
 * This file sits above Bootstrap RTL and below component files.
 * It extends Bootstrap's reboot with:
 *   - Logical properties for RTL safety
 *   - Arabic-first typography rules
 *   - WCAG AA focus-visible states
 *   - Minimum interactive target heights
 *   - Reduced-motion support
 *   - Screen-reader utility
 *
 * No layout styling. No component styling. No brand colors applied here
 * (consume var(--brand-*) tokens only — never raw values).
 *
 * @package PackagingCommerce
 */

/* ── Box model reset ─────────────────────────────────────────────── */

*,
*::before,
*::after {
	box-sizing: border-box;
}

/* ── Document root ───────────────────────────────────────────────── */

html {
	scroll-behavior: smooth;
	text-size-adjust: 100%;
	-webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}
}

body {
	font-family: var(--brand-font-body);
	font-size: var(--brand-text-base);
	font-weight: var(--brand-weight-regular);
	line-height: var(--brand-leading-normal);
	color: var(--brand-color-ink);
	background-color: var(--brand-color-surface);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;

	/*
	 * Arabic text: never set letter-spacing.
	 * Arabic script is contextual — forced spacing breaks glyph connections.
	 */
	letter-spacing: 0;

	/*
	 * Lining, tabular figures for prices/quantities — IBM Plex Sans
	 * Arabic's default numerals otherwise vary in width, which reads as
	 * jitter in price columns and quantity inputs.
	 */
	font-variant-numeric: lining-nums tabular-nums;
}

/* ── Headings ────────────────────────────────────────────────────── */

h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: var(--brand-font-heading);
	font-weight: var(--brand-weight-bold);
	line-height: var(--brand-leading-tight);
	color: var(--brand-color-ink);
	letter-spacing: 0;
	margin-block-start: 0;
	margin-block-end: var(--brand-space-4);
}

/*
 * Mobile scale first (smaller — Arabic headline text wraps awkwardly at
 * desktop sizes on narrow screens), stepped up at the 48rem breakpoint
 * already used elsewhere in the theme's page CSS (shop.css, cart.css).
 * h4–h6 do not need a mobile step down; they're already small enough.
 */
h1 { font-size: var(--brand-text-2xl); }
h2 { font-size: var(--brand-text-xl); }
h3 { font-size: var(--brand-text-lg); }
h4 { font-size: var(--brand-text-md); }
h5 { font-size: var(--brand-text-base); }
h6 { font-size: var(--brand-text-sm); }

@media (min-width: 48rem) {
	h1 { font-size: var(--brand-text-3xl); }
	h2 { font-size: var(--brand-text-2xl); }
	h3 { font-size: var(--brand-text-xl); }
	h4 { font-size: var(--brand-text-lg); }
	h5 { font-size: var(--brand-text-md); }
	h6 { font-size: var(--brand-text-base); }
}

/* ── Paragraphs and text ─────────────────────────────────────────── */

p {
	margin-block-start: 0;
	margin-block-end: var(--brand-space-4);
}

/* ── Links ───────────────────────────────────────────────────────── */

a {
	color: var(--brand-color-primary);
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
	transition: color var(--brand-transition-fast);
}

a:hover,
a:focus {
	color: var(--brand-color-primary-dark);
}

/* ── Images ──────────────────────────────────────────────────────── */

img,
svg {
	max-width: 100%;
	height: auto;
	vertical-align: middle;
}

/* ── Responsive embeds ───────────────────────────────────────────── */

iframe,
video {
	max-width: 100%;
}

/* ── Lists ───────────────────────────────────────────────────────── */

ul,
ol {
	padding-inline-start: var(--brand-space-6);
	margin-block-start: 0;
	margin-block-end: var(--brand-space-4);
}

/* ── Buttons (base) ──────────────────────────────────────────────── */

button,
[type='button'],
[type='reset'],
[type='submit'] {
	cursor: pointer;
	min-height: 44px; /* WCAG 2.5.5 minimum touch target */
}

/* ── Form fields (base) ──────────────────────────────────────────── */

input,
select,
textarea {
	font-family: inherit;
	font-size: inherit;
	min-height: 44px;
	width: 100%;
}

textarea {
	min-height: 100px;
	resize: vertical;
}

label {
	display: block;
	margin-block-end: var(--brand-space-1);
	font-weight: var(--brand-weight-medium);
}

/* ── Focus-visible: WCAG AA ──────────────────────────────────────── */

/*
 * Remove default outline (Bootstrap reboot may already do this).
 * Re-apply focus-visible with a visible, high-contrast ring.
 * Do not use :focus alone — causes visible ring on mouse click.
 */
:focus {
	outline: none;
}

:focus-visible {
	outline: 3px solid var(--brand-color-primary);
	outline-offset: 2px;
	border-radius: var(--brand-radius-sm);
}

/* Ensure WooCommerce buttons also get the ring */
.woocommerce a.button:focus-visible,
.woocommerce button.button:focus-visible,
.woocommerce input.button:focus-visible {
	outline: 3px solid var(--brand-color-primary);
	outline-offset: 2px;
}

/* ── Horizontal rule ─────────────────────────────────────────────── */

hr {
	border: none;
	border-block-start: 1px solid var(--brand-color-border);
	margin-block: var(--brand-space-6);
}

/* ── Tables ──────────────────────────────────────────────────────── */

table {
	border-collapse: collapse;
	width: 100%;
}

th,
td {
	padding: var(--brand-space-3) var(--brand-space-4);
	text-align: start;
	border-block-end: 1px solid var(--brand-color-border);
}

th {
	font-weight: var(--brand-weight-semibold);
}

/* ── Screen-reader utility ───────────────────────────────────────── */

.pkgc-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;
}

/* ── Skip link ───────────────────────────────────────────────────── */

.pkgc-skip-link {
	position: absolute;
	inset-inline-start: -9999px;
	inset-block-start: var(--brand-space-4);
	background: var(--brand-color-primary);
	color: #fff;
	padding: var(--brand-space-3) var(--brand-space-6);
	border-radius: var(--brand-radius-md);
	font-weight: var(--brand-weight-semibold);
	z-index: var(--brand-z-fixed);
	text-decoration: none;
}

.pkgc-skip-link:focus {
	inset-inline-start: var(--brand-space-4);
	outline: 3px solid #fff;
	outline-offset: 2px;
}

/* ── Reduced motion ──────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
