/**
 * Chapter Blocks - Frontend Styles
 */

/* ========================================
   CHAPTER CONTAINER
   ======================================== */
.chapter-dropdown {
    margin: 40px 0;
    background: rgba(30, 41, 59, 0.3);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(59, 130, 246, 0.05);
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
}

.chapter-dropdown:hover {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.chapter-dropdown-card {
    background: transparent;
}

/* ========================================
   CHAPTER HEADER - Orange Gradient
   ======================================== */
.chapter-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 40px;
    gap: 40px;
    background: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);
    position: relative;
}

.chapter-dropdown-header-text {
    flex: 1;
    color: #ffffff;
}

/* Chapter Number */
.chapter-dropdown-super_title {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0 0 12px 0;
    color: #ffffff;
    opacity: 0.95;
}

/* Chapter Title */
.chapter-dropdown-main_title {
    font-size: 32px !important;
    font-weight: 700 !important;
    line-height: 1.3 !important;
    margin: 0 0 24px 0 !important;
    color: #ffffff !important;
    padding-left: 0 !important;
}

.chapter-dropdown-main_title::before {
    display: none !important;
}

/* Bullet Points with Checkmarks */
.chapter-dropdown-bullets {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.chapter-dropdown-bullets li {
    position: relative;
    padding-left: 28px;
    margin-bottom: 10px;
    font-size: 15px;
    line-height: 1.5;
    color: #ffffff;
}

.chapter-dropdown-bullets li::before {
    content: "✓";
    position: absolute;
    left: 0;
    font-weight: bold;
    color: #ffffff;
    font-size: 18px;
}

/* Chapter Image */
.chapter-dropdown-header-image {
    flex-shrink: 0;
    width: 280px;
    max-width: 35%;
}

.chapter-dropdown-header-image img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
}

/* ========================================
   TOGGLE BUTTONS - ULTIMATE FIX
   ======================================== */
.chapter_dropdown-collapse {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 40px;
    background: rgba(248, 250, 252, 0.03);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.chapter_dropdown-collapse:hover {
    background: rgba(59, 130, 246, 0.05);
}

.chapter_dropdown-collapse:focus {
    /*outline: 2px solid #3b82f6;*/
    outline-offset: -2px;
}

.chapter_dropdown-collapse-text {
    font-weight: 600;
    font-size: 15px;
    color: #e2e8f0;
}

.chapter_dropdown-collapse-icons {
    display: flex;
    align-items: center;
}

.chapter_dropdown-collapse-icons .material-icons {
    font-size: 24px;
    color: #3b82f6;
    transition: transform 0.3s ease;
}

/* ========================================
   CRITICAL: Button Visibility Logic
   ======================================== */

/* RULE 1: Hide ALL close buttons inside content by default */
.chapter_dropdown-content .chapter_dropdown-collapse {
    display: none !important;
}

/* RULE 2: Show close button ONLY when content has 'show' class */
/*.chapter_dropdown-content.show .chapter_dropdown-collapse {
    display: flex !important;
}*/

/* RULE 3: Show open button (can-toggle) by default */
.chapter_dropdown-collapse.can-toggle {
    display: flex !important;
}

/* RULE 4: Hide open button when content is open */
.chapter_dropdown-content.show ~ .chapter_dropdown-collapse.can-toggle,
.chapter_dropdown-content.show + .chapter_dropdown-collapse.can-toggle {
    display: none !important;
}

/* ========================================
   CHAPTER CONTENT
   ======================================== */
.chapter_dropdown-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    background: transparent;
}

/*.chapter_dropdown-content.show {
    max-height: 15000px;
    transition: max-height 0.6s ease-in;
}*/

.chapter_dropdown-content.show {
    max-height: none !important;  
    overflow: visible !important;  
    transition: none;  
}

.chapter-inner-content {
    padding: 40px;
    color: #e2e8f0;
    font-size: 18px;
    line-height: 1.8;
}

/* Content Typography */
.chapter-inner-content h2 {
    font-size: 38px !important;
    font-weight: 800 !important;
    margin: 56px 0 28px !important;
    padding-left: 24px !important;
    background: linear-gradient(135deg, #ffffff 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
}

.chapter-inner-content h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 70%;
    background: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);
    border-radius: 3px;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.chapter-inner-content h3 {
    font-size: 28px !important;
    font-weight: 700 !important;
    margin: 40px 0 20px !important;
    padding-left: 16px !important;
    background: linear-gradient(135deg, #ffffff 0%, #0ea5e9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
}

.chapter-inner-content h3::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);
    border-radius: 2px;
}

