/* Book Solutions Frontend - Enhanced Professional Design */

#book-solutions-frontend {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f8fafc;
    min-height: 100vh;
    line-height: 1.6;
}

/* Book Selector - Enhanced Design */
.bs-book-selector {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 40px;
    margin-bottom: 30px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    text-align: center;
}

.bs-book-selector h3 {
    margin: 0 0 25px 0;
    color: #2d3748;
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #2b6cb0 0%, #3182ce 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#frontend-book-select {
    width: 100%;
    max-width: 450px;
    margin: 0 auto;
    display: block;
    padding: 16px 20px;
    border: 2px solid #cbd5e0;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    transition: all 0.3s ease;
    color: #2d3748;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

#frontend-book-select:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 4px rgba(66, 153, 225, 0.15), 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

/* Book Display */
#bs-book-display {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Enhanced Book Info with Cover Display */
#bs-book-info {
    background: linear-gradient(135deg, #2b6cb0 0%, #3182ce 100%);
    color: white;
    padding: 50px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(43, 108, 176, 0.2);
    position: relative;
    overflow: hidden;
}

#bs-book-info::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="20" cy="20" r="1" fill="white" opacity="0.05"/><circle cx="80" cy="80" r="1" fill="white" opacity="0.05"/><circle cx="40" cy="60" r="1" fill="white" opacity="0.03"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    pointer-events: none;
}

.bs-book-info-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    gap: 30px;
}

.bs-book-cover-display {
    flex-shrink: 0;
    width: 140px;
    height: 200px;
    border: 2px solid rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.bs-book-cover-display img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bs-book-cover-placeholder {
    font-size: 48px;
    color: rgba(255,255,255,0.7);
}

.bs-book-details {
    flex: 1;
}

.bs-book-title {
    font-size: 32px;
    font-weight: 800;
    margin: 0 0 12px 0;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.bs-book-author {
    font-size: 20px;
    opacity: 0.95;
    margin: 0 0 20px 0;
    font-weight: 500;
    font-style: italic;
}

.bs-book-description {
    font-size: 16px;
    line-height: 1.7;
    opacity: 0.9;
    margin: 0 0 20px 0;
}

.bs-book-meta {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    flex-wrap: wrap;
}

.bs-book-meta-item {
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 18px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Chapters List */
#bs-chapters-list {
    margin-bottom: 30px;
}

.bs-chapters-header {
    margin-bottom: 30px;
    text-align: center;
}

.bs-chapters-header h3 {
    color: #2d3748;
    font-size: 28px;
    margin: 0;
    font-weight: 700;
    position: relative;
    display: inline-block;
}

.bs-chapters-header h3:after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 4px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    border-radius: 2px;
}

.bs-chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

.bs-chapter-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 28px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    overflow: hidden;
}

.bs-chapter-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.bs-chapter-card:hover::before {
    transform: scaleX(1);
}

.bs-chapter-card:hover {
    border-color: #4299e1;
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.15);
}

.bs-chapter-card.active {
    border-color: #4299e1;
    background: linear-gradient(135deg, #f7fafc 0%, #ebf8ff 100%);
    box-shadow: 0 8px 24px rgba(66, 153, 225, 0.2);
    transform: translateY(-2px);
}

.bs-chapter-card.active::before {
    transform: scaleX(1);
}

.bs-chapter-number {
    position: absolute;
    top: -12px;
    right: -12px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 4px 16px rgba(66, 153, 225, 0.4);
    border: 3px solid white;
}

.bs-chapter-title {
    font-size: 20px;
    font-weight: 700;
    color: #2d3748;
    margin: 0 0 15px 0;
    padding-right: 40px;
    line-height: 1.3;
}

.bs-chapter-problems {
    color: #718096;
    font-size: 15px;
    margin: 0;
    font-weight: 500;
}

/* Problems List */
.bs-problems-header {
    margin-bottom: 30px;
    text-align: center;
}

.bs-problems-header h3 {
    color: #2d3748;
    font-size: 28px;
    margin: 0;
    font-weight: 700;
    position: relative;
    display: inline-block;
}

.bs-problems-header h3:after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 4px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    border-radius: 2px;
}

/* Solution Header - Remove Container Box */
.bs-solution-header {
    background: transparent;
    color: #2d3748;
    padding: 30px 0;
    border-bottom: none;
}

/* Problems Grid - No Container, Free Display like Chapters */
.bs-problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.bs-problem-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 28px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    overflow: hidden;
}

.bs-problem-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.bs-problem-card:hover::before {
    transform: scaleX(1);
}

.bs-problem-card:hover {
    border-color: #48bb78;
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.15);
}

