/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --nex-primary: #1E3A8A;
    --nex-accent: #38bdf8;
    --nex-text: #333;
    --nex-bg: #f9f9f9;
}

/* =========================================
   2. HEADING STYLES (DUAL MODE)
   ========================================= */

/* --- MODE 1: INLINE (Menyatu Paragraf - Editorial Style) --- */
.nex-inline-wrapper {
    margin-bottom: 1.5em;
    display: block;
}

.nex-inline-heading {
    display: inline !important;
    font-size: 1em !important;      /* Ukuran sama dengan 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 (Backup) */
.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: Paksa ukuran font normal agar rapi */
    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. CLUSTER NAV (NEXLINK INTEGRATION)
   ========================================= */
.nexindex-cluster-nav {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.08); /* Separator Halus */
    transition: opacity 0.4s ease-in-out;
}

/* Hide cluster if TOC collapsed */
.nexindex-container.collapsed .nexindex-cluster-nav {
    display: none;
}

.nexindex-cluster-label {
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    margin-bottom: 5px;
    display: block;
    font-weight: 700;
}

.nexindex-cluster-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.nexindex-cluster-list li {
    margin: 4px 0;
    line-height: 1.3;
}

.nexindex-cluster-link {
    text-decoration: none;
    color: inherit;
    font-size: 0.9em;
    font-weight: 600; /* Sedikit lebih tebal dari link biasa */
    transition: color 0.2s;
    display: block;
}

.nexindex-cluster-link:hover {
    color: var(--nex-primary);
}

/* =========================================
   5. 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;
}
/* Cluster Nav Dark Mode Override */
.is-style-midnight .nexindex-cluster-nav { border-top: 1px solid rgba(255,255,255,0.1); }
.is-style-midnight .nexindex-cluster-link { color: #94a3b8; }
.is-style-midnight .nexindex-cluster-link:hover { color: #38bdf8; }

/* 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);
}

/* =========================================
   6. WIDGETS
   ========================================= */

.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;
}

/* =========================================
   7. MOBILE OPTIMIZATION
   ========================================= */

@media (max-width: 768px) {
    /* 1. JIKA MODE = ICON */
    .nex-mode-mobile-icon { display: none !important; } /* Sembunyikan TOC utama */
    
    /* 2. JIKA MODE = BAR */
    .nex-mode-mobile-bar { display: none !important; } /* Sembunyikan TOC utama */

    /* 3. JIKA MODE = STATIC (Biarkan TOC muncul, jangan hide) */

    /* 4. JIKA MODE = FLOAT KIRI / KANAN */
    .nex-mode-mobile-float-left,
    .nex-mode-mobile-float-right {
        display: block !important;
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: min(240px, calc(100vw - 24px));
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        margin: 0;
        z-index: 9992;
        box-shadow: 0 10px 26px rgba(0,0,0,0.18);
    }

    .nex-mode-mobile-float-left {
        left: 8px;
    }

    .nex-mode-mobile-float-right {
        right: 8px;
    }
    
    /* Logic Tampilan Widget: PHP hanya merender widget yang dipilih user */
    .nex-floating-btn, 
    .nex-floating-bar, 
    .nex-offcanvas-menu {
        display: flex; 
    }

    /* Pastikan widget mobile tidak muncul untuk mode float kiri/kanan */
    .nex-mode-mobile-float-left ~ #nex-mobile-widget,
    .nex-mode-mobile-float-right ~ #nex-mobile-widget,
    .nex-mode-mobile-float-left ~ #nex-offcanvas,
    .nex-mode-mobile-float-right ~ #nex-offcanvas {
        display: none !important;
    }

    .nex-offcanvas-menu { display: block; } /* Reset drawer display */

    /* Styling Drawer List */
    .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; }

    /* Desktop Layout Modes */
    .nex-mode-desktop-static {
        position: relative;
        inset: auto;
        width: auto;
        max-width: 100%;
        z-index: auto;
    }

    .nex-mode-desktop-float-right,
    .nex-mode-desktop-float-left,
    .nex-mode-desktop-float-bottom {
        position: fixed;
        width: min(360px, calc(100vw - 32px));
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        z-index: 9992;
        margin: 0;
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
    }

    .nex-mode-desktop-float-right {
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
    }

    .nex-mode-desktop-float-left {
        left: 16px;
        top: 50%;
        transform: translateY(-50%);
    }

    .nex-mode-desktop-float-bottom {
        left: 50%;
        bottom: 16px;
        transform: translateX(-50%);
    }

    /* Float Left/Right: make collapsed state slim + vertical title */
    .nex-mode-desktop-float-left,
    .nex-mode-desktop-float-right {
        transition: width 0.25s ease, padding 0.25s ease;
    }

    .nex-mode-desktop-float-left.collapsed,
    .nex-mode-desktop-float-right.collapsed {
        width: 56px;
        padding: 10px 8px;
        overflow: hidden;
    }

    .nex-mode-desktop-float-left.collapsed .nexindex-header,
    .nex-mode-desktop-float-right.collapsed .nexindex-header {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        margin-bottom: 0;
    }

    .nex-mode-desktop-float-right.collapsed .nexindex-title {
        writing-mode: vertical-rl;
        text-orientation: mixed;
        line-height: 1;
        white-space: nowrap;
        font-size: 0.9em;
    }

    .nex-mode-desktop-float-left.collapsed .nexindex-title {
        writing-mode: vertical-rl;
        text-orientation: mixed;
        line-height: 1;
        white-space: nowrap;
        font-size: 0.9em;
        transform: rotate(180deg);
        transform-origin: center;
    }

    .nex-mode-desktop-float-left.collapsed .nexindex-toggle,
    .nex-mode-desktop-float-right.collapsed .nexindex-toggle {
        width: 18px;
        height: 18px;
    }
}

