/* ديوان الأنظمة — ivory / deep navy / olive-gold, scholarly library feel.
   Law text in Naskh (official voice), everything else IBM Plex Sans Arabic. */
:root {
  --paper: #faf8f2;      /* ivory */
  --paper-2: #f2efe6;    /* deeper ivory for panels */
  --ink: #1b2537;        /* deep navy ink */
  --ink-soft: #4a5468;
  --ink-faint: #8a90a0;
  --navy: #22304a;       /* headers, nav */
  --olive: #6d6a3f;      /* olive accent */
  --gold: #a98f4d;       /* calm gold */
  --gold-faint: #a98f4d33;
  --line: #ddd7c7;
  --line-strong: #c4bca6;
  --ok: #3e6b4f;
  --warn: #8a5a2d;
  --danger: #8c3a36;
  --radius: 3px;
  --sans: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --naskh: "Noto Naskh Arabic", serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.8;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: var(--navy); color: #eee9da;
  border-bottom: 3px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  font-family: var(--naskh); font-size: 26px; font-weight: 600;
  border: 1.5px solid var(--gold); color: var(--gold); border-radius: var(--radius);
}
.brand-text { font-weight: 600; font-size: 18px; line-height: 1.3; }
.brand-text small { display: block; font-weight: 300; font-size: 12px; color: #c9c2ac; }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a {
  color: #d8d2bf; text-decoration: none; padding: 7px 14px; font-size: 14.5px;
  border-bottom: 2px solid transparent;
}
.topnav a:hover { color: #fff; }
.topnav a.active { color: var(--gold); border-bottom-color: var(--gold); }

main { min-height: 72vh; padding: clamp(20px, 4vw, 44px) clamp(16px, 4vw, 48px); max-width: 1240px; margin: 0 auto; }
.foot {
  padding: 20px clamp(16px, 4vw, 48px); border-top: 1px solid var(--line);
  color: var(--ink-faint); font-size: 13px; max-width: 1240px; margin: 0 auto;
}
.loading { color: var(--ink-faint); padding: 48px 0; text-align: center; }

/* ---------- library ---------- */
.page-head { margin: 0 0 8px; }
.page-head h1 { font-size: 26px; font-weight: 600; margin: 0; }
.page-head p { color: var(--ink-soft); margin: 4px 0 0; font-size: 15px; }
.rule { border: 0; border-top: 1px solid var(--line-strong); margin: 20px 0 28px; }

.law-list { display: flex; flex-direction: column; }
.law-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 20px;
  padding: 22px 4px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
}
.law-row:hover { background: var(--paper-2); }
.law-row .t { font-size: 19px; font-weight: 600; font-family: var(--naskh); }
.law-row .meta { color: var(--ink-soft); font-size: 13.5px; margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }
.law-row .counts { color: var(--ink-faint); font-size: 13.5px; white-space: nowrap; }
.law-kind { font-size: 12px; color: var(--olive); border: 1px solid var(--olive); padding: 1px 8px; border-radius: var(--radius); margin-inline-start: 10px; vertical-align: 3px; }
.status { font-size: 12.5px; }
.status.ساري { color: var(--ok); }
.status:not(.ساري) { color: var(--warn); }

/* ---------- law page: sidebar + content ---------- */
.law-layout { display: grid; grid-template-columns: 300px 1fr; gap: clamp(20px, 3vw, 44px); align-items: start; }
@media (max-width: 880px) { .law-layout { grid-template-columns: 1fr; } }
.toc {
  position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 0; font-size: 14px;
}
@media (max-width: 880px) { .toc { position: static; max-height: 300px; } }
.toc .bab > button {
  all: unset; display: flex; justify-content: space-between; width: calc(100% - 28px);
  padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--navy); font-size: 13.5px;
}
.toc .bab > button:hover { color: var(--gold); }
.toc .bab > button .tw { transition: transform .15s; color: var(--ink-faint); }
.toc .bab.open > button .tw { transform: rotate(90deg); }
.toc .fasl { display: none; }
.toc .bab.open .fasl { display: block; }
.toc .fasl a {
  display: block; padding: 6px 26px 6px 14px; color: var(--ink-soft);
  text-decoration: none; border-inline-start: 2px solid transparent;
}
.toc .fasl a:hover { color: var(--ink); background: #ece8db; }
.toc .fasl a.current { border-inline-start-color: var(--gold); color: var(--ink); font-weight: 500; }
.toc-search { margin: 0 14px 10px; }
.toc-search input { width: 100%; }

.law-header h1 { font-family: var(--naskh); font-size: 28px; margin: 0 0 4px; font-weight: 600; }
.law-header .sub { color: var(--ink-soft); font-size: 14px; display: flex; gap: 16px; flex-wrap: wrap; }
.law-tools { display: flex; gap: 8px; margin: 14px 0 6px; flex-wrap: wrap; }

.fasl-head { margin: 34px 0 6px; }
.fasl-head .bab-name { color: var(--olive); font-size: 13.5px; font-weight: 500; }
.fasl-head h2 { font-family: var(--naskh); font-size: 21px; margin: 2px 0 0; font-weight: 600; }

/* ---------- article ---------- */
.article { padding: 26px 0 8px; border-bottom: 1px solid var(--line); }
.art-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.art-num { font-weight: 600; color: var(--navy); font-size: 16.5px; }
.art-src { font-size: 12px; color: var(--ink-faint); }
.art-text {
  font-family: var(--naskh); font-size: 19px; line-height: 2.15;
  margin: 10px 0 4px; white-space: pre-line; max-width: 75ch;
}
.amended {
  margin: 10px 0 0; padding: 10px 14px; background: #f5f1e2; border-inline-start: 3px solid var(--gold);
  font-size: 13.5px; color: var(--ink-soft);
}
.amended .cur { font-family: var(--naskh); font-size: 17px; line-height: 2; color: var(--ink); white-space: pre-line; margin-top: 6px; }
.art-actions { display: flex; gap: 8px; margin: 14px 0 10px; flex-wrap: wrap; }

button, .btn {
  font-family: var(--sans); font-size: 13.5px; cursor: pointer;
  background: transparent; color: var(--navy);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 7px 16px; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--gold); color: var(--olive); }
