/* Shared design for the whole site. No external dependencies. Mobile-first. */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #0f172a;
  --muted: #566277;
  --border: #dde3ee;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-text: #ffffff;
  --primary-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --bad: #b91c1c;
  --bad-soft: #fdeaea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 14px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #121b2f;
    --surface-2: #18233b;
    --text: #e8edf6;
    --muted: #9aa8c0;
    --border: #25324f;
    --primary: #7aa7ff;
    --primary-hover: #9bbcff;
    --primary-text: #0b1220;
    --primary-soft: #16264a;
    --ok: #5fd08a;
    --ok-soft: #12301f;
    --warn: #f0b95a;
    --warn-soft: #34270d;
    --bad: #ff8f8f;
    --bad-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.65rem, 4.5vw, 2.4rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); margin-top: 0; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
ul, ol { margin: 0 0 1em; padding-left: 1.3em; }
code, .mono { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.formula {
  font-family: var(--mono); font-size: .95rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: .65rem .9rem;
  margin: 0 0 .8rem; overflow-x: auto; white-space: pre-wrap; line-height: 1.7;
}
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; min-height: 44px; display: inline-flex; align-items: center; background: var(--primary); color: var(--primary-text); padding: .5rem .9rem; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }
[hidden] { display: none !important; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 4px 12px; min-height: 58px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 800; font-size: 1.08rem; color: var(--text); text-decoration: none; letter-spacing: -.02em; }
.brand:hover { color: var(--text); }
.brand-mark { width: 28px; height: 28px; flex: none; }
.site-nav { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; }
.site-nav a { color: var(--text); text-decoration: none; padding: .4rem .55rem; border-radius: 8px; font-weight: 500; font-size: .95rem; display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
.site-nav a:hover { background: var(--surface-2); color: var(--text); }
.site-nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.site-nav a.nav-cta { background: var(--primary); color: var(--primary-text); }
.site-nav a.nav-cta:hover { background: var(--primary-hover); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: .65rem 1.15rem; border-radius: 10px; border: 1px solid transparent; min-height: 44px;
  background: var(--primary); color: var(--primary-text); line-height: 1.2;
}
.btn:hover { background: var(--primary-hover); color: var(--primary-text); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .45rem .8rem; font-size: .9rem; border-radius: 8px; min-height: 44px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* Hero */
.hero { padding: 40px 0 28px; }
.hero p.lead { font-size: 1.12rem; color: var(--muted); max-width: 60ch; }
.eyebrow { display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin-bottom: .6rem; }
.hero-points { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 0; list-style: none; margin: 1rem 0 0; color: var(--muted); font-size: .95rem; }
.hero-points li::before { content: "\2713\00a0"; color: var(--ok); font-weight: 700; }

/* Sections and cards */
main { display: block; padding-bottom: 40px; }
.section { margin: 36px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.prose { max-width: 74ch; }
.prose h2 { margin-top: 1.6em; }
.prose h2:first-child { margin-top: 0; }
.page-head { padding: 30px 0 6px; }
.page-head .lead { color: var(--muted); font-size: 1.08rem; max-width: 66ch; }
.breadcrumbs { font-size: .88rem; color: var(--muted); margin: 18px 0 0; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs span[aria-hidden] { margin: 0 .35em; }

/* Tool grid */
.cat-title { margin: 32px 0 12px; font-size: 1.05rem; color: var(--text); font-weight: 700; }
.tool-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.tool-card {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.tool-card:hover { border-color: var(--primary); color: var(--text); transform: translateY(-1px); }
.tool-card strong { font-size: 1.05rem; }
.tool-card span { color: var(--muted); font-size: .93rem; }
.tool-card .go { margin-top: auto; padding-top: 6px; color: var(--primary); font-weight: 600; font-size: .9rem; }

/* Calculator layout */
.calc-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
.calc-layout > * { min-width: 0; }
.calc-form h2, .calc-results h2 { font-size: 1.15rem; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .93rem; margin-bottom: 4px; }
.field .opt { font-weight: 400; color: var(--muted); }
.input-wrap { position: relative; display: flex; align-items: center; }
.field input[type="number"], .field input[type="text"], .field select, .field textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 9px; padding: .6rem .75rem; min-height: 44px;
}
.field textarea { min-height: 140px; resize: vertical; font-family: var(--mono); font-size: .93rem; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: 2px solid var(--primary-soft); }
.input-wrap .unit { position: absolute; right: 12px; color: var(--muted); font-size: .85rem; pointer-events: none; }
.input-wrap.has-unit input { padding-right: 4.4rem; }
.field .hint { margin: 4px 0 0; font-size: .84rem; color: var(--muted); line-height: 1.4; }
.field-check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field-adv { border: 1px solid var(--border); border-radius: 10px; padding: 0 14px 4px; margin: 4px 0 14px; background: var(--surface-2); }
.field-adv > summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: .94rem; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; align-items: center; }
.copy-status { font-size: .88rem; color: var(--ok); min-height: 1.2em; }

.stats { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 1.35rem; font-weight: 750; line-height: 1.25; margin-top: 2px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.stat-primary { background: var(--primary-soft); border-color: var(--primary); grid-column: 1 / -1; }
.stat-primary .stat-value { font-size: 1.9rem; color: var(--primary); }
.stat-ok .stat-value { color: var(--ok); }
.stat-warn .stat-value { color: var(--warn); }
.stat-bad .stat-value { color: var(--bad); }

.notice { border-radius: 10px; padding: 11px 14px; font-size: .94rem; margin-bottom: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.notice.error { background: var(--bad-soft); border-color: var(--bad); color: var(--text); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.notice.info { background: var(--primary-soft); border-color: var(--primary); }
.empty-state { color: var(--muted); padding: 10px 0; }

.table-wrap { overflow-x: auto; margin: 0 0 1em; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-weight: 650; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.txt, th.txt { text-align: left; white-space: normal; min-width: 12ch; }
tr.hl td { background: var(--primary-soft); font-weight: 650; }

/* CTA box */
.cta-box {
  background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 22px 24px; margin: 36px 0;
}
.cta-box h2, .cta-box h3 { margin-bottom: .3em; }
.cta-box p { color: var(--muted); max-width: 62ch; }

/* FAQ */
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.faq summary { cursor: pointer; padding: .85rem 1rem; font-weight: 650; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-weight: 400; font-size: 1.3rem; line-height: 1; color: var(--muted); }
.faq details[open] summary::after { content: "\2212"; }
.faq details > div { padding: 0 1rem 1rem; color: var(--text); }
.faq details > div p:last-child { margin-bottom: 0; }

/* Ad slots: reserved space (no layout shift), almost invisible until ads are enabled. */
.ad-slot { display: block; width: 100%; min-height: 100px; margin: 22px 0; border-radius: 10px; background: rgba(127, 127, 127, .035); overflow: hidden; text-align: center; }
.ad-slot.has-ad { background: transparent; }
.ad-slot:not(.has-ad) { display: none; } /* reserved space appears only once ads are configured */
@media (min-width: 760px) { .ad-slot { min-height: 110px; } }

/* Related / lists */
.related { display: grid; gap: 10px; grid-template-columns: 1fr; padding: 0; list-style: none; }
.related a { display: block; padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; text-decoration: none; font-weight: 600; }
.related a:hover { border-color: var(--primary); }
.related small { display: block; color: var(--muted); font-weight: 400; }

.price-grid, .service-grid, .steps { display: grid; gap: 14px; grid-template-columns: 1fr; }
.service h3 { margin-bottom: .3em; }
.service ul { color: var(--muted); font-size: .94rem; margin-bottom: .7em; }
.service .price { font-weight: 700; color: var(--primary); }
.steps { counter-reset: step; padding: 0; list-style: none; }
.steps li { counter-increment: step; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 16px 58px; position: relative; }
.steps li::before { content: counter(step); position: absolute; left: 16px; top: 14px; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-weight: 700; display: grid; place-items: center; }
.steps strong { display: block; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 32px 0 24px; margin-top: 30px; font-size: .93rem; }
.footer-grid { display: grid; gap: 22px; grid-template-columns: 1fr; }
.site-footer h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .6em; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin: 0; }
.site-footer a { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
.site-footer .brand { min-height: 44px; }
.site-footer a:hover { color: var(--primary); text-decoration: underline; }
.footer-bottom { border-top: 1px solid var(--border); margin-top: 22px; padding-top: 16px; color: var(--muted); font-size: .85rem; }

@media (min-width: 420px) { .site-nav a { padding: .4rem .7rem; } }
@media (min-width: 560px) {
  .tool-grid, .related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-row { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .price-grid, .service-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 860px) {
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
  .related { grid-template-columns: repeat(3, 1fr); }
  .calc-layout { grid-template-columns: minmax(320px, 5fr) minmax(0, 6fr); align-items: start; }
  .calc-results { position: sticky; top: 74px; }
  .footer-grid { grid-template-columns: 1.4fr 1.3fr 1fr; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 24px; }
}
@media print {
  .site-header, .site-footer, .ad-slot, .cta-box, .form-actions { display: none !important; }
  body { background: #fff; color: #000; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* Language switch (header, both languages) */
.lang-switch { display: inline-flex; align-items: center; gap: 2px; border: 0; box-shadow: inset 0 0 0 1px var(--border); border-radius: 999px; padding: 0 3px; font-size: .85rem; font-weight: 600; background: var(--surface); }
.lang-switch a, .lang-switch .lang-current { padding: .25rem .75rem; border-radius: 999px; text-decoration: none; line-height: 1.3; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; }
.site-nav .lang-switch a { padding: .25rem .75rem; font-size: .85rem; min-height: 44px; }
.lang-switch .lang-current { background: var(--primary-soft); color: var(--primary); }
.lang-switch .lang-sep { color: var(--muted); font-size: .8rem; }

/* ---------------------------------------------------------------------------
   Arabic / RTL. Everything here is scoped to [dir="rtl"], so English pages are unaffected.
   Font stack: system Arabic-capable fonts only (no external downloads).
   --------------------------------------------------------------------------- */
[dir="rtl"] { --font: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", "Helvetica Neue", Arial, sans-serif; }
[dir="rtl"] body { line-height: 1.8; text-align: start; }
/* Arabic letters must stay connected: no letter-spacing anywhere */
[dir="rtl"] *, [dir="rtl"] *::before, [dir="rtl"] *::after { letter-spacing: 0; }
[dir="rtl"] .eyebrow, [dir="rtl"] .cat-title, [dir="rtl"] .stat-label, [dir="rtl"] .site-footer h2 { text-transform: none; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { line-height: 1.5; }
[dir="rtl"] ul, [dir="rtl"] ol { padding-left: 0; padding-right: 1.3em; }
[dir="rtl"] .related, [dir="rtl"] .hero-points, [dir="rtl"] .site-footer ul, [dir="rtl"] .steps { padding-right: 0; }
[dir="rtl"] .skip-link { left: auto; right: -999px; }
[dir="rtl"] .skip-link:focus { right: 8px; left: auto; }
/* Formulas, code and Latin symbols stay left-to-right inside the RTL page */
[dir="rtl"] .formula { direction: ltr; text-align: left; unicode-bidi: isolate; }
[dir="rtl"] code, [dir="rtl"] .mono { direction: ltr; unicode-bidi: isolate; }
/* Form controls */
[dir="rtl"] .field input[type="number"] { direction: ltr; text-align: right; }
[dir="rtl"] .field textarea { text-align: start; unicode-bidi: plaintext; }
[dir="rtl"] .input-wrap .unit { right: auto; left: 12px; }
[dir="rtl"] .input-wrap.has-unit input { padding-right: .75rem; padding-left: 4.6rem; }
[dir="rtl"] .field select { text-align: start; }
/* Results */
[dir="rtl"] th, [dir="rtl"] td, [dir="rtl"] td.num, [dir="rtl"] th.num, [dir="rtl"] td.txt, [dir="rtl"] th.txt { text-align: right; }
[dir="rtl"] .stat-value { unicode-bidi: plaintext; }
[dir="rtl"] .steps li { padding: 16px 58px 16px 18px; }
[dir="rtl"] .steps li::before { left: auto; right: 16px; }
[dir="rtl"] .tool-card .go { unicode-bidi: plaintext; }
[dir="rtl"] .price { unicode-bidi: plaintext; }
[dir="rtl"] .cta-box { border-left-width: 1px; border-right: 4px solid var(--primary); }
@media (max-width: 859px) { [dir="rtl"] .header-inner { gap: 8px; } }

/* ---- QA pass: touch targets, layout stability, small-screen header ---- */
.field-adv > summary, .faq summary { min-height: 44px; align-items: center; }
.field-adv > summary { display: flex; }
@media (max-width: 759px) {
  .site-header { position: static; }          /* a 2-3 row sticky header would eat a third of a phone screen */
  /* row 1: brand + language switch; row 2: the page links, spread evenly */
  .header-inner { padding-top: 2px; padding-bottom: 2px; gap: 0; justify-content: flex-start; align-content: flex-start; min-height: 0; }
  [dir="rtl"] .header-inner { gap: 0; }
  .site-nav { display: contents; }
  .site-nav .lang-switch { order: 1; margin-inline-start: auto; }
  .site-nav::before { content: ""; order: 2; flex: 0 0 100%; height: 0; }
  .site-nav > a { order: 3; flex: 1 1 auto; justify-content: center; padding: .4rem .25rem; font-size: .88rem; }
  .site-nav { gap: 0; }
}
@media (min-width: 480px) and (max-width: 859px) {
  .site-footer .footer-grid ul { columns: 2; column-gap: 24px; }
  .site-footer .footer-grid li { break-inside: avoid; }
}
/* Reserve the space of the script-injected header so the page does not jump when it appears */
#site-header { min-height: 60px; }
@media (max-width: 759px) { #site-header { min-height: 96px; } }

.hero-note { margin: .4rem 0 0; color: var(--muted); font-size: .95rem; }

/* ---- Guides (articles under /guides/ and /ar/guides/) ---- */
.byline { color: var(--muted); font-size: .9rem; margin: .5em 0 0; }
.guide .prose h3 { margin-top: 1.2em; }
.guide .prose th, .guide .prose td { white-space: normal; }
.author-box { margin: 26px 0 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-size: .95rem; color: var(--muted); max-width: 74ch; }
.author-box strong { color: var(--text); }
/* Phones: keep the page links on one row; Portfolio and About stay in the footer */
@media (max-width: 479px) { .site-nav a.nav-secondary { display: none; } }
.guide .prose { margin-top: 18px; }
