/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --sidebar-width: 180px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
}

/* ─── App Shell ─── */
.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.5rem 1rem;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 0.8rem;
}

.app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gray-900);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-700);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: var(--gray-100); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--gray-700); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.78rem; }
.btn-icon { padding: 0.3rem 0.5rem; font-size: 1.1rem; font-weight: 700; border: none; background: none; cursor: pointer; color: var(--gray-500); }
.btn-icon:hover { color: var(--gray-800); }

/* ─── Cursos List ─── */
.cursos-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.cursos-toolbar h2 { font-size: 1.3rem; }

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

.curso-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.2rem;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: var(--shadow);
}
.curso-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}
.curso-card .curso-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}
.curso-card .curso-school {
    font-size: 0.85rem;
    color: var(--gray-500);
}
.curso-card .curso-actions {
    margin-top: 0.8rem;
    display: flex;
    gap: 0.4rem;
}

/* ─── Workspace Layout ─── */
.workspace {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 100px);
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    border-right: 1px solid var(--gray-200);
    padding-right: 0.8rem;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--gray-200);
}
.sidebar-header strong { font-size: 0.85rem; color: var(--gray-600); }

.groups-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.group-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.1s;
}
.group-item:hover { background: var(--gray-100); }
.group-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.group-item .group-actions {
    display: none;
    gap: 0.2rem;
}
.group-item:hover .group-actions,
.group-item.active .group-actions { display: flex; }
.group-item .group-actions button {
    padding: 0.1rem 0.3rem;
    font-size: 0.7rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--gray-400);
    border-radius: 3px;
}
.group-item .group-actions button:hover { color: var(--gray-700); background: var(--gray-200); }

.main-content {
    flex: 1;
    min-width: 0;
    padding-left: 0.8rem;
}

