:root {
  --ink: #111111;
  --muted: #666666;
  --line: #d6d6d6;
  --paper: #ffffff;
  --canvas: #eeeeee;
  --panel: #f8f8f8;
  --accent: #1f2937;
  --danger: #8a1f1f;
  --receipt-width: 210mm;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  font-family: "Segoe UI", Aptos, sans-serif;
  background: var(--canvas);
}

body {
  margin: 0;
  min-width: 320px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  min-height: 100vh;
}

.editor {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 16px;
  background: #f5f5f5;
  border-right: 1px solid #cfcfcf;
}

.editor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 10px;
}

.eyebrow,
.section-label {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.toolbar button,
.toolbar-file-action,
.secondary-action,
.item-card-head button,
.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #bdbdbd;
  border-radius: 4px;
  color: var(--ink);
  background: #ffffff;
}

.toolbar-file-action {
  margin: 0;
  font-size: 1rem;
  font-weight: 400;
  cursor: pointer;
}

.toolbar-file-action input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.url-import-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  flex: 1 1 100%;
  gap: 6px;
}

.url-import-group input {
  min-height: 32px;
}

.import-status {
  flex: 1 1 100%;
  min-height: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.import-status.is-error {
  color: var(--danger);
}

.primary-action {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
  white-space: nowrap;
}

.panel {
  margin: 0 0 10px;
  padding: 10px 12px 8px;
  border: 1px solid #d1d1d1;
  border-radius: 4px;
  background: var(--panel);
}

legend {
  padding: 0 5px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

label {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  color: #4b4b4b;
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  padding: 7px 8px;
  color: var(--ink);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #b9c0ca;
  border-color: #6b7280;
}

input:disabled {
  color: #777777;
  background: #eeeeee;
}

.form-grid {
  display: grid;
  gap: 8px;
}

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

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

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

.item-card {
  padding: 10px;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #ffffff;
}

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

.item-card-head strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.item-card-head button {
  color: var(--danger);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  margin-top: 18px;
}

.checkbox-label input {
  width: auto;
}

.is-hidden {
  display: none !important;
}

.preview-area {
  overflow: auto;
  padding: 16px;
  background: var(--canvas);
}

.receipt-sheet {
  width: min(var(--receipt-width), 100%);
  margin: 0 auto;
  padding: 11mm 12mm;
  background: var(--paper);
  border: 1px solid #d0d0d0;
}

.receipt-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
}

.brand-block {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.brand-block img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 3px;
}

.company-name {
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.15;
}

.muted-lines {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: pre-line;
}

.receipt-title {
  min-width: 150px;
  text-align: right;
}

.receipt-title h2 {
  margin: 5px 0 9px;
  color: var(--ink);
  font-size: 1.75rem;
  line-height: 0.95;
  text-transform: uppercase;
}

.status-pill {
  display: inline-block;
  margin: 0;
  padding: 3px 7px;
  border: 1px solid #bdbdbd;
  border-radius: 3px;
  color: var(--ink);
  background: #f3f3f3;
  font-size: 0.72rem;
  font-weight: 800;
}

dl {
  margin: 0;
}

.receipt-title dl,
.compact-list,
.totals-card dl {
  display: grid;
  gap: 5px;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  margin: 0;
  font-weight: 800;
}

.address-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  padding: 14px 0;
}

.address-grid h3 {
  margin-bottom: 4px;
  font-size: 0.98rem;
  line-height: 1.15;
}

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

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

.receipt-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

.receipt-table th {
  padding: 7px 8px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  background: #f1f1f1;
  text-align: right;
}

.receipt-table th:first-child {
  text-align: left;
}

.receipt-table td {
  padding: 8px;
  border-bottom: 1px solid #dddddd;
  text-align: right;
  vertical-align: top;
}

.receipt-table td:first-child {
  text-align: left;
}

.item-title {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

.item-detail {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.3;
  white-space: pre-line;
}

.receipt-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  padding-top: 14px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.receipt-summary.no-annotation {
  grid-template-columns: minmax(0, 1fr) 280px;
}

.receipt-summary.no-annotation .totals-card {
  grid-column: 2;
}

.annotation {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.annotation p {
  white-space: pre-line;
}

.terms-label {
  margin-top: 12px;
}

.totals-card {
  align-self: start;
  padding: 10px;
  border: 1px solid #cfcfcf;
  border-radius: 3px;
  background: #ffffff;
}

.totals-card div {
  padding: 2px 0;
}

.grand-total {
  margin-top: 4px;
  padding-top: 8px !important;
  border-top: 2px solid var(--ink);
  color: var(--ink);
  font-size: 1.02rem;
}

.balance-row {
  margin-top: 3px;
  padding: 7px 0 1px !important;
  border-top: 1px solid #d0d0d0;
  color: var(--ink);
}

.receipt-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding-top: 8px;
  border-top: 1px solid #d0d0d0;
  color: var(--muted);
  font-size: 0.78rem;
  break-inside: avoid;
}

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

  .editor {
    position: relative;
    height: auto;
  }
}

@media (max-width: 720px) {
  .editor,
  .preview-area {
    padding: 12px;
  }

  .editor-header,
  .form-grid.two,
  .form-grid.three,
  .form-grid.four,
  .receipt-top,
  .address-grid,
  .receipt-summary {
    grid-template-columns: 1fr;
  }

  .primary-action {
    width: 100%;
  }

  .receipt-sheet {
    min-height: auto;
    padding: 12px;
  }

  .receipt-title {
    text-align: left;
  }
}

@page {
  size: A4;
  margin: 10mm;
}

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

  .editor {
    display: none !important;
  }

  .app-shell,
  .preview-area {
    display: block;
    padding: 0;
    background: #ffffff;
  }

  .receipt-sheet {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .receipt-top,
  .receipt-summary,
  .receipt-footer {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .receipt-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
