:root {
  --utama: #0d9488;
  --utama-gelap: #0f766e;
  --teks: #0f172a;
  --muted: #64748b;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --garis: #e2e8f0;
  --hadir: #16a34a;
  --terlambat: #d97706;
  --izin: #2563eb;
  --sakit: #7c3aed;
  --alpa: #dc2626;
  --belum: #64748b;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--teks);
  font-size: 15px;
  visibility: hidden;
}
body.siap { visibility: visible; }
[hidden] { display: none !important; }

a { color: var(--utama-gelap); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; }
h2.judul { font-size: 19px; }
.muted { color: var(--muted); font-size: 13px; }
.kecil { font-size: 12px; }
.tengah { text-align: center; }
.kanan { text-align: right; }

/* ---------- Topbar & Nav ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff;
}
.topbar-isi {
  max-width: 1080px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand .b1 { font-weight: 700; font-size: 15px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .b2 { font-size: 11px; opacity: .85; }
.pengguna { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.pengguna .nama { opacity: .95; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.btn-keluar {
  background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 8px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.btn-keluar:hover { background: rgba(255,255,255,.28); }

#nav { position: sticky; top: 54px; z-index: 49; background: #fff; border-bottom: 1px solid var(--garis); }
.nav-isi { max-width: 1080px; margin: 0 auto; display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; scrollbar-width: none; }
.nav-isi::-webkit-scrollbar { display: none; }
.nav-isi a {
  padding: 11px 12px; font-size: 13.5px; color: var(--muted); white-space: nowrap;
  border-bottom: 2.5px solid transparent; font-weight: 500;
}
.nav-isi a.aktif { color: var(--utama-gelap); border-bottom-color: var(--utama); font-weight: 700; }

/* ---------- Wadah & panel ---------- */
.wadah { max-width: 1080px; margin: 0 auto; padding: 14px; padding-bottom: 60px; }
.wadah.sempit { max-width: 640px; }
.panel {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: 0 1px 3px rgba(15, 23, 42, .07);
}
.panel-tanpa-pad { padding: 0; overflow: hidden; }
.baris-antara { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.baris { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Tombol ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff; color: var(--teks); border: 1px solid var(--garis);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.utama { background: var(--utama); border-color: var(--utama); color: #fff; }
.btn.utama:hover { background: var(--utama-gelap); }
.btn.besar { padding: 13px 18px; font-size: 15px; width: 100%; }
.btn.merah { color: var(--alpa); border-color: #fecaca; }
.btn.merah:hover { background: #fef2f2; }
.btn.kecil { padding: 5px 9px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Form ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=month], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--garis); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--teks);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #99f6e4; border-color: var(--utama); }
textarea { min-height: 110px; resize: vertical; }

/* ---------- Badge status ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.b-hadir { background: #dcfce7; color: #166534; }
.b-terlambat { background: #fef3c7; color: #92400e; }
.b-izin { background: #dbeafe; color: #1e40af; }
.b-sakit { background: #ede9fe; color: #5b21b6; }
.b-alpa { background: #fee2e2; color: #991b1b; }
.b-belum { background: #f1f5f9; color: #475569; }

/* ---------- Chip ringkasan ---------- */
.chip-baris { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: 999px; background: #f8fafc; border: 1px solid var(--garis); font-size: 13px;
}
.chip b { font-size: 15px; }
.chip.c-hadir b { color: var(--hadir); }
.chip.c-terlambat b { color: var(--terlambat); }
.chip.c-izin b { color: var(--izin); }
.chip.c-sakit b { color: var(--sakit); }
.chip.c-alpa b { color: var(--alpa); }
.chip.c-belum b { color: var(--belum); }

/* ---------- Stat ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--garis); border-radius: 12px; padding: 12px; text-align: center; }
.stat .angka { font-size: 24px; font-weight: 800; line-height: 1.1; }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat.hadir .angka { color: var(--hadir); }
.stat.terlambat .angka { color: var(--terlambat); }
.stat.izin .angka { color: var(--izin); }
.stat.sakit .angka { color: var(--sakit); }
.stat.alpa .angka { color: var(--alpa); }
.stat.belum .angka { color: var(--belum); }

/* ---------- Avatar bulat (kanan atas) ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  border: 2px solid rgba(255, 255, 255, .65);
  font-weight: 800; font-size: 13px; color: #fff; user-select: none; vertical-align: middle;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-tombol { all: unset; cursor: pointer; display: inline-flex; border-radius: 50%; }
.avatar-tombol:hover .avatar, .avatar-tombol:focus-visible .avatar { border-color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, .35); }

/* ---------- Kehadiran + tren garis ---------- */
.kehadiran { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.kehadiran .stat-grid { flex: 1 1 380px; grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); }
.tren { flex: 1 1 280px; min-width: 260px; max-width: 380px; }
svg.grafik-garis { width: 100%; height: auto; display: block; margin: 4px 0 2px; }
svg.grafik-garis text { font-family: inherit; }
.gr-sumbu { font-size: 8.5px; fill: #94a3b8; }
.gr-garis-dasar { stroke: var(--garis); stroke-width: 1; }
.gr-nilai { font-size: 9px; fill: #0f766e; font-weight: 700; }
.gr-nilai.ini { fill: #0d9488; font-weight: 800; }
.gr-hari { font-size: 9.5px; fill: var(--muted); font-weight: 600; }
.gr-hari.ini { fill: var(--utama-gelap); font-weight: 800; }
.gr-kosong { font-size: 11px; fill: var(--muted); }

@media (max-width: 760px) {
  .kehadiran { align-items: stretch; }
  .kehadiran .stat-grid { flex: 1 1 100%; }
  .tren { flex: 1 1 100%; max-width: none; }
}

/* ---------- Tabel ---------- */
.tabel-wrap { overflow-x: auto; }
table.tabel { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tabel th, table.tabel td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--garis); vertical-align: middle; }
table.tabel thead th { background: #f8fafc; font-size: 12.5px; color: #475569; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
table.tabel tbody tr:hover { background: #f8fafc; }
table.tabel td.angka { font-variant-numeric: tabular-nums; }

/* ---------- Scan ---------- */
.area-kamera { width: 100%; max-width: 520px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #020617; min-height: 200px; }
.area-kamera video { width: 100% !important; height: auto !important; display: block; }
.jam-besar { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--utama-gelap); }

.hasil {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: min(94vw, 520px); z-index: 90; border-radius: 16px; padding: 14px 18px;
  display: flex; align-items: center; gap: 12px; color: #fff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .35);
  animation: naik .18s ease-out;
}
@keyframes naik { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.hasil .ikon { font-size: 30px; font-weight: 800; }
.hasil .n1 { font-size: 18px; font-weight: 800; line-height: 1.15; }
.hasil .n2 { font-size: 13px; opacity: .95; }
.hasil.berhasil { background: var(--hadir); }
.hasil.ulang { background: var(--terlambat); }
.hasil.gagal { background: var(--alpa); }

.daftar-riwayat { display: flex; flex-direction: column; }
.riwayat-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--garis); font-size: 14px; }
.riwayat-item:last-child { border-bottom: 0; }
.pesan-info { background: #fef9c3; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-top: 10px; }

details.input-manual { margin-top: 10px; }
details.input-manual summary { cursor: pointer; font-size: 13.5px; color: var(--utama-gelap); font-weight: 600; }

/* ---------- Kartu pelajar ---------- */
.grid-kartu { display: grid; grid-template-columns: repeat(auto-fill, 85.6mm); gap: 3mm; justify-content: center; }
.kartu {
  width: 85.6mm; height: 54mm; background: #fff; border: 1px solid #94a3b8;
  border-radius: 2.5mm; padding: 2.5mm 3mm; display: flex; flex-direction: column;
  overflow: hidden; break-inside: avoid; page-break-inside: avoid;
}
.kartu-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; border-bottom: 1.5px solid var(--utama-gelap); padding-bottom: 1.5mm; }
.kartu-sekolah { font-size: 10.5px; font-weight: 800; color: var(--utama-gelap); line-height: 1.1; text-transform: uppercase; }
.kartu-label { font-size: 7.5px; letter-spacing: .6px; color: #475569; border: 1px solid #cbd5e1; border-radius: 999px; padding: 1px 6px; white-space: nowrap; }
.kartu-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: .8mm; padding-top: 1mm; }
.kartu-nama { font-size: 13px; font-weight: 800; text-transform: uppercase; line-height: 1.15; }
.kartu-baris { display: flex; gap: 6px; font-size: 10.5px; color: #334155; }
.kartu-baris span { width: 11mm; color: #64748b; }
.kartu-baris b { font-weight: 700; }
.kartu svg.barcode { width: 100%; height: 13mm; }
.kartu-foot { font-size: 7.5px; color: #64748b; text-align: center; }

@media print {
  body { background: #fff; }
  #topbar, #nav, #toast, .tanpa-cetak { display: none !important; }
  .wadah { max-width: none; padding: 0; }
  .panel { box-shadow: none; border-radius: 0; padding: 0; margin: 0; }
  .grid-kartu { display: grid; grid-template-columns: 85.6mm 85.6mm; gap: 2mm; justify-content: flex-start; }
  .kartu { border: 1px dashed #94a3b8; }
  @page { size: A4; margin: 8mm; }
}

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 18px; width: min(94vw, 440px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, .3);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h3 { font-size: 16px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: 12px; z-index: 120;
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13.5px; max-width: 92vw; box-shadow: 0 8px 24px rgba(15,23,42,.4);
  display: none;
}
#toast.tampil { display: block; }
#toast.merah { background: var(--alpa); }
#toast.hijau { background: var(--hadir); }

/* ---------- Login ---------- */
.login-latar {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #0f766e 0%, #14b8a6 55%, #99f6e4 130%);
  padding: 18px;
}
.login-kartu { background: #fff; border-radius: 20px; padding: 26px 22px; width: min(94vw, 400px); box-shadow: 0 24px 60px rgba(15, 23, 42, .3); }
.login-logo { width: 62px; height: 62px; margin: 0 auto 10px; }

/* ---------- Halaman khusus ---------- */
.kelas-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--garis); }
.kelas-item:last-child { border-bottom: 0; }
.aksi-btn { display: flex; gap: 6px; }

.petunjuk li { margin-bottom: 6px; font-size: 14px; }
