:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #6f6b66;
  --line: #dedbd6;
  --panel: #ffffff;
  --canvas: #e8e7e4;
  --soft: #f6f5f2;
  --red: #b51f2e;
  --red-dark: #8f1722;
  --green: #20715a;
  --shadow: 0 18px 45px rgba(24, 22, 20, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--soft);
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

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

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 86px;
  padding: 14px 24px;
  border-bottom: 1px solid #d9d6d0;
  background: rgba(250, 249, 247, 0.97);
}

.app-header > div:first-child {
  min-width: 0;
}

.app-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.app-header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.08;
}

.app-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  margin-left: 24px;
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

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

.button-primary:hover {
  background: var(--red-dark);
}

.button-secondary {
  color: #fff;
  background: #232323;
}

.button-secondary:hover {
  background: #000;
}

.button-ghost {
  border-color: #cfcac2;
  color: #3f3c38;
  background: transparent;
}

.button-ghost:hover {
  background: #efede9;
}

.history-view {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 44px 0 32px;
}

.history-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  padding: 0 4px 26px;
}

.history-eyebrow {
  display: block;
  margin-bottom: 9px;
  color: var(--red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.history-hero h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
}

.history-hero p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.history-create-button {
  min-height: 44px;
  white-space: nowrap;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.history-stats article {
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.history-stats span,
.history-stats small {
  display: block;
}

.history-stats span {
  color: #615c56;
  font-size: 11px;
  font-weight: 700;
}

.history-stats strong {
  display: block;
  margin: 8px 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 31px;
  line-height: 1;
}

.history-stats strong.history-latest {
  font-family: inherit;
  font-size: 17px;
  line-height: 1.18;
}

.history-stats small {
  color: #8a847d;
  font-size: 10px;
}

.history-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 12px 35px rgba(24, 22, 20, 0.06);
  overflow: hidden;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.history-toolbar h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
}

.history-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.history-filters {
  display: flex;
  gap: 8px;
}

.history-search input,
.history-filter select {
  height: 38px;
  border: 1px solid #cbc7c1;
  border-radius: 7px;
  outline: none;
  color: #26231f;
  background: #fff;
  font-size: 12px;
}

.history-search input {
  width: min(280px, 36vw);
  padding: 0 12px;
}

.history-filter select {
  min-width: 116px;
  padding: 0 30px 0 10px;
}

.history-search input:focus,
.history-filter select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(181, 31, 46, 0.1);
}

.history-list {
  min-height: 120px;
}

.history-record {
  display: grid;
  grid-template-columns: minmax(205px, 1.4fr) minmax(120px, 0.7fr) minmax(130px, 0.75fr) minmax(125px, 0.7fr) auto;
  gap: 20px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid #ebe8e3;
}

.history-record:last-child {
  border-bottom: 0;
}

.history-record:hover {
  background: #fbfaf8;
}

.history-record-identity,
.history-record-meta {
  min-width: 0;
}

.history-record-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.history-status {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 0 8px;
  border-radius: 999px;
  color: #755b22;
  background: #fff2cf;
  font-size: 9px;
  font-weight: 800;
}

.history-status.is-issued {
  color: #16604b;
  background: #e3f4ed;
}

.history-record-number {
  color: #817b74;
  font-size: 10px;
  font-weight: 700;
}

.history-record-identity > strong {
  display: block;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-record-identity > small {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #817b74;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-record-meta span {
  display: block;
  margin-bottom: 5px;
  color: #8a847d;
  font-size: 9px;
  font-weight: 700;
}

.history-record-meta strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.history-record-total strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
}

.history-record-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.history-action {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #d5d0c9;
  border-radius: 7px;
  color: #49443f;
  background: #fff;
  font-size: 10px;
  font-weight: 700;
}

.history-action:hover {
  border-color: #918981;
  background: #f5f3ef;
}

.history-action.is-primary {
  border-color: var(--red);
  color: #fff;
  background: var(--red);
}

.history-action.is-primary:hover {
  background: var(--red-dark);
}

.history-action.is-danger:hover {
  border-color: var(--red);
  color: var(--red);
  background: #fff7f7;
}

.history-empty {
  display: grid;
  min-height: 330px;
  padding: 48px 20px;
  place-items: center;
  text-align: center;
}

.history-empty img {
  width: 64px;
  height: 48px;
  object-fit: contain;
}

.history-empty h3 {
  margin: 16px 0 7px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
}

.history-empty p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.history-privacy-note {
  margin: 16px 2px 0;
  color: #847e77;
  font-size: 10px;
  text-align: center;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(760px, 1fr);
  min-height: calc(100vh - 86px);
}

.editor-panel {
  z-index: 2;
  padding: 22px 20px 60px;
  border-right: 1px solid #d5d1cb;
  background: #fff;
}

.editor-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 2px;
}

