/* =============================================
   Exercise Extension Styles
   ============================================= */

/* Wide container */
.container-wide {
    max-width: 1400px;
}

/* Page header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h2 {
    margin-bottom: 1.5rem;
}

.page-header .btn + h2 {
    margin-top: 1rem;
}

.page-header .help-text {
    margin-bottom: 1.5rem;
}

/* Card header with actions */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.card-header h3 {
    margin: 0;
}

/* Inline forms */
.inline-form {
    background: var(--bg);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

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

.text-input,
.textarea-input {
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    min-width: 200px;
    flex: 1;
}

.textarea-input {
    resize: vertical;
    min-height: 80px;
}

.text-input:focus,
.textarea-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.full-width {
    width: 100%;
    flex: 1 1 100%;
}

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

/* File uploads */
.file-uploads {
    flex-direction: column;
}

.file-upload-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-upload-group label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
}

/* Chart image preview and paste target */
.chart-image-preview {
    max-width: 100%;
    max-height: 500px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.chart-paste-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    color: var(--muted);
    background: var(--bg);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.chart-paste-area:hover,
.chart-paste-area:focus-within {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.chart-paste-area p {
    margin: 0;
    font-size: 0.9rem;
}

/* List items */
.items-list {
    display: flex;
    flex-direction: column;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.list-item:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.list-item.active {
    background: #eff6ff;
    border-color: var(--primary);
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.item-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

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

/* Button variants */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-xs {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* Status info type */
.status-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: var(--primary);
}

/* Sortable list items */
.sortable-item {
    cursor: grab;
    align-items: center;
}

.sortable-item .item-info {
    flex: 1;
    cursor: pointer;
}

.sortable-item:active {
    cursor: grabbing;
}

.sortable-item.dragging {
    opacity: 0.5;
    border: 2px dashed var(--primary);
}

.drag-handle {
    margin-right: 0.75rem;
    color: var(--text-muted);
    cursor: grab;
    user-select: none;
    font-size: 1.1rem;
}

.type-tag {
    display: inline-block;
    background: #dbeafe;
    color: var(--primary);
    padding: 0.1rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

/* Microbit exercise styles */
.microbit-hex {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    max-height: 400px;
    overflow: auto;
    font-family: monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 1rem 0;
}

.microbit-file-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.microbit-file-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.microbit-file-list li:last-child {
    border-bottom: none;
}

.microbit-file-link {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 500;
}

.microbit-submitted-preview {
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.microbit-preview-label {
    padding: 0.5rem 0.75rem;
    background: var(--bg, #f8fafc);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.microbit-pdf-preview {
    display: block;
    border: none;
}

/* =============================================
   Student Course View
   ============================================= */

.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.course-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
}

.course-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.course-card-header {
    margin-bottom: 0.75rem;
}

.course-subject-badge {
    background: #dbeafe;
    color: var(--primary);
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.course-card h3 {
    margin-bottom: 0.5rem;
}

.course-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.course-card-footer {
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}

/* Module view */
.module-block {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.module-header {
    padding: 1.25rem 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.module-header h3 {
    margin-bottom: 0.25rem;
}

.module-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.exercises-list {
    padding: 0;
}

.exercise-item {
    display: flex;
    align-items: center;
    gap: 5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background 0.2s;
}

.exercise-item-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

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

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

.exercise-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.exercise-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.exercise-status {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-not-started {
    background: #f1f5f9;
    color: var(--text-muted);
}

.status-in-progress {
    background: #fef3c7;
    color: #92400e;
}

.status-submitted {
    background: #d1fae5;
    color: #065f46;
}

.status-feedback {
    background: #e0f2fe;
    color: #0c4a6e;
}

.status-rework {
    background: #f3e8ff;
    color: #6b21a8;
}

.exercise-score {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* =============================================
   Exercise Page (shared / Univer)
   ============================================= */

.exercise-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.exercise-header {
    padding: 0.75rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.exercise-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.exercise-title-bar h2 {
    font-size: 1.2rem;
    margin: 0;
}

.exercise-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0.75rem 0 0;
    max-height: 300px;
    overflow: hidden auto;
    word-break: break-all;
    overflow-wrap: break-word;
}

.exercise-desc ul,
.exercise-desc ol {
    margin: 0.5rem 0 0.5rem 0.5rem;
    padding-left: 2rem;
}

.exercise-desc li {
    margin: 0.25rem 0;
}

.exercise-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#excel-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: visible;
    align-items: flex-start;
}

#excel-upload-preview,
#excel-chart-preview,
.file-upload-preview {
    position: relative;
    height: 400px;
    min-height: 400px;
    overflow: hidden;
    margin: 0;
    width: 100%;
}

.file-upload-preview .file-upload-preview-overlay,
#excel-upload-preview .excel-upload-preview-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    cursor: pointer;
    background: transparent;
}

#score-section {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    margin: 0;
    flex: 0 0 auto;
}

#python-code-render {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre;
    margin: 0;
}

.python-code-blank {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    padding: 0.1rem 0.3rem;
    margin: 0 0.1rem;
    min-width: 2rem;
    text-align: center;
    color: #212529;
    background: #fff;
}

.python-code-blank:disabled {
    background: #e9ecef;
    color: #212529;
    border-color: #adb5bd;
}

#python-code-score-section {
    margin-top: 1rem;
}

.save-indicator {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.save-indicator.saved {
    color: var(--success);
    background: #f0fdf4;
}

.save-indicator.unsaved {
    color: #92400e;
    background: #fef3c7;
}

.submitted-banner {
    background: #d1fae5;
    color: #065f46;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Score display */
.score-card {
    margin-top: 1rem;
    display: block;
}

.score-overview {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 1.5rem 0;
}

.score-big {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
}

.score-percentage {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.score-original {
    font-size: 1rem;
    color: var(--text-muted);
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.score-table th,
.score-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    word-break: break-all;
    overflow-wrap: break-word;
}

.score-details {
    display: block;
    overflow: auto;
}

.score-table code {
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: break-word;
}

.score-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.score-table tr.correct td {
    background: #f0fdf4;
}

.score-table tr.incorrect td {
    background: #fef2f2;
}

.score-table code {
    background: var(--bg);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.85em;
}

/* =============================================
   Progress Dashboard
   ============================================= */

.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-card {
    text-align: center;
    padding: 1.5rem 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Progress table */
.table-responsive {
    overflow-x: auto;
}

.progress-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 600px;
}

.progress-table th,
.progress-table td {
    padding: 0.6rem 0.75rem;
    text-align: center;
    border: 1px solid var(--border);
}

.progress-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
}

.progress-table td:first-child {
    text-align: left;
}

.cell-not-started {
    color: var(--text-muted);
}

.cell-in-progress {
    background: #fef3c7;
    color: #92400e;
}

.cell-good {
    background: #d1fae5;
    color: #065f46;
}

.cell-medium {
    background: #fef3c7;
    color: #92400e;
}

.cell-poor {
    background: #fecaca;
    color: #991b1b;
}

.cell-feedback {
    background: #e0f2fe;
    color: #0c4a6e;
    font-weight: 500;
}

.cell-rework {
    background: #f3e8ff;
    color: #6b21a8;
    font-weight: 500;
}

.cell-detail {
    cursor: pointer;
}

/* Score bar */
.score-bar {
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    margin-top: 1rem;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease;
}

.result-cell {
    white-space: nowrap;
}

.result-correct {
    color: var(--success);
    font-weight: 600;
}

.result-incorrect {
    color: var(--danger);
    font-weight: 600;
}

/* Detail section */
.detail-summary {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
}

/* Archived status */
.status-archived {
    background: #e5e7eb;
    color: #374151;
}

.cell-archived {
    background: #e5e7eb;
    color: #374151;
    font-weight: 500;
}

.exercise-item-disabled {
    cursor: not-allowed;
    opacity: 0.7;
    background: var(--bg);
}

.exercise-item-disabled .exercise-item-info strong {
    color: var(--text-muted);
}

/* Archive page */
.select-all-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.archive-student-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
}

.archive-student-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
}

.archive-student-item:hover {
    background: var(--bg);
}

.archive-student-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.archive-student-item .help-text {
    margin-left: auto;
    font-size: 0.8rem;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

/* Visibility toggle for courses and modules */
.list-item.hidden-item .item-info {
    opacity: 0.6;
}

.visibility-toggle {
    min-width: 2rem;
}
