/* BBW Purchase Orders. The PO editor is drawn as the paper document itself;
   everything around it stays quiet. Accent = signature ink. */
:root {
  --desk: #eceeed;
  --sheet: #ffffff;
  --ink: #1b2430;
  --muted: #5b6471;
  --rule: #d5dbd8;
  --field: #ffffff;
  --field-rule: #b9c1bd;
  --signature: #23406e;
  --signature-ink: #ffffff;
  --signature-soft: #e6ecf5;
  --ok: #1f6b45;
  --warn: #8a5300;
  --bad: #a3271f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #12161c;
    --sheet: #1b2129;
    --ink: #e7ebf0;
    --muted: #9aa4b1;
    --rule: #2d3540;
    --field: #141920;
    --field-rule: #3d4652;
    --signature: #8fb0e6;
    --signature-ink: #0f1622;
    --signature-soft: #1f2b3d;
    --ok: #6fcf9a;
    --warn: #e9b764;
    --bad: #f0877d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--desk);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--signature); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 0; font-weight: 600; }
h3 { font-size: 1rem; margin: 0 0 0.75rem; font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0; }
.loading { color: var(--muted); }
.center { text-align: center; margin-top: 20vh; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- top bar */
.bar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.75rem 1.5rem;
  background: var(--sheet);
  border-bottom: 1px solid var(--rule);
}
.brand { font-weight: 600; color: var(--ink); text-decoration: none; }
#nav { display: flex; gap: 0.25rem; flex: 1; }
#nav a {
  color: var(--muted); text-decoration: none; padding: 0.35rem 0.7rem; border-radius: 4px;
}
#nav a:hover { color: var(--ink); background: var(--desk); }
#nav a[aria-current="page"] { color: var(--signature); background: var(--signature-soft); font-weight: 600; }
.account { display: flex; gap: 0.75rem; align-items: center; color: var(--muted); font-size: 0.9rem; }

/* ---------- page */
.page { max-width: 68rem; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.empty { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 2.5rem; text-align: center; }
.empty p { color: var(--muted); }
.signin { max-width: 26rem; margin: 18vh auto 0; padding: 2.5rem; background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; }
.signin p { color: var(--muted); }

/* ---------- buttons and fields */
button, .button {
  font: inherit; display: inline-block; text-decoration: none; cursor: pointer;
  border-radius: 4px; padding: 0.5rem 1.1rem; line-height: 1.4;
}
.primary { background: var(--signature); color: var(--signature-ink); border: 1px solid var(--signature); font-weight: 600; }
.primary:disabled { opacity: 0.6; cursor: wait; }
.quiet { background: transparent; color: var(--ink); border: 1px solid var(--field-rule); }
.quiet:hover { border-color: var(--ink); }
.link { background: none; border: none; padding: 0; color: var(--signature); text-decoration: underline; }
.danger { color: var(--bad); }
.quiet.danger { border-color: var(--bad); }
:focus-visible { outline: 3px solid var(--signature); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--field-rule); border-radius: 3px;
  padding: 0.4rem 0.55rem; width: 100%;
}
textarea { resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: transparent; border-color: transparent; color: var(--ink); padding-left: 0; opacity: 1; }
textarea:disabled { resize: none; }
select:disabled { appearance: none; -webkit-appearance: none; }
input[aria-invalid="true"] { border-color: var(--bad); }
.field { margin-bottom: 0.75rem; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.2rem; }
.check { display: flex; gap: 0.5rem; align-items: center; margin: 0.5rem 0 1rem; }
.check input { width: auto; }
.pair, .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 1.25rem; }
.actions .hint { margin: 0 0 0 auto; }

.message { margin: 1rem 0 0; }
.message-ok { color: var(--ok); }
.message-error { color: var(--bad); }
.message-info { color: var(--muted); }

/* ---------- status */
.status { font-size: 0.85rem; font-weight: 600; padding: 0.15rem 0.55rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.status-draft, .status-returned { color: var(--warn); }
.status-pending_verification, .status-pending_approval { color: var(--signature); }
.status-approved { color: var(--ok); }
.status-cancelled { color: var(--muted); }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.list-table { background: var(--sheet); border: 1px solid var(--rule); }
.list-table th, .list-table td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
.list-table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.list-table tr.inactive td { color: var(--muted); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-actions { text-align: right; white-space: nowrap; }

/* ---------- the PO sheet */
.toolbar { display: grid; grid-template-columns: 3fr 2fr; gap: 0 1rem; max-width: 56rem; }
.sheet {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 2px;
  padding: 2.25rem 2.5rem 2rem;
  box-shadow: 0 1px 0 var(--rule), 0 12px 32px -24px rgba(27, 36, 48, 0.45);
}
.po-top { display: grid; grid-template-columns: 1fr 17rem; gap: 2rem; padding-bottom: 1.25rem; border-bottom: 2px solid var(--ink); }
.letterhead { display: flex; gap: 1rem; align-items: flex-start; }
.letterhead p { margin: 0; font-size: 0.85rem; color: var(--muted); }
.letterhead .company-name { font-size: 1.05rem; font-weight: 700; color: var(--ink); margin-bottom: 0.2rem; }
.letterhead .reg { font-size: 0.75rem; font-weight: 600; }
.logo img { max-width: 5.5rem; max-height: 4.5rem; object-fit: contain; }
.doc-title { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.04em; text-align: right; margin: 0 0 0.5rem; }
.po-meta dl { margin: 0; }
.po-meta dl div { display: grid; grid-template-columns: 6.5rem 1fr; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.po-meta dt { font-size: 0.85rem; color: var(--muted); text-align: right; }
.po-meta dd { margin: 0; }
.po-meta input { padding: 0.25rem 0.45rem; }

.addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin: 1.5rem 0; }
fieldset { border: none; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 700; font-size: 0.9rem; padding: 0; margin-bottom: 0.6rem; }

.lines { margin-top: 0.5rem; }
.lines th { text-align: left; font-size: 0.85rem; padding: 0.5rem; background: var(--desk); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule); }
.lines td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.lines .line-no { width: 2.5rem; color: var(--muted); text-align: center; padding-top: 0.9rem; }
.lines td:nth-child(3) { width: 6rem; }
.lines td:nth-child(4) { width: 9rem; }
.lines .amount { width: 8.5rem; padding-top: 0.9rem; }
.lines textarea { min-height: 2.6rem; }
.add-line { margin-top: 0.75rem; }

.totals-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 2rem; margin-top: 1.5rem; }
.totals-row .field { width: 16rem; }
.totals { width: auto; min-width: 20rem; }
.totals th { text-align: right; font-weight: 400; color: var(--muted); padding: 0.35rem 1rem 0.35rem 0; }
.totals td { padding: 0.35rem 0; min-width: 8rem; }
.totals select { width: auto; padding: 0.15rem 0.35rem; margin-left: 0.25rem; }
.totals tr:last-child th, .totals tr:last-child td { border-top: 2px solid var(--ink); font-weight: 700; color: var(--ink); padding-top: 0.5rem; }
.terms { font-size: 0.75rem; color: var(--muted); margin: 2rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--rule); }

