/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2333;
    --bg-input: #0d1117;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #f0a500;
    --accent-hover: #d4940a;
    --green: #3fb950;
    --green-bg: rgba(63, 185, 80, 0.15);
    --amber: #f0a500;
    --amber-bg: rgba(240, 165, 0, 0.15);
    --red: #f85149;
    --red-bg: rgba(248, 81, 73, 0.15);
    --blue: #58a6ff;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 15px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Navbar ===== */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand:hover {
    text-decoration: none;
    color: var(--accent-hover);
}

.navbar-nav {
    display: flex;
    list-style: none;
    margin-left: 2rem;
    gap: 0.25rem;
}

.navbar-nav a {
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: background 0.2s, color 0.2s;
}

.navbar-nav a:hover,
.navbar-nav a.active {
    color: var(--text-primary);
    background: var(--bg-card);
    text-decoration: none;
}

/* ===== Layout ===== */
.page-container {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    gap: 1.5rem;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    min-width: 0;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* ===== Progress Card ===== */
.progress-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.progress-stat + .progress-stat {
    border-top: 1px solid var(--border-color);
}

.progress-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.progress-value {
    font-weight: 600;
    font-size: 0.95rem;
}

.progress-total {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    padding: 1rem 0;
}

.progress-total span {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ===== Filter Pills ===== */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.pill {
    padding: 0.35rem 0.9rem;
    border-radius: 20px;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.pill:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: center;
}

.search-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.55rem 0.9rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.filter-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.55rem 0.9rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    min-width: 130px;
}

.filter-select:focus {
    border-color: var(--accent);
}

/* ===== Problem Table ===== */
.problem-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.problem-table th {
    text-align: left;
    padding: 0.65rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.problem-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.problem-table tr:last-child td {
    border-bottom: none;
}

.problem-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.problem-table tbody tr:hover {
    background: var(--bg-secondary);
}

.status-icon {
    width: 20px;
    text-align: center;
}

.status-icon.solved {
    color: var(--green);
}

.status-icon.unsolved {
    color: var(--text-muted);
}

.problem-id {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-right: 0.5rem;
}

.problem-title-link {
    color: var(--text-primary);
    font-weight: 500;
}

.problem-title-link:hover {
    color: var(--accent);
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-easy {
    background: var(--green-bg);
    color: var(--green);
}

.badge-medium {
    background: var(--amber-bg);
    color: var(--amber);
}

.badge-hard {
    background: var(--red-bg);
    color: var(--red);
}

.badge-topic {
    background: rgba(88, 166, 255, 0.12);
    color: var(--blue);
    font-weight: 500;
}

/* ===== Problem Page ===== */
.problem-layout {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.problem-description {
    width: 45%;
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
}

.problem-editor-panel {
    width: 55%;
    display: flex;
    flex-direction: column;
}

.problem-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.problem-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
}

.problem-id-badge {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.problem-meta {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.problem-body {
    color: var(--text-secondary);
    line-height: 1.8;
}

.problem-body h2 {
    color: var(--text-primary);
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.problem-body p {
    margin-bottom: 0.75rem;
}

.problem-body pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
}

.problem-body code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: var(--bg-primary);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
}

.problem-body pre code {
    background: none;
    padding: 0;
}

.problem-body ul, .problem-body ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.problem-body li {
    margin-bottom: 0.25rem;
}

/* ===== Editor Area ===== */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.editor-toolbar-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
}

.editor-wrapper {
    flex: 1;
    overflow: auto;
    min-height: 250px;
}

.editor-wrapper .cm-editor {
    height: 100%;
}

.editor-wrapper .cm-scroller {
    font-family: var(--font-mono) !important;
    font-size: 14px !important;
}

/* CodeMirror 5 overrides */
.editor-wrapper .CodeMirror {
    height: 100%;
    font-family: var(--font-mono);
    font-size: 14px;
    border: none;
}

/* ===== Test Results Panel ===== */
.test-panel {
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    max-height: 40%;
    overflow-y: auto;
}

.test-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.test-result {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

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

.test-result-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.test-pass {
    color: var(--green);
}

.test-fail {
    color: var(--red);
}

.test-detail {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-top: 0.35rem;
    white-space: pre-wrap;
    word-break: break-all;
}

.test-error {
    color: var(--red);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
    background: var(--red-bg);
    border-radius: var(--radius-sm);
    margin-top: 0.35rem;
    white-space: pre-wrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

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

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card);
    border-color: var(--text-muted);
}

.btn-success {
    background: var(--green);
    color: #000;
    border-color: var(--green);
}

.btn-success:hover {
    filter: brightness(0.9);
}

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red);
}

.btn-danger:hover {
    background: var(--red-bg);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Pyodide Loading ===== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 17, 23, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    gap: 1rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

/* ===== Success Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.modal-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.modal h2 {
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.modal p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.modal-id {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.5rem 1.5rem;
    display: inline-block;
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

/* ===== Admin Page ===== */
.admin-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-control {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.55rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--font-sans);
}

.form-control:focus {
    border-color: var(--accent);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

/* ===== Test Case Editor ===== */
.test-case-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    position: relative;
}

.test-case-item .remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
}

.test-case-item .remove-btn:hover {
    background: var(--red-bg);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
}

/* ===== Admin Questions Table ===== */
.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 1.5rem;
}

.admin-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.admin-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.admin-table tbody tr:hover {
    background: var(--bg-secondary);
}

.action-btns {
    display: flex;
    gap: 0.4rem;
}

/* ===== Login Container ===== */
.login-container {
    max-width: 360px;
    margin: 15vh auto;
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    text-align: center;
}

.login-container h1 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.login-container input {
    width: 100%;
    margin-bottom: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

.login-container input:focus {
    border-color: var(--accent);
}

.login-container .btn {
    width: 100%;
    justify-content: center;
}

.error {
    color: var(--red);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

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

.resizer:hover,
.resizer.active {
    background: var(--accent);
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .page-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .problem-layout {
        flex-direction: column;
        height: auto;
    }

    .problem-description {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 50vh;
    }

    .problem-editor-panel {
        width: 100%;
        min-height: 60vh;
    }

    .resizer {
        display: none;
    }

    .filter-bar {
        flex-wrap: wrap;
    }

    .navbar {
        padding: 0 1rem;
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Markdown content math (rendered as code) ===== */
.problem-body .math-inline {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: var(--bg-primary);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
}

/* ===== Toast notification ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    z-index: 300;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--green);
}

.toast.error {
    border-color: var(--red);
}
