/*
 * TAIF-DEV — front-end utilities
 * Six colors only. Flat. Sharp corners. Corner marks instead of borders.
 * All colors reference theme.json CSS custom properties.
 */

/* ---------- root aliases (short names for internal use) ---------- */
:root {
	--paper:         var(--wp--preset--color--paper);
	--paper-alt:     var(--wp--preset--color--paper-alt);
	--ink:           var(--wp--preset--color--ink);
	--ink-secondary: var(--wp--preset--color--ink-secondary);
	--ink-muted:     var(--wp--preset--color--ink-muted);
	--rule:          var(--wp--preset--color--rule);
	--accent:        var(--wp--preset--color--accent);
	--ease-doc:      cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Fallback spacing tokens — inside @layer so theme.json (unlayered)
   always wins if it defines the same var. Prevents broken layouts when
   theme.json cache is stale after an upload. */
@layer taif-fallbacks {
	:root {
		--wp--preset--spacing--xs:  0.5rem;
		--wp--preset--spacing--sm:  1rem;
		--wp--preset--spacing--md:  1.5rem;
		--wp--preset--spacing--lg:  2.5rem;
		--wp--preset--spacing--xl:  2.5rem;
		--wp--preset--spacing--2xl: 3.5rem;
		--wp--preset--spacing--3xl: 5rem;

		/* Section-level padding tokens — overridden by Appearance → Taif Settings.
		   These defaults match the "normal" spacing preset. */
		--taif-hero-py-top:    clamp(32px, 5vw, 64px);
		--taif-hero-py-bottom: clamp(48px, 7vw, 80px);
		--taif-section-py:     clamp(48px, 8vw, 96px);
	}
}

/* ---------- unified section spacing (overrideable from Taif Settings) ----------
   Applied via class names on the top-level <section> of each pattern.
   `!important` deliberately used to override pattern-inline padding stored in
   post_content from previous installer runs — the block editor writes padding
   inline, and legacy pages carry it in the database. This lets Taif Settings
   control every section site-wide, whether the page was created before or
   after the pattern files were updated. */
.section-hero,
.section-thesis {
	padding-block-start: var(--taif-hero-py-top) !important;
	padding-block-end:   var(--taif-hero-py-bottom) !important;
}

.section-featured-case,
.section-contact,
.section-writing,
.section-index,
.section-standard {
	padding-block: var(--taif-section-py) !important;
}

/* ==========================================================================
   المدونة — أرشيف المقالات والمقال المفرد
   ========================================================================== */

/* `hidden` must win over any display value the layout sets (TOC placeholder). */
[hidden] {
	display: none !important;
}

/* WordPress maps the editor's "right" justification to `justify-content:
   flex-end`. In an RTL flex container flex-end is the LEFT edge — so a row
   marked "right" lands on the left, opposite the text beside it. These rows
   always begin at the reading edge, so pin them to flex-start instead of
   depending on that mapping.

   .taif-post-nav and .taif-pagination are deliberately excluded — they use
   space-between, which is direction-neutral and already correct. */
.taif-meta-bar,
.post-card__meta {
	justify-content: flex-start;
}

/* CTA blocks are a centred composition — heading, copy and buttons all align
   to the middle regardless of text direction. */
.section-contact .wp-block-buttons {
	justify-content: center;
}

/* ---------- شريط التصنيفات ---------- */
.taif-cat-bar ul,
ul.taif-cat-bar {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.25rem;
	margin: 0;
	padding: 0;
	list-style: none;
	border-block: 1px solid var(--rule);
	padding-block: 0.875rem;
}

.taif-cat-bar li {
	margin: 0;
}

.taif-cat-bar a {
	color: var(--ink-secondary);
	text-decoration: none;
	font-size: 0.9375rem;
}

.taif-cat-bar a:hover,
.taif-cat-bar a:focus-visible {
	color: var(--accent);
}

/* ---------- كارت المقال ---------- */
.post-card {
	display: flex;
	flex-direction: column;
	height: 100%;
	/* Grid and flex items default to min-width:auto, so one long unbroken
	   string sizes the track to its full length and spills across the row. */
	min-width: 0;
}

/* WordPress' constrained layout adds margin-inline:auto to every child. That is
   a no-op in normal flow, but .post-card is a flex column — there auto margins
   absorb the free space and centre each child. Templates use flow layout for
   these cards; this is the safety net for cards edited in the site editor. */
.post-card > * {
	margin-inline: 0;
	max-width: none;
}

/* `anywhere`, not `break-word`: only `anywhere` also shrinks the element's
   min-content width, which is the size the grid track measures. */
.post-card .wp-block-post-title,
.post-card .wp-block-post-excerpt,
.post-card .wp-block-post-terms {
	overflow-wrap: anywhere;
}

.post-card .wp-block-post-excerpt__excerpt {
	margin: 0;
}

.post-card .wp-block-post-excerpt__more-link {
	display: inline-block;
	margin-block-start: 0.5rem;
	font-size: 0.875rem;
	color: var(--accent);
	text-decoration: none;
}

.post-card .wp-block-post-excerpt__more-link:hover,
.post-card .wp-block-post-excerpt__more-link:focus-visible {
	text-decoration: underline;
}

.post-card__media img {
	width: 100%;
	height: auto;
	display: block;
}

.post-card__tag {
	margin-block-start: 0.875rem;
	font-size: 0.75rem;
	text-transform: uppercase;
}

.post-card__tag a {
	text-decoration: none;
	color: inherit;
}

.post-card__tag a:hover,
.post-card__tag a:focus-visible {
	text-decoration: underline;
}

.post-card .wp-block-post-title a {
	text-decoration: none;
	color: var(--ink);
}

.post-card .wp-block-post-title a:hover,
.post-card .wp-block-post-title a:focus-visible {
	color: var(--accent);
}

/* Meta row is pinned to the bottom so cards of differing length stay aligned. */
.post-card__meta {
	margin-block-start: auto;
	font-size: 0.75rem;
}

.post-card__meta p,
.post-card__meta time,
.post-card__meta .wp-block-post-date {
	margin: 0;
}

/* post-template wraps every card in <li class="wp-block-post">, so the <li> is
   the actual grid item — min-width:0 has to land there, not on .post-card. */
.taif-post-grid > .wp-block-post,
.taif-related .wp-block-post-template > .wp-block-post {
	min-width: 0;
	display: flex;
}

.taif-post-grid > .wp-block-post > .post-card,
.taif-related .wp-block-post-template > .wp-block-post > .post-card {
	flex: 1 1 auto;
	min-width: 0;
}

/* Grid falls back to two columns, then one, on narrow viewports. */
@media (max-width: 960px) {
	.taif-post-grid.is-layout-grid,
	.taif-related .is-layout-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 640px) {
	.taif-post-grid.is-layout-grid,
	.taif-related .is-layout-grid {
		grid-template-columns: 1fr;
	}
}

/* ---------- شريط بيانات المقال ---------- */
.taif-meta-bar {
	font-size: 0.8125rem;
}

.taif-meta-bar p,
.taif-meta-bar div,
.taif-meta-bar time {
	margin: 0;
}

.taif-meta-bar a {
	color: inherit;
	text-decoration: none;
}

.taif-meta-bar a:hover,
.taif-meta-bar a:focus-visible {
	text-decoration: underline;
}

/* ---------- فهرس المحتوى ---------- */
.taif-toc {
	margin-block: var(--wp--preset--spacing--lg);
	padding: var(--wp--preset--spacing--md);
	background: var(--paper-alt);
	border-inline-start: 2px solid var(--accent);
}

.taif-toc__title {
	margin: 0 0 0.75rem;
	font-size: 0.75rem;
	text-transform: uppercase;
	color: var(--ink-muted);
}

.taif-toc__list {
	margin: 0;
	padding-inline-start: 1.25rem;
	line-height: 1.9;
}

.taif-toc__list a {
	color: var(--ink-secondary);
	text-decoration: none;
}

.taif-toc__list a:hover,
.taif-toc__list a:focus-visible {
	color: var(--accent);
	text-decoration: underline;
}

/* Keeps a jumped-to heading clear of the viewport edge. */
.wp-block-post-content :is(h2, h3) {
	scroll-margin-block-start: 2rem;
}

/* Long unbroken strings (pasted URLs, placeholder text like "asdasdas…") must
   break — otherwise one giant word sizes the content column past the viewport
   and the whole page scrolls horizontally.

   Two things are needed together:

   1. min-width: 0 on the container. The default `auto` uses the content's
      min-content width, which for one unbroken word is the word's full length.
   2. overflow-wrap: anywhere on the inline text. `break-word` isn't enough —
      only `anywhere` also shrinks the min-content width the layout measures. */
.wp-block-post-content {
	min-width: 0;
}

.wp-block-post-content :where(p, h1, h2, h3, h4, h5, h6, li, blockquote, figcaption, pre, code) {
	overflow-wrap: anywhere;
}

/* Featured image and any content image should never overflow their column. */
.taif-post-cover img,
.wp-block-post-featured-image img,
.wp-block-post-content img {
	max-width: 100%;
	height: auto;
}

/* Last-resort clamp: no page ever scrolls sideways. `clip` (not `hidden`) so
   position:sticky elsewhere keeps working. */
html {
	overflow-x: clip;
}

/* ---------- الخلاصة السريعة ---------- */
.taif-tldr {
	border-inline-start: 2px solid var(--accent);
}

.taif-tldr__title {
	margin-block-end: 0.5rem;
}

.taif-tldr ul {
	margin-block: 0;
	padding-inline-start: 1.25rem;
}

/* ---------- الدعوة الداخلية ---------- */
.taif-inline-cta p {
	margin-block: 0;
}

.taif-inline-cta a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 4px;
}

