:root {
  --acc: #1a56db;
  --acc-h: #1648c0;
  --acc-bg: #eff4ff;
  --ok: #15803d;
  --err: #dc2626;
  --bd: #e2e2df;
  --bd2: #ccc;
  --t0: #111;
  --t1: #444;
  --t2: #777;
  --t3: #bbb;
  --inp: #fff;
  --bg: #f3f2ee;
  --pnl: #fff;
  --pv: #c8c4bc;
  --hdr: #131313;
  --r: 4px;
  --f-ui: 'Noto Sans JP', sans-serif;
  --f-mono: 'DM Mono', monospace;
  --f-doc: 'Shippori Mincho', 'Noto Serif JP', serif;
  --paper-pad: 13.75mm 15.875mm 12.7mm;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--f-ui);
  background: var(--bg);
  color: var(--t0);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 1024px;
}

.unsupported {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: #131313; color: #e4e4e2;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 24px;
}
.unsupported p:first-child { font-size: 16px; font-weight: 700; }
.unsupported p:last-child { font-size: 12px; color: #666; }
@media (max-width: 1023px) { .unsupported { display: flex; } }

.hdr {
  flex-shrink: 0;
  background: var(--hdr);
  border-bottom: 1px solid #2a2a2a;
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.hdr-logo {
  font-family: var(--f-mono);
  font-size: 12px;
  color: #666;
  letter-spacing: .05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.hdr-logo strong { color: #e4e4e2; font-weight: 500; }
.hdr-r { margin-left: auto; }
.btn-contact {
  color: #888;
  font-family: var(--f-mono);
  font-size: 11.5px;
  text-decoration: none;
  letter-spacing: .03em;
  transition: color .12s;
  white-space: nowrap;
}
.btn-contact:hover { color: #e4e4e2; }

.body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.form-panel {
  width: 460px;
  flex-shrink: 0;
  background: var(--pnl);
  border-right: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.doc-type-bar {
  flex-shrink: 0;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--bd);
  background: #fafaf8;
}
.doc-type-bar-lbl {
  font-size: 10px;
  color: var(--t2);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-family: var(--f-mono);
}
.doc-type-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding-bottom: 12px;
}
.doc-type-btn {
  padding: 7px 2px;
  border: 1px solid var(--bd2);
  border-radius: var(--r);
  background: #fff;
  color: var(--t1);
  font-family: var(--f-ui);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all .12s;
  white-space: nowrap;
  letter-spacing: -.01em;
}
.doc-type-btn:hover { border-color: var(--acc); color: var(--acc); }
.doc-type-btn.active {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
  font-weight: 700;
}

.form-tabs {
  flex-shrink: 0;
  display: flex;
  border-bottom: 1px solid var(--bd);
  background: #fafaf8;
}
.form-tab {
  flex: 1;
  padding: 11px 4px;
  border: none;
  background: transparent;
  font-family: var(--f-ui);
  font-size: 12.5px;
  color: var(--t2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .12s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}
.form-tab:hover { color: var(--t0); }
.form-tab.active {
  color: var(--acc);
  border-bottom-color: var(--acc);
  font-weight: 700;
}
.form-tab .tab-step {
  font-family: var(--f-mono);
  font-size: 9px;
  color: var(--t3);
  font-weight: 400;
}
.form-tab.active .tab-step { color: var(--acc); opacity: .7; }

.tab-panes {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--bd2) transparent;
}
.tab-panes::-webkit-scrollbar { width: 4px; }
.tab-panes::-webkit-scrollbar-thumb { background: var(--bd2); border-radius: 2px; }

.tab-pane {
  display: none;
  padding: 20px 20px 24px;
}
.tab-pane.active { display: block; }

.fg-group {
  margin-bottom: 20px;
}
.fg-group-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--t2);
  font-family: var(--f-mono);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bd);
  margin-bottom: 12px;
}

.fg { margin-bottom: 12px; }
.fg:last-child { margin-bottom: 0; }
.fg label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--t1);
  margin-bottom: 5px;
}
.fg label .sub { font-size: 10px; color: var(--t2); font-weight: 400; margin-left: 4px; }
.fg label .req { color: var(--err); font-size: 10px; margin-left: 3px; }
.fg input, .fg textarea, .fg select {
  width: 100%;
  background: var(--inp);
  border: 1px solid var(--bd2);
  border-radius: var(--r);
  color: var(--t0);
  font-family: var(--f-ui);
  font-size: 13px;
  padding: 0 12px;
  height: 40px;
  transition: border-color .12s, box-shadow .12s;
  -webkit-appearance: none;
  appearance: none;
}
.fg input:focus, .fg select:focus, .fg textarea:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 3px rgba(26,86,219,.08);
}
.fg input::placeholder, .fg textarea::placeholder { color: var(--t3); }
.fg textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.fg select option { background: #fff; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.frow3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.up-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.up-col > .up-col-lbl {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--t1);
  margin-bottom: 5px;
  display: block;
}
.upbox {
  border: 1px dashed var(--bd2);
  border-radius: var(--r);
  background: #fafaf8;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: all .12s;
  position: relative;
  padding: 10px 8px;
}
.upbox:hover { border-color: var(--acc); background: var(--acc-bg); }
.upbox.has { border-style: solid; border-color: var(--ok); background: #f0fdf4; }
.upbox input { display: none; }
.up-prev { max-width: 90%; max-height: 44px; object-fit: contain; display: none; }
.up-prev.on { display: block; }
.up-txt { font-size: 10px; color: var(--t2); line-height: 1.4; text-align: center; }
.upbox.has .up-txt { color: var(--ok); }
.up-x {
  position: absolute; top: 4px; right: 4px;
  background: var(--err); border: none; border-radius: 2px;
  width: 16px; height: 16px; color: #fff;
  font-size: 9px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
}
.upbox.has .up-x { display: flex; }
.up-note {
  font-size: 11px;
  color: var(--t2);
  line-height: 1.6;
  background: #fafaf8;
  border: 1px solid var(--bd);
  border-radius: var(--r);
  padding: 8px 10px;
}

.items-table-wrap {
  border: 1px solid var(--bd2);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 10px;
}
.items-head {
  display: grid;
  grid-template-columns: 1fr 70px 60px 90px 80px 24px;
  gap: 0;
  background: #f5f5f3;
  border-bottom: 1px solid var(--bd2);
}
.items-head span {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--t2);
  padding: 7px 8px;
  border-right: 1px solid var(--bd);
  text-align: center;
}
.items-head span:first-child { text-align: left; }
.items-head span:last-child { border-right: none; }
.item-row {
  display: grid;
  grid-template-columns: 1fr 70px 60px 90px 80px 24px;
  gap: 0;
  border-bottom: 1px solid var(--bd);
  background: #fff;
  transition: background .1s;
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: #fafaf8; }
.item-row input, .item-row select {
  width: 100%;
  height: 36px;
  border: none;
  border-right: 1px solid var(--bd);
  border-radius: 0;
  background: transparent;
  font-family: var(--f-ui);
  font-size: 12.5px;
  color: var(--t0);
  padding: 0 8px;
  box-shadow: none;
}
.item-row input:focus, .item-row select:focus {
  outline: none;
  background: var(--acc-bg);
}
.item-row input::placeholder { color: var(--t3); }
.item-row .item-del-cell {
  border-right: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-del {
  background: none; border: none;
  color: var(--t3); cursor: pointer;
  font-size: 12px; padding: 4px; line-height: 1;
  transition: color .1s;
}
.item-del:hover { color: var(--err); }
.item-sub-row {
  display: grid;
  grid-template-columns: 1fr;
  padding: 3px 8px 3px;
  background: #fafaf8;
  border-bottom: 1px solid var(--bd);
}
.item-sub-row:last-child { border-bottom: none; }
.item-sub-txt {
  font-size: 10.5px;
  color: var(--acc);
  text-align: right;
  font-family: var(--f-mono);
  min-height: 14px;
}
.btn-add-item {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--bd2);
  border-radius: var(--r);
  color: var(--t2);
  cursor: pointer;
  font-family: var(--f-ui);
  font-size: 12.5px;
  padding: 9px;
  transition: all .12s;
}
.btn-add-item:hover { border-color: var(--acc); color: var(--acc); }

.fl-info {
  background: #eff4ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--r);
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 11.5px;
  color: #1e40af;
  line-height: 1.65;
}
.fl-info strong { font-size: 12px; display: block; margin-bottom: 3px; }

.form-footer {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--bd);
  background: #fafaf8;
  display: flex;
  gap: 8px;
  align-items: center;
}
.btn-new {
  background: transparent;
  border: 1px solid var(--bd2);
  border-radius: var(--r);
  color: var(--t2);
  cursor: pointer;
  font-family: var(--f-ui);
  font-size: 12px;
  padding: 8px 14px;
  transition: all .12s;
}
.btn-new:hover { border-color: var(--err); color: var(--err); }
.btn-print {
  flex: 1;
  background: var(--acc);
  border: none;
  border-radius: var(--r);
  color: #fff;
  cursor: pointer;
  font-family: var(--f-ui);
  font-size: 13.5px;
  font-weight: 700;
  padding: 10px;
  transition: background .12s;
}
.btn-print:hover { background: var(--acc-h); }

