@font-face {
  font-family: Kanit;
  src: local("Kanit"), local("Kanit Regular"), url("assets/Kanit-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Kanit;
  src: local("Kanit Medium"), url("assets/Kanit-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: Kanit;
  src: local("Kanit Bold"), url("assets/Kanit-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #171d28;
  --muted: #525d6d;
  --nav: #20293b;
  --accent: #214da7;
  --accent-light: #edf2fb;
  --surface: #fff;
  --ground: #f2f4f7;
  --line: #dce1e8;
  --rule: #e9edf2;
  --control: #929eaf;
  --warn: #79420b;
  --warn-light: #fff2d9;
  --error: #982c42;
  --error-light: #fff1f2;
  --success: #176245;
  --success-light: #e6f3ec;
  --focus: #2554cc;
  --chart-in: #007594;
  --chart-out: #8490a0;
  --panel-radius: 10px;
  --control-radius: 7px;
  --space: 16px;
  --gutter: 32px;
  --nav-width: 216px;
  --touch: 44px;
  --layer-shadow: 0 12px 36px rgb(10 23 64 / 16%);
  --gradient: linear-gradient(to right, #c76cab 0 35%, #00b9f2 100%);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.5 Kanit, system-ui, sans-serif;
}
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
a { color: inherit; }
input, select, textarea, button { color: inherit; font: inherit; }
button { cursor: pointer; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: #b7dce4; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
::selection { background: #bce2ec; color: var(--nav); }
strong { font-weight: 500; }
small { font-size: .875rem; }
#shell { display: grid; grid-template-columns: var(--nav-width) minmax(0, 1fr); min-height: 100dvh; }
.workspace { min-width: 0; }
.wrap { width: min(calc(100% - 2 * var(--gutter)), 1300px); margin-inline: auto; }
.masthead {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 22px 14px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding-inline: 5px;
  text-decoration: none;
  width: fit-content;
}
.brand img { object-fit: contain; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; font-weight: 500; line-height: 1.2; }
.brand small, .workspace-domain { color: var(--muted); font-size: 13px; }
.workspace-domain { margin-top: auto; padding: 14px 9px 0; border-top: 1px solid var(--line); }
.desktop-nav { display: grid; gap: 4px; }
nav a, .more-nav summary {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: var(--touch);
  padding: 8px 10px;
  border-radius: var(--control-radius);
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
nav a:hover, .more-nav summary:hover { background: var(--ground); color: var(--ink); }
nav [aria-current] { background: #e9edf3; color: var(--ink); font-weight: 500; }
.desktop-nav a { border-inline-start: 2px solid transparent; }
.desktop-nav a[aria-current] { border-inline-start-color: var(--nav); }
.mobile-nav { display: none; }
.sample-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding-inline: var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.sample-banner strong { color: var(--ink); margin-inline-end: 8px; }
.text-button {
  min-height: var(--touch);
  border: 0;
  padding: 4px 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-button:hover { color: var(--nav); }
.main { padding-block: 30px 64px; }
.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}
h1 { font-size: 1.875rem; font-weight: 500; line-height: 1.22; overflow-wrap: anywhere; }
h1:focus, #preview-title:focus { outline: none; }
h2 { font-size: 1.0625rem; font-weight: 500; }
.button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  text-decoration: none;
  font-weight: 500;
  text-align: center;
  line-height: 1.3;
}
.button:hover, .icon-button:hover { background: var(--accent-light); }
.button.primary { background: var(--nav); color: white; border-color: var(--nav); }
.button.primary:hover { background: #33415b; }
.button:disabled { opacity: .55; cursor: wait; }
.button.quiet { background: transparent; color: var(--muted); }
.button.quiet:hover { background: var(--accent-light); color: var(--ink); }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: #fff;
}
svg { flex-shrink: 0; }
.numeric, .summary dd, .deal-amount { font-variant-numeric: tabular-nums; }
.summary {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
  overflow: hidden;
}
.summary div { padding: 16px 20px; }
.summary div + div { border-left: 1px solid var(--line); }
.summary dt { font-size: .9375rem; color: var(--muted); }
.summary dd { font-size: clamp(1.28rem, 2.3vw, 2rem); font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }
.summary dd small { font-size: .94rem; color: var(--muted); font-weight: 400; }
.list-panel, .detail-flow, .detail-invoices, .doc-sidebar, .editor-form, .preview-panel {
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
}
.list-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.list-bar h2 span {
  display: inline-block;
  min-width: 24px;
  margin-left: 4px;
  font-size: .8125rem;
  text-align: center;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent);
}
.list-bar small { color: var(--muted); }
.compact-label { display: flex; align-items: center; gap: 10px; font-size: .9375rem; }
select, input:not([type="checkbox"], [type="radio"]), textarea {
  min-width: 0;
  max-width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--control);
  border-radius: var(--control-radius);
  background: #fff;
  min-height: var(--touch);
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
textarea { resize: vertical; }
.deal-columns, .deal-row {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(294px, 1.8fr) minmax(125px, .65fr) 18px;
  align-items: center;
  gap: 24px;
  padding-inline: 22px;
}
.deal-columns { border-bottom: 1px solid var(--rule); color: var(--muted); font-size: .875rem; padding-block: 10px; }
.deal-columns :nth-child(2) { text-align: center; }
.deal-columns :nth-child(3) { text-align: right; }
.deal-list, .document-list, .pending-list { list-style: none; padding: 0; }
.deal-list > li + li, .pending-list > li + li { border-top: 1px solid var(--line); }
.deal-list > li:last-child .deal-row { border-radius: 0 0 12px 12px; }
.deal-row { padding-block: 18px; text-decoration: none; min-height: 102px; }
.deal-row:hover, .pending-list a:hover { background: #f7fafb; }
.deal-name { min-width: 0; overflow-wrap: anywhere; }
.deal-name strong, .deal-name > span { display: block; }
.deal-name strong { line-height: 1.3; margin-bottom: 3px; font-size: 1.05rem; }
.deal-name > span { font-size: .875rem; line-height: 1.4; color: var(--muted); }
.deal-name .reference { margin-top: 4px; color: var(--accent); }
.deal-amount { text-align: right; }
.deal-amount > strong { display: block; font-size: 1.12rem; }
.deal-amount small { color: var(--muted); font-weight: 400; }
.chip {
  display: inline-block;
  width: fit-content;
  border-radius: 6px;
  padding: 3px 9px;
  color: var(--accent);
  background: var(--accent-light);
  font-size: .8125rem;
  text-align: center;
}
.deal-amount .chip { margin-bottom: 4px; }
.chip-invoice, .chip-partial { color: var(--warn); background: var(--warn-light); }
.chip-accepted, .chip-receipt { color: var(--success); background: var(--success-light); }
.chip-cancelled { color: var(--error); background: var(--error-light); }
.row-arrow { display: flex; color: var(--accent); }
.timeline {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0;
  padding: 0;
}
.timeline li { position: relative; min-width: 0; text-align: center; font-size: .8125rem; color: var(--muted); }
.timeline li:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 9px;
  left: calc(50% + 10px);
  width: calc(100% - 20px);
  height: 1px;
  background: #bfcdd0;
}
.timeline li.done:has(+ .done)::after { background: var(--accent); }
.step-dot {
  position: relative;
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  margin: 0 auto 5px;
  border: 1px solid #9caeb3;
  border-radius: 50%;
  background: #fff;
}
.step-dot svg { width: 16px; height: 16px; border-radius: 50%; }
.timeline .done { color: var(--ink); }
.timeline .done .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.timeline .done .step-label { font-weight: 500; }
.timeline small { display: block; color: var(--muted); font-size: .75rem; }
.empty { padding: 24px 22px; color: var(--muted); }
.back-link { min-height: var(--touch); display: inline-flex; gap: 7px; align-items: center; margin-bottom: 12px; color: var(--accent); text-decoration: none; }
.back-icon { display: flex; transform: rotate(180deg); }
.back-link:hover { text-decoration: underline; }
.detail-customer { margin: -13px 0 20px; color: var(--muted); }
.detail-flow, .detail-invoices { padding: 12px 20px; margin-bottom: 18px; }
.detail-flow .timeline { max-width: 720px; }
.timeline-installments { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.timeline-installments .step-label { display: block; padding-inline: 2px; }
.deal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 14px; margin-top: 16px; }
.deal-actions:empty { display: none; }
.deal-actions > span { color: var(--muted); font-size: .9rem; }
.invoice-row { display: flex; gap: 10px 16px; align-items: center; flex-wrap: wrap; padding-top: 10px; }
.invoice-row + .invoice-row { border-top: 1px solid var(--rule); margin-top: 10px; }
.invoice-row a, .ledger-table a { min-height: var(--touch); display: inline-flex; align-items: center; color: var(--accent); text-underline-offset: 3px; }
.invoice-row .button { margin-left: auto; }
.invoice-balances { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.invoice-balances dt { color: var(--muted); font-size: .82rem; }
.invoice-balances dd { margin: 0; font-weight: 500; }
.detail-grid, .editor-grid { display: grid; gap: 22px; align-items: start; }
.detail-grid { grid-template-columns: minmax(250px, .6fr) minmax(0, 1.4fr); }
.editor-grid { grid-template-columns: minmax(360px, .78fr) minmax(0, 1.22fr); }
.doc-sidebar { padding: 16px; }
.doc-sidebar h2 { margin-bottom: 10px; }
.document-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--control-radius);
  padding: 11px 8px;
  text-decoration: none;
}
.document-list a:hover, .document-list a[aria-current] { background: var(--accent-light); color: var(--accent); }
.document-list a > span { flex: 1; min-width: 0; }
.document-list small { display: block; font-size: .78rem; color: var(--muted); }
.saved-plan { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 12px; }
.plan-lines { list-style: none; padding: 0; }
.plan-lines li { display: flex; justify-content: space-between; align-items: start; gap: 8px; padding: 6px 0; }
.plan-lines span { min-width: 0; overflow-wrap: anywhere; }
.plan-lines small { display: block; color: var(--muted); }
.plan-lines strong { flex-shrink: 0; font-size: .9rem; }
.history { border-top: 1px solid var(--line); margin-top: 10px; padding: 11px 0 0; }
.history summary { min-height: var(--touch); padding-block: 10px; cursor: pointer; }
.history ol { padding-left: 25px; padding-top: 8px; }
.history li { padding-block: 4px; }
.history li div { font-size: .84rem; color: var(--muted); overflow-wrap: anywhere; }
.form-section { display: grid; gap: 12px; padding: 16px 20px; }
.form-section + .form-section { border-top: 1px solid var(--line); }
.field { display: grid; gap: 4px; min-width: 0; font-size: .92rem; }
.field > span { color: var(--muted); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-section > .button { justify-self: start; }
.item-fields, .plan-fields {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  margin: 0;
  padding: 10px 12px 12px;
  display: grid;
  gap: 8px;
}
.item-fields + .item-fields, .plan-fields + .plan-fields { margin-top: 13px; }
.item-fields legend, .plan-fields legend { padding-inline: 5px; color: var(--muted); font-size: .875rem; }
#custom-plan > .button { margin-top: 12px; }
.item-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) var(--touch); gap: 8px; align-items: end; }
.switches, .choices { display: grid; gap: 9px; }
.switches label, .choices label { display: flex; align-items: center; gap: 8px; min-height: var(--touch); cursor: pointer; }
.preview-panel { background: #e9edf3; min-width: 0; overflow: hidden; }
.live-preview { position: sticky; top: 12px; }
.preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.preview-bar small { color: var(--muted); flex-shrink: 0; }
.paper-stage { margin: 15px; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }
.preview-jump { display: none; }
.ledger-panel + .ledger-panel { margin-top: 20px; }
.ledger-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ledger-table th, .ledger-table td { padding: 11px 12px; text-align: left; vertical-align: top; }
.ledger-table th { border-bottom: 1px solid var(--rule); color: var(--muted); font-weight: 500; }
.ledger-table th:first-child, .ledger-table td:first-child { padding-left: 22px; }
.ledger-table th:last-child, .ledger-table td:last-child { padding-right: 22px; }
.ledger-table tr + tr td { border-top: 1px solid var(--line); }
.ledger-table td small { display: block; color: var(--muted); font-size: .8rem; }
.ledger-table .numeric, .ledger-table th:nth-last-child(-n+4) { text-align: right; }
.total-value { font-weight: 500; }
.mobile-cell-label { display: none; }
.pending-list a {
  display: grid;
  grid-template-columns: 1fr auto 18px;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  padding: 12px 22px;
}
.pending-list a small { display: block; color: var(--muted); }
dialog {
  width: min(470px, calc(100% - 28px));
  max-height: calc(100% - 36px);
  color: var(--ink);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  box-shadow: var(--layer-shadow);
}
dialog::backdrop { background: rgb(10 23 64 / 54%); }
.dialog-heading, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--ground);
}
.dialog-heading { border-bottom: 1px solid var(--line); }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); }
.dialog-body { display: grid; gap: 11px; padding: 14px 16px; }
.dialog-context { color: var(--muted); }
.invoice-due, .deal-next { color: var(--muted); }
.invoice-due { display: block; }
.choices { border: 1px solid var(--line); border-radius: var(--control-radius); margin: 0; padding: 5px 11px 9px; }
.choices legend { padding-inline: 5px; }
.calculation { color: var(--accent); font-size: .95rem; }
.error { color: var(--error); }
#notice:not(:empty) {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: calc(100% - 36px);
  padding: 10px 16px;
  border-radius: var(--control-radius);
  color: white;
  background: var(--nav);
  box-shadow: var(--layer-shadow);
}
.workspace:has(.paper-stage) #notice:not(:empty) {
  position: static;
  width: max-content;
  margin: 10px var(--gutter) 0 auto;
}

