:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #1d2421;
  --muted: #6b726e;
  --line: #e3dfd5;
  --primary: #1f5f4a;
  --primary-ink: #ffffff;
  --primary-soft: #e4efe9;
  --accent: #e2a83a;
  --ok: #2f7d4f; --ok-soft: #e3f2e8;
  --warn: #a96b06; --warn-soft: #fbefd6;
  --bad: #b23b31; --bad-soft: #f8e1de;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 4px 14px rgba(30, 30, 20, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917; --surface: #1c2320; --ink: #e8ece9; --muted: #98a19c; --line: #2c3531;
    --primary: #3f9a78; --primary-soft: #1f3a30; --ok-soft: #1c3426; --warn-soft: #3a2e15; --bad-soft: #3c201d;
    --ok: #6cc592; --warn: #e6b04f; --bad: #ef8a80;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .15rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); font-size: .92em; }
.center { text-align: center; }
.num { text-align: right; white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
[hidden] { display: none !important; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.2rem; padding: 0 1.25rem; height: 58px; background: var(--primary); color: var(--primary-ink); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; flex: none; }
.brand { min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; gap: .2rem; flex: 1; }
.nav a, .nav .link { color: rgba(255,255,255,.82); padding: .45rem .7rem; border-radius: 7px; font-size: .92rem; white-space: nowrap; }
.nav a:hover, .nav .link:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.18); color: #fff; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: .2rem; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; font: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head p { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.back { display: inline-block; font-size: .85rem; margin-bottom: .3rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.grid2.gap { gap: 1.1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2.gap { margin-bottom: 1.1rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: .8rem; align-items: end; }
.span2 { grid-column: span 2; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: .9rem; margin-bottom: 1.1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); border-top: 3px solid var(--primary); }
.stat span { display: block; font-size: .8rem; color: var(--muted); }
.stat strong { font-size: clamp(1.1rem, 4.5vw, 1.45rem); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat.ok { border-top-color: var(--ok); } .stat.warn { border-top-color: var(--accent); } .stat.bad { border-top-color: var(--bad); }
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { margin-bottom: .7rem; }
.bar-label { display: flex; justify-content: space-between; font-size: .9rem; gap: .5rem; }
progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 99px; background: var(--primary-soft); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--primary-soft); }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .7rem .8rem; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, var(--line)); white-space: nowrap; }
.table td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface) 94%, var(--primary)); }
.table.compact td, .table.compact th { padding: .45rem .5rem; }
.table th.num { text-align: right; }
.chk { width: 34px; }
.thumb img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; border: 1px solid var(--line); }
.nophoto { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.nophoto.big { width: 100%; height: 100%; min-height: 200px; }
.row-actions { white-space: nowrap; }
.row-actions a { display: inline-block; padding: .2rem .4rem; border-radius: 5px; }
.row-actions a:hover { background: var(--primary-soft); text-decoration: none; }

/* ---------- Badges & alerts ---------- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--bg); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Forms ---------- */
.form label { display: flex; flex-direction: column; gap: .3rem; font-size: .86rem; font-weight: 600; margin-bottom: .85rem; }
.form .grid2 label, .form .grid4 label { margin-bottom: 0; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 0; border-color: var(--primary); }
input:disabled { background: var(--bg); color: var(--muted); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
textarea { resize: vertical; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; margin: .2rem 0 .8rem; }
.form .check, label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 300px; gap: 2rem; }
.form-grid h3:first-child { margin-top: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; border-top: 1px solid var(--line); margin-top: 1.4rem; padding-top: 1rem; }
.photo-drop { aspect-ratio: 4/3; border: 2px dashed var(--line); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: .7rem; background: var(--bg); }
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 2.6rem; }
.pw-toggle { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; font-size: 1rem; opacity: .6; }
.filters { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 260px; }
.filters select { flex: 0 1 170px; width: auto; }
.inline-edit { display: flex; gap: .4rem; align-items: center; margin: 0; }
.inline-edit input, .inline-edit select { padding: .35rem .55rem; font-size: .88rem; }
.inline-edit.add { margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed var(--line); }
.inline-edit .count { min-width: 2.2rem; text-align: right; color: var(--muted); font-size: .85rem; }
.w-kode { width: 5.5rem; flex: none; }
.selbar { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 66px; z-index: 5; background: var(--primary-soft); border-color: var(--primary); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-size: .9rem; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.btn.danger:hover { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: .32rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: center; }
.pager a, .pager span { padding: .35rem .7rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.pager .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 1.1rem; align-items: start; }
.detail-top { display: grid; grid-template-columns: 260px 1fr; gap: 1.5rem; }
.detail-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); display: block; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: .45rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .86rem; }
.dl dd { margin: 0; font-weight: 500; }
.code-preview { background: #fff; color: #000; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; }
.code-preview .barcode { width: 100%; height: 76px; display: block; margin-bottom: 1rem; }
.qr-lg { width: 170px; height: 170px; margin: 0 auto .6rem; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr-content { text-align: left; font-size: .75rem; white-space: pre-wrap; word-break: break-all; background: #f6f6f3; padding: .6rem; border-radius: 6px; }
details summary { cursor: pointer; color: #555; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.timeline li { padding: .35rem 0 .35rem .9rem; border-left: 2px solid var(--line); text-transform: capitalize; }
.danger-zone { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

/* ---------- Auth ---------- */
.auth-page { background: radial-gradient(ellipse at top, color-mix(in srgb, var(--primary) 18%, var(--bg)), var(--bg) 60%); min-height: 100vh; }
.auth-page .container { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding-top: 2rem; }
.auth-page .alert { width: 100%; max-width: 400px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.8rem 1.4rem; box-shadow: 0 10px 40px rgba(20, 40, 30, .12); }
.auth-card.wide { max-width: 600px; }
.auth-head { text-align: center; margin-bottom: 1.4rem; }
.auth-head img { margin-bottom: .5rem; }
.auth-head h1 { font-size: 1.35rem; }
.auth-head p { margin: 0; }
.checklist { list-style: none; padding: .8rem 1rem; margin: 0 0 1.2rem; background: var(--bg); border-radius: 8px; font-size: .88rem; columns: 2; }
.checklist .ok { color: var(--ok); } .checklist .bad { color: var(--bad); font-weight: 600; }

/* ---------- Label ---------- */
.label-options { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.label-options label { display: flex; flex-direction: column; font-size: .8rem; font-weight: 600; gap: .25rem; }
.label-options select { width: auto; }
.label-options input { width: 6rem; }
.sheet { background: #fff; color: #000; display: flex; flex-wrap: wrap; gap: 3mm; padding: 8mm; border-radius: 6px; box-shadow: var(--shadow); width: 210mm; max-width: 100%; margin: 0 auto; }
.sheet-roll { width: auto; justify-content: center; background: transparent; box-shadow: none; }
.sheet-roll .label { box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.label { background: #fff; color: #000; font-family: Arial, "Helvetica Neue", sans-serif; overflow: hidden; border: .2mm dashed #bbb; border-radius: 1.5mm; padding: 1.6mm; display: grid; gap: 1mm 2mm; break-inside: avoid; page-break-inside: avoid; }
.l-qr { grid-area: qr; aspect-ratio: 1; align-self: start; }
.l-info { grid-area: info; min-width: 0; display: flex; flex-direction: column; gap: .4mm; }
.l-bar { grid-area: bar; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.l-barcode { width: 100%; height: auto; display: block; min-height: 0; flex: 1 1 0; }
.l-inst { font-size: 5.5pt; text-transform: uppercase; letter-spacing: .04em; color: #333; border-bottom: .2mm solid #000; padding-bottom: .4mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-nama { font-weight: 700; line-height: 1.12; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.l-kode, .l-kode-bar { font-family: "Courier New", var(--mono); font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.l-kode-bar { flex: none; text-align: center; font-size: 6.5pt; line-height: 1.15; padding-top: .3mm; }
.l-meta { font-size: 6pt; color: #222; display: flex; flex-wrap: wrap; gap: 0 2mm; }

/* 70 × 35 mm */
.label-sedang { width: 70mm; height: 35mm; grid-template-columns: 21mm 1fr; grid-template-rows: 21mm 1fr; grid-template-areas: "qr info" "bar bar"; }
.label-sedang .l-nama { font-size: 8pt; }
.label-sedang .l-kode { font-size: 7.5pt; }
.label-sedang.jenis-barcode { grid-template-columns: 1fr; grid-template-rows: auto 1fr; grid-template-areas: "info" "bar"; }
.label-sedang.jenis-qr { grid-template-columns: 30mm 1fr; grid-template-rows: 1fr; grid-template-areas: "qr info"; }

/* 100 × 50 mm */
.label-besar { width: 100mm; height: 50mm; padding: 2.2mm; grid-template-columns: 31mm 1fr; grid-template-rows: 31mm 1fr; grid-template-areas: "qr info" "bar bar"; gap: 1.5mm 3mm; }
.label-besar .l-inst { font-size: 7pt; }
.label-besar .l-nama { font-size: 11pt; }
.label-besar .l-kode { font-size: 10pt; }
.label-besar .l-meta { font-size: 7.5pt; }
.label-besar.jenis-barcode { grid-template-columns: 1fr; grid-template-rows: auto 1fr; grid-template-areas: "info" "bar"; }
.label-besar.jenis-qr { grid-template-columns: 44mm 1fr; grid-template-rows: 1fr; grid-template-areas: "qr info"; }

/* 50 × 25 mm */
.label-kecil { width: 50mm; height: 25mm; padding: 1.3mm; grid-template-columns: 1fr; grid-template-rows: auto 1fr; grid-template-areas: "info" "bar"; gap: .6mm; }
.label-kecil .l-nama { font-size: 6.5pt; -webkit-line-clamp: 1; line-clamp: 1; white-space: nowrap; text-overflow: ellipsis; display: block; }
.label-kecil .l-inst { font-size: 5pt; }
.label-kecil.jenis-qr { grid-template-columns: 21mm 1fr; grid-template-rows: 1fr; grid-template-areas: "qr info"; }
.label-kecil.jenis-qr .l-nama { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; }
.label-kecil .l-kode { font-size: 6pt; }


/* ---------- Kop label (logo) ---------- */
.l-kop { display: flex; align-items: center; gap: 1.2mm; min-width: 0; text-overflow: clip; }
.l-kop img { display: block; height: 3.4mm; width: auto; max-width: 100%; object-fit: contain; object-position: left center; flex: none; }
.l-kop.kop-logo_teks img { max-width: 45%; }
.l-kop span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.label-kecil .l-kop img { height: 2.8mm; }
.label-kecil .l-kop.kop-logo img { height: 3.2mm; }
.label-sedang .l-kop.kop-logo img { height: 4.2mm; }
.label-besar .l-kop img { height: 5mm; }
.label-besar .l-kop.kop-logo img { height: 6.5mm; }

/* ---------- Border label (ikut tercetak) ---------- */
.label.b-tipis { border: .3mm solid #000; }
.label.b-tebal { border: .7mm solid #000; }
.label.b-putus { border: .3mm dashed #000; }
.label.b-none  { border: .2mm dashed #bbb; } /* hanya panduan di layar */

/* ---------- Pengaturan ---------- */
.settings-grid { align-items: start; }
.kop-options { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .9rem; }
.kop-options .kop-opt { margin-bottom: 0; }
.logo-box { border: 2px dashed var(--line); border-radius: var(--radius); background: #fff; min-height: 90px; display: flex; align-items: center; justify-content: center; padding: .8rem; margin-bottom: .7rem; }
.logo-preview { max-width: 100%; max-height: 110px; object-fit: contain; }
.logo-box .muted { color: #888; }
.card-actions { border-top: 0; margin-top: 0; padding-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats .stat:first-child { grid-column: span 2; }
  .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .nav { display: none; position: absolute; top: 58px; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--primary); padding: .5rem; }
  .nav.open { display: flex; }
  .nav-user { margin-left: 0; justify-content: space-between; border-top: 1px solid rgba(255,255,255,.2); padding-top: .4rem; }
}
@media (max-width: 640px) {
  .container { padding: 1rem .9rem 2rem; }
  .grid2, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .detail-top { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 120px 1fr; }
  .checklist { columns: 1; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  .container { max-width: none; padding: 0; margin: 0; }
  .sheet { box-shadow: none; padding: 0; width: auto; border-radius: 0; gap: 2mm; }
  .label { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .label.b-none { border-color: transparent; }
}
.form .settings-grid label { margin-bottom: .85rem; }
.form .settings-grid .kop-options label { margin-bottom: 0; }
