/* CSS Variables */
:root {
  --brand-blue: #0b3a7a;
  --brand-blue-2: #173a8a;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f8fafc;
  --paper: #ffffff;
  --space-1: 0.25rem; /*4px*/
  --space-2: 0.5rem; /*8px*/
  --space-3: 0.75rem; /*12px*/
  --space-4: 1rem; /*16px*/
  --space-5: 1.5rem; /*24px*/
  --a4-h: 1123px; /* approx 297mm at 96dpi */
  /* Indent untuk baris wrap setelah baris pertama pada nilai meta */
  --meta-wrap-indent: 12px;
}

html,
body {
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text-main);
  background: var(--bg);
}

/* Topbar */
.topbar {
  background: var(--brand-blue);
  color: #fff;
  padding: var(--space-3) 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.topbar-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.topbar-logo {
  height: 40px;
  width: auto;
}

/* Section titles */
.section-title {
  font-weight: 600;
  color: var(--brand-blue);
}

/* Form items */
.item-list {
  border: 1px dashed var(--border);
  padding: var(--space-3);
  border-radius: 0.5rem;
  background: #fff;
}
.item-row {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 0.9fr 1.2fr auto;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.item-row .form-control,
.item-row .form-select {
  height: 38px;
}
.item-actions .btn {
  height: 38px;
}

/* Invoice preview */
.invoice.paper {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: var(--a4-h);
}
.invoice-header {
  background: var(--brand-blue);
  color: #fff;
  padding: var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.invoice-header .title {
  font-size: 1.25rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}
.company-logo {
  height: 40px;
}

.invoice-meta {
  padding: var(--space-4);
  padding-bottom: var(--space-3);
}
.meta-block {
  font-size: 0.95rem;
}
.meta-block .label {
  color: #667085;
  width: 180px; /* beri ruang label tetap */
  display: inline-block;
  white-space: nowrap;
}
/* Tambahkan tanda ':' setelah label agar sesuai contoh */
/* Pindahkan ':' ke depan value (bukan sesudah label) */
.meta-block .label::after {
  content: "";
  margin: 0;
}
.meta-block span + span::before {
  content: ":";
  margin: 0 6px;
}
/* Setiap baris meta menjadi grid agar wrap value sejajar dengan awal value */
.meta-block > div {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: start;
}
.meta-block > div span:last-child {
  word-break: break-word;
  overflow-wrap: anywhere;
  /* Hanging indent: baris pertama tetap, baris selanjutnya bergeser ke kanan */
  padding-left: var(--meta-wrap-indent);
  text-indent: calc(var(--meta-wrap-indent) * -1);
}

/* Force two-column layout for meta section */
.invoice-meta .row {
  display: flex;
  flex-wrap: nowrap;
}
.invoice-meta .row .col-6 {
  flex: 0 0 50%;
  max-width: 50%;
}

/* Table */
.invoice-table {
  border: 1px solid var(--border);
  margin: 0 var(--space-4);
  width: calc(100% - 2rem);
  table-layout: fixed; /* pastikan lebar kolom konsisten saat render & capture */
}
.invoice-table thead th {
  background: #eef2ff;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.invoice-table td,
.invoice-table th {
  padding: 0.5rem 0.6rem;
}
.invoice-table tbody tr:nth-child(even) {
  background: #fafafa;
}

/* Alignments per column */
.invoice-table th:nth-child(3),
.invoice-table td:nth-child(3),
.invoice-table th:nth-child(4),
.invoice-table td:nth-child(4) {
  text-align: center; /* Qty & Satuan di tengah */
}
.invoice-table th:nth-child(5),
.invoice-table td:nth-child(5),
.invoice-table th:nth-child(6),
.invoice-table td:nth-child(6) {
  text-align: right; /* Harga Satuan & Total di kanan */
  white-space: nowrap;
}
.invoice-table td:nth-child(2) div {
  white-space: normal; /* Deskripsi bebas meluas dan wrap */
  word-break: break-word;
  overflow-wrap: anywhere; /* jaga wrap sama antara preview & pdf */
}

/* Summary */
.summary {
  border: none;
  margin: var(--space-4);
}
.summary {
  margin-left: auto;
}
.summary-table {
  width: 360px;
}
.summary-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.summary-table td:last-child {
  text-align: right;
  padding-right: 0.75rem;
}
.summary-table tr:last-child td {
  border-bottom: none;
}

/* Notes */
.notes {
  margin: 0 var(--space-4);
}
.notes-content {
  min-height: 60px;
  border: 1px dashed var(--border);
  padding: var(--space-3);
  border-radius: 0.5rem;
  background: #fff;
}
/* Rapatkan spasi catatan */
.notes-content {
  line-height: 1.45;
}
.notes-content ol,
.notes-content ul {
  margin: 0.25rem 0;
  padding-left: 1.1rem;
}
.notes-content li {
  margin-bottom: 0.25rem;
}

/* Footer area sticks to bottom when content short */
.invoice-footer {
  margin-top: auto;
}

/* Attachments grid */
.attachments-grid {
  margin: 0 var(--space-4);
  margin-bottom: var(--space-4);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.attachments-grid .attachment-item {
  position: relative;
  /* Buat kotak konsisten agar gambar tidak terlihat lonjong */
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachments-grid img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* jaga proporsi gambar tanpa distorsi */
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  break-inside: avoid;
  page-break-inside: avoid;
}
.attachment-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  color: #dc3545;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(16, 24, 40, 0.12);
}
.attachment-remove:hover {
  background: #fff;
}
@media print {
  .attachment-remove {
    display: none !important;
  }
}

@media (max-width: 992px) {
  .attachments-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 576px) {
  .attachments-grid {
    grid-template-columns: 1fr;
  }
}

/* Signature */
.signature {
  position: relative;
  margin: var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.signature-img {
  height: 68px;
  width: auto;
  margin: var(--space-2) 0;
  opacity: 0.95;
}
.sig-name {
  font-weight: 600;
}
.sig-title {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.sig-watermark {
  position: absolute;
  right: 16px;
  bottom: 0;
  width: 200px;
  height: 200px;
  opacity: 0.08;
  background: radial-gradient(circle at 20% 20%, #9ab6ff 0, #9ab6ff 20%, transparent 22%), radial-gradient(circle at 80% 60%, #9ab6ff 0, #9ab6ff 20%, transparent 22%);
  border-radius: 50%;
}

/* Print styles */
@media print {
  body {
    background: #fff;
  }
  .topbar,
  .card-header .btn,
  .d-print-none {
    display: none !important;
  }
  .card {
    box-shadow: none !important;
    border: none !important;
  }
  .invoice.paper {
    border: none;
  }
}

/* Responsive breakpoints */
@media (max-width: 992px) {
  .item-row {
    grid-template-columns: 1fr 1fr 0.8fr 1fr auto;
  }
  .summary-table {
    width: 100%;
  }
}
@media (max-width: 576px) {
  .item-row {
    grid-template-columns: 1fr;
  }
}
