/**
 * Dark palette: one token block on `<html class="ahan-dark">` (inc/dark-mode.php).
 *
 * Two layers only. The block below names every colour the dark theme uses; the rules after it take
 * their colour from a token and never from a literal, so a shade changes in one place and a
 * near-duplicate cannot creep back in (the old file carried #101010, #1c1c1c, #1a1a1a, #232323,
 * #2b2b2b, #2e2e2e, #2f2f2f, #3a3a3a, #e8e8e8 and #f5f5f5 side by side).
 *
 * The neutral ramp is mirrored: in light `--gray-1` is the page (the lightest step), here it is the
 * darkest, so the utilities (`bg-gray-3`, `text-muted`…) keep their meaning. Four tones carry the
 * whole dark ui: the page (`--c-bg`) and three ramp steps — surface, raised/zebra, hover.
 *
 * Everything else already reads tokens: the Tailwind utilities resolve `var(--c-*)` at runtime
 * (tailwind/input.css, @theme), so no rebuild is needed. Loaded after app.css, so these rules also
 * win over the few hardcoded colours of style.css and the components.
 */
:root {
	/* Light default; dark overrides them below. `-ink` is for brand-coloured TEXT and `-surface` for
	   brand-coloured FILLS (buttons, header blocks); in the light theme both are the brand itself. */
	--c-primary-ink: var(--c-primary);
	--c-primary-surface: var(--c-primary);
}