.chapter-inner-content h4 {
    font-size: 22px !important;
    font-weight: 600 !important;
    margin: 32px 0 16px !important;
    color: #60a5fa !important;
}

.chapter-inner-content p {
    margin-bottom: 28px;
    color: #e2e8f0;
}

.chapter-inner-content ul,
.chapter-inner-content ol {
    margin: 28px 0;
    padding-left: 32px;
    color: #e2e8f0;
}

.chapter-inner-content li {
    margin-bottom: 14px;
    line-height: 1.7;
}

.chapter-inner-content a {
    color: #60a5fa;
    text-decoration: underline;
    transition: color 0.3s ease;
}

.chapter-inner-content a:hover {
    color: #3b82f6;
}

.chapter-inner-content blockquote {
    margin: 40px 0;
    padding: 28px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, rgba(14, 165, 233, 0.05) 100%);
    border-left: 4px solid #3b82f6;
    border-radius: 12px;
    font-style: italic;
    color: #94a3b8;
}

.chapter-inner-content img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 20px 0;
}

.chapter-inner-content code {
    background: rgba(15, 23, 42, 0.5);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #60a5fa;
}

.chapter-inner-content pre {
    background: rgba(15, 23, 42, 0.8);
    padding: 20px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 20px 0;
}

.chapter-inner-content table {
    width: 100%;
    margin: 32px 0;
    border-collapse: collapse;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(30, 41, 59, 0.5);
}

.chapter-inner-content th {
    background: rgba(59, 130, 246, 0.1);
    color: #ffffff;
    padding: 16px;
    text-align: left;
    font-weight: 600;
}

.chapter-inner-content td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #e2e8f0;
}

/* ========================================
   TABLE OF CONTENTS
   ======================================== */
.chapters-toc-widget {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(59, 130, 246, 0.1);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 30px;
}

.toc-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 12px 0;
    color: #ffffff;
}

.toc-divider {
    height: 3px;
    width: 60px;
    background: #3b82f6;
    margin-bottom: 20px;
    border-radius: 2px;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: toc-counter;
}

.toc-item {
    margin-bottom: 12px;
    counter-increment: toc-counter;
}

.toc-item::before {
    content: counter(toc-counter) ". ";
    font-weight: 700;
    color: #ffffff;
}

.toc-link {
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.2s ease;
    font-size: 15px;
    line-height: 1.5;
}

.toc-link:hover {
    color: #3b82f6;
}

.toc-item.active .toc-link {
    color: #ffffff;
    font-weight: 600;
}

.toc-item.active::before {
    color: #3b82f6;
}

/* ========================================
   DARK MODE (Light Theme)
   ======================================== */
body.dark-mode .chapter-dropdown {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(59, 130, 246, 0.2);
}

body.dark-mode .chapter_dropdown-collapse {
    background: rgba(248, 250, 252, 1);
    border-top-color: rgba(203, 213, 225, 0.3);
}

body.dark-mode .chapter_dropdown-collapse:hover {
    background: rgba(241, 245, 249, 1);
}

body.dark-mode .chapter_dropdown-collapse-text {
    color: #0f172a;
}

body.dark-mode .chapter-inner-content {
    color: #334155;
}

body.dark-mode .chapter-inner-content p,
body.dark-mode .chapter-inner-content li {
    color: #334155;
}

body.dark-mode .chapter-inner-content h2,
body.dark-mode .chapter-inner-content h3 {
    background: linear-gradient(135deg, #0f172a 0%, #3b82f6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.dark-mode .chapter-inner-content h4 {
    color: #3b82f6 !important;
}

body.dark-mode .chapter-inner-content blockquote {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(14, 165, 233, 0.08) 100%);
    color: #475569;
}

body.dark-mode .chapter-inner-content code {
    background: rgba(248, 250, 252, 1);
    color: #3b82f6;
}

body.dark-mode .chapter-inner-content table {
    background: rgba(248, 250, 252, 1);
}

body.dark-mode .chapter-inner-content th {
    background: rgba(59, 130, 246, 0.08);
    color: #0f172a;
}

body.dark-mode .chapter-inner-content td {
    border-bottom-color: rgba(203, 213, 225, 0.3);
    color: #334155;
}

body.dark-mode .chapters-toc-widget {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(59, 130, 246, 0.3);
}

