/* ============================================
   ExamSutra Code Practice Platform
   ============================================ */

/* --- Light Theme Override --- */
.light-theme {
    --bg-dark: #f5f6fa;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f0f5;
    --text-primary: #1a1a2e;
    --text-secondary: #555770;
    --text-muted: #8a8da0;
    --border-color: #e0e2ea;
    --border-hover: #c0c2ca;
}

.light-theme .main-header {
    background: rgba(245, 246, 250, 0.9);
}

.light-theme .brand-logo {
    background: linear-gradient(to right, #1a1a2e, #333);
    -webkit-background-clip: text;
    background-clip: text;
}

/* --- Practice Layout --- */
.practice-wrapper {
    display: flex;
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
    overflow: hidden;
}

/* --- Left Sidebar: Question Browser --- */
.question-sidebar {
    width: 340px;
    min-width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
    z-index: 10;
}

.question-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h2 i {
    color: var(--primary-color);
}

.sidebar-search {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    transition: border-color 0.2s;
}

.light-theme .sidebar-search {
    background: #f0f0f5;
}

.sidebar-search:focus-within {
    border-color: var(--primary-color);
}

.sidebar-search i {
    color: var(--text-muted);
    margin-right: 8px;
    font-size: 0.85rem;
}

.sidebar-search input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 100%;
    outline: none;
    font-family: var(--font-body);
}

/* Filter Chips */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-chip {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-body);
}

.filter-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.filter-chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.filter-chip.diff-easy.active {
    background: #2ecc71;
    border-color: #2ecc71;
}

.filter-chip.diff-medium.active {
    background: #f39c12;
    border-color: #f39c12;
}

.filter-chip.diff-hard.active {
    background: #e74c3c;
    border-color: #e74c3c;
}

/* Question List */
.question-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.question-list::-webkit-scrollbar {
    width: 5px;
}

.question-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.question-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.question-item:hover {
    background: var(--bg-card-hover);
}

.question-item.selected {
    background: rgba(126, 61, 255, 0.08);
    border-left-color: var(--primary-color);
}

.q-status-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    flex-shrink: 0;
    transition: all 0.2s;
}

.q-status-icon.solved {
    background: #2ecc71;
    border-color: #2ecc71;
    color: white;
}

.q-status-icon.attempted {
    background: transparent;
    border-color: #f39c12;
    color: #f39c12;
}

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

.q-title {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.q-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.q-diff-badge {
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
}

.q-diff-badge.easy {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.q-diff-badge.medium {
    background: rgba(243, 156, 18, 0.15);
    color: #f39c12;
}

.q-diff-badge.hard {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.sidebar-stats {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

/* --- Main Content Area --- */
.main-practice-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Top Toolbar */
.practice-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 12px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-sidebar-btn,
.toolbar-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    gap: 6px;
}

.toggle-sidebar-btn:hover,
.toolbar-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.theme-toggle-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.lang-selector {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    cursor: pointer;
    outline: none;
}

.light-theme .lang-selector {
    background: #f0f0f5;
}

.lang-selector option {
    background: var(--bg-card);
}

.run-btn {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-heading);
}

.run-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}

.run-btn:active {
    transform: translateY(0);
}

.run-btn.running {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    pointer-events: none;
}

.run-btn i.fa-spinner {
    animation: spin 1s linear infinite;
}

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

/* --- Split Panels: Description + Editor / Output --- */
.panels-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Horizontal split: desc | editor+output */
.left-panel {
    width: 45%;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 300px;
}

/* Resize handle */
.resize-handle-h {
    width: 5px;
    cursor: col-resize;
    background: var(--border-color);
    transition: background 0.2s;
    flex-shrink: 0;
}

.resize-handle-h:hover,
.resize-handle-h.active {
    background: var(--primary-color);
}

.resize-handle-v {
    height: 5px;
    cursor: row-resize;
    background: var(--border-color);
    transition: background 0.2s;
    flex-shrink: 0;
}

.resize-handle-v:hover,
.resize-handle-v.active {
    background: var(--primary-color);
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-card);
}

