/* ------------------------------------------------------------------ app chrome */

:root {
  --bg: #f1f0ec;
  --surface: #ffffff;
  --surface-2: #f7f6f2;
  --text: #1c1c1a;
  --muted: #6a6862;
  --line: #e0ded6;
  --accent: #27527e;
  --accent-hover: #1e4166;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --po: #4f6228;
  --invoice: #7a6a38;
  --focus: #e9a800;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1f1e1c;
    --surface-2: #292825;
    --text: #ecebe6;
    --muted: #a3a19a;
    --line: #36342f;
    --accent: #86b4e2;
    --accent-hover: #a6c9ee;
    --accent-ink: #0e1a27;
    --danger: #f0877e;
    --po: #a9c46b;
    --invoice: #d6c58c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: inherit;
  text-decoration: none;
  margin-right: 6px;
}
.brand:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.spacer { flex: 1; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:focus-visible, .linkbtn:focus-visible, .starter:focus-visible, .docmain:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.linkbtn {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge.po { color: var(--po); }
.badge.invoice { color: var(--invoice); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* list */

.listwrap { max-width: 980px; margin: 0 auto; padding: 28px 16px 64px; }
.listwrap h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }

.listhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search {
  flex: 0 1 320px;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.doclist {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.docrow {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
}
.docrow:first-child { border-top: 0; }
.docrow:hover { background: var(--surface-2); }

.docmain {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 76px 100px minmax(0, 1fr) 96px 110px 96px;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 16px;
  color: inherit;
  text-decoration: none;
}
.docmain .badge { justify-self: start; }
.docnum { font-variant-numeric: tabular-nums; font-weight: 600; }
.docparty { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doclabel { margin-left: 8px; font-size: 12px; color: var(--muted); }
.docdate, .docupdated { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.doctotal { text-align: right; font-variant-numeric: tabular-nums; }
.docactions { display: flex; gap: 2px; padding-right: 8px; }
.empty-search { padding: 20px 16px; margin: 0; }
.showmore { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); }

.backup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.backup p { margin: 0; max-width: 560px; }
.backup-actions { display: flex; gap: 6px; }

.empty { text-align: center; padding-top: 40px; }
.empty h1 { font-size: 26px; }
.empty > p { max-width: 460px; margin: 10px auto; }

.starters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 260px));
  justify-content: center;
  gap: 16px;
  margin: 28px 0;
}
.starter {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 20px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.starter:hover { border-color: var(--accent); }
.starter-title { font-size: 18px; font-weight: 650; }
.starter-title.po { color: var(--po); }
.starter-title.invoice { color: var(--invoice); }

@media (max-width: 760px) {
  .docrow { align-items: flex-start; }
  .docmain {
    grid-template-columns: auto auto 1fr;
    grid-template-areas: "badge num total" "party party party" "date updated updated";
    row-gap: 4px;
  }
  .docmain .badge { grid-area: badge; justify-self: start; }
  .docnum { grid-area: num; }
  .doctotal { grid-area: total; }
  .docparty { grid-area: party; }
  .docdate { grid-area: date; }
  .docupdated { grid-area: updated; }
  .docactions { flex-direction: column; padding-top: 8px; }
  .starters { grid-template-columns: minmax(0, 1fr); }
}

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
}
.notice .failed {
  flex-basis: 100%;
  order: 3;
  margin: 0;
  padding-left: 18px;
  max-height: 180px;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
}

/* editor */

.editor-bar { gap: 8px; flex-wrap: nowrap; }
.editor-bar > * { flex-shrink: 0; }
.editor-bar .label-input { flex: 0 1 230px; min-width: 70px; }
.editor-bar .status { white-space: nowrap; }
@media (max-width: 980px) { .editor-bar .badge, .editor-bar .status { display: none; } }
@media (max-width: 720px) { .editor-bar { flex-wrap: wrap; } }
.label-input {
  width: 230px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.status { font-size: 13px; margin-right: 4px; }
.status.error { color: var(--danger); }

.canvas {
  display: flex;
  justify-content: center;
  padding: 28px 16px 80px;
  overflow-x: hidden;
}

.popover {
  position: absolute;
  z-index: 40;
  width: 320px;
  max-width: calc(100vw - 16px);
  max-height: 360px;
  overflow: auto;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.pop-title { font-size: 12px; font-weight: 650; color: var(--muted); padding: 6px 8px; }
.pop-item {
  appearance: none;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.pop-item span { font-size: 12px; color: var(--muted); }
.pop-item:hover, .pop-item:focus-visible { background: var(--surface-2); outline: none; }
.pop-empty { margin: 4px 8px 10px; }

/* ------------------------------------------------------------------ the document */
/* Measured from the original FormSwift PDFs (US Letter, ~0.6in margins). */

.page {
  --blue: #4f81bd;
  --tan: #ddd9c4;
  --green-fill: #d7e4bd;
  --green: #4f6228;
  --green-label: #5f7632;

  flex: none;
  width: 8.5in;
  min-height: 11in;
  padding: 0.6in;
  background: #fff;
  color: #000;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 10px 30px rgba(0, 0, 0, .10);
  font-family: "Tinos", "Times New Roman", Times, serif;
  font-size: 11pt;
  line-height: 1.12;
  letter-spacing: 0.17pt;
  color-scheme: light;
}

.page table { border-collapse: collapse; }
.page .lbl, .page th {
  font-family: "Noto Serif", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0;
}

/* editable fields */
.page .f {
  display: block;
  min-height: 1.12em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  border-radius: 2px;
}
.page span.f { display: inline-block; min-width: 3em; vertical-align: top; }

@media screen {
  .page .f { background: rgba(250, 214, 90, .16); cursor: text; }
  .page .f:hover { background: rgba(250, 200, 60, .30); }
  .page .f:focus { background: #fff6cc; box-shadow: 0 0 0 1.5px var(--focus); }
  .page .f:empty::before { content: attr(data-ph); color: #a3a3a3; pointer-events: none; }
  .page .rows tr:not(:first-child) .f:empty::before { content: none; }
}

.page .company-name { font-weight: 700; font-size: 12pt; }

/* line items (shared) */
.page .items { width: 100%; table-layout: fixed; }
.page .items th {
  height: 0.27in;
  padding: 2px 4px;
  font-size: 7.5pt;
  text-align: center;
  border: 1px solid var(--blue);
}
.page .items td {
  height: 0.42in;
  padding: 3px 6px;
  vertical-align: middle;
  border: 1px solid var(--blue);
  border-top-width: 2px;
}
.page .items td.qty, .page .items td.item { text-align: center; }
.page .items td.qty { font-size: 10pt; }
.page .items td.item { font-size: 10pt; padding: 3px 3px; }
.page .items td.price, .page .items td.total { text-align: right; padding-right: 0.14in; }
.page .items td.desc { padding-left: 0.08in; padding-right: 0.1in; }
.page .items tr { break-inside: avoid; }
.page .items td.total { position: relative; }

.page .rm {
  position: absolute;
  top: 50%;
  right: -30px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #d5d5d5;
  background: #fff;
  color: #777;
  font: 15px/1 system-ui, sans-serif;
  cursor: pointer;
  opacity: 0;
}
.page .rows tr:hover .rm, .page .rm:focus-visible { opacity: 1; }
.page .rm:hover { color: #b3261e; border-color: #b3261e; }
@media (hover: none) { .page .rm { opacity: .7; } }

.page .items-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font: 13px system-ui, sans-serif;
}
.page .add-row {
  appearance: none;
  border: 1px dashed #9db3d3;
  border-radius: 6px;
  background: #f5f8fc;
  color: #2c5282;
  padding: 5px 10px;
  font: inherit;
  cursor: pointer;
}
.page .add-row:hover { background: #e9f0f9; }
.page .hint { color: #8a8a8a; }

.page .pick {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #c9c9c9;
  background: #fff;
  color: #555;
  font: 11px/1.4 system-ui, sans-serif;
  cursor: pointer;
}
.page .pick:hover { border-color: #27527e; color: #27527e; }
.page .party { position: relative; }

.page .sum-line { display: flex; align-items: center; }
.page .sum-line .lbl { font-size: 9pt; text-align: right; line-height: 1.35; }
.page .sum-line .val { text-align: right; }

/* ------------------------------ invoice */

.invoice .inv-rule { border-top: 1px solid var(--blue); }
.invoice .inv-title {
  text-align: right;
  font-weight: 700;
  font-size: 20pt;
  margin: 0.17in 0.08in 0 0;
  line-height: 1;
}
.invoice .inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 0.24in;
}
.invoice .inv-head .company-name { padding-left: 0.08in; margin-bottom: 0.02in; font-size: 13pt; }
.invoice .inv-meta { width: 3.36in; margin-right: 0.08in; }
.invoice .inv-meta th {
  width: 1.53in;
  background: var(--tan);
  border: 1px solid #000;
  font-size: 13pt;
  line-height: 1.1;
  padding: 1px 4px 0;
  text-align: center;
}
.invoice .inv-meta td {
  border: 1px solid #000;
  text-align: center;
  vertical-align: top;
  padding: 3px 4px 0;
}
.invoice .inv-addr { margin: 0.2in 0 0 0.08in; }

.invoice .inv-parties {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 0.34in;
}
.invoice .inv-billto { margin-left: 0.63in; width: 2.97in; }
.invoice .inv-billto-bar {
  background: var(--tan);
  font-family: "Noto Serif", Georgia, serif;
  font-weight: 700;
  font-size: 13pt;
  line-height: 1.45;
  height: 0.19in;
  letter-spacing: 0;
  overflow: visible;
  display: flex;
  align-items: center;
}
.invoice .inv-billto-bar span { text-decoration: underline; text-underline-offset: 2px; }
.invoice .inv-billto .pick { top: 0; right: 4px; }
.invoice .inv-from { width: 3.9in; }
.invoice .inv-from .pick { top: -0.02in; }
.po .po-company { min-width: 3.9in; }
.invoice .inv-sideline { width: 2.98in; border-top: 1px solid var(--tan); margin-right: 0.06in; }

.invoice .items { margin-top: 0.16in; }
.invoice .items td.desc { padding-left: 0.13in; padding-right: 0.17in; }
.invoice .items th { background: var(--tan); }
/* FormSwift sizes invoice columns to their content: these are the widths with short item numbers,
   and the item column grows (taking room from the others) when an item number doesn't fit. */
.invoice .items { table-layout: auto; }
.invoice .c-qty { width: 11.7%; }
.invoice .c-item { width: 13.4%; }
.invoice .c-desc { width: 30%; }
.invoice .c-price { width: 22.9%; }
.invoice .c-total { width: 22%; }
.invoice .items td.item { padding: 3px 0.08in; }
.invoice .items td.item .f { white-space: nowrap; overflow-wrap: normal; }

.invoice .inv-sum {
  display: grid;
  grid-template-columns: 1fr 2.44in;
  grid-template-areas: ". sub" "terms tot";
  row-gap: 0.2in;
  margin-top: 0.16in;
  break-inside: avoid;
}
.invoice .inv-sub { grid-area: sub; }
.invoice .inv-terms { grid-area: terms; }
.invoice .inv-tot { grid-area: tot; }
.invoice .inv-sum .sum-line .lbl { width: 0.78in; }
.invoice .inv-sum .sum-line .val { flex: 1; padding-right: 0.08in; }
.invoice .sum-line.tax { border-bottom: 1px solid #000; padding-bottom: 1px; }
.invoice .sum-line.due .val { font-weight: 700; }
.invoice .inv-terms > div { display: flex; align-items: baseline; line-height: 1.1; min-height: 0.19in; }
.invoice .inv-terms .lbl { width: 2.01in; text-align: right; font-size: 9pt; padding-right: 0.15in; flex: none; }
.invoice .inv-terms .f { min-width: 1.5in; }

.invoice .inv-payable { text-align: center; margin-top: 0.26in; }
.invoice .inv-payable .f { text-align: left; }
.invoice .inv-thanks { text-align: center; font-weight: 700; font-size: 12pt; margin-top: 0.19in; }

/* ------------------------------ purchase order */

.po .po-head { display: flex; justify-content: space-between; align-items: flex-start; }
.po .po-company { padding-left: 0.07in; max-width: 4in; }
.po .po-title {
  font-family: "Noto Serif", Georgia, serif;
  font-weight: 700;
  font-size: 20pt;
  color: var(--green);
  margin: 0.14in 0.08in 0 0;
  line-height: 1;
  white-space: nowrap;
}
.po .po-meta { text-align: right; margin: 0.63in 0.08in 0 0; line-height: 1.25; }
.po .po-meta .lbl { color: var(--green-label); font-size: 10pt; }
.po .po-meta .f { text-align: right; min-width: 0; }

.po .po-parties { display: flex; margin-top: 0.08in; }
.po .po-party { display: flex; align-items: flex-start; width: 4in; }
.po .po-party.ship { width: auto; flex: 1; }
.po .po-party .lbl { color: var(--green-label); font-size: 10pt; flex: none; padding-top: 0.18in; line-height: 0.25in; margin-top: -0.03in; }
.po .po-party:first-child .lbl { width: 0.87in; padding-left: 0.07in; }
.po .po-party.ship .lbl { width: 0.74in; }
.po .po-party .f[data-f] { flex: 1; min-width: 0; min-height: 4.48em; }

.po .po-ship { width: 100%; table-layout: fixed; margin-top: 0.38in; }
.po .po-ship th {
  background: var(--green-fill);
  border: 1px solid var(--blue);
  font-size: 7.5pt;
  height: 0.28in;
  text-align: center;
}
.po .po-ship td { border: 1px solid var(--blue); text-align: center; height: 0.28in; padding: 1px 4px; }
.po .po-ship tr.spacer td { height: 0.23in; }

.po .items { margin-top: 0; }
.po .items th { background: var(--green-fill); border-top: 0; }
.po .c-qty { width: 11.8%; }
.po .c-item { width: 18.9%; }
.po .c-desc { width: 28.3%; }
.po .c-price { width: 20%; }
.po .c-total { width: 21%; }
.po .items td.item { text-align: left; padding-left: 0.08in; }

.po .po-sum { width: 2.93in; margin: 0.34in 0 0 auto; break-inside: avoid; }
.po .po-sum .sum-line .lbl { width: 1.27in; flex: none; }
.po .po-sum .sum-line .val { flex: 1; padding-right: 0.08in; }
.po .po-sum .sum-line { min-height: 0.19in; }
.po .po-sum .po-total { border-top: 1px solid #000; margin-top: 0.2in; padding-top: 1px; }
.po .po-sum .po-total .val { text-align: left; padding-left: 0.15in; }

.po .po-sigs { margin-top: 0.65in; break-inside: avoid; }
.po .sig {
  width: 3.84in;
  border-top: 1.5px solid #000;
  padding: 1px 0 0 0.08in;
  margin-bottom: 0.52in;
}

/* ------------------------------------------------------------------ print */

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

  html, body { background: #fff !important; }
  .topbar, .toast, .popover, .screen-only { display: none !important; }
  .canvas { display: block; padding: 0; overflow: visible; }

  .page {
    zoom: 1 !important;
    box-shadow: none;
    min-height: 0;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }
  .page .f:empty::before { content: none !important; }
  .page .rows tr.blank { display: none; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
