@font-face {
  font-family: "MICR";
  src: url("fonts/micrenc.ttf") format("truetype");
}

:root {
  --accent: #2e1a47;
  --ui-bg: #f3f4f7;
  --ui-panel: #ffffff;
  --ui-border: #d9dce3;
  --ui-text: #1d2330;
  --ui-muted: #667085;
  --off-x: 0mm;
  --off-y: 0mm;
  --zoom: 0.75;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ui-text);
  background: var(--ui-bg);
}

/* ---------- App chrome ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand small { display: block; color: var(--ui-muted); font-size: 11px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.void-pill {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  color: #b42318; background: #fee4e2; border: 1px solid #fda29b;
  padding: 4px 10px; border-radius: 999px;
}

button {
  font: inherit; font-size: 13px;
  padding: 7px 12px; border-radius: 6px;
  border: 1px solid var(--ui-border); background: #fff; color: var(--ui-text);
  cursor: pointer;
}
button:hover { background: #f6f7fa; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.1); }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100% - 53px);
}
.panel {
  overflow: auto;
  border-right: 1px solid var(--ui-border);
  background: var(--ui-panel);
  padding: 8px 12px 40px;
}
.panel details { border-bottom: 1px solid var(--ui-border); padding: 6px 0 10px; }
.panel summary { font-weight: 600; font-size: 13px; cursor: pointer; padding: 6px 0; }
.panel label { display: block; font-size: 12px; color: var(--ui-muted); margin: 8px 0 0; }
.panel label.chk { display: flex; gap: 8px; align-items: center; margin-top: 10px; color: var(--ui-text); }
.panel input:not([type=checkbox]):not([type=range]):not([type=color]),
.panel select {
  display: block; width: 100%; margin-top: 3px;
  font: inherit; font-size: 13px; color: var(--ui-text);
  padding: 6px 8px; border: 1px solid var(--ui-border); border-radius: 6px; background: #fff;
}
.panel input[type=color] { width: 48px; height: 28px; padding: 0; border: 1px solid var(--ui-border); border-radius: 6px; margin-top: 3px; }
.bank-preview { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--ui-text); min-height: 28px; }
.bank-preview svg, .bank-preview img { width: 28px; height: 28px; object-fit: contain; }
.bank-preview .muted { color: var(--ui-muted); font-size: 11px; }
.panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel .row button { margin-top: 8px; }
.hint { font-size: 11px; color: var(--ui-muted); line-height: 1.4; margin: 8px 0 0; }
.register { max-height: 160px; overflow: auto; font-size: 11px; margin-top: 8px; border: 1px solid var(--ui-border); border-radius: 6px; }
.register table { width: 100%; border-collapse: collapse; }
.register td, .register th { padding: 3px 6px; border-bottom: 1px solid #eef0f4; text-align: left; white-space: nowrap; }
.register th { background: #f6f7fa; font-weight: 600; }
.register .empty { padding: 10px; color: var(--ui-muted); }

.preview-wrap { overflow: auto; padding: 16px 24px 60px; }
.preview-toolbar { display: flex; gap: 18px; align-items: center; font-size: 12px; color: var(--ui-muted); margin-bottom: 12px; }
.preview-toolbar label, .preview-toolbar label.chk { display: flex; gap: 6px; align-items: center; }

/* ---------- Page (physical units) ---------- */
.page {
  position: relative;
  width: 8.5in;
  height: 11in;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  transform: scale(var(--zoom));
  transform-origin: top left;
  overflow: hidden;
}
.page.layout-single { height: 3.5in; }
.page.pdf-render { position: fixed; left: 0; top: 0; z-index: -1; transform: none; box-shadow: none; }

.slot {
  position: absolute;
  left: 0;
  width: 8.5in;
  padding-left: var(--off-x);
  padding-top: var(--off-y);
}
.perf {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 1px dashed #b7b7b7;
}
.page.no-guides .perf { display: none; }