.taif-inline-cta a:hover,
.taif-inline-cta a:focus-visible {
	text-decoration-thickness: 2px;
}

.taif-inline-cta :focus-visible {
	outline-color: var(--paper);
}

/* ---------- الأسئلة الشائعة ---------- */
.taif-faq .wp-block-details summary {
	cursor: pointer;
	font-size: var(--wp--preset--font-size--x-large);
	font-weight: 500;
	list-style: none;
}

.taif-faq .wp-block-details summary::-webkit-details-marker {
	display: none;
}

/* Marker is drawn manually so it sits on the correct side in RTL. */
.taif-faq .wp-block-details summary::after {
	content: "+";
	float: inline-end;
	margin-inline-start: 1rem;
	color: var(--accent);
	font-weight: 400;
}

.taif-faq .wp-block-details[open] summary::after {
	content: "−";
}

.taif-faq .wp-block-details[open] summary {
	margin-block-end: 0.75rem;
}

/* ---------- صندوق الكاتب ---------- */
.taif-author-box .wp-block-post-author {
	display: flex;
	align-items: flex-start;
	gap: var(--wp--preset--spacing--md);
}

.taif-author-box .wp-block-post-author__avatar img {
	display: block;
	border-radius: 50%;
}

.taif-author-box .wp-block-post-author__byline {
	font-size: 0.75rem;
	text-transform: uppercase;
	color: var(--ink-muted);
	margin-block-end: 0.25rem;
}

