/* 無料ツールの画面。style.css の色と文字の変数を使う。帳票（A4）は mm で組み、印刷と画面で同じ見た目にする。 */

/* 入力欄・ボタンの色。暗い表示（ダークモード）でも文字が読めるように、白を直接書かず変数で切り替える。帳票（.sheet）は紙なので白のまま */
:root {
  color-scheme: light dark;
  --field-bg: #fff; --field-line: #cfd4d0; --field-line-hover: #aab2ac;
  --muted-bg: #f6f7f6; --paper-bg: #e9ece9; --bar-bg: rgba(255, 255, 255, .97);
  --warn-ink: #9a3412; --err-ink: #b42318; --err-line: #c2410c; --err-bg: #fff7f3; --ng-bg: #fff1ee;
  --note-bg: #fff6e5; --note-line: #f0d9a8; --on-accent: #fff; --accent-hover: #12683a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --field-bg: #0f1216; --field-line: #3a424c; --field-line-hover: #56606b;
    --muted-bg: #1c2027; --paper-bg: #23272d; --bar-bg: rgba(23, 26, 31, .97);
    --warn-ink: #f4a26b; --err-ink: #ff8f80; --err-line: #e0704f; --err-bg: #2a1714; --ng-bg: #2a1714;
    --note-bg: #2a2214; --note-line: #5a4a24; --on-accent: #08120c; --accent-hover: #6ad79e;
  }
}

.crumbs { display: flex; gap: .45rem; align-items: center; font-size: .82rem; color: var(--ink-3); padding-top: .4rem; }
.crumbs a { color: var(--ink-3); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.tool-page .post-head { padding-bottom: 1.2rem; }
.tool { margin: 0 0 2.6rem; }
.tool-noscript { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 10px; padding: .9rem 1rem; }

/* main の幅（46rem）では帳票の横並びが窮屈なので、ツールの部分だけ広げる */
main:has(.tool-page) { max-width: 76rem; }
main:has(.tool-page) .post-head,
main:has(.tool-page) .post-body,
main:has(.tool-page) .cta,
main:has(.tool-page) .related-tools,
main:has(.tool-page) .back,
main:has(.tool-page) .crumbs,
main:has(.tool-page) .aff-disclosure { max-width: 46rem; margin-left: auto; margin-right: auto; }

/* 1〜2文字だけの最終行を作らない（対応していないブラウザでは普通に折り返す） */
.tool-page p, .tool-page li, .tool-page small, .tool-page label, .calc-formula { text-wrap: pretty; }
.tool-page h1, .tool-page h2, .tool-page h3 { text-wrap: balance; }

/* hidden 属性は、display を指定した部品でも必ず隠す */
.tool [hidden], #print-root [hidden] { display: none !important; }

/* ---- 共通の部品 ---- */
.t-field { display: grid; grid-template-columns: minmax(0, 1fr); gap: .3rem; margin: 0 0 .85rem; }
.tool input[type="file"] { max-width: 100%; min-width: 0; } /* 320px で文字を大きくしても横にはみ出さない */
.t-input::placeholder, .tool textarea::placeholder { color: var(--ink-3); opacity: 1; } /* 暗い表示でも見本の文字が読める */
.t-field > span, .t-label { font-size: .84rem; font-weight: 600; color: var(--ink-2); }
.t-field small, .t-hint { font-size: .8rem; color: var(--ink-3); line-height: 1.6; }
.t-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); align-items: end; } /* ラベルの行数が違っても入力欄の高さをそろえる */
.t-input, .tool select, .tool textarea {
  width: 100%; font: inherit; font-size: 16px; /* iOS で入力時に拡大されないよう16px */
  color: var(--ink); background: var(--field-bg); border: 1px solid var(--field-line); border-radius: 8px; padding: .55rem .65rem; line-height: 1.5;
}
.tool textarea { min-height: 4.5rem; resize: vertical; }
.t-input:focus, .tool select:focus, .tool textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.t-input[aria-invalid="true"] { border-color: var(--err-line); background: var(--err-bg); }
.t-num { text-align: right; font-variant-numeric: tabular-nums; }
.t-err { color: var(--err-ink); font-size: .8rem; margin: .2rem 0 0; }
.t-check { display: inline-flex; align-items: center; gap: .45rem; font-size: .92rem; cursor: pointer; }
.t-check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.t-radios { display: flex; flex-wrap: wrap; gap: .4rem .9rem; }

