/* ==================================================
   ADMIN PANEL — STYLESHEET
   ================================================== */

/* --------------------------------------------------
   FONT ARAB UTAMA — SCHEHERAZADE NEW
   --------------------------------------------------
   Font Arab yang dipakai aplikasi adalah "Scheherazade New"
   (SIL International) — dirancang untuk teks kitab dan
   menampilkan harakat dengan sangat jelas.

   Pemuatan font (3 lapis, tahan blokir hosting):
     1. @font-face LOKAL di bawah ini (sumber utama) — jika file
        tersedia di public/fonts/, browser memakainya lebih dulu
        TANPA koneksi eksternal.
     2. Google Fonts (dimuat di admin/partials/header.php &
        admin/login.php) sebagai cadangan.
     3. Font sistem sebagai cadangan terakhir.

   Cara mengaktifkan font lokal (opsional):
     1. Unduh ScheherazadeNew-Regular.ttf & ScheherazadeNew-Bold.ttf
     2. Letakkan di public/fonts/
   Jika file tidak ada, blok ini diabaikan browser (tidak error)
   dan browser otomatis memakai Google Fonts / font sistem.
   -------------------------------------------------- */
/*
 * `unicode-range` membatasi font ini HANYA untuk blok Unicode Arab
 * (U+0600–U+06FF, U+0750–U+077F, U+08A0–U+08FF, U+FB50–U+FDFF,
 * U+FE70–U+FEFF). Efeknya: pada elemen berisi CAMPURAN teks Indonesia
 * + Arab (mis. editor Review, Nahwu, Shorof), huruf Arab otomatis
 * memakai Scheherazade New sedangkan huruf Latin tetap memakai font
 * normal. Ini teknik yang benar untuk konten campuran — font UI Latin
 * TIDAK terpengaruh.
 */
@font-face {
    font-family: "Scheherazade New";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891,
                   U+0898-08E1, U+08E3-08FF, U+FB50-FDFF, U+FE70-FEFF;
    src: url("../fonts/ScheherazadeNew-Regular.ttf") format("truetype"),
         url("../fonts/ScheherazadeNew-Regular.woff2") format("woff2");
}

@font-face {
    font-family: "Scheherazade New";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891,
                   U+0898-08E1, U+08E3-08FF, U+FB50-FDFF, U+FE70-FEFF;
    src: url("../fonts/ScheherazadeNew-Bold.ttf") format("truetype"),
         url("../fonts/ScheherazadeNew-Bold.woff2") format("woff2");
}

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1f2933;
    --text-muted: #6b7280;
    --primary: #1d6f42;
    --primary-dark: #155232;
    --danger: #b91c1c;
    --warning: #b45309;
    --success: #15803d;
    --info: #1d4ed8;
    --sidebar-bg: #14261c;
    --sidebar-text: #d7e3da;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --------------------------------------------------
   Layout
   -------------------------------------------------- */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
}

.sidebar-brand {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 16px;
}

.brand-ar {
    display: block;
    font-size: 26px;
    direction: rtl;
    font-family: var(--font-arabic);
    color: #ffffff;
}

.brand-id {
    display: block;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #8fae9c;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.nav-group-title {
    padding: 14px 20px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8fae9c;
}

.nav-item {
    padding: 11px 20px;
    color: var(--sidebar-text);
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-left-color: var(--primary);
    text-decoration: none;
}

/* Item sidebar yang belum tersedia (mis. fitur FASE 14) */
.nav-item-disabled {
    display: block;
    opacity: 0.45;
    cursor: not-allowed;
}

.nav-item-disabled:hover {
    background: transparent;
    border-left-color: transparent;
}

.nav-item-disabled small {
    font-size: 0.75em;
    font-style: italic;
}

/*
 * Item sidebar MENU LAMA (nonaktif dari alur utama AI-First).
 * Tetap dapat diklik (akses data lama), namun tampil redup agar
 * tidak terlihat sebagai bagian workflow utama.
 */
.nav-item-muted {
    opacity: 0.6;
    font-size: 0.92em;
}

.nav-item-muted small {
    font-size: 0.75em;
    font-style: italic;
    opacity: 0.85;
}

.nav-item-muted:hover {
    opacity: 1;
}

.sidebar-user {
    padding: 16px 20px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 13px;
}

.user-name {
    font-weight: 600;
    color: #ffffff;
}

.user-username {
    color: #8fae9c;
    margin-bottom: 10px;
}

.content {
    flex: 1;
    padding: 24px 32px 48px;
    min-width: 0;
}

.content-header {
    margin-bottom: 20px;
}

.content-header h1 {
    margin: 0;
    font-size: 24px;
}

/* --------------------------------------------------
   Kartu & Grid
   -------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.card-title {
    margin: 0 0 14px;
    font-size: 17px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--primary);
}

/* --------------------------------------------------
   Filter
   --------------------------------------------------
   Layout filter dibuat GRID 3 kolom sama lebar (desktop) agar:
   - posisi & ukuran kolom TIDAK berubah saat select disabled/enabled;
   - label tiap kolom rata atas dengan jarak label->select yang sama;
   - tinggi/lebar/padding/font select seragam.
   Pada layar kecil, grid turun menjadi 1 kolom (bertumpuk vertikal). */
.filter-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

/* Tiap kolom filter: flex kolom agar label selalu di atas select dan
   jarak label->select konsisten, tanpa bergantung tinggi kolom lain. */
.filter-form .form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-bottom: 0;
}

/* Label filter rata atas & seragam. */
.filter-form .form-label {
    margin-bottom: 6px;
    line-height: 1.3;
}

