:root {
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: #1e2e28;
  background: #eef1eb;
  line-height: 1.45;
  --text: #1e2e28;
  --muted: #56645b;
  --green: #234a37;
  --dark: #192d25;
  --paper: #fcfdf9;
  --rule: #dce3d9;
  --field-border: #a8b5aa;
  --light-green: #dcebdd;
  --danger: #982e31;
  --row-columns: minmax(215px, 2.5fr) minmax(67px, .65fr) minmax(86px, .8fr)
    minmax(105px, 1.05fr) minmax(93px, .9fr) minmax(70px, .65fr) 44px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .52; }
button, input:not([type="checkbox"]), select, textarea { min-block-size: 42px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #33734c;
  outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
h1:focus { outline: none; }
h1 { font-size: clamp(2.15rem, 4.2vw, 3.3rem); font-weight: 700; line-height: 1.1; letter-spacing: -.055em; }
h2 { font-size: 1.14rem; letter-spacing: -.025em; line-height: 1.25; }
h3 { font-size: 1rem; margin: 1rem 0 .55rem; }
small { font-size: .77rem; color: var(--muted); }
label { display: flex; flex-direction: column; gap: .3rem; color: #31463b; font-size: .86rem; font-weight: 650; min-inline-size: 0; }
input:not([type="checkbox"]), select, textarea {
  inline-size: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--field-border);
  border-radius: 5px;
  color: var(--text);
  background: #fff;
  font-size: .96rem;
  font-weight: 500;
  min-inline-size: 0;
}
input::placeholder, textarea::placeholder { color: #657067; opacity: 1; }
textarea { resize: vertical; }
input[type="checkbox"] { accent-color: var(--green); inline-size: 1.15rem; block-size: 1.15rem; margin: 0; flex: none; }
.check { flex-direction: row; align-items: center; gap: .65rem; min-block-size: 42px; }
.check small { margin-inline-start: .3rem; font-weight: 500; }
.primary, .secondary, .icon-button, .link-button {
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
  padding: .52rem .85rem;
  font-size: .92rem;
}
.primary { background: var(--green); color: #fff; }
.primary:hover:not(:disabled) { background: #183a29; }
.secondary { color: var(--green); background: #f7f9f4; border-color: #aab8ab; }
.secondary:hover:not(:disabled) { background: var(--light-green); }
.icon-button { font-size: 1.52rem; line-height: 1; color: var(--muted); background: transparent; min-inline-size: 42px; padding: .25rem; }
.icon-button:hover:not(:disabled) { color: var(--danger); background: #faeeea; }
.link-button { color: var(--green); text-decoration: underline; text-underline-offset: .22em; background: transparent; }
.link-button:hover { background: var(--light-green); }
.hint, .error { font-size: .87rem; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.dialog-status:empty { padding: 0; margin: 0; }

.signin { min-block-size: 100dvh; display: grid; align-items: center; justify-items: center; padding: 1.25rem; background: #dce6dc; }
.signin-panel { background: var(--paper); border-top: 4px solid var(--green); border-radius: 5px; padding: clamp(1.5rem, 7vw, 3rem); inline-size: min(100%, 27rem); box-shadow: 0 16px 45px #293c2e17; }
.signin-panel h1 { font-size: 2.1rem; margin: 2.35rem 0 1.5rem; }
.signin-panel form { display: grid; gap: .55rem; }
.signin-panel .primary { margin-top: .45rem; }
.brand { display: inline-flex; gap: .62rem; align-items: center; font-size: 1.18rem; font-weight: 750; white-space: nowrap; letter-spacing: -.035em; }
.brand-mark { display: inline-grid; place-items: center; border-radius: 5px 5px 5px 1px; inline-size: 2.05rem; block-size: 2.05rem; background: #a9deae; color: #1e3f2b; font-weight: 850; }
.brand-sub { font-weight: 540; opacity: .82; }
.shell { inline-size: min(100% - 3rem, 75rem); margin-inline: auto; }
.topbar { background: var(--dark); color: #fff; }
.topbar-inner { min-block-size: 4.15rem; display: flex; align-items: center; justify-content: space-between; gap: 1.4rem; }
.topbar nav { display: flex; gap: .25rem; align-items: center; }
.topbar button { border: 0; border-radius: 4px; background: transparent; color: #e5eee6; padding: .45rem .75rem; font-size: .88rem; font-weight: 600; }
.topbar button:hover, .topbar button[aria-current] { background: #304a3c; color: white; }
.topbar button:focus-visible { outline-color: #a9deae; }
.topbar .signout { padding-inline: .5rem; text-decoration: underline; text-underline-offset: .23em; }
.page-title { display: flex; align-items: end; justify-content: space-between; gap: .8rem; padding: 2rem 0 1.2rem; }
.seller { font-size: .88rem; font-weight: 650; margin-block-end: .25rem; color: var(--green); }
.mode, .kind-badge { font-size: .78rem; font-weight: 700; border-radius: 4px; padding: .28rem .56rem; text-align: center; white-space: nowrap; }
.mode { background: #f4ebd3; color: #694812; }
.kind-badge { background: var(--light-green); color: var(--green); }

.invoice-grid { display: grid; grid-template-columns: 1.14fr 1fr; gap: .9rem; align-items: start; }
.paper { border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); }
section.paper { padding: 1.1rem 1.25rem 1.2rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; min-block-size: 33px; margin-block-end: .68rem; }
.section-heading time { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .75rem; }
.fields .wide { grid-column: 1 / -1; }
.fields small { display: inline-block; margin-inline-start: .25rem; font-weight: 500; white-space: nowrap; }
.lookup-control > label { margin-block-end: .3rem; }
.inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .55rem; }
.lookup-control { margin-block-end: .55rem; }
.lookup-control .hint { min-block-size: 1.4rem; padding-block-start: .2rem; }
fieldset { min-inline-size: 0; border: 0; padding: .65rem 0 0; margin: 1.1rem 0 0; border-block-start: 1px solid var(--rule); }
legend { padding: 0 .55rem 0 0; font-weight: 700; font-size: .88rem; color: var(--green); }
.items { margin-top: .9rem; }
.line, .line-headings { display: grid; grid-template-columns: var(--row-columns); gap: .55rem; align-items: end; }
.line-headings { font-size: .8rem; font-weight: 670; color: var(--muted); margin-block-end: .3rem; }
.line + .line { margin-block-start: .55rem; }
.line label { font-size: 0; gap: 0; }
.line :is(input, select) { font-variant-numeric: tabular-nums; }
.product-field { min-inline-size: 0; position: relative; }
.suggestions { position: absolute; z-index: 2; inset: calc(100% + 4px) 0 auto; min-inline-size: min(100%, 16rem); max-block-size: 13rem; overflow-y: auto; padding: .2rem; border: 1px solid var(--field-border); border-radius: 5px; background: #fff; box-shadow: 0 4px 10px #14291d29; }
.suggestion { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .15rem .5rem; border-radius: 3px; padding: .48rem .55rem; cursor: pointer; font-size: .92rem; }
.suggestion:hover, .suggestion[aria-selected="true"] { background: var(--light-green); }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .55rem 1rem; padding: 1rem 0 1.5rem; }
.action-bar .error { margin-inline-end: auto; flex: 1 1 48%; }
.running-total { display: grid; text-align: end; line-height: 1.1; min-inline-size: 8rem; }
.running-total span { font-size: .75rem; color: var(--muted); font-weight: 650; }
.running-total output { font-size: 1.6rem; font-weight: 720; font-variant-numeric: tabular-nums; }
#history { padding-block-end: 1.6rem; }
#history-info { margin-block-end: .5rem; }
#load-more { margin-block-start: .65rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; text-align: left; inline-size: 100%; font-size: .87rem; font-variant-numeric: tabular-nums; }
thead { color: var(--green); background: #eaf0e7; }
th, td { border-bottom: 1px solid var(--rule); padding: .52rem .67rem; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th:not(:first-child), td:not(:first-child) { white-space: nowrap; }

dialog { inline-size: min(48rem, 100% - 1.4rem); max-block-size: calc(100dvh - 1.4rem); border: 1px solid var(--field-border); border-radius: 9px; padding: 1rem 1.2rem; color: var(--text); background: var(--paper); box-shadow: 0 18px 60px #182a2255; }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: #172a23b9; overflow: hidden; overscroll-behavior: contain; }
.dialog-head, .dialog-actions, .document-heading { display: flex; align-items: center; justify-content: space-between; gap: .55rem; }
.dialog-head { border-block-end: 1px solid var(--rule); margin-block-end: .8rem; }
.dialog-actions { border-block-start: 1px solid var(--rule); padding-block-start: .7rem; margin-block-start: .8rem; }
.dialog-status { font-size: .85rem; padding: .65rem .72rem; margin-block-start: .7rem; background: #edf2e9; color: var(--green); border-radius: 4px; overflow-wrap: anywhere; }
#dialog-error:not(:empty) { margin-block-start: .65rem; }
.document-heading { margin-bottom: .5rem; color: var(--muted); font-size: .84rem; }
.document-type { font-size: 1.26rem; font-weight: 750; color: var(--green); }
.document-details { display: grid; grid-template-columns: 1.45fr 1fr; gap: .4rem .95rem; margin-block-end: .8rem; }
.details { display: grid; grid-template-columns: minmax(6rem, .62fr) minmax(0, 1fr); gap: .2rem .6rem; font-size: .83rem; margin: 0; }
.details dt { font-weight: 650; color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.document-totals { inline-size: min(100%, 19rem); margin-inline-start: auto; margin-block: .75rem 0; text-align: end; grid-template-columns: 1fr auto; font-variant-numeric: tabular-nums; }
.document-totals > :nth-last-child(-n+2) { font-weight: 750; color: var(--green); padding-block-start: .3rem; }

@media (max-width: 820px) {
  .shell { inline-size: calc(100% - 1.5rem); }
  .invoice-grid { grid-template-columns: 1fr 1fr; gap: .65rem; }
  section.paper { padding-inline: .85rem; }
  .line-headings { display: none; }
  .line { grid-template-columns: repeat(5, minmax(0, 1fr)) 42px; gap: .55rem; }
  .line label { font-size: .8rem; gap: .3rem; }
  .product-field { grid-column: 1 / -1; }
  .line + .line { padding-block-start: .65rem; border-block-start: 1px solid var(--rule); margin-block-start: .65rem; }
}
@media (max-width: 610px) {
  .topbar-inner { display: grid; grid-template-columns: 1fr auto; gap: 0 .5rem; padding-block: .35rem; }
  .topbar nav { grid-row: 2; grid-column: 1 / -1; }
  .topbar .signout { grid-row: 1; grid-column: 2; }
  .page-title { padding-top: 1.4rem; }
  .invoice-grid { grid-template-columns: 1fr; }
  .line { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .line .icon-button { justify-self: end; }
  .document-details { grid-template-columns: 1fr; }
  .dialog-actions { flex-wrap: wrap; }
  dialog { padding: .65rem .78rem; }
}

.picker, .picker-field { min-inline-size: 0; }
.picker > label { margin-block-end: .3rem; }
.picker-field { position: relative; }
.picker-field.has-toggle input { padding-inline-end: 2.55rem; }
.picker-field input:disabled { background: #edf1e9; color: var(--muted); }
.picker-toggle {
  position: absolute; inset: 1px 1px 1px auto; inline-size: 2.35rem; min-block-size: 0;
  border: 0; border-radius: 0 4px 4px 0; color: var(--green); background: transparent;
  display: grid; place-items: center;
}
.picker-toggle:not(:disabled):hover, .picker-toggle[aria-expanded="true"] { background: var(--light-green); }
.picker-toggle span { inline-size: .46rem; block-size: .46rem; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-20%) rotate(45deg); }
.picker-field .suggestions { z-index: 3; }
.picker-field .suggestion small { white-space: normal; }
.recipient-actions { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-block-start: .8rem; }
.recipient-actions button { flex: none; margin-inline-start: auto; }