.bs-problem-card.active {
    border-color: #48bb78;
    background: linear-gradient(135deg, #f7fafc 0%, #ebf8ff 100%);
    box-shadow: 0 8px 24px rgba(72, 187, 120, 0.2);
    transform: translateY(-2px);
}

.bs-problem-card.active::before {
    transform: scaleX(1);
}

.bs-problem-number {
    position: absolute;
    top: -12px;
    right: -12px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 4px 16px rgba(72, 187, 120, 0.4);
    border: 3px solid white;
}

.bs-problem-title {
    font-size: 20px;
    font-weight: 700;
    color: #2d3748;
    margin: 0 0 15px 0;
    padding-right: 40px;
    line-height: 1.3;
    text-align: center;
}

.bs-problem-subtitle {
    color: #718096;
    font-size: 15px;
    margin: 0;
    font-weight: 500;
    text-align: center;
}

/* Solution Viewer - Remove Container Box */
#bs-solution-viewer {
    background: transparent;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    border: none;
}

.bs-solution-header {
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    color: #2d3748;
    padding: 40px;
    border-bottom: 1px solid #e2e8f0;
}

.bs-solution-navigation {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 12px;
}

.bs-nav-btn {
    background: white;
    color: #4a5568;
    border: 2px solid #e2e8f0;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.bs-nav-btn:hover {
    background: #4299e1;
    color: white;
    border-color: #4299e1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.3);
}

.bs-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.bs-problem-header h3 {
    font-size: 28px;
    margin: 0 0 25px 0;
    color: #2d3748;
    font-weight: 800;
    text-align: center;
    background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Enhanced Problem Statement - Professional Mathematical Display */
.bs-problem-statement {
    background: white;
    padding: 40px;
    border-radius: 12px;
    font-size: 18px;
    line-height: 1.8;
    margin: 0;
    color: #2d3748;
    border: 2px solid #e2e8f0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    text-align: justify;
    font-family: 'Times New Roman', serif;
    position: relative;
}

.bs-problem-statement::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, #9f7aea 0%, #805ad5 100%);
    border-radius: 12px 12px 0 0;
}

/* Solution Content - Remove Container Box and Reset Margins */
.bs-solution-content {
    padding: 0;
    background: transparent;
    margin: 0;
    width: 100%;
}

.bs-steps-header {
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    padding: 25px 40px;
    border-bottom: 1px solid #e2e8f0;
}

.bs-steps-header h4 {
    color: #2d3748;
    font-size: 22px;
    margin: 0;
    font-weight: 700;
    text-align: center;
}

/* Step Container - Reset margins for proper alignment */
.bs-step {
    border-bottom: 1px solid #f1f5f9;
    background: white;
    transition: all 0.3s ease;
    margin: 0;
    padding: 0;
}

.bs-step:last-child {
    border-bottom: none;
}

