/* ===== Study Page - Material Design 3 ===== */

/* Main Layout */
.study-main {
    height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--md-surface);
}

/* Chapter Tabs - M3 Filter Chips */
.chapter-tabs {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 16px 24px;
    background: var(--md-surface-container);
    border-bottom: 1px solid var(--md-outline-variant);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chapter-tabs::-webkit-scrollbar {
    height: 4px;
}

.chapter-tabs::-webkit-scrollbar-thumb {
    background: var(--md-outline-variant);
    border-radius: 8px;
}

.chapter-tab {
    padding: 8px 16px;
    border: 1px solid var(--md-outline);
    border-radius: 8px;
    background: var(--md-surface);
    color: var(--md-on-surface-variant);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    cursor: pointer;
    transition: all var(--md-motion-duration-short);
    white-space: nowrap;
}

.chapter-tab:hover {
    background: var(--md-surface-container-high);
}

.chapter-tab.active {
    background: var(--md-secondary-container);
    border-color: transparent;
    color: var(--md-on-secondary-container);
}

/* 2-Column Layout */
.study-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar - M3 Navigation Drawer */
.study-sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--md-surface-container-low);
    border-right: 1px solid var(--md-outline-variant);
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topic-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 4px 10px;
    border-radius: var(--radius-full);
}

.topic-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    padding-bottom: 100px;
    /* Space for bottom navigation bar */
}

/* Custom Scrollbar */
.topic-list::-webkit-scrollbar {
    width: 6px;
    display: block;
}

.topic-list::-webkit-scrollbar-track {
    background: transparent;
}

.topic-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
}

.topic-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Topic Item in Sidebar - M3 List Item */
.topic-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--md-shape-lg);
    cursor: pointer;
    transition: all var(--md-motion-duration-short);
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.topic-item:hover {
    background: rgba(168, 199, 250, var(--md-state-hover));
}

.topic-item.active {
    background: var(--md-secondary-container);
    border-color: transparent;
}

.topic-item-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.topic-item-info {
    flex: 1;
    min-width: 0;
}

.topic-item-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 2;
}

.topic-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.topic-progress-container {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.progress-bar-bg {
    width: 60px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.progress-badge {
    font-weight: 700;
    padding: 0 4px;
    border-radius: 3px;
    font-size: 0.7rem;
}

.progress-badge.good {
    color: var(--correct);
    background: rgba(34, 197, 94, 0.1);
}

.progress-badge.average {
    color: var(--warning);
    background: rgba(234, 179, 8, 0.1);
}

.topic-item-count {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--accent);
    background: var(--accent-light);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-left: auto;
    flex-shrink: 0;
}

.topic-score {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    /* Push to right if no count */
}

.topic-score.good {
    color: var(--correct);
    background: var(--correct-bg);
    border: 1px solid var(--correct);
}

.topic-score.average {
    color: var(--warning);
    background: var(--warning-bg);
    border: 1px solid var(--warning);
}

/* Sidebar Toggle (Mobile) */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 110px;
    /* Above bottom navigation bar (80px + 24px + 6px) */
    left: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
    z-index: 999;
    /* Just below nav bar z-index of 1000 */
    transition: var(--transition);
}

.sidebar-toggle:hover {
    transform: scale(1.1);
}

/* Main Content Area */
.study-content {
    flex: 1;
    padding: 24px;
    padding-bottom: 120px;
    /* Space for bottom nav */
    overflow-y: auto;
    height: 100%;
}

.study-content::-webkit-scrollbar {
    width: 8px;
}

.study-content::-webkit-scrollbar-track {
    background: transparent;
}

.study-content::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
}

.study-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.content-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    text-align: center;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.mobile-msg {
    display: none;
}