body.dark-mode .toc-title {
    color: #0f172a;
}

body.dark-mode .toc-item::before {
    color: #0f172a;
}

body.dark-mode .toc-link {
    color: #64748b;
}

body.dark-mode .toc-item.active .toc-link {
    color: #0f172a;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 992px) {
    .chapter-dropdown-header {
        padding: 30px;
        gap: 30px;
    }
    
    .chapter-dropdown-main_title {
        font-size: 28px !important;
    }
    
    .chapter-dropdown-header-image {
        width: 240px;
    }
}

@media (max-width: 768px) {
    .chapter-dropdown {
        margin: 30px 0;
        border-radius: 16px;
    }
    
    .chapter-dropdown-header {
        flex-direction: column;
        padding: 24px;
        text-align: center;
    }
    
    .chapter-dropdown-main_title {
        font-size: 24px !important;
        margin-bottom: 20px !important;
    }
    
    .chapter-dropdown-super_title {
        font-size: 13px;
    }
    
    .chapter-dropdown-bullets {
        text-align: left;
    }
    
    .chapter-dropdown-bullets li {
        font-size: 14px;
    }
    
    .chapter-dropdown-header-image {
        width: 100%;
        max-width: 280px;
        margin-top: 20px;
    }
    
    .chapter_dropdown-collapse {
        padding: 16px 20px;
        font-size: 14px;
    }
    
    .chapter-inner-content {
        padding: 24px 20px;
        font-size: 16px;
    }
    
    .chapter-inner-content h2 {
        font-size: 24px !important;
    }
    
    .chapter-inner-content h3 {
        font-size: 20px !important;
    }
}

@media (max-width: 480px) {
    .chapter-dropdown {
        margin: 20px -15px;
        border-radius: 0;
    }
    
    .chapter-dropdown-header {
        padding: 35px;
    }
    
    .chapter-dropdown-main_title {
        font-size: 20px !important;
    }
    
    .chapter-inner-content {
        padding: 20px 15px;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .chapter-dropdown {
        box-shadow: none;
        page-break-inside: avoid;
        border: 1px solid #ddd;
    }
    
    .chapter_dropdown-collapse {
        display: none !important;
    }
    
    .chapter_dropdown-content {
        max-height: none !important;
        display: block !important;
    }
}

/* Material Icons fallback */
.material-icons {
    font-family: 'Material Icons', sans-serif;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    display: inline-block;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
}

/*.material-icons:not([class*="material-icons-"]):before {
    content: attr(data-icon);
}*/

/* ========================================
   FLOATING CLOSE BUTTON (Bottom Right)
   ======================================== */
.chapter-close-floating {
    position: sticky;
    bottom: 24px;
    right: 24px;
    margin-left: auto;
    width: fit-content;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    transition: all 0.3s ease;
    z-index: 100;
    margin-top: 40px;
    margin-right: 24px;
}

.chapter-close-floating:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(59, 130, 246, 0.6);
    background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
}

.chapter-close-floating:active {
    transform: translateY(0);
}

.chapter-close-floating .material-icons {
    font-size: 20px;
}

.chapter-close-floating .close-text {
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Show floating button only when chapter is open */
.chapter_dropdown-content.show .chapter-close-floating {
    display: flex;
}

/* Make it pulse on first open to draw attention */
@keyframes pulseButton {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.chapter_dropdown-content.show .chapter-close-floating {
    animation: pulseButton 2s ease-in-out 1;
}

/* Focus state for accessibility */
.chapter-close-floating:focus {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 3px;
}

/* ========================================
   RESPONSIVE - Floating Button
   ======================================== */
@media (max-width: 768px) {
    .chapter-close-floating {
        bottom: 16px;
        right: 16px;
        padding: 12px 20px;
        font-size: 13px;
        margin-right: 16px;
    }
    
    .chapter-close-floating .close-text {
        display: none; /* Hide text on mobile, show only icon */
    }
    
    .chapter-close-floating {
        padding: 12px;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        justify-content: center;
    }
}

/* Dark mode support */
body.dark-mode .chapter-close-floating {
    background: linear-gradient(135deg, #1e40af 0%, #0c4a6e 100%);
    box-shadow: 0 8px 24px rgba(30, 64, 175, 0.4);
}

body.dark-mode .chapter-close-floating:hover {
    background: linear-gradient(135deg, #0c4a6e 0%, #1e40af 100%);
    box-shadow: 0 12px 32px rgba(30, 64, 175, 0.6);
}