:root {
  color-scheme: light;
  --ink: #162731;
  --muted: #54646c;
  --line: #c4cfd1;
  --ground: #e8edec;
  --paper: #fff;
  --blue: #194d70;
  --form-font: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--ground); font: 1rem/1.6 var(--form-font); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { color: #596970; cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #1379b4; outline-offset: 3px; }
.top { padding-inline: max(1rem, calc((100% - 82rem)/2)); display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 58px; background: #183440; color: white; }
.top > div { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.brand, .jump { color: inherit; display: inline-flex; align-items: center; min-height: 44px; text-underline-offset: .24em; }
.brand { font-weight: 850; text-decoration: none; }
.local { color: #d3e1e6; font-size: .8rem; }
.jump { font-size: .875rem; white-space: nowrap; }
.desk { display: grid; grid-template-columns: minmax(20rem,.9fr) minmax(24rem,1.15fr); max-width: 86rem; margin: auto; }
.editor, .preview { min-width: 0; padding: clamp(1rem,3.3vw,2.8rem); }
.editor { background: #f6f7f4; border-right: 1px solid var(--line); }
.intro { border-bottom: 2px solid #263d49; padding-bottom: 1.1rem; margin-bottom: 1.4rem; }
.intro h1 { margin: 0; font-size: clamp(2rem,4.4vw,3.8rem); letter-spacing: -.075em; line-height: 1.1; }
.intro p { margin: .6rem 0 .25rem; color: var(--muted); }
.plain { background: transparent; border: 0; padding: .25rem 0; min-height: 44px; color: var(--blue); text-decoration: underline; text-underline-offset: .25em; font-weight: 700; }
fieldset { border: 0; padding: 0 0 1.4rem; margin: 0 0 1.35rem; min-width: 0; border-bottom: 1px solid var(--line); }
legend { padding: 0; margin-bottom: .7rem; font-size: 1.12rem; font-weight: 850; }
.fields, .line-editor { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .7rem; }
label { display: block; min-width: 0; font-size: .875rem; font-weight: 700; }
.required { font-size: .75rem; margin-inline-start: .35rem; color: #6e3b35; }
input, textarea, select { margin-top: .26rem; width: 100%; min-width: 0; min-height: 44px; border: 1px solid #9eafb4; border-radius: 4px; background: white; color: var(--ink); padding: .37rem .5rem; font-size: 1rem; font-weight: 500; }
textarea { resize: vertical; }
input[type="date"] { appearance: none; }
.wide { grid-column: 1 / -1; }
.line-editor { border-top: 1px solid var(--line); padding: .7rem 0 .1rem; }
.line-editor [data-remove] { justify-self: start; font-size: .875rem; }
.rounding { max-width: 14rem; margin-top: .45rem; }
.editor-footer, .preview-bar { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; }
#storage-status, .print-hint { color: var(--muted); font-size: .875rem; }
.preview-bar { margin-bottom: .8rem; }
.preview-bar h2 { margin: 0; font-size: 1rem; }
.primary { color: white; background: var(--blue); border: 1px solid transparent; border-radius: 4px; padding: .45rem .75rem; min-height: 44px; font-size: .875rem; font-weight: 800; }
.primary:hover { background: #103a58; }
.paper { padding: clamp(.8rem,4vw,2.6rem); background: var(--paper); border: 1px solid #ccd4d1; box-shadow: 0 10px 24px #233a3912; font-size: .875rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.paper p, .paper dl { margin: 0; }
.paper-top, .parties { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr); gap: .75rem; }
.paper-top { padding: 0 0 1.2rem; border-bottom: 2px solid var(--ink); align-items: end; }
.paper-top h2 { font-size: clamp(1.65rem,3vw,2.8rem); margin: 0; line-height: 1.1; }
#out-subject { margin-top: .35rem; }
.paper dt, .paper-label { font-size: .78rem; color: var(--muted); }
.paper dd { margin: 0; }
.parties { margin: 1rem 0; }
.client, #out-issuer { font-weight: 850; font-size: 1.05rem; }
#out-contact, .paper-extra p { white-space: pre-wrap; }
.billing-total { background: #eaf0f1; border-inline-start: 3px solid var(--blue); padding: .65rem .75rem; display: flex; align-items: center; justify-content: space-between; gap: .3rem .6rem; flex-wrap: wrap; }
.billing-total strong { font-size: clamp(1.65rem,4.1vw,2.7rem); line-height: 1.12; color: #173d53; }
.paper .dates { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin: 1rem 0; }
.lines { width: 100%; border-collapse: collapse; table-layout: fixed; }
.lines th, .lines td { padding: .43rem .3rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.lines th { font-size: .77rem; border-bottom: 2px solid var(--ink); }
.lines th:first-child { width: 40%; }
.lines th:nth-child(2) { width: 31%; }
.lines th:last-child, .lines td:last-child { text-align: right; }
.lines small { display: block; color: var(--muted); }
.paper .sums { margin: .8rem 0 .8rem auto; width: min(100%,19rem); }
.sums > div { display: flex; justify-content: space-between; gap: .5rem; padding: .22rem .25rem; }
.sums dd { text-align: right; }
.sums > div:last-child { margin-top: .2rem; border-top: 2px solid var(--ink); font-weight: 850; }
.sums > div:last-child dt { color: var(--ink); }
.paper-extra { border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .65rem; }
.paper-extra h3 { margin: 0 0 .15rem; font-size: .875rem; }
@media (max-width: 810px) {
  .desk { display: block; }
  .editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview { scroll-margin-top: .35rem; }
}
@media (max-width: 380px) {
  .top > div { gap: .4rem; }
  .fields { gap: .55rem; }
  .paper { font-size: .79rem; }
  .lines th, .lines td { padding-inline: .14rem; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@page { size: A4; margin: 13mm; }
@media print {
  html, body { background: white; }
  .top, .editor, .preview-bar, .print-hint { display: none !important; }
  .desk, .preview { display: block; max-width: none; padding: 0; margin: 0; }
  .paper { padding: 0; border: 0; box-shadow: none; font-size: 10pt; }
  .paper-top h2 { font-size: 24pt; }
  .paper-top, .parties, .billing-total, .dates, .sums, tr, .paper-extra { break-inside: avoid; }
  .lines thead { display: table-header-group; }
  .billing-total { print-color-adjust: exact; }
}