/* Topic Detail View */
.topic-detail {
    max-width: 900px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.topic-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.topic-detail-icon {
    font-size: 3.5rem;
    background: var(--accent-light);
    padding: 16px;
    border-radius: var(--radius);
}

.topic-detail-info h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.topic-detail-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.chapter-badge {
    background: var(--accent-gradient);
    color: white;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
}

.question-count {
    background: var(--correct-bg);
    color: var(--correct);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 500;
}

/* Detail Sections */
.detail-section {
    margin-bottom: 32px;
}

.detail-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Video Grid */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.video-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}

.video-card:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: var(--shadow-sm);
}

.video-thumbnail {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--bg-secondary);
    overflow: hidden;
}

.video-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    transition: var(--transition);
}

.video-card:hover .play-overlay {
    background: var(--accent);
    transform: translate(-50%, -50%) scale(1.1);
}

.video-score-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.video-score-badge.good {
    background: var(--correct);
    color: white;
}

.video-score-badge.average {
    background: var(--warning);
    color: black;
}

.video-card-info {
    padding: 14px;
}

.video-card-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 2;
}

.video-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.video-question-badge {
    font-size: 0.75rem;
    color: var(--accent);
    background: var(--accent-light);
    padding: 4px 10px;
    border-radius: var(--radius-full);
}

.video-practice-btn {
    padding: 6px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.video-practice-btn:hover {
    background: var(--accent-hover);
}

/* Video Player */
.video-player-container {
    margin-top: 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.video-wrapper {
    position: relative;
    padding-top: 56.25%;
    /* 16:9 */
}

.video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.close-video {
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-video:hover {
    background: var(--incorrect-bg);
    color: var(--incorrect);
}

/* Theory Box */
.theory-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.theory-box b,
.theory-box strong {
    color: var(--accent);
}

.theory-box ul,
.theory-box ol {
    margin: 12px 0;
    padding-left: 24px;
}

.theory-box li {
    margin-bottom: 8px;
}

/* Goals List */
.goals-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.goals-list li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    background: var(--correct-bg);
    border-left: 4px solid var(--correct);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.goals-list li::before {
    content: "✓";
    color: var(--correct);
    font-weight: bold;
}

/* Tips List */
.tips-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tip-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    background: var(--warning-bg);
    border-left: 4px solid var(--warning);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.tip-item::before {
    content: "💡";
}

/* Topic Actions */
.topic-actions {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.topic-actions .btn {
    flex: 1;
    min-width: 200px;
    padding: 16px 24px;
    font-size: 1rem;
    justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .study-sidebar {
        width: 280px;
        min-width: 280px;
    }
}

@media (max-width: 768px) {
    .chapter-tabs {
        padding: 12px 16px;
    }

    .chapter-tab {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .study-sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 80px;
        /* Account for bottom navigation bar */
        width: 300px;
        z-index: 60;
        transform: translateX(-100%);
        transition: var(--transition);
        height: auto;
    }

    .study-sidebar.active {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    /* Ensure topic list has enough padding for bottom nav on mobile */
    .topic-list {
        padding-bottom: 120px !important;
        /* Extra space for bottom nav bar */
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .study-content {
        padding: 16px;
    }

    .topic-detail-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
        align-items: center;
    }

    .topic-detail-icon {
        font-size: 2.5rem;
        padding: 12px;
    }

    .topic-detail-info h2 {
        font-size: 1.4rem;
    }

    .topic-detail-meta {
        justify-content: center;
    }

    .video-grid {
        grid-template-columns: 1fr;
    }

    .topic-actions {
        flex-direction: column;
    }

    .topic-actions .btn {
        width: 100%;
    }

    .content-placeholder {
        height: 50vh;
    }

    .placeholder-icon {
        display: none;
    }

    .desktop-msg {
        display: none;
    }

    .mobile-msg {
        display: block;
        font-weight: 600;
        color: var(--accent);
        font-size: 1.1rem;
        padding: 0 20px;
    }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
}

.sidebar-overlay.active {
    display: block;
}

/* Hidden utility */
.hidden {
    display: none !important;
}