:root {
  --bg: #f3f2ef;
  --panel: #ffffff;
  --line: #dddad3;
  --text: #24221e;
  --muted: #7a766d;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --accent-soft: #f4ebe1;
  --danger: #b3261e;
  --sel: #2f6fde;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 "Segoe UI", system-ui, sans-serif; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 20px; padding: 0 16px; height: 48px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab { border: 0; background: none; padding: 0 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.topbar-right { margin-left: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.main { flex: 1; display: grid; grid-template-columns: 260px 1fr 300px; min-height: 0; }

/* Buttons & inputs */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: var(--radius); padding: 5px 10px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #b9b4a9; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; }
.btn.sm { padding: 2px 7px; font-size: 12px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }
input[type=text], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 7px; font: inherit; background: #fff; color: var(--text); width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input[type=color] { display: block; width: 100%; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 12px; }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); font-size: 13px; }
.chk { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 6px 0; }
.chk input { width: auto; margin: 0; }

/* Sidebar */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.list { flex: 1; overflow: auto; }
.item { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-bottom: 1px solid #efede8; cursor: pointer; }
.item:hover { background: #faf9f6; }
.item.active { background: var(--accent-soft); }
.item input[type=checkbox] { width: auto; }
.item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .qty { width: 52px; padding: 2px 4px; }
.empty { padding: 20px; color: var(--muted); text-align: center; }
.side-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }

/* Workspace */
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.toolbar #label-name { width: 220px; }
.toolbar select.btn { width: auto; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar .spacer { flex: 1; }
.canvas-wrap { flex: 1; overflow: auto; padding: 24px; }
.ruler-note { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stage-outer { position: relative; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 20px rgba(0,0,0,.08); background: #fff; }
.stage { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 14px; max-width: 900px; }

/* Label rendering (shared by editor, preview & print) */
.label { position: relative; background: #fff; overflow: hidden; color: #000; }
.el { position: absolute; }
.el-text { white-space: pre-wrap; overflow-wrap: break-word; }
.el-fields .frow { display: flex; align-items: baseline; }
.el-fields .fk { flex: none; overflow: hidden; white-space: nowrap; }
.el-fields .fs { flex: none; padding-right: .4em; }
.el-fields .fv { flex: 1; white-space: pre-wrap; }
.el-qr svg, .el-barcode svg { display: block; width: 100%; height: 100%; }
.el-image img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; user-select: none; }
.el-err { width: 100%; height: 100%; border: .3mm dashed #c00; color: #c00; font: 2.5mm/1.2 sans-serif; padding: .5mm; overflow: hidden; }

/* Editor-only */
.stage .el { cursor: move; }
.stage .el:hover { outline: 1px dashed rgba(47,111,222,.5); }
.stage .el.sel { outline: 1.5px solid var(--sel); z-index: 1000; }
.stage .rs { position: absolute; right: -4px; bottom: -4px; width: 9px; height: 9px; background: #fff; border: 1.5px solid var(--sel); cursor: nwse-resize; }
.stage .el-text:empty::before { content: "(teks kosong)"; color: #aaa; }

/* Properties */
.props { background: var(--panel); border-left: 1px solid var(--line); overflow: auto; padding: 12px; }
.props h3 { margin: 4px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.props .sec { border-bottom: 1px solid #efede8; padding-bottom: 12px; margin-bottom: 12px; }
.props .row { display: flex; gap: 6px; margin-bottom: 8px; align-items: flex-end; }
.props .row > * { flex: 1; min-width: 0; }
.props .row > .btn { flex: none; }
.props .stack > * { margin-bottom: 8px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 4px; }
.frow-edit { display: grid; grid-template-columns: 1fr 1.3fr auto auto; gap: 4px; margin-bottom: 4px; }
.frow-edit input { padding: 3px 5px; }
.layers .ly { display: flex; justify-content: space-between; padding: 5px 7px; border-radius: 4px; cursor: pointer; }
.layers .ly:hover { background: #faf9f6; }
.layers .ly.active { background: var(--accent-soft); }
.layers .ly span:last-child { color: var(--muted); font-size: 11px; }
.qr-preview { font-family: Consolas, monospace; font-size: 11px; white-space: pre-wrap; background: #faf9f6; border: 1px solid var(--line); border-radius: 4px; padding: 6px; max-height: 120px; overflow: auto; color: var(--muted); }

/* Print dialog */
dialog#print-dlg { border: 0; border-radius: 10px; padding: 0; width: min(1100px, 96vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(30,25,20,.45); }
.dlg { display: flex; flex-direction: column; max-height: 92vh; margin: 0; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { display: grid; grid-template-columns: 340px 1fr; min-height: 0; flex: 1; overflow: hidden; }
.dlg-settings { padding: 14px 16px; overflow: auto; border-right: 1px solid var(--line); }
.dlg-settings h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 4px 0 10px; }
.dlg-settings h3:not(:first-child) { margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.info { background: var(--accent-soft); border-radius: var(--radius); padding: 8px 10px; margin: 10px 0 0; }
.info.bad { background: #fde8e6; color: var(--danger); }
.p-items .pi { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.p-items .pi .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-items .pi input { width: 60px; }
.dlg-preview { background: #e9e7e2; overflow: auto; padding: 16px; }
.p-preview { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.p-preview .pg-wrap { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); position: relative; overflow: hidden; }
.p-preview .pg-wrap > .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }

/* Pages */
.page { position: relative; background: #fff; overflow: hidden; }
.slot { position: absolute; overflow: hidden; }
.slot.cut { outline: 0.1mm dashed #999; }
.slot .label.rot { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

#print-root { display: none; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #2b2925; color: #fff; padding: 9px 16px; border-radius: 6px; opacity: 0; transition: .2s; pointer-events: none; z-index: 10000; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

@media print {
  html, body { background: #fff; height: auto; }
  #app, dialog, #toast { display: none !important; }
  #print-root { display: block; }
  #print-root .page { break-after: page; page-break-after: always; }
  #print-root .page:last-child { break-after: auto; page-break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
