/**
 * NCERT Books - Shared Styles
 * Used across all NCERT textbook solution pages
 */

/* Map NCERT tokens to Exam design system variables when needed */
:root {
    --accent: var(--accent-primary, #6366f1);
    --accent-secondary: var(--accent-hover, #4f46e5);
    --border-primary: var(--border, #e2e8f0);
    --border-secondary: var(--border-light, #f1f5f9);
}

/* ============================================
   Hero Sections
   ============================================ */
.books-hero,
.ncert-hero,
.subject-hero,
.chapter-hero {
    padding: var(--space-6) var(--space-4);
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-6);
}

.books-hero {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
}

.ncert-hero {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(16, 185, 129, 0.1) 100%);
}

.subject-hero,
.chapter-hero {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
}

.books-hero h1,
.ncert-hero h1 {
    font-size: var(--text-4xl);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

.subject-hero h1 {
    font-size: var(--text-3xl);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.chapter-hero h1 {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.books-hero p,
.ncert-hero p,
.subject-hero p,
.chapter-hero p {
    font-size: var(--text-base);
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* ============================================
   Stats Display
   ============================================ */
.subject-stats,
.chapter-stats {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-4);
    flex-wrap: wrap;
}

.subject-stat {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.subject-stat strong {
    color: var(--accent);
    font-weight: 700;
}

.chapter-stat {
    background: var(--bg-primary);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.chapter-stat strong {
    color: var(--accent);
}

/* ============================================
   Grid Layouts
   ============================================ */
.publishers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-6);
}

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-4);
}

.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-4);
}

/* ============================================
   Publisher Cards
   ============================================ */
.publisher-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    transition: all 0.3s ease;
    text-decoration: none;
    display: block;
}

.publisher-card:hover {
    border-color: var(--accent);
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.15);
    transform: translateY(-4px);
}

.publisher-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: var(--space-4);
}

.publisher-card h2 {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.publisher-card p {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
    line-height: 1.6;
}

.publisher-stats {
    display: flex;
    gap: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-secondary);
}

.publisher-stats .stat {
    text-align: center;
}

.publisher-stats .stat-value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--accent);
}

.publisher-stats .stat-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
}

/* ============================================
   Subject Cards
   ============================================ */
.subject-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    transition: all 0.2s ease;
}

.subject-card:hover {
    border-color: #22c55e;
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.15);
}

.subject-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.subject-icon.math { background: rgba(99, 102, 241, 0.15); }
.subject-icon.science { background: rgba(34, 197, 94, 0.15); }
.subject-icon.physics { background: rgba(59, 130, 246, 0.15); }
.subject-icon.chemistry { background: rgba(249, 115, 22, 0.15); }

.subject-info h3 {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.subject-info p {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ============================================
   Chapter Cards
   ============================================ */
.chapter-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-decoration: none;
    display: block;
    transition: all 0.2s ease;
}

.chapter-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.12);
    transform: translateY(-2px);
}

.chapter-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.chapter-num {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.chapter-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
}

.chapter-meta {
    display: flex;
    gap: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-secondary);
}

.chapter-meta-item {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.chapter-meta-item strong {
    color: var(--text-secondary);
}

.difficulty-bar {
    display: flex;
    gap: 2px;
    margin-top: var(--space-2);
}

.difficulty-segment {
    width: 20px;
    height: 4px;
    background: var(--border-secondary);
    border-radius: 2px;
}

.difficulty-segment.filled { background: var(--accent); }
.difficulty-segment.filled.medium { background: #f59e0b; }
.difficulty-segment.filled.hard { background: #ef4444; }

/* ============================================
   Exercise Sections
   ============================================ */
.exercise-section {
    margin-bottom: var(--space-8);
}

.exercise-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    cursor: pointer;
    transition: background 0.2s;
}

.exercise-header:hover {
    background: var(--bg-tertiary);
}

.exercise-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.exercise-count {
    font-size: var(--text-sm);
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
}

/* ============================================
   Question Cards
   ============================================ */
.question-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    overflow: hidden;
}

.question-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
}

