/* Import Font Google */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

/* Reset Global */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 1. KUNCI LAYAR: Matikan scroll body, gunakan dvh untuk mobile */
body {
    font-family: 'Inter', sans-serif;
    background-color: #f4f7f6;
    color: #333;
    display: flex;
    flex-direction: column;
    height: 100vh; /* Fallback browser lama */
    height: 100dvh; /* Solusi modern untuk address bar HP */
    overflow: hidden; 
}

/* Header Mewah & Elegan Dua Kolom */
.main-header {
    background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    color: #ffffff;
    padding: 15px 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 100;
    flex-shrink: 0;
}

.header-container {
    max-width: 1300px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto auto; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 20px;
}

.header-left {
    display: flex;
    align-items: center;
}

.header-logo {
    height: 70px;
    margin-right: 25px;
    filter: drop-shadow(0px 2px 4px rgba(0,0,0,0.5));
}

.header-text h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 3px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.header-text p {
    font-size: 13px;
    color: #d1d5db;
    font-weight: 400;
}

/* Aturan Default (Desktop): Tampilkan teks panjang, sembunyikan teks singkatan */
.teks-desktop {
    display: inline;
}
.teks-mobile {
    display: none;
}

/* Kolom Kanan: Status Bar Live */
.header-right {
    display: flex;
    flex-direction: column; 
    align-items: flex-end; 
    background-color: rgba(255, 255, 255, 0.1); 
    padding: 10px 15px;
    border-radius: 8px;
    backdrop-filter: blur(5px); 
}

.status-top-row {
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    width: 100%; 
    margin-bottom: 3px;
}

.status-indicator {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    color: #34d399; 
}