.taif-author-box .wp-block-post-author__name {
	font-weight: 500;
	margin-block-end: 0.375rem;
}

.taif-author-box .wp-block-post-author__bio {
	margin: 0;
	font-size: 0.9375rem;
	line-height: 1.8;
}

@media (max-width: 640px) {
	.taif-author-box .wp-block-post-author {
		flex-direction: column;
		gap: var(--wp--preset--spacing--sm);
	}
}

/* ---------- التنقل والترقيم ---------- */
.taif-post-nav a,
.taif-pagination a {
	text-decoration: none;
	color: var(--ink-secondary);
	font-size: 0.875rem;
}

.taif-post-nav a:hover,
.taif-post-nav a:focus-visible,
.taif-pagination a:hover,
.taif-pagination a:focus-visible {
	color: var(--accent);
}

.taif-pagination .page-numbers.current {
	color: var(--accent);
	font-weight: 500;
}

/* ==========================================================================
   نموذج التواصل (بدون بلاجن) — /about/#start
   ========================================================================== */

.taif-form {
	display: grid;
	gap: var(--wp--preset--spacing--lg);
	margin-block-start: var(--wp--preset--spacing--lg);
}

.taif-form__row {
	display: grid;
	gap: 0.5rem;
}

/* Side-by-side rows collapse to stacked on narrow screens. */
.taif-form__row--split {
	grid-template-columns: 1fr 1fr;
	gap: var(--wp--preset--spacing--md);
}

@media (max-width: 640px) {
	.taif-form__row--split {
		grid-template-columns: 1fr;
	}
}

.taif-form__label {
	font-family: var(--wp--preset--font-family--sans, "IBM Plex Sans Arabic", system-ui, sans-serif);
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--ink);
}

.taif-form__hint {
	font-size: 0.8125rem;
	color: var(--ink-muted);
	line-height: 1.6;
}

.taif-form__required {
	color: var(--accent);
	margin-inline-start: 4px;
}