button.primary, .btn.primary { background: var(--navy); color: #eee9da; border-color: var(--navy); }
button.primary:hover { background: #2d3d5e; color: #fff; }
button.quiet { border-color: transparent; color: var(--ink-soft); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: wait; }
.fav-on { color: var(--gold); border-color: var(--gold); }

/* ---------- explanation ---------- */
.expl { margin: 6px 0 18px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.expl-sec { padding: 18px 22px; border-bottom: 1px solid var(--line); }
.expl-sec:last-child { border-bottom: 0; }
.expl-sec h3 {
  margin: 0 0 8px; font-size: 15px; font-weight: 600; color: var(--olive);
  display: flex; align-items: center; gap: 10px;
}
.expl-sec h3::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.expl-sec .body { white-space: pre-line; font-size: 15px; color: var(--ink); max-width: 80ch; }
.expl-meta { padding: 8px 22px; font-size: 12px; color: var(--ink-faint); background: var(--paper-2); }
.badge-ai { font-size: 11.5px; color: var(--warn); border: 1px dashed var(--warn); padding: 0 8px; border-radius: var(--radius); }

/* linked regulation articles */
.linked { margin: 10px 0 16px; }
.linked h4 { font-size: 14px; color: var(--olive); margin: 0 0 4px; }
.linked-item { border-inline-start: 3px solid var(--olive); background: var(--paper-2); padding: 10px 14px; margin: 8px 0; }
.linked-item .ln { font-size: 13px; font-weight: 600; color: var(--navy); }
.linked-item .lt { font-family: var(--naskh); font-size: 16px; line-height: 2; white-space: pre-line; }
.linked-item a { font-size: 12.5px; color: var(--olive); }

/* ---------- quiz ---------- */
.quiz { margin: 8px 0 18px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); }
.quiz .q { padding: 16px 22px; border-bottom: 1px solid var(--line); }
.quiz .q:last-child { border-bottom: 0; }
.quiz .qt { font-weight: 500; margin-bottom: 10px; }
.quiz .qtype { font-size: 11.5px; color: var(--ink-faint); margin-inline-start: 8px; }
.quiz .opt {
  display: block; width: 100%; text-align: start; margin: 5px 0; padding: 8px 14px;
  background: var(--paper); border: 1px solid var(--line);
}
.quiz .opt:hover { border-color: var(--gold); }
.quiz .opt.correct { border-color: var(--ok); color: var(--ok); font-weight: 600; background: #eef3ee; }
.quiz .opt.wrong { border-color: var(--danger); color: var(--danger); background: #f6ecec; }
.quiz .why { margin-top: 10px; padding: 10px 14px; background: var(--paper-2); font-size: 14px; white-space: pre-line; display: none; }
.quiz .why.show { display: block; }
.quiz-score { padding: 14px 22px; font-weight: 600; color: var(--navy); }

/* ---------- pager ---------- */
.pager { display: flex; justify-content: space-between; gap: 10px; margin: 20px 0; }

/* ---------- search ---------- */
.search-box { display: flex; gap: 10px; margin: 18px 0; flex-wrap: wrap; }
.search-box input[type=text], .search-box select { flex: 1; min-width: 200px; }
input[type=text], input[type=number], select, textarea {
  font-family: var(--sans); font-size: 15px; padding: 9px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 1px;
}
.result { padding: 16px 4px; border-bottom: 1px solid var(--line); }
.result .rn { font-weight: 600; color: var(--navy); font-size: 15px; }
.result .rn small { color: var(--olive); font-weight: 400; }
.result .rt { font-family: var(--naskh); font-size: 16.5px; line-height: 2; color: var(--ink-soft); }
mark { background: var(--gold-faint); color: inherit; padding: 0 1px; }

.ask-panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin: 22px 0; }
.ask-panel h2 { margin: 0 0 4px; font-size: 18px; }
.ask-panel .hint { color: var(--ink-faint); font-size: 13.5px; margin: 0 0 12px; }
.ask-row { display: flex; gap: 10px; }
.ask-row input { flex: 1; }
.answer { margin-top: 16px; white-space: pre-line; border-top: 1px solid var(--line); padding-top: 14px; max-width: 80ch; }
.answer-src { margin-top: 10px; font-size: 13px; }
.answer-src a { color: var(--olive); margin-inline-end: 12px; }

/* ---------- manage ---------- */
.mgr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.panel h2 { margin: 0 0 10px; font-size: 17px; }
.panel label { display: block; font-size: 13px; color: var(--ink-soft); margin: 10px 0 3px; }
.panel .row { display: flex; gap: 10px; }
.msg { padding: 10px 14px; margin: 10px 0; font-size: 14px; border-radius: var(--radius); }
.msg.ok { background: #eef3ee; color: var(--ok); }
.msg.err { background: #f6ecec; color: var(--danger); }

/* modal-less editing */
.edit-area textarea { min-height: 160px; font-family: var(--naskh); font-size: 17px; line-height: 2; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .top { flex-direction: column; align-items: flex-start; gap: 8px; }
  .art-text { font-size: 17.5px; }
  .pager { flex-direction: column; }
}
