/* =========================================
   NILAI SYSTEM STYLES - MODERN & CLEAN
   Final Consolidated Version (FIXED: class-grid/class-card added)
   ========================================= */

/* 1. Base & Reset */
* {
    box-sizing: border-box;
}

.nilai-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    background: #f8fafc;
    min-height: 100vh;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #334155;
}

/* 2. Header Section */
.nilai-header {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 24px 32px;
    margin-bottom: 32px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    flex-wrap: wrap;
}

.nilai-header > div:first-child {
    flex: 1;
    min-width: 280px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #64748b;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 8px 16px;
    border-radius: 8px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    margin-bottom: 12px;
}

.btn-back:hover {
    color: #3b82f6;
    background: #eff6ff;
    border-color: #3b82f6;
    transform: translateX(-3px);
}

.nilai-header h1 {
    color: #1e293b;
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: -0.025em;
}

.nilai-header h1 i {
    color: #3b82f6;
}

.subtitle {
    color: #64748b;
    font-size: 0.9375rem;
    margin: 0;
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.header-actions a,
.header-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    white-space: nowrap;
}

.header-actions a:hover,
.header-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Button Variants */
.btn-rapor {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}
.btn-rapor:hover {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
}

.btn-export[href*="excel"],
.btn-export:nth-of-type(1) {
    background: linear-gradient(135deg, #10b981, #059669);
}
.btn-export[href*="excel"]:hover,
.btn-export:nth-of-type(1):hover {
    background: linear-gradient(135deg, #059669, #047857);
}

.btn-export[href*="pdf"]:not([href*="excel"]),
.btn-export:nth-of-type(2) {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}
.btn-export[href*="pdf"]:not([href*="excel"]):hover,
.btn-export:nth-of-type(2):hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.btn-print {
    background: linear-gradient(135deg, #64748b, #475569);
}
.btn-print:hover {
    background: linear-gradient(135deg, #475569, #334155);
}

/* 3. Statistics Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.5s ease-out forwards;
    opacity: 0;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.15s; }
.stat-card:nth-child(3) { animation-delay: 0.2s; }
.stat-card:nth-child(4) { animation-delay: 0.25s; }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.stat-icon.total { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stat-icon.average { background: linear-gradient(135deg, #10b981, #059669); }
.stat-icon.highest { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.late { background: linear-gradient(135deg, #ef4444, #dc2626); }
/* Fallback for old class names if used elsewhere */
.stat-icon.submissions { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.stat-icon.range { background: linear-gradient(135deg, #f59e0b, #d97706); }

.stat-info {
    flex: 1;
}

.stat-info h3 {
    font-size: 1.875rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 4px 0;
    line-height: 1.2;
    letter-spacing: -0.025em;
}

.stat-info p {
    font-size: 0.9375rem;
    color: #1e293b;
    margin: 0 0 4px 0;
    font-weight: 600;
}

.stat-info small {
    font-size: 0.8125rem;
    color: #64748b;
    font-weight: 500;
    display: block;
}

/* 4. Section Headers */
.subject-performance h2,
.recent-grades h2,
.class-selector h2,
.student-ranking h2 {
    color: #1e293b;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 24px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid #f1f5f9;
}

.subject-performance h2 i,
.recent-grades h2 i,
.class-selector h2 i,
.student-ranking h2 i {
    color: #3b82f6;
}

/* 5. Content Sections (Performance, Grades, etc.) */
.subject-performance,
.recent-grades,
.class-selector,
.student-ranking {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 28px 32px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 32px;
    animation: fadeInUp 0.6s ease-out forwards;
    opacity: 0;
}

.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.subject-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid #3b82f6;
    transition: all 0.2s ease;
}

.subject-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    background: white;
}

.subject-card h3 {
    color: #1e293b;
    margin: 0 0 16px 0;
    font-size: 1.0625rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subject-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.subject-score {
    text-align: center;
    padding: 12px 16px;
    background: #dbeafe;
    border-radius: 10px;
    min-width: 90px;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2563eb;
    line-height: 1.2;
}

.score-label {
    font-size: 0.75rem;
    color: #1d4ed8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
    display: block;
}

.subject-details {
    flex: 1;
    text-align: right;
}

.subject-details p {
    margin: 6px 0;
    font-size: 0.875rem;
    color: #64748b;
    font-weight: 500;
    line-height: 1.4;
}

.subject-details p:first-child {
    color: #1e293b;
    font-weight: 600;
}

/* 5b. Class Selector Grid (Pilih Kelas) — FIX: previously missing */
.class-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.class-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 24px 20px;
    text-align: center;
    text-decoration: none;
    color: #1e293b;
    border-left: 4px solid #8b5cf6;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.class-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
    background: white;
    border-left-color: #7c3aed;
}

.class-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 8px rgba(139, 92, 246, 0.25);
    margin-bottom: 4px;
    flex-shrink: 0;
}

.class-card h3 {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 700;
    color: #1e293b;
}

.class-card p {
    margin: 0;
    font-size: 0.8125rem;
    color: #64748b;
    font-weight: 500;
}

/* 6. Grades & Ranking Tables */
.grades-table,
.ranking-table {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.grades-table::-webkit-scrollbar,
.ranking-table::-webkit-scrollbar {
    height: 8px;
}
.grades-table::-webkit-scrollbar-track,
.ranking-table::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.grades-table::-webkit-scrollbar-thumb,
.ranking-table::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.grades-table::-webkit-scrollbar-thumb:hover,
.ranking-table::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.grades-table table,
.ranking-table table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    min-width: 800px;
}

.grades-table th,
.grades-table td,
.ranking-table th,
.ranking-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.grades-table th,
.ranking-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.grades-table tbody tr,
.ranking-table tbody tr {
    transition: background-color 0.2s ease;
}

.grades-table tbody tr:hover,
.ranking-table tbody tr:hover {
    background: #f8fafc;
}

.grades-table tbody tr:last-child td,
.ranking-table tbody tr:last-child td {
    border-bottom: none;
}

.tugas-info strong,
.student-info strong {
    color: #1e293b;
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9375rem;
}

.tugas-info small,
.student-info small {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    font-weight: 500;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

.score {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    font-size: 0.875rem;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
    min-width: 60px;
}

.percentage-bar {
    position: relative;
    background: #e2e8f0;
    border-radius: 9999px;
    height: 28px;
    min-width: 110px;
    max-width: 140px;
    overflow: hidden;
}

.percentage-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    border-radius: 9999px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.percentage-bar span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 700;
    color: #1e293b;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
    white-space: nowrap;
}

/* Badges */
.grade-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border: 1px solid transparent;
}

.grade-sangat-baik, .grade-a {
    background: #dcfce7;
    color: #15803d;
    border-color: #86efac;
}

.grade-baik, .grade-b {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

.grade-cukup, .grade-c {
    background: #fef9c3;
    color: #a16207;
    border-color: #fde047;
}

.grade-perlu-perbaikan, .grade-d, .grade-e {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fca5a5;
}

.late-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fee2e2;
    color: #dc2626;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid #fecaca;
}

.ontime-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #dcfce7;
    color: #15803d;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid #86efac;
}

.date {
    color: #64748b;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Aksi (Lihat Detail) button in teacher/admin table */
.btn-detail {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #dbeafe;
    color: #1d4ed8;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-detail:hover {
    background: #3b82f6;
    color: white;
    transform: translateY(-2px);
}

/* 7. Empty State */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    background: white;
    border: 2px dashed #e2e8f0;
    border-radius: 16px;
    animation: fadeInUp 0.5s ease-out forwards;
}

.empty-state i {
    font-size: 4rem;
    color: #cbd5e1;
    margin-bottom: 16px;
    display: block;
}

.empty-state p {
    color: #1e293b;
    font-size: 1.125rem;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.empty-state small {
    color: #64748b;
    font-size: 0.9375rem;
}

/* 8. Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 9. Responsive Design */
@media (max-width: 1024px) {
    .nilai-container {
        padding: 16px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    
    .subject-grid {
        grid-template-columns: 1fr;
    }

    .class-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .nilai-header {
        flex-direction: column;
        gap: 20px;
        padding: 20px;
    }
    
    .header-actions {
        width: 100%;
        justify-content: stretch;
    }
    
    .header-actions a,
    .header-actions button {
        flex: 1;
        font-size: 0.8125rem;
        padding: 10px 12px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .subject-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .subject-score {
        width: 100%;
        text-align: left;
        display: flex;
        align-items: baseline;
        gap: 8px;
    }
    
    .subject-details {
        text-align: left;
        width: 100%;
    }
    
    .grades-table th,
    .grades-table td,
    .ranking-table th,
    .ranking-table td {
        padding: 12px;
        font-size: 0.875rem;
    }

    .class-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .nilai-header h1 {
        font-size: 1.5rem;
    }
    
    .header-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .stat-info h3 {
        font-size: 1.5rem;
    }
    
    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }
}

/* 10. Print Styles */
@media print {
    body {
        background: white !important;
    }
    
    .nilai-container {
        max-width: 100%;
        padding: 0;
        background: white;
    }
    
    .btn-back,
    .header-actions,
    .empty-state {
        display: none !important;
    }
    
    .nilai-header {
        border: none;
        box-shadow: none;
        padding: 0 0 16px 0;
        margin-bottom: 24px;
        border-bottom: 2px solid #1e293b;
    }
    
    .stat-card,
    .subject-card,
    .subject-performance,
    .recent-grades,
    .student-ranking {
        box-shadow: none;
        border: 1px solid #cbd5e1;
        break-inside: avoid;
        page-break-inside: avoid;
        margin-bottom: 16px;
    }
    
    .grades-table,
    .ranking-table {
        border: 1px solid #cbd5e1;
    }
    
    .grades-table th,
    .grades-table td,
    .ranking-table th,
    .ranking-table td {
        padding: 8px;
        font-size: 0.8rem;
    }
    
    .percentage-fill,
    .grade-badge,
    .late-badge,
    .ontime-badge,
    .stat-icon,
    .score {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}