/* ============================================================================
   Wawasan-Wawasan Perancangan Strategik Dakwah (Ru'an Takhtitiyyah) PWA
   Self-Hosted Amiri Fonts (Arabic + Latin 400/700 with exact unicode-range)
   Palette: Islamic Emerald (#065F46), Royal Navy (#132A3E), Warm Gold (#B45309)
   ============================================================================ */

@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/amiri-arabic-400.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+00AB, U+00BB;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('./fonts/amiri-arabic-700.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+00AB, U+00BB;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/amiri-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('./fonts/amiri-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f8f6f1;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --ink: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --emerald: #065f46;
  --emerald-soft: rgba(6, 95, 70, 0.10);
  --navy: #132a3e;
  --gold: #b45309;
  --gold-soft: rgba(180, 83, 9, 0.11);
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --reader-fs: 1.06rem;
  --font-ui: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-ar: 'Amiri', 'Traditional Arabic', serif;
}

[data-theme="dark"] {
  --bg: #0b131e;
  --surface: #111c2b;
  --surface-alt: #182538;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --border: #24354c;
  --emerald: #34d399;
  --emerald-soft: rgba(52, 211, 153, 0.14);
  --navy: #e2e8f0;
  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.14);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }

/* ── TOPBAR & NAV ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(135deg, #0b2434 0%, #064e3b 100%);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { border-radius: 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); flex-shrink: 0; }
.brand-ar {
  font-family: var(--font-ar);
  font-size: 1.25rem;
  font-weight: 700;
  color: #fde68a;
  line-height: 1.2;
}
.brand-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.10);
  color: inherit;
  border-radius: 8px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.20); }
.btn-install {
  border: none;
  background: #f59e0b;
  color: #111827;
  font-weight: 700;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.84rem;
}

.main-nav {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 14px 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.nav-tab {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-tab:hover { background: rgba(255, 255, 255, 0.18); }
.nav-tab.active {
  background: #fde68a;
  color: #132a3e;
  border-color: #fde68a;
  font-weight: 700;
}

/* ── MAIN CONTAINER ──────────────────────────────────────────────────────── */
.container {
  max-width: 1240px;
  margin: 18px auto 40px;
  padding: 0 16px;
}

.hero-card {
  background: linear-gradient(135deg, #132a3e 0%, #065f46 100%);
  color: #ffffff;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.hero-ar {
  font-family: var(--font-ar);
  font-size: 1.7rem;
  font-weight: 700;
  color: #fde68a;
  text-align: center;
  margin-bottom: 6px;
  line-height: 1.5;
}
.hero-sub {
  text-align: center;
  margin: 0 0 14px;
  font-size: 0.94rem;
  color: #e2e8f0;
}
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
}
.stat-pill {
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
}
.stat-pill strong { display: block; font-size: 1.15rem; color: #fde68a; }
.stat-pill span { font-size: 0.78rem; color: #e2e8f0; }

/* ── READER LAYOUT ───────────────────────────────────────────────────────── */
.reader-layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.sidebar-card {
  position: sticky;
  top: 112px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 130px);
  overflow-y: auto;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.badge-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
}
.search-box input, .input-ctrl, .select-ctrl {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
}
.search-results {
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-alt);
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
}
.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.search-hit:hover { background: var(--emerald-soft); }
.search-hit strong { display: block; color: var(--emerald); font-size: 0.78rem; }

.chapter-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.chapter-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.35;
}
.chapter-btn:hover { background: var(--surface-alt); }
.chapter-btn.active {
  background: var(--emerald-soft);
  border-color: var(--emerald);
  color: var(--emerald);
  font-weight: 700;
}
.chapter-btn small { display: block; font-size: 0.74rem; color: var(--muted); font-weight: 500; }