.t-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.75rem;
  font: inherit; font-size: .93rem; font-weight: 600; padding: .5rem 1rem; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--field-line); background: var(--field-bg); color: var(--ink);
}
.t-btn:hover { border-color: var(--field-line-hover); }
.t-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.t-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.t-btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); font-weight: 500; }
.t-btn-quiet:hover { color: var(--accent); }
.t-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.t-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.15rem; }
.t-note { font-size: .86rem; color: var(--ink-2); background: var(--accent-soft); border-radius: 10px; padding: .7rem .85rem; margin: 0 0 1rem; }

/* ---- 書類を作るツール ---- */
.dm-types { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .9rem; }
.dm-types a { text-decoration: none; color: var(--ink-2); border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .38rem .95rem; font-size: .9rem; font-weight: 600; }
.dm-types a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.dm-privacy { font-size: .84rem; color: var(--ink-2); margin: 0 0 1rem; position: relative; padding-left: 1rem; }
.dm-privacy::before { content: ""; position: absolute; left: 0; top: .5rem; width: .55rem; height: .55rem; border-radius: 50%; background: var(--accent); }

.dm-grid { display: grid; gap: 1.4rem; grid-template-columns: minmax(0, 1fr); }
.dm-grid > * { min-width: 0; }
.calc > * { min-width: 0; }
@media (min-width: 1000px) {
  .dm-grid { grid-template-columns: minmax(0, 27rem) minmax(0, 1fr); align-items: start; }
  .dm-side { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }
}

.dm-form fieldset { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 1rem 1.05rem .3rem; margin: 0 0 1rem; min-width: 0; }
.dm-form legend { font-weight: 700; font-size: .98rem; padding: 0 .35rem; }
.dm-form details > summary { cursor: pointer; font-weight: 700; font-size: .98rem; list-style: none; padding: .1rem 0 .8rem; }
.dm-form details > summary::-webkit-details-marker { display: none; }
.dm-form details > summary::after { content: "＋"; float: right; color: var(--ink-3); font-weight: 400; }
.dm-form details[open] > summary::after { content: "－"; }
.dm-sub { font-size: .84rem; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.dm-saved { font-size: .78rem; color: var(--accent); font-weight: 600; margin-left: .4rem; white-space: nowrap; }

/* 明細の行 */
.dm-line { border-top: 1px dashed var(--line); padding: .8rem 0 .4rem; display: grid; gap: .5rem; grid-template-columns: 1fr 1fr; }
.dm-line:first-child { border-top: 0; padding-top: .2rem; }
.dm-line .l-name { grid-column: 1 / -1; }
.dm-line .l-date { grid-column: 1 / -1; }
.dm-line .l-tools { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.dm-line label > span { font-size: .76rem; color: var(--ink-3); font-weight: 600; display: block; margin-bottom: .15rem; }
.dm-line .l-amount { font-variant-numeric: tabular-nums; font-weight: 700; font-size: .95rem; }
.dm-line .l-del { color: var(--err-ink); }
@media (min-width: 520px) {
  .dm-line { grid-template-columns: 4.6rem 4.2rem 1fr 6.4rem; }
  .dm-line .l-name { grid-column: 1 / -1; }
}

.dm-add { margin: .2rem 0 1rem; }

/* スマホの下の帯（金額と保存ボタン） */
.dm-mobile-bar { display: none; }
@media (max-width: 999px) {
  .dm-mobile-bar {
    display: flex; align-items: center; gap: .5rem; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--bar-bg); border-top: 1px solid var(--line); padding: .55rem max(1rem, env(safe-area-inset-right)) calc(.55rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    box-shadow: 0 -4px 14px rgba(0,0,0,.06);
  }
  .dm-mobile-bar span { flex: 1 1 auto; display: grid; line-height: 1.25; min-width: 0; }
  .dm-mobile-bar small { font-size: .74rem; color: var(--ink-3); }
  .dm-mobile-bar strong { font-size: 1.12rem; font-variant-numeric: tabular-nums; }
  .dm-mobile-bar .t-btn { min-height: 2.6rem; padding: .4rem .8rem; }
  .tool-page ~ .site-foot, body:has(.dm-mobile-bar) .site-foot { padding-bottom: 5rem; }
}

/* 右側（操作・確認・プレビュー） */
.dm-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .8rem; }
.dm-actions .t-btn-primary { flex: 1 1 12rem; }
.dm-total-strip { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .75rem 1rem; margin: 0 0 .8rem; }
.dm-total-strip strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.dm-total-strip span { font-size: .84rem; color: var(--ink-2); }
.dm-check { margin: 0 0 .9rem; }
.dm-check-title { font-size: .9rem; font-weight: 700; margin: 0 0 .45rem; }
.dm-check ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; font-size: .86rem; }
.dm-check li { display: flex; gap: .45rem; align-items: baseline; }
.dm-check li::before { content: "✓"; color: var(--accent); font-weight: 700; flex: 0 0 1rem; }
.dm-check li.ng::before { content: "！"; color: var(--err-ink); }
.dm-check li.opt::before { content: "–"; color: var(--ink-3); }
.dm-check p:not(.dm-check-title) { font-size: .82rem; color: var(--ink-3); margin: .5rem 0 0; line-height: 1.6; }
.dm-msgs { font-size: .86rem; margin: 0 0 .8rem; }
.dm-msgs p { margin: .25rem 0; }
.dm-msgs .warn { color: var(--warn-ink); }
.dm-print-hint { font-size: .8rem; color: var(--ink-3); margin: -.2rem 0 .9rem; line-height: 1.6; }

