:root {
  --theme: #000000;
  --accent: #0d5c2a;
  --paper: #ffffff;
  --ink: #111111;
  --muted: #555555;
  --panel: #f3f5f7;
  --line: #dedede;
  --font-doc: "Courier New", Courier, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #dfe4ea;
  font-family: Arial, Helvetica, sans-serif;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.controls {
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid #cfd6dd;
  border-radius: 8px;
  background: var(--paper);
  padding: 20px;
  box-shadow: 0 18px 50px rgba(20, 28, 38, 0.14);
}

.controls__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.primary-action,
.secondary-action {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.primary-action {
  flex: 0 0 auto;
  background: var(--theme);
  color: #ffffff;
  padding: 11px 14px;
}

.secondary-action {
  width: 100%;
  margin-top: 10px;
  border: 1px solid #bbc4ce;
  background: #ffffff;
  color: #1f2933;
  padding: 10px 12px;
}

.control-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d0d8;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  padding: 9px 10px;
}

input[type="color"] {
  min-height: 38px;
  padding: 4px;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

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

details {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
}

summary {
  cursor: pointer;
  font-weight: 800;
  margin-bottom: 12px;
}

.items-editor {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 64px 92px 34px;
  gap: 8px;
  align-items: end;
}

.remove-item {
  width: 34px;
  height: 38px;
  border: 1px solid #c8d0d8;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.preview-panel {
  overflow: auto;
  padding: 8px;
}

.document {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  padding: 54px 80px 44px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-doc);
  font-size: 13.5px;
  line-height: 1.34;
  box-shadow: 0 18px 60px rgba(20, 28, 38, 0.22);
}

.document__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 40px;
  margin-bottom: 38px;
}

.brand-block {
  width: 124px;
  height: 124px;
  display: grid;
  place-items: center;
}

#logoPreview {
  display: none;
  max-width: 124px;
  max-height: 124px;
  object-fit: contain;
}

.logo-fallback {
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  border: 5px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 40px;
  font-weight: 800;
}

.document h2 {
  margin: 24px 0 0;
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 0;
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 40px;
  margin-bottom: 30px;
}

.meta-row p,
.client-block span,
.project-row p,
.document__footer p {
  margin: 0 0 6px;
}

.client-block {
  display: grid;
  gap: 4px;
  margin-bottom: 40px;
}

.rule {
  width: 100%;
  background: var(--theme);
}

.rule--heavy {
  height: 15px;
}

.project-row {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 10px;
  margin: 24px 0 48px;
}

.project-row p {
  max-width: 500px;
}

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

.items-table th,
.items-table td {
  padding: 0 12px 20px 12px;
  text-align: left;
  vertical-align: top;
}

.items-table th {
  padding-bottom: 18px;
  font-weight: 800;
}

.items-table th:nth-child(1),
.items-table td:nth-child(1) {
  width: 58%;
  padding-left: 12px;
}

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

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

.items-table thead {
  border-bottom: 1px solid var(--theme);
}

.items-table tbody tr:first-child td {
  padding-top: 22px;
}

.items-table tbody {
  border-bottom: 1px solid var(--theme);
}

.totals-row {
  display: grid;
  grid-template-columns: 1fr 300px;
  margin-top: 18px;
  margin-bottom: 46px;
}

.totals-row dl {
  margin: 0;
}

.totals-row dl > div {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  align-items: center;
}

.totals-row dt {
  font-weight: 800;
  color: #4a4a4a;
}

.totals-row dd {
  margin: 0;
  text-align: right;
}

.grand-total dd {
  background: var(--theme);
  color: #ffffff;
  font-weight: 800;
  padding: 2px 10px;
}

.footer-rule {
  margin-bottom: 24px;
}

.document__footer {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 50px;
}

.document__footer strong {
  display: inline;
  font-weight: 800;
}

.signature {
  padding-top: 2px;
}

.signature span {
  display: block;
  height: 42px;
  border-bottom: 1px solid var(--theme);
}

.signature em {
  display: block;
}

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

  .controls {
    max-height: none;
  }
}

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

  .controls__header,
  .control-grid,
  .form-grid,
  .item-row {
    grid-template-columns: 1fr;
  }

  .controls__header {
    display: grid;
  }

  .document {
    transform: scale(0.55);
    transform-origin: top left;
    margin-right: -360px;
    margin-bottom: -500px;
  }
}

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

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

  .controls {
    display: none;
  }

  .app-shell,
  .preview-panel {
    display: block;
    padding: 0;
  }

  .document {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 21.5mm 21mm 17mm;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