/* =========================================
   8. CURSOR-FOLLOWING VERTICAL POPUP
   ========================================= */

#nex-cursor-popup {
    position: fixed;
    right: 0;
    top: 50%;
    z-index: 9998;
    transform: translateY(-50%);
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

#nex-cursor-popup.active {
    opacity: 1;
    visibility: visible;
}

.nex-cursor-popup-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.90);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-radius: 10px 0 0 10px;
    padding: 14px 10px;
    max-height: 65vh;
    overflow: hidden;
    box-shadow: -6px 0 28px rgba(0, 0, 0, 0.22);
    transition: max-height 0.3s ease, box-shadow 0.2s ease;
}

.nex-cursor-popup-inner:hover {
    overflow-y: auto;
    box-shadow: -8px 0 36px rgba(0, 0, 0, 0.32);
}

.nex-cursor-popup-inner::-webkit-scrollbar { width: 3px; }
.nex-cursor-popup-inner::-webkit-scrollbar-track { background: transparent; }
.nex-cursor-popup-inner::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Individual TOC links — text rotated vertically (menyamping) */
.nex-cursor-popup-link {
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    color: rgba(203, 213, 225, 0.75);
    text-decoration: none;
    font-size: 11px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    max-height: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s, font-weight 0.2s;
    padding: 2px 0;
    flex-shrink: 0;
    position: relative;
}

.nex-cursor-popup-link:hover {
    color: #fff;
    text-decoration: none;
}

.nex-cursor-popup-link.nex-popup-active {
    color: #38bdf8;
    font-weight: 700;
}

/* Sub-level heading dimming */
.nex-cursor-popup-link[data-level="3"] {
    opacity: 0.70;
    font-size: 10px;
}
.nex-cursor-popup-link[data-level="4"] {
    opacity: 0.55;
    font-size: 9px;
}

/* Dot separator between items */
.nex-cursor-popup-sep {
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    flex-shrink: 0;
}

/* Floating label tooltip (shows full heading on hover) */
.nex-cursor-popup-tooltip {
    position: fixed;
    right: 50px;
    background: rgba(15, 23, 42, 0.96);
    color: #fff;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    transform: translateY(-50%);
}

.nex-cursor-popup-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

/* Hide on touch/mobile devices */
@media (max-width: 768px) {
    #nex-cursor-popup { display: none !important; }
}