:root {
  --accent: #ffb133;
  --accent-soft: rgba(255, 177, 51, 0.18);
  --accent-focus: rgba(255, 177, 51, 0.35);
  --accent-shadow: rgba(255, 177, 51, 0.28);
  --ink: #222222;
  --muted: #9b9b9b;
  --line: #dddddd;
  --soft: #f7f7f7;
  --paper: #ffffff;
  --toolbar: #f2f3f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--toolbar);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.35;
}

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

.app-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 30px rgba(34, 34, 34, 0.08);
}

.toolbar-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar-group.compact {
  gap: 6px;
}

.toolbar-group label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input,
textarea {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

select {
  padding: 0 32px 0 10px;
}

button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

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

.primary-action {
  background: var(--accent);
  color: var(--ink);
  box-shadow: 0 5px 14px var(--accent-shadow);
}

.dark-action {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 5px 14px rgba(34, 34, 34, 0.22);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.option-controls {
  flex-wrap: wrap;
}

.toggle-option {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.toggle-option.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.workspace {
  overflow: auto;
  padding: 28px 16px 60px;
}

.invoice-root {
  display: grid;
  gap: 18px;
  justify-content: center;
}

.invoice-page {
  width: 210mm;
  min-height: 297mm;
  display: flex;
  flex-direction: column;
  padding: 13mm 15mm 11mm;
  background: var(--paper);
  box-shadow: 0 18px 45px rgba(34, 34, 34, 0.14);
  page-break-after: always;
}

.invoice-page:last-child {
  page-break-after: auto;
}

.page-continuation {
  min-height: 297mm;
}

.invoice-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 1fr);
  gap: 16px;
  align-items: center;
  padding-bottom: 10px;
}

.brand-left {
  display: flex;
  min-height: 42px;
  align-items: center;
}

.logo-image {
  max-width: 210px;
  max-height: 46px;
  object-fit: contain;
}

.fallback-logo {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: 0;
}

.fallback-logo::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background:
    linear-gradient(135deg, var(--accent) 0 50%, transparent 50%),
    linear-gradient(45deg, var(--ink) 0 48%, transparent 48%);
  border: 2px solid var(--accent);
}

.fallback-logo small {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.document-title {
  justify-self: end;
  margin: 0;
  font-size: 18px;
  font-weight: 850;
  text-align: right;
  text-transform: uppercase;
}

.document-title small {
  display: block;
  margin-top: 3px;
  font-size: 9px;
  font-weight: 700;
  text-transform: none;
}

.accent-rule {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 6px;
  margin: 0 0 10px;
}

.accent-rule span:first-child {
  background: var(--accent);
}

.accent-rule span:last-child {
  background: var(--ink);
}

.party-meta {
  display: grid;
  grid-template-columns: 1.95fr 0.8fr;
  gap: 28px;
  margin-bottom: 18px;
  font-size: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: 96px 1fr;
  row-gap: 6px;
  column-gap: 14px;
}

.label {
  font-weight: 800;
}

.value-strong {
  font-weight: 850;
  font-style: italic;
}

.muted-line {
  color: var(--muted);
}

.date-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-self: start;
  gap: 6px 14px;
}

.date-box .value {
  text-align: right;
}

.section-title {
  margin: 0 0 4px;
  border: 1px solid var(--ink);
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  text-transform: uppercase;
}

.invoice-table,
.totals-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.invoice-table th,
.invoice-table td,
.totals-table td {
  border: 1px solid var(--ink);
  vertical-align: middle;
}

.invoice-table th {
  padding: 4px 5px;
  background: #fff;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.invoice-table td {
  min-height: 35px;
  padding: 5px 5px;
}

.col-no {
  width: 32px;
  text-align: center;
}

.col-goods {
  width: auto;
}

.col-qty {
  width: 78px;
}

.col-unit {
  width: 106px;
}

.col-total {
  width: 130px;
}

.col-delete {
  width: 58px;
}

.invoice-table .number-cell,
.invoice-table .money-cell {
  text-align: right;
  white-space: nowrap;
}

.goods-cell {
  text-align: center;
}

.goods-title {
  font-weight: 500;
}

.goods-note {
  margin-top: 3px;
}

[contenteditable="true"] {
  outline: 0;
  border-radius: 4px;
}

[contenteditable="true"]:focus {
  box-shadow: 0 0 0 2px var(--accent-focus);
  background: var(--accent-soft);
}

.delete-row,
.add-row {
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 11px;
}

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 4px;
}

.add-row {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.totals-table {
  margin-top: 10px;
}

.totals-table td {
  height: 24px;
  padding: 3px 5px;
}

.totals-table .label-cell {
  text-align: right;
  font-style: italic;
}

.totals-table .value-cell {
  width: 130px;
  text-align: right;
  white-space: nowrap;
}

.totals-table .subtotal-row .label-cell {
  font-weight: 650;
  font-style: italic;
}

.totals-table .subtotal-row .value-cell {
  font-weight: 650;
}

.totals-table .final-row td {
  border-top-width: 2px;
  font-weight: 850;
  font-style: normal;
}

.terms-bank {
  margin-top: auto;
  padding-top: 14px;
  font-size: 12px;
}

.terms-grid {
  display: grid;
  grid-template-columns: 112px 1fr;
  row-gap: 4px;
  column-gap: 14px;
  max-width: 560px;
}

.terms-grid .label {
  font-weight: 500;
}

.terms-grid .emphasis {
  font-weight: 850;
  font-style: italic;
}

.bank-kicker {
  margin-top: 10px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.continued-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.admin-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 25px 80px rgba(34, 34, 34, 0.28);
}

.admin-dialog::backdrop {
  background: rgba(34, 34, 34, 0.44);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-heading,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.dialog-panel input,
.dialog-panel textarea {
  width: 100%;
  padding: 8px 10px;
  color: var(--ink);
  font-weight: 500;
  text-transform: none;
}

.dialog-panel input[type="color"] {
  width: 64px;
  min-height: 38px;
  padding: 3px;
  cursor: pointer;
}

.dialog-panel textarea {
  min-height: 74px;
  resize: vertical;
}

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

.form-error {
  margin: 0;
  color: #a23b1d;
  font-weight: 800;
}

.is-exporting .ui-only,
.pdf-clone .ui-only {
  display: none !important;
}

@media (max-width: 920px) {
  .workspace {
    padding-inline: 8px;
  }

  .invoice-root {
    justify-content: start;
  }

  .invoice-page {
    transform-origin: top left;
  }
}

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

  body {
    background: #fff;
  }

  .ui-only {
    display: none !important;
  }

  .workspace {
    padding: 0;
    overflow: visible;
  }

  .invoice-root {
    display: block;
  }

  .invoice-page {
    width: 210mm;
    min-height: 297mm;
    box-shadow: none;
  }
}