html.ahan-dark {
	color-scheme: dark;

	/* Neutrals, mirrored: low = surface, high = ink (the roles of the light ramp). */
	--black: #f2f2f2;
	--gray-9: #ececec;
	--gray-8: #d6d6d6;
	--gray-7: #a6a6a6;
	--gray-6: #8a8a8a;
	--gray-5: #6f6f6f;
	--gray-4: #4c4c4c;
	--gray-3: #383838;
	--gray-2: #2a2a2a;
	--gray-1: #1a1a1a;

	/* The four dark tones and the two inks; every rule below uses one of these names. */
	--c-bg: #121212;              /* page: one step below the ramp */
	--c-surface: var(--gray-1);   /* cards, odd rows, sticky bars */
	--c-surface-2: var(--gray-2); /* zebra rows, tooltips bar of the price table, hairlines */
	--c-surface-3: var(--gray-3); /* row under the pointer, strong hairlines, hover fills */
	--c-text: var(--black);
	--c-text-muted: var(--gray-7);
	--c-border: var(--gray-2);
	--form-bg: var(--c-surface);
	--form-border: var(--gray-3);

	/* Links: neutral, because the brand tint on every link turned the prose into a pink field. The
	   ramp step is the readable one (7.7:1 on the page); hover brightens to the body ink. */
	--c-link: var(--gray-7);

	/* Brand: one fill and one ink. `--c-primary` is a literal here, like every other dark token. */
	--c-primary: #6e1e36; /* the brand, lifted for dark: #5e0520 + 10% white. A literal, like every other dark token; re-pick it if the brand changes */
	--c-primary-surface: var(--c-primary);
	--c-primary-ink: var(--black);      /* brand-coloured TEXT: plain white */
	--c-hover: var(--gray-7);           /* text under the pointer */
	--c-focus: var(--gray-7);           /* focus rings and focused/hovered/active borders */
	--c-primary-line: var(--gray-5);    /* borders that were brand-coloured */
	--c-primary-tint: rgba(242, 242, 242, 0.12); /* selected row, soft highlight */
	--c-primary-tint: color-mix(in srgb, var(--c-primary-ink) 12%, transparent);
	--c-primary-hairline: rgba(255, 255, 255, 0.22); /* seam inside the brand header */
	--c-primary-hairline: color-mix(in srgb, var(--c-primary-contrast) 22%, transparent);

	/* Status inks of the invoice chips (pastel fills on light → tinted blocks on dark). */
	--c-success-tint: #13321e;
	--c-success-tint: color-mix(in srgb, var(--c-success) 22%, var(--c-bg));
	--c-success-ink: #7fcc9b;
	--c-success-ink: color-mix(in srgb, var(--c-success) 55%, #ffffff);
	--c-warning-tint: #443110;
	--c-warning-tint: color-mix(in srgb, var(--c-warning) 22%, var(--c-bg));
	--c-warning-ink: #faca79;
	--c-warning-ink: color-mix(in srgb, var(--c-warning) 55%, #ffffff);
	--c-error-tint: #2f1717;
	--c-error-tint: color-mix(in srgb, var(--c-error) 24%, var(--c-bg));
	--c-error-ink: #ec8888;
	--c-error-ink: color-mix(in srgb, var(--c-error) 55%, #ffffff);
	--c-info-ink: #87a9f4;
	--c-info-ink: color-mix(in srgb, var(--c-info) 55%, #ffffff);

	/* Shadows */
	--shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
	--shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6), 0 4px 16px rgba(0, 0, 0, 0.45);
}

/* ---------- Utilities ---------- */

/* Brand-coloured text: the maroon is unreadable on dark, the tint is not. */
html.ahan-dark .text-primary,
html.ahan-dark .hover\:text-primary:hover,
html.ahan-dark .group:hover .group-hover\:text-primary {
	color: var(--c-hover);
}

/* Brand-coloured fills and borders of the utilities take the lifted surface instead of the maroon. */
html.ahan-dark .bg-primary {
	background-color: var(--c-primary-surface);
}

html.ahan-dark .border-primary {
	border-color: var(--c-primary-line);
}

html.ahan-dark :is(.hover\:border-primary:hover, .hover\:border-primary\/40:hover) {
	border-color: var(--c-focus);
}

html.ahan-dark :where(:focus-visible) {
	outline-color: var(--c-focus);
}

/* Links of the content: style.css paints them with the brand ink, which is loud on dark. */
html.ahan-dark :is(p, .post-content) a,
html.ahan-dark :is(table tr th, table tr td) a,
html.ahan-dark .comments-area :is(.comment-meta a, .reply a, .logged-in-as > a) {
	color: var(--c-link);
}

html.ahan-dark :is(p, .post-content) a:hover,
html.ahan-dark :is(table tr th, table tr td) a:hover,
html.ahan-dark .comments-area :is(.comment-meta a, .reply a, .logged-in-as > a):hover {
	color: var(--c-text);
}

/* ---------- Forms and components ---------- */

/* tailwind/base.css hardcodes the border as rgb(0 0 0 / 10%). */
html.ahan-dark .ahan-v2 :where(input[type="text"], input[type="email"], input[type="tel"], input[type="url"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select, textarea) {
	border-color: var(--form-border) !important;
    background: var(--ahp-bg) !important;
}

html.ahan-dark .ahan-v2 :where(input[type="text"], input[type="email"], input[type="tel"], input[type="url"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select, textarea):focus {
	border-color: var(--c-focus);
}

/* Hardcoded light surfaces of the components (popup and lightbox keep their own settings). */
html.ahan-dark .ahan-popup {
	--ahan-popup-bg: var(--c-surface);
}

html.ahan-dark .ahan-popup__close:hover,
html.ahan-dark .ahan-popup__close:focus-visible {
	background: var(--c-surface-2);
}

html.ahan-dark .ahan-lightbox__img {
	background: var(--c-surface);
}

/* The advisor card is a «black block» on light; on dark it becomes a normal raised card. */
html.ahan-dark .ahan-advisor {
	background: var(--c-surface);
}

/* The photo box of the advisor cards is `#efefef` (experts.css): one step above its card. */
html.ahan-dark .ahan-expert__photo {
	background: var(--c-surface-2);
}

/* ==========================================================================
   Plugin surfaces: text tables, price tables, proforma, freight calculator.
   They draw with hardcoded light colours or with the `:root` variables they print themselves, so the
   block above redefines those variables; the plugin files stay untouched (they are not ours).
   ========================================================================== */

/* ---------- Text tables ---------- */

/* style.css paints every table white (`table:not(.ahp-cart-table)`) while the cell ink is `--c-text`,
   so on dark a prose table stayed white with #f2f2f2 text (1.1:1, unreadable). They take the surface
   now, with the zebra row and the row under the pointer of prose.css. The header is the brand block,
   the same fill as the price tables. */
html.ahan-dark table:not(.apt-table):not(.ahp-cart-table) {
	background: var(--c-surface);
}

html.ahan-dark table:not(.apt-table):not(.ahp-cart-table) tr:nth-child(2n) {
	background: var(--c-surface-2);
}

html.ahan-dark table:not(.apt-table):not(.ahp-cart-table) tr:hover {
	background: var(--c-surface-3);
}

html.ahan-dark table:not(.apt-table):not(.ahp-cart-table) tr th {
	background: var(--c-primary-surface);
	border-color: var(--c-primary-surface);
	color: var(--c-primary-contrast);
}

/* ---------- Price tables (ahan-price-tables: .apt-table-wrap) ---------- */

html.ahan-dark .apt-table-wrap {
	--apt-border: var(--c-border);
	--apt-row-odd: var(--c-surface);
	--apt-row-even: var(--c-surface-2);
	--apt-row-hover: var(--c-surface-3);
	--apt-text: var(--c-text);
	--apt-text-light: var(--c-text-muted);
	--apt-accent: var(--c-info-ink);
	--apt-shadow: var(--shadow);
	--apt-head-bg: var(--c-primary-surface);
}

/* style.css gives every cell a `1px solid #eeeff1` border, so the price table drew a white grid
   (14.8:1 on the surface) and `--apt-border` only reached the outer frame. */
html.ahan-dark .apt-table-wrap :is(th, td) {
	border-color: var(--apt-border);
}

/* Inside the brand header the neutral hairline reads as a dark groove, and the 2px seam under it cuts
   the block off from the rows; a light hairline between the headers replaces both. */
html.ahan-dark .apt-table-wrap thead th {
	border-bottom-color: transparent;
}

html.ahan-dark .apt-table-wrap thead th + th::before {
	background: var(--c-primary-hairline);
}

/* The sticky bar above the table is built by apt-frontend.js with inline `background:#fff` and
   `border-bottom:1px solid #ddd`; its print icon is an inline SVG with `fill="#5E0520"`. */
html.ahan-dark .apt-sticky-header {
	background: var(--c-surface) !important;
	border-bottom-color: var(--c-border) !important;
}

html.ahan-dark .apt-print-btn {
	box-shadow: var(--shadow);
}

html.ahan-dark .apt-print-btn svg {
	filter: brightness(0) invert(1);
	opacity: 0.85;
}

/* «آخرین بروزرسانی» and the VAT checkbox of that bar. */
html.ahan-dark .apt-table-date {
	color: var(--c-text-muted);
}

html.ahan-dark .apt-vat-label {
	color: var(--c-text);
	accent-color: var(--c-primary-surface);
}

/* ---------- Proforma (ahan-proforma) ---------- */

/* Its neutrals are literal greys of ahp-cart.css and its brand comes from the plugin settings; both
   are re-pointed at the site tokens, so the cart is built from the same four tones and one brand. */
html.ahan-dark {
	--ahp-text: var(--c-text);
	--ahp-text-muted: var(--c-text-muted);
	--ahp-border: var(--c-border);
	--ahp-bg: var(--c-surface);
	--ahp-bg-soft: var(--c-surface-2);
	--ahp-shadow-sm: var(--shadow);
	--ahp-shadow-lg: var(--shadow-lg);

	--ahp-primary-light: #260f16;
	--ahp-primary-light: color-mix(in srgb, var(--c-primary) 26%, var(--c-bg));
	/* The plugin prints its brand on :root from its own settings; here it follows the site brand.
	   `-dark` is the plugin's TEXT-on-tint colour (and its hover fill, fixed below), so it is the white ink. */
	--ahp-primary: var(--c-primary);
	--ahp-primary-dark: var(--c-primary-ink);
	--ahp-contact-light: #4b4122;
	--ahp-contact-light: color-mix(in srgb, var(--c-secondary) 26%, var(--c-bg));
	--ahp-contact-ink: #f7e5b0;
	--ahp-contact-ink: color-mix(in srgb, var(--c-secondary) 45%, #ffffff);
}

/* The add/buy buttons were a brand tint with brand text, i.e. a nearly invisible block on the row;
   they become the brand surface with the contrast ink (10.8:1), like the header of the price table. */
html.ahan-dark :is(.ahp-add-btn, .ahp-cart-icon-btn, .ahp-auth-icon-btn) {
	background-color: var(--ahp-primary);
	color: var(--c-primary-contrast);
}

/* Text under the pointer. */
html.ahan-dark :is(.ahp-qty-btn:hover, .ahp-view-cart-btn:hover) {
	color: var(--c-hover);
}

html.ahan-dark .ahp-contact-btn {
	color: var(--ahp-contact-ink);
}

/* Filled buttons keep the contrast text on the brand fill. */
html.ahan-dark .ahp-add-btn:hover,
html.ahan-dark .ahp-cart-icon-btn:hover,
html.ahan-dark .ahp-contact-btn:hover {
	color: var(--c-primary-contrast);
}

/* Hardcoded light surface of the cart head. */
html.ahan-dark .ahp-cart-table thead tr th {
	background: var(--ahp-bg);
}

html.ahan-dark :is(.ahp-add-btn:disabled, .ahp-contact-btn--disabled) {
	background-color: var(--c-surface-2);
	color: var(--gray-5);
}

html.ahan-dark .ahp-drawer-close {
	background: color-mix(in srgb, var(--c-primary-contrast) 8%, transparent);
}

/* Tooltip: it used `--ahp-text` as its background, which is now light. */
html.ahan-dark .ahp-btn-tooltip {
	background-color: var(--c-text);
	color: var(--c-bg);
}

html.ahan-dark .ahp-btn-tooltip::after {
	border-top-color: var(--c-text);
}

/* Invoice status chips of the account page (pastel on light, tinted on dark). */
html.ahan-dark .ahp-invoice-status--expired {
	background: var(--c-surface-2);
	color: var(--c-text-muted);
}

html.ahan-dark .ahp-invoice-status--approved {
	background: var(--c-success-tint);
	color: var(--c-success-ink);
}

html.ahan-dark .ahp-invoice-status--pending {
	background: var(--c-warning-tint);
	color: var(--c-warning-ink);
}

html.ahan-dark .ahp-invoice-status--rejected {
	background: var(--c-error-tint);
	color: var(--c-error-ink);
}

/* Where the plugin used the brand (`--ahp-primary`) as TEXT, as a focus/hover border or as a ring. */
html.ahan-dark :is(.ahp-account-tab.is-active, .ahp-invoice-card-total, .ahp-account-menu-item svg, .ahp-auth-resend) {
	color: var(--c-primary-ink);
}

html.ahan-dark :is(.ahp-auth-back:hover, .ahp-auth-resend:not(:disabled):hover) {
	color: var(--c-hover);
}

html.ahan-dark :is(.ahp-cart-qty:focus, .ahp-drawer .ahp-cart-qty:focus, .ahp-account-field-row input:focus, .ahp-auth-field input:focus, .ahp-qty-btn:hover, .ahp-view-cart-btn:hover, .ahp-invoice-card:hover) {
	border-color: var(--c-focus);
}

html.ahan-dark :is(.ahp-cart-qty:focus, .ahp-drawer .ahp-cart-qty:focus, .ahp-auth-field input:focus) {
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-focus) 25%, transparent);
}

html.ahan-dark .ahp-account-tab.is-active {
	border-bottom-color: var(--c-focus);
}

/* Desktop account tabs: the plugin paints the active one with the brand and `--ahp-bg` (now dark) text. */
@media (min-width: 768px) {
	html.ahan-dark :is(.ahp-account-tab.is-active, .ahp-account-tab:hover) {
		color: var(--c-primary-contrast) !important;
	}
}

/* `-dark` is white now, so the plugin's brand→dark gradient and hover fills get an explicit fill. */
html.ahan-dark .ahp-checkout-btn {
	background: var(--ahp-primary);
}

html.ahan-dark :is(.ahp-account-save-btn:hover, .ahp-auth-icon-btn-active:hover, .ahp-auth-submit:hover:not(:disabled)) {
	background: color-mix(in srgb, var(--ahp-primary) 85%, #ffffff);
}

/* ---------- Freight calculator (asp-freight-calculator) ---------- */

html.ahan-dark .bc-wrap {
	--bc-ink: var(--c-text);
	--bc-line: var(--form-border);
	--bc-muted: var(--c-text-muted);
	--bc-rust-dark: var(--c-primary-ink); /* the maroon price, links and notes of the plugin */
}

html.ahan-dark .bc-select {
	background-color: var(--c-surface);
}

/* The arrow of the selects and the magnifier of the combobox are data-URI SVGs with a dark stroke;
   they carry `%23a6a6a6` (—c-text-muted) because a var() cannot live inside a data URI. */
html.ahan-dark .bc-select:not(.bc-combo-input) {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23a6a6a6' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

html.ahan-dark .bc-combo-input {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='5.2' fill='none' stroke='%23a6a6a6' stroke-width='1.5'/%3E%3Cline x1='11' y1='11' x2='14.5' y2='14.5' stroke='%23a6a6a6' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

html.ahan-dark .bc-combo-list {
	background: var(--c-surface);
	box-shadow: var(--shadow);
}

html.ahan-dark :is(.bc-combo-option:hover, .bc-combo-option.bc-combo-option-active, .bc-result) {
	background: var(--c-primary-tint);
}

html.ahan-dark .bc-spinner {
	border-color: var(--form-border);
	border-top-color: var(--c-primary-ink);
}

/* ==========================================================================
   Roles on the components. The components read `--c-primary-ink` for text and hover text and
   `--c-primary` for fills, borders and focus rings. In dark `--c-primary` itself is the lifted brand
   (set once in the block above), and the roles below are re-pointed:
   text white, hover text grey, focus/hover/active borders grey, other borders a quiet grey, and
   fills follow `--c-primary`. Generated from the component
   selectors, so a new component with the same declarations needs a line here too.
   ========================================================================== */

/* Text under the pointer / focus: grey. */
html.ahan-dark .ahan-accordion__link:hover,
html.ahan-dark .ahan-accordion__trigger:hover,
html.ahan-dark .ahan-accordion__toggle:hover,
html.ahan-dark .ahan-breadcrumb__link:hover,
html.ahan-dark .ahan-calc__field:focus-within .ahan-calc__label,
html.ahan-dark .ahan-calc__field:focus-within .ahan-calc__unit,
html.ahan-dark a.ahan-category-card:hover .ahan-category-card__title,
html.ahan-dark .ahan-comment__date:hover,
html.ahan-dark .ahan-experts__slider .ahan-slider__btn:hover,
html.ahan-dark .ahan-post-list__link:hover,
html.ahan-dark .ahan-post-list__toggle:hover,
html.ahan-dark .ahan-post-list__toggle:focus-visible,
html.ahan-dark .ahan-search__result:hover,
html.ahan-dark .ahan-share__btn:hover:not(.is-done),
html.ahan-dark .ahan-share__btn:focus-visible:not(.is-done),
html.ahan-dark .ahan-subcats__link:hover,
html.ahan-dark .ahan-subcats__link:focus-visible,
html.ahan-dark .ahan-tabs__tab:not(.is-active):hover,
html.ahan-dark .ahan-theme-toggle:hover,
html.ahan-dark .ahan-theme-toggle:focus-visible,
html.ahan-dark .ahan-toc__link:hover,
html.ahan-dark .ahan-footer__links a:hover,
html.ahan-dark .ahan-footer__contact a:hover,
html.ahan-dark .ahan-header__nav-item:hover .ahan-header__nav-link,
html.ahan-dark .ahan-simple-dropdown__link:hover,
html.ahan-dark .ahan-catmenu__grid > li > a:hover,
html.ahan-dark .ahan-catmenu__grid ul li a:hover,
html.ahan-dark .ahan-mobile-bar__burger:hover,
html.ahan-dark .ahan-home-section__all:hover,
html.ahan-dark .ahan-contact__row a:hover {
	color: var(--c-hover);
}

/* Borders and focus rings that were brand-coloured. */
html.ahan-dark .ahan-blog-section__all,
html.ahan-dark .ahan-blog-more__btn,
html.ahan-dark .ahan-expert__btn,
html.ahan-dark .ahan-toc--summary,
html.ahan-dark .ahan-price__intro .ahan-toc--static {
	border-color: var(--c-primary-line);
}

html.ahan-dark .ahan-calc__field:focus-within,
html.ahan-dark .ahan-collapse__toggle:hover,
html.ahan-dark .ahan-collapse__toggle:focus-visible,
html.ahan-dark .ahan-comments .comments-pagination .current,
html.ahan-dark .ahan-share__btn:hover,
html.ahan-dark .ahan-share__btn:focus-visible,
html.ahan-dark .ahan-share__btn.is-done,
html.ahan-dark .ahan-theme-toggle:hover,
html.ahan-dark .ahan-theme-toggle:focus-visible,
html.ahan-dark .ahan-v2 .ahan-request__input:focus-visible {
	border-color: var(--c-focus);
}

html.ahan-dark .ahan-collapse__toggle:focus-visible,
html.ahan-dark .ahan-comments__submit:focus-visible,
html.ahan-dark .ahan-expert__btn:focus-visible,
html.ahan-dark .ahan-expert__msg:focus-visible,
html.ahan-dark .ahan-popup .ahan-popup__btn:focus-visible,
html.ahan-dark .ahan-popup__decline:focus-visible,
html.ahan-dark .ahan-popup__close:focus-visible,
html.ahan-dark .ahan-popup__media--ad:focus-visible,
html.ahan-dark .ahan-popup__input:focus-visible,
html.ahan-dark .ahan-request__input:focus-visible,
html.ahan-dark .ahan-search__input:focus {
	outline-color: var(--c-focus);
}

html.ahan-dark .ahan-form-toast,
html.ahan-dark .ahan-prose blockquote {
	border-inline-start-color: var(--c-primary-line);
}

html.ahan-dark .ahan-tabs__tab.is-active {
	border-bottom-color: var(--c-focus);
}