.editor-intro span {
  display: block;
  color: var(--red);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.editor-intro strong {
  display: block;
  margin-top: 3px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
}

.editor-intro p {
  margin: 0 0 2px 12px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.editor-intro p.is-saved {
  color: var(--green);
}

.form-section {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.form-section summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  list-style: none;
  user-select: none;
}

.form-section summary::-webkit-details-marker {
  display: none;
}

.form-section summary::after {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid #77716a;
  border-bottom: 1.5px solid #77716a;
  content: "";
  transform: rotate(45deg);
}

.form-section:not([open]) summary::after {
  transform: rotate(-45deg);
}

.form-section summary > span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--red);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.form-section summary strong {
  font-size: 13px;
}

.field-grid {
  display: grid;
  gap: 12px;
  padding: 4px 14px 16px;
}

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

.field-span-2 {
  grid-column: 1 / -1;
}

.field {
  display: block;
  min-width: 0;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  color: #625e58;
  font-size: 10px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #cbc7c1;
  border-radius: 7px;
  outline: none;
  color: #1c1b19;
  background: #fff;
  font-size: 12px;
  line-height: 1.35;
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(181, 31, 46, 0.1);
}

.money-input {
  position: relative;
}

.money-input > span {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 11px;
  color: var(--muted);
  font-size: 12px;
  transform: translateY(-50%);
}

.money-input input {
  padding-left: 28px;
}

.line-items-editor {
  padding: 2px 14px 8px;
}

.line-item-card {
  position: relative;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid #dedad4;
  border-radius: 8px;
  background: #faf9f7;
}

.line-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.line-item-head strong {
  color: var(--red);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.remove-line-button {
  display: grid;
  width: 25px;
  height: 25px;
  padding: 0;
  place-items: center;
  border: 1px solid #d2cdc6;
  border-radius: 50%;
  color: #776f67;
  background: #fff;
  font-size: 16px;
  line-height: 1;
}

.remove-line-button:hover {
  border-color: var(--red);
  color: var(--red);
}

.line-item-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 10px;
}

.line-field-full {
  grid-column: 1 / -1;
}

.line-item-grid .field > span {
  font-size: 9px;
}

.line-price-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 0.62fr 0.72fr 1fr 0.72fr;
  gap: 8px;
}

.calculated-value {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #d7d2cb;
  border-radius: 7px;
  color: #403b36;
  background: #efede9;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tax-inclusive-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 9px 11px;
  border: 1px solid #d7d2cb;
  border-radius: 8px;
  color: #4a4540;
  background: #fff;
  cursor: pointer;
}

.tax-inclusive-toggle:has(input:checked) {
  border-color: var(--red);
  background: #fff7f7;
  box-shadow: inset 3px 0 0 var(--red);
}

.tax-inclusive-toggle input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--red);
}

.tax-inclusive-toggle span {
  min-width: 0;
}

.tax-inclusive-toggle strong,
.tax-inclusive-toggle small {
  display: block;
}

.tax-inclusive-toggle strong {
  font-size: 11px;
}

.tax-inclusive-toggle small {
  margin-top: 2px;
  color: #77716a;
  font-size: 9px;
  line-height: 1.35;
}

.add-line-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% - 28px);
  min-height: 38px;
  margin: 0 14px 14px;
  border: 1px dashed #b8b2aa;
  border-radius: 8px;
  color: #4f4a44;
  background: #fff;
  font-size: 11px;
  font-weight: 700;
}

.add-line-button span {
  margin-right: 7px;
  color: var(--red);
  font-size: 17px;
}

.add-line-button:hover {
  border-color: var(--red);
  color: var(--red);
  background: #fffafa;
}

.preview-panel {
  min-width: 0;
  background: var(--canvas);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  padding: 0 22px;
  border-bottom: 1px solid #d0cdc8;
  color: #595550;
  background: #f0efec;
  font-size: 11px;
  font-weight: 700;
}

.preview-toolbar span {
  display: flex;
  align-items: center;
}

.preview-toolbar i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--green);
}

.preview-toolbar button {
  padding: 6px 9px;
  border: 1px solid #c9c5bf;
  border-radius: 6px;
  color: #5e5953;
  background: #fff;
  font-size: 10px;
  font-weight: 700;
}

.paper-stage {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: calc(100vh - 132px);
  padding: 28px 24px 70px;
  overflow: auto;
}

