:root {
  --pink: #be185d;
  --pink-mu: #fce7f3;
  --pink-tua: #9d174d;
  --teks: #1f2937;
  --abu: #6b7280;
  --garis: #e5e7eb;
  --bg: #f8fafc;
  --ok: #059669;
  --err: #dc2626;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--teks);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: 30px;
}

h1, h3 { margin: 0; }

/* ---------- bar atas ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--pink), #db2777);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand .logo { font-size: 24px; }
.brand b { display: block; font-size: 16px; line-height: 1.1; }
.brand small { opacity: .85; font-size: 11px; }
.bar-kanan { display: flex; align-items: center; gap: 6px; }

.pil {
  background: rgba(255, 255, 255, .22);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.ikon {
  background: rgba(255, 255, 255, .18);
  border: 0;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.ikon:active { transform: scale(.94); }

/* ---------- menu utama ---------- */
.menu {
  display: flex;
  gap: 6px;
  padding: 10px 14px 0;
  max-width: 1400px;
  margin: 0 auto;
}

.menu-item {
  flex: 1;
  padding: 11px;
  border: 1px solid var(--garis);
  background: #fff;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--abu);
  cursor: pointer;
}

.menu-item.aktif {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

.view { display: none; padding: 12px 14px 0; max-width: 1400px; margin: 0 auto; }
.view.aktif { display: block; }

/* ---------- kamera ---------- */
.kamera-kotak {
  position: relative;
  background: #0b1020;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  max-height: 62vh;
}

#video { width: 100%; height: 100%; object-fit: cover; display: block; }

.reticle {
  position: absolute;
  inset: 16% 8%;
  border: 2px solid rgba(255, 255, 255, .55);
  border-radius: 12px;
  pointer-events: none;
  display: none;
}

.reticle.on { display: block; }

.reticle::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  top: 50%;
  height: 2px;
  background: #f43f5e;
  box-shadow: 0 0 12px #f43f5e;
  animation: sapu 2.1s ease-in-out infinite;
}

@keyframes sapu {
  0%, 100% { transform: translateY(-46%); }
  50% { transform: translateY(46%); }
}

.kamera-mati {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  color: #cbd5e1;
  background: #0b1020;
}

