:root {
  --orange: #e58b1f;
  --orange-dark: #c66d0a;
  --ink: #202020;
  --muted: #686d76;
  --line: #e7e7e7;
  --panel: #ffffff;
  --app-bg: #f2f3f5;
  --danger: #a93c32;
  --shadow: 0 18px 50px rgba(25, 28, 33, 0.12);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--app-bg);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top left, rgba(229, 139, 31, 0.09), transparent 28rem),
    var(--app-bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 3rem) 1.25rem;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--orange-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.app-header h1,
.entry-panel h2 {
  margin: 0;
  letter-spacing: -0.035em;
}

.app-header h1 {
  font-size: clamp(1.75rem, 3vw, 2.6rem);
}

.app-intro {
  max-width: 42rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.65rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.8rem;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  font-weight: 800;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
input:focus-visible,
.remove-button:focus-visible {
  outline: 3px solid rgba(229, 139, 31, 0.35);
  outline-offset: 2px;
}

.button-primary,
.button-add {
  color: #171717;
  background: var(--orange);
}

.button-primary:hover,
.button-add:hover {
  background: #f19a30;
}

.button-secondary {
  border-color: #d7d9dc;
  color: #3f444b;
  background: #fff;
}

.button-secondary:hover {
  border-color: #bfc3c8;
  background: #fafafa;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
  align-items: start;
  gap: clamp(1.25rem, 3vw, 2.5rem);
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3rem) 4rem;
}

.entry-panel {
  position: sticky;
  top: 1rem;
  padding: 1.35rem;
  border: 1px solid #e1e2e5;
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: 0 12px 35px rgba(25, 28, 33, 0.07);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.3rem;
}

.entry-panel h2 {
  font-size: 1.45rem;
}

.saved-state {
  flex: 0 0 auto;
  margin-top: 0.15rem;
  color: #4e755c;
  font-size: 0.72rem;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field span {
  color: #494e56;
  font-size: 0.78rem;
  font-weight: 800;
}

.field input {
  width: 100%;
  min-height: 2.8rem;
  padding: 0.65rem 0.72rem;
  border: 1px solid #d6d8dc;
  border-radius: 0.55rem;
  color: var(--ink);
  background: #fff;
}

.field input:hover {
  border-color: #b9bdc3;
}

.invoice-number-field,
.field-wide {
  grid-column: 1 / -1;
}

.invoice-number-field {
  margin-bottom: 0.9rem;
}

.button-add {
  width: 100%;
  margin-top: 1rem;
}

.preview-wrap {
  min-width: 0;
}

.preview-label {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.invoice {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 210mm);
  min-height: 297mm;
  margin: 0 auto;
  padding: 15mm 15mm 0;
  overflow: hidden;
  color: #202020;
  background: #fff;
  box-shadow: var(--shadow);
}

.invoice-brand {
  display: flex;
  align-items: center;
  gap: 4.5mm;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 11.5mm;
  height: 11.5mm;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--orange);
  background: #1b1b1b;
  font-size: 4.2mm;
  font-style: italic;
  font-weight: 800;
}

.brand-copy h2 {
  margin: 0 0 1.2mm;
  font-size: 4.4mm;
  line-height: 1;
  letter-spacing: 0.01em;
}

.brand-copy h2 span {
  color: var(--orange);
}

.brand-copy p {
  margin: 0;
  font-size: 2.85mm;
  font-weight: 700;
}

.brand-copy i {
  padding: 0 0.8mm;
  font-style: normal;
}

.orange-rule {
  width: 100%;
  height: 0.55mm;
  margin-top: 2.2mm;
  background: var(--orange);
}

.invoice-title {
  margin: 7.2mm 0 6.8mm;
  font-size: 5.15mm;
  line-height: 1;
  text-align: center;
  text-decoration: underline;
}

.table-wrap {
  width: 100%;
}

.invoice table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 3.18mm;
}

.col-number {
  width: 6%;
}

.col-date {
  width: 18%;
}

.col-description {
  width: 52%;
}

.col-amount {
  width: 24%;
}

.col-action {
  width: 2.2rem;
}

.invoice thead {
  color: #fff;
  background: #1d1d1d;
}

.invoice th,
.invoice td {
  overflow-wrap: anywhere;
}

.invoice thead th {
  padding: 2.5mm 2.5mm;
  border-right: 0.2mm solid #545454;
  font-size: 2.95mm;
  text-align: left;
}

.invoice thead th:first-child,
.invoice tbody td:first-child {
  text-align: center;
}

.invoice thead th:nth-child(4),
.invoice tbody td:nth-child(4),
.invoice tfoot td {
  text-align: right;
}

.invoice tbody td {
  padding: 2.2mm 2.5mm;
  border-bottom: 0.2mm solid var(--line);
  vertical-align: top;
}

.invoice tbody td:nth-child(4),
.invoice tfoot td {
  font-weight: 800;
  white-space: nowrap;
}

.invoice tfoot {
  background: #e7e7e7;
}

.invoice tfoot th,
.invoice tfoot td {
  padding: 2.45mm 2.5mm;
  font-size: 3.15mm;
}

.invoice tfoot th {
  text-align: right;
}

.row-action-heading,
.row-action-cell {
  padding-right: 0 !important;
  padding-left: 0 !important;
  background: #fff;
}

.remove-button {
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  margin: -0.18rem auto 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--danger);
  background: #f8e8e6;
  font-size: 1.05rem;
  line-height: 1;
}

.remove-button:hover {
  background: #f3d4d0;
}