.paper-stage { position: relative; }
.paper-open, .paper-hint { display: none; }
#paper-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
}
.paper-tools { display: flex; align-items: center; gap: 4px; }
.paper-viewport { overflow: auto; padding: 8px; background: var(--surface); }
.paper-viewport .paper { margin-inline: auto; }

@media (max-width: 1099px) {
  :root { --gutter: 24px; }
  #shell { display: block; }
  .masthead { position: static; min-height: 58px; height: auto; display: block; padding: 5px var(--gutter); border: 0; }
  .brand { min-height: 48px; padding: 0; }
  .brand img { width: 35px; height: 35px; }
  .brand strong { font-size: 16px; }
  .desktop-nav, .workspace-domain { display: none; }
  .sample-banner { min-height: var(--touch); border-top: 1px solid var(--rule); }
  html { scroll-padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .main { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed;
    z-index: 3;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 3px 8px max(3px, env(safe-area-inset-bottom));
    color: var(--surface);
    background: var(--surface);
    border-top: 1px solid var(--line);
  }
  .mobile-nav > a, .more-nav summary {
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    min-height: 54px;
    padding: 4px 2px;
    font-size: 12px;
    text-align: center;
  }
  .more-nav summary { list-style: none; }
  .more-nav summary::-webkit-details-marker { display: none; }
  .more-panel {
    position: absolute;
    right: 12px;
    bottom: calc(100% + 8px);
    min-width: 156px;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--panel-radius);
    box-shadow: var(--layer-shadow);
  }
  #notice:not(:empty) { bottom: calc(72px + env(safe-area-inset-bottom)); }
  .deal-columns, .deal-row { grid-template-columns: minmax(0, 1fr) minmax(258px, 1.72fr) minmax(110px, .62fr) 16px; gap: 12px; padding-inline: 16px; }
  .editor-grid { grid-template-columns: minmax(320px, 1fr) minmax(0, 1fr); gap: 14px; }
}

