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

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --primary: #0d6efd;
  --primary-hover: #0b5ed7;
  --success: #198754;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #0dcaf0;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

.container { max-width: 1800px; margin: 0 auto; padding: 0 1rem; }
.container-wide { max-width: none; padding: 0 1.25rem; }

/* Nav */
nav { background: var(--text); color: #fff; padding: 0.75rem 0; margin-bottom: 1.5rem; }
.nav-inner { display: flex; align-items: baseline; gap: 2rem; }
.nav-user { margin-left: auto; color: #ced4da; font-size: 0.85rem; }
.nav-brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.2rem; }
.nav-links { display: flex; gap: 1rem; }
.nav-links a { color: #ced4da; text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; }

/* Buttons */
.btn { display: inline-block; padding: 0.4rem 0.9rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 0.9rem; font-family: inherit; line-height: 1.5; cursor: pointer; box-sizing: border-box; }
.btn:hover { background: #e9ecef; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 0.2rem 0.6rem; font-size: 0.8rem; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 3px; font-size: 0.8rem; font-weight: 600; }
.badge-success { background: #d1e7dd; color: #0f5132; }
.badge-danger { background: #f8d7da; color: #842029; }
.badge-warning { background: #fff3cd; color: #664d03; }
.badge-info { background: #cff4fc; color: #055160; }
.badge-muted { background: #e9ecef; color: var(--muted); }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1.5rem; text-align: center; }
.stat-number { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-sub { margin-top: 0.3rem; font-size: 0.8rem; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1rem; }
.data-table th, .data-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.data-table th { background: #f1f3f5; font-weight: 600; }
.data-table tr:hover { background: #f8f9fa; }
.data-table tr.row-dirty { background: #fff7e6; }
.data-table tr.row-dirty:hover { background: #fff1cc; }
.sort-header-btn { width: 100%; border: 0; background: transparent; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 0.25rem; padding: 0; font: inherit; font-weight: inherit; text-align: left; }
.sort-header-btn:hover { color: var(--primary); }
.sort-indicator::after { content: "-"; color: var(--muted); font-size: 0.75rem; }
th[data-sort-dir="asc"] .sort-indicator::after { content: "^"; color: var(--primary); }
th[data-sort-dir="desc"] .sort-indicator::after { content: "v"; color: var(--primary); }

.info-table td { padding: 0.4rem 0.75rem; }
.info-table td:first-child { font-weight: 600; color: var(--muted); white-space: nowrap; width: 150px; }

/* Forms */
.full-width { width: 100%; }
textarea { width: 100%; padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-family: inherit; font-size: 0.9rem; resize: vertical; overflow-y: hidden; }
input[type="text"], input[type="number"] { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; }
.input-small { width: 80px; }
select { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; }

/* Layout helpers */
.page-title-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.segmented-nav { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; background: var(--surface); }
.segmented-nav a { padding: 0.35rem 0.75rem; color: var(--text); text-decoration: none; font-size: 0.85rem; border-left: 1px solid var(--border); }
.segmented-nav a:first-child { border-left: 0; }
.segmented-nav a:hover { background: #e9ecef; }
.segmented-nav a.active { background: var(--primary); color: #fff; }
.actions-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.actions-bar form { margin: 0; }
.filter-bar { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.input-filter { padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; background: var(--surface); color: var(--text); }
.filter-bar { margin-bottom: 1rem; }
.filter-form { display: flex; gap: 0.5rem; align-items: center; }
.inline-form { display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap; }
.detail-section { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.deadline-admin h2 { margin-bottom: 0.75rem; }
.selected-actions-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.selected-actions-bar button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Server-side mark summary */
.mark-summary-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-bottom: 1rem; color: var(--muted); font-size: 0.9rem; }
.mark-summary-meta strong { color: var(--text); }
.mark-summary-list { display: grid; gap: 0.75rem; }
.mark-summary-item { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.mark-summary-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.35rem; }
.mark-summary-heading h3 { margin: 0; font-size: 1rem; }
.mark-summary-score { color: var(--muted); font-weight: 600; white-space: nowrap; }
.mark-summary-feedback { white-space: pre-wrap; overflow-wrap: anywhere; }
.mark-summary-notes { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 0.75rem; }
.mark-summary-notes h3 { margin-bottom: 0.35rem; font-size: 1rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.alert-warning { background: #fff3cd; color: #664d03; border: 1px solid #ffecb5; }
.alert-info { background: #cff4fc; color: #055160; border: 1px solid #b6effb; }

/* Logs */
.error-log, .build-log { background: #1e1e1e; color: #d4d4d4; padding: 0.75rem; border-radius: 4px; font-size: 0.8rem; overflow-x: auto; max-height: 400px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }

/* Marking layout */
.marking-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
.marking-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(520px, 0.9fr); gap: 1rem; }
@media (min-width: 2200px) { .marking-layout { grid-template-columns: minmax(0, 1.7fr) minmax(560px, 0.85fr); } }
@media (max-width: 1200px) { .marking-layout { grid-template-columns: 1fr; } }

.marking-content { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; max-height: 85vh; overflow-y: auto; }
.marking-form-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; max-height: 85vh; overflow-y: auto; }
.repo-meta-bar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: -0.25rem 0 0.75rem; color: var(--muted); font-size: 0.85rem; }
.repo-meta-bar strong { color: var(--text); }
.repo-meta-bar code { background: #f1f3f5; padding: 0.1rem 0.3rem; border-radius: 3px; color: var(--text); }
.repo-commit-subject { max-width: 42rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-link-warning { color: #664d03; }

/* Tabs */
.marking-pane-header { position: sticky; top: -1rem; z-index: 20; margin: -1rem -1rem 1rem; padding: 1rem 1rem 0; background: var(--surface); border-bottom: 1px solid var(--border); }
.tab-buttons { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1rem; }
.tab-btn { padding: 0.5rem 1rem; border: none; background: none; cursor: pointer; font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab-btn:hover { background: #f1f3f5; }
.tab-active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
.tab-pane { min-height: 200px; }

/* Rendered content */
.rendered-content { font-size: 0.95rem; }
.rendered-content h1, .rendered-content h2, .rendered-content h3 { margin: 1rem 0 0.5rem; }
.rendered-content p { margin-bottom: 0.75rem; }
.rendered-content img { max-width: 100%; }
.rendered-content pre { background: #f1f3f5; padding: 0.75rem; border-radius: 4px; overflow-x: auto; }
.rendered-content code { background: #f1f3f5; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }

.video-player { width: 100%; max-height: 500px; }

/* Marking file browser */
.file-browser { display: grid; grid-template-columns: minmax(220px, 0.28fr) minmax(0, 1fr); gap: 0.75rem; min-height: 560px; }
.file-tree { border: 1px solid var(--border); border-radius: 4px; background: #f8f9fa; padding: 0.5rem; overflow: auto; }
.file-tree-list { list-style: none; margin: 0; padding-left: 0.8rem; }
.file-tree > .file-tree-list { padding-left: 0; }
.file-tree-item { margin: 0.1rem 0; }
.file-tree-dir-label { width: 100%; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: block; font: inherit; font-size: 0.82rem; font-weight: 600; padding: 0.15rem 0.25rem; text-align: left; border-radius: 3px; overflow-wrap: anywhere; }
.file-tree-dir-label:hover { background: #e9ecef; }
.file-tree-dir-label::before { content: "▸ "; color: var(--muted); }
.file-tree-open > .file-tree-dir-label::before { content: "▾ "; }
.file-tree-dir > .file-tree-list { display: none; }
.file-tree-dir.file-tree-open > .file-tree-list { display: block; }
.file-tree-file { width: 100%; border: 0; background: transparent; color: var(--text); cursor: pointer; display: block; font: inherit; font-size: 0.82rem; padding: 0.15rem 0.25rem; text-align: left; border-radius: 3px; overflow-wrap: anywhere; }
.file-tree-file:hover, .file-tree-file-active { background: #e9ecef; }
.file-preview { min-width: 0; border: 1px solid var(--border); border-radius: 4px; background: #0f172a; display: flex; flex-direction: column; overflow: hidden; }
.file-preview-header { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0.65rem; background: #111827; color: #e5e7eb; font-size: 0.82rem; border-bottom: 1px solid #243047; }
.code-view { margin: 0; padding: 0.75rem; overflow: auto; color: #d1d5db; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; line-height: 1.45; white-space: pre; tab-size: 2; }
.tok-keyword { color: #93c5fd; }
.tok-string { color: #86efac; }
.tok-comment { color: #94a3b8; font-style: italic; }
.tok-number { color: #fca5a5; }
.tok-tag { color: #67e8f9; }
.tok-attr, .tok-key { color: #f9a8d4; }
@media (max-width: 900px) { .file-browser { grid-template-columns: 1fr; } .file-tree { max-height: 260px; } }

/* Component fields in marking form */
.component-field { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 0.75rem; border-bottom: 1px solid var(--border); padding: 0.75rem 0; }
.component-field:last-of-type { border-bottom: none; }
.component-main { min-width: 0; }
.component-header { margin-bottom: 0.3rem; display: flex; align-items: baseline; gap: 0.5rem; }
.component-inputs { min-width: 0; }
.component-criteria { margin: 0; padding: 0.15rem 0 0 1rem; font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.component-criteria li { margin-bottom: 0.2rem; }
.mark-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.mark-max { color: var(--muted); font-size: 0.85rem; }
.feedback-row { margin-top: 0; }
.feedback-row label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.15rem; }
.form-field { margin-bottom: 0.75rem; }
.form-field label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.field-header { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.25rem; }
.field-header label { margin-bottom: 0; }
.input-invalid { border-color: var(--danger); background: #fff5f5; }
.mark-error { color: var(--danger); font-size: 0.75rem; min-width: 4rem; }
.feedback-error { display: block; min-height: 1em; color: var(--danger); font-size: 0.75rem; margin-top: 0.15rem; }

.weighted-total { background: #e8f4f8; padding: 1rem; border-radius: 4px; margin: 1rem 0; font-size: 1.2rem; text-align: center; }

.form-actions { display: flex; gap: 0.5rem; padding-top: 0.5rem; align-items: center; }
.autosave-status { font-size: 0.78rem; margin-left: 0.5rem; }
.local-action-status { font-size: 0.78rem; align-self: center; }
.local-action-error { color: var(--danger); font-weight: 600; }

/* Feedback page */
.feedback-rendered { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1.5rem; margin-top: 1rem; }
.feedback-rendered h2 { margin-top: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.feedback-rendered h2:first-child { margin-top: 0; }

/* Selection & word counts */
.selection-word-count { background: #e9ecef; color: var(--muted); padding: 0.3rem 0.75rem; border-radius: 4px; font-size: 0.85rem; text-align: center; transition: background 0.15s, color 0.15s; }
.selection-word-count.active { background: var(--primary); color: #fff; font-weight: 600; }
.textarea-wrap { position: relative; }
.word-count { position: absolute; top: -1.25rem; right: 0; min-height: 1em; font-size: 0.75rem; color: var(--muted); font-weight: 400; pointer-events: none; white-space: nowrap; }
@media (max-width: 700px) { .component-field { grid-template-columns: 1fr; } .component-criteria { padding-left: 1rem; } }
/* Filter select */
.filter-select { position: relative; }
.filter-select-input { width: 100%; padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; background: var(--surface); }
.filter-select-dropdown { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 4px 4px; max-height: 180px; overflow-y: auto; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.filter-select-option { padding: 0.25rem 0.5rem; font-size: 0.85rem; cursor: pointer; }
.filter-select-option:hover { background: #e9ecef; }

[x-cloak] { display: none !important; }
.legacy-flags .badge { margin-left: 0.4rem; cursor: help; }
.legacy-count { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; cursor: help; }
.legacy-count-warning { background: #fff3cd; border-radius: 3px; padding: 0.1rem 0.25rem; }

.hidden { position: absolute; left: -9999px; }
.muted { color: var(--muted); }

h1 { margin-bottom: 1rem; }
h2 { margin-bottom: 0.75rem; }
