/* ---------- Font bawaan (dibundel, dipakai bila tidak terpasang di komputer) ---------- */
@font-face {
  font-family: "KFGQPC Uthman Taha Naskh";
  font-weight: 400;
  src: local("KFGQPC Uthman Taha Naskh"), local("KFGQPC_Uthman_Taha_Naskh_H"),
       url("fonts/UthmanTN1Ver10.ttf") format("truetype");
}
@font-face {
  font-family: "KFGQPC Uthman Taha Naskh";
  font-weight: 700;
  src: local("KFGQPC Uthman Taha Naskh Bold"), local("KFGQPC_Uthman_Taha_Naskh_HB"),
       url("fonts/UthmanTN1BVer10.ttf") format("truetype");
}
/* Font mushaf KFGQPC (rasm Utsmani lengkap: tanda waqaf, sukun kepala, alif washal); lisensi bebas pakai & sebar */
@font-face {
  font-family: "KFGQPC HAFS Uthmanic Script";
  font-weight: 400;
  src: url("fonts/UthmanicHafs_V22.ttf") format("truetype");
  font-display: swap;
  /* tanpa tanda baca Arab (، ؛ ؟ ۔): font mushaf ini menggambarnya sebagai bulatan hitam bergerigi.
     Angka tetap dari font ini = bulatan nomor ayat (di isi kitab); halaman 1–2 memakai "Angka Biasa" di bawah. */
  unicode-range: U+0000-060B, U+060D-061A, U+061C-061E, U+0620-06D3, U+06D5-10FFFF;
}
/* Angka Arab biasa (bukan bulatan nomor ayat) untuk halaman sampul & identitas */
@font-face {
  font-family: "Angka Biasa";
  src: url("fonts/UthmanTN1Ver10.ttf") format("truetype");
  unicode-range: U+0660-066D, U+06F0-06F9;
}
@font-face {
  font-family: "Aref Ruqaa";
  font-weight: 400;
  src: local("Aref Ruqaa"), local("ArefRuqaa-Regular"), url("fonts/ArefRuqaa-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Aref Ruqaa";
  font-weight: 700;
  src: local("Aref Ruqaa Bold"), local("ArefRuqaa-Bold"), url("fonts/ArefRuqaa-Bold.ttf") format("truetype");
}
/* Amiri (naskh) dengan versi miring asli: pilihan huruf makna & kedudukan */
@font-face {
  font-family: "Amiri";
  font-style: normal;
  src: local("Amiri"), local("Amiri-Regular"), url("fonts/Amiri-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Amiri";
  font-style: italic;
  src: local("Amiri Italic"), local("Amiri-Italic"), url("fonts/Amiri-Italic.ttf") format("truetype");
}
/* Noto Nastaliq Urdu: gaya nasta'liq (miring alami), pilihan huruf makna & kedudukan */
/* versi statis (bukan font variabel): tercetak ke PDF sebagai font biasa, jauh lebih cepat & kecil */
@font-face {
  font-family: "Noto Nastaliq Urdu";
  font-weight: 400;
  src: url("fonts/NotoNastaliqUrdu-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Noto Nastaliq Urdu";
  font-weight: 700;
  src: url("fonts/NotoNastaliqUrdu-Bold.ttf") format("truetype");
}
/* Cadangan untuk huruf pegon yang tidak ada di Aref Ruqaa (mis. ࢴ ڟ ڮ ۑ) */
@font-face {
  font-family: "Scheherazade New";
  font-weight: 400;
  src: local("Scheherazade New"), local("ScheherazadeNew-Regular"), url("fonts/ScheherazadeNew-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Scheherazade New";
  font-weight: 700;
  src: local("Scheherazade New Bold"), local("ScheherazadeNew-Bold"), url("fonts/ScheherazadeNew-Bold.ttf") format("truetype");
}

:root {
  --bg: #f4f1ea;
  --paper: #ffffff;
  --ink: #1d1a16;
  --muted: #6b645a;
  --line: #d9d2c4;
  --accent: #0f6b5c;
  --accent-soft: #e0f0ec;
  --danger: #a33a2a;

  /* Diisi dari app.js sesuai pengaturan kitab. Satuan pt seperti di Word. */
  --font-ar: "KFGQPC Uthman Taha Naskh";
  --font-mk: "Aref Ruqaa";
  --font-kd: "Aref Ruqaa";
  --font-hf: "Amiri";
  --ar-size: 18pt;
  --mk-size: 8pt;
  --kd-size: 8pt;
  --kd-gap: 0pt;       /* geser kedudukan dari puncak huruf; negatif = makin turun/menempel */
  --mk-gap: -4pt;      /* jarak makna ke lafal; negatif = naik merapat ke bawah huruf */
  --hf-size: 10pt;
  --ar-color: #000;
  --mk-ink: #000;
  --kd-ink: #000;
  --hf-color: #000;
  --mk-style: italic;
  --kd-style: italic;
  --angle: 28;
  --gap: 40pt;       /* jarak bawah kata bermakna (menentukan jarak baris) */
  --gap-empty: 6pt;  /* jarak bawah kata tanpa makna */
  --space: 0pt;
  --nz-gap: 10pt;    /* jarak tanda tengah bait nadzom ke tiap syathar */
  --nz-ar-size: 18pt; /* ukuran lafal di bait nadzom (diisi app.js; bawaan = ukuran lafal) */
  --hd-gap: 14pt;     /* judul bab: spasi di atas */
  --hd-ar-size: 18pt; /* judul bab: ukuran lafal (bawaan = ukuran lafal) */
  --hd-weight: 400;

  --paper-w: 210mm;
  --paper-h: 297mm;
  --m-top: 25mm;
  --m-right: 20mm;
  --m-bottom: 25mm;
  --m-left: 20mm;
  --hf-top-gap: 3mm;
  --hf-bot-gap: 3mm;

  --font-ui: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  --fallback-ar: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
  --fallback-mk: "Scheherazade New", "Amiri", "Traditional Arabic", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  padding-bottom: 320px;
}

button, .btn, select {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  min-height: 34px;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button.icon { font-size: 20px; line-height: 1; padding: 2px 10px; }
.grow { flex: 1; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint code { background: #f1ede4; padding: 0 4px; border-radius: 3px; }
.check { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Sidebar (menu tetap di kiri) ---------- */
:root { --sidebar-w: 224px; }
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px 12px 20px;
}
.sb-brand {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 17px; color: var(--accent); padding: 0 4px;
}
.sb-group { display: flex; flex-direction: column; gap: 4px; }
.sb-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 4px 2px; }
.sidebar button, .sidebar .btn { width: 100%; justify-content: flex-start; text-align: left; }
.sidebar a.btn { text-decoration: none; }
.sb-check { padding: 4px 6px; font-size: 13px; cursor: pointer; }
.sb-brand span { white-space: nowrap; }
.sb-brand button { width: auto; min-height: 0; }
.only-mobile { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
.backdrop[hidden] { display: none; }

.main { margin-left: var(--sidebar-w); min-width: 0; }

/* Bar atas: hanya pilihan kitab + status simpan, supaya tidak ada tombol yang berpindah */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.topbar-label { color: var(--muted); font-size: 13px; }
#docSelect { flex: 1; min-width: 0; max-width: 420px; }
#kelasSelect { flex: 0 1 auto; min-width: 0; max-width: 140px; }
.undo-btns { display: inline-flex; gap: 4px; }
.undo-btns button { padding: 0 8px; min-width: 34px; justify-content: center; }
.undo-btns button:disabled { opacity: .35; cursor: default; border-color: var(--line); }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 9em; }
.save-status.ok { color: var(--accent); }
.save-status.busy { color: #8a6d1d; }
.save-status.err { color: var(--danger); font-weight: 600; }

/* ---------- Panel pengaturan (panel geser di kanan) ---------- */
.settings {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 45;
  width: min(440px, 100vw);
  display: flex; flex-direction: column; gap: 10px;
  padding: 0 16px 16px;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(0,0,0,.12);
  overflow-y: auto;
}
.settings[hidden] { display: none; }
.settings-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0 8px; margin: 0 -16px 0; padding-left: 16px; padding-right: 10px;
  background: #fff; border-bottom: 1px solid var(--line);
  font-size: 16px;
}
.settings fieldset {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px 10px; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.settings legend { font-weight: 600; color: var(--accent); padding: 0 4px; }
.settings label { display: flex; align-items: center; gap: 8px; }
.settings input[type=range] { flex: 1; min-width: 80px; touch-action: pan-y; } /* gulir vertikal tidak menggeser slider */
.settings input.num { width: 64px; font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; }
.settings label { flex-wrap: wrap; }
.settings .font-input, .settings .hf-input { flex: 1; min-width: 140px; }
.settings input[type=number] { width: 64px; font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; }
.settings input[type=color] { width: 36px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; }
.settings output { min-width: 2.5em; color: var(--muted); }
.font-input, .hf-input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; width: 180px; }
.hf-input { font-family: "Amiri", var(--font-ui); font-size: 15px; }
.cv-input { font-family: "Amiri", var(--font-ui); font-size: 15px; }
textarea.cv-input { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; resize: vertical; line-height: 1.6; }
.margins { display: grid; grid-template-columns: auto auto; gap: 4px 12px; }
.margins > span { grid-column: 1 / -1; }
.margins label { justify-content: space-between; }
.hf-img { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hf-img img { max-height: 36px; max-width: 160px; border: 1px solid var(--line); background: #fff; }
.ornaments { display: flex; flex-wrap: wrap; gap: 3px; }
.ornaments button { font-family: "Amiri", "Segoe UI Symbol", serif; font-size: 18px; min-width: 34px; padding: 0 6px; justify-content: center; }
.settings-actions { display: flex; align-items: center; gap: 6px; }

/* ---------- Halaman ---------- */
.desk { overflow-x: auto; padding: 24px 16px; }
.page {
  position: relative;
  width: var(--paper-w);
  min-height: var(--paper-h);
  margin: 0 auto;
  padding: var(--m-top) var(--m-right) var(--m-bottom) var(--m-left);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
body.fit .desk { padding: 8px; overflow: visible; }
body.fit .page {
  width: auto; min-height: 0;
  padding: 8px 12px 24px;
  border-radius: 6px;
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Pratinjau header/footer di layar (saat cetak diganti margin box @page) */
.hf-preview {
  position: absolute; left: var(--m-left); right: var(--m-right);
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px;
  direction: ltr; /* kolom kiri | tengah | kanan tetap di tempatnya meski halaman rtl (teks tiap kolom dir=auto) */
  font-family: var(--font-hf), var(--fallback-ar);
  font-size: var(--hf-size); color: var(--hf-color);
  pointer-events: none;
}
.hf-preview[hidden] { display: none; }
.hf-preview > span { min-width: 0; overflow: hidden; white-space: nowrap; }
.hf-preview > span:nth-child(1) { text-align: left; }
.hf-preview > span:nth-child(2) { text-align: center; }
.hf-preview > span:nth-child(3) { text-align: right; }
.hf-preview img { display: block; margin: 0 auto; }
/* --hf-line-gap: jarak garis header/footer ke isi halaman (sama dengan margin box @page di app.js) */
.hf-top { top: 0; height: calc(var(--m-top) - var(--hf-line-gap, 3mm)); align-items: end; padding-bottom: var(--hf-top-gap); }
.hf-top.line { border-bottom: 0.5pt solid var(--hf-color); }
.hf-bottom { bottom: 0; height: calc(var(--m-bottom) - var(--hf-line-gap, 3mm)); align-items: start; padding-top: var(--hf-bot-gap); }
.hf-bottom.line { border-top: 0.5pt solid var(--hf-color); }
/* Gaya garis "ornamen": garis ganda berukir (gambar) selebar isi halaman */
.hf-top.line.orn { border-bottom: 0; padding-bottom: calc(var(--hf-top-gap) + var(--orn-h, 2mm)); background: url("img/garis-ornamen.png") center bottom / 100% auto no-repeat; }
.hf-bottom.line.orn { border-top: 0; padding-top: calc(var(--hf-bot-gap) + var(--orn-h, 2mm)); background: url("img/garis-ornamen-bawah.png") center top / 100% auto no-repeat; }
body.fit .hf-preview { position: static; height: auto; padding: 4px 0; margin: 0 0 8px; }
body.fit .hf-bottom { margin: 12px 0 0; }

/* Teks: paragraf rata kanan-kiri, kata dipisah spasi biasa seperti di Word */
.text { direction: rtl; }
.para {
  text-align: justify;
  text-align-last: auto;
  word-spacing: var(--space);
  font-family: var(--font-ar), var(--fallback-ar);
  font-size: var(--ar-size);
  line-height: 1;
  margin: 0 0 4pt;
}
/* Kitab panjang, tampilan layar (satu aliran): paragraf yang jauh dari layar tidak ditata & digambar
   sampai digulir mendekat. content-visibility memotong gambar di tepi paragraf, jadi kotak paragraf
   dilebarkan (padding) lalu ditarik kembali (margin negatif) supaya stroke makna di tepi tidak terpotong.
   Di tampilan kertas yang dilewati adalah lembar utuh (lihat .sheet). */
@media screen {
  body.fit .para {
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
    padding: 0 12px 20pt;
    margin: 0 -12px -16pt;
  }
}
/* Paragraf rata tengah (token pertama al='c', dari perataan di Word) */
.para.ctr { text-align: center; text-align-last: center; }
/* Paragraf prosa yang terpotong di dasar lembar: baris terakhir potongan depan tetap rata penuh */
.para.split { text-align-last: justify; }

/* ---------- Tampilan kertas: lembar per halaman ---------- */
.sheet {
  position: relative;
  width: var(--paper-w);
  height: var(--paper-h);
  margin: 0 auto 28px;
  padding: var(--m-top) var(--m-right) var(--m-bottom) var(--m-left);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.sheet-body { height: 100%; box-sizing: border-box; }
/* Saat dicetak, Chrome menata huruf sedikit lebih lebar daripada di layar sehingga sebagian baris prosa
   terlipat lebih awal dan isi lembar meluber ke halaman baru. Di layar (dan lembar ukur) isi dibuat
   sedikit lebih sempit; saat cetak lebar penuh dipakai, jadi selalu ada sisa ruang. */
@media screen {
  .sheet-body { margin: 0 2mm; }
  /* bait nadzom & tabel tidak dilipat ulang oleh peramban (tata letaknya diatur sendiri): pakai lebar penuh */
  .sheet-body > .para.nz, .sheet-body > .para.tbl { margin-left: -2mm; margin-right: -2mm; }
}
.sheet::before { /* nomor lembar di layar (tidak ikut cetak); di dalam kotak karena content-visibility memotong luar kotak */
  content: "Hal. " attr(data-page);
  position: absolute; top: 4px; left: 6px;
  font: 11px var(--font-ui); color: var(--muted);
}
@media screen {
  .sheet { content-visibility: auto; } /* lembar yang jauh dari layar tidak digambar */
  /* Layar sempit (HP): lembar diperkecil agar muat selebar layar; --sheet-zoom dihitung fitSheets() di app.js */
  .sheet:not(.measuring) { zoom: var(--sheet-zoom, 1); }
  .sheet::before { font-size: calc(11px / var(--sheet-zoom, 1)); } /* nomor lembar tetap terbaca */
  /* lembar ukur: tersembunyi, tidak memakan tempat, tetapi tetap ditata (lebar isi sama) */
  .sheet.measuring { content-visibility: visible; position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; }
}
/* Halaman 1: sampul berbingkai lengkung (SVG .cv-art) memenuhi kertas; isi diskala --cv-scale (lebar/148mm) */
.sheet.cover { padding: 0; overflow: hidden; }
.sheet.cover::before { z-index: 2; }
.cv-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.cv-in {
  position: absolute; left: 20%; right: 20%; top: 0; bottom: 0;
  direction: rtl; text-align: center; color: #231f20;
  font-family: "Angka Biasa", var(--font-ar), var(--fallback-ar);
}
.cv-in > * { position: absolute; left: 0; right: 0; }
.cv-title {
  top: 12%; height: 22%; display: flex; align-items: center; justify-content: center;
  font-family: var(--cv-font, "Aref Ruqaa"), var(--fallback-ar); font-weight: 700;
  font-size: calc(40pt * var(--cv-scale, 1)); line-height: 1.25;
}
.cv-sub { top: 37%; font-size: calc(11pt * var(--cv-scale, 1)); line-height: 1.9; }
.cv-orn { top: 52%; font-family: "Segoe UI Symbol", serif; font-size: calc(8pt * var(--cv-scale, 1)); letter-spacing: 2pt; }
.cv-foot { top: 57%; font-size: calc(11pt * var(--cv-scale, 1)); line-height: 1.9; }
.cv-logo { top: 76%; margin: 0 auto; max-width: 100%; object-fit: contain; }
/* Gaya "mihrab": judul di dalam jendela mihrab (lengkung runcing), logo di bawah alas mihrab */
.cv-mihrab .cv-in { left: 21%; right: 21%; }
.cv-mihrab .cv-title { top: 27%; height: 19%; font-size: calc(38pt * var(--cv-scale, 1)); }
.cv-mihrab .cv-sub { top: 47%; }
.cv-mihrab .cv-orn { top: 60%; font-family: "Amiri", serif; font-size: calc(14pt * var(--cv-scale, 1)); letter-spacing: 0; }
.cv-mihrab .cv-foot { top: 66%; font-size: calc(12pt * var(--cv-scale, 1)); }
.cv-mihrab .cv-logo { top: 84%; background: #fff; padding: 1mm 2.5mm; box-sizing: content-box; }
/* Gaya "gambar": gambar sampul milik pengguna sepenuh kertas, teks otomatis di atasnya */
.cv-bgimg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.cv-gambar .cv-in { left: 18%; right: 18%; z-index: 1; }
.cv-gambar .cv-title { height: 14%; font-size: calc(34pt * var(--cv-scale, 1)); line-height: 1.15; font-weight: 700; }
.cv-gambar .cv-sub { left: 25%; right: 25%; font-size: calc(11.5pt * var(--cv-scale, 1)); line-height: 1.65; } /* di antara dua ranting bunga template */
.cv-gambar .cv-orn { display: none; }
.cv-gambar .cv-foot { font-size: calc(14pt * var(--cv-scale, 1)); font-weight: 700; }
.cv-gambar .cv-kelas { font-weight: 700; font-size: 1.1em; }
/* Gaya "kubah": judul dalam kartusy bergerigi di bawah kubah; keterangan diapit ranting bunga */
.cv-kubah .cv-in { left: 16%; right: 16%; }
.cv-kubah .cv-title { top: 27.5%; height: 14%; font-size: calc(34pt * var(--cv-scale, 1)); line-height: 1.15; font-weight: 700; }
.cv-kubah .cv-sub { top: 47.5%; left: 12%; right: 12%; font-size: calc(12.5pt * var(--cv-scale, 1)); line-height: 1.7; }
.cv-kubah .cv-orn { display: none; }
.cv-kubah .cv-foot { top: 68%; font-size: calc(14pt * var(--cv-scale, 1)); font-weight: 700; }
.cv-kubah .cv-logo { top: 78.5%; background: #fff; padding: 0.8mm 2mm; box-sizing: content-box; }
/* Gaya "anggun": minimalis, judul di dalam kartusy, banyak ruang kosong */
.cv-anggun .cv-in { left: 18%; right: 18%; }
.cv-anggun .cv-title { top: 29%; height: 16%; font-size: calc(36pt * var(--cv-scale, 1)); line-height: 1.2; }
.cv-anggun .cv-sub { top: 47.5%; font-size: calc(13pt * var(--cv-scale, 1)); line-height: 1.7; }
.cv-anggun .cv-orn { display: none; }
.cv-anggun .cv-foot { top: 66.5%; font-size: calc(14pt * var(--cv-scale, 1)); letter-spacing: 0.3pt; }
.cv-anggun .cv-logo { top: 80%; }
/* Gaya "mewah": latar warna penuh, judul emas di dalam medali bintang, teks krem */
.cv-mewah .cv-in { left: 20%; right: 20%; color: var(--cv-text, #1d1d1b); }
.cv-mewah .cv-title { top: 25%; height: 20%; font-size: calc(38pt * var(--cv-scale, 1)); color: var(--cv-gold, #1d1d1b); }
.cv-mewah .cv-sub { top: 61%; font-size: calc(11.5pt * var(--cv-scale, 1)); line-height: 1.8; }
.cv-mewah .cv-orn { display: none; }
.cv-mewah .cv-foot { top: 75%; left: 14%; right: 14%; margin: 0 auto; width: max-content; max-width: 72%; padding: 0.6mm 5mm;
  border: 0.5pt solid var(--cv-gold, #1d1d1b); border-radius: 10mm; font-size: calc(11.5pt * var(--cv-scale, 1)); line-height: 1.7; }
.cv-mewah .cv-foot:empty { display: none; }
.cv-mewah .cv-logo { top: 83%; background: var(--cv-badge, #fff); padding: 1.5mm 4mm; border: 0.6pt solid var(--cv-gold, #1d1d1b); border-radius: 2.5mm; box-sizing: content-box; }
/* Gaya "klasik": lapang, tanpa pola; hiasan digambar di SVG */
.cv-klasik .cv-in { left: 18%; right: 18%; }
.cv-klasik .cv-title { top: 25%; height: 19%; font-size: calc(44pt * var(--cv-scale, 1)); }
.cv-klasik .cv-sub { top: 48.5%; font-size: calc(12pt * var(--cv-scale, 1)); }
.cv-klasik .cv-orn { display: none; }
.cv-klasik .cv-foot { top: 63%; font-size: calc(12.5pt * var(--cv-scale, 1)); letter-spacing: 0.2pt; }
.cv-klasik .cv-logo { top: 80%; }
/* Halaman 2 gaya mihrab: kartu "بطاقة الكتاب" */
.id-mihrab .id-wrap { padding-top: 3mm; }
.id-title { font-family: "Aref Ruqaa", var(--fallback-ar); font-weight: 700; font-size: 26pt; line-height: 1.5; }
.id-subl { font-size: 13.5pt; line-height: 1.7; }
.id-div svg { display: block; width: 62mm; height: 7mm; margin: 2mm auto 0; }
.id-card { width: 86%; margin: 4mm auto 0; border: 0.75pt solid #1d1d1b; outline: 0.3pt solid #1d1d1b; outline-offset: 1.2mm; }
.id-card-h { font-family: "Aref Ruqaa", var(--fallback-ar); font-weight: 700; font-size: 14pt; line-height: 1.8; border-bottom: 0.75pt solid #1d1d1b; background: #efefef; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.id-card .id-tab { width: auto; margin: 0; padding: 1mm 4mm 2.5mm; gap: 0 5mm; font-size: 13pt; line-height: 1.75; }
.id-card .id-k, .id-card .id-v { border-bottom: 0.5pt dotted #8a8a8a; padding: 0.4mm 0; }
.id-card .id-k { font-weight: 700; }
.id-mihrab .id-ed { margin-top: 6mm; font-size: 14pt; }
.id-mihrab .id-notice { width: 80%; margin-top: 6mm; padding-top: 2mm; border-top: 0.5pt solid #1d1d1b; font-size: 11.5pt; line-height: 1.7; color: #333; }
/* Halaman 2: identitas kitab (seperti halaman hak cipta) */
.id-wrap { direction: rtl; text-align: center; font-family: "Angka Biasa", var(--font-ar), var(--fallback-ar); color: #000; padding-top: 6mm; }
.id-head { font-size: 16pt; font-weight: 700; line-height: 1.7; }
.id-ed { margin-top: 7mm; font-size: 12pt; line-height: 1.7; }
.id-rule { width: 75%; margin: 4mm auto; border-top: 2.25pt solid #000; }
.id-tab { display: grid; grid-template-columns: auto 1fr; gap: 0 4mm; width: 88%; margin: 0 auto; text-align: start; font-size: 11pt; line-height: 1.8; }
.id-notice { width: 88%; margin: 2mm auto 0; font-size: 12pt; line-height: 1.7; }
.id-logo { display: block; margin: 8mm auto 0; }

/* Di tampilan kertas, kotak .page hanya wadah lembar-lembar */
body:not(.fit) .page { width: auto; min-height: 0; padding: 0; background: none; border: none; box-shadow: none; }

/* Judul bab: di tengah, dengan spasi di atasnya; boleh berukuran/tebal berbeda dari lafal */
.para.hd {
  text-align: center; text-align-last: center;
  margin-top: var(--hd-gap);
  --ar-size: var(--hd-ar-size);
  font-weight: var(--hd-weight);
}

/* Bait nadzom: dua syathar sebaris, tanda (۞) di tengah; tiap syathar rata kanan-kiri penuh
   (termasuk barisnya yang terakhir) seperti cetakan nadzom. Tanda tengah adalah token tanpa makna. */
.para.nz { display: flex; align-items: flex-start; --ar-size: var(--nz-ar-size); } /* lafal nadzom boleh lebih kecil dari narasi */
.para.nz .shatr { flex: 1 1 0; min-width: 0; }
/* Titik-titik di syathar nadzom: titiknya memanjang mengisi sisa syathar sampai ujung */
.para.nz .shatr:has(> .tok.dots) { display: flex; column-gap: calc(0.25em + var(--space)); } /* flex membuang spasi antarkata: ganti dengan jarak setara */
.para.nz .shatr > .tok.dots { flex: 1 1 auto; min-width: 2em; }
.para.nz .shatr > .tok.dots .ar { align-self: stretch; position: relative; color: transparent; }
.para.nz .shatr > .tok.dots .ar::after { content: ""; position: absolute; left: 0; right: 0; top: 58%;
  border-bottom: calc(var(--ar-size) * 0.14) dotted var(--ar-color); }
/* Bawaan: syathar kanan rapat ke margin kanan, syathar kiri rapat ke margin kiri, tanda tepat
   di tengah (membentuk kolom lurus); teks nadzom biasanya sudah disamakan panjangnya dengan kasyidah. */
.para.nz .shatr:first-child { text-align: start; text-align-last: start; }
.para.nz .shatr:last-child { text-align: end; text-align-last: end; }
body.nz-justify .para.nz .shatr { text-align: justify; text-align-last: justify; }
/* Bertingkat bila perlu (kertas sempit / lafal besar). app.js (nzFit) mengukur tiap bait di tampilan kertas:
   - nz-row : kedua syathar muat setengah lebar -> sebaris, porsi seimbang, rata penuh, tanda tepat di tengah;
   - nz-r   : hanya syathar kanan muat -> baris 1: syathar kanan | tanda di tengah, baris 2: syathar kiri;
   - nz-l   : hanya syathar kiri muat  -> baris 1: syathar kanan, baris 2: tanda di tengah | syathar kiri;
   - lainnya: syathar kanan, tanda menyusul di ujungnya, syathar kiri turun rapat kiri. */
body.nz-stagger .para.nz { flex-wrap: wrap; }
body.nz-stagger .para.nz .shatr { flex: 0 1 auto; }
body.nz-stagger .para.nz .shatr:last-child { margin-inline-start: auto; }
body.nz-stagger .para.nz.nz-probe { flex-wrap: nowrap; }
body.nz-stagger .para.nz.nz-probe .shatr { flex: none; width: max-content; margin: 0; }
body.nz-stagger .para.nz:is(.nz-probe, .nz-row, .nz-r, .nz-l) .tok.sep { margin-left: var(--nz-gap); margin-right: var(--nz-gap); }
body.nz-stagger .para.nz.nz-row { flex-wrap: nowrap; }
/* --nz-half (px, dari nzFit): setengah lebar isi dikurangi tanda; syathar yang muat diberi lebar ini */
body.nz-stagger .para.nz.nz-row .shatr,
body.nz-stagger .para.nz.nz-r .shatr:first-child,
body.nz-stagger .para.nz.nz-l .shatr:last-child { flex: 0 0 var(--nz-half); margin: 0; text-align: justify; text-align-last: justify; }
body.nz-stagger .para.nz.nz-r .shatr:last-child { flex: 0 0 100%; margin: 0; }
body.nz-stagger .para.nz.nz-l .shatr:first-child { flex: 0 0 100%; }
body.nz-stagger .para.nz.nz-l .tok.sep { margin-inline-start: auto; } /* dorong tanda ke tengah, rapat ke syathar kiri */
body.nz-stagger .tok.sep { margin-left: 0; margin-right: var(--nz-gap); } /* RTL: jarak ke syathar = sisi kanan */
.tok.sep { flex: 0 0 auto; margin-left: var(--nz-gap); margin-right: var(--nz-gap); }
.tok.sep .kd { visibility: hidden; }
.tok.sep .ar { font-family: "Amiri", "Scheherazade New", var(--font-ar), var(--fallback-ar); font-size: 0.7em; line-height: calc(var(--ar-size) * 2); } /* tanda tengah tidak terlalu besar; tinggi baris tetap sama dengan lafal supaya letaknya sejajar tengah huruf */

/* Satu kata: kedudukan / lafal / makna (bisa beberapa baris miring) */
.tok {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: top;
  margin: 0 0 var(--gap);
  cursor: pointer;
  border-radius: 3px;
}
/* Paragraf yang sama sekali tidak bermakna memakai jarak baris yang lebih rapat */
.para.no-mk .tok { margin-bottom: var(--gap-empty); }
/* Teks pegon / keterangan (tidak perlu makna): ukuran sendiri, tanpa ruang kedudukan & makna,
   jarak baris rapat (--pg-lh × ukuran huruf). Dikenali otomatis atau lewat tombol Pegon. */
.para.pg { --ar-size: var(--pg-ar-size); }
.para.pg .kd, .para.pg .mk { display: none; }
.para.pg .tok { margin-bottom: 0; }
.para.pg .ar { line-height: var(--pg-lh); margin-top: 0; }
/* Bagian catatan: kiri-ke-kanan; baris isian berupa garis selebar isi halaman */
.para.nt { direction: ltr; text-align: left; text-align-last: left; --ar-size: var(--pg-ar-size); }
.para.nt .kd, .para.nt .mk { display: none; }
.para.nt .tok { margin-bottom: 0; }
.para.nt .ar { line-height: 1.6; margin-top: 0; max-width: 100%; overflow: hidden; }
.para.nt-line { height: 7mm; box-sizing: border-box; border-bottom: 0.6pt solid var(--ar-color); margin: 0; overflow: hidden; }
.para.nt-line .tok { visibility: hidden; }
/* Halaman catatan otomatis (padNotes): judul "Catatan:" rata kiri, garis isian 8 mm */
.note-sheet .sheet-body { margin: 0; }
.note-head { direction: ltr; text-align: left; height: 6mm; box-sizing: border-box; overflow: hidden; font-family: var(--font-ar), var(--fallback-ar); font-size: var(--pg-ar-size); line-height: 1.2; }
.note-line { height: 7mm; box-sizing: border-box; border-bottom: 0.6pt solid var(--ar-color); } /* garis termasuk dalam 7mm */
/* Catatan kaki: angka kecil di kata; daftar di dasar lembar di bawah garis pendek (kanan) */
.fnref { font-family: "Angka Biasa", var(--font-ar), var(--fallback-ar); font-size: 0.5em; vertical-align: super; line-height: 0; margin-inline-start: 1pt; }
.fn-area { position: relative; padding-top: 2.5mm; }
.fn-area::before { content: ""; position: absolute; top: 1mm; right: 0; width: 38%; border-top: 0.6pt solid var(--ar-color); }
.fn-item { direction: rtl; text-align: justify; font-family: "Angka Biasa", var(--font-ar), var(--fallback-ar); font-size: var(--fn-size, 11pt); line-height: 1.6; color: var(--ar-color); }
.fn-no { font-size: 0.7em; vertical-align: super; line-height: 0; margin-inline-end: 2pt; }
/* Tabel (kotak masalah faraidh, dll.): di tengah, garis tunggal; sisi bertanda nb-* tanpa garis.
   Isi ditulis seukuran teks pegon, tanpa ruang kedudukan & makna. */
.para.tbl { display: flex; justify-content: center; margin: 3pt 0 8pt; --ar-size: var(--pg-ar-size); }
.mj-tbl { border-collapse: collapse; direction: rtl; max-width: 100%; }
.mj-tbl-row { display: flex; direction: rtl; justify-content: center; align-items: flex-start; gap: 10pt; max-width: 100%; } /* tabel contoh berdampingan */
.mj-tbl td { border: 0.75pt solid var(--ar-color); padding: 0 4pt; text-align: center; vertical-align: middle; white-space: nowrap; }
.tbl-wrap .mj-tbl td { white-space: normal; } /* tabel kelebaran: kalimat dalam sel turun baris (app.js) */
.mj-tbl td.nb-t { border-top: none; }
.mj-tbl td.nb-b { border-bottom: none; }
.mj-tbl td.nb-l { border-left: none; }
.mj-tbl td.nb-r { border-right: none; }
.para.tbl .kd, .para.tbl .mk { display: none; }
.para.tbl .tok { margin-bottom: 0; }
.para.tbl .ar { line-height: 1.6; margin-top: 0; }
/* Kata ayat Al-Qur'an (berisi tanda/huruf rasm Utsmani yang tidak ada di font lafal): pakai font mushaf */
.tok.qr .ar { font-family: "KFGQPC HAFS Uthmanic Script", var(--font-ar), var(--fallback-ar); }
/* Paragraf tanpa kutipan ayat (judul, penutup/tanggal, dll.): angka biasa, bukan bulatan nomor ayat font mushaf */
.para.nq .ar { font-family: "Angka Biasa", var(--font-ar), var(--fallback-ar); }
/* Tulisan abu-abu tipis (buku latihan: kata untuk ditebali) */
.tok.gr .ar { color: #b8b8b8; }
/* Tanda rujuk dlamir: nomor kecil di pojok kiri atas lafal (sama pada dlamir & marji'-nya) */
/* tanda rujuk: ukuran & huruf sama dengan kedudukan (di atas kata yang dirujuk) dan makna (di ujung makna dlamir) */
.kd > .rj, .mk > .rj { font-size: 1em; }
.kd > .rj { position: relative; top: calc(var(--rj-y, 3pt) * -1); left: calc(var(--rj-x, 0pt) * -1); } /* bisa digeser di Pengaturan > Kedudukan */
.tok:hover .ar { background: var(--accent-soft); }
.tok.active .ar { background: #ffe9a8; outline: 1px solid #e0b93b; }

.kd {
  font-family: var(--font-kd), var(--fallback-mk);
  font-style: var(--kd-style);
  font-size: var(--kd-size);
  color: var(--kd-ink);
  min-height: calc(var(--kd-size) * 1.3);
  line-height: 1.3;
  white-space: nowrap;
  direction: rtl;
  position: relative; z-index: 1;
  /* dasar -0.42em: turun sampai puncak huruf (tanpa harakat); --kd-gap menggeser dari situ */
  margin-bottom: calc(var(--ar-size) * -0.42 + var(--kd-gap));
  /* dua slot: ujung kanan (awal lafal) dan ujung kiri (akhir lafal) */
  align-self: stretch;
  display: flex; justify-content: space-between; gap: 4pt;
  padding: 0 1pt;
}
.kd > span { white-space: pre; }
.kd > span:empty::before { content: "\00a0"; }
.ar {
  font-family: var(--font-ar), var(--fallback-ar);
  font-size: var(--ar-size);
  color: var(--ar-color);
  line-height: 2;
  margin-top: calc(var(--ar-size) * -0.25);
  white-space: nowrap;
  border-radius: 3px;
}
/* Makna: stroke miring di bawah lafal. Makna panjang dipecah menjadi beberapa
   stroke sejajar; stroke lanjutan diletakkan SEPENUHNYA DI SEBELAH KIRI stroke
   sebelumnya pada ketinggian awal yang sama (posisi `right` diatur app.js), sehingga
   tingginya tetap satu stroke (tidak menabrak baris bawah) dan dibaca kanan -> kiri.
   Makna kiri (akhir lafal) memakai anchor right:80% (diatur app.js). */
.mk {
  position: absolute;
  top: calc(100% - var(--ar-size) * 0.35 + var(--mk-gap));
  right: 20%;
  transform-origin: right top;
  transform: rotate(calc(var(--angle) * -1deg));
  font-family: var(--font-mk), var(--fallback-mk);
  font-style: var(--mk-style);
  font-size: var(--mk-size);
  color: var(--mk-ink);
  white-space: pre;
  direction: rtl;
  text-align: right;
  line-height: 1.2;
  pointer-events: none;
}
.tok.no-mk .mk::before {
  content: "";
  display: inline-block;
  width: 10pt; height: 1px;
  background: var(--line);
  vertical-align: middle;
}

/* ---------- Editor ---------- */
.editor {
  position: fixed; left: var(--sidebar-w); right: 0; bottom: 0; z-index: 30;
  background: #fff;
  border-top: 2px solid var(--accent);
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  padding: 8px 16px 10px;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 70vh; overflow-y: auto;
}
.editor[hidden] { display: none; }
.ed-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ed-head { justify-content: space-between; flex-wrap: nowrap; }
.ed-word {
  flex: 1; text-align: center; min-width: 0;
  font-family: var(--font-ar), var(--fallback-ar); font-size: 26px; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ed-grid {
  display: grid;
  grid-template-columns: 2fr 1.4fr 1fr 1fr 1fr;
  gap: 8px;
  direction: rtl;
}
.ed-field { display: flex; flex-direction: column; gap: 2px; direction: ltr; min-width: 0; }
.ed-field span { font-size: 12px; color: var(--muted); }
#editor .ed-field input {
  /* isian memakai huruf naskh biasa (bukan font makna nasta'liq/riq'ah) supaya mudah dibaca saat mengetik */
  font-family: "Noto Naskh Arabic", "Scheherazade New", "Segoe UI", Tahoma, sans-serif;
  font-size: 22px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  direction: rtl;
  width: 100%;
  min-width: 0;
}
/* kolom lafal juga huruf naskh biasa (sama dengan isian lain) */
.ed-field input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* pemilih font berpratinjau di pengaturan */
.font-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; margin: 2px 0 6px; }
.font-pick button {
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 6px; min-height: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; overflow: hidden; min-width: 0;
}
.font-pick button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.font-pick .fp-sample { font-size: 18px; line-height: 1.9; white-space: nowrap; }
.font-pick small { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* mode ringkas: hanya 5 isian (makna kanan/kiri, kedudukan kanan/kiri, lafal), tanpa chip/huruf pegon/tombol */
.editor.ed-simple .ed-row:not(.ed-head) { display: none; }
.editor.ed-simple .ed-grid { grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.editor.ed-simple .ed-makna, .editor.ed-simple .ed-maknal { grid-column: 1 / -1; }
.editor.ed-simple .ed-field:last-child { grid-column: 1 / -1; }
.editor.ed-simple .ed-field span { font-size: 11px; }
#editor.ed-simple .ed-field input { font-size: 20px; padding: 5px 8px; }
/* mode ringkas tampil sebagai kotak kecil di tengah layar (yang terlihat), lembar tetap kelihatan di sekitarnya */
.editor.ed-simple {
  left: 50%; right: auto; bottom: auto; top: var(--ed-top, 50%);
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 24px)); box-sizing: border-box;
  max-height: none; overflow: visible;
  padding: 8px 12px 12px; gap: 6px;
  border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.08);
}
.editor.ed-simple .ed-word { font-size: 24px; }
#edMode { font-size: 13px; }
/* HP: isian bersusun ke bawah, satu per baris, huruf besar supaya jelas; kotak tidak melebihi layar yang terlihat */
@media (max-width: 820px) {
  .editor.ed-simple {
    max-height: calc(var(--ed-vh, 100vh) - 16px); overflow-y: auto;
    padding: 6px 12px 12px;
  }
  .editor.ed-simple .ed-grid { grid-template-columns: 1fr; gap: 8px; }
  .editor.ed-simple .ed-field { grid-column: auto; }
  .editor.ed-simple .ed-field span { font-size: 13px; }
  #editor.ed-simple .ed-field input { font-size: 28px; padding: 8px 12px; line-height: 1.5; }
  .editor.ed-simple .ed-word { font-size: 30px; }
}

.chips { gap: 4px; }
.chip { padding: 2px 8px; font-size: 12px; border-radius: 999px; background: #faf7f0; min-height: 30px; }
.chip b { font-family: var(--font-kd), var(--fallback-mk); font-size: 16px; color: var(--kd-ink); font-weight: 400; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

.pegon-keys { display: flex; gap: 3px; flex-wrap: wrap; }
.pegon-keys button {
  font-family: var(--font-mk), var(--fallback-mk);
  font-size: 20px; min-width: 36px; justify-content: center; padding: 0 6px;
}

/* ---------- Dialog & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; width: min(760px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.3); }
.dlg { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg textarea {
  font-family: var(--font-ar), var(--fallback-ar);
  font-size: 24px; line-height: 1.8; padding: 10px;
  border: 1px solid var(--line); border-radius: 6px; resize: vertical; width: 100%;
}
.dlg-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nz-opts { display: flex; flex-direction: column; gap: 6px; }
.nz-opts b { margin-top: 6px; }
.nz-opts input:disabled + * , .nz-opts label:has(input:disabled) { color: var(--muted); }
.settings .nz-sym { width: 80px; flex: 0 0 auto; font-family: var(--font-ar), var(--fallback-ar); font-size: 18px; }
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 6px; z-index: 50;
  max-width: 90vw; text-align: center;
}

/* ---------- Layar kecil (HP / tablet) ---------- */
@media (max-width: 820px) {
  body { padding-bottom: 65vh; }
  .only-mobile { display: inline-flex; }
  .main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; width: min(280px, 85vw); }
  .sidebar.open { transform: none; box-shadow: 6px 0 24px rgba(0,0,0,.2); }
  .topbar { padding: 6px 10px; gap: 8px; }
  .topbar-label { display: none; }
  #docSelect { max-width: none; }
  .save-status { font-size: 11px; min-width: 0; }
  body:not(.fit) .desk { padding: 12px 8px; } /* tampilan kertas: sisakan lebar sebanyak mungkin untuk lembar */

  .editor { left: 0; padding: 6px 10px 8px; max-height: 62vh; gap: 5px; }
  .ed-word { font-size: 22px; }
  .ed-head button { padding: 4px 8px; font-size: 13px; }
  .ed-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .ed-makna, .ed-maknal { grid-column: 1 / -1; }
  #editor .ed-field input { font-size: 20px; padding: 5px 8px; }
  .scroll-row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .scroll-row > * { flex: 0 0 auto; }
  .pegon-keys { flex-wrap: nowrap; }
  .chip { font-size: 12px; }

  dialog { width: 96vw; }
  .dlg { padding: 12px; }
  .dlg textarea { font-size: 20px; }

  /* Tampilan layar di HP: dua syathar terlalu lebar untuk sebaris -> ditumpuk, tanda di tengah */
  body.fit .para.nz { flex-direction: column; align-items: stretch; }
  body.fit .para.nz .shatr { text-align: justify; text-align-last: auto; }
  body.fit .tok.sep { align-self: center; margin: 0 0 4pt; }
  body.fit.nz-stagger .tok.sep { margin-right: var(--nz-gap); }
}

/* ---------- Cetak ---------- */
/* Ukuran kertas, margin, header & footer (@page) diatur dari app.js lewat #pageStyle. */
@media print {
  body { background: #fff; padding: 0; }
  .no-print, .toast, .editor, .settings, .sidebar, .topbar, .backdrop { display: none !important; }
  .main { margin-left: 0; }
  .desk, body.fit .desk { padding: 0; overflow: visible; }
  .page, body.fit .page { border: none; box-shadow: none; margin: 0; padding: 0; width: auto; min-height: 0; overflow: visible; border-radius: 0; }
  /* Tiap lembar layar = satu halaman cetak (isinya sudah diukur muat); margin dari @page */
  .sheet { width: auto; height: auto; margin: 0; padding: 0; border: none; box-shadow: none; break-after: page; content-visibility: visible; }
  .sheet:last-child { break-after: auto; }
  .sheet::before { display: none; }
  /* Sampul: halaman bernama "sampul" (tanpa margin & header/footer, lihat #pageStyle), satu lembar penuh */
  /* wadah halaman tanpa sisa jarak/garis saat cetak (dulu menggeser semua isi ± 3 mm ke bawah & 2 mm ke kiri) */
  .main, .desk, .page, .text { margin: 0 !important; padding: 0 !important; border: 0 !important; }
  .main::before, .desk::before, .page::before, .page::after, .text::before { display: none !important; }
  /* --cv-shift: geser turun (0-5 mm) supaya bingkai gambar sampul sama jauhnya dari tepi atas & bawah (dihitung app.js) */
  .sheet.cover { page: sampul; width: var(--paper-w); height: calc(var(--paper-h) - 5mm); margin-top: var(--cv-shift, 2.5mm) !important; position: relative; overflow: hidden; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-body { height: auto; }
  .tok.active .ar, .tok:hover .ar { background: none; outline: none; }
  body.hide-empty .tok.no-mk .mk::before { display: none; }
  /* Cetak tanpa makna (lafal saja): ruang makna tetap untuk ditulisi */
  body.print-bare .mk, body.print-bare .kd { visibility: hidden !important; }
  .tok { break-inside: avoid; }
}

/* Panel kemajuan ekspor PDF */
.pdf-prog { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(20, 20, 20, 0.35); }
.pdf-prog-card { width: min(360px, calc(100vw - 32px)); background: var(--panel, #fff); color: var(--ink, #222); border-radius: 10px; padding: 16px 18px; box-shadow: 0 8px 30px rgba(0,0,0,.25); font-size: 14px; }
.pdf-prog-card > b { font-size: 16px; }
.pdf-prog-title { color: var(--muted, #666); margin: 2px 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-prog ol { list-style: none; margin: 0 0 12px; padding: 0; }
.pdf-prog li { padding: 3px 0 3px 24px; position: relative; color: var(--muted, #888); }
.pdf-prog li::before { content: "○"; position: absolute; left: 4px; }
.pdf-prog li.now { color: var(--ink, #222); font-weight: 600; }
.pdf-prog li.now::before { content: "◔"; animation: pdfspin 1s linear infinite; }
.pdf-prog li.ok { color: var(--ink, #222); }
.pdf-prog li.ok::before { content: "✓"; color: #2e8b57; font-weight: 700; }
@keyframes pdfspin { to { transform: rotate(360deg); } }
.pdf-prog-bar { height: 8px; border-radius: 4px; background: var(--line, #e4e4e4); overflow: hidden; }
.pdf-prog-bar span { display: block; height: 100%; width: 0; background: var(--accent, #2f6f4f); transition: width .2s linear; }
.pdf-prog-info { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted, #666); }

/* Akun & hak akses */
.acct-name { font-weight: 600; padding: 2px 2px 6px; overflow-wrap: anywhere; }
.super-only { display: none; }
body.is-super .super-only { display: block; }
body.is-super label.super-only { display: flex; }
.pj-info { font-size: 13px; color: var(--muted, #666); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }
.pj-info.ro { color: #a0522d; font-weight: 600; }
body.readonly #btnPaste, body.readonly label:has(#fileDocx), body.readonly #btnNazham, body.readonly #btnRenameDoc { opacity: .45; pointer-events: none; }
.login-dlg::backdrop { background: rgba(15, 60, 50, .85); }
.login-dlg .dlg { min-width: min(320px, calc(100vw - 48px)); }
.login-dlg label, #passDialog label, .user-form label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.login-err { color: #b3261e; margin: 4px 0; }
.users-wrap { max-height: 45vh; overflow: auto; margin: 6px 0 10px; }
.users-tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.users-tbl th, .users-tbl td { border-bottom: 1px solid var(--line, #ddd); padding: 4px 6px; text-align: left; vertical-align: middle; }
.users-tbl td button { padding: 2px 8px; margin-right: 4px; }
.users-tbl tr.off td { color: var(--muted, #999); text-decoration: line-through; }
.user-form { border-top: 1px solid var(--line, #ddd); padding-top: 8px; }
.user-form label.check { flex-direction: row; align-items: center; }
.pj-list { display: flex; flex-direction: column; gap: 4px; max-height: 45vh; overflow: auto; margin: 8px 0; }
.sb-logo { display: inline-flex; align-items: center; gap: 8px; }
.sb-logo img { border-radius: 6px; flex: none; }

/* ======================================================================
   Tampilan antarmuka (tema) — hanya bagian layar; lembar kitab & cetak tidak berubah
   ====================================================================== */
:root {
  --bg: #f2efe8;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --line: #e4ddcf;
  --ink: #1f2a27;
  --muted: #6d7571;
  --accent: #0f6b5c;
  --accent-2: #0a5246;
  --accent-soft: #e3f1ed;
  --gold: #c9962b;
  --danger: #b3402e;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  --sh-1: 0 1px 2px rgba(16, 40, 34, .06), 0 1px 3px rgba(16, 40, 34, .05);
  --sh-2: 0 6px 18px rgba(16, 40, 34, .10);
  --sh-3: 0 24px 60px rgba(10, 40, 34, .28);
  --ring: 0 0 0 3px rgba(15, 107, 92, .22);
}
body { -webkit-font-smoothing: antialiased; }
::selection { background: #cfe9e2; }

/* Tombol & isian */
button, .btn, select {
  border-radius: var(--r-sm); border-color: var(--line); background: var(--surface);
  box-shadow: var(--sh-1); transition: background .15s, border-color .15s, box-shadow .15s, transform .08s, color .15s;
  font-weight: 500;
}
button:hover, .btn:hover { border-color: #c9d9d3; background: #fbfdfc; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-within, select:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary { background: linear-gradient(180deg, #13806e, var(--accent)); border-color: var(--accent-2); color: #fff; box-shadow: 0 1px 2px rgba(10,82,70,.3), inset 0 1px 0 rgba(255,255,255,.15); }
button.primary:hover { background: linear-gradient(180deg, #158a77, var(--accent-2)); border-color: var(--accent-2); }
button.danger { color: var(--danger); }
button.danger:hover { background: #fdf3f1; border-color: #efc7bf; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 11px;
  transition: border-color .15s, box-shadow .15s;
}
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=range] { accent-color: var(--accent); }

/* Menu samping */
.sidebar { background: var(--surface); border-right: 1px solid var(--line); gap: 18px; padding: 16px 12px 24px; scrollbar-width: thin; }
.sb-brand { font-size: 18px; letter-spacing: -.01em; color: var(--accent-2); padding: 2px 4px 6px; }
.sb-logo img { border-radius: 9px; box-shadow: var(--sh-1); }
.sb-title { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; color: #9aa19d; padding: 0 8px 4px; }
.sb-group { gap: 2px; }
.sidebar button, .sidebar .btn {
  border-color: transparent; background: transparent; box-shadow: none; min-height: 36px;
  border-radius: var(--r-sm); padding: 7px 10px; color: #33403c; font-weight: 500;
}
.sidebar button:hover, .sidebar .btn:hover { background: var(--surface-2); border-color: transparent; color: var(--accent-2); }
.sidebar button.primary { background: linear-gradient(180deg, #13806e, var(--accent)); color: #fff; box-shadow: 0 2px 8px rgba(15,107,92,.25); margin-bottom: 2px; }
.sidebar button.primary:hover { color: #fff; background: linear-gradient(180deg, #158a77, var(--accent-2)); }
.sidebar button.danger { color: var(--danger); }
.sidebar button.danger:hover { background: #fdf3f1; color: var(--danger); }
.sb-check { padding: 6px 10px; border-radius: var(--r-sm); }
.sb-check:hover { background: var(--surface-2); }

/* Kartu akun */
.acct-card { display: flex; align-items: center; gap: 10px; padding: 10px; margin-bottom: 6px; border-radius: var(--r-md);
  background: linear-gradient(135deg, #eef7f4, #f8f4ea); border: 1px solid #e1ece7; }
.acct-ava { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #2a9d84); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em; box-shadow: 0 2px 6px rgba(15,107,92,.3); }
.acct-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.acct-meta b { font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-meta small { font-size: 11.5px; color: var(--accent); font-weight: 600; }

/* Bilah atas */
.topbar { background: rgba(255,255,255,.86); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line); padding: 10px 18px; gap: 12px; }
.topbar-label { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #9aa19d; }
.topbar select { min-height: 38px; padding-left: 12px; font-weight: 600; }
.save-status { font-weight: 600; padding: 4px 10px; border-radius: 999px; min-width: 0; background: var(--surface-2); }
.save-status.ok { color: var(--accent); background: var(--accent-soft); }
.save-status.busy { color: #8a6d1d; background: #fbf3dc; }
.save-status.err { color: var(--danger); background: #fdf0ed; }
.pj-info { font-weight: 500; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.pj-info:empty { display: none; }
.pj-info.ro { background: #fdf3ea; border-color: #f0d9c3; color: #9a4f17; }

/* Lembar kertas di layar */
@media screen { .sheet { border-color: #e7e1d4; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(40,34,20,.08); border-radius: 2px; } } /* hanya layar: jangan ikut tercetak */

/* Panel pengaturan */
.settings { background: var(--surface-2); border-left: 1px solid var(--line); box-shadow: -18px 0 50px rgba(10,40,34,.14); padding: 0 18px 18px; gap: 12px; }
.settings-head { background: rgba(250,248,244,.92); backdrop-filter: blur(8px); font-weight: 700; padding: 14px 12px 12px 18px; margin: 0 -18px; }
.settings fieldset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 14px 12px; box-shadow: var(--sh-1); }
.settings legend { font-weight: 700; color: var(--accent-2); background: var(--surface); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; }

/* Panel edit kata */
.editor { background: rgba(255,255,255,.97); border-top: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: 0 -10px 40px rgba(10,40,34,.16); padding: 10px 18px 12px; }
.editor::before { content: ""; display: block; width: 44px; height: 4px; border-radius: 4px; background: #d9d4c8; margin: 0 auto 2px; }
.ed-field span { font-weight: 600; letter-spacing: .02em; }
.ed-field input { border-radius: var(--r-sm); }
.chip { box-shadow: none; background: var(--surface-2); }
.chip:hover { background: var(--accent-soft); }

/* Dialog */
dialog { border: 0; border-radius: var(--r-lg); box-shadow: var(--sh-3); background: var(--surface); color: var(--ink); }
dialog[open] { animation: dlg-in .22s cubic-bezier(.2,.8,.2,1); }
dialog::backdrop { background: rgba(14, 32, 28, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog[open]::backdrop { animation: fade-in .2s ease; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.dlg { padding: 22px 24px 20px; gap: 12px; }
.dlg h2 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; color: var(--accent-2); display: flex; align-items: center; gap: 10px; }
.dlg h2::before { content: ""; width: 6px; height: 20px; border-radius: 4px; background: linear-gradient(180deg, var(--gold), #e3bb5c); }
.dlg-actions { margin-top: 4px; padding-top: 14px; border-top: 1px solid #efeadf; }
.dlg textarea { border-radius: var(--r-md); }
.hint { line-height: 1.5; }

/* Tabel dalam dialog (kelola user, riwayat) */
.users-wrap { border: 1px solid var(--line); border-radius: var(--r-md); }
.users-tbl th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 9px 10px; }
.users-tbl td { padding: 8px 10px; border-bottom: 1px solid #f0ebe1; }
.users-tbl tr:last-child td { border-bottom: 0; }
.users-tbl tr:hover td { background: #fbfaf6; }
.users-tbl td button { min-height: 30px; font-size: 12.5px; }
.user-form { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; border-top: 0; padding: 14px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--line); }
.user-form > b, .user-form .dlg-actions, .user-form label.check { grid-column: 1 / -1; }
.user-form > b { color: var(--accent-2); }
.user-form label { margin: 4px 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.user-form .dlg-actions { border-top: 1px solid var(--line); }
.pj-list { border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px; gap: 2px; }
.pj-list label { padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.pj-list label:hover { background: var(--surface-2); }
.pj-list label:has(input:checked) { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }

/* Halaman masuk (login) */
.login-dlg { width: min(400px, calc(100vw - 32px)); overflow: visible; }
.login-dlg::backdrop {
  background:
    radial-gradient(circle at 20% 20%, rgba(201,150,43,.22), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(42,157,132,.35), transparent 45%),
    repeating-conic-gradient(from 22.5deg at 50% 50%, rgba(255,255,255,.035) 0 45deg, transparent 0 90deg),
    linear-gradient(135deg, #0a4a40, #0f6b5c 55%, #13806e);
  background-size: auto, auto, 46px 46px, auto;
  backdrop-filter: none;
}
.login-dlg .dlg { padding: 28px 28px 22px; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand img { border-radius: 16px; box-shadow: 0 8px 20px rgba(15,107,92,.35); }
.login-brand h2 { font-size: 24px; color: var(--ink); }
.login-brand h2::before { display: none; }
.login-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.login-ar { margin: 2px 0 4px; text-align: center; font-family: "Amiri", var(--fallback-ar); font-size: 20px; color: var(--accent); opacity: .85; }
.login-dlg .field, .user-form label, #passDialog label { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.login-dlg .field > span:first-child { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-dlg input { font-size: 15px; padding: 11px 13px; }
.pass-wrap { position: relative; display: block; }
.pass-wrap input { width: 100%; padding-right: 44px !important; }
.pass-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 34px; padding: 0 9px; border: 0; box-shadow: none; background: transparent; font-size: 16px; opacity: .55; }
.pass-eye:hover { opacity: 1; background: var(--surface-2); }
.pass-eye:active { transform: translateY(-50%); }
.login-btn { width: 100%; justify-content: center; min-height: 46px; font-size: 15px; font-weight: 700; border-radius: var(--r-md); margin-top: 4px; }
.login-err { margin: 0; padding: 9px 12px; border-radius: var(--r-sm); background: #fdf0ed; border: 1px solid #f3cfc7; color: var(--danger); font-size: 13px; }
.login-err[hidden] { display: none; }
.login-foot { margin: 0; text-align: center; font-size: 12px; color: #9aa19d; }
#passDialog { width: min(420px, calc(100vw - 32px)); }
#pjDialog, #riwayatDialog { width: min(560px, 94vw); }

/* Pemberitahuan */
.toast { top: auto; bottom: 28px; background: #18302b; border-radius: 999px; padding: 10px 20px; box-shadow: var(--sh-2); font-weight: 500; animation: toast-in .25s cubic-bezier(.2,.8,.2,1); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Panel kemajuan PDF */
.pdf-prog { background: rgba(14, 32, 28, .45); backdrop-filter: blur(3px); }
.pdf-prog-card { border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: 22px 24px; animation: dlg-in .22s cubic-bezier(.2,.8,.2,1); }
.pdf-prog-card > b { color: var(--accent-2); }
.pdf-prog-bar { height: 10px; border-radius: 999px; background: #ece7dc; }
.pdf-prog-bar span { border-radius: 999px; background: linear-gradient(90deg, var(--accent), #2a9d84, var(--gold)); }

@media (max-width: 820px) {
  .topbar { padding: 8px 10px; }
  .pj-info { display: none; }
  .user-form { grid-template-columns: 1fr; }
  .toast { bottom: 18px; border-radius: var(--r-md); }
}
