* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  background: #e7e2d8;
  color: #000;
  font: 16px/1.45 Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
}

.sheet {
  max-width: 760px;
  margin: 32px auto;
  padding: 40px 48px 48px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.rule {
  border: 0;
  border-top: 2px solid #1e3a5f;
  margin: 12px 0 20px;
}

.actions, .add-row { margin: 0; }

button {
  font: inherit;
  color: #000;
  background: #fff;
  border: 1px solid #000;
  padding: 6px 12px;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.4;
}

.actions button + button { margin-left: 8px; }

.error {
  margin: 0 0 16px;
  padding: 8px 10px;
  border: 1px solid #000;
}

.error:empty { display: none; }

.parties, .meta {
  display: grid;
  gap: 16px;
  margin-bottom: 20px;
}

.parties { grid-template-columns: 1fr 1fr; }
.meta { grid-template-columns: 1fr 1fr 1fr; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input, textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-bottom: 1px solid #000;
  padding: 4px 2px;
  width: 100%;
  text-transform: none;
  letter-spacing: 0;
  font-size: 16px;
}

textarea { resize: vertical; }

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

:focus {
  outline: 2px solid #1e3a5f;
  outline-offset: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 6px 4px;
  vertical-align: top;
}

th {
  font-size: 12px;
  font-weight: normal;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid #000;
}

td { border-bottom: 1px solid #c8c8c8; }

.num, .num input { text-align: right; }

.add-row { margin-top: 12px; }

.totals {
  width: 240px;
  margin: 20px 0 0 auto;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}

.totals dt, .totals dd { margin: 0; }

.grand {
  border-top: 1px solid #000;
  font-weight: bold;
}

@media (max-width: 390px) {
  .sheet {
    margin: 0;
    padding: 16px;
    box-shadow: none;
  }

  .sheet-head, .parties, .meta { display: block; }

  .field { margin-bottom: 12px; }

  .actions button { margin: 8px 8px 0 0; }

  table, thead, tbody, tr, th, td { display: block; width: 100%; }

  thead { display: none; }

  tr {
    border-bottom: 1px solid #000;
    padding: 8px 0;
  }

  td {
    border: 0;
    padding: 4px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .num, .num input { text-align: left; }

  .totals { width: 100%; }
}

@page { margin: 16mm; }

@media print {
  html, body {
    margin: 0;
    padding: 0;
    background: #fff;
  }

  .sheet {
    max-width: none;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }

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

  input, textarea {
    border: none;
    resize: none;
  }

  input::-webkit-calendar-picker-indicator { display: none; }
}