.reader-article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 28px;
  box-shadow: var(--shadow);
}
.article-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.subtopic-jump-wrap { flex: 1 1 240px; max-width: 420px; }
.toolbar-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-outline, .btn-primary {
  border-radius: 8px;
  padding: 7px 13px;
  font-weight: 600;
  font-size: 0.84rem;
  cursor: pointer;
}
.btn-outline {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--ink);
}
.btn-outline:hover { border-color: var(--emerald); color: var(--emerald); }
.btn-primary {
  border: none;
  background: var(--emerald);
  color: #ffffff;
}
[data-theme="dark"] .btn-primary { color: #052e16; font-weight: 700; }

.ch-title-block {
  border-bottom: 2px solid var(--emerald);
  padding-bottom: 10px;
  margin-bottom: 18px;
}
.ch-title-block h2 { margin: 0 0 4px; font-size: 1.55rem; color: var(--navy); }
.ch-title-ar {
  font-family: var(--font-ar);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--gold);
  direction: rtl;
  text-align: right;
}

.chapter-body { font-size: var(--reader-fs); line-height: 1.82; }
.chapter-body h3 {
  margin: 24px 0 10px;
  font-size: 1.2rem;
  color: var(--emerald);
  border-left: 4px solid var(--emerald);
  padding-left: 10px;
  scroll-margin-top: 120px;
}
.chapter-body h4 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
  color: var(--gold);
}
.chapter-body p {
  margin: 0 0 14px;
  text-align: justify;
}
.chapter-body blockquote {
  margin: 14px 0 16px;
  padding: 12px 18px;
  background: var(--gold-soft);
  border-left: 4px solid var(--gold);
  border-radius: 0 10px 10px 0;
  font-style: italic;
  color: var(--navy);
}
.fn-ref {
  border: none;
  background: var(--emerald-soft);
  color: var(--emerald);
  font-weight: 700;
  font-size: 0.74em;
  vertical-align: super;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 4px;
  cursor: pointer;
}
.fn-ref:hover { background: var(--emerald); color: #ffffff; }

.chapter-footnotes {
  margin-top: 26px;
  padding: 16px 18px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 4px solid var(--emerald);
  border-radius: 10px;
}
.chapter-footnotes h4 { margin: 0 0 10px; color: var(--emerald); font-size: 0.96rem; }
.fn-item { margin: 0 0 8px; font-size: 0.88rem; line-height: 1.55; }
.fn-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  margin-right: 4px;
}
.fn-tag.penulis { background: var(--gold-soft); color: var(--gold); }
.fn-tag.penterjemah { background: var(--emerald-soft); color: var(--emerald); }

.article-footer-nav {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* ── SECTION HEADERS & GRIDS ─────────────────────────────────────────────── */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.section-head h2 { margin: 0; font-size: 1.35rem; color: var(--navy); }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-row .select-ctrl, .filter-row .input-ctrl { width: auto; min-width: 210px; }

.exec-card, .uf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.exec-pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.pillar-item {
  background: var(--surface-alt);
  border-left: 4px solid var(--emerald);
  border-radius: 10px;
  padding: 12px 14px;
}
.pillar-item strong { display: block; color: var(--emerald); margin-bottom: 4px; font-size: 0.93rem; }
.pillar-item p { margin: 0; font-size: 0.87rem; }

.summaries-grid { display: grid; gap: 12px; }
.sum-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.sum-meta { font-size: 0.76rem; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.03em; }
.sum-card h3 { margin: 3px 0 8px; font-size: 1.04rem; color: var(--navy); }
.sum-card p { margin: 0; font-size: 0.92rem; }
.sum-kps { margin: 8px 0 0; padding-left: 18px; font-size: 0.87rem; color: var(--muted); }

/* ── QUOTES (28 MUTIARA KATA) ────────────────────────────────────────────── */
.quotes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}
.quote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quote-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.quote-head strong { color: var(--navy); font-size: 0.96rem; }
.quote-ch { font-size: 0.74rem; color: var(--emerald); font-weight: 700; white-space: nowrap; }
.quote-ar {
  font-family: var(--font-ar);
  font-size: 1.48rem;
  line-height: 1.95;
  direction: rtl;
  text-align: right;
  color: var(--navy);
  background: var(--gold-soft);
  padding: 12px 14px;
  border-radius: 10px;
}
.quote-ms { margin: 0; font-style: italic; font-size: 0.93rem; color: var(--ink); flex: 1; }
.quote-copy {
  align-self: flex-end;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.quote-copy:hover { border-color: var(--emerald); color: var(--emerald); }

/* ── GLOSSARY (30 ISTILAH) ───────────────────────────────────────────────── */
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 12px;
}
.gl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.gl-ar {
  font-family: var(--font-ar);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--emerald);
  direction: rtl;
  text-align: right;
  line-height: 1.5;
}
.gl-tr { font-weight: 700; color: var(--navy); font-size: 0.96rem; }
.gl-std {
  display: inline-block;
  margin: 4px 0 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
}
.gl-ctx { margin: 0; font-size: 0.88rem; color: var(--muted); }

