:root {
  --bg: #f6f7f4;
  --bg-alt: #eef0ea;
  --card: #ffffff;
  --text: #14181c;
  --text-soft: #3b4252;
  --muted: #6c7280;
  --primary: #0b5e3f;
  --primary-700: #09472f;
  --primary-50: #e6f0eb;
  --secondary: #b7800d;
  --secondary-50: #f8eed9;
  --accent: #6b21a8;
  --line: #e3e5dd;
  --line-strong: #cfd2c5;
  --danger: #b91c1c;
  --ok: #166534;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", "Noto Kufi Arabic", sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 1160px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 28, .04), 0 1px 1px rgba(20, 24, 28, .03);
  --shadow: 0 4px 16px rgba(20, 24, 28, .06), 0 2px 4px rgba(20, 24, 28, .04);
  --shadow-lg: 0 20px 40px rgba(20, 24, 28, .08), 0 4px 10px rgba(20, 24, 28, .04);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 100%/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[dir="rtl"] body { text-align: right; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: .5rem; top: .5rem; background: var(--card); padding: .35rem .6rem; z-index: 99; border-radius: var(--radius-sm); box-shadow: var(--shadow); }

/* ===== Header ===== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-row {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .75rem 1.5rem;
  padding: .65rem 0;
}
.brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: var(--text);
}
.brand-mark {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary) 0%, #0a7d52 100%);
  color: #fff; font-weight: 800; font-size: 1.05rem;
  border-radius: 10px;
  letter-spacing: -.02em;
  box-shadow: 0 2px 6px rgba(11, 94, 63, .25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 1.1rem; color: var(--text); letter-spacing: -.01em; }
.brand-tag { font-size: .75rem; color: var(--muted); }

.topnav { display: flex; flex-wrap: wrap; gap: .25rem .35rem; align-items: center; }
.topnav a {
  padding: .4rem .65rem; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: .92rem; font-weight: 500;
  border: 1px solid transparent; transition: all .15s;
  text-decoration: none;
}
.topnav a:hover { background: var(--primary-50); color: var(--primary-700); text-decoration: none; }
.topnav a.lang {
  color: var(--primary); border-color: var(--primary);
  font-weight: 600; padding-inline: .75rem;
}
.topnav a.lang:hover { background: var(--primary); color: #fff; }

/* ===== Main ===== */
main { padding: 0; position: relative; }

.hero { margin-bottom: 1.5rem; }
.hero h1 {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  margin: 0 0 .5rem;
  color: var(--text); font-weight: 700; letter-spacing: -.015em;
}
.summary {
  font-size: 1.05rem; line-height: 1.6;
  background: var(--card);
  border: 0 solid var(--line);
  border-inline-start: 4px solid var(--primary);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  margin: 0 0 .5rem;
}
.last-updated { color: var(--muted); font-size: .82rem; display: inline-block; margin-top: .35rem; }
.last-updated time { font-family: var(--mono); font-weight: 600; color: var(--text-soft); }

/* ===== Rate cards stack ===== */
.rates-stack {
  display: flex; flex-direction: column; gap: .85rem; margin: 1.5rem 0;
}
.rate-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.rate-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.rate-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: var(--muted); opacity: .8;
}
.rate-card.official::before { background: var(--primary); }
.rate-card.parallel::before { background: var(--secondary); }
.rate-card.spread::before { background: var(--accent); }

.rate-flag {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  background: var(--bg-alt);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  box-shadow: inset 0 0 0 1px var(--line);
}
.rate-flag .rate-flag-sep {
  font-size: .65rem;
  opacity: .55;
  margin: 0 .05em;
}
.rate-body {
  flex: 1 1 auto;
  min-width: 0;
}
.rate-card h2, .rate-card h3 {
  font-size: .82rem; margin: 0 0 .35rem; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.other-currencies > h2 {
  font-size: 1.05rem; margin: 0 0 .25rem; color: var(--text);
}
.rate-value {
  font-family: var(--mono); font-weight: 600;
  font-size: 1.75rem; margin: 0; line-height: 1.1;
  color: var(--text); letter-spacing: -.02em;
}
.rate-value small {
  display: inline-block; font-size: .55em; color: var(--muted);
  font-family: var(--font); font-weight: 500; margin-inline-start: .35em; letter-spacing: .03em;
}

/* ===== Converter ===== */
.converter {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem; margin: 1.75rem 0;
  box-shadow: var(--shadow-sm);
}
.converter h2 { margin: 0 0 1rem; font-size: 1.15rem; color: var(--text); }
.converter-form {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  gap: .75rem 1rem;
  align-items: end;
}
.converter-form label { display: flex; flex-direction: column; font-size: .78rem; color: var(--muted); gap: .3rem; }
.converter-form input, .converter-form select {
  font-size: 1rem; padding: .55rem .65rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fdfdfb; color: var(--text); min-width: 0;
}
.converter-form input:focus, .converter-form select:focus {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary);
}
.converter-form .arrow {
  grid-row: 2 / 3; grid-column: 2; align-self: center; text-align: center;
  font-size: 1.4rem; color: var(--muted); padding: .4rem;
  user-select: none;
}
.converter-form button {
  grid-column: 1 / -1;
  background: var(--primary); color: #fff;
  border: 0; padding: .7rem 1.5rem;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 1rem;
  cursor: pointer; transition: background .15s;
  margin-top: .5rem;
}
.converter-form button:hover { background: var(--primary-700); }
.converter-result {
  background: var(--primary-50);
  border: 1px solid color-mix(in srgb, var(--primary) 15%, transparent);
  padding: 1rem 1.25rem; border-radius: var(--radius-sm); margin-top: 1rem;
}
[dir="rtl"] .converter-result { background: var(--primary-50); }
.converter-result p { margin: .2rem 0; font-size: 1rem; }
.converter-result strong { font-family: var(--mono); color: var(--primary-700); font-weight: 700; }
.converter-result .note { color: var(--muted); font-size: .78rem; margin-top: .5rem; }

