:root {
  --navy: #17223a;
  --navy-2: #25314a;
  --orange: #c96d3a;
  --cream: #f5f2ec;
  --paper: #fffefb;
  --line: #d8d8d3;
  --muted: #687083;
  --green: #2e6b53;
  --shadow: 0 8px 30px rgba(23,34,58,.05);
}
* { box-sizing: border-box; }
html { background: var(--cream); }
body {
  margin: 0;
  color: var(--navy);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
}
button, input, textarea { font: inherit; }
.topbar {
  height: 56px;
  background: var(--navy);
  border-bottom: 3px solid var(--orange);
  color: white;
}
.topbar-inner {
  max-width: 1500px;
  height: 100%;
  margin: auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; background: white; }
.brand-name { font-weight: 800; letter-spacing: .01em; }
.internal-pill {
  font-size: 13px;
  padding: 7px 11px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
}
.page { max-width: 1500px; margin: auto; padding: 44px 24px 64px; }
.hero { margin-bottom: 28px; }
.eyebrow {
  color: #a65330;
  font-weight: 800;
  letter-spacing: .15em;
  font-size: 12px;
}
h1 {
  margin: 18px 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: clamp(42px, 5vw, 64px);
  letter-spacing: -.03em;
}
.hero p, .section-head p { color: var(--muted); }
.tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 28px;
  margin-bottom: 24px;
}
.tab {
  border: 0;
  background: none;
  padding: 12px 2px 16px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--navy); border-bottom-color: var(--orange); }