.taif-form input[type="text"],
.taif-form input[type="email"],
.taif-form input[type="tel"],
.taif-form input[type="url"],
.taif-form select,
.taif-form textarea {
	width: 100%;
	padding: 0.75rem 0.875rem;
	font: inherit;
	color: var(--ink);
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: 2px;
	transition: border-color 200ms var(--ease-doc), box-shadow 200ms var(--ease-doc);
	/* iOS zooms in on any input font-size below 16px — pin to 16px on mobile. */
	font-size: 16px;
}

.taif-form textarea {
	min-height: 6.5rem;
	resize: vertical;
	line-height: 1.7;
}

.taif-form input:focus,
.taif-form select:focus,
.taif-form textarea:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(27, 58, 115, 0.15);
}

.taif-form__radio-group {
	display: grid;
	gap: 0.5rem;
	padding: 0;
	margin: 0;
	border: 0;
}

.taif-form__radio-group legend {
	font-family: var(--wp--preset--font-family--sans, "IBM Plex Sans Arabic", system-ui, sans-serif);
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--ink);
	margin-block-end: 0.5rem;
}

.taif-form__radio {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	padding: 0.625rem 0.875rem;
	border: 1px solid var(--rule);
	border-radius: 2px;
	cursor: pointer;
	transition: background 160ms;
}

.taif-form__radio:hover {
	background: var(--paper-alt);
}

.taif-form__radio input[type="radio"] {
	margin: 0;
	accent-color: var(--accent);
}

/* Honeypot — visually removed for humans, but not display:none (some bots skip that). */
.taif-form__honeypot {
	position: absolute !important;
	inset-inline-start: -9999px;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.taif-form__submit {
	justify-self: start;
	padding: 1rem 1.75rem;
	font: inherit;
	font-weight: 500;
	color: var(--paper);
	background: var(--ink);
	border: 0;
	border-radius: 2px;
	cursor: pointer;
	transition: background 200ms, transform 200ms var(--ease-doc);
}

.taif-form__submit:hover,
.taif-form__submit:focus-visible {
	background: var(--accent);
	transform: translateY(-1px);
}

.taif-form__submit:active {
	transform: translateY(0);
}

/* ---------- Status banner (after redirect) ---------- */
.taif-form-banner {
	margin-block-end: var(--wp--preset--spacing--lg);
	padding: var(--wp--preset--spacing--md);
	border-inline-start: 3px solid var(--accent);
	background: var(--paper-alt);
}

.taif-form-banner strong {
	display: block;
	font-size: 1.0625rem;
	margin-block-end: 0.375rem;
	color: var(--ink);
}

.taif-form-banner p {
	margin: 0;
	color: var(--ink-secondary);
	line-height: 1.75;
}

.taif-form-banner--error {
	border-inline-start-color: #b91c1c;
}

.taif-form-banner--error strong {
	color: #b91c1c;
}

/* ---------- base tweaks ---------- */
html {
	scroll-behavior: smooth;
}

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	background-color: var(--paper);
}

a,
button,
.wp-block-button__link {
	transition:
		color 240ms var(--ease-doc),
		background-color 240ms var(--ease-doc),
		border-color 240ms var(--ease-doc),
		transform 240ms var(--ease-doc);
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
	border-radius: 2px;
}

/* Stronger focus for interactive controls */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
	box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Minimum touch-target size: 44×44px per WCAG 2.5.5 */