/* ---------- The check (8.5 x 3.5) ---------- */
.check {
  position: relative;
  width: 8.5in;
  height: 3.5in;
  color: #111;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 9pt;
  overflow: hidden;
  --accent: #2e1a47;
  --accent-rgb: 46, 26, 71;
}
.check .paper {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0.625in; /* keep the MICR clear band unprinted */
}
.check .paper.pattern-linen {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.028) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.028) 0 1px, transparent 1px 3px),
    linear-gradient(135deg, rgba(var(--accent-rgb), .09), rgba(255,255,255,0) 45%, rgba(var(--accent-rgb), .12)),
    #fff;
}
.check .paper.pattern-marble {
  background:
    radial-gradient(ellipse at 20% 30%, rgba(var(--accent-rgb), .10), transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(var(--accent-rgb), .14), transparent 55%),
    #fbfbfd;
}
.check .paper.pattern-none { background: transparent; }
.check.preprinted .static, .check.preprinted .paper { visibility: hidden; }

.check .border {
  position: absolute; inset: 0.12in 0.18in 0.7in 0.18in;
  border: 1.5px solid var(--accent);
  border-radius: 3px;
  pointer-events: none;
}
.check .border::after {
  content: ""; position: absolute; inset: 3px;
  border: 0.5px solid rgba(var(--accent-rgb), .45);
  border-radius: 2px;
}

