@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root{
  --ink: #14171c;
  --ink-soft: #2a2e35;
  --paper: #f2efe6;
  --paper-dim: #e7e2d3;
  --signal: #ff5a1f;
  --signal-dim: #ffb18c;
  --teal: #3d5a52;
  --line: rgba(20,23,28,0.12);
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', sans-serif;
  --serif-doc: 'Times New Roman', Times, serif;
}

*{ box-sizing: border-box; margin:0; padding:0; }

html, body{
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
}

body{
  position: relative;
  display: flex;
  flex-direction: column;
}

.noise{
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  z-index: 1;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 2px, #000 2px, #000 3px);
  mix-blend-mode: multiply;
}

button, input, select, textarea{
  font-family: inherit;
  color: inherit;
}

/* ---------------- TOPBAR ---------------- */
.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(20px, 5vw, 56px);
  border-bottom: 1px solid var(--line);
}

.brand{
  font-family: var(--mono);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.brand-mark{ color: var(--ink); }
.brand-slash{ color: var(--signal); }
.brand-name{
  font-weight: 500;
  margin-left: 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  opacity: 0.7;
}

.topbar-meta{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--teal);
}
.dot{
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 rgba(255,90,31,0.5);
  animation: pulse 2s infinite;
}
@keyframes pulse{
  0%{ box-shadow: 0 0 0 0 rgba(255,90,31,0.45); }
  70%{ box-shadow: 0 0 0 6px rgba(255,90,31,0); }
  100%{ box-shadow: 0 0 0 0 rgba(255,90,31,0); }
}

/* ---------------- LAYOUT ---------------- */
.layout{
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 480px) 1fr;
  position: relative;
  z-index: 2;
}

@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; }
}

.panel{
  padding: clamp(28px, 4vw, 56px);
}

.panel-input{
  border-right: 1px solid var(--line);
  max-height: calc(100vh - 130px);
  overflow-y: auto;
}

@media (max-width: 900px){
  .panel-input{ border-right: none; border-bottom: 1px solid var(--line); max-height: none; overflow-y: visible; }
}

.panel-label{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  text-transform: uppercase;
}
.panel-label span{
  color: var(--paper);
  background: var(--ink);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 2px;
}
.panel-label-spaced{ margin-top: 36px; }

/* ---------------- STEP INDICATOR ---------------- */


/* ---------------- FORM FIELDS ---------------- */
.field{ margin-bottom: 18px; }

label{
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--ink-soft);
}