.invoice-paper {
  position: relative;
  flex: 0 0 auto;
  width: 210mm;
  min-height: 297mm;
  padding: 11mm 16mm 17mm;
  color: #171513;
  background: #fff;
  box-shadow: var(--shadow);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 8.2pt;
  line-height: 1.38;
  transform-origin: top center;
}

.invoice-letterhead {
  display: flex;
  align-items: center;
  flex-direction: column;
  min-height: 38mm;
  color: #111;
  text-align: center;
}

.invoice-letterhead img {
  width: 20mm;
  height: 12mm;
  margin-bottom: 4.3mm;
  object-fit: contain;
}

.invoice-letterhead strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11pt;
}

.invoice-letterhead span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 8.2pt;
  line-height: 1.22;
}

.invoice-title-block {
  display: grid;
  grid-template-columns: 1fr 68mm;
  gap: 10mm;
  align-items: end;
  padding: 4.5mm 0 4mm;
  border-top: 0.7mm solid var(--red);
  border-bottom: 0.25mm solid #8f8a84;
}

.invoice-title-block > div > span {
  color: var(--red);
  font-size: 6.8pt;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.invoice-title-block h2 {
  margin: 1.2mm 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21pt;
  line-height: 1;
}

.invoice-title-block p {
  margin: 1mm 0 0;
  color: #5e5954;
  font-size: 8pt;
  font-weight: 700;
  letter-spacing: 0.15em;
}

.document-meta {
  display: grid;
  gap: 1.2mm;
  margin: 0;
}

.document-meta > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4mm;
  align-items: baseline;
}

.document-meta dt {
  color: #68625c;
  font-size: 7pt;
}

.document-meta dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7mm;
  min-height: 37mm;
  padding: 5mm 0 4mm;
}

.supplier-card,
.customer-card {
  padding: 3.5mm 4mm;
  border: 0.25mm solid #d7d3ce;
}

.customer-card {
  border-top: 0.7mm solid var(--red);
}

.section-label {
  display: block;
  margin-bottom: 2mm;
  color: var(--red);
  font-size: 6.7pt;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.supplier-card strong,
.customer-card strong {
  display: block;
  margin-bottom: 1.3mm;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 9.4pt;
}

.supplier-card p,
.customer-card p {
  margin: 0.8mm 0 0;
  color: #4c4844;
  white-space: pre-line;
}

.placeholder-text {
  color: #aaa49d;
}

.reference-row {
  display: grid;
  grid-template-columns: 43mm 1fr;
  gap: 4mm;
  margin-bottom: 3mm;
  padding: 2.3mm 3mm;
  background: #f3f1ed;
}

.reference-row span {
  color: #6b655f;
  font-size: 7pt;
}

.reference-row strong {
  font-size: 7.5pt;
}

.invoice-lines table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.description-col {
  width: 42%;
}

.quantity-col {
  width: 8%;
}

.unit-col {
  width: 10%;
}

.price-col {
  width: 14%;
}

.vat-col {
  width: 9%;
}

.amount-col {
  width: 17%;
}

.invoice-lines th {
  padding: 2.7mm 2mm;
  border-bottom: 0.45mm solid #26221f;
  color: #fff;
  background: #26221f;
  font-size: 6.6pt;
  font-weight: 700;
  text-align: right;
}

.invoice-lines th:first-child {
  text-align: left;
}

.invoice-lines td {
  padding: 3mm 2mm;
  border-bottom: 0.25mm solid #dedad5;
  vertical-align: top;
  text-align: right;
}

.invoice-lines td:first-child {
  text-align: left;
}

.invoice-lines td strong {
  display: block;
  margin-bottom: 0.7mm;
  font-size: 8.1pt;
  overflow-wrap: anywhere;
}

.invoice-lines td small {
  display: block;
  color: #6f6963;
  font-size: 6.9pt;
  line-height: 1.35;
  white-space: pre-line;
}

.invoice-lines tr.is-empty td {
  height: 15mm;
  color: #aca69f;
}

.invoice-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 67mm;
  gap: 10mm;
  margin-top: 6mm;
}

.payment-details {
  min-width: 0;
  padding-top: 1mm;
}

.payment-details dl {
  display: grid;
  grid-template-columns: 25mm 1fr;
  gap: 1.2mm 3mm;
  margin: 0;
}

.payment-details dt {
  color: #6a655f;
  font-size: 6.8pt;
}