.empty-row td {
  padding: 8mm 3mm !important;
  color: #777c83;
  text-align: center !important;
  font-style: italic;
  font-weight: 400 !important;
  white-space: normal !important;
}

.invoice-spacer {
  min-height: 16mm;
  flex: 1 1 15mm;
}

.signature-block {
  align-self: flex-end;
  width: 57mm;
  margin: 0 0 22mm;
  text-align: center;
}

.signature-line {
  border-top: 0.25mm dotted #858585;
}

.signature-block p {
  margin: 1.4mm 0 0;
  font-size: 2.9mm;
  font-weight: 700;
}

.invoice-footer {
  width: calc(100% + 30mm);
  min-height: 8.5mm;
  margin-left: -15mm;
  padding: 2.4mm 15mm 2mm;
  color: #111;
  background: var(--orange);
  font-size: 3mm;
  font-weight: 800;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .entry-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    gap: 1rem;
    padding-top: 1.2rem;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 0.75fr 1.25fr;
  }

  .app-layout {
    padding-right: 0;
    padding-left: 0;
  }

  .entry-panel {
    margin: 0 0.75rem;
    padding: 1.1rem;
  }

  .preview-label {
    margin-left: 0.75rem;
  }

  .invoice {
    min-height: 141vw;
    padding: 5.5vw 4vw 0;
    box-shadow: 0 8px 28px rgba(25, 28, 33, 0.1);
  }

  .invoice-brand {
    gap: 2.2vw;
  }

  .logo-mark {
    width: 8.4vw;
    height: 8.4vw;
    font-size: 3.2vw;
  }

  .brand-copy h2 {
    margin-bottom: 0.8vw;
    font-size: 3.45vw;
  }

  .brand-copy p {
    font-size: 2.05vw;
  }

  .orange-rule {
    height: 0.42vw;
    margin-top: 1.7vw;
  }

  .invoice-title {
    margin: 5vw 0 4.8vw;
    font-size: 4vw;
  }

  .invoice table {
    font-size: 2.45vw;
  }

  .invoice thead th {
    padding: 1.7vw 1.4vw;
    font-size: 2.2vw;
  }

  .invoice tbody td {
    padding: 1.5vw 1.4vw;
  }

  .invoice tfoot th,
  .invoice tfoot td {
    padding: 1.7vw 1.4vw;
    font-size: 2.35vw;
  }

  .col-number {
    width: 8%;
  }

  .col-date {
    width: 20%;
  }

  .col-description {
    width: 44%;
  }

  .col-amount {
    width: 28%;
  }

  .col-action {
    width: 1.6rem;
  }

  .remove-button {
    width: 1.25rem;
    height: 1.25rem;
    font-size: 0.9rem;
  }

  .signature-block {
    width: 43vw;
    margin-bottom: 15vw;
  }

  .signature-block p {
    font-size: 2.2vw;
  }

  .invoice-footer {
    width: calc(100% + 8vw);
    min-height: 6.2vw;
    margin-left: -4vw;
    padding: 1.65vw 4vw 1.4vw;
    font-size: 2.2vw;
  }
}

@media (max-width: 430px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  :root,
  body {
    width: 210mm;
    height: auto;
    min-width: 0;
    margin: 0;
    background: #fff;
  }

  .no-print {
    display: none !important;
  }

  .app-layout,
  .preview-wrap {
    display: block;
    width: 210mm;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .invoice {
    position: relative;
    display: block;
    width: 210mm;
    height: 296mm;
    min-height: 0;
    max-height: 296mm;
    margin: 0;
    padding: 15mm 15mm 0;
    overflow: hidden;
    box-shadow: none;
    break-after: avoid-page;
    break-inside: avoid-page;
    page-break-after: avoid;
    page-break-inside: avoid;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  /*
   * iOS Safari can keep the narrow-screen media-query values while printing.
   * Restate every invoice measurement in physical units so mobile vw sizing
   * cannot shrink the A4 output.
   */
  .invoice-brand {
    gap: 4.5mm;
  }

  .logo-mark {
    width: 11.5mm;
    height: 11.5mm;
    font-size: 4.2mm;
  }

  .brand-copy h2 {
    margin-bottom: 1.2mm;
    font-size: 4.4mm;
  }

  .brand-copy p {
    font-size: 2.85mm;
  }

  .orange-rule,
  .red-rule {
    height: 0.55mm;
    margin-top: 2.2mm;
  }

  .invoice-title {
    margin: 7.2mm 0 6.8mm;
    font-size: 5.15mm;
  }

  .invoice table {
    font-size: 3.18mm;
  }

  .invoice thead th {
    padding: 2.5mm;
    font-size: 2.95mm;
  }

  .invoice tbody td {
    padding: 2.2mm 2.5mm;
  }

  .invoice tfoot th,
  .invoice tfoot td {
    padding: 2.45mm 2.5mm;
    font-size: 3.15mm;
  }

  .invoice thead {
    display: table-header-group;
  }

  .invoice tr {
    break-inside: avoid;
  }

  .col-number {
    width: 6%;
  }

  .col-date {
    width: 18%;
  }

  .col-description {
    width: 52%;
  }

  .col-amount {
    width: 24%;
  }

  .invoice-spacer {
    display: none;
  }

  .signature-block {
    position: absolute;
    right: 15mm;
    bottom: 20mm;
    width: 57mm;
    margin: 0;
  }

  .signature-block p {
    margin-top: 1.4mm;
    font-size: 2.9mm;
  }

  .invoice-footer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    min-height: 8.5mm;
    margin: 0;
    padding: 2.4mm 15mm 2mm;
    font-size: 3mm;
  }
}