/* ===== Rate note / CTA ===== */
.rate-note {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
  margin: 1.5rem 0; box-shadow: var(--shadow-sm);
}
.cta-links {
  text-align: center; margin: 2rem 0;
  display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center;
}
.cta-links a {
  display: inline-block; padding: .55rem 1.25rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; color: var(--primary-700); font-weight: 600;
  font-size: .92rem; text-decoration: none;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.cta-links a:hover {
  background: var(--primary); color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px); box-shadow: var(--shadow);
  text-decoration: none;
}

/* ===== History ===== */
.range-tabs { display: flex; gap: .4rem; margin: 1.25rem 0; flex-wrap: wrap; }
.range-tabs a {
  padding: .45rem 1rem;
  border: 1px solid var(--line); border-radius: 999px;
  text-decoration: none; color: var(--text-soft);
  background: var(--card); font-size: .88rem; font-weight: 500;
  transition: all .15s;
}
.range-tabs a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.range-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 2px 6px rgba(11, 94, 63, .2); }

.chart-wrap {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
#rateChart { max-height: 420px; min-height: 300px; }

.history-table {
  width: 100%; border-collapse: collapse; margin: 1.25rem 0;
  font-size: .9rem; font-variant-numeric: tabular-nums;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden;
}
.history-table th, .history-table td {
  padding: .6rem .75rem; border-bottom: 1px solid var(--line); text-align: start;
}
.history-table thead th {
  background: var(--bg-alt); color: var(--text-soft);
  font-weight: 600; font-size: .82rem; letter-spacing: .03em; text-transform: uppercase;
}
.history-table tbody tr:last-child td { border-bottom: 0; }
.history-table tbody tr:hover { background: var(--primary-50); }
.history-table td time, .history-table td [data-num] { font-family: var(--mono); }

/* ===== Articles / static pages ===== */
.article {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 2rem clamp(1.25rem, 3vw, 2.5rem);
  line-height: 1.85; font-size: clamp(1rem, 1.15vw, 1.06rem);
  box-shadow: var(--shadow-sm);
  max-width: 760px; margin: 0 auto;
}
.article h1 {
  margin: 0 0 1.25rem; font-size: clamp(1.5rem, 3vw, 2rem);
  color: var(--text); font-weight: 700; letter-spacing: -.015em;
}
.article h2 {
  color: var(--primary-700); margin-top: 2rem; font-size: 1.25rem;
  border-bottom: 1px solid var(--line); padding-bottom: .35rem; font-weight: 700;
}
.article p { margin: .9rem 0; color: var(--text-soft); }
.article h2 + p { margin-top: 1rem; }
.lead { font-size: 1.15rem; color: var(--muted); font-style: normal; font-weight: 500; margin: 0 0 1.5rem; padding-inline-start: 1rem; border-inline-start: 3px solid var(--secondary); }

/* ===== Footer ===== */
.site-footer {
  background: var(--card); border-top: 1px solid var(--line);
  padding: 2rem 0 1.5rem; margin-top: 3rem;
}
.footer-cols {
  display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: 1.5rem;
  margin-bottom: 1.25rem;
}
.footer-cols > * { min-width: 0; }
.footer-nav { display: flex; flex-direction: column; gap: .35rem; }
.footer-nav-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; margin: 0 0 .5rem;
}
.footer-nav a {
  color: var(--text-soft); font-size: .9rem; text-decoration: none; padding: .1rem 0;
  border-bottom: 1px solid transparent; transition: border-color .15s;
}
.footer-nav a:hover { border-bottom-color: var(--primary); text-decoration: none; color: var(--primary-700); }
.footer-note { color: var(--muted); font-size: .82rem; margin: 0; padding-top: 1rem; border-top: 1px solid var(--line); }
.footer-copy { color: var(--muted); font-size: .8rem; margin: .5rem 0 0; }