/* ─── Eval Tabs ─── */
.eval-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 0.6rem;
}
.eval-tab {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: var(--gray-500);
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.eval-tab:hover { color: var(--gray-700); }
.eval-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ─── Grid Toolbar ─── */
.grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.grid-toolbar-left, .grid-toolbar-right {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

/* ─── Grade Grid ─── */
.grade-grid-container {
    overflow-x: auto;
    overflow-y: visible;
    margin-bottom: 0.5rem;
}

.grade-table {
    border-collapse: collapse;
    font-size: 0.78rem;
    white-space: nowrap;
    width: max-content;
    min-width: 100%;
}

.grade-table th,
.grade-table td {
    border: 1px solid var(--gray-200);
    padding: 0.2rem 0.35rem;
    text-align: center;
    vertical-align: middle;
}

.grade-table thead th {
    background: var(--gray-100);
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--gray-600);
    position: sticky;
    top: 0;
    z-index: 2;
}

.grade-table .col-student {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 3;
    background: white;
    min-width: 160px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.grade-table thead .col-student {
    z-index: 4;
    background: var(--gray-100);
}

/* Task header alternating blues */
.grade-table .col-task-header {
    color: white;
    font-weight: 700;
}
.grade-table .col-task-header.task-a { background: #3b82f6; }
.grade-table .col-task-header.task-b { background: #6366f1; }

/* Task sub-header and body cell tints */
.grade-table .task-a-sub { background: #eff6ff; }
.grade-table .task-b-sub { background: #eef2ff; }

/* Exam header alternating greens */
.grade-table .col-exam-header {
    color: white;
    font-weight: 700;
}
.grade-table .col-exam-header.exam-a { background: #16a34a; }
.grade-table .col-exam-header.exam-b { background: #0d9488; }

.grade-table .exam-a-sub { background: #f0fdf4; }
.grade-table .exam-b-sub { background: #f0fdfa; }

/* Total column for each task/exam — bold left border separator */
.grade-table .col-total {
    background: var(--gray-50);
    font-weight: 600;
}
.grade-table .col-task-total {
    border-right: 2px solid var(--gray-400);
    background: #f1f5f9;
    font-weight: 700;
}
.grade-table .col-exam-total {
    border-right: 2px solid var(--gray-400);
    background: #f1f5f9;
    font-weight: 700;
}

.grade-table .col-final {
    background: #fefce8;
    font-weight: 700;
}

.grade-table .col-inactive {
    opacity: 0.4;
}

.grade-table .task-header-row th {
    font-size: 0.7rem;
    padding: 0.15rem 0.3rem;
    border-bottom: none;
}

.grade-table .task-header-row .task-name {
    cursor: pointer;
}
.grade-table .task-header-row .task-name:hover {
    text-decoration: underline;
}

.grade-table input[type="number"] {
    width: 3.2rem;
    padding: 0.15rem 0.2rem;
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    font-size: 0.78rem;
    text-align: center;
    background: white;
}
.grade-table input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}
.grade-table input[type="number"].manual-input {
    width: 3.5rem;
    border-style: dashed;
}

.grade-table input[type="checkbox"] {
    cursor: pointer;
}

.grade-table .grade-fail { color: var(--danger); }
.grade-table .grade-pass { color: var(--success); }
.grade-table .grade-na { color: var(--gray-400); font-style: italic; }

.grade-table .row-even { background: white; }
.grade-table .row-odd { background: var(--gray-50); }
.grade-table .row-even .col-student { background: white; }
.grade-table .row-odd .col-student { background: var(--gray-50); }
.grade-table .row-even .col-task-total,
.grade-table .row-even .col-exam-total { background: #e8ecf1; }
.grade-table .row-odd .col-task-total,
.grade-table .row-odd .col-exam-total { background: #e2e6eb; }

/* ─── Warnings Bar ─── */
.warnings-bar {
    background: #fffbeb;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    color: #92400e;
}
.warnings-bar ul {
    margin: 0;
    padding-left: 1.2rem;
}
.warnings-bar li { margin-bottom: 0.15rem; }

/* ─── Empty State ─── */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--gray-400);
    font-size: 0.9rem;
}

/* ─── Forms ─── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}
.form-grid .full-width { grid-column: 1 / -1; }

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

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.2rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.15s;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.form-group textarea { resize: vertical; }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-weight: 500;
}
.checkbox-label input[type="checkbox"] { margin: 0; }

.form-warning {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

/* ─── Component Row (in task/exam modals) ─── */
.component-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.4rem;
}
.component-row input[type="text"] {
    flex: 2;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.82rem;
}
.component-row input[type="number"] {
    flex: 1;
    max-width: 80px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.82rem;
    text-align: center;
}
.component-row input:focus {
    outline: none;
    border-color: var(--primary);
}
.component-row .btn-remove {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--gray-400);
}
.component-row .btn-remove:hover { color: var(--danger); }

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 2rem 1rem;
}
.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
}
.modal-sm { max-width: 400px; }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close { font-size: 1.5rem; }
.modal-body {
    padding: 1.2rem;
    overflow-y: auto;
    max-height: 70vh;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.8rem 1.2rem;
    border-top: 1px solid var(--gray-200);
}
.modal-divider {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 1rem 0;
}
.modal-subtitle {
    font-size: 0.9rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* ─── Student List (in modal) ─── */
.student-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.85rem;
}
.student-item:last-child { border-bottom: none; }
.student-item .student-actions {
    display: flex;
    gap: 0.2rem;
}

/* ─── Stats ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    text-align: center;
}
.stat-card .stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gray-900);
}
.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
}
.stat-card.pass { border-color: var(--success); }
.stat-card.pass .stat-value { color: var(--success); }
.stat-card.fail { border-color: var(--danger); }
.stat-card.fail .stat-value { color: var(--danger); }

.histogram {
    display: flex;
    align-items: flex-end;
    gap: 0.3rem;
    height: 100px;
    padding: 0.5rem 0;
}
.histogram-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}
.histogram-bar .bar {
    width: 100%;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s;
}
.histogram-bar .bar-label {
    font-size: 0.65rem;
    color: var(--gray-500);
}
.histogram-bar .bar-count {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--gray-700);
}

/* ─── Import Preview ─── */
.import-summary p { font-size: 0.85rem; margin-bottom: 0.3rem; }
.import-warning { color: #b45309; font-size: 0.85rem; margin-bottom: 0.3rem; }

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--gray-800);
    color: white;
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes slideIn {
    from { transform: translateY(1rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Print ─── */
@media print {
    body { background: white; font-size: 9pt; }
    .app-header, .sidebar, .eval-tabs, .grid-toolbar, .warnings-bar, .empty-state,
    .modal-overlay, .toast { display: none !important; }
    .workspace { display: block; }
    .main-content { padding: 0; }
    .grade-grid-container { overflow: visible; }
    .grade-table { font-size: 8pt; }
    .grade-table th, .grade-table td { padding: 2px 4px; }
    .grade-table .col-student { position: static; }
    .grade-table thead th { position: static; }
    .grade-table input[type="number"],
    .grade-table input[type="checkbox"] { display: none; }
    .grade-table .print-value { display: inline !important; }
    .print-header { display: block !important; margin-bottom: 0.5rem; }
}
.print-header { display: none; }
.grade-table .print-value { display: none; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .workspace { flex-direction: column; }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
        padding-right: 0;
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
    }
    .groups-list { flex-direction: row; flex-wrap: wrap; gap: 0.3rem; }
    .main-content { padding-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
}
