.memo-page {
  padding-bottom: var(--space-lg);
}

.memo-page-header,
.page-header.memo-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.memo-page-layout {
  display: block;
}

.memo-workspace {
  min-width: 0;
}

/* ── Toolbar ── */
.memo-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  position: sticky;
  top: calc(var(--header-height) + 8px);
  z-index: 5;
}

.memo-toolbar .btn-brand,
.memo-toolbar .btn-outline {
  justify-content: center;
}

/* ── Workspace / Canvas ── */
.memo-preview-wrap {
  display: flex;
  justify-content: center;
  padding: var(--space-lg);
  background: #d1d5db;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

/* ── Inline Field System ── */
.memo-field {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.memo-field:focus {
  box-shadow: inset 0 -2px 0 rgba(107, 33, 168, 0.35);
}

.memo-field::placeholder {
  color: rgba(107, 114, 128, 0.55);
}

.memo-field-readonly {
  font-family: var(--font-en);
  font-size: 14px;
  font-weight: 800;
}

.memo-field-title {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 34px;
  font-weight: 800;
  color: #c41e3a;
  line-height: 1.15;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.memo-field-multiline {
  display: block;
  max-width: 620px;
  margin: 0 auto 6px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
}

.memo-field-address {
  display: block;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
}

.memo-field-contact {
  display: block;
  text-align: center;
  font-size: 10px;
  line-height: 1.65;
}

.memo-field-badge {
  width: auto;
  min-width: 80px;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
}

.memo-field-no {
  width: auto;
  min-width: 64px;
  cursor: default;
}

.memo-field-no:focus {
  box-shadow: none;
}

.memo-field-date {
  width: 32px;
  min-width: 32px;
  text-align: center;
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 700;
}

.memo-field-date.memo-date-year {
  width: 44px;
  min-width: 44px;
}

.memo-field-deposit {
  width: 80px;
  min-width: 60px;
  text-align: right;
  font-family: var(--font-en);
  font-size: 14px;
  font-weight: 800;
  -moz-appearance: textfield;
}

.memo-field-deposit::-webkit-outer-spin-button,
.memo-field-deposit::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ── Memo Sheet ── */
.memo-sheet {
  position: relative;
  width: 100%;
  max-width: 794px;
  min-height: 1123px;
  padding: 14px 18px 24px;
  background: #fff;
  border: 2px solid #1f2937;
  box-shadow: var(--shadow-lg);
  font-family: var(--font-bn);
  color: #111;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.memo-sheet-top-rule {
  height: 6px;
  margin: -14px -18px 12px;
  background: linear-gradient(to bottom, #c41e3a 4px, #6b21a8 4px, #6b21a8 6px);
}

.memo-sheet-header {
  text-align: center;
  border-bottom: 2px solid #6b21a8;
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.memo-contact-grid {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.memo-tax-badges {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.memo-tax-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}

.memo-tax-prefix {
  flex-shrink: 0;
}

.memo-meta-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.memo-no-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.memo-no-box {
  display: inline-block;
  min-width: 64px;
  padding: 5px 12px;
  border: 2.5px solid #1f2937;
  text-align: center;
  font-family: var(--font-en);
  font-size: 14px;
  font-weight: 800;
  background: transparent;
}

.memo-title-badge {
  padding: 7px 22px;
  background: #6b21a8;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  border-radius: 4px;
  letter-spacing: 1px;
  box-shadow: 0 2px 6px rgba(107, 33, 168, 0.25);
  text-transform: uppercase;
}

.memo-date-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
}

.memo-date-box {
  display: inline-block;
  min-width: 32px;
  padding: 4px 6px;
  border: 1.5px solid #1f2937;
  text-align: center;
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 700;
  background: transparent;
}

.memo-customer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.memo-customer-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid #6b7280;
}

.memo-customer-field.is-green {
  background: #bbf7d0;
}

.memo-customer-field.is-red {
  background: #fecaca;
}

.memo-customer-label {
  flex-shrink: 0;
  width: 72px;
  font-weight: 700;
}

.memo-customer-value {
  flex: 1;
  min-width: 0;
  min-height: 16px;
  word-break: break-word;
}

/* ── Table ── */
.memo-table-wrap {
  position: relative;
  margin-bottom: 10px;
  border: 2px solid #1f2937;
}

.memo-table-wrap::after {
  content: 'AT';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 80px;
  font-weight: 900;
  color: rgba(107, 33, 168, 0.04);
  pointer-events: none;
  z-index: 0;
}

.memo-table {
  position: relative;
  z-index: 1;
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.memo-table thead th {
  padding: 8px 4px;
  background: #6b21a8;
  color: #fff;
  font-weight: 700;
  border: 1px solid #4c1d95;
  text-align: center;
  letter-spacing: 0.3px;
}

.memo-table tbody td {
  padding: 2px 4px;
  border: 1px solid #9ca3af;
  vertical-align: middle;
  height: 30px;
}

.memo-table tbody tr:nth-child(even) td {
  background: #fafafa;
}

.memo-table .col-serial {
  width: 36px;
  text-align: center;
  font-family: var(--font-en);
  font-weight: 600;
}

.memo-table .col-desc {
  text-align: left;
  padding-left: 4px;
}

.memo-table .col-desc .memo-field {
  text-align: left;
  padding-left: 4px;
}

.memo-table .col-pcs {
  width: 50px;
  text-align: center;
  background: #fef9c3 !important;
  font-family: var(--font-en);
}

.memo-table .col-pcs .memo-field {
  text-align: center;
  -moz-appearance: textfield;
}

.memo-table .col-rate {
  width: 60px;
  text-align: center;
  background: #dbeafe !important;
  font-family: var(--font-en);
}

.memo-table .col-rate .memo-field {
  text-align: center;
  -moz-appearance: textfield;
}

.memo-table .col-pcs .memo-field::-webkit-outer-spin-button,
.memo-table .col-pcs .memo-field::-webkit-inner-spin-button,
.memo-table .col-rate .memo-field::-webkit-outer-spin-button,
.memo-table .col-rate .memo-field::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.memo-table .col-total {
  width: 70px;
  text-align: center;
  background: #fce7f3 !important;
  font-family: var(--font-en);
  font-weight: 600;
}

.memo-table .item-total {
  display: block;
  text-align: center;
}

/* ── Footer ── */
.memo-amount-words {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1.5px solid #6b7280;
  font-size: 12px;
  font-weight: 600;
}

.memo-amount-words-value {
  flex: 1;
  border-bottom: 2px dotted #6b7280;
  min-height: 24px;
  padding-bottom: 2px;
}

.memo-totals-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.memo-total-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 2px solid #1f2937;
  font-size: 12px;
  font-weight: 700;
}

.memo-total-box.is-deposit {
  background: #fef08a;
}

.memo-total-box.is-due {
  background: #fdba74;
}

.memo-total-box.is-due.has-balance .memo-field-readonly {
  color: #dc2626;
}

.memo-hadith-box {
  padding: 10px 12px;
  margin-bottom: 16px;
  background: #dcfce7;
  border: 2px solid #16a34a;
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.65;
}

.memo-hadith-title {
  font-weight: 800;
  margin-bottom: 6px;
  color: #166534;
}

.memo-hadith-box ul {
  margin: 0;
  padding-left: 18px;
  list-style: decimal;
}

.memo-hadith-box li {
  margin-bottom: 3px;
}

.memo-signature {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 8px;
}

.memo-signature-line {
  width: 200px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  border-top: 1.5px solid #1f2937;
  padding-top: 6px;
}

/* ── Print ── */
@media print {
  body {
    background: #fff;
  }

  .top-header,
  .breadcrumb-bar,
  .sidebar,
  .memo-page-header,
  .memo-toolbar {
    display: none !important;
  }

  .app-layout,
  .main-wrapper,
  .main-content,
  .memo-page,
  .memo-page-layout,
  .memo-workspace,
  .memo-preview-wrap {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
    border: none !important;
  }

  .memo-sheet {
    max-width: 100%;
    min-height: auto;
    border: none;
    box-shadow: none;
    margin: 0;
    padding: 10mm;
  }

  .memo-sheet-top-rule {
    margin-left: 0;
    margin-right: 0;
  }

  .memo-field {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    -webkit-appearance: none;
    appearance: none;
  }

  .memo-field:focus {
    box-shadow: none !important;
  }

  .memo-no-box,
  .memo-date-box {
    border-color: #1f2937 !important;
  }
}

@media (max-width: 768px) {
  .memo-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .memo-sheet {
    padding: 10px;
    font-size: 90%;
  }

  .memo-field-title {
    font-size: 26px;
  }

  .memo-meta-row {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .memo-date-wrap {
    justify-content: center;
  }

  .memo-customer-grid {
    grid-template-columns: 1fr;
  }

  .memo-totals-row {
    grid-template-columns: 1fr;
  }

  .memo-toolbar .btn-brand,
  .memo-toolbar .btn-outline {
    width: 100%;
    justify-content: center;
    min-height: var(--touch-min);
  }

  .memo-table .memo-field {
    min-height: var(--touch-min);
    font-size: var(--text-base);
  }

  .memo-table tbody td {
    padding: 8px 4px;
  }
}
