:root {
  --navy: #0b192c;
  --teal: #189ab4;
  --dark-teal: #133e58;
  --gold: #d4af37;
  --ink: #1a1a1a;
  --grey: #5c656e;
  --line: #d5dde3;
  --desk: #d5dee4;
  --paper: #ffffff;
  --off: #f7f7f3;
  --danger: #c62828;
  --ok: #2e7d32;
  --amber: #8a5a00;
  --shadow: 0 16px 40px rgba(10, 22, 40, 0.14);
  color-scheme: light;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--desk);
  min-height: 100vh;
}

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

button { cursor: pointer; }

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--navy);
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  display: block;
  height: 28px;
  width: auto;
  background: transparent;
}

.brand-name, .brand-legal {
  display: block;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-legal {
  color: #c5d0d8;
  font-size: 0.82rem;
}

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 64px);
}

.rail {
  background: #f4f7f8;
  border-right: 1px solid #c5d0d6;
  padding: 16px 12px;
}

.rail-head { margin-bottom: 12px; }

.rail-head .primary,
.empty .primary { width: 100%; }

.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.invoice-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0;
  padding: 8px 10px;
}

.invoice-item strong {
  font-weight: 600;
}

.invoice-item span {
  color: var(--grey);
  font-size: 0.82rem;
}

.invoice-meta { grid-column: 1 / -1; }

.invoice-item.selected {
  background: white;
  border-left-color: var(--teal);
}

.invoice-item.void strong {
  text-decoration: line-through;
}

.desk, main {
  padding: 8px 24px 48px;
  min-width: 0;
}

.empty {
  max-width: 36rem;
  margin: 10vh auto 0;
  background: white;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.empty-logo {
  height: 52px;
  width: auto;
  margin-bottom: 18px;
}

.empty h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  color: var(--navy);
}

.empty p { margin: 0 0 18px; color: var(--grey); max-width: 42ch; }

.actions {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  background: var(--desk);
}

.save-state {
  margin-left: auto;
  color: var(--grey);
  font-size: 0.88rem;
}

.primary, .quiet, .danger {
  border-radius: 4px;
  padding: 8px 12px;
}

.primary {
  background: var(--navy);
  color: white;
  border: 1px solid var(--navy);
  font-weight: 600;
}

.quiet {
  background: white;
  color: var(--navy);
  border: 1px solid #b7c3cb;
}

.topbar .quiet {
  background: transparent;
  color: white;
  border-color: #3d5163;
}

.danger {
  background: transparent;
  color: var(--danger);
  border: 0;
  padding-inline: 8px;
}

.warnings { display: grid; gap: 8px; margin-bottom: 12px; }

.warning {
  margin: 0;
  padding: 8px 12px;
  background: #fff8ee;
  border-left: 3px solid var(--amber);
  color: var(--ink);
}

.paper {
  width: min(860px, 100%);
  min-width: 0;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 32px 36px 28px;
}

.paper-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--brand-accent, var(--teal));
}

.paper-logo { height: 78px; width: auto; display: block; }
.paper-brand { margin: 6px 0 0; font-size: .85rem; font-weight: 650; color: var(--brand-ink, var(--navy)); }

.paper-title { text-align: right; }

.paper-title h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--navy);
  font-weight: 600;
}

#doc-number {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--navy);
}

