/* المكتبة النظامية — visual identity (web-build.md §6) */
:root {
  --bg: #F1F3F4; --surface: #FFFFFF; --surface-2: #E8EBEC;
  --ink: #10161B; --muted: #5C6771; --line: #D3D8DB;
  --accent: #2C5B4E; --accent-soft: #E3EDE9;
  --brass: #8A6A2F; --brass-soft: #F3EBDB; --danger: #8C3A34;
  --danger-soft: #F5E4E2;
  --radius: 10px;
  --f-head: "Noto Kufi Arabic", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-body: "IBM Plex Sans Arabic", system-ui, "Segoe UI", Tahoma, sans-serif;
  --f-mono: "IBM Plex Mono", "IBM Plex Sans Arabic", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1316; --surface: #161D21; --surface-2: #1F282D;
    --ink: #E6EAEC; --muted: #9AA6AE; --line: #2C373D;
    --accent: #6FB39F; --accent-soft: #1B302A;
    --brass: #D1AE6B; --brass-soft: #2E2616; --danger: #E08A82;
    --danger-soft: #3A1F1C;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: 17px; line-height: 1.85;
  overflow-wrap: anywhere;
}
h1, h2, h3, h4, .brand, .section-title { font-family: var(--f-head); line-height: 1.5; }
h1 { font-size: 1.6rem; margin: .4em 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.num, .mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; top: 8px; right: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 20px; padding-bottom: 48px; min-height: 60vh; }

