:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --ink: #000000d9;
  --muted: #00000073;
  --line: #d9d9d9;
  --soft-line: #f0f0f0;
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --danger: #ff4d4f;
  --success: #52c41a;
  --warning: #faad14;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  min-height: 32px;
  padding: 4px 15px;
  white-space: nowrap;
}

button:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgb(5 145 255 / 10%);
  outline: none;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.secondary,
.ant-button,
.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary:hover,
.ant-button:hover,
.ghost:hover {
  border-color: var(--primary-hover);
  color: var(--primary-hover);
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  align-items: center;
  display: flex;
  margin: 0 auto 16px;
  max-width: 1320px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand img {
  border-radius: 4px;
  height: 40px;
  object-fit: cover;
  width: 64px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.brand p {
  color: var(--muted);
  margin: 4px 0 0;
}

.workspace {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(720px, 900px) minmax(320px, 390px);
  justify-content: center;
  margin: 0 auto;
  max-width: 1320px;
}

.editor-pane {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
  min-width: 0;
  padding: 40px 48px;
}

.reference-pane {
  min-width: 0;
}

.form-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 32px;
  text-align: center;
}

.divider-title {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 24px 0 16px;
  position: relative;
}

.divider-title::before {
  border-top: 1px solid #000;
  content: "";
  left: 0;
  position: absolute;
  right: 0;
  top: 50%;
}

.divider-title > span {
  background: #fff;
  color: #000;
  font-weight: 700;
  padding-right: 12px;
  position: relative;
  z-index: 1;
}

.stamp-tools {
  align-items: center;
  background: #fff;
  display: flex;
  gap: 8px;
  padding-left: 12px;
  position: relative;
  z-index: 1;
}

.stamp-tools .ant-button {
  font-size: 12px;
  min-height: 28px;
  padding: 2px 10px;
}

.stamp-tools .is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.stamp-size-control {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 6px;
}

.stamp-size-control input {
  border: 0;
  box-shadow: none;
  min-height: auto;
  padding: 0;
  width: 92px;
}

.stamp-size-control input:focus {
  border-color: transparent;
  box-shadow: none;
}

.stamp-size-control output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}

.form-strip {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 8px;
}

label {
  color: var(--ink);
  display: grid;
  gap: 8px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 32px;
  padding: 4px 11px;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

.invoice-paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 16px;
  padding: 24px;
}

.invoice-head {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr 240px;
  min-height: 132px;
}

.company-block {
  font-weight: 700;
  min-height: 132px;
  position: relative;
}

.company-block .stamp {
  height: auto;
  left: 0;
  object-fit: contain;
  opacity: 0.85;
  pointer-events: none;
  position: absolute;
  touch-action: none;
  top: -42px;
  width: 150px;
}

.invoice-paper.stamp-editing {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgb(22 119 255 / 10%);
}

.invoice-paper.stamp-editing .company-block .stamp {
  cursor: grab;
  outline: 1px dashed var(--primary);
  outline-offset: 3px;
  pointer-events: auto;
}

.invoice-paper.stamp-editing .company-block .stamp.is-dragging {
  cursor: grabbing;
  opacity: 0.95;
}

.company-block p {
  margin: 56px 0 6px;
  position: relative;
}

.company-block textarea {
  background: transparent;
  border-color: transparent;
  font-weight: 700;
  min-height: 48px;
  padding-left: 0;
  position: relative;
}

.company-block textarea:focus {
  border-color: var(--line);
}

.invoice-title {
  position: relative;
  text-align: center;
}

.invoice-title h2 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.invoice-title img {
  height: auto;
  margin-top: 8px;
  width: 160px;
}

.invoice-meta {
  display: grid;
  gap: 32px;
  grid-template-columns: 1fr 300px;
  margin-top: 18px;
}

.bill-to {
  font-weight: 700;
}

.bill-to span {
  display: block;
  margin-bottom: 8px;
}

.bill-to input,
.bill-to textarea {
  border-color: transparent;
  font-weight: 700;
  padding-left: 0;
}

.bill-to input:focus,
.bill-to textarea:focus {
  border-color: var(--line);
}

.date-grid {
  display: grid;
  gap: 10px;
}

.date-grid label {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 110px 1fr;
}

.line-items {
  margin-top: 24px;
}

.table-head,
.item-row,
.table-total {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 140px 24px;
}

.table-head {
  border-bottom: 1px solid #000;
  font-weight: 700;
  padding-bottom: 8px;
}

.table-head span:last-child {
  grid-column: 2 / 4;
  text-align: right;
}

.rows {
  display: grid;
}