/* ── UF & PBI TABLES ─────────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; margin-top: 10px; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th {
  background: #132a3e;
  color: #ffffff;
  text-align: left;
  padding: 10px 12px;
  font-size: 0.84rem;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:nth-child(even) td { background: var(--surface-alt); }

.pbi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.pbi-chip {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
  padding: 10px 13px;
}
.pbi-chip strong { display: block; color: var(--navy); font-size: 0.9rem; margin-bottom: 4px; }
.pbi-chip p { margin: 0; font-size: 0.84rem; color: var(--muted); }

/* ── QUIZ ────────────────────────────────────────────────────────────────── */
.score-pill {
  background: var(--emerald-soft);
  color: var(--emerald);
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
}
.quiz-list { display: grid; gap: 14px; }
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.quiz-q { margin: 0 0 12px; font-weight: 700; color: var(--navy); font-size: 0.98rem; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opt {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 13px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}
.quiz-opt:hover:not([disabled]) { border-color: var(--emerald); }
.quiz-opt.correct { background: rgba(16, 185, 129, 0.16); border-color: #059669; color: #065f46; font-weight: 700; }
.quiz-opt.wrong { background: rgba(239, 68, 68, 0.14); border-color: #dc2626; color: #b91c1c; }
[data-theme="dark"] .quiz-opt.correct { color: #6ee7b7; }
[data-theme="dark"] .quiz-opt.wrong { color: #fca5a5; }
.quiz-exp {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--emerald-soft);
  font-size: 0.86rem;
}

/* ── DOWNLOAD STRIP & FOOTNOTES MASTER ───────────────────────────────────── */
.download-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.dl-card {
  display: block;
  text-decoration: none;
  background: linear-gradient(135deg, #065f46 0%, #132a3e 100%);
  color: #ffffff;
  border-radius: var(--radius);
  padding: 15px 18px;
  box-shadow: var(--shadow);
}
.dl-card strong { display: block; font-size: 0.96rem; color: #fde68a; margin-bottom: 4px; }
.dl-card span { font-size: 0.82rem; color: #e2e8f0; }

.fn-master-list { display: grid; gap: 8px; }
.fn-row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.9rem;
}

/* ── DIALOG & TOAST ──────────────────────────────────────────────────────── */
.fn-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  max-width: 520px;
  width: calc(100% - 32px);
  padding: 0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.fn-dialog::backdrop { background: rgba(15, 23, 42, 0.55); }
.fn-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.fn-dialog-body { padding: 16px; }
.fn-dialog-body p { margin: 10px 0 8px; font-size: 0.96rem; line-height: 1.6; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  background: #132a3e;
  color: #fde68a;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.86rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.site-footer {
  text-align: center;
  padding: 20px 16px 32px;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
}
.site-footer p { margin: 3px 0; }

@media (max-width: 880px) {
  .reader-layout { grid-template-columns: 1fr; }
  .sidebar-card { position: static; max-height: none; }
  .reader-article { padding: 16px; }
  .quotes-grid { grid-template-columns: 1fr; }
}