.check .company {
  position: absolute; left: 0.4in; top: 0.28in;
  display: flex; gap: 0.12in; align-items: center;
}
.check .company img { max-height: 0.5in; max-width: 0.9in; object-fit: contain; }
.check .company .name { font-weight: 700; font-size: 12pt; color: var(--accent); letter-spacing: .01em; }
.check .company .addr { font-size: 7.5pt; line-height: 1.3; color: #333; }

.check .bank {
  position: absolute; left: 3.75in; top: 0.28in; width: 2.1in;
  display: flex; gap: 0.08in; align-items: center;
  font-size: 7.5pt; line-height: 1.3; color: #333;
}
.check .bank .bankmark, .check .bank .banklogo { flex: 0 0 auto; width: 0.36in; height: 0.36in; object-fit: contain; }
.check .bank .banklogo { width: auto; max-width: 0.7in; }
.check .bank .bankname { font-weight: 700; font-size: 10pt; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.check .bank .fractional { font-size: 7pt; color: #555; margin-top: 2px; }

.check .number {
  position: absolute; right: 0.4in; top: 0.24in;
  font-weight: 700; font-size: 13pt; color: var(--accent);
  font-family: "Courier New", Courier, monospace;
}
.check .date {
  position: absolute; right: 0.4in; top: 0.72in; width: 1.7in;
  display: flex; align-items: flex-end; gap: 6px; font-size: 7.5pt; color: #444;
}
.check .date .val {
  flex: 1; border-bottom: 1px solid #333; padding: 0 4px 1px;
  font-family: "Courier New", Courier, monospace; font-size: 10pt; color: #111; text-align: center;
}

.check .payline {
  position: absolute; left: 0.4in; right: 2.1in; top: 1.27in;
  display: flex; align-items: flex-end; gap: 8px;
}
.check .payline .lbl { font-size: 6.5pt; line-height: 1.1; color: #444; width: 0.62in; text-transform: uppercase; font-weight: 600; }
.check .payline .val {
  flex: 1; border-bottom: 1px solid #333; padding: 0 4px 2px;
  font-family: "Courier New", Courier, monospace; font-size: 10.5pt; min-height: 0.22in;
}
.check .amountbox {
  position: absolute; right: 0.4in; top: 1.2in; width: 1.55in; height: 0.3in;
  border: 1.5px solid var(--accent); border-radius: 2px; background: rgba(255,255,255,.7);
  display: flex; align-items: center; padding: 0 6px; gap: 4px;
  font-family: "Courier New", Courier, monospace; font-size: 10.5pt; font-weight: 700;
}
.check .amountbox .cur { color: var(--accent); }

.check .words {
  position: absolute; left: 0.4in; right: 0.4in; top: 1.72in;
  display: flex; align-items: flex-end; gap: 8px;
}
.check .words .val {
  flex: 1; border-bottom: 1px solid #333; padding: 0 4px 2px;
  font-family: "Courier New", Courier, monospace; font-size: 9.5pt; letter-spacing: .01em; white-space: nowrap; overflow: hidden;
}
.check .words .lbl { font-size: 7.5pt; font-weight: 700; color: #444; }

.check .memo {
  position: absolute; left: 0.4in; top: 2.3in; width: 3.6in;
  display: flex; align-items: flex-end; gap: 6px; font-size: 7.5pt; color: #444;
}
.check .memo .val { flex: 1; border-bottom: 1px solid #333; padding: 0 4px 1px; font-family: "Courier New", Courier, monospace; font-size: 9pt; color: #111; }

.check .signature {
  position: absolute; right: 0.4in; top: 2.16in; width: 3in;
  text-align: center; font-size: 6.5pt; color: #444;
}
.check .signature .line { border-bottom: 1px solid #333; height: 0.28in; margin-bottom: 2px; }
.check .signature .voidafter { position: absolute; right: 0; top: -0.14in; font-size: 6.5pt; color: #444; font-weight: 600; }

.check .security {
  position: absolute; left: 0.4in; bottom: 0.72in;
  font-size: 5.5pt; color: #666; display: flex; align-items: center; gap: 4px;
}
.check .security .lock { font-size: 7pt; }

/* MICR clear band: bottom 5/8". Baseline ~ 1/4" from bottom edge, 8 cpi. */
.check .micr {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0.625in;
  font-family: "MICR", monospace;
  font-size: 0.25in;         /* glyph advance = 0.5em = 0.125in = 8 characters per inch */
  line-height: 1;
  color: #000;
}
.check .micr span {
  position: absolute;
  bottom: 0.21in;
  width: 0.125in;
  text-align: center;
}
.page.no-guides .check .micr-band { display: none; }
.check .micr-band {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0.625in;
  background: repeating-linear-gradient(90deg, rgba(46,26,71,.05) 0 0.125in, rgba(46,26,71,.02) 0.125in 0.25in);
  border-top: 1px dashed rgba(46,26,71,.35);
}

.check .void {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  z-index: 3;
}
.check .void span {
  font-weight: 900; font-size: 92pt; letter-spacing: .25em;
  color: rgba(180, 35, 24, .30);
  transform: rotate(-18deg);
  border: 6px solid rgba(180, 35, 24, .30);
  border-radius: 14px;
  padding: 0 .3em;
  line-height: 1.05;
}
.check .void small {
  position: absolute; left: 0.4in; top: 0.05in;
  font-size: 6pt; font-weight: 700; color: #b42318; letter-spacing: .1em; transform: none; border: 0; padding: 0;
}

/* ---------- Voucher stubs ---------- */
.stub {
  position: relative; width: 8.5in; height: 3.6667in;
  padding: 0.35in 0.45in; font-size: 8.5pt; color: #222;
}
.stub h4 { margin: 0 0 4px; font-size: 9pt; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.stub .meta { display: flex; justify-content: space-between; color: #555; font-size: 8pt; margin-bottom: 8px; }
.stub table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
.stub th, .stub td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #ddd; }
.stub th { color: #555; font-weight: 600; font-size: 7.5pt; text-transform: uppercase; }
.stub td.num, .stub th.num { text-align: right; font-family: "Courier New", monospace; }
.stub .foot { position: absolute; bottom: 0.3in; left: 0.45in; right: 0.45in; display: flex; justify-content: space-between; font-size: 7.5pt; color: #777; }
.stub .void-tag { color: #b42318; font-weight: 700; }

/* ---------- Print ---------- */
@media print {
  @page { size: 8.5in 11in; margin: 0; }
  html, body { background: #fff; height: auto; }
  .no-print, .panel, .topbar, .preview-toolbar { display: none !important; }
  .layout { display: block; height: auto; }
  .preview-wrap { padding: 0; overflow: visible; }
  .page { transform: none; box-shadow: none; }
  .perf, .micr-band { display: none !important; }
}
.page.single-print { }
@media print { .page.layout-single { height: 3.5in; } }
