:root {
  --orange: #f7c7ac;
  --orange-soft: #fbe2d5;
  --border: #c9a08a;
  --line: #999;
  --bg: #f4f5f7;
  --card: #ffffff;
  --accent: #c2410c;
  --text: #1f2937;
  /* Tinggi topbar dipakai sebagai offset banner yang menempel di bawahnya. */
  --topbar-h: 50px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  color: #fff;
  padding: 12px 16px;
  min-height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 16px; margin: 0; }

main {
  padding: 12px 12px calc(76px + env(safe-area-inset-bottom));
  max-width: 1100px;
  margin: 0 auto;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.ghost { background: transparent; color: inherit; border-color: currentColor; }
.topbar button.ghost { color: #fff; }
.topbar .setup-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
}
button:active { transform: scale(0.98); }

input, select {
  font: inherit;
  padding: 7px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  width: 100%;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #475569; }
label small { color: #94a3b8; }

.panel, .toolbar, .card {
  background: var(--card);
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.hidden { display: none; }

.panel { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.toolbar > label { flex: 1 1 180px; }
.toolbar.sticky {
  position: sticky;
  bottom: 0;
  z-index: 15;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.status { font-size: 12px; color: #64748b; }
.status.error { color: #dc2626; }
.hint { color: #94a3b8; font-size: 11px; }
.device-label { color: #64748b; font-size: 12px; font-weight: 600; }

/* ---------- Banner (lock / konflik) ---------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  font-size: 13px;
  border-bottom: 1px solid;
  position: sticky;
  top: var(--topbar-h);
  z-index: 18;
}
.banner .row { gap: 6px; }
.banner.warn { background: #fef9c3; color: #854d0e; border-color: #fde047; }
.banner.danger { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.banner button { padding: 4px 10px; font-size: 12px; }

#editor { display: grid; gap: 12px; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;            /* bisa dilipat/dibuka */
  user-select: none;
}
.card-head strong { display: inline-flex; align-items: center; gap: 6px; }
.card.collapsed .card-head { margin-bottom: 0; }
.card.collapsed .card-body { display: none; }
.caret {
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}
.card.collapsed .caret { transform: rotate(-90deg); }
/* Kolom otomatis menyesuaikan: 1 kolom di HP sempit, banyak kolom di desktop. */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.jarak-info { font-size: 12px; color: #0f766e; margin: 6px 0; min-height: 16px; }
.jarak-info.changed { color: #b91c1c; font-weight: 600; }

/* Tabel unit digulir mendatar bila layar sempit agar kolom tidak hancur. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.unit-table, .mini { width: 100%; border-collapse: collapse; margin-top: 6px; }
.unit-table { min-width: 420px; }
.unit-table th, .unit-table td, .mini th, .mini td {
  border: 1px solid #cbd5e1;
  padding: 4px 6px;
  font-size: 12px;
}
.unit-table th, .mini th { background: #f1f5f9; }
.unit-table select, .unit-table input { padding: 4px 6px; }
.icon-btn { padding: 2px 8px; border-color: #fca5a5; color: #b91c1c; }

.pengawas-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px; }
.pengawas-list label { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.pengawas-list input { width: auto; }

/* ---------- Preview / report ---------- */
#previewWrap { overflow: auto; -webkit-overflow-scrolling: touch; }
.preview-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.preview-bar .zoom-label {
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}
#previewStage { position: relative; }
#previewScale {
  display: inline-block;      /* mengecil mengikuti lebar konten, bukan lebar layar */
  transform-origin: top left; /* skala dihitung dari kiri-atas */
}
#preview,
.preview-sheet {
  background: #fff;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  min-width: 720px;
}
/* offscreen sheet: dipakai agar export selalu berbentuk desktop (1280px).
   Sengaja position:absolute (bukan fixed) supaya koordinat dokumen elemen
   tetap berada di origin, sehingga html2canvas mem-crop dengan benar. */
.preview-sheet {
  position: absolute;
  left: -100000px;
  top: 0;
  border: none;
  border-radius: 0;
}
.report-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 0 170px;
  margin-bottom: 12px;
}
.report-logo {
  position: absolute;
  left: 0;
  top: 0;
  height: 56px;
  width: auto;
}
.report-titles { text-align: center; }
.report-title { text-align: center; font-size: 17px; font-weight: 700; margin: 0 0 2px; }
.report-date { text-align: center; font-size: 13px; margin-bottom: 4px; }

.ex-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.ex-col { border: 1px solid var(--line); display: flex; flex-direction: column; }
.ex-col .pit { background: var(--orange); text-align: center; font-weight: 600; padding: 4px; font-size: 12px; }
.ex-col .excode, .ex-col .loading { text-align: center; font-weight: 700; padding: 3px; font-size: 12px; border-top: 1px solid var(--line); }
.pair { display: flex; border-top: 1px solid var(--line); font-size: 11px; }
.pair .lbl { flex: 0 0 42%; background: #f8fafc; padding: 3px 5px; font-weight: 600; border-right: 1px solid var(--line); }
.pair .val { flex: 1; padding: 3px 5px; }
.mini { margin: 0; }
.mini th, .mini td { font-size: 10px; padding: 2px 3px; text-align: center; }
.mini td.st-bd { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.mini td.st-sb { background: #dcfce7; color: #166534; font-weight: 700; }
.mini td.st-run { background: #fef08a; color: #854d0e; font-weight: 700; }
.report-oleh { text-align: right; font-size: 10px; color: #64748b; margin-top: 6px; }
.jarak {
  /* Dorong ke dasar kolom EX supaya tingginya sejajar di semua kolom. */
  margin-top: auto;
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;      /* rata tengah, sama seperti .excode */
  border-top: 1px solid var(--line);
  padding: 4px 5px;
  font-size: 11px;
  font-weight: 600;
}

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 14px; }
.sum-box { border: 1px solid var(--line); }
.sum-title { background: var(--orange-soft); padding: 3px 6px; font-size: 11px; font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); }
.sum-val {
  min-height: 30px;
  padding: 8px 6px;
  display: flex;
  align-items: center;
  justify-content: center;   /* angka rata tengah, sejajar antar kotak */
  font-size: 15px;
  font-weight: 700;
}
.sum-box.sum-bd .sum-val { background: #fee2e2; color: #b91c1c; }
.sum-box.sum-sb .sum-val { background: #dcfce7; color: #166534; }
.sum-box.sum-run .sum-val { background: #fef08a; color: #854d0e; }
.sum-box.pengawas .sum-val {
  display: block;
  min-height: 0;
  padding: 6px;
  text-align: left;
  font-weight: 400;
  font-size: 12px;
}

.totals { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.totals .pair { border: 1px solid var(--line); }
.totals .pair .val { font-weight: 700; }

/* ---------- Dialog export (pilih tampil/sembunyi Remark) ---------- */
#exportDialog {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}
#exportDialog.hidden { display: none; }
#exportDialog .dlg {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
#exportDialog .dlg h3 { margin: 0; font-size: 15px; }
#exportDialog .dlg p { margin: 0; font-size: 13px; color: #475569; }
#exportDialog .dlg .row { justify-content: flex-end; }
#exportDialog .dlg button { min-width: 104px; }

/* ---------- Fokus keyboard ---------- */
button:focus-visible,
input:focus-visible,
select:focus-visible,
.card-head:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* ---------- Layar sempit (HP) ---------- */
@media (max-width: 640px) {
  main { padding-left: 10px; padding-right: 10px; }
  /* Banner tidak menempel di HP supaya tidak menimpa topbar yang ikut wrap. */
  .banner { position: static; }
  .toolbar.sticky > button { flex: 1 1 140px; }
  .toolbar.sticky .status { flex: 1 1 100%; }
}

/* ---------- Target sentuh lebih besar ---------- */
@media (pointer: coarse) {
  input,
  select { min-height: 38px; }
  button { min-height: 40px; padding: 9px 14px; }
  .icon-btn { min-width: 36px; min-height: 36px; padding: 4px 10px; }
  .unit-table select,
  .unit-table input { min-height: 34px; padding: 6px; }
  input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; }
}

@media print {
  .topbar, .panel, .toolbar, #editor { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  #preview { border: none; padding: 0; min-width: 0; }
}