.kamera-alat {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.ikon-bulat {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: rgba(15, 23, 42, .62);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.ikon-bulat.nyala { background: #f59e0b; }

#pilihKamera {
  background: rgba(15, 23, 42, .62);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 9px;
  max-width: 42vw;
  font-size: 12px;
}

/* kilatan hijau/merah saat resi terbaca */
.tanda { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.tanda.ok { background: rgba(16, 185, 129, .35); animation: kedip .45s ease-out; }
.tanda.err { background: rgba(239, 68, 68, .35); animation: kedip .45s ease-out; }

@keyframes kedip {
  from { opacity: 1; }
  to { opacity: 0; }
}

.status {
  margin: 10px 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--abu);
  min-height: 20px;
}

.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* ---------- kartu ---------- */
.kartu {
  background: #fff;
  border: 1px solid var(--garis);
  border-radius: var(--radius);
  padding: 13px;
  margin-bottom: 12px;
}

.kartu-judul {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.kartu-judul h3 { font-size: 14px; }
.mini { font-size: 12px; color: var(--abu); }
.ocr-status { font-size: 12px; color: var(--abu); margin: 8px 0 0; min-height: 16px; }

.baris-input { display: flex; gap: 8px; }
.baris-input input { flex: 1; }

input, select {
  padding: 10px 12px;
  border: 1px solid var(--garis);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--teks);
  min-width: 0;
}

input:focus, select:focus { outline: 2px solid var(--pink-mu); border-color: var(--pink); }

.tombol {
  padding: 10px 15px;
  border: 1px solid var(--garis);
  background: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--teks);
  white-space: nowrap;
}

.tombol.utama { background: var(--pink); border-color: var(--pink); color: #fff; }
.tombol.bahaya { background: #fff; border-color: #fecaca; color: var(--err); }
.dialog .tombol.bahaya { background: var(--err); border-color: var(--err); color: #fff; }
.tombol[disabled] { opacity: .5; cursor: not-allowed; }
.tombol:active { transform: scale(.97); }
.tombol.lebar { width: 100%; }

.setelan { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--abu); }
.setelan label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.setelan input { accent-color: var(--pink); width: 16px; height: 16px; }

/* ---------- daftar scan terbaru ---------- */
.daftar { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }

.daftar li {
  padding: 9px 4px;
  border-bottom: 1px dashed var(--garis);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.daftar li:last-child { border-bottom: 0; }
.daftar .kode { font-family: ui-monospace, "Cascadia Code", monospace; font-weight: 700; }
.daftar .jam { color: var(--abu); font-size: 12px; white-space: nowrap; }
.daftar .kosong { color: var(--abu); justify-content: center; }

/* ---------- tab tanggal ---------- */
.tab-tanggal {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scrollbar-width: thin;
}

.tab-tgl {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--garis);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--abu);
  cursor: pointer;
  line-height: 1.25;
  text-align: center;
}

.tab-tgl small { display: block; font-weight: 500; font-size: 11px; opacity: .8; }
.tab-tgl.aktif { background: var(--pink); border-color: var(--pink); color: #fff; }

/* ---------- filter & ringkasan ---------- */
.filter { display: flex; gap: 8px; flex-wrap: wrap; }
.filter #cari { flex: 1; min-width: 180px; }

.ringkas {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  background: var(--pink-mu);
  border-radius: 11px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
}

.stat span { font-size: 11px; color: var(--pink-tua); }
.stat b { font-size: 16px; color: var(--pink-tua); }

.aksi-export { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }

/* penanda pembaruan otomatis */
.live {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
  color: var(--abu);
  cursor: pointer;
  white-space: nowrap;
}

.live input { accent-color: var(--pink); width: 15px; height: 15px; }

.live .titik {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(5, 150, 105, .55);
  animation: denyut 1.8s infinite;
}

.live .titik.mati { background: #9ca3af; animation: none; box-shadow: none; }

@keyframes denyut {
  0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, .5); }
  70% { box-shadow: 0 0 0 7px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* baris yang baru masuk saat tabel menyegarkan diri */
@keyframes sorot {
  from { background: #dcfce7; }
  to { background: transparent; }
}

tbody tr.baru { animation: sorot 2.4s ease-out; }

/* ---------- tabel ---------- */
.tabel-kotak { padding: 0; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 1000px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--pink-mu);
  color: var(--pink-tua);
  text-align: left;
  padding: 10px 8px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 2;
}

tbody td { padding: 8px; border-top: 1px solid var(--garis); vertical-align: middle; }
tbody tr:nth-child(even) { background: #fcfcfd; }
td.kode { font-family: ui-monospace, "Cascadia Code", monospace; font-weight: 700; white-space: nowrap; }
td.jam-detik { font-family: ui-monospace, "Cascadia Code", monospace; white-space: nowrap; }
td.angka { text-align: right; white-space: nowrap; }
td.potong { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tbody img { width: 44px; height: 34px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
td select { padding: 5px 7px; font-size: 12px; border-radius: 8px; }

.hapus {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 15px;
  opacity: .6;
}

.hapus:hover { opacity: 1; }
.kosong-tabel { padding: 26px; text-align: center; color: var(--abu); }

/* ---------- tirai / dialog ---------- */
.tirai {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .68);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 18px;
}

.tirai img { max-width: 96vw; max-height: 92vh; border-radius: 10px; }
.sembunyi { display: none !important; }

.dialog {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  width: min(380px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dialog-aksi { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- peringatan resi dobel ---------- */
#tiraiDobel { background: rgba(127, 29, 29, .8); }

.dialog.dobel {
  border: 3px solid var(--err);
  text-align: center;
  gap: 6px;
  animation: goyang .45s ease-in-out 2;
}

.dobel-kepala {
  background: var(--err);
  color: #fff;
  margin: -18px -18px 4px;
  padding: 12px;
  border-radius: 11px 11px 0 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .5px;
}

.dobel-kode {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 21px;
  font-weight: 800;
  color: var(--err);
  margin: 6px 0 0;
  word-break: break-all;
}

.dobel-info { margin: 0; font-size: 14px; color: var(--teks); }

@keyframes goyang {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 130%);
  background: #111827;
  color: #fff;
  padding: 11px 17px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  transition: transform .25s;
  max-width: 92vw;
  text-align: center;
}

.toast.tampil { transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }

/* ---------- halaman masuk ---------- */
.halaman-masuk {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #fdf2f8, #eef2ff);
}

.kotak-masuk {
  background: #fff;
  padding: 30px 26px;
  border-radius: 18px;
  width: min(360px, 92vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .1);
  display: flex;
  flex-direction: column;
  gap: 11px;
  text-align: center;
}

.kotak-masuk h1 { font-size: 21px; color: var(--pink); }
.kotak-masuk .mini { margin: 0 0 6px; }
.logo-besar { font-size: 42px; }
.pesan-salah { color: var(--err); font-size: 13px; margin: 0; }

@media (max-width: 600px) {
  .ringkas { grid-template-columns: repeat(2, 1fr); }
  .view { padding: 12px 10px 0; }
}
