.document-workspace .main-area {
  padding: 18px 20px 32px;
}

/* ── Topbar ── */
.document-workspace .topbar {
  margin-bottom: 14px;
  align-items: center;
}

.document-workspace .topbar h1 {
  font-size: 20px;
  line-height: 1.2;
}

.document-workspace .topbar p {
  margin-top: 2px;
  font-size: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* ── Layout grid ── */
.document-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

/* ── Form panel ── */
.input-panel {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

fieldset:last-child {
  border-bottom: 0;
}

legend {
  float: left;
  width: 100%;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* clear float so fieldset grid works */
legend + * {
  clear: left;
}

label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

label input,
label select,
label textarea {
  color: var(--ink);
  font-size: 13px;
}

/* compact inputs for this page */
.document-workspace select,
.document-workspace input:not([type="radio"]):not([type="checkbox"]) {
  height: 32px;
  padding: 0 9px;
  font-size: 13px;
}

.document-workspace textarea {
  padding: 6px 9px;
  font-size: 13px;
  min-height: 52px;
}

.form-grid {
  display: grid;
  gap: 8px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* ── Checkbox / radio grids ── */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.checkbox-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 12px;
  background: var(--surface-soft);
}

.checkbox-grid input {
  width: 14px;
  height: 14px;
  padding: 0;
  flex-shrink: 0;
}

/* ── Certificate list table ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table-wrap th,
.table-wrap td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.table-wrap thead th {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
}

.table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--surface-soft);
}

.clickable-row.selected td {
  background: var(--green-soft);
}

.empty-state {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ── Line editor ── */
.line-editor {
  display: grid;
  gap: 8px;
}

.line-card {
  display: grid;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.line-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.line-card header strong {
  font-size: 12px;
  color: var(--muted);
}

.line-card header button {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
}

/* ── Buttons ── */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.full {
  width: 100%;
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* ── Preview modal ── */
.preview-frame {
  min-width: 0;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9e5db;
  box-shadow: var(--shadow);
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}

.preview-modal.hidden {
  display: none !important;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 29, 25, 0.58);
}

.preview-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preview-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.preview-modal-panel .preview-frame {
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.print-stage {
  width: fit-content;
  margin: 0 auto;
}

/* ── WHT Document (print layout) ── */
.wht-sheet {
  width: 210mm;
  min-height: 0;
  padding: 6mm 7mm;
  color: #111;
  background: #fff;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 10px;
  line-height: 1.4;
}

.copy-note {
  margin-bottom: 1mm;
  padding-left: 1mm;
  font-size: 9.5px;
}

.certificate-border {
  border: 2px solid #111;
}

.certificate-title {
  display: grid;
  grid-template-columns: 34mm 1fr 36mm;
  align-items: start;
  padding: 1.4mm 3mm 1mm;
  border-bottom: 1px solid #111;
}

.certificate-title h2 {
  margin: 0;
  text-align: center;
  font-size: 18px;
  line-height: 1.15;
}

.certificate-title p {
  margin: 1mm 0 0;
  text-align: center;
  font-size: 12px;
}

.doc-number {
  display: grid;
  gap: 2mm;
  justify-self: end;
  min-width: 35mm;
  font-size: 12px;
}

.doc-number span {
  display: inline-block;
  min-width: 22mm;
  border-bottom: 1px dotted #111;
}

.party-box {
  position: relative;
  min-height: 23mm;
  padding: 1.5mm 3mm;
  border-bottom: 1px solid #111;
}

.party-heading {
  font-size: 13px;
  font-weight: 800;
}

.tax-row {
  position: absolute;
  top: 1.5mm;
  right: 3mm;
  display: flex;
  align-items: center;
  gap: 2mm;
  font-size: 10px;
  font-weight: 800;
}

.tax-id {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 1px;
}

.tax-id span {
  display: grid;
  width: 4.7mm;
  height: 4.7mm;
  place-items: center;
  border: 1px solid #111;
  font-size: 10px;
}

.field-line {
  display: grid;
  grid-template-columns: 12mm 1fr;
  gap: 2mm;
  margin-top: 1.3mm;
  border-bottom: 1px dotted #111;
}

.field-line span {
  min-height: 12px;
  overflow-wrap: anywhere;
}

.hint {
  margin-left: 14mm;
  color: #333;
  font-size: 8px;
  font-style: italic;
}

.pnd-row {
  display: grid;
  grid-template-columns: 59mm 1fr;
  gap: 2mm;
  padding: 1.2mm 3mm;
  border-bottom: 1px solid #111;
}

.sequence-box {
  display: grid;
  grid-template-columns: auto 32mm auto;
  gap: 2mm;
  align-items: center;
}

.sequence-box strong {
  min-height: 7mm;
  border: 1px solid #111;
  text-align: center;
  line-height: 7mm;
}

.pnd-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1mm 3mm;
}

.pnd-item {
  display: inline-flex;
  align-items: center;
  gap: 2mm;
  font-weight: 700;
}

.box-mark {
  display: inline-grid;
  width: 4.8mm;
  height: 4.8mm;
  place-items: center;
  border: 1px solid #111;
  font-size: 10px;
  line-height: 1;
}

.income-table {
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 10px;
}

.income-table th,
.income-table td {
  padding: 1mm 1.5mm;
  border: 1px solid #111;
  color: #111;
  vertical-align: top;
}

.income-table th:first-child,
.income-table td:first-child {
  width: 58%;
}

.income-table th:nth-child(2),
.income-table td:nth-child(2) {
  width: 15%;
  text-align: center;
}

.income-table th:nth-child(3),
.income-table td:nth-child(3),
.income-table th:nth-child(4),
.income-table td:nth-child(4) {
  width: 15%;
  text-align: right;
}

.income-table thead th {
  text-align: center;
  font-size: 13px;
}

.income-table tbody td {
  height: 6.8mm;
}

.income-description {
  white-space: pre-line;
}

.amount-cell {
  border-bottom-style: dotted;
}

.tax-text,
.fund-row,
.payment-condition {
  display: flex;
  gap: 3mm;
  align-items: center;
  min-height: 8mm;
  padding: 1mm 3mm;
  border-bottom: 1px solid #111;
}

.tax-text span {
  flex: 1;
  min-height: 6mm;
  padding: 1mm 2mm;
  background: #d9d9d9;
}

.fund-row {
  justify-content: space-between;
  font-size: 9px;
}

.fund-row strong {
  display: inline-block;
  min-width: 20mm;
  border-bottom: 1px dotted #111;
  text-align: right;
  font-weight: 400;
}

.payment-condition {
  flex-wrap: wrap;
  font-size: 10px;
}

.payment-condition span {
  display: inline-flex;
  align-items: center;
  gap: 1mm;
}

.payment-condition span::before {
  content: "";
  display: inline-grid;
  width: 4.8mm;
  height: 4.8mm;
  place-items: center;
  border: 1px solid #111;
}

.payment-condition span.selected::before {
  content: "✓";
}

.certificate-footer {
  display: grid;
  grid-template-columns: 41% 59%;
  min-height: 22mm;
}

.warning,
.signature {
  padding: 2mm;
}

.warning {
  display: grid;
  grid-template-columns: 17mm 1fr;
  gap: 2mm;
  border-right: 1px solid #111;
}

.warning strong {
  font-size: 12px;
}

.signature {
  position: relative;
  text-align: center;
}

.signature p {
  margin: 0 0 5mm;
}

.signature span {
  display: inline-block;
  min-width: 52mm;
  border-bottom: 1px dotted #111;
  font-size: 11px;
  font-weight: normal;
  text-align: center;
}

.sig-top-row {
  margin-bottom: 1mm;
}

.sig-name-row,
.sig-date-row {
  margin-top: 1mm;
}

.sig-date-label {
  font-size: 9px;
  color: #555;
  font-style: italic;
  margin-top: 0.5mm;
}

.stamp {
  position: absolute;
  right: 4mm;
  bottom: 3mm;
  display: grid;
  width: 17mm;
  height: 17mm;
  place-items: center;
  border: 1px solid #111;
  border-radius: 50%;
  font-size: 8px;
}

.note-line {
  margin-top: 1mm;
  font-size: 8px;
}

/* ── Tabs ── */
.wht-tabs {
  display: flex;
  border-bottom: 2px solid var(--line);
  margin-bottom: 14px;
}

.tab-btn {
  padding: 7px 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

/* ── List tab ── */
.list-header {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 10px;
}

.year-month-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: 1;
}

.year-month-row label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.year-month-row select {
  height: 32px;
  padding: 0 9px;
  font-size: 13px;
}

.list-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ── Form tab toolbar ── */
.form-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  align-items: center;
}

/* ── Danger button ── */
.button.danger {
  border-color: #c0392b;
  background: #c0392b;
  color: #fff;
}

/* ── form-grid four ── */
.form-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* ── Party grid (payer + payee side by side) ── */
.party-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.party-grid > fieldset {
  border-bottom: 0;
}

.party-grid > fieldset + fieldset {
  border-left: 1px solid var(--line);
}

/* ── Compact PND row ── */
.pnd-compact-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.seq-label {
  min-width: 110px;
  flex-shrink: 0;
}

.pnd-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.pnd-radios label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  color: var(--ink);
  background: var(--surface-soft);
  cursor: pointer;
  white-space: nowrap;
}

.pnd-radios input[type="radio"] {
  width: 12px;
  height: 12px;
  padding: 0;
  flex-shrink: 0;
}

/* ── Income line: 4-column inline row ── */
.line-fields-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.line-card header label {
  flex: 1;
  gap: 3px;
}

/* ── Responsive ── */
@media (max-width: 760px) {
  .form-grid.two,
  .form-grid.three,
  .form-grid.four,
  .checkbox-grid,
  .checkbox-grid.compact,
  .party-grid,
  .line-fields-row {
    grid-template-columns: 1fr;
  }

  .preview-frame {
    padding: 8px;
  }
}

/* ── Print ── */
@page {
  size: A4;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .no-print,
  .sidebar,
  .sidebar-toggle,
  .topbar,
  .button-row,
  .input-panel,
  .preview-modal-backdrop,
  .preview-modal-header,
  nav,
  aside {
    display: none !important;
  }

  html,
  body {
    height: 297mm;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  .app-shell,
  .main-area,
  .document-grid,
  .preview-modal,
  .preview-modal-panel,
  .preview-frame,
  .print-stage {
    display: block;
    position: static;
    margin: 0;
    padding: 0;
    width: auto;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  .wht-sheet {
    width: 210mm;
    height: 297mm;
    min-height: 0;
    max-height: 297mm;
    padding: 6mm 7mm;
    box-shadow: none;
    overflow: hidden;
    page-break-after: avoid;
    break-after: avoid;
  }
}