.bs-step-header {
    background: #f7fafc;
    padding: 24px 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 24px;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.bs-step-header:hover {
    background: #edf2f7;
    border-left-color: #4299e1;
}

.bs-step.expanded .bs-step-header {
    background: #edf2f7;
    border-left-color: #4299e1;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.bs-step-number {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.3);
}

.bs-step-title {
    font-size: 20px;
    font-weight: 700;
    color: #2d3748;
    margin: 0;
    flex: 1;
}

.bs-step-toggle {
    color: #718096;
    font-size: 20px;
    transition: all 0.3s ease;
    font-weight: bold;
}

.bs-step.expanded .bs-step-toggle {
    transform: rotate(180deg);
    color: #4299e1;
}

/* Enhanced Step Content - Clean without Border and Shadow */
.bs-step-content {
    padding: 40px;
    background: white;
    font-size: 18px;
    line-height: 1.8;
    color: #2d3748;
    display: none;
    margin-left: 40px;
    margin-right: 40px;
    border-radius: 0 8px 8px 0;
    text-align: justify;
    font-family: 'Times New Roman', serif;
}

.bs-step.expanded .bs-step-content {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Enhanced Mathematical Expression Styling */

/* Display Math - Professional Centered Style with Enhanced Aesthetics */
#bs-book-info mjx-container[display="true"],
.bs-problem-statement mjx-container[display="true"],
.bs-step-content mjx-container[display="true"] {
    display: block !important;
    text-align: center !important;
    margin: 30px auto !important;
    padding: 25px !important;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
    border: 2px solid #e2e8f0 !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
    max-width: 95% !important;
    overflow-x: auto !important;
    font-size: 1.2em !important;
    position: relative !important;
}

/* Add subtle mathematical expression highlighting */
#bs-book-info mjx-container[display="true"]::before,
.bs-problem-statement mjx-container[display="true"]::before,
.bs-step-content mjx-container[display="true"]::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 3px !important;
    background: linear-gradient(135deg, #9f7aea 0%, #805ad5 100%) !important;
    border-radius: 12px 12px 0 0 !important;
}

/* Inline Math - Clean Professional Integration */
#bs-book-info mjx-container,
.bs-problem-statement mjx-container,
.bs-step-content mjx-container {
    font-size: 1.1em !important;
    margin: 0 4px !important;
    color: #1a365d !important;
    font-weight: 500 !important;
}

/* Enhanced equation styling for better readability */
#bs-book-info mjx-math,
.bs-problem-statement mjx-math,
.bs-step-content mjx-math {
    color: #1a365d !important;
    font-family: 'Times New Roman', 'Computer Modern', serif !important;
}

/* Fraction and complex expression styling */
#bs-book-info mjx-mfrac,
.bs-problem-statement mjx-mfrac,
.bs-step-content mjx-mfrac {
    margin: 0 6px !important;
}

/* Enhanced matrix and table styling */
#bs-book-info mjx-mtable,
.bs-problem-statement mjx-mtable,
.bs-step-content mjx-mtable {
    margin: 10px auto !important;
}

/* Image Styles - Direct Integration without Containers, Center Aligned */
.bs-problem-image,
.bs-step-image {
    max-width: 100%;
    height: auto;
    margin: 20px auto;
    display: block;
    border: none;
    box-shadow: none;
    border-radius: 0;
    text-align: center;
}

/* Remove Image Container - Images appear directly in content */
.bs-image-container {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    text-align: center;
}

/* Math Container Global Styles */
.mathjax_process {
    font-family: 'Times New Roman', 'Computer Modern', serif;
}

/* Loading and Empty States */
.bs-loading {
    text-align: center;
    padding: 80px;
    color: #718096;
    font-size: 18px;
    background: white;
    border-radius: 12px;
    margin: 20px 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.bs-loading:before {
    content: '';
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f1f5f9;
    border-top-color: #4299e1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 20px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.bs-empty-state {
    text-align: center;
    padding: 100px 40px;
    color: #718096;
    background: white;
    border-radius: 12px;
    margin: 20px 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.bs-empty-state h3 {
    color: #4a5568;
    font-size: 24px;
    margin: 0 0 20px 0;
    font-weight: 700;
}

.bs-empty-state p {
    font-size: 18px;
    margin: 0;
    line-height: 1.6;
}

.bs-error {
    background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
    color: #c53030;
    padding: 25px;
    border-radius: 8px;
    margin: 20px 0;
    text-align: center;
    font-weight: 600;
    border: 2px solid #feb2b2;
    font-size: 16px;
}

/* Print Styles */
@media print {
    #book-solutions-frontend {
        background: white;
        padding: 20px;
    }
    
    .bs-solution-navigation,
    .bs-step-toggle {
        display: none !important;
    }
    
    .bs-step {
        page-break-inside: avoid;
        border: 1px solid #ccc;
        margin-bottom: 15px;
    }
    
    .bs-step-content {
        display: block !important;
        border: none;
        margin: 0;
        padding: 20px;
        font-size: 16px;
    }
    
    .bs-step.expanded .bs-step-content {
        display: block !important;
    }
    
    mjx-container {
        break-inside: avoid;
    }
    
    mjx-container[display="true"] {
        background: white !important;
        border: 1px solid #ccc !important;
        padding: 15px !important;
        margin: 15px auto !important;
    }
    
    .bs-problem-image,
    .bs-step-image {
        page-break-inside: avoid;
        margin: 15px auto;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    #book-solutions-frontend {
        padding: 20px;
    }
    
    .bs-book-selector {
        padding: 30px;
    }
    
    .bs-book-selector h3 {
        font-size: 24px;
    }
    
    .bs-book-info-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 25px;
    }
    
    .bs-book-cover-display {
        width: 160px;
        height: 230px;
    }
    
    #bs-book-info {
        padding: 40px;
    }
    
    .bs-book-title {
        font-size: 28px;
    }
    
    .bs-book-author {
        font-size: 18px;
    }
    
    .bs-chapters-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .bs-problems-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .bs-solution-navigation {
        flex-direction: column;
        gap: 12px;
    }
    
    .bs-nav-btn {
        width: 100%;
        justify-content: center;
    }
    
    .bs-solution-header {
        padding: 25px 0;
    }
    
    .bs-solution-header-step .bs-step-header,
    .bs-step-header {
        padding: 20px;
        gap: 18px;
    }
    
    .bs-step-content {
        padding: 30px 20px;
        margin-left: 20px;
        margin-right: 20px;
        font-size: 16px;
    }
    
    .bs-step-number {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .bs-step-title {
        font-size: 18px;
    }
    
    mjx-container[display="true"] {
        padding: 20px !important;
        margin: 20px auto !important;
        font-size: 1.1em !important;
    }
}

@media (max-width: 480px) {
    #book-solutions-frontend {
        padding: 15px;
    }
    
    .bs-book-selector h3 {
        font-size: 22px;
    }
    
    .bs-book-cover-display {
        width: 140px;
        height: 200px;
    }
    
    .bs-chapter-card,
    .bs-problem-card {
        padding: 20px;
    }
    
    .bs-chapter-number {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
    
    .bs-solution-header {
        padding: 20px 0;
    }
    
    .bs-solution-header-step .bs-step-header,
    .bs-step-header {
        padding: 15px;
        gap: 15px;
    }
    
    .bs-step-content {
        padding: 25px 15px;
        font-size: 15px;
        margin-left: 15px;
        margin-right: 15px;
    }
    
    .bs-steps-header {
        padding: 20px 25px;
    }
    
    .bs-image-container {
        padding: 0;
        margin: 15px 0;
    }
    
    mjx-container[display="true"] {
        padding: 15px !important;
        margin: 15px auto !important;
        font-size: 1.0em !important;
    }
}