/* CSS Variables & Theme */
:root {
    /* Safe Colors (defaults) */
    --primary-hue: 250;
    /* Deep Purple/Indigo */
    --primary: hsl(var(--primary-hue), 70%, 60%);
    --primary-hover: hsl(var(--primary-hue), 70%, 50%);
    --secondary: #00d4ff;
    /* Cyan accent */

    --bg-app: #f8f9fa;
    --bg-panel: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --font-heading: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --header-height: 70px;
}

[data-theme="dark"] {
    --bg-app: #0f1117;
    /* Very dark blue-grey */
    --bg-panel: #1e222d;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: #2d3748;
    --primary: hsl(var(--primary-hue), 70%, 65%);
}

/* Base Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-heading);
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Inputs & Buttons Reset */
button,
input,
textarea {
    font-family: inherit;
    border: none;
    outline: none;
    background: transparent;
}

button {
    cursor: pointer;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.logo-icon {
    font-size: 2rem;
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.header-controls {
    display: flex;
    gap: 1rem;
}

/* Icon Buttons */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
    background: transparent;
    border: 1px solid transparent;
    position: relative;
}

.icon-btn:hover {
    background-color: var(--bg-app);
    color: var(--text-main);
    border-color: var(--border-color);
}

.status-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background-color: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-panel);
}

.status-dot.active {
    background-color: var(--success);
}

/* Dashboard Grid */
.dashboard-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 40% 60%;
    grid-template-rows: 1fr;
    /* Fix: Constrain height */
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-app);
    overflow: hidden;
    /* Fix: Container overflow */
    min-height: 0;
    /* Fix: Flex shrink */
}

.panel.output-panel {
    background-color: var(--bg-panel);
    border-right: none;
    padding: 0;
}

/* Panel Header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    background: rgba(124, 58, 237, 0.1);
    /* Primary low alpha */
    color: var(--primary);
    border-radius: 20px;
    font-weight: 500;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Input Area */
.editor-container {
    flex: 1;
    background-color: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    transition: box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.editor-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

textarea#codeInput {
    flex: 1;
    width: 100%;
    resize: none;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-main);
    background: transparent;
}

textarea#codeInput::placeholder {
    color: var(--text-muted);
}

/* Panel Footer */
.panel-footer {
    padding-top: 1.5rem;
}

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.1s, opacity 0.2s;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.primary-btn:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-app);
    border-color: var(--text-muted);
}

/* Tabs */
.tabs-header {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.tab-btn {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
    background-color: rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--primary);
    background-color: rgba(124, 58, 237, 0.1);
}

.tabs-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    opacity: 0.7;
}

.large-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: var(--border-color);
}

/* Loading State */
.loading-state {
    position: absolute;
    inset: 0;
    /* Cover the entire parent */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    /* Semi-transparent bg */
    backdrop-filter: blur(2px);
    z-index: 50;
    color: var(--primary);
}

[data-theme="dark"] .loading-state {
    background: rgba(15, 17, 23, 0.8);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(124, 58, 237, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Tab Panes */
.tab-pane {
    animation: fadeIn 0.3s ease;
}

.tab-pane.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Markdown Content Styling */
.markdown-body {
    line-height: 1.7;
    font-size: 1rem;
    max-width: 100%;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-main);
    font-weight: 700;
}

.markdown-body p {
    margin-bottom: 1rem;
    color: var(--text-muted);
    /* Softer reading text */
}

/* Code Blocks in Markdown */
.markdown-body pre {
    background-color: transparent;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-family: var(--font-mono);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

/* Wrapper for our custom code blocks */
.code-block-wrapper {
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.code-header {
    background-color: #2d2d2d;
    /* ChatGPT-like dark header */
    color: #e0e0e0;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    font-family: var(--font-heading);
    border-bottom: 1px solid #404040;
}

.code-lang {
    font-weight: 500;
    text-transform: uppercase;
}

.copy-code-btn {
    background: transparent;
    border: none;
    color: #b0b0b0;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.copy-code-btn:hover {
    color: #fff;
}

.copy-code-icon {
    font-size: 14px;
}

.code-block-wrapper pre {
    margin: 0;
    padding: 1rem;
    background-color: var(--bg-panel);
    overflow-x: auto;
    border: none;
    border-radius: 0;
}

[data-theme="dark"] .code-block-wrapper pre {
    background-color: #1a1a1a;
}

[data-theme="light"] .code-block-wrapper pre {
    background-color: #f6f8fa;
    color: #24292e;
}

.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: rgba(124, 58, 237, 0.1);
    color: var(--primary);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

/* Reset code inside pre since wrapper handles bg */
.code-block-wrapper pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
}

/* Lists */
.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

/* Utils */
.hidden {
    display: none !important;
}


/* Analytics & Scores */
.score-card {
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.score-info h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-muted);
}

.score-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
}

