.builder {
  padding-top:54px;
  padding-bottom:80px;
  --max:1440px;
}
.builder-heading {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:24px;
  margin-bottom:38px;
}
.builder-heading h1 {
  font-size:clamp(2.6rem,5vw,4.5rem);
  line-height:1.05;
  margin:15px 0;
  letter-spacing:-.055em;
}
.builder-heading h1 span {
  color:var(--lime);
}
.builder-heading p,.back-link {
  color:var(--muted);
}
button,input,textarea,select {
  font:inherit;
}
button {
  cursor:pointer;
  border:0;
}
button:disabled {
  cursor:default;
}
button:focus-visible,a:focus-visible {
  outline:3px solid var(--lime);
  outline-offset:4px;
}
.primary,.secondary {
  font-size:.88rem;
  font-weight:750;
  border-radius:5px;
  padding:13px 18px;
}
.primary {
  background:var(--lime);
  color:#17191d;
  white-space:nowrap;
}
.primary:hover {
  background:#ffb664;
}
.secondary {
  background:var(--surface2);
  color:var(--text);
  border:1px solid var(--line);
}
.text-button {
  background:none;
  color:var(--lime);
  padding:8px;
  font-size:.8rem;
}
.workspace {
  display:grid;
  grid-template-columns:minmax(310px,.85fr) minmax(0,1.25fr);
  align-items:start;
  gap:34px;
}
.editor {
  padding:26px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:8px;
}
.editor-heading {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.editor h2 {
  font-size:1.2rem;
  letter-spacing:-.02em;
  line-height:1.4;
}
.hint {
  font-size:.78rem;
  color:var(--muted);
  line-height:1.6;
}
.editor fieldset {
  border:0;
  border-top:1px solid var(--line);
  padding:24px 0 14px;
  margin:24px 0 0;
  min-width:0;
}
.editor legend {
  padding:0 10px 0 0;
  color:var(--lime);
  font:700 .7rem ui-monospace,monospace;
  letter-spacing:.08em;
  text-transform:uppercase;
}
.editor label {
  display:flex;
  flex-direction:column;
  gap:7px;
  font-size:.78rem;
  color:var(--muted);
  margin-bottom:16px;
  min-width:0;
}
.editor input,.editor textarea,.editor select {
  width:100%;
  min-width:0;
  background:var(--bg);
  border:1px solid #4b535e;
  border-radius:4px;
  color:var(--text);
  padding:10px 11px;
  font-size:.88rem;
  color-scheme:dark;
}
.editor input:focus,.editor textarea:focus,.editor select:focus {
  outline:2px solid var(--lime);
  outline-offset:1px;
}
.editor textarea {
  resize:vertical;
  min-height:75px;
}
.field-grid {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:0 14px;
}
.item {
  border:1px solid var(--line);
  border-radius:5px;
  padding:14px;
  margin-bottom:14px;
}
.item-heading {
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:10px;
  font-size:.72rem;
  color:var(--muted);
}
.remove-item {
  background:transparent;
  color:#ffb297;
  padding:5px;
  font-size:.75rem;
}
.remove-item:disabled {
  opacity:.4;
}
.item label:last-child {
  margin-bottom:0;
}
.editor-total {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:22px 0 0;
  font-size:.85rem;
}
.editor-total strong {
  font-size:1.3rem;
}
.export-button {
  width:100%;
}
.preview-heading {
  display:flex;
  justify-content:space-between;
  gap:12px;
  font:700 .65rem ui-monospace,monospace;
  letter-spacing:.1em;
  color:var(--muted);
  margin:0 0 14px;
}
.invoice {
  background:#fff;
  color:#25303b;
  box-shadow:0 12px 44px #0003;
  padding:clamp(24px,3.5vw,50px);
  font:14px/1.55 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  overflow-wrap:anywhere;
  border-top:6px solid #e68b30;
}
.invoice-header {
  display:flex;
  justify-content:space-between;
  align-items:start;
  gap:24px;
  padding-bottom:30px;
  border-bottom:1px solid #dde2e7;
}
.document-label {
  color:#926024;
  font-size:11px;
  letter-spacing:.25em;
  font-weight:800;
  margin-bottom:14px;
}
.invoice h2 {
  font-size:26px;
  line-height:1.2;
  letter-spacing:-.04em;
}
.invoice-id {
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:10px;
  text-align:right;
  max-width:45%;
}
.invoice-id strong {
  font-size:13px;
}
.badge {
  padding:4px 10px;
  border-radius:3px;
  background:#f2f3f5;
  color:#525b65;
  font-size:10px;
  text-transform:uppercase;
  letter-spacing:.08em;
  font-weight:800;
}
.badge.paid {
  background:#e6f4eb;
  color:#27623e;
}
.invoice h3 {
  font-size:9px;
  letter-spacing:.13em;
  color:#64707c;
  margin:0 0 8px;
  font-weight:800;
}
.invoice p {
  margin:0;
  white-space:pre-wrap;
}
.invoice-parties {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:28px;
  margin:30px 0;
}
.invoice-parties p {
  margin-top:6px;
  font-size:12px;
}
.invoice-dates {
  display:flex;
  gap:50px;
  margin:26px 0;
  font-size:12px;
}
.invoice table {
  width:100%;
  border-collapse:collapse;
  table-layout:fixed;
  font-size:12px;
}
.description-col {
  width:46%;
}
.invoice th {
  text-align:right;
  background:#f3f5f7;
  color:#53606d;
  font-size:10px;
  padding:12px 7px;
}
.invoice th:first-child {
  text-align:left;
}
.invoice td {
  vertical-align:top;
  text-align:right;
  padding:15px 7px;
  border-bottom:1px solid #e5e8ec;
  font-variant-numeric:tabular-nums;
}
.invoice td:first-child {
  text-align:left;
  white-space:pre-wrap;
}
.invoice th:nth-child(2) {
  width:12%;
}
.totals {
  margin:24px 0 32px auto;
  width:65%;
  font-variant-numeric:tabular-nums;
}
.totals>div {
  display:flex;
  justify-content:space-between;
  gap:20px;
  padding:8px 0;
}
.totals small {
  font-size:9px;
  color:#64707c;
}
.totals .balance {
  border-top:2px solid #25303b;
  margin-top:5px;
  padding-top:13px;
  font-size:17px;
}
.document-section {
  border-top:1px solid #e5e8ec;
  margin-top:20px;
  padding-top:16px;
  font-size:12px;
}
.screen-only .footer {
  display:flex;
  flex-wrap:wrap;
  gap:12px;
}
.invoice-footer {
  color:#78828b;
  font-size:10px;
  border-top:1px solid #e5e8ec;
  margin-top:40px;
  padding-top:16px;
}
.editor [hidden],.invoice [hidden] {
  display:none;
}
@media(min-width:1150px) {
  .preview-column {
    position:sticky;
    top:96px;
  }
}
@media(max-width:950px) {
  .workspace {
    grid-template-columns:1fr;
  }
  .preview-column {
    max-width:800px;
    width:100%;
    margin:auto;
  }
  .builder-heading {
    align-items:start;
  }
  .builder-heading>.primary {
    margin-top:15px;
  }
}
@media(max-width:520px) {
  .builder-heading {
    display:block;
  }
  .builder-heading>.primary {
    width:100%;
  }
  .editor {
    padding:18px;
  }
  .back-link {
    font-size:.75rem;
  }
  .invoice {
    padding:22px 16px;
  }
  .invoice h2 {
    font-size:21px;
  }
  .invoice table {
    font-size:10px;
  }
  .invoice th,.invoice td {
    padding:10px 4px;
  }
  .totals {
    width:80%;
  }
  .totals .balance {
    font-size:15px;
  }
  .preview-heading {
    font-size:.6rem;
  }
  .field-grid {
    gap:0 10px;
  }
}
@page {
  size:auto;
  margin:16mm;
}
@media print {
  html,body {
    background:#fff;
    color:#25303b;
    margin:0;
    padding:0;
  }
  .screen-only {
    display:none!important;
  }
  .builder {
    width:100%;
    max-width:none;
    padding:0;
    margin:0;
  }
  .workspace {
    display:block;
  }
  .preview-column {
    position:static;
    max-width:none;
  }
  .invoice {
    box-shadow:none;
    border-top:5px solid #e68b30;
    padding:20px 0 0;
    font-size:11pt;
    print-color-adjust:exact;
    -webkit-print-color-adjust:exact;
  }
  .invoice-header,.invoice-parties,.invoice-dates,.totals,.document-section,.invoice-footer,tr {
    break-inside:avoid;
  }
  .invoice thead {
    display:table-header-group;
  }
  .invoice table {
    font-size:10pt;
  }
  .invoice h2 {
    font-size:24pt;
  }
  .invoice-parties p,.document-section {
    font-size:10pt;
  }
  .invoice th {
    font-size:8pt;
  }
  .invoice-footer {
    font-size:8pt;
  }
  .invoice-dates {
    font-size:10pt;
  }
  .invoice p,.invoice td {
    overflow-wrap:anywhere;
  }
  .invoice .document-section {
    break-inside:auto;
  }
}
/* Keep ordinary invoices on one sheet while allowing long tables to paginate. */
@media print {
  .invoice {
    font-size: 10pt;
  }
  .invoice-header {
    padding-bottom: 20px;
  }
  .invoice-parties {
    margin: 20px 0;
  }
  .invoice-dates {
    margin: 20px 0;
  }
  .invoice th {
    padding: 9px 6px;
  }
  .invoice td {
    padding: 11px 6px;
  }
  .totals {
    margin-top: 18px;
    margin-bottom: 22px;
  }
  .document-section {
    margin-top: 15px;
    padding-top: 12px;
  }
  .invoice-footer {
    margin-top: 24px;
    padding: 12px 0 0;
  }
}

.invoice-brand { min-width: 0; }
.invoice-logo {
  display: block;
  width: auto;
  height: auto;
  max-width: min(180px, 100%);
  max-height: 72px;
  object-fit: contain;
  object-position: left center;
  margin-bottom: 18px;
}
.primary:disabled { opacity: .6; cursor: wait; }
@media print {
  .invoice-logo { max-width: 150px; max-height: 60px; margin-bottom: 12px; }
}