.item-row {
  border-bottom: 1px solid #eee;
  padding: 8px 0;
}

.item-row input:first-child {
  border-color: transparent;
  font-weight: 700;
  min-width: 0;
  padding-left: 0;
}

.item-row input:first-child:focus {
  border-color: var(--line);
}

.item-row input.amount {
  font-weight: 700;
  text-align: right;
}

.icon-button {
  background: transparent;
  border: 0;
  color: var(--danger);
  font-size: 18px;
  line-height: 1;
  min-height: 32px;
  padding: 0;
}

.icon-button:hover {
  color: #ff7875;
}

.line-add {
  background: transparent;
  border: 0;
  color: var(--primary);
  display: inline-flex;
  font-size: 20px;
  margin: 8px 0 4px;
  min-height: 32px;
  padding: 0;
  width: fit-content;
}

.line-add:hover {
  color: var(--primary-hover);
}

.table-total {
  align-items: center;
  border-top: 2px solid #000;
  font-weight: 700;
  margin-top: 8px;
  padding-top: 8px;
}

.table-total strong {
  grid-column: 2 / 4;
  text-align: right;
}

.bank-block {
  margin-top: 24px;
}

.bank-block dl {
  display: grid;
  gap: 4px;
  margin: 0;
}

.bank-block div {
  display: grid;
  gap: 16px;
  grid-template-columns: 130px 1fr;
}

.bank-block dt {
  color: var(--ink);
}

.bank-block dd {
  margin: 0;
}

.claim-sheet,
.reference-pane section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.claim-sheet {
  margin-top: 16px;
  padding: 16px;
}

.section-title {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.section-title span {
  color: var(--muted);
}

.claim-grid {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1.3fr) minmax(92px, 0.7fr) minmax(92px, 0.7fr) minmax(112px, 0.8fr) minmax(140px, 1fr) 24px;
}

.claim-grid-head {
  border-bottom: 1px solid var(--soft-line);
  color: var(--muted);
  font-size: 12px;
  padding-bottom: 8px;
}

.claim-row {
  border-bottom: 1px solid var(--soft-line);
  padding: 8px 0;
}

.readonly-cell {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.claim-total {
  display: flex;
  gap: 18px;
  justify-content: flex-end;
  padding-top: 12px;
}

.claim-total span {
  color: var(--muted);
}

.claim-total strong {
  color: var(--ink);
}

.submit-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 32px;
}

.submit-row button {
  height: 50px;
  font-size: 16px;
  font-weight: 600;
}

.submit-row .secondary {
  width: 132px;
}

.submit-main {
  border-radius: 8px;
  width: 240px;
}

.reference-pane {
  align-content: start;
  display: grid;
  gap: 16px;
}

.reference-pane section {
  box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
  padding: 14px;
}

.reference-list {
  display: grid;
  gap: 10px;
  max-height: 275px;
  overflow: auto;
}

.reference-item {
  border: 1px solid var(--soft-line);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.reference-item strong {
  font-size: 14px;
}

.reference-item dl {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
  margin: 0;
}

.reference-item dt {
  color: var(--muted);
  font-size: 12px;
}

.reference-item dd {
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.badge {
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 12px;
  justify-content: center;
  padding: 3px 8px;
  width: fit-content;
}

.badge.green {
  background: var(--success);
}

.badge.amber {
  background: var(--warning);
}

.badge.red {
  background: var(--danger);
}

#resultBox {
  background: #141414;
  border-radius: 6px;
  color: #f5f5f5;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
  max-height: 410px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.warning {
  border-color: var(--warning) !important;
}

.is-negative {
  color: #d92d20 !important;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(0, 900px);
  }

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

  .reference-pane section:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 12px;
  }

  .editor-pane {
    padding: 28px 18px;
  }

  .form-strip,
  .invoice-head,
  .invoice-meta,
  .reference-pane {
    grid-template-columns: 1fr;
  }

  .date-grid label {
    grid-template-columns: 1fr;
  }

  .invoice-paper {
    padding: 18px;
  }

  .company-block {
    padding-top: 116px;
  }

  .company-block .stamp {
    top: 0;
    width: 118px;
  }

  .company-block p {
    margin-top: 0;
  }

  .table-head,
  .item-row,
  .table-total {
    grid-template-columns: minmax(0, 1fr) 120px 24px;
  }

  .claim-grid {
    grid-template-columns: 1fr;
  }

  .claim-grid-head {
    display: none;
  }

  .bank-block div {
    grid-template-columns: 1fr;
  }

  .submit-row {
    flex-wrap: wrap;
  }
}