/* ---------- admin */
.admin-section { margin-bottom: 2.5rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.admin-section > .hint { margin-bottom: 0.75rem; }
.admin-form { background: var(--sheet); border: 1px solid var(--rule); border-top: 3px solid var(--signature); padding: 1.25rem 1.5rem; margin-top: 1rem; }
.logo-preview img { max-height: 4rem; max-width: 10rem; object-fit: contain; margin-top: 1.4rem; }

/* ---------- small screens */
@media (max-width: 52rem) {
  .po-top, .addresses, .toolbar, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .doc-title { text-align: left; }
  .po-meta dt { text-align: left; }
  .sheet { padding: 1.25rem; }
  .totals-row { flex-direction: column; align-items: stretch; }
  .totals { min-width: 0; width: 100%; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--rule); }
  .lines td { border: none; padding: 0; width: auto !important; }
  .lines td:nth-child(2), .lines td.line-no, .lines td.line-actions { grid-column: 1 / -1; }
  .lines td.line-no { text-align: left; padding: 0; font-weight: 600; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: 0.8rem; color: var(--muted); }
  .lines td.line-no::before { content: "Line "; }
  .bar { gap: 0.5rem 1rem; }
  .account { width: 100%; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Step 5: signing */
.banner { background: var(--signature-soft); border-left: 4px solid var(--signature); padding: 0.75rem 1rem; margin: 0 0 1.25rem; }
.banner-warn { background: transparent; border: 1px solid var(--warn); border-left-width: 4px; color: var(--ink); }
.banner-warn strong { color: var(--warn); }
.banner-ok { background: transparent; border: 1px solid var(--ok); border-left-width: 4px; }

.signoffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; margin-top: 1.75rem; }
.signoff p { margin: 0.1rem 0; font-size: 0.85rem; }
.signoff-title { font-weight: 700; font-size: 0.85rem !important; }
.signoff-sig { height: 4.5rem; border-bottom: 1px solid var(--ink); display: flex; align-items: flex-end; margin: 0.25rem 0 0.4rem; }
.signoff-sig img { max-height: 4.25rem; max-width: 100%; }
@media (prefers-color-scheme: dark) { .signoff-sig img, .sig-saved { background: #fff; border-radius: 3px; } }

.decision { background: var(--sheet); border: 1px solid var(--rule); border-top: 3px solid var(--signature); padding: 1.25rem 1.5rem; margin-top: 1.25rem; }
.decision h2 { margin-bottom: 0.5rem; }
.decision h3 { margin-top: 1.25rem; }
.decision-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 2rem; }
.sig-pad { display: block; width: 100%; max-width: 30rem; aspect-ratio: 3 / 1; background: #fff; border: 1px dashed var(--field-rule); border-radius: 3px; touch-action: none; cursor: crosshair; }
.sig-saved { display: block; max-width: 18rem; max-height: 6rem; border-bottom: 1px solid var(--rule); }
.sig-tools { display: flex; gap: 1rem; margin-top: 0.4rem; }

.picker { max-width: 30rem; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.2rem; }
.people { list-style: none; padding: 0; margin: 0.25rem 0 0; border: 1px solid var(--rule); border-radius: 3px; }
.people:empty { display: none; }
.people li + li { border-top: 1px solid var(--rule); }
.person { width: 100%; text-align: left; background: var(--sheet); border: none; border-radius: 0; padding: 0.5rem 0.75rem; color: var(--ink); }
.person:hover { background: var(--signature-soft); }
.chosen { display: flex; gap: 1rem; align-items: baseline; padding: 0.6rem 0.75rem; border: 1px solid var(--signature); border-radius: 3px; background: var(--signature-soft); }

.waiting-section { margin-bottom: 2.25rem; }
.waiting-section h2 { margin-bottom: 0.6rem; }
.list-table.waiting { border-left: 3px solid var(--signature); }

@media (max-width: 52rem) {
  .signoffs, .decision-grid { grid-template-columns: 1fr; gap: 1.25rem; }
}