.payment-details dd {
  min-width: 0;
  margin: 0;
  font-size: 7.3pt;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.invoice-notes {
  margin-top: 5mm;
}

.invoice-notes p {
  margin: 0;
  color: #57524d;
  font-size: 7pt;
  white-space: pre-line;
}

.invoice-summary {
  margin: 0;
}

.invoice-summary > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5mm;
  padding: 1.8mm 0;
  border-bottom: 0.25mm solid #ddd8d2;
}

.invoice-summary dt {
  color: #5b5650;
  font-size: 7.2pt;
}

.invoice-summary dd {
  margin: 0;
  font-size: 7.7pt;
  font-weight: 700;
  text-align: right;
}

.invoice-summary .summary-total {
  margin-top: 1.6mm;
  padding: 3mm;
  border: 0;
  color: #fff;
  background: var(--red);
}

.invoice-summary .summary-total dt {
  color: #fff;
  font-size: 8.4pt;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.invoice-summary .summary-total dd {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12pt;
}

.legal-note {
  margin: 8mm 0 0;
  padding-top: 2.2mm;
  border-top: 0.25mm solid #cfcac4;
  color: #7b746e;
  font-size: 6.3pt;
  text-align: center;
}

.invoice-footer {
  position: absolute;
  right: 16mm;
  bottom: 7mm;
  left: 16mm;
  display: flex;
  align-items: center;
  flex-direction: column;
  color: #2e2b28;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 6.5pt;
  line-height: 1.2;
  text-align: center;
}

.invoice-footer strong {
  font-size: 7.4pt;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 11px 14px;
  border-radius: 8px;
  color: #fff;
  background: #24211e;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: var(--red-dark);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 390px minmax(720px, 1fr);
  }

  .paper-stage {
    justify-content: flex-start;
  }
}

@media (max-width: 840px) {
  .app-header {
    position: relative;
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
  }

  .header-actions {
    width: 100%;
    margin: 0;
  }

  .header-actions .button {
    flex: 1;
    min-width: 0;
    padding: 0 8px;
  }

  .history-view {
    width: min(100% - 28px, 680px);
    padding-top: 28px;
  }

  .history-hero {
    align-items: flex-start;
  }

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

  .history-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .history-filters {
    width: 100%;
  }

  .history-search {
    flex: 1;
  }

  .history-search input {
    width: 100%;
  }

  .history-record {
    grid-template-columns: minmax(0, 1.4fr) minmax(110px, 0.7fr) minmax(120px, 0.75fr);
    gap: 14px;
  }

  .history-record-updated {
    display: none;
  }

  .history-record-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .workspace {
    display: block;
  }

  .editor-panel {
    padding: 18px 14px 36px;
    border-right: 0;
  }

  .preview-toolbar {
    position: sticky;
    z-index: 4;
    top: 0;
  }

  .paper-stage {
    min-height: 0;
    padding: 16px 0 40px;
    overflow-x: auto;
  }

  .invoice-paper {
    transform: scale(0.78);
    transform-origin: top left;
  }
}

@media (max-width: 520px) {
  .app-header h1 {
    font-size: 21px;
  }

  .app-header p {
    font-size: 11px;
  }

  .button {
    font-size: 11px;
  }

  #editorHeaderActions:not([hidden]) {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .history-view {
    width: calc(100% - 24px);
    padding-top: 22px;
  }

  .history-hero {
    flex-direction: column;
    gap: 18px;
  }

  .history-hero h2 {
    font-size: 31px;
  }

  .history-create-button {
    width: 100%;
  }

  .history-stats {
    gap: 8px;
  }

  .history-stats article {
    padding: 14px;
  }

  .history-stats strong {
    font-size: 26px;
  }

  .history-filters {
    flex-direction: column;
  }

  .history-filter select {
    width: 100%;
  }

  .history-record {
    grid-template-columns: 1fr 1fr;
    gap: 14px 10px;
    padding: 16px;
  }

  .history-record-identity {
    grid-column: 1 / -1;
  }

  .history-record-total {
    text-align: right;
  }

  .history-record-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .history-action {
    padding: 0 6px;
  }

  .field-grid-2,
  .line-item-grid {
    grid-template-columns: 1fr;
  }

  .field-span-2,
  .line-field-full,
  .line-price-row {
    grid-column: 1;
  }

  .line-price-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #fff;
  }

  body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-header,
  .history-view,
  .editor-panel,
  .preview-toolbar,
  .toast {
    display: none !important;
  }

  .workspace,
  .preview-panel,
  .paper-stage {
    display: block;
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 0;
    background: #fff;
    overflow: visible;
  }

  .invoice-paper {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    box-shadow: none;
    transform: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
