:root {
  --green: #739B6C;      /* letterhead green: fills and rules */
  --green-txt: #4F7A49;  /* darker green for text on white */
  --tint: #EEF4EC;
  --ink: #1F2523;
  --muted: #5F6B65;
  --rule: #D9E2D6;
  --edit-bg: rgba(255, 214, 102, .22);
  --edit-line: #E0B43A;
}

body {
  background: #E7EBE6;
  color: var(--ink);
}

/* ---------- App chrome ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid #d6ddd4;
}
.app-bar-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding-top: .75rem;
  padding-bottom: .5rem;
}
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green);
}
.legend-swatch {
  display: inline-block; width: 14px; height: 10px; vertical-align: middle;
  background: var(--edit-bg); border-bottom: 1.5px dashed var(--edit-line);
}
.nav-tabs { border-bottom: 0; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs .nav-link { color: var(--muted); font-weight: 600; white-space: nowrap; }
.nav-tabs .nav-link.active { color: var(--green-txt); border-top: 3px solid var(--green); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  max-width: 210mm; margin: 1.25rem auto .75rem; padding: 0 16px;
}
.btn-brand { background: var(--green); border-color: var(--green); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--green-txt); border-color: var(--green-txt); color: #fff; }
.overflow-warn { display: none; white-space: normal; text-align: left; }
.overflow-warn.show { display: inline-block; }

/* Phones: toolbar buttons share the width in two columns */
@media (max-width: 575.98px) {
  .app-bar { position: static; }
  .app-bar-inner { padding-top: .5rem; padding-bottom: .25rem; }
  .legend { font-size: .75rem; }
  .toolbar { margin-top: .75rem; }
  .toolbar .btn { flex: 1 1 calc(50% - .5rem); }
  .overflow-warn.show { display: block; width: 100%; }
}

/* ---------- A4 pages ---------- */
.pages {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 0 16px 48px;
  overflow-x: hidden;
}
/* Frame takes the scaled size; the page inside keeps its real A4 layout (see fitPages in app.js) */
.page-frame { position: relative; flex: none; width: 210mm; height: 297mm; }
.page {
  position: absolute; top: 0; left: 0;
  transform-origin: top left;
  width: 210mm;
  height: 297mm;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .14);
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  line-height: 1.35;
  color: var(--ink);
}
.page-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
/* content area clear of the letterhead header and footer, same 15mm side margins on every page */
.page-body {
  position: absolute;
  top: 41mm; bottom: 19mm; left: 14.8mm; right: 14.8mm;
}
.page-body > :first-child { margin-top: 0; }

/* Lay out a hidden tab off-screen so its pages can be measured */
.tab-pane.measuring { display: block !important; visibility: hidden; position: absolute; left: -9999px; top: 0; width: 100%; }

/* ---------- Invoice typography ---------- */
.inv-title { font-size: 22pt; font-weight: 700; margin: 0 0 4pt; letter-spacing: -.2pt; }
.inv-title.long { font-size: 18pt; line-height: 1.3; }
.inv-sub { font-size: 9.5pt; color: var(--muted); margin: 0 0 11pt; }
.inv-h2 {
  display: flex; align-items: baseline; gap: 10pt;
  font-size: 12pt; font-weight: 700; color: var(--green-txt);
  border-bottom: 1.2pt solid var(--green);
  padding-bottom: 3pt; margin: 10pt 0 5pt;
}
.inv-h2 .extra { font-size: 10pt; font-weight: 400; color: var(--muted); }

.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th {
  background: var(--green); color: #fff;
  font-size: 9.5pt; font-weight: 700;
  padding: 5pt 6pt; text-align: left;
}
.inv-table td {
  padding: 3.5pt 6pt; vertical-align: top;
  border-bottom: .6pt solid var(--rule);
}
.inv-table .r { text-align: right; }
.inv-table .c { text-align: center; }
.inv-table .lbl { color: var(--muted); width: 34%; }
.items .qty { width: 9%; }
.items .amt { width: 20%; }
.items .cis { width: 22%; }

.parties td { border-bottom: 0; padding: 2pt 6pt; }
.parties .name { font-weight: 700; font-size: 10.5pt; padding-top: 6pt; padding-bottom: 5pt; }
.parties .lab { color: var(--muted); white-space: nowrap; padding-right: 4pt; width: 1%; }
.parties-wrap { border-bottom: .6pt solid var(--rule); margin-bottom: 11pt; padding-bottom: 3pt; }
.parties-grid { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }

.totals { margin-top: 12pt; }
.totals td { padding: 3.5pt 6pt; }
.due td {
  background: var(--tint);
  border-top: 1.4pt solid var(--green); border-bottom: 1.4pt solid var(--green);
  font-size: 13pt; font-weight: 700; color: var(--green-txt);
  padding: 6pt 6pt;
}

.note { font-size: 9.5pt; color: var(--muted); margin: 0 0 7pt; }
.note b { color: var(--ink); }
.draft { font-size: 9.5pt; color: var(--muted); font-style: italic; margin-top: 12pt; }
.gp { margin: 0 0 6pt; }
.disclaimer {
  margin-top: 14pt; padding: 9pt 12pt;
  background: var(--tint); border-left: 2.5pt solid var(--green);
  font-size: 9.5pt; font-style: italic; color: var(--muted);
}

/* ---------- Editable fields ---------- */
.editable {
  background: var(--edit-bg);
  border-bottom: 1.5px dashed var(--edit-line);
  border-radius: 2px;
  outline: none;
  min-width: 2.5em;
  display: inline-block;
  cursor: text;
}
.editable:hover { background: rgba(255, 214, 102, .38); }
.editable:focus { background: #fff8e1; border-bottom-style: solid; }
.editable:empty::before { content: attr(data-ph); color: #b7b09a; font-style: italic; }
td > .editable, p > .editable.block, .editable.block { display: block; }
/* run-in fields that sit inside a sentence */
.note .editable, .editable.rate { display: inline; min-width: 0; padding: 0 1px; }

.cis-toggle { cursor: pointer; user-select: none; }
.cis-toggle::after { content: ' \21C4'; color: var(--edit-line); font-size: 8pt; }

.row-del {
  border: 0; background: none; color: #b5483b; font-size: 13pt; line-height: 1;
  padding: 0 2pt; cursor: pointer;
}
.row-tools { width: 18pt; padding-left: 0 !important; padding-right: 0 !important; text-align: center; }

/* Hide editing aids while exporting or printing */
body.exporting .editable,
body.exporting .editable:focus { background: none; border-bottom-color: transparent; }
body.exporting .editable:empty::before { content: ''; }
body.exporting .cis-toggle::after { content: ''; }
body.exporting .edit-only { display: none !important; }
body.exporting .page { transform: none !important; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-print, .toolbar, .tab-pane:not(.active) { display: none !important; }
  .pages { padding: 0; gap: 0; display: block; overflow: visible; }
  .page-frame { width: 210mm !important; height: 297mm !important; break-after: page; page-break-after: always; }
  .page { box-shadow: none; transform: none !important; }
  .editable { background: none !important; border-bottom-color: transparent !important; }
  .editable:empty::before, .cis-toggle::after { content: '' !important; }
  .edit-only { display: none !important; }
}