/* ===== Page frame with ad slots ===== */
.page-frame {
  display: grid;
  grid-template-areas:
    "top top top"
    "left center right"
    "bottom bottom bottom";
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}
.page-center {
  grid-area: center;
  min-width: 0;
}

/* ===== AdSense slots ===== */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: repeating-linear-gradient(45deg, transparent 0, transparent 10px, color-mix(in srgb, var(--muted) 5%, transparent) 10px, color-mix(in srgb, var(--muted) 5%, transparent) 20px);
  text-align: center;
}
.ad-slot .ad-label {
  color: var(--muted); font-size: .72rem; letter-spacing: .04em;
  text-transform: uppercase; font-weight: 600;
}
.ad-top {
  grid-area: top;
  min-height: 90px;
  max-width: 970px;
  justify-self: center;
  width: 100%;
}
.ad-bottom {
  grid-area: bottom;
  min-height: 90px;
  max-width: 970px;
  justify-self: center;
  width: 100%;
}
.ad-left {
  grid-area: left;
  width: 160px;
  min-height: 600px;
  position: sticky; top: 5.5rem; align-self: start;
}
.ad-right {
  grid-area: right;
  width: 160px;
  min-height: 600px;
  position: sticky; top: 5.5rem; align-self: start;
}
.ad-header { margin: 0 0 1.5rem; }
.ad-infeed { margin: 2rem 0; }

/* ===== Admin ===== */
.admin { max-width: 720px; margin: 2rem auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.admin h1 { color: var(--primary-700); margin: 0 0 1rem; }
.admin .muted { color: var(--muted); font-size: .85rem; margin: 0 0 1.25rem; }
.admin-form { display: flex; flex-direction: column; gap: .85rem; }
.admin-form label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: .35rem; font-weight: 500; }
.admin-form input, .admin-form textarea {
  font-size: 1rem; padding: .6rem .75rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fdfdfb; color: var(--text); font-family: inherit;
}
.admin-form input:focus, .admin-form textarea:focus {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary);
}
.admin-form button {
  background: var(--primary); color: #fff;
  border: 0; padding: .8rem 1.25rem;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 1rem;
  cursor: pointer; align-self: flex-start; min-width: 140px;
  transition: background .15s;
}
.admin-form button:hover { background: var(--primary-700); }
.err { color: var(--danger); font-size: .9rem; padding: .5rem .75rem; background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: var(--radius-sm); margin: 0 0 1rem; }
.ok { color: var(--ok); font-size: .9rem; padding: .5rem .75rem; background: color-mix(in srgb, var(--ok) 8%, transparent); border-radius: var(--radius-sm); margin: 0 0 1rem; }

/* ===== Misc ===== */
.note { color: var(--muted); font-size: .82rem; margin: .25rem 0; }
.summary-note { color: var(--muted); font-size: .85rem; margin-top: .75rem; }

/* ===== Responsive ===== */
@media (max-width: 980px) {
  .page-frame {
    grid-template-areas:
      "top"
      "center"
      "left"
      "right"
      "bottom";
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .ad-left, .ad-right {
    min-height: 90px;
    position: static;
    justify-self: center;
    width: 100%;
    max-width: 970px;
  }
}
@media (max-width: 820px) {
  .footer-cols { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .header-row { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .topnav { font-size: .88rem; overflow-x: auto; flex-wrap: nowrap; width: 100%; padding-bottom: .25rem; }
  .topnav::-webkit-scrollbar { height: 0; }
  .hero h1 { font-size: 1.4rem; }
  .rate-card { gap: .75rem; padding: .85rem 1rem; }
  .rate-flag { width: 46px; height: 46px; font-size: 1.25rem; }
  .rate-value { font-size: 1.45rem; }
  .converter-form { grid-template-columns: 1fr; }
  .converter-form .arrow { display: none; }
  .article { padding: 1.25rem; }
  .article h1 { font-size: 1.35rem; }
  .article h2 { font-size: 1.1rem; }
  .footer-cols { grid-template-columns: 1fr; gap: 1rem; }
  .range-tabs a { padding: .35rem .8rem; font-size: .82rem; }
  #rateChart { min-height: 260px; }
}

/* Print-friendly */
@media print {
  .site-header, .site-footer, .ad-slot, .cta-links, .converter-form { display: none; }
  .article, .summary, .rate-card { box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; }
}

/* Focus visibility for keyboard users */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.topnav a:focus-visible, .footer-nav a:focus-visible { outline-offset: 1px; }