:root {
  --ui-bg: #edf1f5;
  --panel-bg: #ffffff;
  --ink: #17212f;
  --muted: #667385;
  --border: #dce2e9;
  --accent: #2463eb;
  --page-mono: "Courier New", Courier, monospace;
  --page-sans: Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--ui-bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; }
.topbar { height: 66px; background: #111c2d; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; box-shadow: 0 2px 12px rgba(14, 25, 41, .16); position: relative; z-index: 20; }
.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #4384ff, #2457be); font-weight: 800; font-size: 13px; letter-spacing: -.5px; }
.app-title { font-size: 15px; font-weight: 750; letter-spacing: .1px; }
.app-subtitle { font-size: 10px; color: #a9b8cc; margin-top: 2px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.btn { border: 1px solid transparent; border-radius: 7px; padding: 8px 12px; font-size: 11px; font-weight: 650; cursor: pointer; transition: .15s ease; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn-quiet { color: #d9e3f1; background: #1d2a3e; border-color: #34445c; }
.btn-quiet:hover { background: #293a53; }
.btn-primary { background: #2f70f5; color: #fff; box-shadow: 0 2px 6px rgba(47,112,245,.22); }
.btn-primary:hover { background: #1f5fdc; }
.btn-outline { background: #fff; border-color: #cbd6e4; color: #2a5ec4; }
.btn-small { padding: 7px 10px; font-size: 10px; }
.import-label { display: inline-flex; align-items: center; }
.workspace { height: calc(100vh - 66px); min-height: 650px; display: grid; grid-template-columns: 365px minmax(0, 1fr); }
.editor-panel { background: var(--panel-bg); border-right: 1px solid var(--border); overflow-y: auto; padding: 19px 18px 28px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; }
.eyebrow { color: #8190a4; font-size: 9px; font-weight: 800; letter-spacing: 1.3px; }
h1 { margin: 4px 0 0; font-size: 19px; letter-spacing: -.45px; }
h2 { margin: 4px 0 0; font-size: 14px; letter-spacing: -.2px; }
.icon-btn { width: 30px; height: 30px; border: 1px solid var(--border); background: #f9fafb; color: #536173; border-radius: 7px; cursor: pointer; font-size: 18px; }
.panel-intro { font-size: 11px; color: #69778a; line-height: 1.5; margin: 11px 0 16px; }
.control-group { border: 1px solid #e0e6ed; border-radius: 9px; margin-bottom: 10px; overflow: hidden; background: #fff; }
.control-group summary { list-style: none; cursor: pointer; padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 720; color: #273548; background: #fbfcfd; }
.control-group summary::-webkit-details-marker { display: none; }
.control-group summary:after { content: "＋"; color: #8593a5; font-size: 13px; font-weight: 400; }
.control-group[open] summary:after { content: "−"; }
.fields-grid { padding: 11px 12px 13px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px 10px; }
.field { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #607087; font-size: 9px; font-weight: 650; }
.field input, .field textarea, .field select, .item-field input { width: 100%; min-width: 0; border: 1px solid #dce3eb; background: #fff; color: #17212f; border-radius: 5px; padding: 6px 7px; font-size: 10px; outline: none; }
.field input:focus, .field textarea:focus, .field select:focus, .item-field input:focus { border-color: #6e9cff; box-shadow: 0 0 0 2px rgba(47,112,245,.10); }
.field textarea { resize: vertical; min-height: 44px; }
.section-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.control-section { border-top: 1px solid #e8edf2; padding-top: 16px; margin-top: 17px; }
.count-pill { background: #edf3ff; color: #2b64d4; border-radius: 99px; padding: 2px 6px; font-size: 9px; vertical-align: 2px; }
.item-hint { margin: 8px 0 10px; font-size: 10px; color: #7a8798; line-height: 1.4; }
.item-editors { display: flex; flex-direction: column; gap: 7px; }
.item-details { border: 1px solid #e1e7ee; border-radius: 7px; overflow: hidden; }
.item-details summary { list-style: none; display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 9px; background: #fafbfd; cursor: pointer; font-size: 10px; }
.item-details summary::-webkit-details-marker { display: none; }
.item-label { font-weight: 750; color: #273548; white-space: nowrap; }
.item-description { color: #778599; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.item-fields { padding: 9px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.item-field label { color: #748298; font-size: 8px; font-weight: 700; }
.item-field input { padding: 5px 6px; font-size: 9px; }
.item-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.delete-item { border: 0; background: none; color: #c14444; cursor: pointer; font-size: 9px; font-weight: 700; padding: 3px 0; }
.layout-section h2 { margin-bottom: 9px; }
.layout-subgroup { margin-top: 9px; border: 1px solid #e1e7ee; border-radius: 7px; overflow: hidden; }
.layout-subgroup summary { padding: 8px 9px; background: #fafbfd; font-size: 10px; font-weight: 750; cursor: pointer; list-style: none; }
.layout-subgroup summary::-webkit-details-marker { display: none; }
.layout-subgroup .fields-grid { padding: 9px; }
.panel-footnote { margin-top: 18px; padding: 11px; border-radius: 8px; background: #f5f8fc; color: #718097; font-size: 9px; line-height: 1.55; }
.panel-footnote strong { color: #42536a; }
.panel-footnote code { background: #e8eef6; padding: 1px 3px; border-radius: 3px; }
.preview-area { min-width: 0; display: flex; flex-direction: column; background: #e9edf2; }
.preview-toolbar { height: 45px; flex: 0 0 45px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #dce2e9; background: rgba(255,255,255,.66); }
.preview-label { font-size: 11px; font-weight: 750; color: #36465a; display: flex; align-items: center; gap: 7px; }
.preview-note { color: #8a97a8; font-size: 9px; font-weight: 500; margin-left: 4px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: #2eb67d; box-shadow: 0 0 0 3px rgba(46,182,125,.12); }
.zoom-controls { display: flex; align-items: center; gap: 7px; color: #657286; font-size: 10px; }
.zoom-btn { width: 25px; height: 23px; border-radius: 5px; border: 1px solid #d4dce6; background: #fff; color: #4f5f73; cursor: pointer; }
.fit-btn { width: auto; padding: 0 8px; }
.preview-viewport { flex: 1; overflow: auto; padding: 24px 20px 30px; display: flex; align-items: flex-start; justify-content: center; }
.paper-scaler { transform-origin: top center; width: 792pt; }
#paperContainer { width: 792pt; display: flex; flex-direction: column; gap: 22px; }
.invoice-page { width: 792pt; height: 612pt; position: relative; flex: 0 0 612pt; background: #fff; color: var(--page-ink, #111); overflow: hidden; box-shadow: 0 10px 30px rgba(29,42,59,.16); font-family: var(--page-mono); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.invoice-page * { box-sizing: border-box; }
.invoice-page .mono { font-family: var(--page-mono); white-space: pre; font-weight: 400; }
.invoice-page .sans { font-family: var(--page-sans); font-weight: 400; white-space: pre; }
.invoice-page .text-node { position: absolute; white-space: pre; line-height: 1.15; color: var(--page-ink, #111); }
.invoice-page .small-label { font-family: var(--page-sans); font-size: 7pt; }
.invoice-page .section-rule { position: absolute; height: 1.8pt; background: var(--page-rule, #000); left: 1.8pt; width: 799.2pt; }
.invoice-page .meta-vertical { position: absolute; width: .7pt; height: 26.6pt; background: var(--page-rule, #000); top: 130.36pt; }
.invoice-page .meta-text { position: absolute; font-family: var(--page-sans); font-size: 7pt; white-space: pre; }
.invoice-page .meta-value { position: absolute; font-family: var(--page-mono); font-size: 10pt; white-space: pre; }
.invoice-page .customer-box { position: absolute; width: 72pt; height: 31.5pt; border: .7pt solid var(--page-rule, #000); }
.invoice-page .customer-box .customer-number { position: absolute; top: 4.8pt; left: 0; width: 100%; text-align: center; font: 10pt var(--page-mono); }
.invoice-page .customer-box .customer-caption { position: absolute; left: 0; top: 20.6pt; width: 100%; text-align: center; height: 10pt; background: #dedede; border-top: .7pt solid #000; font: 9pt var(--page-sans); line-height: 9pt; }
.invoice-page .logo { position: absolute; object-fit: fill; }
.invoice-page .header-band { position: absolute; left: 0; width: 792pt; height: 23.4pt; background: var(--page-head-fill, #e5e5e5); border-top: 1.8pt solid var(--page-rule, #000); border-bottom: 1.8pt solid var(--page-rule, #000); }
.invoice-page .mono-line { position: absolute; left: 0; width: 792pt; height: 12pt; overflow: hidden; font: 8pt/9pt var(--page-mono); white-space: pre; margin: 0; padding: 0; }
.invoice-page .bold-mono-line { font-weight: 700; }
.invoice-page .item-line { position: absolute; left: 0; width: 792pt; height: 9pt; font: 8pt/9pt var(--page-mono); white-space: nowrap; overflow: visible; }
.invoice-page .item-cell { position: absolute; top: 0; height: 9pt; display: block; overflow: visible; white-space: pre; }
.invoice-page .item-cell.right { text-align: right; }
.invoice-page .item-cell.left { text-align: left; }
.invoice-page .footer-legal { position: absolute; left: 144pt; width: 610pt; font: 10pt/10.8pt var(--page-sans); white-space: pre; }
.invoice-page .shipped-from { position: absolute; left: 18pt; font: 12pt/14pt var(--page-mono); white-space: pre; }
.invoice-page .editable { outline: none; }
.invoice-page .editable:focus { outline: 1px dashed #3077f6; background: rgba(48,119,246,.08); }
body.direct-edit .invoice-page .editable { cursor: text; }
body.direct-edit .invoice-page .editable:hover { outline: 1px dashed rgba(48,119,246,.5); background: rgba(48,119,246,.045); }
.preview-footer { flex: 0 0 28px; display: flex; justify-content: space-between; align-items: center; color: #8491a2; font-size: 9px; padding: 0 18px; border-top: 1px solid #dce2e9; background: #f4f6f8; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 320px minmax(0,1fr); }
  .topbar { padding: 0 12px; }
  .toolbar-actions { gap: 5px; }
  .btn { padding: 7px 8px; font-size: 10px; }
}
@media (max-width: 760px) {
  .topbar { height: auto; min-height: 66px; flex-wrap: wrap; gap: 8px; padding: 10px; }
  .toolbar-actions { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .workspace { height: auto; min-height: 100vh; grid-template-columns: 1fr; }
  .editor-panel { max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .preview-area { min-height: 760px; }
  .preview-viewport { justify-content: flex-start; }
}
@page { size: letter landscape; margin: 0; }
@media print {
  html, body { width: 11in; height: 8.5in; margin: 0 !important; padding: 0 !important; background: #fff !important; overflow: visible !important; }
  .topbar, .editor-panel, .preview-toolbar, .preview-footer { display: none !important; }
  .workspace, .preview-area, .preview-viewport, .paper-scaler, #paperContainer { display: block !important; width: 792pt !important; height: auto !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; overflow: visible !important; transform: none !important; }
  #paperContainer { display: block !important; }
  .invoice-page { display: block !important; width: 792pt !important; height: 612pt !important; margin: 0 !important; box-shadow: none !important; page-break-after: always !important; break-after: page !important; }
  .invoice-page:last-child { page-break-after: auto !important; break-after: auto !important; }
  .invoice-page .editable:focus, .invoice-page .editable:hover { outline: none !important; background: transparent !important; }
}