.panel-tab {
    padding: 10px 20px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: transparent;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-tab:hover {
    color: var(--text-primary);
}

.panel-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Description Panel */
.description-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.description-content::-webkit-scrollbar {
    width: 5px;
}

.description-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.desc-header {
    margin-bottom: 20px;
}

.desc-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.desc-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.desc-badge {
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.desc-badge.easy {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.desc-badge.medium {
    background: rgba(243, 156, 18, 0.15);
    color: #f39c12;
}

.desc-badge.hard {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.desc-badge.topic {
    background: rgba(126, 61, 255, 0.12);
    color: var(--primary-color);
}

.desc-body {
    font-size: 0.92rem;
    line-height: 1.75;
    color: var(--text-secondary);
}

.desc-body h2 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    color: var(--text-primary);
    margin: 20px 0 10px;
}

.desc-body h3 {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-primary);
    margin: 16px 0 8px;
}

.desc-body code {
    background: rgba(126, 61, 255, 0.1);
    color: var(--primary-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

.desc-body ul, .desc-body ol {
    padding-left: 24px;
    margin: 8px 0;
}

.desc-body li {
    margin-bottom: 4px;
}

/* Example boxes */
.example-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
    margin: 12px 0;
}

.light-theme .example-box {
    background: #f8f9fc;
}

.example-box h4 {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.example-io {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.example-io pre {
    background: var(--bg-dark);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.82rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    overflow-x: auto;
    color: var(--text-primary);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.light-theme .example-io pre {
    background: #eef0f5;
}

.example-io label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.example-explanation {
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Hints */
.hints-section {
    margin-top: 20px;
}

.hint-toggle-btn {
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    gap: 6px;
}

.hint-toggle-btn:hover {
    border-color: #f39c12;
    color: #f39c12;
}

.hints-list {
    display: none;
    margin-top: 10px;
}

.hints-list.visible {
    display: block;
}

.hint-item {
    background: rgba(243, 156, 18, 0.08);
    border-left: 3px solid #f39c12;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 0 8px 8px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* --- Editor Panel --- */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#monaco-editor {
    width: 100%;
    height: 100%;
}

/* --- Output Panel --- */
.output-panel {
    height: 200px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-top: 1px solid var(--border-color);
}

.output-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-card);
}

.output-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.output-content::-webkit-scrollbar {
    width: 5px;
}

.output-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Console Output */
.console-output {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-secondary);
    line-height: 1.6;
}

.console-output .error {
    color: #e74c3c;
}

.console-output .success {
    color: #2ecc71;
}

.console-output .info {
    color: var(--secondary-color);
}

/* Test Results */
.test-results {
    display: none;
}

.test-results.visible {
    display: block;
}

.test-result-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.test-result-item:last-child {
    border-bottom: none;
}

.test-status-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.test-status-icon.pass {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.3);
}

.test-status-icon.fail {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.3);
}

.test-detail {
    flex: 1;
    min-width: 0;
}

.test-detail h4 {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.test-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    font-size: 0.78rem;
}

.test-detail-grid label {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.68rem;
    display: block;
    margin-bottom: 2px;
}

.test-detail-grid pre {
    background: var(--bg-dark);
    padding: 6px 10px;
    border-radius: 4px;
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
}

.light-theme .test-detail-grid pre {
    background: #eef0f5;
}

/* Execution timer */
.exec-timer {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Test summary bar */
.test-summary-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.test-summary-bar .pass-count {
    color: #2ecc71;
    font-weight: 600;
    font-size: 0.85rem;
}

.test-summary-bar .fail-count {
    color: #e74c3c;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Placeholder states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 300px;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 21, 0.8);
    z-index: 20;
    flex-direction: column;
    gap: 12px;
}

.light-theme .loading-overlay {
    background: rgba(245, 246, 250, 0.85);
}

.loading-overlay i {
    font-size: 2rem;
    color: var(--primary-color);
    animation: spin 1s linear infinite;
}

.loading-overlay p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Solution toggle */
.solution-section {
    margin-top: 20px;
}

.solution-toggle-btn {
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    gap: 6px;
}

.solution-toggle-btn:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.solution-code {
    display: none;
    margin-top: 10px;
    background: var(--bg-dark);
    border-radius: 8px;
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.light-theme .solution-code {
    background: #eef0f5;
}

.solution-code.visible {
    display: block;
}

/* --- Mobile Responsive --- */

/* Tablet */
@media (max-width: 1024px) {
    .question-sidebar {
        width: 280px;
        min-width: 240px;
    }

    .left-panel {
        width: 40%;
    }
}

/* Mobile toggle panels */
@media (max-width: 768px) {
    .practice-wrapper {
        flex-direction: column;
    }

    .question-sidebar {
        width: 100% !important;
        min-width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .question-sidebar.mobile-open {
        transform: translateX(0);
    }

    .question-sidebar.collapsed {
        transform: translateX(-100%);
    }

    .panels-container {
        flex-direction: column;
    }

    .left-panel {
        width: 100%;
        border-right: none;
        display: none;
    }

    .left-panel.mobile-active {
        display: flex;
        height: 50%;
    }

    .resize-handle-h {
        display: none;
    }

    .right-panel {
        width: 100%;
        min-width: 0;
    }

    .example-io {
        grid-template-columns: 1fr;
    }

    .test-detail-grid {
        grid-template-columns: 1fr;
    }

    /* Mobile bottom nav for panels */
    .mobile-panel-nav {
        display: flex !important;
    }
}

.mobile-panel-nav {
    display: none;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.mobile-panel-nav button {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.mobile-panel-nav button.active {
    color: var(--primary-color);
}

.mobile-panel-nav button i {
    font-size: 1rem;
}

/* Pyodide loading banner */
.pyodide-status {
    padding: 6px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(126, 61, 255, 0.05);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.pyodide-status.ready {
    color: #2ecc71;
    background: rgba(46, 204, 113, 0.05);
}

.pyodide-status.error {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.05);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.test-result-item {
    animation: fadeIn 0.3s ease forwards;
}

.test-result-item:nth-child(2) { animation-delay: 0.05s; }
.test-result-item:nth-child(3) { animation-delay: 0.1s; }
.test-result-item:nth-child(4) { animation-delay: 0.15s; }
.test-result-item:nth-child(5) { animation-delay: 0.2s; }