.preview-panel {
  flex: 1;
  background: var(--pv);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  overflow: hidden;
}
.page-display {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
}
#scaleOuter { position: relative; flex-shrink: 0; }
#pageClip {
  width: 210mm;
  height: 296mm;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 4px 28px rgba(0,0,0,.2), 0 1px 4px rgba(0,0,0,.12);
}
#pageClip .doc {
  position: absolute;
  left: 0;
  width: 210mm;
  box-shadow: none;
}
.page-nav {
  flex-shrink: 0;
  height: 44px;
  background: rgba(0,0,0,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.page-nav-btn {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--r);
  color: #fff;
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 16px;
  cursor: pointer;
  transition: background .12s;
}
.page-nav-btn:hover:not(:disabled) { background: rgba(255,255,255,.3); }
.page-nav-btn:disabled { opacity: .3; cursor: default; }
.page-nav-indicator {
  font-family: var(--f-mono);
  font-size: 12px;
  color: rgba(255,255,255,.8);
  min-width: 60px;
  text-align: center;
}

#docMeasure {
  position: fixed; top: -99999px; left: -99999px;
  width: 210mm; visibility: hidden; pointer-events: none;
  overflow: visible; background: #fff;
  font-family: var(--f-doc); font-size: 9pt; line-height: 1.7; color: #111;
  padding: var(--paper-pad);
}