/* Select filter seragam: tinggi, padding, font, dan lebar penuh kolom.
   `box-sizing: border-box` + `height` tetap menjaga tinggi sama walau
   select dalam keadaan disabled. */
.filter-form .form-control {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    font-size: 15px;
    line-height: 1.4;
    box-sizing: border-box;
}

/* Teks bantuan di bawah select tidak boleh menggeser select di atasnya. */
.filter-form .form-group > small {
    display: block;
    margin-top: 4px;
    line-height: 1.3;
}

/* Tombol fallback <noscript> tidak boleh menjadi kolom grid ke-4.
   Dibuat membentang penuh di barisnya sendiri. */
.filter-form .filter-form-noscript {
    grid-column: 1 / -1;
}

/* Layar kecil: filter bertumpuk vertikal dengan jarak rapi. */
@media (max-width: 768px) {
    .filter-form {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

/* --------------------------------------------------
   Form
   -------------------------------------------------- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

/* Input/textarea yang JUGA ber-class Arab: jangan warisi font Indonesia.
   (Mengalahkan `.form-control { font-family: inherit }`.) */
.form-control.arabic-text,
.form-control.input-arabic,
.form-control.text-arabic {
    font-family: var(--font-arabic) !important;
    font-size: var(--arabic-size) !important;
    line-height: var(--arabic-line-height) !important;
    direction: rtl !important;
    text-align: right !important;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 111, 66, 0.12);
}

/* Select/input yang DISABLED (mis. Filter Bab sebelum Kitab dipilih).
   Dibuat jelas terlihat nonaktif: latar abu, teks redup, kursor not-allowed. */
.form-control:disabled,
.form-control[disabled] {
    background: #f1f3f5;
    color: #8a94a0;
    border-color: #d7dce1;
    cursor: not-allowed;
    opacity: 1;
}

.form-control:disabled:hover,
.form-control[disabled]:hover {
    border-color: #d7dce1;
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

/* --------------------------------------------------
   Editor Review (textarea materi pembelajaran)
   --------------------------------------------------
   Full-width, tinggi nyaman untuk review & koreksi,
   padding & line-height lega, dan responsif.
   -------------------------------------------------- */
.review-editor {
    display: block;
    width: 100%;
    min-height: 280px;
    height: 320px;
    padding: 14px 16px;
    font-size: 15px;
    line-height: 1.75;
    font-family: inherit;
    resize: vertical;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    tab-size: 4;
}

/* Editor review yang JUGA ber-class Arab: pakai font Arab, bukan inherit. */
.review-editor.arabic-text,
.review-editor.arabic-input,
.review-editor.input-arabic {
    font-family: var(--font-arabic) !important;
    font-size: var(--arabic-size) !important;
    line-height: var(--arabic-line-height) !important;
    direction: rtl !important;
    text-align: right !important;
}

/* --------------------------------------------------
   EDITOR KONTEN CAMPURAN (Review / Nahwu / Shorof)
   --------------------------------------------------
   Editor ini berisi CAMPURAN teks Indonesia + Arab.
   Karena itu kita TIDAK memaksa direction: rtl pada
   seluruh elemen (agar teks Indonesia tetap LTR),
   melainkan hanya memakai font Arab. Berkat
   `unicode-range` pada @font-face di atas, hanya
   huruf Arab yang memakai Scheherazade New; huruf
   Latin tetap memakai font normal. line-height lega
   agar harakat tidak terpotong.
   -------------------------------------------------- */
.review-editor,
.arabic-text.arabic-input,
textarea.input-arabic {
    /* PENTING: `inherit` TIDAK boleh digabung dalam daftar font-family
       (itu CSS tidak valid dan membuat SELURUH deklarasi dibuang oleh
       browser). Jadi kita tulis font UI Latin eksplisit, lalu font Arab
       sebagai fallback. Berkat `unicode-range`, hanya huruf Arab yang
       memakai Scheherazade New; huruf Latin tetap font UI normal. */
    font-family: "Segoe UI", Tahoma, Arial, sans-serif, var(--font-arabic) !important;
    line-height: 2 !important;
    font-feature-settings: "liga" 1, "calt" 1, "kern" 1;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

@media (max-width: 768px) {
    .review-editor {
        min-height: 240px;
        height: 260px;
        padding: 12px 14px;
        font-size: 14px;
        line-height: 1.7;
    }
}

/* ==================================================
   TYPOGRAPHY TEKS ARAB — STANDAR TERPUSAT
   ==================================================
   Satu sumber kebenaran untuk SEMUA tampilan teks Arab
   di aplikasi (Teks Kitab, Pembagian Teks, Review/Pratinjau,
   editor konten, judul Arab kitab/bab/subbab, dsb).

   Prinsip:
   - HANYA berlaku pada konten Arab. Teks Indonesia dan
     layout aplikasi TIDAK ikut menjadi RTL.
   - Font UTAMA adalah Scheherazade New (fallback:
     Noto Naskh Arabic) agar huruf dan harakat terlihat jelas.
   - Ukuran, line-height, dan jarak dibuat lega supaya
     harakat tidak bertumpuk.

   Cara pakai (reusable):
     <div class="arabic-text">...</div>          -> blok teks Arab
     <span class="arabic-text arabic-inline">..</span> -> inline
     <textarea class="arabic-text arabic-input">..</textarea> -> editor
     <div class="arabic-block">...</div>          -> blok berkotak
   ================================================== */

:root {
    /* Font Arab: Scheherazade New adalah font UTAMA (prioritas pertama).
       Urutan fallback: Scheherazade New -> Noto Naskh Arabic
       -> Traditional Arabic (font sistem Windows) -> serif.
       Font ini HANYA berlaku untuk teks Arab; font UI Latin tidak berubah. */
    --font-arabic: "Scheherazade New", "Noto Naskh Arabic",
                   "Traditional Arabic", "Times New Roman", serif;
    --arabic-size: 30px;
    --arabic-line-height: 2.15;
    --arabic-letter-spacing: 0;
}

/* Fondasi reusable — berlaku untuk semua elemen ber-class ini.
   PENTING: memakai !important pada properti font inti agar TIDAK
   kalah oleh selector yang lebih spesifik (mis. `.learning-body`,
   `.form-control`, `.review-editor` yang memakai font-family: inherit).
   Ini aman karena hanya menyasar elemen ber-class Arab. */
.arabic-text,
.input-arabic,
.text-arabic,
.arabic-block,
.arabic-line,
[dir="rtl"].arabic-text,
[dir="rtl"].arabic-block,
[dir="rtl"].arabic-line {
    direction: rtl !important;
    text-align: right !important;
    unicode-bidi: isolate;
    font-family: var(--font-arabic) !important;
    font-size: var(--arabic-size) !important;
    line-height: var(--arabic-line-height) !important;
    letter-spacing: var(--arabic-letter-spacing) !important;
    /* Jangan pecah kata Arab di tengah huruf sambung. */
    word-break: normal;
    overflow-wrap: break-word;
    /* Harakat butuh ruang vertikal lebih. */
    padding-block: 2px;
    /* Rendering nyaman untuk harakat. */
    font-variant-ligatures: common-ligatures;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

/* Varian inline (mis. judul Arab di dalam baris teks Indonesia). */
.arabic-text.arabic-inline {
    display: inline-block;
    font-size: 1.15em !important;
    line-height: 1.9 !important;
    padding-block: 0;
}

/* Varian editor (input/textarea) — warisi fondasi di atas.
   font-family/font-size tetap dari fondasi (dengan !important),
   sehingga `font-family: inherit` pada .form-control TIDAK menang. */
.arabic-text.arabic-input,
textarea.input-arabic,
input.input-arabic {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    resize: vertical;
}

textarea.input-arabic {
    min-height: 200px;
}

.arabic-text.arabic-input:focus,
textarea.input-arabic:focus,
input.input-arabic:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 111, 66, 0.12);
}

/* Tampilan tabel: teks Arab di dalam sel. */
td.text-arabic,
td.arabic-text {
    font-size: 22px !important;
    line-height: 1.95 !important;
    padding-block: 6px;
}

/* Ukuran lebih kecil di layar sempit agar tidak meluber. */
@media (max-width: 768px) {
    :root {
        --arabic-size: 22px;
        --arabic-line-height: 2.05;
    }

    td.text-arabic,
    td.arabic-text {
        font-size: 19px;
        line-height: 1.9;
    }
}

.form-hint,
.field-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-error,
.field-error {
    font-size: 13px;
    color: var(--danger);
    margin-top: 4px;
}

/* Baris form berdampingan */
.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row > .form-group {
    flex: 1 1 200px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Form aksi inline di dalam tabel */
.inline-form {
    display: inline-block;
    margin: 0;
}

.actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

/* --------------------------------------------------
   Header Halaman & Filter
   -------------------------------------------------- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0;
    font-size: 22px;
}

.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px;
    margin-bottom: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filter-bar label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.filter-bar select {
    min-width: 180px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}

.empty-state {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

/* Baris statistik ringkas */
.stats-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* Preview singkat di dalam tabel */
.cell-preview {
    max-width: 180px;
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --------------------------------------------------
   Tombol
   -------------------------------------------------- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
}

.btn:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn-secondary {
    background: #e5e7eb;
    color: var(--text);
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #991b1b;
}

.btn-warning {
    background: var(--warning);
}

.btn-warning:hover {
    background: #92400e;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 13px;
}

.btn-logout {
    display: block;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
}

.btn-logout:hover {
    background: var(--danger);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --------------------------------------------------
   Tabel
   -------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

.table th,
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.table th {
    background: #f9fafb;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.table-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* --------------------------------------------------
   Badge & Alert
   -------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active,
.badge-published {
    background: #dcfce7;
    color: var(--success);
}

.badge-inactive {
    background: #f3f4f6;
    color: var(--text-muted);
}

.badge-draft {
    background: #fef3c7;
    color: var(--warning);
}

.badge-empty {
    background: #f3f4f6;
    color: var(--text-muted);
}

/* --------------------------------------------------
   Analisis AI per Subbab
   -------------------------------------------------- */
.analisis-panel {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
}

.analisis-panel h2 {
    margin: 0 0 4px;
    font-size: 20px;
}

.analisis-panel .hint {
    margin: 0 0 16px;
    color: var(--text-muted);
    font-size: 13px;
}

.analisis-jenis {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    padding: 12px 16px 16px;
    margin: 0 0 16px;
}

.analisis-jenis legend {
    padding: 0 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
}

.analisis-jenis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}

.analisis-jenis-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}

.analisis-jenis-item:hover {
    background: #f9fafb;
}

.analisis-jenis-label {
    flex: 1;
}

.analisis-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* --------------------------------------------------
   Overlay loading Analisis AI
   --------------------------------------------------
   Dipakai saat form Generate dikirim. Proses analisis
   berjalan dalam satu request PHP, jadi indikator ini
   hanya animasi tanpa persentase. Overlay baru hilang
   ketika halaman hasil (redirect) selesai dimuat.
   -------------------------------------------------- */
.ai-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17, 24, 39, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.ai-loading-overlay[hidden] {
    display: none;
}

.ai-loading-box {
    background: var(--surface, #fff);
    border-radius: 14px;
    padding: 28px 32px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

.ai-loading-spinner {
    width: 46px;
    height: 46px;
    margin: 0 auto 16px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--primary, #2563eb);
    border-radius: 50%;
    animation: ai-loading-spin 0.9s linear infinite;
}

@keyframes ai-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.ai-loading-title {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text, #111827);
}

.ai-loading-sub {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted, #6b7280);
}

/* Hormati preferensi pengguna yang mengurangi animasi:
   spinner tetap terlihat, tetapi tidak berputar cepat. */
@media (prefers-reduced-motion: reduce) {
    .ai-loading-spinner {
        animation-duration: 2.4s;
    }
}

.category-card {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.category-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.category-head h3 {
    margin: 0;
    font-size: 16px;
}

/* --------------------------------------------------
   Review — TAB 6 Analisis (per Subbab)
   -------------------------------------------------- */
.review-tabs {
    margin-top: 18px;
}

.review-tab-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 2px solid var(--border, #e5e7eb);
    margin-bottom: 16px;
}

.review-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border: 1px solid var(--border, #e5e7eb);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: #f9fafb;
    color: var(--text, #111827);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -2px;
}

.review-tab-btn:hover {
    background: #f3f4f6;
}

.review-tab-btn.is-active {
    background: var(--surface, #fff);
    border-color: var(--border, #e5e7eb);
    border-bottom: 2px solid var(--surface, #fff);
    color: var(--primary, #1d4ed8);
}

.review-tab-btn .badge {
    font-size: 11px;
    padding: 1px 7px;
}

.review-tab-panel {
    display: none;
}

.review-tab-panel.is-active {
    display: block;
}

.review-analysis-block {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.review-analysis-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.review-analysis-head h2 {
    margin: 0;
    font-size: 18px;
}

.review-preview-box {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 14px;
    background: #fcfcfd;
}

.review-analysis-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: #dcfce7;
    border-color: #86efac;
    color: #14532d;
}

.alert-danger,
.alert-error {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #7f1d1d;
}

.alert-warning {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #78350f;
}

.alert-info {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1e3a8a;
}

/* --------------------------------------------------
   Generate AI
   -------------------------------------------------- */
.generate-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.generate-panel h2 {
    margin: 0 0 6px;
    font-size: 16px;
}

.generate-parts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.batch-result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.batch-result h2 {
    margin: 0 0 6px;
    font-size: 16px;
}

.batch-summary {
    margin: 0 0 10px;
    color: var(--text-muted);
    font-size: 14px;
}

.batch-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 14px;
}

.batch-list li {
    padding: 4px 0;
    border-bottom: 1px dashed var(--border);
}

.batch-list li:last-child {
    border-bottom: none;
}

.batch-ok {
    color: var(--success);
}

.batch-fail {
    color: var(--danger);
}

/* --------------------------------------------------
   Halaman Review & Publish
   -------------------------------------------------- */
.review-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.review-breadcrumb {
    font-size: 14px;
}

.review-label {
    color: var(--text-muted);
}

.review-sep {
    margin: 0 6px;
    color: var(--text-muted);
}

.review-timestamps {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.review-arabic {
    background: #f8faf9;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
}

.review-arabic h2 {
    font-size: 16px;
    margin: 0 0 6px;
}

/* Blok teks Arab berkotak (Review, Pratinjau, dsb).
   RTL/font/ukuran diwarisi dari aturan terpusat di atas. */
.arabic-block {
    padding: 12px 0;
    border-bottom: 1px dashed var(--border);
}

.arabic-block:last-child {
    border-bottom: none;
}

/* --------------------------------------------------
   Pratinjau Materi Terformat (Review)
   -------------------------------------------------- */
.review-preview {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.review-preview h2 {
    font-size: 16px;
    margin: 0 0 6px;
}

.learning-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.learning-section:first-of-type {
    border-top: none;
    padding-top: 0;
}

.learning-title {
    font-size: 15px;
    color: var(--primary);
    margin: 0 0 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.learning-body {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text);
    /* PENTING: font Arab ditambahkan SETELAH font UI Latin.
       Berkat `unicode-range` pada @font-face Scheherazade New, HANYA
       huruf Arab yang memakai Scheherazade New — huruf Latin tetap
       memakai font UI normal (Segoe UI/Tahoma/Arial).
       Ini menangani teks Arab hasil AI yang TIDAK memakai penanda
       [[AR]] (mis. Nahwu/Shorof yang bercampur dalam satu baris
       dengan teks Indonesia). */
    font-family: "Segoe UI", Tahoma, Arial, sans-serif, var(--font-arabic);
}

.learning-body p {
    margin: 0 0 14px;
}

.learning-body p:last-child {
    margin-bottom: 0;
}

.learning-body .learning-h3 {
    font-size: 16px;
    margin: 18px 0 8px;
    color: var(--text);
}

.learning-body .learning-h4 {
    font-size: 14px;
    margin: 14px 0 6px;
    color: var(--text-muted);
}

.learning-body .learning-list {
    margin: 0 0 14px;
    padding-left: 22px;
}

.learning-body .learning-list li {
    margin-bottom: 6px;
}

.learning-body .learning-list li.sub-item {
    margin-left: 18px;
    list-style-type: circle;
}

/* Markdown inline: tebal, miring, kode */
.learning-body strong {
    font-weight: 700;
    color: var(--text);
}

.learning-body em {
    font-style: italic;
}

.learning-body code {
    font-family: "Consolas", "Monaco", "Courier New", monospace;
    font-size: 0.9em;
    background: #f1f5f3;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    color: #b03060;
}

/* Blok Arab di dalam materi pembelajaran (Nahwu/Shorof/Penjelasan).
   PENTING: font/RTL/ukuran ditegaskan ulang di sini agar TIDAK
   diwarisi dari `.learning-body` (yang memakai font Indonesia).
   Font Arab = Scheherazade New (via --font-arabic). */
.learning-body .arabic-block,
.learning-body .arabic-text {
    direction: rtl !important;
    text-align: right !important;
    font-family: var(--font-arabic) !important;
    font-size: var(--arabic-size) !important;
    line-height: var(--arabic-line-height) !important;
}

.learning-body .arabic-block {
    background: #f8faf9;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 12px 0;
}

.learning-body .arabic-line {
    margin-bottom: 6px;
}

.learning-body .arabic-line:last-child {
    margin-bottom: 0;
}

/* ============================================================
   TAB KATEGORI KONTEN (Konten Pembelajaran — arsitektur baru)
   Tab: Semua, Pengertian, Hukum, dst.
   ============================================================ */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0 22px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.category-tab {
    appearance: none;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.category-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.category-tab.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.category-panel {
    margin-top: 8px;
}

.category-panel + .category-panel {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px dashed var(--border);
}

.category-panel > .learning-title {
    font-size: 17px;
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 6px;
}

/* Teks Arab asli (TEKS ASLI) di dalam panel kategori. */
.category-panel .learning-body.arabic-text {
    direction: rtl !important;
    text-align: right !important;
    font-family: var(--font-arabic) !important;
    font-size: var(--arabic-size) !important;
    line-height: var(--arabic-line-height) !important;
    background: #f8faf9;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
}

.review-actions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* --------------------------------------------------
   Halaman Login
   -------------------------------------------------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #14261c 0%, #1d6f42 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-brand .brand-ar {
    font-size: 40px;
    color: var(--primary);
}

.login-brand .brand-id {
    color: var(--text-muted);
}

/* --------------------------------------------------
   Utilitas
   -------------------------------------------------- */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-2 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* --------------------------------------------------
   Halaman Pembagian Teks Kitab (Manual / AI)
   -------------------------------------------------- */
.page-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.card {
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

.card h2 {
    margin-top: 0;
    font-size: 18px;
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.card-header-row h2 {
    margin: 0;
}

.source-block {
    border-left: 3px solid var(--primary);
    padding: 8px 12px;
    margin-bottom: 12px;
    background: rgba(0, 0, 0, 0.02);
}

.source-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.mode-box {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
}

.mode-box h3 {
    margin-top: 0;
    font-size: 16px;
}

.part-row {
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.part-row label {
    display: block;
    font-size: 13px;
    margin-top: 8px;
    margin-bottom: 4px;
}

.part-row input[type="text"],
.part-row textarea {
    width: 100%;
}

.division-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.division-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.division-no {
    font-weight: 700;
}

.division-form label {
    display: block;
    font-size: 13px;
    margin-top: 8px;
    margin-bottom: 4px;
}

.division-form input[type="text"],
.division-form textarea {
    width: 100%;
}

.division-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* Catatan: aturan dasar .stats-bar sudah didefinisikan di atas (gap 8px).
   Blok ini hanya menambahkan varian kartu .stat di dalamnya. */
.stats-bar .stat {
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    min-width: 120px;
}

.stats-bar .stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

.stats-bar .stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
}

.required {
    color: var(--danger);
}

/* --------------------------------------------------
   Struktur Kitab Otomatis (AI)
   -------------------------------------------------- */

/* Textarea teks Arab (input struktur kitab). */
textarea.arabic-input {
    width: 100%;
    min-height: 220px;
    padding: 12px;
    font-family: 'Scheherazade New', 'Noto Naskh Arabic', 'Amiri', serif;
    font-size: 22px;
    line-height: 2;
    direction: rtl;
    text-align: right;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 8px;
    background: #fff;
    resize: vertical;
}

textarea.arabic-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Teks Arab utuh (halaman "Lihat Teks Kitab Utuh"). */
.arabic-fulltext {
    font-family: 'Scheherazade New', 'Noto Naskh Arabic', 'Amiri', serif;
    font-size: 24px;
    line-height: 2.2;
    text-align: right;
    padding: 16px;
    background: #fafaf9;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    max-height: 70vh;
    overflow-y: auto;
}

/* Sel tabel berisi teks Arab. */
.arabic-cell {
    font-family: 'Scheherazade New', 'Noto Naskh Arabic', 'Amiri', serif;
    font-size: 18px;
    text-align: right;
    white-space: nowrap;
}

/* Daftar statistik ringkasan struktur. */
.stat-list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}

.stat-list li {
    font-size: 14px;
    color: var(--text-muted);
}

.stat-list li strong {
    color: var(--text, #111827);
}

/* Daftar pohon struktur nyata. */
.tree-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border, #f3f4f6);
}

.tree-list li:last-child {
    border-bottom: none;
}

/* ============================================================
   REVIEW & PUBLISH PER BAB — PRESENTATION LAYER
   ============================================================
   Hanya untuk tampilan. Tidak mengubah data, database, atau
   proses AI. Font Arab memakai "Traditional Arabic" agar
   mengikuti gaya Input Teks Kitab.
   ============================================================ */

/* Kartu tiap jenis analisis (Terjemah Perlafadz, Terjemah Seluruh, dst). */
.review-analysis-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 20px 22px;
    margin-bottom: 22px;
}

.review-analysis-card:last-child {
    margin-bottom: 0;
}

.review-analysis-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.review-analysis-head h3 {
    margin: 0;
    font-size: 17px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.review-analysis-body {
    margin-bottom: 16px;
}

.review-analysis-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

/* Editor konten AI (textarea) — lega & nyaman dibaca. */
.review-analysis-card .review-editor {
    min-height: 300px;
    height: auto;
}

/* Pratinjau hasil render (Markdown rapi). */
.review-preview-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fbfcfb;
    padding: 16px 20px;
    line-height: 1.85;
}

.review-preview-box .learning-body {
    margin: 0;
}

/* ------------------------------------------------------------
   TERJEMAH PERLAFADZ — daftar SATU KOLOM, rata kanan (RTL)
   ------------------------------------------------------------
   Setiap baris: "lafadz : arti" rata kanan. TIDAK memakai layout
   dua kolom kiri-kanan. Tidak ada textarea/resizable.
   ------------------------------------------------------------ */
.perlafadz-list {
    display: block;
    direction: rtl;
    text-align: right;
}

.perlafadz-item {
    direction: rtl;
    text-align: right;
    padding: 4px 0;
    line-height: 2;
}

.perlafadz-arab {
    direction: rtl !important;
    text-align: right !important;
    font-family: "Traditional Arabic", serif !important;
    font-size: 30px !important;
    line-height: 2 !important;
    color: var(--text);
}

.perlafadz-sep {
    color: var(--text-muted);
}

.perlafadz-arti {
    direction: rtl;
    text-align: right;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 2;
    color: var(--text-muted);
}

/* Wadah pratinjau Perlafadz di halaman Review (satu kolom, rata kanan). */
.review-perlafadz-preview {
    direction: rtl;
    text-align: right;
    margin: 8px 0 16px;
}

/* ------------------------------------------------------------
   TERJEMAH PERLAFADZ BERBASIS CONTENT BLOCK
   ------------------------------------------------------------
   Setiap Content Block = satu unit: teks Arab block di atas,
   lalu hasil perlafadz block tersebut di bawahnya. Satu kolom,
   rata kanan (RTL). TIDAK memakai layout dua kolom kiri-kanan.
   ------------------------------------------------------------ */
.perlafadz-blocks {
    direction: rtl;
    text-align: right;
    margin: 8px 0 16px;
}

.perlafadz-block {
    direction: rtl;
    text-align: right;
    border-top: 1px solid var(--border);
    padding: 14px 0;
}

.perlafadz-block:first-child {
    border-top: 0;
    padding-top: 0;
}

.perlafadz-block-arab {
    direction: rtl !important;
    text-align: right !important;
    font-family: "Traditional Arabic", serif !important;
    font-size: 30px !important;
    line-height: 2 !important;
    color: var(--text);
    margin-bottom: 8px;
}

.perlafadz-block-heading {
    font-weight: 700;
    font-size: 34px !important;
}

.perlafadz-block .perlafadz-list {
    margin-top: 4px;
}

/* ------------------------------------------------------------
   TEKS ARAB DI DALAM KONTEN REVIEW (Terjemah/Syarah)
   ------------------------------------------------------------
   Hanya bagian Arab yang RTL; konten Indonesia tetap LTR.
   Font: "Traditional Arabic" (mengikuti Input Teks Kitab).
   ------------------------------------------------------------ */
.review-analysis-card .arabic-text,
.review-analysis-card .arabic-block,
.review-analysis-card .arabic-line {
    direction: rtl !important;
    text-align: right !important;
    font-family: "Traditional Arabic", serif !important;
    font-size: 28px !important;
    line-height: 2 !important;
}

.review-analysis-card .arabic-block {
    background: #f8faf9;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 12px 0;
}

.review-analysis-card .arabic-line {
    margin-bottom: 6px;
}

.review-analysis-card .arabic-line:last-child {
    margin-bottom: 0;
}

/* Editor textarea yang berisi teks Arab (mis. perlafadz). */
.review-analysis-card textarea.arabic-text {
    direction: rtl !important;
    text-align: right !important;
    font-family: "Traditional Arabic", serif !important;
    font-size: 26px !important;
    line-height: 2 !important;
}

@media (max-width: 768px) {
    .review-analysis-card {
        padding: 16px;
    }

    .perlafadz-arab,
    .review-analysis-card .arabic-text,
    .review-analysis-card .arabic-block,
    .review-analysis-card .arabic-line {
        font-size: 22px !important;
    }
}

/* ============================================================
   ANALYSIS TABS — PRESENTATION LAYER
   ============================================================
   Sistem tab sederhana (tanpa library) untuk menampilkan satu
   jenis analisis pada satu waktu. Hanya lapisan tampilan; tidak
   mengubah data, database, service AI, atau proses generate.
   ============================================================ */

.analysis-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 18px;
}

.analysis-tabs button {
    appearance: none;
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.analysis-tabs button:hover {
    background: #eef2ef;
    color: var(--text);
}

.analysis-tabs button.is-active {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--border);
    border-bottom: 2px solid var(--surface);
    margin-bottom: -2px;
}

.analysis-tab-panel {
    display: none;
}

.analysis-tab-panel.is-active {
    display: block;
}

/* Badge status kecil di dalam tab (mis. Draft / Published). */
.analysis-tabs button .tab-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
    background: #e5e7eb;
    color: #4b5563;
}

.analysis-tabs button .tab-badge.is-published {
    background: #dcfce7;
    color: #15803d;
}

.analysis-tabs button .tab-badge.is-draft {
    background: #fef3c7;
    color: #b45309;
}

@media (max-width: 768px) {
    .analysis-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .analysis-tabs button {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* ============================================================
   NAHWU — PRESENTATION LAYER (Review & Publish → tab Nahwu)
   ============================================================
   HANYA tampilan. Tidak mengubah data, database, prompt AI,
   OpenAIService, maupun mekanisme continuation.
   Setiap item analisis ditampilkan sebagai kartu terpisah agar
   teks Arab, istilah Nahwu, i'rab, dan penjelasan Indonesia
   mudah dibedakan.
   ============================================================ */

.nahwu-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* SATU LAFADZ = SATU UNIT ANALISIS (kartu terpisah). */
.nahwu-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fbfcfb;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* LAFADZ ARAB — JUDUL item, rata kanan / RTL.
   Hanya elemen ini yang RTL; detail di bawahnya tetap LTR. */
.nahwu-arabic {
    display: block;
    width: 100%;
    direction: rtl;
    text-align: right;
    font-family: "Noto Naskh Arabic", "Noto Sans Arabic", "Tajawal", Arial, sans-serif !important;
    font-size: 1.35rem;
    line-height: 2.1;
    color: var(--text);
    padding: 10px 14px;
    background: #f4f7f5;
    border: 1px solid var(--border);
    border-radius: 6px;
}

/* Detail analisis: "Kedudukan:" dan "Penjelasan:" masing-masing
   pada baris/blok sendiri (LTR, rata kiri). */
.nahwu-detail {
    display: flex;
    flex-direction: column;
    gap: 8px;
    direction: ltr;
    text-align: left;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
}

/* Baris "Kedudukan: ..." — satu baris utuh (label + nilai). */
.nahwu-row {
    display: block;
    direction: ltr;
    text-align: left;
}

.nahwu-label {
    font-weight: 700;
    color: var(--text);
}

.nahwu-value {
    color: var(--text);
}

/* Blok "Penjelasan: ..." — dipisahkan garis atas agar jelas
   sebagai unit tersendiri; boleh wrap ke beberapa baris. */
.nahwu-explanation {
    display: block;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    color: var(--text-muted);
    line-height: 1.75;
}

.nahwu-explanation .nahwu-label {
    color: var(--text);
}

/* ------------------------------------------------------------
   HASIL NAHWU/SHOROF FORMAT BARU (TERSTRUKTUR)
   ------------------------------------------------------------
   Setiap kalimat bernomor, setiap unsur pada baris tersendiri,
   dan Ringkasan Penjelasan dengan bullet "○". Pemisah baris
   antar unsur DIPERTAHANKAN (tidak digabung jadi satu paragraf).
   ------------------------------------------------------------ */
.nahwu-structured {
    display: flex;
    flex-direction: column;
    gap: 4px;
    direction: ltr;
    text-align: left;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
}

/* Judul kalimat utama (bernomor). */
.nahwu-structured-sentence {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-weight: 700;
    color: var(--text);
    margin-top: 10px;
}

/* Nomor kalimat utama ("1.", "2.", ...) — lebar tetap agar rapi. */
.nahwu-structured-num {
    flex: 0 0 auto;
    min-width: 1.6em;
    font-variant-numeric: tabular-nums;
    color: var(--primary, #1f6f54);
}

/* Teks kalimat utama (boleh memuat teks Arab). */
.nahwu-structured-sentence-text {
    flex: 1 1 auto;
    direction: rtl;
    text-align: right;
    unicode-bidi: plaintext;
}

/* Baris teks Arab murni (RTL). */
.nahwu-structured-arab {
    display: block;
    direction: rtl;
    text-align: right;
    font-family: "Noto Naskh Arabic", "Noto Sans Arabic", "Tajawal", Arial, sans-serif !important;
    font-size: 1.25rem;
    line-height: 2.1;
    color: var(--text);
    padding: 8px 12px;
    background: #f4f7f5;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin: 4px 0;
}

/* Satu unsur analisis = satu baris tersendiri. */
.nahwu-structured-item {
    display: block;
    direction: ltr;
    text-align: left;
    padding: 2px 0;
}

/* Jeda antar kalimat. */
.nahwu-structured-gap {
    display: block;
    height: 8px;
}

/* Blok Ringkasan Penjelasan (bullet ○). */
.nahwu-structured-summary {
    display: block;
    margin-top: 8px;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 6px;
}

.nahwu-structured-summary-line {
    display: block;
    direction: ltr;
    text-align: left;
    padding: 2px 0;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .nahwu-item {
        padding: 12px 14px;
    }

    .nahwu-arabic {
        font-size: 1.05rem;
    }

    .nahwu-structured-arab {
        font-size: 1.05rem;
    }
}

/* ------------------------------------------------------------
   REVIEW PER TAB — ANALISIS BERBASIS CONTENT BLOCK (Nahwu/Shorof)
   ------------------------------------------------------------
   Setiap Content Block = satu unit: teks Arab block di atas,
   lalu hasil analisis block tersebut di bawahnya. Satu kolom,
   rata kanan (RTL). TIDAK memakai layout dua kolom kiri-kanan.
   ------------------------------------------------------------ */
.analysis-blocks {
    direction: rtl;
    text-align: right;
    margin: 8px 0 16px;
}

.analysis-block {
    direction: rtl;
    text-align: right;
    border-top: 1px solid var(--border, #e5e7eb);
    padding: 14px 0;
}

.analysis-block:first-child {
    border-top: 0;
    padding-top: 0;
}

.analysis-block-arab {
    direction: rtl !important;
    text-align: right !important;
    font-family: "Traditional Arabic", serif !important;
    font-size: 30px !important;
    line-height: 2 !important;
    color: var(--text, #111827);
    margin-bottom: 8px;
}

.analysis-block-heading {
    font-weight: 700;
    font-size: 34px !important;
}

.analysis-block-result {
    direction: ltr;
    text-align: left;
    margin-top: 8px;
    /* ROMBAK TOTAL: hasil AI = FINAL TEXT. Pertahankan newline, blank line,
       nomor (1., 2., 3.), bullet "○", dan struktur apa adanya (1:1 dengan
       database). TIDAK ada parsing / rekonstruksi paragraph. */
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.75;
    color: var(--text, #111827);
}

/* Label kecil di atas hasil analisis (mis. "ANALISIS NAHWU"). */
.analysis-block-label {
    display: block;
    direction: ltr;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted, #6b7280);
    margin: 4px 0 10px;
}

/* Hasil Nahwu/Shorof di dalam block: kartu item netral (LTR),
   lafadz Arab tetap RTL via .nahwu-arabic, detail tetap LTR. */
.analysis-block-result .nahwu-list {
    direction: ltr;
    text-align: left;
}

.analysis-block-result .nahwu-arabic {
    direction: rtl;
    text-align: right;
}

.analysis-block-result .nahwu-detail,
.analysis-block-result .nahwu-row,
.analysis-block-result .nahwu-explanation,
.analysis-block-result .nahwu-value {
    direction: ltr;
    text-align: left;
}

/* ------------------------------------------------------------
   REVIEW PER TAB — UNIT KONTEKS (Terjemah/Syarah/Kesimpulan)
   ------------------------------------------------------------
   Satu unit konteks (Subbab bila ada, jika tidak BAB):
   Sumber Teks Arab (RTL) di atas, Hasil (LTR) di bawahnya.
   ------------------------------------------------------------ */
.review-context-source {
    direction: rtl;
    text-align: right;
    font-family: "Traditional Arabic", serif;
    font-size: 28px;
    line-height: 2;
    color: var(--text, #111827);
    background: #f9fafb;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius, 8px);
    padding: 14px 16px;
    margin-bottom: 16px;
    white-space: pre-wrap;
}

.review-context-result {
    direction: ltr;
    text-align: left;
    margin-bottom: 16px;
}

.review-subhead {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #6b7280);
    margin: 0 0 8px;
}

.review-rendered {
    direction: ltr;
    text-align: left;
    line-height: 1.75;
    color: var(--text, #111827);
}

/* ROMBAK TOTAL: FINAL TEXT dari database ditampilkan 1:1.
   Pertahankan newline, blank line, nomor, bullet "○", dan struktur apa adanya.
   TIDAK ada parsing Nahwu/Shorof, TIDAK ada rekonstruksi paragraph. */
.review-final-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.review-rendered .arabic-text {
    direction: rtl;
    text-align: right;
    font-family: "Traditional Arabic", serif;
    font-size: 26px;
    line-height: 2;
}

/* Info konteks (Kitab → Bab → Subbab) di atas tab. */
.review-context-info {
    background: #f9fafb;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius, 8px);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text, #111827);
}

.review-context-info .review-context-path {
    font-weight: 600;
}

.review-context-info .review-context-sep {
    color: var(--text-muted, #6b7280);
    margin: 0 6px;
}

/* --------------------------------------------------
   HALAMAN REVIEW & PUBLISH (daftar)
   -------------------------------------------------- */

/* Subjudul di bawah judul halaman. */
.page-subtitle {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    max-width: 820px;
}

/* Blok tiap kelompok review (Kategori, Level BAB, Konten Pembelajaran). */
.review-section {
    margin-bottom: 32px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.review-section-head {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.review-section-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.review-section-desc {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    max-width: 900px;
}

.review-section-desc code {
    padding: 1px 5px;
    border-radius: 4px;
    background: #f3f4f6;
    font-size: 12px;
}

/* Pembungkus tabel agar bisa digulir horizontal di layar kecil. */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table-wrap > .table {
    margin: 0;
    min-width: 720px;
}

/* Tabel review: padding & ukuran teks seragam. */
.table-review th,
.table-review td {
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
}

.table-review th {
    white-space: nowrap;
}

.table-review tbody tr:last-child td {
    border-bottom: 0;
}

.table-review tbody tr:hover {
    background: #fafbfc;
}

/* Lebar kolom standar. */
.table-review .col-no {
    width: 48px;
    text-align: center;
    color: var(--text-muted);
}

.table-review .col-status {
    width: 110px;
    white-space: nowrap;
}

.table-review .col-date {
    width: 130px;
    white-space: nowrap;
}

.table-review .col-summary {
    min-width: 180px;
    max-width: 260px;
}

.table-review .col-action {
    width: 96px;
    white-space: nowrap;
    text-align: right;
}

/* Ringkasan terpotong: satu baris dengan elipsis. */
.table-review .cell-preview {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tombol Review seragam. */
.table-review .btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    line-height: 1.4;
}

/* Varian tombol yang dipakai halaman review. */
.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-link {
    background: transparent;
    color: var(--primary);
    border-color: transparent;
    padding: 9px 10px;
}

.btn-link:hover {
    background: rgba(29, 111, 66, 0.08);
    color: var(--primary-dark);
    text-decoration: none;
}

/* Filter bar: field membungkus label + select. */
.filter-bar .filter-field {
    display: flex;
    flex-direction: column;
    min-width: 180px;
    flex: 1 1 180px;
}

.filter-bar .filter-field select {
    width: 100%;
}

.filter-bar .filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 1px;
}

@media (max-width: 768px) {
    .analysis-block-arab,
    .review-context-source {
        font-size: 24px !important;
    }

    .review-section {
        padding: 14px;
        margin-bottom: 24px;
    }

    .review-section-title {
        font-size: 16px;
    }

    .filter-bar .filter-field {
        flex: 1 1 100%;
        min-width: 0;
    }

    .filter-bar .filter-actions {
        width: 100%;
    }

    .filter-bar .filter-actions .btn {
        flex: 1 1 auto;
        text-align: center;
    }
}
