:root {
  --bg: #eef5f3;
  --card: #ffffff;
  --ink: #1b1f24;
  --muted: #6b7280;
  --line: #242424;
  --accent: #0f766e;
  --accent-2: #10b981;
  --danger: #b91c1c;
  --soft: #e7f7f3;
  --shadow: 0 16px 45px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 10% 20%, rgba(16,185,129,.18), transparent 28%),
    radial-gradient(circle at 80% 10%, rgba(14,116,144,.16), transparent 30%),
    var(--bg);
  color: var(--ink);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; padding: 14px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; margin: 0 auto 12px; max-width: 1100px;
  border-radius: 18px; background: rgba(255,255,255,.86); backdrop-filter: blur(12px);
  box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,.7);
}
.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 25px; font-weight: 900; color: #fff;
  background: linear-gradient(145deg, #0f766e, #111827);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 8px 18px rgba(15,118,110,.3);
}
.app-title { font-weight: 800; font-size: 17px; }
.app-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.status-pill {
  border-radius: 999px; padding: 8px 10px; background: #ecfeff; border: 1px solid #99f6e4;
  color: #0f766e; font-weight: 700; font-size: 12px; white-space: nowrap;
}
.status-pill.error { background:#fee2e2; color:#991b1b; border-color:#fecaca; }
.status-pill.ok { background:#dcfce7; color:#166534; border-color:#bbf7d0; }

.toolbar, .notice { max-width: 1100px; margin: 0 auto 12px; }
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 10px;
  border-radius: 16px; background: rgba(255,255,255,.82); box-shadow: var(--shadow);
}
.toolbar button, .clear-sign {
  border: 1px solid #cbd5e1; color: #0f172a; background: #fff;
  border-radius: 12px; padding: 10px 12px; font-weight: 700;
  box-shadow: 0 2px 0 rgba(15,23,42,.08);
}
.toolbar button.primary { background: linear-gradient(145deg, var(--accent), var(--accent-2)); color:#fff; border-color: transparent; }
.toolbar button.danger { border-color:#fecaca; color:#991b1b; background:#fff5f5; }
.notice {
  border-left: 5px solid var(--accent); background: rgba(255,255,255,.86);
  padding: 10px 12px; border-radius: 14px; color: #334155; box-shadow: var(--shadow); line-height: 1.45;
}

.page-wrap { max-width: 1100px; margin: 0 auto; display: flex; justify-content: center; }
.paper {
  width: min(100%, 920px);
  background: var(--card);
  box-shadow: 0 24px 70px rgba(15,23,42,.18);
  border-radius: 6px;
  padding: 22px;
  margin: 10px auto 24px;
}
.document-frame {
  border: 2px solid var(--line);
  min-height: 1180px;
  padding: 0 0 12px;
  background: #fff;
}
.doc-title {
  margin: 8px 12px 8px;
  text-align: center;
  border: 2px solid var(--line);
  height: 38px; display:flex; align-items:center; justify-content:center;
  font-weight: 900; letter-spacing: .4px; font-size: 18px;
}

.header-grid {
  display: grid; grid-template-columns: 1fr 160px 1fr; gap: 8px;
  padding: 0 12px 8px;
}
.left-fields label, .right-fields label {
  display:grid; grid-template-columns: 135px 1fr; align-items:center;
  border-bottom: 2px solid var(--line); min-height: 29px;
}
.left-fields span, .right-fields span { font-weight: 800; font-size: 12px; }
.left-fields span::after, .right-fields span::after { content: ' :'; float: right; padding-right: 9px; }
input, textarea, select {
  width: 100%; border: 0; outline: 0; padding: 6px 7px; background: transparent; color: #111827;
}
textarea { resize: vertical; min-height: 31px; }
.garment-box { display:flex; align-items:center; justify-content:center; color:#444; }
.garment-box svg { max-width: 150px; height: auto; }

.basic-table { width: calc(100% - 24px); margin: 0 12px 8px; border-collapse: collapse; table-layout: fixed; }
.basic-table th, .basic-table td { border: 2px solid var(--line); padding: 4px 6px; vertical-align: middle; }
.basic-table th { font-size: 12px; text-align: center; font-weight: 900; background: #f6f6f6; }
.basic-table td { font-size: 12px; }
.basic-table input { text-align: center; padding: 3px; font-size: 12px; }
.material-table th:nth-child(1) { width: 150px; }
.material-table th:nth-child(2) { width: 260px; }
.material-table th:nth-child(3) { width: 185px; }

.details-grid {
  display: grid; grid-template-columns: 41% 59%;
  width: calc(100% - 24px); margin: 0 12px 12px;
  border: 2px solid var(--line);
}
.details-left { border-right: 2px solid var(--line); }
.section-head { text-align:center; font-weight: 900; font-size: 12px; padding: 6px; border-bottom: 2px solid var(--line); background: #f6f6f6; }
.ok-row, .sub-ok-row {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 7px 10px; min-height: 34px; font-size: 12px; font-weight: 800;
}
.print-title { padding: 12px 10px 3px; font-size: 12px; font-weight: 800; }
.sub-ok-row { padding-left: 38px; }
.ok-buttons { display:flex; gap:0; }
.ok-buttons label {
  border: 2px solid var(--line); border-right: 0; padding: 3px 6px; display:flex; gap:3px; align-items:center; font-weight: 800; font-size: 11px;
}
.ok-buttons label:last-child { border-right: 2px solid var(--line); }
.ok-buttons input { width:auto; appearance:none; padding:0; }
.ok-buttons label:has(input:checked) { background:#111827; color:#fff; }
.details-right textarea { border-bottom: 2px solid var(--line); display:block; min-height: 35px; font-size: 12px; }
.details-right textarea:last-child { border-bottom:0; }

.lined-section, .comment-section {
  display: grid; grid-template-columns: 245px 1fr; align-items:start;
  width: calc(100% - 24px); margin: 0 12px 12px; min-height: 56px;
  border-bottom: 2px solid var(--line);
}
.lined-section label, .comment-section label { font-size: 12px; font-weight:900; padding-top:8px; }
.lined-section label span, .comment-section label span { float:right; padding-right:12px; }
.comment-section textarea { border-bottom: 2px solid var(--line); min-height: 52px; }
.large-comment { min-height: 190px; }
.large-comment textarea { min-height: 170px; line-height: 2.2; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, #1f2937 32px, transparent 33px); }

.workflow-row {
  width: calc(100% - 24px); margin: 0 12px 12px; padding: 9px; border: 1px dashed #94a3b8; border-radius: 10px;
  display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 8px; align-items:center; background:#f8fafc;
}
.workflow-row label { font-size: 12px; font-weight: 800; }
.workflow-row input, .workflow-row select { border: 1px solid #cbd5e1; border-radius: 8px; background:#fff; }

.signature-area {
  display: grid; grid-template-columns: 1fr 2.65fr; gap: 150px;
  padding: 8px 38px 6px;
  align-items:start;
}
.sig-card { border: 2px solid var(--line); background:#fff; }
.sig-title { text-align: center; font-size: 11px; padding: 6px; border-bottom: 2px solid var(--line); }
.sig-grid { display:grid; }
.sig-grid.two { grid-template-columns: 1fr 1fr; }
.sig-grid.four { grid-template-columns: repeat(4, 1fr); }
.sig-cell { min-height: 135px; border-right: 2px solid var(--line); display:flex; flex-direction:column; }
.sig-cell:last-child { border-right:0; }
.sig-label { text-align:center; font-size: 11px; font-weight: 800; padding: 8px 3px; border-bottom: 2px solid var(--line); }
.signature { width: 100%; height: 86px; touch-action: none; background: #fff; display:block; flex:1; }
.clear-sign { margin: 5px; padding: 5px 7px; font-size: 11px; color:#334155; }
.doc-footer { text-align:center; font-size: 11px; color:#334155; padding: 16px 8px 0; }
.doc-footer a { color:#0f766e; font-weight:900; text-decoration:none; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(100px);
  background: #111827; color: #fff; border-radius: 999px; padding: 10px 14px;
  box-shadow: 0 16px 45px rgba(15,23,42,.28); opacity: 0; transition: .25s ease; z-index: 100;
  max-width: calc(100% - 24px); text-align:center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .app-shell { padding: 8px; }
  .topbar { border-radius: 14px; }
  .toolbar { position: sticky; top: 74px; z-index: 19; overflow-x: auto; flex-wrap: nowrap; }
  .toolbar button { white-space: nowrap; }
  .paper { padding: 8px; width: 100%; overflow-x: auto; }
  .document-frame { min-width: 820px; }
  .signature-area { gap: 40px; padding-left: 28px; padding-right: 28px; }
}

@media print {
  @page { size: A4 portrait; margin: 6mm; }
  body { background: #fff; }
  .no-print, .toolbar, .notice, .topbar, .toast, .clear-sign { display: none !important; }
  .app-shell { padding: 0; }
  .page-wrap { max-width: none; }
  .paper { width: 100%; padding: 0; margin: 0; box-shadow: none; border-radius:0; }
  .document-frame { min-height: auto; border: 1.5px solid #111; }
  .no-print-inside { display: none; }
  input, textarea { color: #000; }
  textarea { overflow: hidden; }
  .doc-footer { padding-top: 10px; }
}

/* Dynamic detail rows + garment sketch revisions */
.garment-box {
  position: relative;
  min-height: 118px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #444;
  overflow: hidden;
}
.garment-box svg { max-width: 170px; width: 100%; height: auto; }
.garment-preview {
  max-width: 170px;
  max-height: 118px;
  object-fit: contain;
  display: none;
}
.garment-controls {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 2px;
  background: rgba(255,255,255,.92);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 9px;
  white-space: nowrap;
}
.garment-controls input[type="file"] { display: none; }
.garment-controls label,
.garment-controls button {
  border: 0;
  background: #eef5f3;
  color: #0f172a;
  border-radius: 6px;
  padding: 3px 5px;
  font-weight: 800;
  font-size: 9px;
  line-height: 1;
}
.dynamic-details .section-head { min-height: 30px; }
#detailsLeftRows, #detailsRightRows { min-height: 184px; }
.detail-row {
  min-height: 35px;
  border-bottom: 2px solid var(--line);
  display: flex;
  align-items: stretch;
  width: 100%;
}
.detail-row:last-child { border-bottom: 0; }
.detail-left-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 800;
}
.detail-left-row.is-section {
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 8px 10px 3px;
  font-weight: 900;
  align-items: center;
}
.detail-left-row.is-indent { padding-left: 38px; }
.detail-label {
  font-size: 12px;
  font-weight: 900;
  text-align: left;
  padding: 4px 2px;
  min-width: 0;
}
.dynamic-ok {
  display: flex;
  gap: 0;
}
.ok-toggle {
  min-width: 34px;
  border: 2px solid var(--line);
  border-right: 0;
  padding: 4px 6px;
  background: #fff;
  color: #111827;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}
.ok-toggle:last-child { border-right: 2px solid var(--line); }
.ok-toggle.active { background: #111827; color: #fff; }
.row-delete {
  width: 24px;
  height: 24px;
  align-self: center;
  border: 1px solid #fecaca;
  background: #fff5f5;
  color: #991b1b;
  border-radius: 999px;
  font-weight: 900;
  line-height: 1;
}
.detail-right-row { display: flex; }
.detail-right-row .detail-remark {
  width: 100%;
  min-height: 33px;
  border: 0;
  padding: 8px 6px;
  font-size: 12px;
  resize: vertical;
}
.detail-right-row.is-section .blank-remark { width: 100%; min-height: 35px; }
.details-controls {
  width: calc(100% - 24px);
  margin: -6px 12px 12px;
  padding: 7px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border: 1px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
}
.details-controls button {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 9px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 800;
}
.paper.exporting .no-print,
.paper.exporting .no-print-inside,
.paper.exporting .clear-sign { display: none !important; }

@media print {
  .garment-controls, .details-controls, .row-delete { display: none !important; }
  .detail-label { color: #000; }
  .ok-toggle { color: #000; }
  .ok-toggle.active { background: #000 !important; color: #fff !important; }
}

/* FIX v1.2: form PC/HP sama, auto-fit tanpa geser kiri kanan */
html, body { overflow-x: hidden; }
:root { --paper-width: 920px; --paper-scale: 1; }
.page-wrap {
  width: 100%;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
  overflow-x: hidden;
  align-items: flex-start;
}
#checklistForm {
  width: var(--paper-width);
  max-width: none;
  margin-left: auto;
  margin-right: auto;
  transform-origin: top center;
}
.paper {
  width: var(--paper-width);
  max-width: none;
  box-sizing: border-box;
  overflow: visible;
}
.document-frame { min-width: 0 !important; }
.garment-box svg { max-width: 180px; }

body.pdf-export-mode #checklistForm {
  zoom: 1 !important;
  transform: none !important;
  height: auto !important;
}
body.pdf-export-mode .page-wrap { overflow: visible !important; }

@media (max-width: 820px) {
  .app-shell { padding: 8px 6px; }
  .topbar {
    position: static;
    margin-bottom: 8px;
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
  }
  .brand-block { gap: 8px; }
  .logo-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 22px; }
  .app-title { font-size: 14px; line-height: 1.15; }
  .app-subtitle { font-size: 10.5px; }
  .status-pill { font-size: 10px; padding: 7px 8px; max-width: 132px; text-align: center; }
  .toolbar {
    position: static;
    overflow: visible;
    flex-wrap: wrap;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    padding: 8px;
  }
  .toolbar button {
    white-space: normal;
    min-width: 0;
    width: 100%;
    padding: 9px 7px;
    font-size: 12px;
    line-height: 1.2;
  }
  .notice { font-size: 12px; padding: 8px 10px; margin-bottom: 8px; }
  .paper { padding: 22px; margin-top: 0; }
  .page-wrap { justify-content: center; }
}

@media print {
  #checklistForm { width: 100% !important; zoom: 1 !important; transform: none !important; height: auto !important; }
  .page-wrap { overflow: visible !important; }
  .paper { width: 100% !important; max-width: none !important; }
}
