/* ==========================================================================
   [BLOK 1: GLOBAL RESET & TYPOGRAPHY]
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: #f8fafc;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

body.iframe-body {
    height: auto;
    overflow-y: auto;
    padding: 20px;
    background-color: #f8fafc;
}

/* ==========================================================================
   [BLOK 2: HEADER & NAVIGASI]
   ========================================================================== */
.top-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 30px; background-color: #ffffff; border-bottom: 1px solid #e2e8f0; }
.header-title { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 22px; }
.title-text h1 { font-size: 16px; font-weight: 700; color: #0f172a; }
.title-text p { font-size: 11px; color: #64748b; margin-top: 1px; }

.header-user { display: flex; align-items: center; gap: 12px; }
.username-badge { background-color: #f1f5f9; padding: 5px 12px; border-radius: 20px; font-size: 12px; color: #475569; font-weight: 600; border: 1px solid #e2e8f0; }
.btn-signout { text-decoration: none; border: 1px solid #e2e8f0; padding: 5px 12px; border-radius: 20px; font-size: 12px; color: #64748b; transition: all 0.2s; }
.btn-signout:hover { background-color: #fee2e2; color: #ef4444; border-color: #fecaca; }

.main-nav { background-color: #ffffff; padding: 0 30px; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
.nav-links { display: flex; gap: 25px; }
.nav-link { text-decoration: none; color: #64748b; font-size: 13px; font-weight: 500; padding: 14px 0; border-bottom: 3px solid transparent; transition: all 0.2s ease; cursor: pointer; }
.nav-link:hover, .nav-link.active { color: #2563eb; border-bottom: 3px solid #2563eb; }

/* ==========================================================================
   [BLOK 3: LAYOUTING & GRID SYSTEM]
   ========================================================================== */
.content-area { flex: 1; padding: 25px; overflow: hidden; }
.content-frame { width: 100%; height: 100%; border: 1px solid #e2e8f0; border-radius: 8px; background-color: #ffffff; }

.grid-2-col { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.col-left { flex: 1; min-width: 300px; }
.col-right { flex: 1.5; min-width: 350px; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin-bottom: 25px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 25px; }

/* ==========================================================================
   [BLOK 4: KARTU (CARDS) & FORM INPUT]
   ========================================================================== */
.content-card, .chart-box { border: 1px solid #e2e8f0; border-radius: 8px; padding: 20px; background: #ffffff; width: 100%; }
.card-title { margin-bottom: 15px; font-size: 15px; color: #1e293b; font-weight: 600; }

.form-group { margin-bottom: 15px; }
.form-label { display: block; font-size: 12px; color: #64748b; margin-bottom: 6px; font-weight: 500; }
.form-control { width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; outline: none; transition: border-color 0.2s; background-color: #ffffff; }
.form-control:focus { border-color: #2563eb; background-color: #f8fafc; }

.metric-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 20px; border-top: 4px solid #cbd5e1; }
.metric-card.green { border-top-color: #22c55e; }
.metric-card.yellow { border-top-color: #f59e0b; }
.metric-card.blue { border-top-color: #3b82f6; }
.metric-card.red { border-top-color: #ef4444; }
.metric-title { font-size: 11px; color: #64748b; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.metric-value { font-size: 32px; font-weight: 800; color: #1e293b; margin-top: 5px; }

/* ==========================================================================
   [BLOK 5: BUTTONS]
   ========================================================================== */
.btn { padding: 9px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background-color: #2563eb; color: white; border-color: #2563eb; }
.btn-primary:hover { background-color: #1d4ed8; border-color: #1d4ed8; }
.btn-danger { background-color: #ef4444; color: white; border-color: #ef4444; }
.btn-danger:hover { background-color: #dc2626; border-color: #dc2626; }
.btn-secondary { background-color: #ffffff; color: #475569; border: 1px solid #cbd5e1; }
.btn-secondary:hover { background-color: #f1f5f9; border-color: #94a3b8; color: #1e293b; }

.btn-update { background-color: #3b82f6; color: white; border-color: #3b82f6; } 
.btn-pdf { background-color: #0f172a; color: white; border-color: #0f172a; } 
.btn-csv { background-color: #ecfdf5; color: #059669; border: 1px solid #10b981; } 
.btn-csv:hover { background-color: #d1fae5; border-color: #059669; }

.btn-block { width: 100%; padding: 12px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ==========================================================================
   [BLOK 6: FILTER BAR & TABEL DATA (DENGAN PROPORSI STATIS)]
   ========================================================================== */
.filter-bar { display: flex; flex-wrap: wrap; gap: 15px; align-items: flex-end; background: #f8fafc; padding: 15px; border-radius: 8px; border: 1px solid #e2e8f0; margin-bottom: 20px; }

.table-wrapper { width: 100%; overflow-x: auto; background: #fff; border-radius: 6px; border: 1px solid #e2e8f0; }
.clean-table { width: 100%; border-collapse: collapse; min-width: 900px; table-layout: fixed; /* Kunci lebar agar tidak menebak-nebak */ }

/* Proporsi Lebar Kolom agar tidak berantakan saat ganti Role */
.col-date { width: 10%; }
.col-siswa { width: 15%; }
.col-jam { width: 10%; }
.col-ket { width: 12%; }
.col-hadir { width: 12%; }
.col-logbook { width: auto; /* Memakan sisa ruang */ }
.col-status { width: 12%; }

.clean-table th, .clean-table td { padding: 14px 15px; text-align: left; font-size: 12px; word-wrap: break-word; }
.clean-table th { background-color: #f8fafc; color: #64748b; font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; border-bottom: 1px solid #e2e8f0; }
.clean-table td { color: #1e293b; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.clean-table tbody tr:hover { background-color: #fcfcfc; }

/* Status Badges */
.status-pill { padding: 4px 10px; border-radius: 20px; font-size: 10px; font-weight: 700; display: inline-block; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.5px; }
.status-green { background-color: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.status-red { background-color: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.status-gray { background-color: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

/* ==========================================================================
   [BLOK 7: MODAL & TOAST]
   ========================================================================== */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: #ffffff; padding: 25px; border-radius: 8px; width: 450px; max-width: 90%; border: 1px solid #cbd5e1; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid #e2e8f0; padding-bottom: 12px; }
.modal-title { font-size: 16px; font-weight: 600; color: #1e293b; }
.btn-close { background: none; border: none; font-size: 18px; color: #94a3b8; cursor: pointer; transition: color 0.2s; }

#toast-container { display: none; position: fixed; top: 20px; right: 20px; z-index: 9999; background: #1e293b; color: white; padding: 12px 24px; border-radius: 6px; font-size: 13px; border: 1px solid #334155; }

/* ==========================================================================
   [BLOK 8: SIHIR PRINT TO PDF]
   ========================================================================== */
@media print {
    /* Set kertas ke format LANDSCAPE (Tidur) agar tabel 7 kolom muat */
    @page { size: landscape; margin: 15mm; }

    /* Sembunyikan elemen UI yang tidak perlu */
    .filter-bar, .metric-grid, .chart-grid, .btn-signout, nav.main-nav { display: none !important; }
    /* Sembunyikan elemen UI yang tidak perlu */
    .filter-bar, .metric-grid, .metric-grid-5, .chart-grid, .btn-signout, nav.main-nav, .no-print { display: none !important; }
    
    /* Format Kertas Putih Bersih */
    body, .iframe-body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    
    /* Munculkan Kop Surat Resmi */
    .print-only { display: block !important; text-align: center; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 2px solid #000; }
    .print-only h2 { font-size: 16px; margin: 0; font-weight: bold; }
    .print-only p { font-size: 12px; margin: 5px 0 0; }
    
    /* Matikan Scroll Box (Agar tabel bisa memanjang ke bawah & tidak terpotong horizontal) */
    .table-wrapper { overflow: visible !important; border: none !important; }
    .content-card { box-shadow: none !important; border: none !important; padding: 0 !important; margin: 0 !important; }
    .card-title { display: none !important; } 
    
    /* Format Tabel Hitam-Putih Tegas */
    table.clean-table { width: 100% !important; border-collapse: collapse !important; border: 1px solid #000 !important; table-layout: auto; }
    table.clean-table th, table.clean-table td { border: 1px solid #000 !important; padding: 6px !important; color: #000 !important; font-size: 10px !important; word-wrap: break-word; }
    table.clean-table th { background-color: #f1f5f9 !important; }
    
    /* Pertahankan warna badge/pill */
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    /* Cegah baris tabel terpotong di batas halaman */
    table.clean-table tr { page-break-inside: avoid !important; }
}

/* ==========================================================================
   [BLOK TAMBAHAN: DASHBOARD BARU (5 Kotak & Flat Icons)]
   ========================================================================== */

/* Grid khusus 5 Kotak Absensi agar rapi berjajar */
.metric-grid-5 { 
    display: grid; 
    grid-template-columns: repeat(5, 1fr); 
    gap: 15px; 
    margin-bottom: 25px; 
}
@media (max-width: 1024px) {
    .metric-grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .metric-grid-5 { grid-template-columns: repeat(2, 1fr); }
}

.metric-card.purple { border-top-color: #a855f7; }

/* Desain Flat Icon Button Minimalis */
.btn-icon {
    background-color: transparent;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
    transform: translateY(-1px);
}
.stat-input {
    border: none !important;
    background: transparent !important;
    border-bottom: 2px solid #cbd5e1 !important;
    border-radius: 0 !important;
    padding: 5px 0 !important;
}
.stat-input:focus {
    border-bottom-color: #2563eb !important;
}