.progress-container {
    flex: 1;
    margin-left: 2rem;
    height: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

[data-theme="dark"] .progress-container {
    background: rgba(255, 255, 255, 0.05);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 5px;
    width: 0%;
    transition: width 1s ease-out;
}

.score-card.danger .score-value {
    color: var(--danger);
}

.score-card.danger .progress-bar {
    background: var(--danger);
}

.score-card.warning .score-value {
    color: var(--warning);
}

.score-card.warning .progress-bar {
    background: var(--warning);
}

.score-card.success .score-value {
    color: var(--success);
}

.score-card.success .progress-bar {
    background: var(--success);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s;
}

.modal {
    background: var(--bg-panel);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-body p {
    margin-bottom: 1rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-mono);
}

.modal-footer {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
}

.link {
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
}

.link:hover {
    text-decoration: underline;
}

.close-modal {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-main);
    color: var(--bg-panel);
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-size: 0.9rem;
    box-shadow: var(--shadow-md);
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 200;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow-y: auto;
    }

    .panel {
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .editor-container {
        min-height: 300px;
    }

    .tabs-header {
        padding: 0.5rem 1rem;
    }
}

/* FIX OVERLAP ISSUE */
.tab-pane {
    position: relative;
    z-index: 5;
    background: var(--bg-primary);
}

#emptyState,
#loadingState {
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    z-index: 1;
}

.tabs-content {
    position: relative;
    min-height: 400px;
}

/* =========================================
   NEW FEATURES
   ========================================= */

/* 1. HEALTH DASHBOARD */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.health-card {
    background: var(--bg-app);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.health-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.health-header h4 {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.health-score-big {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.health-bar-track {
    height: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

[data-theme="dark"] .health-bar-track {
    background: rgba(255, 255, 255, 0.05);
}

.health-bar-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 1s ease-out;
}

/* 2. DIFF VIEW */
.diff-container {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: var(--bg-panel);
    max-height: 600px;
    overflow-y: auto;
}

.diff-panel {
    flex: 1;
    padding: 0;
    overflow-x: auto;
}

.diff-panel.original {
    border-right: 1px solid var(--border-color);
    background: rgba(239, 68, 68, 0.02);
}

.diff-panel.modified {
    background: rgba(16, 185, 129, 0.02);
}

[data-theme="dark"] .diff-panel.original {
    background: rgba(239, 68, 68, 0.05);
}

[data-theme="dark"] .diff-panel.modified {
    background: rgba(16, 185, 129, 0.05);
}

.diff-line {
    display: flex;
    line-height: 1.5;
}

.diff-num {
    padding: 0 0.5rem;
    color: var(--text-muted);
    border-right: 1px solid var(--border-color);
    user-select: none;
    min-width: 3rem;
    text-align: right;
    opacity: 0.6;
}

.diff-code {
    padding: 0 0.5rem;
    white-space: pre;
    flex: 1;
}

.diff-line.removed {
    background: rgba(239, 68, 68, 0.1);
}

.diff-line.added {
    background: rgba(16, 185, 129, 0.1);
}

/* 3. MCQ CARDS */
.mcq-card {
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.mcq-question {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
    font-size: 1.05rem;
}

.mcq-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.mcq-option {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.mcq-option:hover {
    background: rgba(124, 58, 237, 0.05);
    border-color: var(--primary);
}

.mcq-option.correct {
    background: rgba(16, 185, 129, 0.1) !important;
    border-color: var(--success) !important;
    color: var(--success);
    font-weight: 600;
}

.mcq-option.wrong {
    background: rgba(239, 68, 68, 0.1) !important;
    border-color: var(--danger) !important;
    color: var(--danger);
}

.mcq-answer-btn {
    margin-top: 1rem;
    font-size: 0.85rem;
    text-decoration: underline;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}