.dm-preview { background: var(--paper-bg); border-radius: 12px; padding: 12px; overflow: hidden; width: 100%; max-width: 100%; }
.dm-preview-warn { font-size: .86rem; font-weight: 600; color: var(--err-ink); background: var(--err-bg); border: 1px solid var(--err-line); border-radius: 10px; padding: .6rem .8rem; margin: 0 0 .8rem; }
.dm-preview-inner { transform-origin: top left; width: 210mm; }

/* ---- 帳票（A4） ---- */
.sheet {
  width: 210mm; min-height: 297mm; padding: 15mm 14mm 14mm; background: #fff; color: #111;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", "Meiryo", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  font-size: 9.5pt; line-height: 1.55; letter-spacing: .01em; box-shadow: 0 1px 3px rgba(0,0,0,.12);
  -webkit-print-color-adjust: exact; print-color-adjust: exact; position: relative;
}
.sheet * { box-sizing: border-box; }
.sh-top { display: flex; justify-content: flex-end; font-size: 8.5pt; color: #333; }
.sh-top dl { display: grid; grid-template-columns: auto auto; gap: .2mm 3mm; margin: 0; }
.sh-top dt { color: #555; }
.sh-top dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.sh-title { text-align: center; font-size: 19pt; font-weight: 700; letter-spacing: .6em; text-indent: .6em; margin: 4mm 0 7mm; }
.sh-head { display: grid; grid-template-columns: 1fr 72mm; gap: 8mm; align-items: start; }
.sh-client { font-size: 13pt; font-weight: 700; border-bottom: .35mm solid #111; padding-bottom: 1.2mm; margin: 0 0 3mm; display: flex; justify-content: space-between; gap: 4mm; }
.sh-client small { font-size: 11pt; font-weight: 600; white-space: nowrap; }
.sh-client-sub { font-size: 8.5pt; color: #333; margin: -1.5mm 0 3mm; white-space: pre-line; }
.sh-subject { margin: 0 0 1.5mm; }
.sh-lead { margin: 0 0 3mm; }
.sh-amount { display: flex; align-items: baseline; justify-content: space-between; gap: 4mm; border: .35mm solid #111; padding: 2.4mm 3.5mm; margin: 0 0 2.5mm; }
.sh-amount span { font-weight: 700; font-size: 10.5pt; }
.sh-amount strong { font-size: 17pt; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.sh-amount em { font-style: normal; font-size: 8.5pt; color: #333; margin-left: 1.5mm; }
.sh-terms { display: grid; grid-template-columns: auto 1fr; gap: .6mm 4mm; margin: 0; font-size: 9pt; }
.sh-terms dt { color: #444; }
.sh-terms dd { margin: 0; }
.sh-issuer { font-size: 8.8pt; line-height: 1.6; position: relative; min-height: 26mm; padding-right: 2mm; }
.sh-issuer .name { font-size: 11pt; font-weight: 700; margin-bottom: 1mm; }
.sh-issuer .reg { margin-top: 1mm; font-variant-numeric: tabular-nums; }
.sh-issuer .line { white-space: pre-line; }
.sh-stamp { position: absolute; right: 0; top: 2mm; width: 21mm; height: 21mm; object-fit: contain; opacity: .92; }
.sh-table { width: 100%; border-collapse: collapse; margin: 7mm 0 0; font-size: 9pt; }
.sh-table thead { display: table-header-group; }
.sh-table th { background: #f1f2f1; font-weight: 700; font-size: 8.5pt; padding: 1.6mm 2mm; border-top: .35mm solid #111; border-bottom: .25mm solid #111; text-align: center; }
.sh-table td { padding: 1.7mm 2mm; border-bottom: .15mm solid #bbb; vertical-align: top; }
.sh-table tr { break-inside: avoid; }
.sh-table .c-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sh-table .c-date { white-space: nowrap; width: 18mm; }
.sh-table .c-qty { width: 15mm; }
.sh-table .c-unit { width: 11mm; text-align: center; }
.sh-table .c-price { width: 23mm; }
.sh-table .c-amount { width: 26mm; }
.sh-table .mark { font-size: 8pt; margin-left: 1mm; }
.sh-table tr.empty td { height: 7.2mm; }
.sh-bottom { display: grid; grid-template-columns: 1fr 74mm; gap: 8mm; margin-top: 4mm; align-items: start; break-inside: avoid; }
.sh-sum { width: 100%; border-collapse: collapse; font-size: 9pt; }
.sh-sum th { text-align: left; font-weight: 500; padding: 1.1mm 2mm; color: #222; }
.sh-sum td { text-align: right; padding: 1.1mm 2mm; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sh-sum tr.total th, .sh-sum tr.total td { font-weight: 700; border-top: .3mm solid #111; font-size: 10pt; }
.sh-sum tr.minus td { color: #111; }
.sh-sum tr.pay th, .sh-sum tr.pay td { font-weight: 700; border-top: .3mm solid #111; border-bottom: .3mm solid #111; font-size: 10.5pt; }
.sh-sum tr.sub th, .sh-sum tr.sub td { font-size: 8.3pt; color: #333; padding-top: .5mm; padding-bottom: .5mm; }
.sh-rates { width: 100%; border-collapse: collapse; font-size: 8.3pt; margin-top: 3mm; }
.sh-rates th, .sh-rates td { padding: .8mm 2mm; border-bottom: .15mm solid #bbb; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sh-rates thead th { font-weight: 600; color: #333; border-bottom: .25mm solid #111; }
.sh-rates tbody th { text-align: left; font-weight: 500; }
.sh-rates thead th:first-child { text-align: left; }
.sh-box { border: .2mm solid #777; padding: 2mm 3mm; font-size: 8.8pt; margin: 0 0 3mm; white-space: pre-line; }
.sh-box h4 { margin: 0 0 1mm; font-size: 8.8pt; }
.sh-foot { margin-top: 4mm; font-size: 8pt; color: #333; }
.sh-revenue { position: absolute; right: 14mm; top: 46mm; width: 24mm; height: 28mm; border: .3mm dashed #888; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 7.5pt; color: #666; line-height: 1.4; }

/* 領収書 */
.sheet.receipt .sh-title { margin-bottom: 9mm; }
.rc-amount { display: flex; justify-content: center; align-items: baseline; gap: 4mm; border-bottom: .4mm solid #111; padding: 0 0 2mm; margin: 6mm 22mm 3mm; }
.rc-amount span { font-size: 11pt; font-weight: 700; }
.rc-amount strong { font-size: 22pt; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.rc-for { text-align: center; margin: 0 0 1.5mm; }
.rc-blank { display: inline-block; width: 48mm; border-bottom: .2mm solid #555; margin: 0 1mm; vertical-align: -1mm; }
.rc-date { text-align: center; margin: 0 0 1.5mm; font-size: 9pt; color: #333; }
.rc-lead { text-align: center; margin: 0 0 6mm; }
.rc-mid { display: grid; grid-template-columns: 1fr 76mm; gap: 8mm; align-items: start; }

/* 直すところがある時に、印刷で帳票の代わりに出す1枚 */
.sheet.sh-draft { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 4mm; font-size: 11pt; }
.sh-draft-title { font-size: 18pt; font-weight: 700; margin: 0; }

/* 画面のプレビューでは、ページの間をあける */
.dm-preview-inner .sheet + .sheet { margin-top: 6mm; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* 印刷: 帳票だけを出す（JSが #print-root に複製する） */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff !important; }
  body > *:not(#print-root):not(#print-measure) { display: none !important; }
  #print-root { display: block; }
  #print-root .sheet { box-shadow: none; margin: 0; height: 296.8mm; min-height: 0; overflow: hidden; break-after: page; page-break-after: always; }
  #print-root .sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ---- 広告の枠（ツールの下。ボタンから離し、PRの札を付ける） ---- */
.aff-slot { max-width: 46rem; margin: 0 auto 2.2rem; border: 1px dashed var(--field-line); border-radius: 12px; padding: .9rem 1.1rem; background: var(--surface); }
.aff-slot-label { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; color: var(--ink-2); border: 1px solid var(--field-line); border-radius: 4px; padding: 0 .4rem; margin: 0 0 .5rem; }
.aff-slot-lead { font-size: .9rem; color: var(--ink-2); margin: 0 0 .6rem; }
.aff-slot .aff-unit { margin: .4rem 0; }

/* ---- 計算ツール ---- */
.calc { display: grid; gap: 1.2rem; }
@media (min-width: 900px) { .calc { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.calc-result { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; }
.calc-title { font-size: .95rem; font-weight: 700; margin: 0 0 .6rem; }
.calc-big { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0 0 .3rem; }
.calc-table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.calc-table th { text-align: left; font-weight: 500; color: var(--ink-2); padding: .4rem 0; border-bottom: 1px solid var(--line); }
.calc-table td { text-align: right; padding: .4rem 0 .4rem .6rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.calc-table th { min-width: 6.5em; }
.nb { white-space: nowrap; }
.calc-law { font-size: .9rem; margin: .8rem 0 0; padding: .6rem .75rem; border-radius: 8px; background: var(--accent-soft); }
.calc-law.ng { background: var(--ng-bg); }
.calc-law strong { display: block; font-size: .8rem; color: var(--ink-2); margin-bottom: .15rem; }
.calc-table tr.strong th, .calc-table tr.strong td { font-weight: 700; color: var(--ink); }
.calc-formula { font-size: .84rem; color: var(--ink-2); background: var(--muted-bg); border-radius: 8px; padding: .6rem .75rem; margin: .8rem 0 0; line-height: 1.7; }

.gap-list { margin: .3rem 0 0; padding-left: 1.3rem; display: grid; gap: .8rem; font-size: .92rem; }
.gap-list li span { color: var(--ink-2); }
.gap-tag { display: inline-block; margin-left: .5rem; font-size: .72rem; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 .35rem; vertical-align: .1em; }
.gap-next { display: inline-block; margin-top: .25rem; font-size: .86rem; }

.related-tools { margin: 2.2rem auto 0; }
.related-tools h2 { font-size: .82rem; letter-spacing: .16em; color: var(--ink-3); font-weight: 600; }
.related-tools ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.related-tools li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .75rem .95rem; display: grid; gap: .1rem; }
.related-tools li a { font-weight: 700; text-decoration: none; }
.related-tools li span { font-size: .86rem; color: var(--ink-2); }