.wp-block-navigation-item__content,
.wp-block-button__link,
.wp-block-navigation__responsive-container-open,
.wp-block-navigation__responsive-container-close,
button {
	min-height: 44px;
	min-width: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

/* Enforce readable minimum font-size — SEOmator flagged 3 spots under 12px */
@media (max-width: 640px) {
	body,
	p,
	li,
	.wp-block-list li {
		font-size: max(1rem, 16px);
	}
	.t-mono,
	.t-label {
		font-size: max(0.8125rem, 13px);
	}
}

img,
video {
	max-width: 100%;
	height: auto;
}

/* SVG diagrams shouldn't blow out mobile viewport */
.wp-block-html svg {
	max-width: 100%;
	height: auto;
}
@media (max-width: 640px) {
	.wp-block-html svg {
		max-width: 300px;
		margin-inline: auto;
		display: block;
	}
}

/* ---------- skip link ---------- */
.taif-skip-link,
.skip-link {
	position: absolute;
	inset-inline-start: 50%;
	top: -100px;
	z-index: 100;
	transform: translateX(50%);
	background: var(--paper);
	border: 1px solid var(--accent);
	color: var(--accent);
	padding: 10px 18px;
	transition: top 200ms var(--ease-doc);
	text-decoration: none;
	font-family: var(--wp--preset--font-family--mono);
	font-size: 13px;
}

.taif-skip-link:focus-visible,
.skip-link:focus-visible {
	top: 12px;
}

/* ---------- typography utilities (map to shortcodes in patterns) ---------- */
.t-mono {
	font-family: var(--wp--preset--font-family--mono);
	font-size: 12px;
	font-weight: 400;
	color: var(--ink-muted);
	/* NO letter-spacing on Arabic text — it breaks readability. */
}

/* Only Latin/English text inside .t-mono gets a tiny tracking bump. */
.t-mono[dir="ltr"],
.t-mono [dir="ltr"] {
	letter-spacing: 0.03em;
}

@media (min-width: 768px) {
	.t-mono {
		font-size: 13px;
	}
}

.t-label {
	font-family: var(--wp--preset--font-family--mono);
	font-size: 12px;
	text-transform: uppercase;
	color: var(--ink-muted);
}

/* Menu items keep their author-added tatweel spacing; no CSS tracking here either. */
.wp-block-navigation .wp-block-navigation-item__content {
	letter-spacing: 0 !important;
}

/* ---------- architectural corner marks ---------- */
.corner-marks {
	position: relative;
}

.corner-marks::before,
.corner-marks::after,
.corner-marks-bottom::before,
.corner-marks-bottom::after {
	content: "";
	position: absolute;
	width: 10px;
	height: 10px;
	pointer-events: none;
	border-color: var(--rule);
	border-style: solid;
}

.corner-marks::before                { top: 0; left: 0;  border-width: 1px 0 0 1px; }
.corner-marks::after                 { top: 0; right: 0; border-width: 1px 1px 0 0; }
.corner-marks-bottom::before         { bottom: 0; left: 0;  border-width: 0 0 1px 1px; }
.corner-marks-bottom::after          { bottom: 0; right: 0; border-width: 0 1px 1px 0; }

.corner-marks-long::before,
.corner-marks-long::after {
	content: "";
	position: absolute;
	width: 18px;
	height: 18px;
	pointer-events: none;
	border-color: var(--rule);
	border-style: solid;
}

.corner-marks-long { position: relative; }
.corner-marks-long::before { top: 0; left: 0;  border-width: 1px 0 0 1px; }
.corner-marks-long::after  { top: 0; right: 0; border-width: 1px 1px 0 0; }

/* ---------- dot leaders ---------- */
.dot-leader {
	flex: 1 1 auto;
	min-width: 24px;
	align-self: flex-end;
	margin-bottom: 6px;
	border-bottom: 1px dotted var(--rule);
}

/* ---------- horizontal rule with ticks ---------- */
.rule-ticks {
	position: relative;
	height: 1px;
	background: var(--rule);
}

.rule-ticks::before,
.rule-ticks::after {
	content: "";
	position: absolute;
	top: -3px;
	width: 1px;
	height: 7px;
	background: var(--rule);
}

.rule-ticks::before { inset-inline-start: 0; }
.rule-ticks::after  { inset-inline-end: 0; }

/* ---------- alternate paper band ---------- */
.band-alt {
	background-color: var(--paper-alt);
}

/* ---------- paper texture overlay (subtle, non-content) ---------- */
.paper-texture,
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	opacity: 0.03;
	mix-blend-mode: multiply;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- header micro-styles ---------- */
.wp-block-navigation .wp-block-navigation-item__content {
	position: relative;
	font-weight: 500;
}

.wp-block-navigation .wp-block-navigation-item__content::after {
	content: "";
	position: absolute;
	inset-inline-start: 0;
	bottom: -4px;
	height: 1px;
	width: 0;
	background: var(--accent);
	transition: width 200ms var(--ease-doc);
}

.wp-block-navigation .wp-block-navigation-item__content:hover::after,
.wp-block-navigation .current-menu-item .wp-block-navigation-item__content::after {
	width: 100%;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/* ---------- print ---------- */
@media print {
	@page { size: A4; margin: 18mm 16mm; }
	html, body { background: #fff !important; color: #000 !important; font-size: 11pt; line-height: 1.7; }
	.site-header, .site-footer, .wp-block-navigation, button, .taif-skip-link { display: none !important; }
	.paper-texture, body::before { display: none !important; }
}

/* ---------- RTL-specific tweaks ---------- */
html[dir="rtl"] .wp-block-quote {
	border-inline-start: 2px solid var(--accent);
	border-inline-end: 0;
	padding-inline-start: 1rem;
	padding-inline-end: 0;
}