.sig-label-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  width: 100%;
}
.sig-label{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  margin-bottom: 0;
}
.sig-default-check{
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.sig-default-text{
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  opacity: 0.65;
}

input[type="text"], input[type="date"], textarea, select{
  width: 100%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 13.5px;
  font-family: var(--mono);
  color: var(--ink);
  transition: box-shadow 0.15s ease;
}

input[type="text"]:focus, input[type="date"]:focus, textarea:focus, select:focus{
  outline: none;
  box-shadow: 0 0 0 3px rgba(255,90,31,0.25);
  border-color: var(--signal);
}

.hint{
  font-size: 11.5px;
  color: var(--ink-soft);
  opacity: 0.65;
  margin-top: 6px;
}

.field-row{
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}
.field-small{ flex: 1; min-width: 0; }

/* ---------------- SIGNATURE PAD ---------------- */
.sig-pad-wrap{
  position: relative;
  border: 1.5px dashed var(--ink-soft);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.sig-pad{
  display: block;
  width: 100%;
  height: 140px;
  touch-action: none;
  cursor: crosshair;
}
.sig-pad-empty{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  opacity: 0.5;
  pointer-events: none;
}
.sig-pad-wrap.has-sig .sig-pad-empty{ display: none; }

.sig-controls{
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.btn-chip{
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: transparent;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-chip:hover{ background: var(--ink); color: var(--paper); }
.sig-controls .btn-chip{ flex: 1; }

.error-msg{
  margin-top: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #b8341c;
  min-height: 0;
}
.error-msg:empty{ display: none; }

.export-actions{
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-download{
  width: 100%;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 8px;
  padding: 15px 18px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-download:hover{ background: var(--teal); }
.btn-download[disabled]{ opacity: 0.55; cursor: not-allowed; }

.btn-go-top{
  width: 100%;
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--ink-soft);
  border-radius: 8px;
  padding: 12px 18px;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 6px;
}
.btn-go-top:hover{
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ---------------- TOGGLE GROUP ---------------- */
.toggle-group{
  display: flex;
  border-radius: 8px;
  border: 1.5px solid var(--ink);
  overflow: hidden;
}
.toggle-btn{
  flex: 1;
  padding: 11px 16px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  border: none;
  background: var(--paper-dim);
  cursor: pointer;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.toggle-btn:first-child{ border-right: 1.5px solid var(--ink); }
.toggle-btn.is-selected{ background: var(--ink); color: var(--paper); }

/* ---------------- PREVIEW PANEL ---------------- */
.panel-preview{
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(circle at 50% 0%, rgba(61,90,82,0.06), transparent 60%);
  max-height: calc(100vh - 130px);
  overflow-y: auto;
}

@media (max-width: 900px){
  .panel-preview{ max-height: none; overflow-y: visible; }
}

.doc-stage{
  width: 100%;
  display: flex;
  justify-content: center;
}

/* The document itself: mimics an A4 page */
.doc-page{
  background: #ffffff;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 210 / 297;
  height: auto;
  padding: 58px 48px;
  box-shadow: 0 2px 4px rgba(20,23,28,0.06), 0 12px 32px rgba(20,23,28,0.12);
  border-radius: 2px;
  font-family: var(--serif-doc);
  color: #111;
  position: relative;
  font-size: 12px;
  line-height: 1.5;
}


.doc-title{
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}
.doc-subtitle{
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 22px;
}

.doc-intro{ margin-bottom: 14px; }

.doc-parties-wrapper{
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  margin-bottom: 16px;
}
.doc-parties-left{
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-party{
  padding-left: 20px;
}
.doc-party-label{
  font-weight: 700;
  margin-bottom: 6px;
}

.doc-table{ border-collapse: collapse; }
.doc-table td{
  padding: 1px 6px 1px 0;
  vertical-align: top;
  font-size: 12px;
}
.doc-table td:first-child{ width: 70px; }
.doc-table td:nth-child(2){ width: 12px; }

.doc-qr{
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.doc-qr img, .doc-qr canvas{
  width: 130px;
  height: 130px;
  display: block;
}
.doc-qr-placeholder{
  width: 130px;
  height: 130px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.doc-qr-placeholder-img{
  width: 60px;
  height: auto;
  opacity: 0.4;
}
.doc-qr-placeholder.hidden,
.doc-qr-canvas.hidden{ display: none; }

.doc-body{ margin-bottom: 30px; text-align: justify; }

.doc-place-date{
  text-align: center;
  margin-bottom: 10px;
}

.doc-signatures{
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  gap: 30px;
}
.doc-sig-block{
  flex: 1;
  text-align: center;
}
.doc-sig-heading{ margin-bottom: 6px; }

.doc-sig-image{
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.doc-sig-image img{
  max-height: 68px;
  max-width: 100%;
  object-fit: contain;
}
.doc-sig-name{ font-weight: 700; margin-top: 38px; font-size: 12px; }
.doc-sig-role{ font-size: 11px; }

.doc-notes{
  margin-top: 20px;
  text-align: left;
  font-size: 11px;
  line-height: 1.5;
  font-style: italic;
  background: #fef9e7;
  padding: 9px 10px;
  border-radius: 6px;
}
.doc-notes-label{ font-weight: 700; }
.doc-notes.is-hidden{ display: none; }

.doc-header{
  position: absolute;
  top: 18px;
  left: 48px;
  right: 48px;
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  color: #ededed;
}

.doc-footer{
  position: absolute;
  bottom: 18px;
  left: 48px;
  right: 48px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #ededed;
  font-family: var(--sans);
}

/* ---------------- WATERMARKS / STAMPS ---------------- */
.doc-stamp{
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 3;
}
.doc-stamp.is-visible{ opacity: 1; }

.doc-stamp-rejected{
  bottom: 55px;
  left: 48px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  color: #c0392b;
  border: 3px solid #c0392b;
  padding: 4px 14px;
  border-radius: 4px;
  opacity: 0;
}
.doc-stamp-rejected.is-visible{ opacity: 0.75; }

.doc-stamp-verified{
  bottom: 55px;
  right: 48px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  color: #2b7a4b;
  border: 3px solid #2b7a4b;
  padding: 4px 14px;
  border-radius: 4px;
  opacity: 0;
}
.doc-stamp-verified.is-visible{ opacity: 0.75; }

/* ---------------- FOOTNOTE ---------------- */
.footnote{
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  opacity: 0.55;
  padding: 18px;
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 2;
}

/* ---------------- MASTER DATA MODAL ---------------- */
.modal-overlay{
  position: fixed; inset: 0;
  background: rgba(20,23,28,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden{ display: none; }

.modal-card{
  background: var(--paper);
  border-radius: 12px;
  width: 90%; max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn{
  from{ opacity: 0; transform: scale(0.96) translateY(8px); }
  to{ opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header{
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px 0;
  font-family: var(--mono); font-weight: 700; font-size: 14px;
}
.modal-close{
  background: none; border: none; font-size: 24px; cursor: pointer;
  color: var(--ink-soft); line-height: 1; padding: 4px;
}
.modal-close:hover{ color: var(--ink); }

.modal-body{ padding: 20px 24px; }
.modal-body .field{ margin-bottom: 16px; }
.modal-body .field:last-child{ margin-bottom: 0; }

.modal-footer{
  display: flex; gap: 12px; justify-content: flex-end;
  padding: 0 24px 20px;
}

/* ---------------- TOMBOL "+" MASTER DATA ---------------- */
.btn-add-master{
  margin-left: auto;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: transparent;
  font-size: 18px; font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  color: var(--ink);
}
.btn-add-master:hover{ background: var(--ink); color: var(--paper); }

/* ---------------- DROPDOWN MASTER DATA ---------------- */
select#p1-master, select#p2-master{
  appearance: auto;
  cursor: pointer;
}

/* ---------------- DATABASE LOADING INDICATOR ---------------- */
.db-loading{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--signal);
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}

/* ---------------- DELETE BUTTON ---------------- */
.field-with-delete{
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 18px;
}
.field-with-delete .field{
  flex: 1;
  margin-bottom: 0;
}
.btn-delete-item{
  width: 42px;
  height: 42px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-delete-item.visible{ display: flex; }
.btn-delete-item:hover{ background: #c0392b; color: #fff; border-color: #c0392b; }

/* ---------------- ACCESSIBILITY ---------------- */
:focus-visible{
  outline: 2.5px solid var(--signal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce){
  .dot{ animation: none; }
}

/* ---------------- PRINT ---------------- */
@media print{
  body *{ visibility: hidden; }
  .doc-page, .doc-page *{ visibility: visible; }
  .doc-page{
    position: absolute;
    left: 0; top: 0;
    box-shadow: none;
    margin: 0;
    width: 100%;
    max-width: none;
    aspect-ratio: auto;
    height: auto;
  }
  .noise{ display: none; }
}