@media (max-width: 710px) {
  :root { --gutter: 16px; }
  .sample-banner { gap: 6px; font-size: 12px; }
  .sample-banner strong { margin-inline-end: 3px; }
  .sample-banner .text-button { text-align: end; }
  .main { padding-top: 20px; }
  h1 { font-size: 1.7rem; }
  .page-heading { flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
  .page-heading .button { font-size: .875rem; }
  .summary { grid-auto-flow: row; grid-auto-rows: minmax(0, auto); margin-bottom: 18px; }
  .summary div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 12px; }
  .summary div + div { border-left: 0; border-top: 1px solid var(--line); }
  .summary dt { font-size: .875rem; }
  .summary dd { font-size: 1.15rem; text-align: right; }
  .summary dd small { font-size: .8rem; }
  .list-bar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .list-bar h2 { font-size: 1rem; }
  .compact-label { gap: 6px; font-size: .875rem; }
  [name="known"] { text-overflow: ellipsis; }
  .compact-label select { padding-inline: 6px; max-width: 133px; }
  .deal-columns, .row-arrow { display: none; }
  .deal-row { grid-template-columns: minmax(0, 1fr) minmax(95px, auto); gap: 12px 7px; padding: 14px 11px; }
  .deal-name strong { font-size: .975rem; }
  .deal-name > span { font-size: .79rem; }
  .deal-amount { grid-row: 1; grid-column: 2; align-self: start; }
  .deal-amount > strong { font-size: .98rem; }
  .deal-amount small, .deal-amount .chip { font-size: .75rem; }
  .deal-row .timeline { grid-column: 1 / -1; }
  .timeline li { font-size: .75rem; }
  .timeline small { font-size: .75rem; }
  .timeline-installments { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 10px; }
  .timeline-installments li:nth-child(4)::after { display: none; }
  .invoice-balances { order: 1; width: 100%; }
  .invoice-row .button { order: 2; margin-left: 0; }
  .live-preview { position: static; }
  .preview-jump { display: inline-flex; }
  .preview-format { display: none; }
  .detail-grid, .editor-grid { grid-template-columns: minmax(0, 1fr); gap: 15px; }
  .detail-flow, .detail-invoices, .doc-sidebar, .form-section { padding: 13px 12px; }
  .detail-customer { margin-top: -7px; }
  .paper-stage { margin: 9px; }
  .preview-bar { padding: 9px; }
  .preview-bar .button { font-size: .875rem; padding-inline: 8px; }
  .field :is(input, textarea, select), .compact-label select { font-size: 16px; }
  .pending-list a { padding-inline: 12px; gap: 7px; }
}