.badge {
  display: inline-flex;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  background: #e6e5e0;
  border-radius: 999px;
  font-size: 11px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 24px;
  align-items: start;
}
.card, .summary-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.card { padding: 24px; margin-bottom: 18px; }
.section-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 22px;
}
.section-head h2 { margin: 1px 0 4px; font-size: 20px; }
.section-head p { margin: 0; font-size: 14px; }
.section-no {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #decfc5;
  color: #a65330;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 13px;
}
.item-counter { margin-left: auto; color: var(--muted); font-size: 13px; }
label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 750;
  color: #525b70;
}
input, textarea {
  width: 100%;
  margin-top: 7px;
  border: 1px solid #d7d9df;
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  padding: 12px 13px;
  outline: none;
}
input:focus, textarea:focus { border-color: #8e96a6; box-shadow: 0 0 0 3px rgba(23,34,58,.06); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { color: #8a8f9a; font-size: 11px; font-weight: 400; }
.items-wrap { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.items-table th {
  text-align: left;
  padding: 10px 8px;
  color: #596176;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
}
.items-table td { padding: 7px 8px; vertical-align: middle; border-bottom: 1px solid #eeeee9; }
.items-table input { margin: 0; padding: 10px; }
.items-table .qty { width: 92px; }
.items-table .kg { width: 82px; }
.items-table .price { width: 150px; }
.amount-cell { min-width: 130px; font-weight: 700; }
.remove-btn {
  border: 0;
  background: transparent;
  color: #9d4b36;
  cursor: pointer;
  font-size: 20px;
}
.secondary-btn, .primary-btn {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 750;
}
.secondary-btn { margin-top: 16px; padding: 10px 14px; background: #ecebe6; color: var(--navy); }
.primary-btn { width: 100%; padding: 15px; background: var(--orange); color: white; }
.primary-btn:hover { filter: brightness(.96); }
.summary-card { position: sticky; top: 18px; }
.summary-section { padding: 24px; border-bottom: 1px solid var(--line); }
.summary-section:last-child { border-bottom: 0; }
.summary-title {
  margin-bottom: 18px;
  color: #a65330;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .12em;
}
.summary-row { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; font-size: 14px; }
.tax-toggle { margin: 0; color: var(--navy); font-size: 14px; font-weight: 500; }
.tax-toggle input { width: auto; margin: 0 7px 0 0; }
.summary-card hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.grand-label { color: var(--muted); font-size: 12px; }
.grand-total { margin: 8px 0 3px; font-family: Georgia, serif; font-size: 34px; }
.pdf-output h3 { margin: 0 0 14px; font-size: 13px; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; color: #536071; font-size: 11px; }
.check-grid span::first-letter { color: var(--green); }
.legal-note { margin: 12px 0 0; text-align: center; color: #989aa2; font-size: 9px; }
.history-list { display: grid; gap: 12px; }
.history-empty { padding: 30px; text-align: center; color: var(--muted); }
.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 20px;
}
.history-item h4 { margin: 0; }
.history-meta { color: var(--muted); font-size: 12px; }
.history-total { font-weight: 800; }
.print-area { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .summary-card { position: static; }
}
@media (max-width: 640px) {
  .page { padding: 28px 14px 48px; }
  .topbar-inner { padding: 0 14px; }
  .card { padding: 16px; }
  .two-col { grid-template-columns: 1fr; gap: 0; }
  .check-grid { grid-template-columns: 1fr; }
}

@media print {
  /*
   * Each physical document is exactly 210 x 160 mm.
   * Two documents therefore require a custom 210 x 320 mm PDF page.
   * This cannot fit at full size on standard A4 (210 x 297 mm).
   */
  @page {
    size: 210mm 320mm;
    margin: 0;
  }

  html, body {
    width: 210mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  body > *:not(.print-area) {
    display: none !important;
  }

  .print-area {
    display: block !important;
    width: 210mm;
    margin: 0;
    padding: 0;
    color: #111827;
    background: #fff;
    font-family: Arial, Helvetica, sans-serif;
  }

  .print-sheet {
    width: 210mm;
    height: 320mm;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    background: #fff;
  }

  .print-sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-document-slot {
    position: relative;
    width: 210mm;
    height: 160mm;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
  }

  .print-cut-line {
    position: absolute;
    left: 0;
    width: 210mm;
    height: 0;
    margin-top: -0.15mm;
    border-top: 0.3mm dashed #6b7280;
    z-index: 50;
    pointer-events: none;
  }

  /* -------- NOTA: exact external size 210 x 160 mm -------- */
  .nota-copy {
    position: relative;
    width: 210mm;
    height: 160mm;
    padding: 5mm 6mm 4mm;
    box-sizing: border-box;
    overflow: hidden;
    font-size: 6.8pt;
    background: #fff;
  }

  .nota-copy-label {
    position: absolute;
    top: 4.7mm;
    right: 6mm;
    font-size: 6.4pt;
    font-weight: 400;
  }

  .nota-title {
    text-align: center;
    font-weight: 700;
    font-size: 10pt;
    line-height: 1;
    padding-top: 0;
    margin: 0;
  }

  .nota-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15mm;
    height: 20mm;
    margin: 2mm 1mm 1.8mm;
    line-height: 1.25;
    overflow: hidden;
  }

  .nota-meta-left,
  .nota-meta-right {
    min-width: 0;
    min-height: 0;
  }

  .nota-meta-left > div,
  .nota-meta-right > div:not(.nota-customer):not(.nota-address) {
    display: grid;
    grid-template-columns: 28mm 3mm minmax(0, 1fr);
  }

  .nota-meta span,
  .nota-meta strong {
    font-weight: 400;
  }

  .nota-customer {
    margin-top: 0.35mm;
    font-size: 7.2pt;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Address is intentionally one printed line to preserve room for 10 item rows. */
  .nota-address {
    margin-top: 0.45mm;
    max-width: 83mm;
    font-size: 6pt;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nota-print-table,
  .nota-totals,
  .sj-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }

  .nota-print-table {
    width: calc(100% - 0.35mm);
    margin: 0;
    font-size: 5.8pt;
  }

  .nota-print-table .col-qty { width: 8.5%; }
  .nota-print-table .col-kg { width: 8.5%; }
  .nota-print-table .col-name { width: 42%; }
  .nota-print-table .col-price { width: 17%; }
  .nota-print-table .col-amount { width: 24%; }

  .nota-print-table th,
  .nota-print-table td {
    border: 0.22mm solid #111827;
    box-sizing: border-box;
    height: 3.45mm;
    max-height: 3.45mm;
    padding: 0.35mm 0.85mm;
    line-height: 1;
    overflow: hidden;
  }

  .nota-print-table th {
    text-align: center;
    font-weight: 700;
    font-size: 5.15pt;
    white-space: nowrap;
  }

  .nota-print-table td:nth-child(1),
  .nota-print-table td:nth-child(2) {
    text-align: center;
    white-space: nowrap;
  }

  .nota-print-table td:nth-child(3) {
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .nota-print-table td:nth-child(4),
  .nota-print-table td:nth-child(5) {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.1pt;
  }

  .nota-print-table tr > *:last-child {
    border-right: 0.28mm solid #111827;
  }

  .nota-bottom {
    display: grid;
    grid-template-columns: minmax(0, 56fr) minmax(0, 44fr);
    gap: 1.8mm;
    width: calc(100% - 0.35mm);
    margin-top: 1mm;
  }

  .nota-bottom > * {
    min-width: 0;
    box-sizing: border-box;
  }

  .nota-payment {
    border: 0.22mm solid #111827;
    padding: 0.8mm 1.4mm;
    height: 12.7mm;
    box-sizing: border-box;
    overflow: hidden;
    font-size: 4.35pt;
    line-height: 1.38;
    font-weight: 700;
    text-transform: uppercase;
  }

  .nota-totals {
    width: 100%;
    height: 12.7mm;
    font-size: 5.55pt;
    font-variant-numeric: tabular-nums;
  }

  .nota-totals th,
  .nota-totals td {
    border: 0.22mm solid #111827;
    box-sizing: border-box;
    height: 4.23mm;
    padding: 0.4mm 0.8mm;
    line-height: 1;
  }

  .nota-totals th {
    width: 56%;
    text-align: right;
    font-weight: 700;
    white-space: nowrap;
  }

  .nota-totals td {
    width: 44%;
    text-align: right;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.12pt;
  }

  .nota-totals tr > *:last-child {
    border-right: 0.28mm solid #111827;
  }

  .nota-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    text-align: center;
    height: 20mm;
    margin-top: 5mm;
    font-size: 5.4pt;
    font-weight: 700;
  }

  .nota-signatures > div {
    position: relative;
    height: 20mm;
  }

  .nota-signatures span {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }

  /* -------- SURAT JALAN: exact external size 210 x 160 mm -------- */
  .surat-jalan-copy {
    position: relative;
    width: 210mm;
    height: 160mm;
    padding: 5mm 6mm 4mm;
    box-sizing: border-box;
    overflow: hidden;
    background: #fff;
  }

  .sj-top {
    position: relative;
    height: 24mm;
  }

  .sj-title {
    position: absolute;
    top: 10mm;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 10pt;
    font-weight: 700;
  }

  .sj-meta {
    position: absolute;
    top: 0;
    right: 0;
    width: 42%;
    font-size: 6.7pt;
    line-height: 1.4;
  }

  .sj-meta > div:not(.sj-customer) {
    display: grid;
    grid-template-columns: 25mm 3mm minmax(0, 1fr);
  }

  .sj-meta strong {
    font-weight: 400;
  }

  .sj-customer {
    margin-top: 0.4mm;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sj-table {
    width: calc(100% - 0.35mm);
    margin-top: 1mm;
    font-size: 5.9pt;
  }

  .sj-table th,
  .sj-table td {
    border: 0.22mm solid #111827;
    box-sizing: border-box;
    height: 4mm;
    max-height: 4mm;
    padding: 0.4mm 1mm;
    line-height: 1;
    overflow: hidden;
  }

  .sj-table th {
    text-align: center;
    font-weight: 700;
    white-space: nowrap;
  }

  .sj-table .sj-no {
    width: 5.5%;
  }

  .sj-table th:nth-child(2) {
    width: 64%;
  }

  .sj-table td:first-child {
    width: 5.5%;
    text-align: center;
  }

  .sj-table .sj-name {
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .sj-table td:nth-child(3),
  .sj-table td:nth-child(4) {
    text-align: center;
    width: 15.25%;
    white-space: nowrap;
  }

  .sj-table tr > *:last-child {
    border-right: 0.28mm solid #111827;
  }

  .sj-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    text-align: center;
    margin-top: 18mm;
    font-size: 5.8pt;
  }

  .print-cancelled-watermark {
    position: absolute;
    left: 15%;
    right: 15%;
    top: 38%;
    z-index: 20;
    transform: rotate(-20deg);
    text-align: center;
    font-size: 34pt;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: rgba(145, 40, 30, 0.16);
    pointer-events: none;
  }
}


.edit-banner {
  margin: -6px 0 22px;
  padding: 13px 16px;
  border: 1px solid #dcbfae;
  background: #fff8f3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 7px;
  font-size: 13px;
}
.edit-banner[hidden] { display: none; }
.edit-banner > div { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-banner button {
  border: 1px solid #c4c7cf;
  background: white;
  color: var(--navy);
  border-radius: 5px;
  padding: 8px 11px;
  cursor: pointer;
}

.history-archive {
  background: transparent;
  padding: 12px 4px 0;
}
.history-page-title {
  margin: 16px 0 34px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -.02em;
}
.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--paper);
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}
.history-table th {
  padding: 16px 18px;
  background: #f0efeb;
  color: #747a89;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
}
.history-table td {
  padding: 18px;
  border-top: 1px solid #e4e3df;
  vertical-align: middle;
  font-size: 13px;
}
.history-table tbody tr:first-child td { border-top: 0; }
.history-table strong { display: block; font-weight: 650; }
.history-sub {
  display: block;
  margin-top: 7px;
  color: #8a8f9a;
  font-size: 11px;
}
.status-pill {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
}
.status-active {
  color: #2f6a54;
  background: #e9f2ed;
}
.status-cancelled {
  color: #8c4a3b;
  background: #f5e9e5;
}
.history-row-cancelled {
  background: #fbfaf8;
}
.history-row-cancelled td:not(.history-actions) {
  opacity: .7;
}
.history-actions {
  text-align: right;
  white-space: nowrap;
}
.history-btn {
  border: 1px solid #cfd1d6;
  background: #fff;
  color: var(--navy);
  border-radius: 5px;
  padding: 8px 12px;
  margin-left: 6px;
  cursor: pointer;
  font-size: 12px;
}
.history-btn-edit { border-color: #b9c4d9; color: #435979; }
.history-btn-cancel { border-color: #dab9b0; color: #974d3b; }
.history-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.history-footnote,
.history-storage-note {
  color: #8a8f9a;
  font-size: 11px;
  margin-top: 12px;
}
@media (max-width: 760px) {
  .edit-banner {
    align-items: flex-start;
    flex-direction: column;
  }
  .history-page-title { margin-bottom: 22px; }
  .history-table {
    min-width: 0;
  }
  .history-table thead {
    display: none;
  }
  .history-table,
  .history-table tbody,
  .history-table tr,
  .history-table td {
    display: block;
    width: 100%;
  }
  .history-table tr {
    padding: 14px 16px;
    border-top: 1px solid #e4e3df;
  }
  .history-table tr:first-child { border-top: 0; }
  .history-table td {
    border: 0;
    padding: 7px 0 7px 112px;
    position: relative;
    min-height: 28px;
  }
  .history-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: 8px;
    width: 100px;
    color: #858a96;
    font-size: 10px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  .history-actions {
    text-align: left;
    padding-left: 0 !important;
    margin-top: 7px;
  }
  .history-actions::before { display: none; }
  .history-btn {
    margin: 0 6px 6px 0;
  }
}
