/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --nex-primary: #1E3A8A;
    --nex-accent: #38bdf8;
    --nex-text: #333;
    --nex-bg: #f9f9f9;
}

/* =========================================
   2. HEADING STYLES (DUAL MODE)
   ========================================= */

/* --- MODE 1: INLINE (Editorial Style) --- */
.nex-inline-wrapper {
    margin-bottom: 1.5em;
    display: block;
}

.nex-inline-heading {
    display: inline !important;
    font-size: 1em !important;      /* Ukuran 1em (Sama Paragraf) */
    line-height: inherit !important;
    margin: 0 !important;
    padding: 0 !important;
    font-weight: 800 !important;
    color: var(--nex-primary);
}

.nex-inline-content { 
    display: inline; 
}

/* Styling Span Asli Inline */
.nex-inline-h2, 
.nex-inline-h3, 
.nex-inline-h4 {
    font-weight: 800;
    color: var(--nex-primary);
    font-size: 1em !important;
}

/* --- MODE 2: STANDARD BLOCK (Baris Sendiri) --- */
h2.nex-standard-heading, 
h3.nex-standard-heading, 
h4.nex-standard-heading,
span.nex-standard-h2, 
span.nex-standard-h3, 
span.nex-standard-h4 {
    display: block !important;
    margin-top: 1.5em !important;
    margin-bottom: 0.5em !important;
    font-weight: 800 !important;
    color: #222;
    border-bottom: 2px solid #eee;
    
    /* KUNCI PERBAIKAN: Paksa ukuran 1em agar sama dengan teks biasa */
    font-size: 1em !important; 
    line-height: 1.5 !important;
}

/* =========================================
   3. TOC CONTAINER (DESKTOP DEFAULT)
   ========================================= */

.nexindex-container {
    margin-bottom: 2em;
    padding: 10px 15px;
    border-radius: 6px;
    font-family: inherit;
    position: relative;
    box-sizing: border-box;
    width: auto; 
    max-width: 100%;
    display: block;
    font-size: 0.95em;
}

.nexindex-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 0; 
    cursor: pointer;
}

.nexindex-container:not(.collapsed) .nexindex-header {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.nexindex-title {
    font-weight: 700;
    font-size: 1em;
    margin: 0;
}

/* Toggle Button */
.nexindex-toggle {
    background: none;
    border: none;
    cursor: pointer;
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nexindex-toggle::after {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-right: 2px solid #666;
    border-bottom: 2px solid #666;
    transform: rotate(45deg);
    transition: transform 0.3s ease;
    margin-top: -3px;
}

.nexindex-container.collapsed .nexindex-toggle::after {
    transform: rotate(-135deg);
    margin-top: 3px;
}

/* List Items */
.nexindex-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-height: 3000px;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out;
    opacity: 1;
}

.nexindex-container.collapsed .nexindex-list {
    max-height: 0;
    opacity: 0;
}

.nexindex-item {
    margin: 3px 0;
    line-height: 1.3;
}

.nexindex-link {
    text-decoration: none;
    color: inherit;
    font-size: 0.9em;
    transition: color 0.2s;
    display: inline-block;
}

.nexindex-link:hover {
    color: var(--nex-primary);
    text-decoration: underline;
}

/* Indentasi Level */
.nexindex-level-3 { padding-left: 15px; font-size: 0.9em; }
.nexindex-level-4 { padding-left: 30px; font-size: 0.85em; }

/* Active State (ScrollSpy) */
.nexindex-item.active > .nexindex-link {
    font-weight: 700;
    color: var(--nex-primary);
}

/* =========================================
   4. SKINS (PRESETS)
   ========================================= */

/* Skin: Glassmorphism */
.is-style-glass {
    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

/* Skin: Notion */
.is-style-notion {
    background: transparent;
    padding-left: 0;
    padding-right: 0;
    border: none;
}
.is-style-notion .nexindex-header {
    border-bottom: 2px solid #333;
    padding-bottom: 5px;
}

/* Skin: Midnight SaaS */
.is-style-midnight {
    background: #0F172A;
    color: #f1f5f9;
    border: 1px solid #1E293B;
}
.is-style-midnight .nexindex-title { color: #fff; }
.is-style-midnight .nexindex-link { color: #cbd5e1; }
.is-style-midnight .nexindex-link:hover, 
.is-style-midnight .nexindex-item.active > .nexindex-link { color: #38bdf8; }
.is-style-midnight .nexindex-toggle::after { border-color: #cbd5e1; }
.is-style-midnight .nexindex-container:not(.collapsed) .nexindex-header {
    border-bottom: 1px solid #334155;
}

/* Skin: Minimal */
.is-style-minimal {
    background: #fff;
    border: 1px solid #eee;
    border-left: 4px solid var(--nex-primary);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Skin: Card */
.is-style-card {
    background: #fff;
    border: 1px solid #e5e5e5;
    box-shadow: 0 5px 10px -3px rgba(0, 0, 0, 0.1);
}

/* =========================================
   5. PROGRESS BAR & MOBILE WIDGET
   ========================================= */

.nex-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 4px;
    background: var(--nex-primary);
    width: 0%;
    z-index: 99999;
    transition: width 0.1s linear;
}

/* Floating Button (Icon) */
.nex-floating-btn {
    position: fixed;
    bottom: 30px;
    right: 20px;
    width: 45px;
    height: 45px;
    background: var(--nex-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 9990;
    transition: transform 0.2s;
    -webkit-tap-highlight-color: transparent;
    display: none; /* Hidden by default */
}
.nex-floating-btn:active { transform: scale(0.9); }

/* Floating Bar (Bottom Panel) */
.nex-floating-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: var(--nex-primary);
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 9990;
    font-size: 0.95em;
    font-weight: 600;
    display: none; /* Hidden by default */
}
.nex-bar-text { flex-grow: 1; text-align: center; }

/* Off-Canvas Drawer */
.nex-offcanvas-menu {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    background: white;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 15px 20px;
    box-shadow: 0 -5px 40px rgba(0,0,0,0.15);
    transition: bottom 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 9991;
    max-height: 80vh;
    overflow-y: auto;
    box-sizing: border-box;
    display: none; /* Hidden by default */
}

.nex-offcanvas-menu.open { bottom: 0; }

.nex-offcanvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

#nex-close-offcanvas {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #333;
    padding: 0 5px;
}

/* =========================================
   6. MOBILE OPTIMIZATION
   ========================================= */

@media (max-width: 768px) {
    /* Sembunyikan TOC Utama */
    #nexindex-toc { display: none !important; }

    /* Logic: Widget akan muncul (display:flex) jika dirender oleh PHP */
    .nex-floating-btn, 
    .nex-floating-bar, 
    .nex-offcanvas-menu {
        display: flex; 
    }
    .nex-offcanvas-menu { display: block; } /* Reset drawer display */

    .nex-offcanvas-menu .nexindex-list { max-height: none !important; opacity: 1 !important; }
    .nex-offcanvas-menu .nexindex-item { margin: 8px 0; border-bottom: 1px dashed #eee; padding-bottom: 5px; }
    .nex-offcanvas-menu .nexindex-link { font-size: 1rem; color: #333; }
}

@media (min-width: 769px) {
    .nex-floating-btn, .nex-floating-bar, .nex-offcanvas-menu { display: none !important; }
    #nexindex-toc { display: block !important; }
}