.status {
  display: inline-block;
  margin: 4px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.status.draft { color: var(--grey); }
.status.issued { color: var(--dark-teal); }
.status.paid { color: var(--ok); }
.status.void { color: var(--danger); }

.status-banner {
  margin: 14px 0 0;
  padding: 8px 10px;
  font-weight: 600;
}

.status-banner.paid { background: #e8f5e9; color: var(--ok); }
.status-banner.void { background: #fdecea; color: var(--danger); }

.parties, .dates {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

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

.dates { grid-template-columns: repeat(5, 1fr); }

h2 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--grey);
}

.paper h2 { font-size: 0.82rem; }

.identity-name {
  margin: 0;
  color: var(--navy);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.identity-address {
  margin: 4px 0 0;
  font-size: 0.95rem;
  line-height: 1.35;
}

.identity-facts { margin-top: 14px; }

.identity-tin,
.identity-contact {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.identity-tin span:first-child {
  margin-right: 0.4rem;
  color: var(--grey);
  font-size: 0.78rem;
  font-weight: 400;
}

.identity-tin .num {
  color: var(--navy);
  font-weight: 600;
}

.contact-block { margin-top: 12px; }

.pay-account .contact-block { margin-top: 18px; }

.contact-label {
  margin: 0 0 2px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--grey);
}

.num {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--grey);
  margin-bottom: 8px;
}

.field input, .field textarea, .dates input, #discount {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 4px 0;
  color: var(--ink);
  font-size: 1rem;
}

.field textarea { resize: vertical; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.lines-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-top: 8px;
}

.line-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.line-table {
  margin-top: 8px;
  width: 100%;
  overflow-x: auto;
}

.charge {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: fixed;
}

.charge .col-qty { width: 72px; }
.charge .col-unit { width: 100px; }
.charge .col-price { width: 120px; }
.charge .col-amount { width: 130px; }
.charge .col-remove { width: 76px; }

.charge th,
.charge td {
  border: 1px solid #c5d0d6;
  padding: 6px 8px;
  vertical-align: top;
  overflow: hidden;
}

.charge th {
  background: var(--navy);
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
}

.charge th.num,
.charge td.num { text-align: right; }

.charge input,
.charge textarea,
.charge select {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
}

.charge td.num input { text-align: right; }

.charge textarea {
  resize: vertical;
  min-height: 2.6em;
}

.line-amount {
  display: block;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.charge .remove {
  border: 0;
  background: transparent;
  color: var(--grey);
  padding: 0;
}

.line-group { margin-top: 6px; font-size: 0.82rem; color: var(--navy); }

.received-field { max-width: 180px; margin-top: 12px; }

.paper + .paper { margin-top: 18px; }

.paying-sheet .sheet-title {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--navy);
  font-weight: 600;
}

.paying-lead {
  margin: 0 0 8px;
  color: var(--grey);
  font-size: 0.9rem;
}

.pay-group {
  margin-top: 12px;
  border: 1px solid var(--line);
  padding: 10px 12px 12px;
}

.pay-group h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--navy);
}

.pay-item {
  padding: 8px 0 10px;
  border-top: 1px solid var(--line);
}

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

.pay-item-name,
.pay-item-price,
.pay-together { margin: 0; }

.pay-item-name { color: var(--navy); font-weight: 600; }

.pay-item-price,
.pay-together {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.pay-together {
  margin-top: 6px;
  text-align: right;
  color: var(--grey);
  font-weight: 600;
}

.includes {
  margin: 6px 0 0;
  padding-left: 1.15rem;
}

.includes-label {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy);
}

.includes ul {
  margin: 0;
  padding-left: 1.15rem;
}

.includes li {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.include-editor {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.include-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.include-line {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  resize: vertical;
  background: white;
  line-height: 1.4;
}

.include-add { margin-top: 6px; }

.prepaid {
  display: block;
  margin-top: 6px;
  border: 0;
  background: transparent;
  color: var(--dark-teal);
  padding: 0;
  font-size: 0.88rem;
  text-align: left;
}

.pending-note {
  color: var(--amber);
  font-size: 0.9rem;
}

.totals-layout {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 360px);
  gap: 24px;
  margin-top: 18px;
  align-items: start;
}

.withhold {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.92rem;
}

.totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  font-variant-numeric: tabular-nums;
}

.totals .label { text-align: right; color: var(--grey); }
.totals .amount { text-align: right; }

.totals .percent {
  color: var(--navy);
  font-weight: 600;
  font-size: 1.05rem;
}

.totals .grand {
  background: var(--navy);
  color: white;
  font-weight: 600;
  padding: 6px 8px;
  margin: 4px -8px 0;
}

.totals .settle-label,
.totals .settle-amount {
  padding-top: 8px;
}

.notes-field { margin-top: 16px; }

.pay-block { margin-top: 22px; }

.pay-slip {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  padding: 14px 16px 16px;
  background: var(--off);
  border-radius: 4px;
}

.pay-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 28px;
  align-items: start;
}

.pay-side .contact-block { margin-top: 0; }