.doc {
  width: 210mm;
  background: #fff;
  padding: var(--paper-pad);
  font-family: var(--f-doc);
  color: #111;
  font-size: 9pt;
  line-height: 1.7;
  min-height: 296mm;
}

.dh {
  margin-bottom: 12px;
}

.dh-title {
  font-size: 22pt;
  font-weight: 700;
  letter-spacing: .35em;
  color: #111;
  line-height: 1.1;
  text-align: center;
  margin-bottom: 8px;
}

.dh-sub {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  font-size: 8pt;
  color: #888;
  white-space: nowrap;
  font-family: var(--f-ui);
}
.dh-sub span { color: #bbb; margin-right: 3px; }


.da { display: flex; gap: 18px; margin-bottom: 0; align-items: flex-start; }
.da-client { flex: 1; padding-top: 2px; }
.da-cname {
  font-size: 14pt; font-weight: 700;
  border-bottom: 1.5px solid #111;
  padding-bottom: 2px; margin-bottom: 4px;
  word-break: break-all; line-height: 1.3;
}
.da-csub { font-size: 8pt; color: #888; }
.da-addr { font-size: 8pt; color: #666; margin-top: 1px; }

.da-subject {
  font-size: 9pt; color: #333;
  margin-top: 6px;
  font-family: var(--f-ui);
}
.da-subject span { color: #aaa; margin-right: 4px; font-size: 8pt; }

.da-meta-t { border-collapse: collapse; margin-top: 7px; font-size: 8.5pt; font-family: var(--f-ui); }
.da-meta-t td { padding: 2px 10px 2px 0; color: #555; }
.da-meta-t td:first-child { color: #aaa; white-space: nowrap; }

.da-issuer {
  width: 230px;
  flex-shrink: 0;
  position: relative;
  padding-bottom: 4px;
  border-left: 1px solid #d8d8d8;
  padding-left: 14px;
}
.da-logo {
  max-width: 130px;
  max-height: 44px;
  object-fit: contain;
  display: block;
  margin-bottom: 7px;
}
.da-logo-ph { height: 0; }
.da-iinfo { font-size: 8.5pt; line-height: 1.75; color: #333; }
.da-iname { font-size: 10pt; font-weight: 700; color: #111; margin-bottom: 1px; word-break: break-all; }
.da-simg {
  position: absolute; bottom: 0; right: 0;
  width: 52px; height: 52px;
  object-fit: contain;
  mix-blend-mode: multiply; opacity: .82;
  pointer-events: none;
}

.d-intro { font-size: 9pt; color: #555; margin: 5px 0 9px; }
.d-amt { border: 1.5px solid #111; padding: 9px 18px; margin: 9px 0; display: flex; justify-content: space-between; align-items: center; }
.d-amt-lbl { font-size: 9pt; color: #666; font-family: var(--f-ui); }
.d-amt-val { font-size: 21pt; font-weight: 700; color: #111; }

.d-ryo { border: 2px double #111; padding: 14px 24px; margin: 11px 0; text-align: center; }
.d-ryo-yen { font-size: 27pt; font-weight: 700; }
.d-ryo-note { font-size: 7.5pt; color: #888; margin-top: 2px; font-family: var(--f-ui); }
.d-ryo-tad { font-size: 9pt; margin: 8px 0 4px; padding-bottom: 7px; border-bottom: 1px solid #e0e0e0; }
.d-ryo-conf { font-size: 9pt; color: #333; margin-bottom: 8px; }

.d-meta { font-size: 8.5pt; color: #555; margin: 3px 0 9px; }
.d-meta table { border-collapse: collapse; }
.d-meta td { padding: 1.5px 12px 1.5px 0; }
.d-meta td:first-child { color: #aaa; white-space: nowrap; font-family: var(--f-ui); }

.d-tbl { width: 100%; border-collapse: collapse; margin: 7px 0; font-size: 8.5pt; table-layout: fixed; }
.d-tbl th { background: #f7f7f7; border: 1px solid #c0c0c0; height: 22px; line-height: 22px; padding: 0 3.5px; text-align: center; font-weight: 700; font-size: 8pt; white-space: nowrap; overflow: hidden; font-family: var(--f-ui); letter-spacing: .02em; }
.d-tbl td { border: 1px solid #ddd; height: 22px; line-height: 22px; padding: 0 3.5px; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.d-tbl td.r { text-align: right; }
.d-tbl td.c { text-align: center; }
.col-no { width: 22px; } .col-name {} .col-qty { width: 42px; } .col-unit { width: 34px; } .col-price { width: 80px; } .col-tax { width: 56px; } .col-amt { width: 84px; }

.d-tots { display: flex; justify-content: flex-end; margin-top: 5px; }
.d-tots-t { border-collapse: collapse; min-width: 212px; font-size: 8.5pt; }
.d-tots-t td { padding: 3px 7px; border: 1px solid #ddd; }
.d-tots-t td:first-child { color: #888; text-align: right; font-family: var(--f-ui); }
.d-tots-t td:last-child { text-align: right; white-space: nowrap; }
.d-tots-t .grand { background: #f7f7f7; font-weight: 700; }
.d-tots-t .grand td { border-color: #aaa; font-size: 10.5pt; }
.d-taxnote { font-size: 7.5pt; color: #999; margin-top: 3px; font-family: var(--f-ui); }

.d-sec { margin-top: 14px; }
.d-sec-t { font-size: 8.5pt; font-weight: 700; border-left: 2px solid #111; padding-left: 5px; margin-bottom: 5px; font-family: var(--f-ui); letter-spacing: .04em; }
.d-sec-b { font-size: 8.5pt; color: #444; font-family: var(--f-ui); border: 1px solid #e0e0e0; padding: 7px 9px; min-height: 32px; white-space: pre-wrap; word-break: break-all; line-height: 1.75; }

.d-fl { border: 1px solid #d0d0d0; margin-top: 12px; font-family: var(--f-ui); }
.d-fl-head { background: #f7f7f7; border-bottom: 1px solid #d0d0d0; padding: 4px 10px; font-size: 7.5pt; font-weight: 700; color: #555; letter-spacing: .04em; }
.d-fl-grid { display: grid; grid-template-columns: 1fr 1fr; }
.d-fl-cell { padding: 3.5px 10px; border-right: 1px solid #eee; border-bottom: 1px solid #eee; font-size: 8pt; color: #333; }
.d-fl-cell:nth-child(2n) { border-right: none; }
.d-fl-cell:nth-last-child(-n+2) { border-bottom: none; }
.d-fl-cell span { color: #aaa; font-size: 7.5pt; display: block; margin-bottom: 1px; }

#printDoc { display: none !important; }