/* Header / footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 60px; }
.brand { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nav a { text-decoration: none; }
.inline { display: inline; margin: 0; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.site-footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .9rem; padding: 20px 0; }
.footer-links a { color: var(--muted); }

/* Buttons & forms */
.btn { display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
  padding: 10px 20px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
@media (prefers-color-scheme: dark) { .btn { color: #0E1316; } }
.btn:hover { filter: brightness(1.08); }
.btn-small { padding: 4px 14px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 9px 12px; width: 100%; max-width: 100%; }
label { display: block; font-weight: 500; margin-bottom: 12px; }
label input, label select { margin-top: 4px; }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
.notice { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; }
.errors { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: 6px 14px; margin-bottom: 12px; }

/* Home */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-size: 2rem; }
.lead { color: var(--muted); max-width: 680px; margin: 0 auto 18px; }
.search-big { display: flex; gap: 8px; max-width: 760px; margin: 0 auto 10px; flex-wrap: wrap; }
.search-big input { flex: 1 1 260px; font-size: 1.1rem; padding: 14px 16px; }
.search-big select { flex: 0 1 180px; width: auto; }
.search-big .btn { flex: 0 0 auto; }
.hint { color: var(--muted); font-size: .92rem; }
.section-title { margin-top: 32px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 4px; }
.card:hover { border-color: var(--accent); }
.card-title { font-family: var(--f-head); font-weight: 700; }
.card-num { color: var(--accent); font-size: 1.3rem; }
.stats { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; background: var(--accent-soft);
  border-radius: var(--radius); padding: 14px; margin-top: 24px; font-weight: 600; }
.stats .num { color: var(--accent); font-size: 1.35rem; }
.svc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.svc-grid > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.svc-grid h3 { margin: 0 0 4px; }
.svc-grid p { margin: 0; color: var(--muted); }

/* Prose pages */
.prose { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; max-width: 820px; }
.prose blockquote { margin: 0 0 16px; padding: 10px 14px; background: var(--brass-soft); border-inline-start: 4px solid var(--brass); }
.prose blockquote p { margin: 0; }

/* Auth */
.auth { max-width: 460px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.consent { font-size: .88rem; color: var(--muted); text-align: center; margin: 10px 0 0; }

/* Badges */
.badge { display: inline-block; border-radius: 999px; padding: 0 10px; font-size: .82rem; font-weight: 600;
  line-height: 1.9; border: 1px solid currentColor; white-space: nowrap; }
.badge-ok { color: var(--accent); background: var(--accent-soft); }
.badge-amended { color: var(--brass); background: var(--brass-soft); }
.badge-repealed { color: var(--danger); background: var(--danger-soft); }
.badge-neutral { color: var(--muted); background: var(--surface-2); }
.tag { display: inline-block; background: var(--surface-2); color: var(--ink); border-radius: 6px; padding: 0 8px; font-size: .82rem; }

/* Lists */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.filters label { margin: 0; }
.law-list { list-style: none; padding: 0; margin: 0; }
.law-list > li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px; }
.law-list.compact > li { padding: 8px 14px; }
.law-name { font-weight: 600; text-decoration: none; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .9rem; margin-top: 4px; }
.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); text-decoration: none; }
.pager .current { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager .disabled { color: var(--muted); }

/* Law page */
.law-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.law-card h1 { margin-top: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 18px; margin: 12px 0 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0; }
.disclaimer { background: var(--brass-soft); border: 1px solid var(--brass); color: var(--ink); border-radius: var(--radius); padding: 8px 14px; margin: 14px 0; font-size: .92rem; }
.actions { margin: 0 0 14px; }
.law-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
.law-layout > .law-main:only-child { grid-column: 1 / -1; }
.toc { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-size: .9rem; }
.toc ul { list-style: none; padding-inline-start: 12px; margin: 4px 0; }
.toc > details > ul { padding-inline-start: 0; }
.toc summary { cursor: pointer; }
.toc-title { font-family: var(--f-head); font-weight: 700; }
.toc a { text-decoration: none; }
.struct { color: var(--accent); margin: 26px 0 8px; scroll-margin-top: 12px; }
.struct-1 { color: var(--ink); }
.struct-2 { color: var(--muted); }
.article { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; scroll-margin-top: 12px; }
.article-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.article-head h1 { margin: 0; }
.article-label { font-family: var(--f-head); font-weight: 700; text-decoration: none; }
.article-text { margin-top: 6px; }
.article-text.big { font-size: 1.08rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.doc-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-top: 12px; }
.crumbs { font-size: .9rem; margin-bottom: 6px; }
.alert { border-radius: var(--radius); padding: 10px 14px; margin: 14px 0; font-weight: 600; }
.alert-brass { background: var(--brass-soft); border: 1px solid var(--brass); color: var(--brass); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.compare-col h3 { margin: 0 0 6px; }
.timeline { margin-top: 28px; }
.tl-item { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; border-inline-start: 3px solid var(--brass); padding: 6px 12px; margin-bottom: 10px; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.tl-date { color: var(--brass); font-weight: 500; }
.tl-body details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.article-page { margin-bottom: 30px; }

/* Search */
.results { padding-inline-start: 22px; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
.result-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.result-text { margin: 6px 0 2px; }
mark { background: var(--brass-soft); color: inherit; border-bottom: 2px solid var(--brass); padding: 0 1px; }
.print-footer { display: none; }

/* Phones (360px and up) */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .law-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; max-height: none; }
  .compare { grid-template-columns: minmax(0, 1fr); }
  .row2 { grid-template-columns: 1fr; }
  .tl-item { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .hero h1 { font-size: 1.6rem; }
  .search-big select { flex: 1 1 100%; }
  .prose, .auth { padding: 16px; }
}

/* Print (web-build.md §7) */
@media print {
  @page { margin: 18mm 16mm 22mm; }
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #333; --line: #bbb; }
  body { background: #fff !important; color: #000; font-size: 12.5pt; line-height: 1.7; }
  .site-header, .site-footer, .nav, .no-print, .toc, .actions, .crumbs, .pager, .filters, .skip { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .article, .law-card, .doc-body, .article-text.big { border: 0; padding: 0; background: #fff; }
  .article { break-inside: avoid-page; margin-bottom: 8pt; }
  .struct.bab { break-before: page; }
  .print-first + .articles .struct.bab:first-child { break-before: auto; }
  .badge { border: 1px solid #000; color: #000 !important; background: #fff !important; }
  a { color: #000; text-decoration: none; }
  .print-first { border-bottom: 1px solid #000; margin-bottom: 12pt; }
  .print-footer { display: block; position: fixed; bottom: 0; left: 0; right: 0; font-size: 9pt; color: #333;
    border-top: 1px solid #999; padding-top: 3pt; text-align: center; background: #fff; }
  main { padding-bottom: 14mm; }
}