.pay-pair > .pay-side + .pay-side {
  border-left: 1px solid var(--line);
  padding-left: 28px;
}

.pay-label.spaced { margin-top: 12px; }

.pay-slip .pay-pair + .pay-pair,
.pay-wallet {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.pay-wallet-facts {
  display: grid;
  grid-template-columns: minmax(88px, 0.7fr) minmax(160px, 1.4fr) minmax(140px, 1fr);
  gap: 8px 24px;
  align-items: start;
  margin-top: 8px;
}

.pay-wallet-name {
  margin: 1px 0 0;
  color: var(--navy);
  font-weight: 600;
  line-height: 1.3;
}

.pay-wallet .pay-number {
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.pay-bank,
.pay-branch,
.pay-label,
.pay-holder,
.pay-number { margin: 0; }

.pay-label + .pay-bank { margin-top: 1px; }

.pay-bank {
  color: var(--navy);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.pay-branch {
  margin-top: 2px;
  color: var(--grey);
  font-size: 0.92rem;
}

.pay-label {
  color: var(--grey);
  font-size: 0.75rem;
  line-height: 1.3;
}

.pay-holder {
  margin: 1px 0 10px;
  color: var(--navy);
  font-weight: 600;
  line-height: 1.35;
}

.pay-number {
  margin-top: 2px;
  color: var(--navy);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

.pay-empty {
  margin: 8px 0 0;
  color: var(--grey);
}

.legal {
  margin: 18px 0 0;
  color: var(--grey);
  font-size: 0.78rem;
  max-width: 78ch;
}

dialog {
  border: 0;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow);
  color: var(--ink);
}

dialog::backdrop { background: rgba(10, 22, 40, 0.45); }

dialog form { padding: 22px 22px 16px; }

dialog h2 {
  font-size: 1.35rem;
  color: var(--navy);
  margin-bottom: 6px;
}

dialog h3 {
  margin: 14px 0 8px;
  font-size: 1rem;
  color: var(--dark-teal);
}

.dialog-lead { margin: 0 0 14px; color: var(--grey); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

#confirm-body { white-space: pre-line; }

.catalogue-list {
  max-height: 50vh;
  overflow: auto;
  margin: 8px 0 12px;
}

.catalogue-group {
  margin: 12px 0 4px;
  color: var(--dark-teal);
  font-weight: 600;
}

.catalogue-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  width: 100%;
  border-bottom: 1px solid var(--line);
  padding: 4px 2px;
}

.catalogue-add {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex: 1 1 240px;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 2px;
}

.catalogue-pair { font-size: 0.82rem; }

.catalogue-item small { color: var(--grey); display: block; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: white;
  padding: 10px 14px;
  margin: 0;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid #c5d0d6; }
  .invoice-list { max-height: 220px; overflow: auto; }
  .parties, .dates, .totals-layout, .pay-pair, .pay-wallet-facts { grid-template-columns: 1fr; }
  .pay-pair > .pay-side + .pay-side {
    border-left: 0;
    padding-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 14px;
  }
  .paper { padding: 20px 16px; }
  .save-state { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}

/* Finance Desk sign-in and top bar additions */
.signin { min-height: 100vh; display: grid; place-items: center; background: #f8fafc; padding: 24px; }
.signin[hidden], .app[hidden] { display: none; }
.signin-card { width: min(420px, 100%); background: #fff; border: 1px solid #d0d0d0; border-radius: 10px; padding: 32px; text-align: left; }
.signin-sub { margin: -8px 0 12px; letter-spacing: .16em; font-size: .75rem; color: #64748b; }
.signin-logo { height: 88px; width: auto; margin-bottom: 8px; background: transparent; }
.signin-card h1 { letter-spacing: .08em; }
.signin-card h1 { margin: 0 0 8px; font-size: 1.5rem; color: #0a1628; }
.signin-card p { margin: 0 0 20px; color: #4a4a4a; line-height: 1.5; }
.signin-card .primary { width: 100%; }
.signin-card form { margin-top: 20px; display: grid; gap: 8px; }
.signin-status { min-height: 1.5em; margin-top: 16px !important; color: #a02020; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.signed-in-as { color: #6f6f6f; font-size: 0.875rem; }