.question-num {
    background: var(--accent);
    color: white;
    font-size: var(--text-xs);
    font-weight: 700;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.question-text {
    font-size: var(--text-base);
    color: var(--text-primary);
    line-height: 1.7;
    flex: 1;
}

.question-meta {
    display: flex;
    gap: var(--space-3);
    padding: 0 var(--space-4) var(--space-3);
    flex-wrap: wrap;
}

/* ============================================
   Meta Badges
   ============================================ */
.meta-badge {
    font-size: var(--text-xs);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.meta-badge.type-proof { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.meta-badge.type-numerical { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.meta-badge.type-mcq { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.meta-badge.type-shortanswer { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.meta-badge.type-longanswer { background: rgba(236, 72, 153, 0.15); color: #ec4899; }
.meta-badge.difficulty-easy { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.meta-badge.difficulty-medium { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.meta-badge.difficulty-hard { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

/* ============================================
   Diagram Section
   ============================================ */
.diagram-notice {
    margin: var(--space-3) var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: rgba(59, 130, 246, 0.1);
    border: 1px dashed rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-md);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.diagram-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.diagram-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}

.diagram-label {
    font-weight: 600;
    color: #3b82f6;
    display: block;
    margin-bottom: 4px;
}

/* ============================================
   Solution Toggle & Content
   ============================================ */
.solution-toggle {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
}

.hint-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    color: #f59e0b;
    font-weight: 600;
}

.hint-toggle:hover {
    opacity: 0.85;
}

.toggle-btn {
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.toggle-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.hint-content,
.solution-content {
    display: none;
    padding: var(--space-4);
    border-top: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
}

.hint-content-text {
    margin-top: var(--space-3);
    padding: var(--space-3);
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid #f59e0b;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-style: italic;
    display: none;
}

.hint-content-text.show {
    display: block;
}

.hint-content.show,
.solution-content.show {
    display: block;
}

.hint-text {
    color: var(--text-secondary);
    font-style: italic;
    padding: var(--space-3);
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid #f59e0b;
    border-radius: var(--radius-sm);
}

/* ============================================
   Solution Steps
   ============================================ */
.solution-steps {
    list-style: none;
    padding: 0;
    margin: 0;
}

.solution-step {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-secondary);
}

.solution-step:last-child {
    border-bottom: none;
}

.step-num {
    width: 24px;
    height: 24px;
    background: var(--accent);
    color: white;
    font-size: var(--text-xs);
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-text {
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============================================
   Answer Box
   ============================================ */
.answer-box {
    margin-top: var(--space-4);
    padding: var(--space-4);
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--radius-md);
}

.answer-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: #22c55e;
    margin-bottom: var(--space-2);
}

.answer-text {
    color: var(--text-primary);
    font-weight: 500;
}

/* ============================================
   Coming Soon / Disabled States
   ============================================ */
.coming-soon {
    opacity: 0.6;
    pointer-events: none;
}

.coming-soon .publisher-logo,
.coming-soon .subject-icon {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.badge-soon,
.coming-badge {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: var(--text-xs);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-left: var(--space-2);
}

/* ============================================
   Class Sections
   ============================================ */
.class-section {
    margin-bottom: var(--space-8);
}

.class-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.class-badge {
    background: linear-gradient(135deg, #22c55e, #10b981);
    color: white;
    font-size: var(--text-sm);
    font-weight: 700;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
}

.class-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
}

/* ============================================
   Features Grid
   ============================================ */
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-8);
    padding: var(--space-6);
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
}

.feature-item {
    text-align: center;
    padding: var(--space-4);
}

.feature-icon {
    font-size: 2rem;
    margin-bottom: var(--space-2);
}

.feature-item h4 {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.feature-item p {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* ============================================
   Loading States
   ============================================ */
.loading-container {
    text-align: center;
    padding: var(--space-8);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-4);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-lg);
    height: 120px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   Three-Column Layout (Desktop Ads)
   ============================================ */
.three-col-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 var(--space-4);
}

/* Desktop: Three columns */
@media (min-width: 1200px) {
    .three-col-layout {
        grid-template-columns: 160px 1fr 160px;
        gap: var(--space-6);
        /* Center content even if sidebars are blocked by ad blockers */
        justify-content: center;
    }
}

/* Large Desktop: Wider ad columns */
@media (min-width: 1400px) {
    .three-col-layout {
        grid-template-columns: 200px 1fr 200px;
    }
}

/* Ad Sidebar Styles */
.ad-sidebar {
    display: none;
}

@media (min-width: 1200px) {
    .ad-sidebar {
        display: block;
        position: sticky;
        top: 80px;
        height: fit-content;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
        /* Ensure minimum width even when content is blocked */
        min-width: 160px;
    }

    .ad-sidebar::-webkit-scrollbar {
        width: 0;
        display: none;
    }
}

/* Fallback: If sidebars are hidden by ad blockers, center the main content */
@media (min-width: 1200px) {
    .three-col-layout:has(.ad-sidebar:empty),
    .three-col-layout:has(.ad-sidebar[style*="display: none"]),
    .three-col-layout:has(.ad-sidebar[style*="display:none"]) {
        grid-template-columns: 1fr;
        max-width: 1000px;
    }
}

/* Additional fallback using :not(:visible) simulation for ad blockers */
@supports (grid-template-columns: subgrid) {
    @media (min-width: 1200px) {
        .three-col-layout {
            /* Modern browsers: ensure grid doesn't collapse awkwardly */
            grid-auto-columns: minmax(0, 1fr);
        }
    }
}

.ad-sidebar-inner {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.sidebar-ad-unit {
    background: var(--bg-secondary);
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md);
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: var(--text-xs);
    text-align: center;
    padding: var(--space-2);
}

.sidebar-ad-unit.tall {
    min-height: 600px;
}

/* Main Content Area */
.main-content-area {
    min-width: 0; /* Prevent grid blowout */
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

@media (min-width: 1200px) {
    .main-content-area {
        max-width: none;
        /* Ensure content stays centered even if sidebars are blocked */
        justify-self: center;
    }
}

/* When parent grid has only main content visible (sidebars blocked), ensure proper width */
@media (min-width: 1200px) {
    .three-col-layout > .main-content-area:only-child,
    .three-col-layout > .main-content-area:first-child:last-child {
        max-width: 1000px;
        margin: 0 auto;
    }
}

/* Mobile Ad Container - hide on desktop with sidebars */
.mobile-ad-container {
    margin-bottom: var(--space-4);
}

@media (min-width: 1200px) {
    .mobile-ad-container {
        display: none;
    }
}

/* Ad Sidebar Labels (optional - for debugging) */
.sidebar-ad-unit::before {
    content: '160x600';
    font-size: 10px;
    color: var(--text-muted);
}

.sidebar-ad-unit.tall::before {
    content: '160x600';
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 640px) {
    .books-hero h1,
    .ncert-hero h1 {
        font-size: var(--text-2xl);
    }

    .subject-hero h1 {
        font-size: var(--text-xl);
    }

    .chapter-hero h1 {
        font-size: var(--text-lg);
    }

    .chapters-grid,
    .subjects-grid {
        grid-template-columns: 1fr;
    }

    .question-header {
        flex-direction: column;
    }

    .solution-toggle {
        flex-wrap: wrap;
    }

    .diagram-notice {
        flex-direction: column;
    }
}
