:root {
  --bg: #eef2f1;
  --panel: #ffffff;
  --panel-soft: #f8faf8;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0dc;
  --line-strong: #b9c4bf;
  --teal: #28666e;
  --teal-dark: #1f5057;
  --gold: #b7791f;
  --green: #1f7a4d;
  --red: #b42318;
  --shadow: 0 18px 46px rgba(23, 32, 51, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(16px, 3vw, 34px);
  background: rgba(248, 250, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  line-height: 1.15;
}

.brand-lockup p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.header-actions,
.section-title-row,
.test-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink);
  background: #ffffff;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

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

.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(40, 102, 110, 0.22);
  outline-offset: 2px;
}

.button.primary {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal);
}

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

.button.secondary {
  border-color: var(--line-strong);
}

.button.secondary:hover,
.button.compact:hover {
  border-color: var(--teal);
}

.button.compact {
  min-height: 34px;
  padding: 0 10px;
  border-color: var(--line);
  font-size: 0.9rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 0.82fr) minmax(420px, 1.18fr);
  gap: clamp(18px, 2.4vw, 30px);
  align-items: start;
  padding: clamp(18px, 3vw, 34px);
}

.control-pane,
.document-pane {
  min-width: 0;
}

.control-pane {
  display: grid;
  gap: 16px;
}

form {
  display: grid;
  gap: 16px;
}

.panel-section,
.test-panel,
.totals-strip {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.04);
}

.panel-section {
  display: grid;
  gap: 16px;
}

fieldset {
  min-width: 0;
}

legend,
.test-panel h2 {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 760;
}

.panel-section-action {
  position: relative;
  padding-top: 18px;
}

.panel-action {
  position: absolute;
  top: 14px;
  right: 18px;
}

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

.field,
.field-full {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.field b {
  color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
}

input,
select {
  padding: 0 11px;
}

textarea {
  resize: vertical;
  min-height: 96px;
  padding: 10px 11px;
}

input[aria-invalid="true"] {
  border-color: var(--red);
  background: #fff8f7;
}

.field-error {
  min-height: 16px;
  color: var(--red);
  font-size: 0.78rem;
}

.editable-table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
}

.editable-table {
  width: 100%;
  min-width: 560px;
}

.editable-table th {
  padding: 0 8px 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  text-align: left;
  text-transform: uppercase;
}

.editable-table th.number-heading {
  text-align: right;
}

.editable-table th.row-action-heading {
  width: 62px;
  text-align: center;
}

.editable-table td {
  padding: 6px 5px;
  vertical-align: top;
}

.editable-table .amount-input {
  text-align: right;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--red);
  background: #ffffff;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button:hover {
  border-color: var(--red);
  background: #fff8f7;
}

.totals-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 0;
  overflow: hidden;
}

.totals-strip div {
  display: grid;
  gap: 5px;
  min-height: 82px;
  padding: 15px;
  background: var(--panel-soft);
}

.totals-strip span,
.summary-grid span,
.document-meta span,
.signature-block span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 780;
  text-transform: uppercase;
}

.totals-strip strong {
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  white-space: nowrap;
}

.test-panel {
  display: grid;
  gap: 12px;
}

.test-heading {
  justify-content: space-between;
}

.test-summary {
  display: inline-flex;
  width: fit-content;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 0.9rem;
  font-weight: 760;
}

.test-summary.pass {
  color: var(--green);
  background: #edf8f2;
}

.test-summary.fail {
  color: var(--red);
  background: #fff1f0;
}

.test-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.test-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  font-size: 0.9rem;
}

.test-list strong {
  color: var(--green);
  white-space: nowrap;
}

.test-list .failed strong {
  color: var(--red);
}

.output-status {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.output-status.error {
  color: var(--red);
}

.output-status.success {
  color: var(--green);
}

.document-pane {
  position: sticky;
  top: 94px;
}

.document-sheet {
  max-width: 880px;
  min-height: 1050px;
  margin: 0 auto;
  padding: clamp(28px, 4vw, 48px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.document-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 3px solid var(--ink);
}

.document-kicker {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 820;
  text-transform: uppercase;
}

.document-header h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.06;
  overflow-wrap: anywhere;
}

.document-number {
  display: grid;
  gap: 7px;
  min-width: 150px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  text-align: right;
}

.document-number span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  text-transform: uppercase;
}

.document-number strong {
  overflow-wrap: anywhere;
}

.document-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.document-meta div {
  display: grid;
  gap: 7px;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.document-meta strong {
  overflow-wrap: anywhere;
}

.document-section {
  margin-top: 26px;
}

.document-section h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  text-transform: uppercase;
}

.document-reason {
  min-height: 72px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.document-table {
  width: 100%;
  border: 1px solid var(--line-strong);
}

.document-table th,
.document-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.document-table thead th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.document-table tr:last-child th,
.document-table tr:last-child td {
  border-bottom: 0;
}

.document-table .numeric,
.document-table td.numeric,
.contract-table td {
  text-align: right;
}

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

.summary-grid div {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.summary-grid strong {
  font-size: 1.18rem;
}

.summary-grid .summary-total {
  color: #ffffff;
  border-color: var(--teal);
  background: var(--teal);
}

.summary-grid .summary-total span {
  color: rgba(255, 255, 255, 0.78);
}

.contract-table th {
  width: 58%;
  font-weight: 650;
}

.contract-total-row th,
.contract-total-row td {
  background: #fff8ec;
  color: var(--ink);
  font-weight: 820;
}

.signature-block {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 56px;
}

.signature-block div {
  display: grid;
  gap: 28px;
}

.signature-block i {
  display: block;
  border-bottom: 1px solid var(--ink);
}

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

  .document-pane {
    position: static;
  }

  .document-sheet {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .app-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .button {
    flex: 1 1 0;
  }

  .app-shell {
    padding: 14px;
  }

  .field-grid,
  .totals-strip,
  .document-meta,
  .summary-grid,
  .signature-block {
    grid-template-columns: 1fr;
  }

  .section-title-row,
  .test-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-action {
    position: static;
    justify-self: start;
  }

  .document-header {
    flex-direction: column;
  }

  .document-number {
    width: 100%;
    text-align: left;
  }
}

@media print {
  @page {
    size: letter;
    margin: 0.5in;
  }

  html,
  body {
    background: #ffffff;
  }

  .app-header,
  .control-pane {
    display: none !important;
  }

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

  .document-pane {
    position: static;
  }

  .document-sheet {
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
