.billing-shell {
  --billing-ink: #211a12;
  --billing-muted: #756a5c;
  --billing-gold: #a4792d;
  --billing-line: #ddd4c7;
  --billing-paper: #fffdf9;
  color: var(--billing-ink);
}

.billing-loading,
.billing-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 32px;
  border: 1px dashed var(--billing-line, #ddd4c7);
  color: var(--billing-muted, #756a5c);
  text-align: center;
}

.billing-summary {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  padding: 26px 28px;
  margin-bottom: 18px;
  color: #f8f0e5;
  background: linear-gradient(125deg, #1e1811, #393022);
  border-radius: 2px;
}

.billing-summary > div:first-child { max-width: 620px; }
.billing-summary span,
.billing-card header > span,
.billing-dialog-head span,
.billing-collection header > span {
  display: block;
  margin-bottom: 7px;
  color: #c8a66b;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .18em;
}
.billing-summary h2,
.billing-card h3,
.billing-dialog h3 {
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 550;
}
.billing-summary h2 { font-size: clamp(27px, 3vw, 41px); }
.billing-summary p,
.billing-card header p,
.billing-collection header p { margin: 8px 0 0; color: inherit; opacity: .72; line-height: 1.55; }
.billing-summary-metrics { display: grid; grid-template-columns: repeat(3, minmax(92px, 1fr)); gap: 1px; background: rgba(255,255,255,.13); }
.billing-summary-metrics article { min-width: 108px; padding: 17px; background: rgba(24,19,13,.78); }
.billing-summary-metrics article span { color: #bdb09c; letter-spacing: .05em; }
.billing-summary-metrics strong { display: block; font-size: 18px; }

.billing-tabs { display: flex; gap: 7px; margin-bottom: 18px; overflow-x: auto; scrollbar-width: thin; }
.billing-tabs button,
.billing-dialog-actions button,
.billing-record-list button,
.billing-table button,
.billing-form > button,
.billing-collection form > button,
.billing-add-line {
  border: 1px solid #b89459;
  border-radius: 1px;
  background: transparent;
  color: inherit;
  padding: 10px 14px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.billing-tabs button { flex: 0 0 auto; border-color: var(--billing-line); background: #f7f2ea; }
.billing-tabs button.active,
.billing-form > button,
.billing-collection form > button,
.billing-record-list button:not(.quiet),
.billing-table button,
.billing-dialog-actions button:not(.quiet) { background: #282017; border-color: #282017; color: #fffaf2; }
button.quiet { border-color: var(--billing-line); color: var(--billing-muted); background: transparent; }
button:disabled { cursor: not-allowed; opacity: .42; }

.billing-two-column { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: 18px; }
.billing-card { padding: 24px; border: 1px solid var(--billing-line); background: var(--billing-paper); box-shadow: 0 12px 32px rgba(55,42,24,.045); }
.billing-card h3 { font-size: 27px; }
.billing-card header { margin-bottom: 22px; }
.billing-card header > span { color: var(--billing-gold); }

.billing-record-list { display: grid; }
.billing-record-list article { display: flex; justify-content: space-between; gap: 18px; padding: 16px 0; border-top: 1px solid var(--billing-line); }
.billing-record-list article > div:first-child { min-width: 0; }
.billing-record-list strong,
.billing-record-list span,
.billing-record-list small { display: block; }
.billing-record-list span { margin-top: 4px; color: var(--billing-muted); font-size: 12px; }
.billing-record-list small { margin-top: 4px; overflow: hidden; color: var(--billing-muted); text-overflow: ellipsis; white-space: nowrap; }
.billing-record-list article > div:last-child { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 7px; }
.billing-record-list em,
.billing-table em { padding: 5px 8px; border-radius: 999px; background: #eee7dc; color: #564838; font-size: 10px; font-style: normal; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }

.billing-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.billing-form label,
.billing-payment-note { display: grid; gap: 6px; }
.billing-form label > span,
.billing-payment-note > span { color: #65594a; font-size: 11px; font-weight: 720; }
.billing-form input,
.billing-form select,
.billing-collection input,
.billing-collection select {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--billing-line);
  border-radius: 0;
  background: #fff;
  color: var(--billing-ink);
  padding: 9px 10px;
  font: inherit;
}
.billing-form select[multiple] { min-height: 64px; }
.billing-form .wide { grid-column: 1 / -1; }
.billing-consent { display: flex !important; align-items: center; gap: 9px !important; }
.billing-consent input { width: 18px; min-height: auto; }
.billing-form-error { min-height: 18px; margin: 0; color: #a22f2f; font-size: 12px; }
.billing-form > button { grid-column: 1 / -1; justify-self: start; min-width: 170px; }
.billing-notice { margin: 0; padding: 11px 13px; background: #f4ecdf; color: #6d5735; font-size: 12px; }

.billing-service-lines { padding: 0; border: 0; }
.billing-service-lines legend { margin-bottom: 10px; color: #65594a; font-size: 11px; font-weight: 720; }
.billing-service-row,
.billing-tender-row { display: grid; grid-template-columns: 30px minmax(190px, 1.35fr) minmax(150px, 1fr) minmax(160px, 1fr) 65px auto; gap: 9px; align-items: end; padding: 12px; margin-bottom: 9px; border: 1px solid var(--billing-line); background: #faf7f1; }
.billing-service-row > span,
.billing-tender-row > span { align-self: center; color: var(--billing-gold); font-size: 11px; font-weight: 800; }
.billing-service-row label,
.billing-tender-row label { min-width: 0; }
.billing-service-row small,
.billing-tender-row small { display: block; margin-bottom: 5px; color: var(--billing-muted); }
.billing-add-line { margin: 3px 0 8px; border-style: dashed; color: #755927; background: transparent; }

.billing-table-wrap { overflow-x: auto; }
.billing-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.billing-table th,
.billing-table td { padding: 13px 10px; border-top: 1px solid var(--billing-line); text-align: left; font-size: 12px; }
.billing-table th { color: var(--billing-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.billing-table td strong,
.billing-table td small { display: block; }
.billing-table td small { margin-top: 3px; color: var(--billing-muted); }

.billing-dialog-backdrop { position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(17,13,9,.76); overflow: auto; }
.billing-dialog { width: min(920px, 100%); max-height: calc(100vh - 44px); overflow-y: auto; background: #f5f0e8; box-shadow: 0 28px 80px rgba(0,0,0,.35); }
.billing-dialog-head { position: sticky; z-index: 3; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; color: #fff; background: #211a12; }
.billing-dialog-head span { margin: 0 0 3px; }
.billing-dialog-head h3 { font-size: 26px; }
.billing-dialog-head > button { width: 40px; height: 40px; border: 0; color: #fff; background: transparent; font-size: 25px; cursor: pointer; }

.billing-document { margin: 22px; padding: 34px; background: #fff; color: #231d15; box-shadow: 0 5px 22px rgba(44,32,18,.08); }
.billing-document > header { display: flex; justify-content: space-between; gap: 28px; padding-bottom: 22px; border-bottom: 2px solid #2e2419; }
.billing-document > header > div:last-child { text-align: right; }
.billing-document > header span,
.billing-document-customer > span,
.billing-payment-history > span { color: #9e742c; font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.billing-document h2 { margin: 4px 0 6px; font-family: "Cormorant Garamond", Georgia, serif; font-size: 28px; }
.billing-document p { margin: 3px 0; }
.billing-document-tax { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 10px 0; border-bottom: 1px solid #ded7cd; color: #665a4d; font-size: 11px; }
.billing-document-customer { padding: 18px 0; }
.billing-document-customer strong { display: block; margin-top: 4px; }
.billing-document table { width: 100%; border-collapse: collapse; }
.billing-document th,
.billing-document td { padding: 10px 7px; border-bottom: 1px solid #ded7cd; text-align: right; font-size: 11px; vertical-align: top; }
.billing-document th:first-child,
.billing-document td:first-child { text-align: left; }
.billing-document td strong,
.billing-document td small { display: block; }
.billing-document td small { margin-top: 3px; color: #7f7468; }
.billing-document-totals { width: min(360px, 100%); margin: 20px 0 20px auto; }
.billing-document-totals p { display: flex; justify-content: space-between; gap: 18px; padding: 4px 0; }
.billing-document-totals .grand { margin-top: 5px; padding-top: 10px; border-top: 2px solid #2e2419; font-size: 17px; }
.billing-payment-history { padding: 14px 0; border-top: 1px solid #ded7cd; }
.billing-payment-history p { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; font-size: 11px; }
.billing-document > footer { margin-top: 18px; padding-top: 15px; border-top: 1px solid #ded7cd; color: #776b5e; font-size: 9px; line-height: 1.5; }

.billing-collection { margin: 0 22px 22px; padding: 22px; border: 1px solid var(--billing-line); background: #fff; }
.billing-collection header { margin-bottom: 15px; }
.billing-collection h3 { font-size: 25px; }
.billing-tender-row { grid-template-columns: 26px minmax(140px, .8fr) minmax(120px, .7fr) minmax(180px, 1.4fr) auto; }
.billing-payment-note { margin: 8px 0; }
.billing-collection form > button[type="submit"] { margin-top: 8px; }
.billing-dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 22px; }

[data-billing-print] { display: none; }

@media (max-width: 980px) {
  .billing-summary { display: grid; }
  .billing-two-column { grid-template-columns: 1fr; }
  .billing-service-row { grid-template-columns: 26px 1fr 1fr; }
  .billing-service-row label:nth-of-type(3) { grid-column: 2 / -1; }
  .billing-tender-row { grid-template-columns: 26px 1fr 1fr; }
  .billing-tender-row label:nth-of-type(3) { grid-column: 2 / -1; }
}

@media (max-width: 620px) {
  .billing-summary,
  .billing-card { padding: 18px; }
  .billing-summary-metrics { grid-template-columns: 1fr; }
  .billing-summary-metrics article { min-width: 0; }
  .billing-form { grid-template-columns: 1fr; }
  .billing-form .wide,
  .billing-form > button { grid-column: auto; }
  .billing-service-row,
  .billing-tender-row { grid-template-columns: 24px 1fr; }
  .billing-service-row label,
  .billing-service-row label:nth-of-type(3),
  .billing-tender-row label,
  .billing-tender-row label:nth-of-type(3),
  .billing-service-row button,
  .billing-tender-row button { grid-column: 2; }
  .billing-record-list article { display: grid; }
  .billing-record-list article > div:last-child { justify-content: flex-start; }
  .billing-dialog-backdrop { padding: 0; place-items: stretch; }
  .billing-dialog { width: 100%; max-height: 100vh; }
  .billing-document { margin: 10px; padding: 18px; }
  .billing-document > header { display: grid; }
  .billing-document > header > div:last-child { text-align: left; }
  .billing-collection { margin: 10px; padding: 16px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body > *:not([data-billing-print]) { display: none !important; }
  [data-billing-print] { display: block !important; }
  [data-billing-print] .billing-document { width: 100%; margin: 0; padding: 0; box-shadow: none; }
  [data-billing-print] .billing-document table { break-inside: avoid; }
  [data-billing-print] .billing-document { color: #000; }
}