.pulse {
    width: 9px;
    height: 9px;
    background-color: #34d399;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 0 rgba(52, 211, 153, 0.4);
    animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
    0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(52, 211, 153, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.last-update {
    font-size: 12px;
    color: #cbd5e1; 
    margin-top: 5px;
}

/* Tombol Fullscreen */
.btn-fullscreen {
    background: rgba(255,255,255,0.15); 
    border: 1px solid rgba(255,255,255,0.3); 
    color: white; 
    border-radius: 5px; 
    cursor: pointer;
    padding: 4px 10px;
    font-size: 12px;
    font-family: inherit;
    transition: all 0.2s ease;
}

.btn-fullscreen:hover {
    background: rgba(255,255,255,0.3);
}

/* 2. KONTAINER UTAMA: Penuhi layar sisa */
.content-container {
    max-width: 1300px;
    width: 100%;
    margin: 15px auto;
    padding: 0 20px;
    flex: 1; /* Mendorong footer ke bawah */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Konten utama tidak luber */
}

/* Layout Penyejajar Tabel (Desktop) */
.tables-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    flex: 1; /* Mengisi sisa ruang vertikal */
    overflow: hidden; /* Batasi tinggi untuk desktop */
}

/* 3. SEKSI TABEL: Flexbox untuk area scroll */
.table-section {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    height: 100%; /* Penuhi tinggi grid */
    overflow: hidden;
}

/* Judul Tabel */
.table-header-title {
    padding: 12px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.data-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.putra-title { background-color: #e0f2fe; }
.putra-title h2 { font-size: 17px; color: #0369a1; }
.badge-putra { background-color: #0284c7; color: #ffffff; }

.putri-title { background-color: #f3e8ff; }
.putri-title h2 { font-size: 17px; color: #6d28d9; }
.badge-putri { background-color: #9333ea; color: #ffffff; }

/* 4. AREA SCROLL: Pindahkan fungsi scroll ke sini */
.table-responsive {
    flex: 1; /* Penuhi sisa ruang di bawah judul */
    overflow-y: auto; /* Aktifkan scroll di dalam tabel */
}

/* Desain Tabel */
.styled-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.styled-table thead th {
    position: sticky;
    top: 0;
    background-color: #f1f5f9;
    color: #334155;
    font-weight: 600;
    font-size: 13px; 
    padding: 12px 10px; 
    border-bottom: 2px solid #cbd5e1;
    z-index: 10;
    box-shadow: 0 2px 2px -1px rgba(0,0,0,0.1);
}

.styled-table tbody td {
    padding: 10px 10px; 
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px; 
}

.styled-table tbody tr:last-of-type td { border-bottom: none; }
.styled-table tbody tr:nth-child(even) { background-color: #f8fafc; }
.styled-table tbody tr:hover { background-color: #f1f5f9; }

.rank-col {
    font-weight: 700;
    color: #2c5364;
    text-align: center;
}

.nilai-col {
    font-weight: 600;
    color: #10b981;
}

.loading {
    text-align: center;
    padding: 30px !important;
    color: #94a3b8;
    font-style: italic;
    font-size: 13px;
}

/* --- FOOTER ELEGAN --- */
.main-footer {
    background-color: #0f2027; 
    color: #cbd5e1;
    text-align: center;
    padding: 12px 0;
    margin-top: 0; 
    border-top: 4px solid #10b981; 
    flex-shrink: 0; /* Cegah footer menyusut */
}

.footer-container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 20px;
}

.main-footer p {
    margin-bottom: 3px;
    font-size: 13px;
}

.main-footer p:last-child {
    margin-bottom: 0;
    font-size: 12px;
    opacity: 0.7;
}

/* =========================================
   GAYA UNTUK TOMBOL AKSI & MODAL (POP-UP)
   ========================================= */

.btn-lihat {
    background-color: #f1f5f9;
    color: #0284c7;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-lihat:hover {
    background-color: #0284c7;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);
}

.action-col { text-align: center !important; }

.modal-overlay {
    display: none; 
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(15, 32, 39, 0.7); 
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

.modal-content {
    background-color: #ffffff;
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    animation: modalSlideIn 0.3s ease forwards;
    overflow: hidden;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    background: linear-gradient(135deg, #0f2027, #203a43);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 { font-size: 16px; margin: 0; }

.close-btn {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: #94a3b8;
    transition: color 0.2s;
    line-height: 1;
}

.close-btn:hover { color: #ffffff; }

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-school {
    color: #64748b;
    font-size: 13px;
    margin-bottom: 15px;
    font-weight: 600;
    text-align: center;
    border-bottom: 2px dashed #e2e8f0;
    padding-bottom: 10px;
}

.score-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.score-card {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
}

.score-card-title {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 10px;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 5px;
}

.score-item {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    color: #475569;
}

.score-item strong { color: #0f172a; }

.score-highlight {
    background-color: #e0f2fe;
    padding: 5px;
    border-radius: 4px;
    font-weight: 700;
    margin-top: 8px;
    border-top: 1px dashed #bae6fd;
}

.score-final {
    grid-column: span 2;
    background-color: #10b981;
    color: white;
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    margin-top: 5px;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}

/* =========================================
   MEDIA QUERY: PENYESUAIAN MOBILE (CARD VIEW COMPACT + STICKY HEADER)
   ========================================= */
@media (max-width: 992px) {
    .header-container { grid-template-columns: 1fr; justify-content: center; text-align: center; gap: 10px; }
    .header-left { flex-direction: column; }
    .header-logo { margin-right: 0; margin-bottom: 10px; height: 60px; }
    .header-text h1 { font-size: 22px; }
    .header-right { 
        flex-direction: row; /* Ubah susunan menjadi kiri-kanan */
        justify-content: center; 
        align-items: center; 
        width: 100%; 
        gap: 15px; /* Jarak antara icon Live dan teks waktu */
        padding: 8px 10px; /* Buat kotaknya lebih tipis/ramping */
    }
    .status-top-row { 
        width: auto; /* Ukuran secukupnya, tidak perlu 100% */
        margin-bottom: 0; /* Hilangkan jarak bawah */
        justify-content: center; 
    }
    .last-update {
        margin-top: 0; /* Hilangkan jarak atas */
        font-size: 11px; /* Teks sedikit dikecilkan agar muat di HP kecil */
    }
    .btn-fullscreen { display: none !important; }

    /* Balikkan kondisinya di HP: Sembunyikan teks panjang, tampilkan singkatan */
    .teks-desktop {
        display: none !important;
    }
    .teks-mobile {
        display: inline !important;
    }
    
    /* Layout Wrapper Utama Mobile */
    .tables-wrapper {
        display: flex; flex-direction: column; gap: 20px;
        overflow-y: auto; overflow-x: hidden; padding-bottom: 20px; width: 100%;
    }

    /* Hilangkan background dari section agar kartu terlihat mengambang */
    .table-section {
        display: block; height: auto !important; min-height: min-content; width: 100%;
        background: transparent !important; box-shadow: none !important;
        overflow: visible !important; /* WAJIB visible agar efek sticky bekerja */
    }

    /* --- MAGIC: STICKY HEADER --- */
    .table-header-title { 
        border-radius: 12px; 
        margin-bottom: 15px; 
        box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
        
        position: sticky; /* Kunci Elemen */
        top: 0; /* Menempel di jarak 0 dari atas kontainer scroll */
        z-index: 50; /* Pastikan ia berada di atas kartu-kartu yang discroll */
    }
    
    .table-responsive { overflow: visible !important; height: auto !important; max-height: none !important; }
    .styled-table { min-width: 100% !important; }
    .styled-table thead { display: none; }
    
    /* --- BUNGKUSAN KARTU KILAT (COMPACT) --- */
    .styled-table tbody tr {
        display: flex; flex-wrap: wrap; align-items: center;
        background: #ffffff; border-radius: 12px;
        padding: 12px 15px; 
        margin-bottom: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.05);
        border: 1px solid #e2e8f0;
    }

    .styled-table tbody td { padding: 0 !important; border: none !important; display: flex; align-items: center; }

    /* 1. RANK BADGE (Kiri Atas) */
    .styled-table tbody td.rank-col {
        order: 1; width: auto;
        background: linear-gradient(135deg, #0284c7, #0369a1);
        color: #ffffff !important; padding: 4px 12px !important;
        border-radius: 20px; font-size: 12px !important; font-weight: 700;
        margin-bottom: 10px; box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
    }
    .styled-table tbody td.rank-col::before { content: "Rank "; margin-right: 3px; font-weight: 400; font-size: 11px; opacity: 0.9; }

    /* 2. NILAI AKHIR (Kanan Atas) */
    .styled-table tbody td.nilai-col {
        order: 2; width: auto; margin-left: auto; margin-bottom: 10px;
        font-size: 18px !important; font-weight: 800; color: #10b981;
    }

    /* 3. NAMA PESERTA (Baris Tengah) */
    .styled-table tbody td:nth-child(3) {
        order: 3; width: 100%; font-size: 15px; font-weight: 700; color: #0f172a;
        margin-bottom: 12px; line-height: 1.3;
    }

    /* 4. NO PESERTA (Baris Bawah, Kiri) */
    .styled-table tbody td:nth-child(2) {
        order: 4; width: auto; font-size: 11px; color: #475569;
        background: #f1f5f9; padding: 4px 8px !important; border-radius: 6px;
        margin-right: 8px; font-weight: 600;
    }

    /* 5. ASAL SEKOLAH (Baris Bawah, Tengah) */
    .styled-table tbody td:nth-child(4) {
        order: 5; flex: 1; font-size: 12px; color: #64748b; 
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 10px !important; 
    }
    .styled-table tbody td:nth-child(4)::before { content: "🏫 "; }

    /* 6. TOMBOL AKSI (Baris Bawah, Kanan) */
    .styled-table tbody td.action-col {
        order: 6; width: auto; flex-shrink: 0; border-top: none !important; padding-top: 0 !important;
    }
    
    /* Loading Data */
    .styled-table tbody tr td[colspan="6"] { order: 1; width: 100%; justify-content: center; font-size: 14px; }

    .main-footer { padding: 10px 0; }
}

@media (max-width: 600px) {
    .score-grid { grid-template-columns: 1fr; }
    .score-final { grid-column: span 1; }
}