:root {
  --ink: #000;
  --line: #000;
  --paper: #ffffff;
  --serif: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #6b6e73;
  font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #1f2329;
  color: #f3f4f6;
  font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.tb-left { display: flex; align-items: center; gap: 10px; flex: 1 1 360px; }
.tb-title-label { font-size: 13px; font-weight: 600; white-space: nowrap; opacity: .9; }
.tb-title-input {
  flex: 1 1 auto;
  min-width: 200px;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid #3a4049;
  border-radius: 6px;
  background: #ffffff;
  color: #000000;
}
.tb-title-input::placeholder { color: #6b7280; }
.tb-title-input.needs-title {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, .35);
  animation: title-shake .3s ease;
}
@keyframes title-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.tb-actions { display: flex; gap: 10px; }
.btn {
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: #e5e7eb; color: #111827; }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }
.btn-ghost { background: transparent; color: #e5e7eb; border-color: #3a4049; }
.btn-ghost:hover:not(:disabled) { background: #2a2f37; }
.tb-status { flex-basis: 100%; font-size: 13px; min-height: 18px; }
.tb-status.ok { color: #4ade80; }
.tb-status.err { color: #f87171; }
.tb-status.info { color: #93c5fd; }

/* ---------- Sheet (US Letter @ ~96dpi) ---------- */
.sheet {
  width: 816px;
  min-height: 1056px;
  margin: 24px auto;
  padding: 30px 36px 26px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  font-size: 13px;
  line-height: 1.25;
  /* Default on-screen zoom (PDF export resets this to 1, see .exporting). */
  zoom: 1.2;
}
.sheet.exporting { zoom: 1; }

/* ---------- Header ---------- */
.hri-header { text-align: center; margin-bottom: 10px; }
.company {
  font-size: 34px;
  letter-spacing: 6px;
  font-weight: 700;
}
.addr { font-size: 13px; font-weight: 700; line-height: 1.35; }

/* ---------- Date / Show ---------- */
.dateshow { display: flex; align-items: flex-end; gap: 8px; margin: 8px 2px 6px; }
.lbl { font-weight: 700; white-space: nowrap; }
.ml { margin-left: 10px; }
.line { display: inline-flex; align-items: flex-end; }
.flex1 { flex: 1; }
.flex2 { flex: 2; }
.flex3 { flex: 3; }

.uline {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  padding: 0 2px 1px;
  outline: none;
}
.uline:focus { background: #fff7cc; }
.w-state { width: 90px; flex: 0 0 90px; }
.w-zip { width: 110px; flex: 0 0 110px; }

/* The e-mail line sits lower so descenders (j, g, p, y) clear the underline. */
.email-in { padding-bottom: 4px; }

/* Date pickers (Date + shipped-by-week). The native calendar indicator is
   hidden; a custom calendar button sits at the START of the line instead. */
.date-in {
  cursor: pointer;
  font-family: var(--serif);
  color: var(--ink);
}
.date-in::-webkit-calendar-picker-indicator { display: none; }
.cal-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0 4px 1px 0;
  border: none;
  background: transparent;
  color: #1f2937;
  cursor: pointer;
  line-height: 0;
}
.cal-btn:hover { color: #2563eb; }

/* ---------- Main body box ---------- */
.body-box { border: 1.5px solid var(--line); }

/* ---------- Parties ---------- */
.parties { display: grid; grid-template-columns: 1fr 1fr; }
.party { padding: 8px 12px 10px; }
.party-bill { border-right: 1.5px solid var(--line); }
.party-head { display: flex; align-items: flex-start; justify-content: space-between; min-height: 22px; margin-bottom: 4px; }
.party-title { font-weight: 700; font-size: 15px; text-decoration: underline; }
.ship-checks { display: flex; gap: 14px; }
.mini-check { display: flex; align-items: flex-start; gap: 3px; font-size: 8.5px; font-style: italic; font-weight: 700; line-height: 1.05; text-align: left; }
.mini-check input { margin: 1px 0 0; width: 11px; height: 11px; }

.field { display: flex; align-items: flex-end; gap: 6px; margin-top: 5px; }
.field .lbl { font-size: 13px; }
.field .uline { flex: 1; }
.field.invisible { visibility: hidden; }
.hint { font-size: 9.5px; font-style: italic; margin-top: 2px; }
.hint.center { text-align: center; }

/* ---------- Divider ---------- */
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 12px 6px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 0;
  border-top: 1.5px solid var(--line);
}
.divider span { font-weight: 700; font-size: 16px; letter-spacing: 1px; }

/* ---------- Order table ---------- */
.order-table { width: 100%; border-collapse: collapse; }
.order-table th, .order-table td { border: 1px solid var(--line); padding: 0; }
.order-table thead th {
  font-size: 12px; font-style: italic; font-weight: 700; text-align: center; padding: 2px 0;
}
.order-table .col-item { width: 18%; }
.order-table .col-total { width: 16%; }
.order-table tbody td { height: 26px; }
.cell-in {
  width: 100%; height: 26px; border: none; background: transparent;
  font-family: var(--serif); font-size: 15px; font-weight: 700; padding: 0 6px; outline: none;
}
.cell-in:focus { background: #fff7cc; }
.cell-in.num { text-align: right; }

/* ---------- Lower band ---------- */
.lower { display: grid; grid-template-columns: 1.35fr 1.5fr 1.15fr; border-top: 1.5px solid var(--line); }
.cell { border-right: 1px solid var(--line); padding: 6px 8px; }
.cell:last-child { border-right: none; }
.cell-head { font-weight: 700; text-align: center; font-size: 13.5px; margin-bottom: 4px; }

/* shipping list */
.ship-table { width: 100%; border-collapse: collapse; }
.ship-table th { font-size: 9.5px; font-weight: 700; text-align: left; border-bottom: 1px solid var(--line); padding: 1px 4px; }
.ship-table th:nth-child(2), .ship-table th:nth-child(3) { white-space: nowrap; }
.ship-table td { font-size: 11px; font-weight: 700; padding: 1px 4px; }
.ship-table td:nth-child(3) { font-size: 9px; font-weight: 400; white-space: nowrap; }

/* special instructions */
.special { display: flex; flex-direction: column; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 2px; font-style: italic; font-weight: 700; }
.check-row input { width: 13px; height: 13px; }
.ci { font-style: italic; }
.note-block { font-size: 10.5px; font-style: italic; margin: 8px 0 6px; line-height: 1.3; }
.othernotes { font-style: italic; font-weight: 700; }
.notes-area {
  flex: 1; margin-top: 3px; border: 1px solid var(--line); resize: none; background: transparent;
  font-family: var(--serif); font-size: 14px; font-weight: 700; outline: none; padding: 3px 4px;
}
.notes-area:focus { background: #fff7cc; }

/* totals */
.totals { display: flex; flex-direction: column; padding: 0; }
.t-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); min-height: 26px; }
.t-lbl { flex: 0 0 52%; display: flex; align-items: center; padding: 2px 6px; font-style: italic; font-weight: 700; border-right: 1px solid var(--line); }
.t-val { flex: 1; display: flex; align-items: center; padding: 2px 6px; font-weight: 700; }
.t-row.grand .t-lbl { font-style: normal; font-size: 14px; line-height: 1; }
.money-in {
  width: 100%; border: none; background: transparent; font-family: var(--serif);
  font-size: 15px; font-weight: 700; text-align: right; outline: none;
}
.money-in:focus { background: #fff7cc; }
.t-rate { padding: 4px 6px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.t-rate-lbl { font-size: 9px; font-style: italic; text-align: right; line-height: 1.1; }
.t-rate-in { font-weight: 700; white-space: nowrap; }
.rate-in {
  width: 42px; border: none; border-bottom: 1px solid var(--line); background: transparent;
  font-family: var(--serif); font-size: 15px; font-weight: 700; text-align: right; outline: none;
}
.rate-in:focus { background: #fff7cc; }

/* ---------- Ship week / payment ---------- */
.shipweek { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px 2px; border-top: 1.5px solid var(--line); }
.payment { display: flex; justify-content: space-between; gap: 6px; padding: 8px 16px 4px; }
.pay { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 15px; }
.pay input { width: 15px; height: 15px; }
.pay-notes { padding: 0 16px; }
.pay-note { font-size: 9px; font-style: italic; }
.copy-note { text-align: center; font-size: 10px; font-weight: 700; padding: 4px 0 6px; }

/* ---------- PDF capture mode ---------- */
.sheet.exporting .uline:focus,
.sheet.exporting .cell-in:focus,
.sheet.exporting .money-in:focus,
.sheet.exporting .rate-in:focus,
.sheet.exporting .notes-area:focus { background: transparent; }

/*
 * html2canvas renders input text lower than the browser does, which pushes
 * the typed text down onto (and partly under) the underline. During export we
 * add bottom padding so the text baseline is lifted clear of the line. The
 * negative margin keeps surrounding layout from shifting.
 */
.sheet.exporting .uline {
  padding-bottom: 6px;
  margin-bottom: -5px;
}
.sheet.exporting .email-in {
  padding-bottom: 14px;
  margin-bottom: -13px;
}
/* Date/Show: bring the underline up closer to the text (smaller gap). */
.sheet.exporting .dateshow .uline {
  padding-bottom: 2px;
  margin-bottom: -1px;
}
.sheet.exporting .money-in {
  padding-bottom: 6px;
  margin-bottom: -5px;
}
.sheet.exporting .rate-in {
  padding-bottom: 6px;
  margin-bottom: -5px;
}
.sheet.exporting .cell-in { padding-bottom: 6px; }

/* The calendar buttons are interactive controls; omit them from the PDF. */
.sheet.exporting .cal-btn { display: none; }
