/* ==========================================================================
   Base layer (foundation, stage D0): focus, skip link, screen-reader text,
   bidi isolates, motion, text scaling. Logical properties only.
   Loaded after tokens.css.
   ========================================================================== */

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	/* Anchor targets and focus scrolling must not end up under the sticky header. */
	scroll-padding-block-start: calc(var(--ds-header-h) + var(--ds-space-4));
	scroll-behavior: auto;
}
@media (prefers-reduced-motion: no-preference) {
	html { scroll-behavior: smooth; }
}

body {
	font-family: var(--ds-font);
	font-size: 1rem;                 /* rem, not px: honours the browser's text-size setting */
	line-height: var(--ds-lh-body);
	color: var(--ds-text);
	background: var(--ds-bg);
	text-rendering: optimizeLegibility;
	-webkit-font-smoothing: antialiased;
}
button, input, select, textarea, optgroup { font-family: inherit; }

/* Keep wide content from forcing a horizontal page scroll at 320px or 200% zoom. */
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }
table { max-width: 100%; }
:where(h1, h2, h3, h4, p, li, td, th, a, label) { overflow-wrap: break-word; }
:where(h1, h2, h3, h4) { text-wrap: balance; }
:where(p, li) { text-wrap: pretty; }

/* Text inside running copy must not rely on colour alone to read as a link (WCAG 1.4.1). */
:where(p, li, dd, .ds-prose) a:where(:not(.btn, .ds-btn, .ds-card__link, .ds-nolink)) {
	text-decoration: underline;
	text-underline-offset: 0.18em;
	text-decoration-thickness: 1px;
}

/* ---------- Focus: always visible, never replaced by a pale shadow ---------- */
:focus-visible {
	outline: var(--ds-focus-width) solid var(--ds-focus);
	outline-offset: var(--ds-focus-offset);
}
/* A mouse click on a button must not leave a ring; keyboard focus still shows it. */
:focus:not(:focus-visible) { outline: none; }
::selection { background: var(--ds-mint-strong); color: var(--ds-text); }

/* ---------- Skip link ---------- */
.ds-skip {
	position: fixed;
	inset-block-start: var(--ds-space-2);
	inset-inline-start: var(--ds-space-2);
	z-index: calc(var(--ds-z-overlay) + 50);
	padding: var(--ds-space-3) var(--ds-space-4);
	min-height: var(--ds-control-h);
	display: inline-flex;
	align-items: center;
	background: var(--ds-surface);
	color: var(--ds-deep);
	font-weight: var(--ds-fw-semibold);
	border: 2px solid var(--ds-deep);
	border-radius: var(--ds-radius-control);
	text-decoration: none;
	transform: translateY(-300%);
}
.ds-skip:focus, .ds-skip:focus-visible {
	transform: none;
}

/* ---------- Screen-reader only ---------- */
.ds-sr-only,
.sr-only {
	position: absolute !important;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
.ds-sr-only-focusable:focus, .ds-sr-only-focusable:focus-within {
	position: static !important; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none; white-space: normal;
}

/* ---------- Direction helpers ---------- */
/* Emails, URLs, IBANs, wallet addresses, receipt numbers, currency codes, phone numbers: always read left to right, even inside RTL text. */
.ds-ltr,
bdi.ds-amount,
.ds-amount {
	direction: ltr;
	unicode-bidi: isolate;
}
.ds-ltr { text-align: start; display: inline-block; max-width: 100%; }
bdi { unicode-bidi: isolate; }
/* An amount whose server string contains Persian letters (e.g. a Toman figure with the word «تومان») reads right to left. */
.ds-amount[dir="rtl"], bdi.ds-amount[dir="rtl"] { direction: rtl; }
/* Directional icons (arrows, back, next) are mirrored for RTL. */
[dir="rtl"] .ds-flip-rtl,
:root:lang(fa) .ds-flip-rtl { transform: scaleX(-1); }
.ds-nowrap { white-space: nowrap; }
.ds-text-2 { color: var(--ds-text-2); }
.ds-text-sm { font-size: var(--ds-fs-sm); }
.ds-text-xs { font-size: var(--ds-fs-xs); }
.ds-hidden { display: none !important; }

/* ---------- Layout helpers ---------- */
.ds-container {
	width: 100%;
	max-width: var(--ds-container);
	margin-inline: auto;
	padding-inline: var(--ds-gutter);
}
.ds-stack > * + * { margin-block-start: var(--ds-space-4); }
.ds-stack--sm > * + * { margin-block-start: var(--ds-space-2); }
.ds-stack--lg > * + * { margin-block-start: var(--ds-space-6); }
.ds-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); }
.ds-cluster--between { justify-content: space-between; }
.ds-grid { display: grid; gap: var(--ds-space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }

/* Page scroll lock while a dialog / sheet / nav panel is open. */
body.ds-scroll-lock { overflow: hidden; }

/* ---------- Motion: nothing animates for people who ask for less ---------- */
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		transition-delay: 0s !important;
		scroll-behavior: auto !important;
	}
	/* The notification pulse is the one purely decorative loop; remove it outright. */
	.notif-bell__badge { animation: none !important; }
}

/* ---------- Text scaling: nothing may clip when text is enlarged ---------- */
@media (min-resolution: 0dpi) {
	:where(.ds-btn, .ds-badge, .ds-field__control, .ds-tabs [role="tab"], .ds-chip) { min-width: 0; }
}

/* ---------- Print: keep receipts and plain pages readable ---------- */
@media print {
	.ds-skip, .ds-tabbar, .ds-dialog, .ds-toast-region { display: none !important; }
	body { background: #fff; color: #000; }
}