@media (max-width: 768px) {
  .paper-hint { display: block; padding: 7px 12px 0; color: var(--muted); font-size: .875rem; }
  .paper-open {
    display: block;
    position: absolute;
    inset: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
  }
  .ledger-table, .ledger-table tbody, .ledger-table tbody tr { display: block; }
  .ledger-table thead { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .ledger-table tbody tr { padding: 8px 12px; }
  .ledger-table tr + tr { border-top: 1px solid var(--line); }
  .ledger-table tr td, .ledger-table tr td:first-child, .ledger-table tr td:last-child {
    display: grid;
    grid-template-columns: minmax(92px, .7fr) minmax(0, 1.3fr);
    gap: 8px;
    align-items: baseline;
    padding: 4px 0;
    border: 0;
    text-align: left;
    overflow-wrap: anywhere;
  }
  .ledger-table .numeric { text-align: left; }
  .ledger-table .numeric .ledger-value { text-align: right; }
  .ledger-table .mobile-cell-label { display: inline-block; color: var(--muted); }
}

/* Physical page dimensions are shared by the on-screen preview and printing. */
.paper {
  --page-width: 210mm;
  --page-margin: 12mm;
  width: var(--page-width);
  height: 297mm;
  padding: var(--page-margin);
  overflow: hidden;
  color: #333133;
  background: white;
  position: relative;
  font: 400 8pt/1.52 Kanit, system-ui, sans-serif;
  zoom: var(--sheet-zoom, 1);
}
@supports (zoom: min(1, calc(100cqw / 210mm))) {
  .paper-stage { container-type: inline-size; }
  .paper-stage > .paper { zoom: min(1, calc(100cqw / 210mm)); }
}
.paper-invoice::after {
  content: "";
  position: absolute;
  inset: 8.5mm;
  border: .25mm dashed #626366;
  pointer-events: none;
}
.paper-watermark {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 50%;
  color: rgb(51 49 51 / 16%);
  font-size: 58pt;
  font-weight: 600;
  line-height: 1;
  transform: translate(-50%, -50%) rotate(-35deg);
  pointer-events: none;
}
.doc-adjustment { display: block; text-align: right; }
.paper-body { width: 186mm; transform: scale(var(--fit, 1)); transform-origin: top center; }
.doc-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 65mm;
  min-height: 56mm;
  padding: 6.5mm 3mm 5mm 5.5mm;
  gap: 2mm;
  background: repeating-linear-gradient(32deg, #dcddde 0 1mm, #e7e8e9 1mm 1.65mm);
}
.doc-header h2 { color: #00b9f2; font-size: 28pt; font-weight: 400; line-height: 1.12; margin-bottom: 6.2mm; }
.recipient-line { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2.5mm; overflow-wrap: anywhere; }
.recipient-line strong { display: block; font-size: 11.25pt; font-weight: 700; line-height: 1.3; }
.doc-issuer { padding-top: 3.5mm; display: grid; align-items: start; grid-template-columns: 21mm minmax(0, 1fr); gap: 2.5mm; }
.doc-issuer img { display: block; width: 26mm; height: 26mm; object-fit: contain; margin-left: -2.5mm; }
.issuer-copy { font-size: 7.5pt; line-height: 1.54; overflow-wrap: anywhere; }
.issuer-copy strong { display: block; font-size: 18pt; font-weight: 700; line-height: 1.05; }
.issuer-copy span { display: block; font-size: 7.5pt; margin-block: 1.4mm 1.8mm; line-height: 1.15; }
.doc-info {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1mm;
  margin-top: 6.5mm;
}
.doc-info > div { background: #e7e8e9; padding: 3.9mm 5.5mm; min-height: 19.4mm; overflow-wrap: anywhere; }
.doc-info dt { font-size: 7.5pt; }
.doc-reference {
  min-height: 14.6mm;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 2mm;
  padding: 1mm 5.5mm 1.6mm;
}
.doc-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 9pt;
  background: var(--gradient) top / 100% 9.1mm no-repeat;
}
.doc-table thead { color: #fff; }
.doc-table :is(td, th) { text-align: left; padding: 1.5mm 1.5mm 1.5mm 0; }
.doc-table thead th { height: 9.1mm; font-size: 8.5pt; font-weight: 500; }
.doc-table :is(td, th):first-child { width: 46.5%; padding-left: 5.5mm; padding-right: 10mm; }
.doc-table :is(td, th):nth-child(2) { width: 25%; }
.doc-table :is(td, th):nth-child(3) { width: 13%; }
.doc-table :is(td, th):last-child { text-align: right; padding-right: 5.5mm; }
.doc-table :is(td, th):not(:first-child) { overflow-wrap: anywhere; }
.doc-table tbody tr { height: 25.8mm; }
.doc-table tbody tr:nth-child(even) { background: #e7e8e9; }
.doc-table td:first-child { vertical-align: top; overflow-wrap: anywhere; }
.doc-table td strong { display: block; font-size: 10pt; font-weight: 500; }
.doc-table td span { display: block; white-space: pre-wrap; }
.doc-table tr[aria-hidden="true"] td { width: auto; }
.paper-service-invoice .doc-table tbody tr { height: 15.45mm; }
.paper-service-invoice .doc-table :is(td, th):last-child { text-align: center; padding-right: 2mm; }
.paper-service-invoice .doc-finance { margin-top: 15.6mm; }
.receipt-table :is(td, th):first-child { width: 46.5%; }
.receipt-table :is(td, th):nth-child(2) { width: 9%; }
.receipt-table :is(td, th):nth-child(3) { width: 9%; }
.receipt-table :is(td, th):nth-child(4) { width: 17%; }
.doc-finance {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70mm;
  position: relative;
  padding-top: 1.15mm;
}
.doc-finance::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1.15mm;
  background: var(--gradient);
}
.doc-payment { padding: 3.8mm 4.5mm; overflow-wrap: anywhere; }
.doc-payment h3, .doc-terms h3 { color: #007d9e; font-size: 8.6pt; font-weight: 500; margin-bottom: 1.6mm; }
.doc-payment dl > div { display: grid; grid-template-columns: 25mm minmax(0, 1fr); padding-left: 2mm; }
.doc-totals { text-align: right; }
.doc-totals dl > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 43.5mm;
  min-height: 8.95mm;
  border-bottom: 1mm solid transparent;
  border-image: var(--gradient) 1;
}
.doc-totals dl :is(dt, dd) { padding: 1.5mm 3.5mm .8mm 0; overflow-wrap: anywhere; }
.doc-totals dt { justify-self: end; white-space: nowrap; }
.doc-totals dd { padding-left: 3mm; background: #e7e8e9; }
.doc-totals > strong {
  display: inline-block;
  min-width: 51mm;
  padding: 2.25mm 5mm;
  font-size: 15pt;
  font-weight: 500;
  background: var(--gradient);
  color: #fff;
}
.doc-footer { margin-top: -1.2mm; display: flex; justify-content: space-between; align-items: start; gap: 7mm; }
.doc-terms { width: 99mm; position: relative; padding: 3.8mm 4.5mm 0; }
.doc-terms:has(h3)::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 72.4mm;
  height: 1mm;
  background: var(--gradient);
}
.doc-terms h3 { margin-bottom: .4mm; }
.doc-terms p { line-height: 1.57; white-space: pre-wrap; overflow-wrap: anywhere; }
.doc-signature {
  min-width: 43.5mm;
  margin-top: 24.6mm;
  padding-top: .7mm;
  border-top: .8mm solid transparent;
  border-image: var(--gradient) 1;
  text-align: center;
}
.doc-signature > * { display: block; }
.doc-signature small { margin-top: .75mm; font-size: 7pt; }
#print-root { display: none; }
#print-root.preparing-print { display: block; position: fixed; left: -10000px; top: 0; visibility: hidden; }

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { margin: 0; padding: 0; background: #fff; }
  body { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  #shell, #dialog, #paper-dialog, #notice, noscript { display: none !important; }
  #print-root { display: block; }
  #print-root .paper { height: 296.9mm; zoom: 1; }
}
