:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1c2430; --muted: #66718a; --line: #e1e6ee;
  --brand: #1f3a5f; --accent: #2a7de1; --ok: #1f9d55; --warn: #d98e04; --bad: #d64545;
  --r: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.3rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }

.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
}
.brand { color: #fff; font-weight: 700; display: flex; gap: .5rem; align-items: center; }
.logo { background: rgba(255,255,255,.15); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }

main { max-width: 860px; margin: 0 auto; padding: 1rem; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { flex: 1; text-align: center; padding: .55rem 0 .5rem; color: var(--muted); font-size: .78rem; font-weight: 600; }
.bottomnav a i { display: block; font-style: normal; font-size: 1.3rem; line-height: 1.2; }
.bottomnav a.on { color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem; margin-bottom: .75rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .9rem; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: .7rem .9rem; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .8rem; }
.stat.warn b { color: var(--warn); }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: .7rem 0 .25rem; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff;
  border: 1px solid #cfd6e2; border-radius: 10px; padding: .65rem .75rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .5rem 0 .75rem; }
.filters input { grid-column: 1 / -1; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: .7rem 1rem; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
button:disabled { opacity: .55; cursor: default; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); border: 1px solid #c9d6ea; }
.topbar .ghost { color: #fff; border-color: rgba(255,255,255,.4); }
button.danger { background: var(--bad); }
button.ok { background: var(--ok); }
button.sm { padding: .35rem .7rem; font-size: .85rem; }
button.block, .btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.actions > * { flex: 1 1 140px; }

.item {
  display: flex; gap: .75rem; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: .6rem; margin-bottom: .5rem; color: inherit;
}
.item a.lnk { display: flex; gap: .75rem; align-items: center; flex: 1; min-width: 0; color: inherit; }
.item .thumb { width: 58px; height: 58px; border-radius: 9px; background: #e9eef6; object-fit: cover; flex: none; display: grid; place-items: center; color: #9aa6bb; font-size: 1.4rem; overflow: hidden; }
.item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .info { flex: 1; min-width: 0; }
.item .nm { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; background: #eef2f8; padding: .1rem .4rem; border-radius: 6px; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .5rem; border-radius: 99px; background: #e8f5ee; color: var(--ok); }
.badge.Dipinjam { background: #e6f0fd; color: var(--accent); }
.badge.Dalam { background: #fff3d9; color: var(--warn); }
.badge.Hilang, .badge.Rusak { background: #fde8e8; color: var(--bad); }
.badge.Perlu { background: #fff3d9; color: var(--warn); }

.selbar {
  position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); background: var(--brand); color: #fff;
  padding: .6rem .8rem; border-radius: var(--r); display: flex; gap: .6rem; align-items: center; justify-content: space-between; margin-top: .5rem;
}
.selbar button { background: #fff; color: var(--brand); }

.photo { width: 100%; max-height: 320px; object-fit: contain; background: #e9eef6; border-radius: var(--r); display: block; }
.photo-empty { height: 160px; border-radius: var(--r); background: #e9eef6; color: #8c98ae; display: grid; place-items: center; }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85rem; }
dl.kv dd { margin: 0; word-break: break-word; }
.qrbox { display: flex; gap: 1rem; align-items: center; }
.qrbox img { width: 120px; height: 120px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.log { font-size: .85rem; border-left: 3px solid var(--line); padding: .1rem 0 .1rem .7rem; margin: .4rem 0; }
.log small { color: var(--muted); display: block; }

#reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--r); overflow: hidden; background: #000; min-height: 80px; }
.toggle { display: flex; align-items: center; gap: .6rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: .7rem .9rem; margin: .75rem 0; }
.toggle input { width: 22px; height: 22px; }
.toggle label { margin: 0; color: var(--ink); }
.hint { color: var(--muted); font-size: .85rem; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50;
  background: #1c2430; color: #fff; padding: .65rem 1rem; border-radius: 10px; max-width: 90vw; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }
.toast.good { background: var(--ok); }

.login { max-width: 360px; margin: 12vh auto 0; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

/* ---------- Cetak label ---------- */
.label-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: .75rem; }
.label-tools > div { flex: 1 1 140px; }
.labels { display: grid; gap: 4mm; grid-template-columns: repeat(auto-fill, var(--lw)); --lw: 62mm; --lh: 30mm; }
.label {
  width: var(--lw); height: var(--lh); border: 1px dashed #9aa6bb; border-radius: 2mm; background: #fff;
  display: flex; align-items: center; gap: 2mm; padding: 2mm; overflow: hidden; break-inside: avoid;
}
.label img { height: calc(var(--lh) - 4mm); width: calc(var(--lh) - 4mm); image-rendering: pixelated; flex: none; }
.label .lt { min-width: 0; line-height: 1.15; color: #000; }
.label .lt small { display: block; font-size: 6.5pt; color: #333; }
.label .lt b { display: block; font-size: 8.5pt; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.label .lt code { font-size: 8pt; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }
.labels.big { --lw: 90mm; --lh: 45mm; }
.labels.big .label .lt b { font-size: 11pt; } .labels.big .label .lt small { font-size: 8pt; } .labels.big .label .lt code { font-size: 10pt; }
.labels.tiny { --lw: 45mm; --lh: 22mm; }
.labels.tiny .label .lt b { font-size: 7pt; -webkit-line-clamp: 2; } .labels.tiny .label .lt small { display: none; } .labels.tiny .label .lt code { font-size: 6.5pt; }

@media print {
  @page { margin: 8mm; }
  body { background: #fff; padding: 0; }
  .topbar, .bottomnav, .no-print, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .label { border: 1px dashed #bbb; }
}
