/* ===== 全局重置 & 打印控制 ===== */
@page {
    size: A4;
    margin: 8mm 10mm;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    margin: 0;
    padding: 0;
    line-height: 1.5;
    color: #1e293b;
}

/* ===== トップナビ（旧サイドバー）===== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 56px;
    background: #1e293b;
    color: #e2e8f0;
    padding: 0 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: row;
    align-items: center;
    z-index: 1000;
    box-sizing: border-box;
}

.sidebar h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 24px 0 0;
    padding: 0;
    border: none;
    color: #f1f5f9;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar nav {
    flex: 1;
    min-width: 0;
    align-self: stretch;   /* サイドバーの高さ(56px)いっぱいに広げ、下記liのホバー判定を隙間なくする */
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* トップレベルのul（メニュー行）だけnavの高さいっぱいに広げる。
   .sub-menu（ドロップダウン内部）は navの直接の子ではないため対象外。 */
.sidebar nav > ul {
    height: 100%;
    align-items: stretch;
}

.sidebar li {
    margin: 0;
    position: relative;   /* ドロップダウンのアンカー */
}

/* トップレベルのliをナビバーの高さいっぱいに広げる（ドロップダウン内部のliは対象外）。
   これにより、ラベルからドロップダウンへ縦にマウスを動かす際に「liの外」を通る隙間が無くなり、
   ホバーが途切れて子メニューが消える問題を防ぐ。 */
.sidebar nav > ul > li {
    display: flex;
    align-items: center;
}

.sidebar .menu-item {
    display: block;
    padding: 8px 14px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.sidebar .menu-item:hover {
    background: #2d3a4f;
    color: #fff;
}

.sidebar .menu-item.active {
    background: #2563eb;
    color: #fff;
    font-weight: 600;
}

/* ドロップダウン（子メニュー）*/
.sidebar .sub-menu {
    position: absolute;
    top: 100%;   /* liがナビバーいっぱいに広がったため、隙間0で直下に接続（ホバー切れ防止） */
    left: 0;
    min-width: 190px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.35);
    z-index: 1001;
}

.sidebar .sub-menu.expanded {
    display: flex;
}

/* マウスホバーでもドロップダウンを表示（クリック不要）。クリック方式（.expanded）と併用可能。 */
.sidebar li:hover > .sub-menu {
    display: flex;
}

.sidebar .sub-menu li { width: 100%; }

.sidebar .sub-menu .menu-item {
    padding: 9px 12px;
    font-size: 13px;
    border-radius: 6px;
}

.sidebar .menu-item.has-children::after {
    content: "▾";
    margin-left: 6px;
    font-size: 12px;
    display: inline-block;
}

/* ===== トップナビ右側（ユーザー・ログアウト）===== */
.sidebar-footer {
    margin-left: auto;
    padding: 0 0 0 16px;
    border: none;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-user-name {
    font-size: 12px;
    color: #94a3b8;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.sidebar-logout-btn {
    width: auto;
    background: transparent;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
    box-shadow: none;
    transition: background 0.2s, color 0.2s;
}
.sidebar-logout-btn:hover {
    background: #334155;
    color: #e2e8f0;
    box-shadow: none;
}

/* ===== 主内容区 ===== */
.main-content {
    margin-left: 0;
    margin-top: 56px;        /* トップナビの高さ分 */
    padding: 30px 20px;
    overflow-x: auto;
    overflow-y: auto;
    background: #f5f7fa;
    height: calc(100vh - 56px);   /* 内部スクロールにしてプレビューのsticky追従を有効化 */
    box-sizing: border-box;
}

/* 卡片容器 */
.card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
    padding: 24px 28px;
    margin-bottom: 30px;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: 0 6px 24px rgba(0,0,0,0.08);
}

/* ===== 作成画面：左に入力カード／右にプレビュー（B:自動縮小 ＋ C:追従） ===== */
.editor-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}
.editor-layout .form-col {
    flex: 6 1 0;
    min-width: 0;
}
.editor-layout .preview-col {
    flex: 4 1 0;
    min-width: 0;
    position: sticky;
    top: 20px;
    --pv-scale: 1;
}
.editor-layout .preview-frame {
    width: 100%;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border-radius: 8px;
}
/* プレビュー本体を縮小表示（.editor-layout配下限定＝PDF出力・履歴プレビューには影響しない） */
.editor-layout .preview-frame > .invoice,
.editor-layout .preview-frame > .furikomi-doc,
.editor-layout .preview-frame > .rb-doc,
.editor-layout .preview-frame > .si-doc {
    transform: scale(var(--pv-scale));
    transform-origin: top left;
    margin: 0;
}
/* 画面が狭いときは従来どおり縦積み（機能・見た目そのまま） */
@media (max-width: 1200px) {
    .editor-layout { display: block; }
    .editor-layout .preview-col { position: static; --pv-scale: 1; }
    .editor-layout .preview-frame {
        width: auto;
        overflow: visible;
        background: none;
        box-shadow: none;
        border-radius: 0;
        height: auto !important;
    }
    .editor-layout .preview-frame > .invoice,
    .editor-layout .preview-frame > .furikomi-doc,
    .editor-layout .preview-frame > .rb-doc,
    .editor-layout .preview-frame > .si-doc {
        transform: none;
        margin: 0 auto;
    }
}

/* 情報カードを2枚1行に並べる（狭ければ自動で縦積み） */
.card-row {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 30px;
}
.card-row > .card {
    flex: 1 1 300px;
    min-width: 0;
    margin-bottom: 0;
}
/* 各ペアとも左カード:右カード = 5.5:4.5 */
.card-row > .card:nth-child(1) { flex: 5.5 1 300px; }
.card-row > .card:nth-child(2) { flex: 4.5 1 300px; }
.card-row .form-row label { width: 96px; }
.card-row .client-row { flex-direction: column; gap: 12px; }

h1.title {
    text-align: center;
    font-size: 32px;
    font-weight: 600;
    margin: 0 0 30px 0;
    letter-spacing: 1px;
    color: #0f172a;
}

h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 20px 0;
    padding-left: 12px;
    border-left: 5px solid #2563eb;
    color: #0f172a;
}

.form-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 12px;
}

.form-row label {
    width: 140px;
    font-weight: 500;
    padding-top: 8px;
    color: #334155;
    font-size: 14px;
    flex-shrink: 0;      /* 狭い画面でinputや隣接selectに押されてラベルが極端に縮み、
                            縦書きのように1文字ずつ折り返される不具合を防ぐ */
    white-space: nowrap;
}

input,
select,
textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* 取引先情報行 */
.client-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.client-name-wrapper {
    flex: 3;
    display: flex;
    gap: 12px;
    position: relative;
}

#clientName,
#clientNameDelivery {
    flex: 2;
    height: 48px;
    padding: 10px 14px;
    box-sizing: border-box;
    font-size: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    resize: vertical;
}

.suffix-select {
    width: 100px;
    height: 60px;
    padding: 10px 14px;
    box-sizing: border-box;
    font-size: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background-color: white;
    cursor: pointer;
}

.client-address-wrapper {
    flex: 2;
}

#clientAddress,
#clientAddressDelivery {
    width: 100%;
    height: 60px;
    padding: 10px 14px;
    box-sizing: border-box;
    font-size: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    resize: vertical;
}

/* 住所5分割入力（郵便番号・都道府県・市区町村・丁目番地号・建物名） */
.addr-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.addr-group input[type="text"] {
    flex: none;
    width: 100%;
}
.addr-zip-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;   /* 狭いカラム（振込明細書の2カラム等）で郵便番号＋ヒントが収まらない場合は折り返す */
}
.addr-zip-row input[type="text"] {
    flex: 0 1 140px;
    min-width: 90px;   /* 極端に狭い画面でも"123-4567"程度は収まる最小幅を確保しつつ縮小可能に */
    width: 140px;
}
.addr-zip-status {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
}
.addr-zip-status.ok { color: #16a34a; }
.addr-zip-status.err { color: #dc2626; }
.addr-zip-hint {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

/* 取引先メール欄の注記。帳票には出ない項目であることを明示する
   （入力欄が並ぶと「これも印字されるのでは」と迷うため） */
.client-email-note {
    margin: -4px 0 12px;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.6;
}

/* ===== メール本文のリッチテキストエディタ =====
   メールHTMLは制約が強い（Outlook等がstyleタグを剥がす・自由な位置指定が効かない）ため、
   ライブラリは使わず contenteditable ＋ execCommand で必要な範囲だけを実装している。
   出力はインラインスタイルなので、そのままメールに載せられる。 */
.rte-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    background: #f8fafc;
}
.rte-toolbar button {
    margin: 0;
    padding: 5px 10px;
    font-size: 13px;
    min-width: 32px;
    background: #fff;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.4;
}
.rte-toolbar button:hover { background: #eef2f7; }

.rte-editor {
    border: 1px solid #e2e8f0;
    border-radius: 0 0 10px 10px;
    padding: 14px 16px;
    min-height: 220px;
    max-height: 380px;
    overflow-y: auto;
    background: #fff;
    font-size: 14px;
    line-height: 1.8;
    color: #333;
    outline: none;
}
.rte-editor:focus { border-color: #93c5fd; }
.rte-editor img {
    max-width: 100%;
    cursor: pointer;
}
.rte-editor img.rte-selected {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
/* 送信画面の本文欄はツールバーが無いので四隅を丸める */
.rte-compose {
    border-radius: 10px;
    min-height: 150px;
    max-height: 260px;
}

/* 画像リサイズのハンドル */
.rte-resize-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #2563eb;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 10020;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
}


/* テンプレート選択モーダル */
.tpl-pick-wrap {
    display: flex;
    gap: 14px;
    align-items: stretch;
}
.tpl-pick-list {
    width: 280px;
    flex: none;
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}
.tpl-pick-preview {
    flex: 1;
    min-width: 0;
    max-height: 380px;
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
    background: #fff;
    font-size: 14px;
    line-height: 1.8;
}
.tpl-pick-preview img { max-width: 100%; }
.tpl-pick-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
}
.tpl-pick-item:hover { background: #f8fafc; }
.tpl-pick-item.active { background: #eff6ff; }
/* 名前と抜粋。長くてもゴミ箱ボタンを押し出さないよう縮められるようにする */
.tpl-pick-body { flex: 1; min-width: 0; }
.tpl-edit-btn,
.tpl-del-btn {
    flex: none;
    margin: 0;
    padding: 5px;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #94a3b8;
    border: none;
    border-radius: 6px;
    box-shadow: none;
    cursor: pointer;
}
.tpl-edit-btn:hover { background: #e0e7ff; color: #4338ca; }
.tpl-del-btn:hover  { background: #fee2e2; color: #b91c1c; }
.tpl-edit-btn .trash-icon-svg,
.tpl-del-btn  .trash-icon-svg { width: 16px; height: 16px; }
.tpl-pick-item .tpl-name {
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 3px;
}
.tpl-pick-item .tpl-meta {
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tpl-pick-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
    line-height: 1.7;
}

@media (max-width: 700px) {
    .tpl-pick-wrap { flex-direction: column; }
    .tpl-pick-list { width: 100%; max-height: 200px; }
}

/* 下拉列表通用样式 */
.company-dropdown,
.item-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 8px 16px rgba(0,0,0,0.05);
    display: none;
}

.company-dropdown.active,
.item-dropdown.active {
    display: block;
}

.company-dropdown-item,
.item-dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.2s;
}

.company-dropdown-item:hover,
.item-dropdown-item:hover {
    background-color: #f8fafc;
}

.company-dropdown-item:last-child,
.item-dropdown-item:last-child {
    border-bottom: none;
}

.company-dropdown-item .company-name,
.item-dropdown-item .item-name {
    font-weight: 600;
    color: #0f172a;
}

.company-dropdown-item .company-detail,
.item-dropdown-item .item-detail {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-row input,
.form-row select,
.form-row textarea {
    height: auto;
    min-height: auto;
    min-width: 0;   /* labelが縮まなくなった分、input側が自由に縮んで先に幅を譲れるようにする */
}

textarea {
    resize: vertical;
    min-height: 70px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th,
td {
    border: 1px solid #e2e8f0;
    padding: 12px 8px;
    text-align: center;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: #1e293b;
}

.trash-icon-svg {
    width: 20px;
    height: 20px;
    display: block;
}

.trash-icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    min-width: 30px;
    height: 30px;
    padding: 0;
}

.trash-text-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
} 

.delete-btn {
    background-color: #ef4444;
    color: white;
    border: none;
    border-radius: 30px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.delete-btn:hover {
    background-color: #dc2626;
}

.save-btn {
    background-color: #217346;
    color: white;
    border: none;
    border-radius: 30px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 5px;
}

.save-btn:hover {
    background-color: #185c38;
}

/* 商品明细的输入框样式 */
.item-edit-table input[type="number"],
.item-edit-table input[type="text"],
.item-edit-table select,
#deliveryItemTable input[type="number"],
#deliveryItemTable input[type="text"],
#deliveryItemTable select,
#siRowTable input[type="number"],
#siRowTable input[type="text"],
#siRowTable input[type="date"] {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.item-edit-table {
    width: 100%;
    table-layout: fixed;
}

/* 列幅は「役割クラス」で指定する（nth-child依存を廃止）。
   table-layout:fixed のため、先頭行（thead th）の幅指定だけで全列が決まる。
   内容幅がほぼ一定の列は固定幅にし、商品コード・商品名が残り幅を自動で分け合う。
   列を追加・表示切替しても他の列の定義を直す必要がない。 */
.item-edit-table th.col-detail { width: 60px; }  /* “详细”按钮列 */
.item-edit-table th.col-price  { width: 90px; }  /* 单价 */
.item-edit-table th.col-qty    { width: 80px; }  /* 数量 */
.item-edit-table th.col-unit   { width: 64px; }  /* 单位（默认隐藏） */
.item-edit-table th.col-tax    { width: 80px; }  /* 税区分 */
.item-edit-table th.col-amount { width: 100px; }   /* 价格（金额） */
.item-edit-table th.col-ops    { width: 76px; }    /* 操作按钮 */

/* 商品コード表示時：コードは固定幅にし、幅未指定の商品名が残り幅を全部取る（商品名優先） */
.item-edit-table th.col-code   { width: 160px; }
.item-edit-table th.col-orderno { width: 140px; }
.item-edit-table th.col-modelno { width: 130px; }

/* 商品コード非表示時（.code-hidden はJSが表示設定に応じて付け外しする）：
   商品名は300px固定にし、残りの幅は詳細以外の各列で均等に分け合う */
.item-edit-table.code-hidden th.col-name   { width: 300px; }
.item-edit-table.code-hidden th.col-price,
.item-edit-table.code-hidden th.col-qty,
.item-edit-table.code-hidden th.col-unit,
.item-edit-table.code-hidden th.col-tax,
.item-edit-table.code-hidden th.col-amount { width: auto; }
/* 操作列はアイコン2つ分だけあればよいため、他のauto列と均等割りにせず固定幅にする
   （均等割りだとアイコンの周りに大きな余白ができ、不自然に太い列になってしまう） */
.item-edit-table.code-hidden th.col-ops    { width: 76px; }

/* 単価・数量などの数値入力のスピンボタン（上下の増減矢印）を非表示にして入力幅を確保する */
.item-edit-table input[type="number"]::-webkit-outer-spin-button,
.item-edit-table input[type="number"]::-webkit-inner-spin-button,
#deliveryItemTable input[type="number"]::-webkit-outer-spin-button,
#deliveryItemTable input[type="number"]::-webkit-inner-spin-button,
#rbItemTable input[type="number"]::-webkit-outer-spin-button,
#rbItemTable input[type="number"]::-webkit-inner-spin-button,
#siRowTable input[type="number"]::-webkit-outer-spin-button,
#siRowTable input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.item-edit-table input[type="number"],
#deliveryItemTable input[type="number"],
#rbItemTable input[type="number"],
#siRowTable input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}


/* 明細行の操作ボタン（アイコン化して幅を節約）。
   月次請求書の明細表だけ .item-edit-table ではなく #siRowTable なので、両方を並べる。
   （片方だけにすると .icon-btn を付けても効かない死んだクラスになる） */
.item-edit-table .icon-btn,
#siRowTable .icon-btn {
    padding: 5px 9px;
    font-size: 14px;
    line-height: 1;
    margin: 0 2px 0 0;
    box-shadow: none;
    border-radius: 8px;
}

/* 詳細入力ボタン（内容が入っている行は青くハイライト） */
.item-edit-table .detail-btn {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #64748b;
    padding: 5px 8px;
    font-size: 14px;
    line-height: 1;
    margin: 0;
    box-shadow: none;
    border-radius: 8px;
}
.item-edit-table .detail-btn:hover {
    background: #e2e8f0;
    box-shadow: none;
}
.item-edit-table .detail-btn.has-detail {
    background: #dbeafe;
    border-color: #2563eb;
}
.item-edit-table .detail-btn.has-detail:hover {
    background: #bfdbfe;
}

/* 請求書プレビュー内の商品詳細（商品名の下の補足行。空なら生成されない） */
.invoice-items-table .item-detail-note {
    font-size: 10.5px;
    color: #555;
    font-weight: 400;
    line-height: 1.5;
    margin-top: 2px;
    white-space: pre-wrap;
    word-break: break-word;
    text-align: left;
}

.summary-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 20px;
    gap: 20px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.tax-breakdown-container {
    width: 45%;
    min-width: 280px;
}

.right-summary-container {
    width: 40%;
    min-width: 180px;
    margin-left: auto;
}

/* 前金入金済額（テンプレート4専用）：小計欄のすぐ上、右カラムの幅に合わせて表示する。
   他テンプレートでは入力欄はあってもプレビューに反映されない（納期・支払条件などと同じ扱い）。 */
.deposit-amount-row {
    margin-bottom: 8px;
}
.deposit-amount-row label {
    display: block;
    font-size: 12px;
    color: #64748b;
    margin-bottom: 4px;
}
.deposit-amount-row input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
}

.tax-breakdown-title {
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #1e293b;
}

.tax-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: #fff;
    border: none;
}

.tax-breakdown-table th {
    background: transparent;
    border: none;
    border-bottom: 2px solid #cbd5e1;
    padding: 8px 4px;
    text-align: right;
    font-weight: 500;
    font-size: 12px;
    color: #06080a;
}

.tax-breakdown-table td {
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 4px;
    text-align: right;
    font-size: 12px;
}

.tax-breakdown-table th:first-child,
.tax-breakdown-table td:first-child {
    text-align: left;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: #fff;
    border: none;
}

.summary-table th {
    background: transparent;
    border: none;
    border-bottom: 2px solid #cbd5e1;
    padding: 8px 4px;
    text-align: right;
    font-weight: 600;
    color: #334155;
}

.summary-table td {
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 4px;
    text-align: right;
}

.summary-table th:first-child,
.summary-table td:first-child {
    text-align: left;
}

.summary-table tr:last-child td {
    border-bottom: none;
    font-weight: 700;
    font-size: 16px;
}

/* 隐藏旧.right  */
.right {
    display: none;
}

/* ===== 振込明細書 本体 ===== */
.furikomi-doc {
    width: 210mm;
    min-width: 210mm;
    margin: 0 auto;
    background: #fff;
    box-sizing: border-box;
    padding: 14mm 15mm;
    font-family: "Yu Gothic","Meiryo","MS PGothic",sans-serif;
    color: #1a1a1a;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.furikomi-doc * { box-sizing: border-box; }
.fk-issue-row { display:flex; justify-content:flex-end; }
.fk-issue-meta { margin:0 0 3px; text-align:left; font-size:11.5px; line-height:1.6; color:#444; }
.fk-head { display:flex; justify-content:space-between; gap:16px; margin-bottom:16px; }
.fk-party { font-size:12px; line-height:1.4; }
.fk-party.fk-l { width:54%; }
.fk-party.fk-l { display:flex; flex-direction:column; }
.fk-party.fk-r { width:42%; }
.fk-party .nm { font-size:15px; font-weight:700; letter-spacing:.5px; margin-bottom:4px; }
.fk-party .nm .go { font-size:15px; font-weight:700; margin-left:8px; }
.fk-party .sub { color:#333; }
.fk-party .meta { margin-top:0; font-size:11.5px; color:#444; }
.fk-party .meta div { line-height:1.4; }
.fk-title { text-align:center; font-size:21px; font-weight:700; letter-spacing:6px; margin:4px 0 14px; }
.fk-mid { display:flex; justify-content:space-between; gap:20px; margin-bottom:12px; }
.fk-greet { width:55%; font-size:12px; line-height:1.75; color:#333; padding-top:2px; }
.fk-party.fk-l .fk-greet { width:104.63%; margin-top:auto; padding-top:8px; }
.fk-bank { width:42%; border:1px solid #cfcabb; border-radius:4px; overflow:hidden; align-self:flex-start; }
.fk-mid .fk-bank { margin-left:auto; }
.fk-bank .bh, .fk-summary .bh { background:#3a3a3a; color:#fff; font-size:12px; font-weight:700; padding:5px 10px; letter-spacing:1px; text-align:center; }
.fk-mid .fk-bank table, .fk-mid .fk-summary table { margin-top:0; }
.fk-bank table { width:100%; border-collapse:collapse; font-size:11.5px; }
.fk-bank td { height:25px; box-sizing:border-box; padding:4px 10px; line-height:16px; border-bottom:1px solid #e8e4d8; }
.fk-bank td.k { width:34%; background:#f6f2e6; color:#000; white-space:nowrap; }
.fk-bank tr:last-child td { border-bottom:none; }
.fk-summary { border:1px solid #cfcabb; border-radius:4px; overflow:hidden; margin-bottom:6px; }
.fk-summary table { width:100%; border-collapse:collapse; font-size:12px; }
.fk-summary td { padding:5px 12px; border-bottom:1px solid #e8e4d8; }
.fk-summary td.k { width:20%; background:#f6f2e6; color:#000; white-space:nowrap; }
.fk-summary td.sub-k { width:24%; background:#faf8f1; color:#333; padding-left:24px; }
.fk-summary td.amt { text-align:right; width:18%; font-variant-numeric:tabular-nums; }
.fk-summary .total-row td { background:#f6f2e6; font-weight:700; font-size:14px; border-bottom:none; }
.fk-summary .total-row td.amt { font-size:16px; }
.fk-summary.fk-summary-vertical { width:55%; margin-bottom:0; align-self:flex-start; }
.fk-summary.fk-summary-vertical table { table-layout:fixed; }
.fk-summary.fk-summary-vertical td { height:25px; box-sizing:border-box; padding-top:4px; padding-bottom:4px; line-height:16px; }
.fk-summary.fk-summary-vertical td.k,
.fk-summary.fk-summary-vertical td.sub-k { width:50%; padding-left:12px; white-space:nowrap; }
.fk-summary.fk-summary-vertical td.sub-k { background:#f6f2e6; color:#000; }
.fk-summary.fk-summary-vertical td.amt { text-align:left; }
.fk-note { font-size:10.5px; color:#777; margin:4px 2px 14px; }
.fk-sec-h { font-size:13px; font-weight:700; margin:0 0 6px; padding-left:8px; border-left:4px solid #3a3a3a; }
.fk-block { margin-bottom:14px; }
table.fk-detail { width:100%; border-collapse:collapse; font-size:11.5px; margin-bottom:6px; }
table.fk-detail th { background:#3a3a3a; color:#fff; font-weight:500; padding:5px 10px; text-align:left; }
table.fk-detail th.r, table.fk-detail td.r { text-align:right; font-variant-numeric:tabular-nums; }
table.fk-detail td { padding:5px 10px; border-bottom:1px solid #e2ddce; }
table.fk-detail tr.period td { background:#f6f2e6; font-weight:700; font-size:11px; }
table.fk-detail tr.subtotal td { background:#faf8f1; font-weight:700; }
table.fk-detail tr.tax td { color:#444; }
table.fk-detail tr.grand td { background:#f6f2e6; font-weight:700; font-size:12.5px; }
.fk-right-label { text-align:right; }
@media print {
    @page { size: A4; margin: 0; }
    .furikomi-doc { margin:0; }
}

/* 振込明細書 入力テーブル */
#fkRewardTable { width:100%; border-collapse:collapse; }
#fkRewardTable th { font-size:13px; color:#334155; font-weight:500; padding:6px 8px; text-align:left; }
#fkRewardTable td { padding:4px; }
#fkRewardTable input { width:100%; }
.fk-del-btn {
    background:#ef4444;
    box-shadow:none;
    margin:0;
    padding:0;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    width:30px;
    min-width:30px;
    height:30px;
}

/* ===== 社員立替金申請・精算書 ===== */
/* 取引先へ送付する対外文書ではなく社内の経費精算記録なので、請求書・振込明細書のような
   ロゴ/印影/取引先カードは無い。4つの署名欄は印刷専用の空欄（下線のみ、入力欄ではない）。

   配色は翡翠緑＋金。以前はコピー・FAX・スキャン耐性を優先してモノクロにしていたが、
   慶事寄りの華やかさを求めて変更した。赤系（中国紅・朱色など）も試した上で、繁栄・富貴を
   象徴する緑系に決めた。白黒複写では地の色（--rb-key-bg等）が薄いグレーに沈む点は変わらない
   ので、多段階の複写を重ねる運用なら注意。対外帳票（請求書・振込明細書のベージュ＋チャコール）
   とも自然に区別がつく。色は下の変数だけで完結しているので、配色変更時はこの6行を
   書き換えれば済む。 */
.rb-doc {
    --rb-bar-bg:  #0f6b52;   /* 見出しバー・表ヘッダーの背景 */
    --rb-bar-fg:  #fdf6e0;   /* 同・文字色 */
    --rb-key-bg:  #e6f3ee;   /* 項目名セル・合計行の背景 */
    --rb-sub-bg:  #f2f9f6;   /* 税区分内訳行の背景 */
    --rb-border:  #c9a227;   /* 枠線 */
    --rb-rule:    #d2e8df;   /* 行の区切り線 */

    width: 210mm;
    min-width: 210mm;
    margin: 0 auto;
    background: #fff;
    box-sizing: border-box;
    padding: 14mm 15mm;
    font-family: "Yu Gothic","Meiryo","MS PGothic",sans-serif;
    color: #1a1a1a;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.rb-doc * { box-sizing: border-box; }
.rb-title { text-align:center; font-size:21px; font-weight:700; letter-spacing:6px; margin:0 0 16px; }
/* 振込明細書（.fk-summary/.fk-bank）と同じ「ヘッダーバー付きの枠囲みパネル」の構造を踏襲（色だけ別系統） */
.rb-info-box { border:1px solid var(--rb-border); border-radius:4px; overflow:hidden; margin-bottom:16px; }
.rb-info-box .bh { background:var(--rb-bar-bg); color:var(--rb-bar-fg); font-size:12px; font-weight:700; padding:5px 10px; letter-spacing:1px; text-align:center; }
.rb-head-table { width:100%; border-collapse:collapse; font-size:12px; margin:0; }
.rb-head-table td { padding:7px 12px; border-bottom:1px solid var(--rb-rule); }
.rb-head-table tr:last-child td { border-bottom:none; }
.rb-head-table td.rb-k { width:16%; background:var(--rb-key-bg); color:#000; white-space:nowrap; font-weight:600; }
.rb-sec-h { font-size:13px; font-weight:700; margin:0 0 6px; padding-left:8px; border-left:4px solid var(--rb-bar-bg); }
table.rb-detail { width:100%; border-collapse:collapse; font-size:11px; margin-bottom:20px; }
table.rb-detail th { background:var(--rb-bar-bg); color:var(--rb-bar-fg); font-weight:500; padding:6px 8px; text-align:left; }
table.rb-detail th.r, table.rb-detail td.r { text-align:right; font-variant-numeric:tabular-nums; }
/* 折り返してほしくない列（利用日の日付・「税区分」の3文字）。
   見出しの改行位置は renderReimburse() 側で <br> を直接入れて制御している。 */
table.rb-detail .rb-nw { white-space:nowrap; }
/* 括弧つき見出し（「内容・目的（業務との関連）」等）を2行に割ったときの位置合わせ。
   全角の「（」は字幅1em分を占めるため、素直に改行すると括弧が上の行の文字と揃い、
   括弧の中身が1文字ぶん右にずれて見える。左paddingを1em確保したうえで括弧行だけ
   1em引き戻すことで、上の行の文字と括弧の中身が縦に揃う（括弧はぶら下がる）。 */
table.rb-detail th.rb-ph { padding-left:1em; }
table.rb-detail th.rb-ph span { display:inline-block; margin-left:-1em; }
table.rb-detail td { padding:5px 8px; border-bottom:1px solid var(--rb-rule); }
table.rb-detail tr.rb-tax-row td { background:var(--rb-sub-bg); color:#444; font-size:10.5px; }
table.rb-detail tr.rb-total-row td { background:var(--rb-key-bg); color:var(--rb-bar-bg); font-weight:700; font-size:13px; border-bottom:none; }
.rb-right-label { text-align:right; }
.rb-sign-block { display:flex; gap:12px; margin-top:8px; }
.rb-sign-box { flex:1; border:1px solid var(--rb-border); border-radius:4px; overflow:hidden; font-size:11.5px; }
.rb-sign-h { background:var(--rb-bar-bg); color:var(--rb-bar-fg); font-weight:700; padding:5px 8px; text-align:center; letter-spacing:1px; font-size:11.5px; }
.rb-sign-body { padding:10px 12px 30px; }
.rb-sign-line { border-bottom:1px solid #8c8c8c; padding-bottom:2px; margin-top:16px; color:#555; }
@media print {
    @page { size: A4; margin: 0; }
    .rb-doc { margin:0; }
}
/* 立替金申請・精算書 入力テーブル */
#rbItemTable { width:100%; border-collapse:collapse; }
#rbItemTable th { font-size:12px; color:#334155; font-weight:500; padding:6px 6px; text-align:left; }
#rbItemTable td { padding:4px; }
#rbItemTable input, #rbItemTable select, #rbItemTable textarea { width:100%; }
/* 内容・目的は複数行入力。JS側で中身に合わせて高さを伸ばす（上限120px） */
#rbItemTable .rb-purpose {
    min-height: 34px;
    resize: vertical;
    overflow-y: auto;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    padding: 6px 8px;
}
#rbItemTable .rb-row-no { text-align:center; color:#64748b; font-size:13px; }
/* 利用日：明細行が狭いのでカレンダーアイコンだけの省スペース表示にする。
   ★横幅は常に固定★ ホバーで広げるとアイコンの位置がずれて、
   「ホバー→アイコンが動く→狙い直してクリック」と二度手間になるため。
   選択済みの日付は title 属性のツールチップで確認できる（JS側で同期）。
   値は消していない（transparentなのは表示上だけ）ので保存値には影響しない。 */
#rbItemTable .rb-date {
    width: 28px;
    min-width: 28px;
    padding: 4px 2px;
    color: transparent;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
}
#rbItemTable .rb-date::-webkit-calendar-picker-indicator {
    opacity: 1;
    cursor: pointer;
}
/* 数値は右揃えにして、隣の「1人当たり金額」「精算合計」と桁位置を揃える */
#rbItemTable .rb-headcount, #rbItemTable .rb-amount { text-align:right; }
.rb-del-btn {
    background:#ef4444;
    box-shadow:none;
    margin:0;
    padding:0;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    width:30px;
    min-width:30px;
    height:30px;
}

/* ===== 請求書本体 ===== */
.invoice {
    width: 210mm;
    min-width: 210mm;
    max-width: none;
    margin: 0 auto;
    background: #fff;
    border: none;
    border-radius: 0;
    padding: 8mm 10mm;
    box-sizing: border-box;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    --invoice-reg-number-font-size: 14px;
    overflow: hidden;
}

.invoice h1.title {
    font-size: 34px;
    margin-top: 0;
    margin-bottom: 24px;
    letter-spacing: 2px;
}

.invoice > .header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 30px;
    margin-bottom: 24px;
}

.box {
    flex: 2;
    min-width: 200px;
}

.client-name-line {
    font-size: 18px;
    margin-bottom: 6px;
    font-weight: 600;
}

.client-suffix {
    font-size: 15px;
    color: #475569;
    margin-left: 5px;
}

/* 取引先名の下の加盟店表示（.client-name-line内のブロック行。空なら非表示）。
   各テンプレートで対方会社名（.client-name-line strong）と同じ字号・字重に揃える。 */
.client-kamei {
    font-size: 18px;
    font-weight: 600;
    margin-top: 2px;
}
.invoice.template-1 .client-kamei {
    font-size: 13pt;
    font-weight: 500;
    color: #000;
}
.invoice.template-2 .client-kamei {
    font-size: 18px;
    font-weight: 900;   /* template-2の会社名は<strong>のbolderで実効900のため合わせる */
    color: #000;
}
.invoice.template-3 .client-kamei {
    font-size: 15px;
    font-weight: 700;
    color: #000;
}

.company-info {
    position: relative;
    padding-right: 2.8cm;
    margin-left: auto;
    width: auto;
    max-width: 55%;
    background: #fff;
    word-break: break-word;
    text-align: left;
}

.company-details {
    line-height: 1.3;
    margin: 0;
}

.company-details .address-wrap {
    line-height: inherit;
    margin-bottom: 0;
}

.company-reg-number {
    font-size: var(--invoice-reg-number-font-size);
    line-height: 1.3;
    margin: 0;
}

.stamp {
    position: absolute;
    right: 0;
    top: 0; 
    width: 2.2cm;
    height: 2.2cm;
    object-fit: contain;
    border-radius: 8px;
}

.address-wrap {
    display: block;
    word-break: break-all;
    line-height: 1.6;
    margin-bottom: 4px;
    white-space: pre-wrap;
}

.amount-box {
    font-size: 24px;
    font-weight: 700;
    margin: 20px 0 15px;
    background: #fff;
    padding: 12px 20px;
    border-left: 6px solid #2563eb;
    border-radius: 0 12px 12px 0;
    color: #0f172a;
}

#invoiceItems {
    margin: 20px 0;
}

#invoiceItems table {
    width: 100%;
    border-collapse: collapse;
}

.invoice-items {
    margin: 20px 0;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.invoice-items-table thead {
    display: table-header-group;
}

.invoice-items-table thead th {
    font-weight: 700;
    background: #fff;
    padding: 10px 8px;
    border-bottom: 2px solid #94a3b8;
    vertical-align: middle;
    box-sizing: border-box;
}

.invoice-items-table tbody tr {
    page-break-inside: avoid;
}

.invoice-items-table tbody td {
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
    box-sizing: border-box;
}

/* コードあり列幅 */
.invoice-items-table.invoice-layout-code th:nth-child(1),
.invoice-items-table.invoice-layout-code td:nth-child(1) { width: 21%; }
.invoice-items-table.invoice-layout-code th:nth-child(2),
.invoice-items-table.invoice-layout-code td:nth-child(2) { width: 37%; }
.invoice-items-table.invoice-layout-code th:nth-child(3),
.invoice-items-table.invoice-layout-code td:nth-child(3) { width: 15%; }
.invoice-items-table.invoice-layout-code th:nth-child(4),
.invoice-items-table.invoice-layout-code td:nth-child(4) { width: 12%; }
.invoice-items-table.invoice-layout-code th:nth-child(5),
.invoice-items-table.invoice-layout-code td:nth-child(5) { width: 19%; }

/* コードなし列幅 */
.invoice-items-table.invoice-layout-default td:nth-child(1),
.invoice-items-table.invoice-layout-default th:nth-child(1) { width: 51%; }
.invoice-items-table.invoice-layout-default td:nth-child(2),
.invoice-items-table.invoice-layout-default th:nth-child(2) { width: 20%; }
.invoice-items-table.invoice-layout-default td:nth-child(3),
.invoice-items-table.invoice-layout-default th:nth-child(3) { width: 17%; }
.invoice-items-table.invoice-layout-default td:nth-child(4),
.invoice-items-table.invoice-layout-default th:nth-child(4) { width: 20%; }

/* ===== 税区分列あり（請求書設定「税区分を表示」ON時）=====
   既存の invoice-layout-code / invoice-layout-default は一切変更せず、
   列が1本増えた版を別クラスとして新設する。設定OFFのときは従来のクラスがそのまま
   使われるため、既存の請求書の見た目には影響しない。
   列順は「商品名 → 税区分 → 単価 → 数量 → 価格」（税区分は単価の直前）。 */

/* コードあり＋税区分（6列：商品コード/商品名/税区分/単価/数量/価格） */
.invoice-items-table.invoice-layout-code-tax th:nth-child(1),
.invoice-items-table.invoice-layout-code-tax td:nth-child(1) { width: 18%; }
.invoice-items-table.invoice-layout-code-tax th:nth-child(2),
.invoice-items-table.invoice-layout-code-tax td:nth-child(2) { width: 30%; }
.invoice-items-table.invoice-layout-code-tax th:nth-child(3),
.invoice-items-table.invoice-layout-code-tax td:nth-child(3) { width: 11%; }
.invoice-items-table.invoice-layout-code-tax th:nth-child(4),
.invoice-items-table.invoice-layout-code-tax td:nth-child(4) { width: 14%; }
.invoice-items-table.invoice-layout-code-tax th:nth-child(5),
.invoice-items-table.invoice-layout-code-tax td:nth-child(5) { width: 10%; }
.invoice-items-table.invoice-layout-code-tax th:nth-child(6),
.invoice-items-table.invoice-layout-code-tax td:nth-child(6) { width: 17%; }

/* コードなし＋税区分（5列：商品名/税区分/単価/数量/価格） */
.invoice-items-table.invoice-layout-default-tax th:nth-child(1),
.invoice-items-table.invoice-layout-default-tax td:nth-child(1) { width: 42%; }
.invoice-items-table.invoice-layout-default-tax th:nth-child(2),
.invoice-items-table.invoice-layout-default-tax td:nth-child(2) { width: 11%; }
.invoice-items-table.invoice-layout-default-tax th:nth-child(3),
.invoice-items-table.invoice-layout-default-tax td:nth-child(3) { width: 18%; }
.invoice-items-table.invoice-layout-default-tax th:nth-child(4),
.invoice-items-table.invoice-layout-default-tax td:nth-child(4) { width: 12%; }
.invoice-items-table.invoice-layout-default-tax th:nth-child(5),
.invoice-items-table.invoice-layout-default-tax td:nth-child(5) { width: 17%; }

/* 商品コード列は折り返し禁止（税区分ありの場合も同じ扱い） */
.invoice-items-table.invoice-layout-code-tax td:first-child {
    white-space: nowrap;
    word-break: normal;
}

/* 右寄せ（単価・数量・価格）。税区分は金額ではないので中央寄せにする。 */
.invoice-items-table.invoice-layout-code-tax td:nth-child(4),
.invoice-items-table.invoice-layout-code-tax td:nth-child(5),
.invoice-items-table.invoice-layout-code-tax td:nth-child(6),
.invoice-items-table.invoice-layout-code-tax th:nth-child(4),
.invoice-items-table.invoice-layout-code-tax th:nth-child(5),
.invoice-items-table.invoice-layout-code-tax th:nth-child(6) {
    text-align: end;
    font-variant-numeric: tabular-nums;
}
.invoice-items-table.invoice-layout-code-tax td:nth-child(3),
.invoice-items-table.invoice-layout-code-tax th:nth-child(3) {
    text-align: center;
}

.invoice-items-table.invoice-layout-default-tax td:nth-child(3),
.invoice-items-table.invoice-layout-default-tax td:nth-child(4),
.invoice-items-table.invoice-layout-default-tax td:nth-child(5),
.invoice-items-table.invoice-layout-default-tax th:nth-child(3),
.invoice-items-table.invoice-layout-default-tax th:nth-child(4),
.invoice-items-table.invoice-layout-default-tax th:nth-child(5) {
    text-align: end;
    font-variant-numeric: tabular-nums;
}
.invoice-items-table.invoice-layout-default-tax td:nth-child(2),
.invoice-items-table.invoice-layout-default-tax th:nth-child(2) {
    text-align: center;
}

/* 納品書・見積書のプレビュー明細列幅（.dq-cols）。
   請求書の invoice-layout-code/-default とは完全に別系統で、請求書側には一切影響しない。
   列は役割クラスで指定するので、注文No./商品コードの表示切替で列数が変わっても他の列を直す必要がない。
   商品名は幅未指定にして残り幅を自動で吸収させる（編集テーブルの col-name と同じ考え方）。
   数量は「12,345本」（5桁＋3桁区切り＋単位）が1行に収まる幅を確保する。実測で12%が
   折り返しの境目なので余裕を見て13%。増やした分は商品コード側から回す（商品コードは
   23%＝165pxと広く、ABC-12345程度なら20%でも十分なため商品名を削らずに済む）。 */
.invoice-items-table.dq-cols th.col-orderno,
.invoice-items-table.dq-cols td.col-orderno { width: 12%; }
.invoice-items-table.dq-cols th.col-code,
.invoice-items-table.dq-cols td.col-code { width: 20%; }
.invoice-items-table.dq-cols th.col-price,
.invoice-items-table.dq-cols td.col-price { width: 16%; }
.invoice-items-table.dq-cols th.col-qty,
.invoice-items-table.dq-cols td.col-qty { width: 13%; }
.invoice-items-table.dq-cols th.col-amount,
.invoice-items-table.dq-cols td.col-amount { width: 15%; }

/* 見積書テンプレート1の明細列幅（.dq-cols の上書き）。
   .dq-cols は納品書と共用なので、ここは #estimatePreview で囲って見積書だけに効かせる。
   狙いは「単価・価格が9桁＋円でも1行に収まること」。実測で 18%（129px）が折り返しの境目で、
   価格側は余裕を見て19%にしてある。増やした分は幅未指定の商品名列が自動で吸収して縮む。
   テンプレート2は明細に円を付けないため元の15/16%で足りる（:not(.es-template-2) で除外）。 */
#estimatePreview:not(.es-template-2) .invoice-items-table.dq-cols th.col-price,
#estimatePreview:not(.es-template-2) .invoice-items-table.dq-cols td.col-price { width: 18%; }
#estimatePreview:not(.es-template-2) .invoice-items-table.dq-cols th.col-amount,
#estimatePreview:not(.es-template-2) .invoice-items-table.dq-cols td.col-amount { width: 19%; }

/* ===== 見積書テンプレート2 =====
   ★クラス名が template-2 ではなく es-template-2 なのは、請求書の .invoice.template-2
     （全く別デザインの請求書スタイル）と衝突させないため。納品書の dl-template-3 と同じ理屈。
   #estimatePreview は常に .invoice.template-1 を持ったままで、テンプレート2のときだけ
   この es-template-2 が追加される。つまりテンプレート2は「テンプレート1＋差分」という作り。
   いまは差分ゼロ＝完全な複製なので、この下は空にしてある。
   テンプレート2固有のデザインが決まったら、ここに上書き規則を足していく。 */

/* #estimatePreview.es-template-2 { ... } */

/* ===== 数量・規格別内訳（見積書）===== */
/* 税率別内訳と同じ枠（.tax-breakdown-container）に入れるので、幅と位置はそれに乗る。
   表示ONのとき左カラムに入り、税率別内訳は右カラム（合計欄の下）へ移動する。
   入れ替えは createEstimate → renderEstimateSpecBreakdown() がDOMごと行う。 */
.spec-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

/* グローバルの th,td { border: 1px solid ... } を明示的に打ち消す。
   残しておくと1行ずつ格子状に囲まれて、集計表としては線が多すぎる。
   区切りは「見出しの下」と「総数量の上」の2本だけにする。 */
.spec-breakdown-table td {
    border: none;
    padding: 6px 4px;
    vertical-align: middle;
}

/* 規格名と数量は本文として読ませるので、表の基準(11px)より少し大きくする。
   単位（本・点）は添え物なので基準サイズのまま小さく残す。 */
.spec-breakdown-table .spec-name {
    text-align: start;
    font-size: 14px;
}

/* 数量は桁を揃えたいので等幅数字＋右寄せ。単位は数字のすぐ右に小さく添える。 */
.spec-breakdown-table .spec-qty {
    text-align: end;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    width: 30%;
    font-size: 14px;
}

.spec-breakdown-table .spec-unit {
    text-align: start;
    width: 2.5em;
    padding-left: 4px;
    color: #475569;
    white-space: nowrap;
    font-size: 12px;
}

.spec-breakdown-table .spec-total-tr td {
    border-top: 1px solid #e2e8f0;
    font-weight: 700;
    padding-top: 10px;
}

/* 規格表を出すときは上揃えにする。既定の align-items:flex-end のままだと、
   税率別内訳を取り込んで背の高くなった右カラムに引きずられ、左の規格表が
   下端へ落ちて明細との間に大きな空白ができる。 */
.summary-wrapper.has-spec-breakdown {
    align-items: flex-start;
}

/* 規格表と税率別内訳を同時に出すときは、左右をそれぞれ枠で囲む。
   枠が無いと2つの表がばらばらに浮いて見え、上端・下端も揃わない。
   align-items:stretch で高さを揃え、2つの枠の天地をぴったり合わせる。 */
.summary-wrapper.boxed-summary {
    align-items: stretch;
}

.summary-wrapper.boxed-summary > .tax-breakdown-container,
.summary-wrapper.boxed-summary > .right-summary-container {
    /* 罫線は明細と同じ淡いグレー。濃い線で囲うと枠だけが浮いて硬く見える。 */
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 14px 14px;
    box-sizing: border-box;
    background: #fff;
}

/* 枠を付けると内側の余白のぶんだけ表の使える幅が減る。既定の 45%/40% のままだと
   右枠に金額サマリーと税率別内訳を縦に重ねたとき、百万円台の金額が「1,135,985」と
   「円」に泣き別れる。枠モードのときだけ左右を広げて余白ぶんを取り戻す。 */
.summary-wrapper.boxed-summary > .tax-breakdown-container {
    width: 46%;
}

.summary-wrapper.boxed-summary > .right-summary-container {
    width: 50%;
}

/* 枠の中の見出し（数量・規格別内訳／金額サマリー／税率別内訳）。
   先頭に小さな■を付け、下に区切り線を敷いて中身と分ける。 */
.summary-wrapper.boxed-summary .tax-breakdown-title {
    font-size: 11.5px;
    font-weight: 700;
    color: #1e293b;
    padding-bottom: 7px;
    margin-bottom: 10px;
    border-bottom: 1px solid #e2e8f0;
}

.summary-wrapper.boxed-summary .tax-breakdown-title::before {
    content: "■";
    color: #94a3b8;
    font-size: 9px;
    margin-right: 5px;
    vertical-align: 1px;
}

/* 枠内に入った税率別内訳は、金額サマリーとの間を少し空ける。 */
.summary-wrapper.boxed-summary .right-summary-container .tax-breakdown-container {
    margin-top: 12px;
}

/* 右枠は金額サマリーと税率別内訳を縦に重ねるぶん背が高くなりやすい。
   枠モードのときだけ行の上下余白を詰めて、左の規格表と釣り合う高さにする。
   枠を付けないときは従来どおり（8px）のゆったりした行間のまま。 */
.summary-wrapper.boxed-summary .summary-table th,
.summary-wrapper.boxed-summary .summary-table td,
.summary-wrapper.boxed-summary .tax-breakdown-table th,
.summary-wrapper.boxed-summary .tax-breakdown-table td {
    padding-top: 5px;
    padding-bottom: 5px;
}

/* 税率別内訳が右カラム（合計欄の下）へ移ったときは、枠いっぱいに広げて合計欄と幅を揃える。
   左カラムにいるときの width:45% / min-width:280px は効かせない。 */
.right-summary-container .tax-breakdown-container {
    width: 100%;
    min-width: 0;
    margin-top: 16px;
}

.page-break-before {
    page-break-before: always;
    display: none;
}

/* 左对齐（商品名・商品コード） */
.invoice-items-table td:first-child,
.invoice-items-table th:first-child {
    text-align: start;
    word-break: break-word;
}

/* 商品コード列は折り返し禁止 */
.invoice-items-table.invoice-layout-code td:first-child {
    white-space: nowrap;
    word-break: normal;
}

/* 右对齐（单価・数量・価格） */
.invoice-items-table.invoice-layout-default td:nth-child(2),
.invoice-items-table.invoice-layout-default td:nth-child(3),
.invoice-items-table.invoice-layout-default td:nth-child(4),
.invoice-items-table.invoice-layout-default th:nth-child(2),
.invoice-items-table.invoice-layout-default th:nth-child(3),
.invoice-items-table.invoice-layout-default th:nth-child(4) {
    text-align: end;
    font-variant-numeric: tabular-nums;
}

.invoice-items-table.invoice-layout-code td:nth-child(3),
.invoice-items-table.invoice-layout-code td:nth-child(4),
.invoice-items-table.invoice-layout-code td:nth-child(5),
.invoice-items-table.invoice-layout-code th:nth-child(3),
.invoice-items-table.invoice-layout-code th:nth-child(4),
.invoice-items-table.invoice-layout-code th:nth-child(5) {
    text-align: end;
    font-variant-numeric: tabular-nums;
}

/* 银行信息和备注区域加包装，以便控制 */
/* 備考・振込先は途中で改ページされると読みにくいため、ブロックごと次ページへ送る。
   納品書・見積書の備考も請求書と同じ挙動に揃える。 */
#bankSection,
#remarkSection,
#deliveryRemarkSection,
#estimateRemarkSection {
    display: block;
    break-inside: avoid;
    page-break-inside: avoid;
}

#i_bank,
#i_remark,
#d_remark,
#e_remark {
    display: block;
    background: #f8fafc;
    padding: 12px 16px;
    border: 1px dashed #94a3b8;
    margin: 10px 0 20px;
    border-radius: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* 備考が未入力の場合でも枠が細くなりすぎないよう最小高さを確保する（全テンプレート共通）。
   テンプレート3側の個別 min-height（#i_bank と共有していた1.6em）はこの値を上書きしないよう分離済み。 */
#i_remark,
#d_remark,
#e_remark {
    min-height: 4.5em;
}

hr {
    margin: 24px 0;
    border: none;
    border-top: 2px solid #e2e8f0;
}

/* ==== 按钮样式 ===== */
button {
    background: #2563eb;
    color: white;
    border: none;
    padding: 10px 22px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin: 8px 10px 0 0;
    box-shadow: 0 2px 8px rgba(37,99,235,0.2);
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    display: inline-block;
}

button:hover {
    background: #1d4ed8;
    box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba(37,99,235,0.2);
}

button.secondary {
    background: #2563eb;
    color: #ffffff;
    box-shadow: none;
}

button.secondary:hover {
    background: #1d4ed8;
}

/* ===== 商品一括追加モーダル ===== */
.bulk-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.bulk-modal-backdrop.active {
    display: flex;
}

.bulk-modal {
    width: min(720px, 92vw);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    padding: 20px;
    /* 中身が増えても画面からはみ出さないようにする。
       これが無いと背が高いモーダルで閉じる✕がビューポート外に出て、
       閉じる手段が無くなってしまう。 */
    max-height: 90vh;
    overflow-y: auto;
}

/* 背の高いモーダル用：ヘッダーと操作ボタンを固定し、中身だけスクロールさせる。
   .bulk-modal に付けて使う。 */
.modal-fixed-head {
    display: flex;
    flex-direction: column;
    overflow: hidden;   /* スクロールは .modal-scroll 側が担当する */
}
.modal-fixed-head > .modal-head,
.modal-fixed-head > .bulk-modal-actions { flex: none; }
.modal-fixed-head > .modal-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    /* スクロール領域の端で影が切れて見えないよう、わずかに余白を取る */
    padding: 2px 2px 4px;
    margin: 0 -2px;
}

.bulk-modal h4 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #0f172a;
}

.bulk-modal p {
    margin: 0 0 10px;
    color: #475569;
    font-size: 13px;
}

.bulk-modal-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===== 模板相关样式 ===== */

/*
 * テンプレート1：ユーザ指定のコンパクト帳票。
 * 画面（.invoice.template-1）と印刷で同じルールを共有し、印刷は @media で位置だけ補う（WYSIWYG）。
 */
.invoice.template-1 {
    /* 画面プレビューの余白を実際の印刷時の余白（PRINT_LAYOUT_OVERRIDEの
       @page margin-top:14mm + .print-active padding:0 10mm 8mm 10mm）と一致させる。
       印刷時は !important のオーバーライドで上書きされるため、この値は印刷結果には
       影響しない（プレビュー表示専用）。請求書テンプレート1・納品書（同じ
       .template-1 クラスを使用）の両方に適用される。 */
    padding: 14mm 10mm 8mm 10mm;
    font-size: 11pt;
    color: #000;
}

.invoice.template-1 h1.title {
    font-weight: 500;
    font-size: 26px;
    margin-top: 0;
    margin-bottom: 16px;
    letter-spacing: normal;
    color: #000;
}


.invoice.template-1 .company-info {
    transform: translateX(20mm);
    /* 右端からの余白：transform の +20mm と相殺して、文字の折り返し境界が
       紙の右端から 33mm(=4.3cm-20mm+10mm) の位置に来る。2026-09-18 に
       4.3cm → 3.3cm へ変更し、23mm まで右へ寄せた（請求書テンプレート1のみ。
       納品書・見積書は #deliveryPreview/#estimatePreview 側で 2cm に上書きしている）。
       この余白は印影(幅1.7cm・右端が紙の右端から10mm)の逃げ幅も兼ねており、
       3.3cm では文字が印影に約4mm重なる。重なりが気になる場合は印影を
       ドラッグで右へ逃がすか、STAMP_BASE_SHIFT['invoice.template1'].x を調整する。 */
    padding-right: 3.3cm;
    /* 会社名・住所が折り返しやすいため、表示幅を広げてテキスト領域を確保する
       （グローバルの max-width:55% を上書き。padding-right は印影の逃げ幅なのでそのまま）。
       70%を超えるとレイアウト上の制約（取引先情報側の最小幅など）で頭打ちになるため70%に設定。 */
    max-width: 70%;
    /* ロゴが無いときの既定位置：我方会社名を対方の住所（郵便番号）行と水平に揃える。
       対方会社名の上端から対方住所行の上端までの実測ギャップ（32px）をそのまま採用。
       ロゴがある場合はこの余白を無くし（.has-logo）、その分をロゴ自身に明け渡す。
       ここをJSで測って書き換える方式（旧実装）はロゴ画像の読込が非同期のため、
       アップロード直後は正しい高さが取れず、後で別の操作が再計算をトリガーした
       瞬間に対方情報側が動いて見える不具合の原因だった。今はCSSの固定値だけで
       完結させ、対方側（.header .box）には一切手を触れない＝常に固定にしてある。 */
    padding-top: 32px;
}
.invoice.template-1 .company-info.has-logo {
    padding-top: 0;
}

/* 登録番号ブロックと住所ブロックの間にある区切り用<br>を消し、
   住所→TELの間隔（余白なし）と同じ詰まり方に揃える。
   テンプレート3は独自の行間調整（.company-details ~ .company-details）を持つため対象外。 */
.invoice.template-1 .company-details + br,
.invoice.template-2 .company-details + br {
    display: none;
}

.invoice.template-1 .stamp {
    width: 1.7cm;
    height: 1.7cm;
    border: none;
    box-shadow: none;
    background: none;
    border-radius: 0;
    /* 左右位置（旧-20mm基準＋ユーザー調整分）はJS側のalignStampEl()が行内styleで一元設定する。 */
}

/* 納品書・見積書（テンプレート1のみ）は請求書と異なり、印影が我方会社情報に重なってもよい
   （実際の紙の帳票で判を会社名・住所の上に押す表現に近づける）。
   請求書の共通テンプレート1ルール（padding-right:4.3cm・印影のtranslateX(-20mm)）は、
   印影を右端ぎりぎりに逃がす前提の値のため、そのまま使うと右余白が大きく空きすぎる。
   ここでは逃げ幅を縮め、印影も右端寄りに保ちつつ会社情報へ軽く重ねる。 */
#deliveryPreview.template-1 .company-info,
#estimatePreview.template-1 .company-info {
    padding-right: 2cm;
}
#deliveryPreview.template-1 .stamp,
#estimatePreview.template-1 .stamp {
    width: 1.5cm;
    height: 1.5cm;
    opacity: 1;
    /* 左右位置（-18mm基準＋ユーザー調整分）はJS側のalignStampEl()が行内styleで一元的に設定する。
       ここではCSSでtransformを持たない（行内styleと二重管理にしない。快照保存時に行内styleが
       そのまま凍結されるため、ユーザーの方向キー調整もここに書いてしまうと反映されなくなる）。 */
}

.invoice.template-1 .client-name-line {
    font-size: 13pt;
    font-weight: normal;
}

.invoice.template-1 .client-name-line strong,
.invoice.template-1 .client-name-line .client-suffix {
    font-size: 13pt;
    font-weight: 500;
    color: #000;
}

.invoice.template-1 #i_myCompany,
.invoice.template-1 #d_myCompany {
    font-size: 13pt;
    font-weight: 500;
    color: #000;
}

.invoice.template-1 .amount-box {
    font-size: 18px;
    margin: 8px 0 10px;
    padding: 6px 16px;
    background: none;
    border-left: 4px solid #333;
    border-radius: 0;
    color: #000;
}

.invoice.template-1 hr {
    margin: 10px 0;
}

.invoice.template-1 .invoice-item {
    font-size: 9.5pt;
}

.invoice.template-1 .invoice-items-table tbody td {
    padding-top: 3px;
    padding-bottom: 3px;
}

.invoice.template-1 .invoice-item.invoice-line-header,
.invoice.template-1 .invoice-items-table thead th {
    padding: 5px 0;
    font-weight: 700;
}

.invoice.template-1 .invoice-items-table thead th {
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding-top: 5px;
    padding-bottom: 5px;
}

.invoice.template-1 #i_bank,
.invoice.template-1 #i_remark,
.invoice.template-1 #d_remark,
.invoice.template-1 #e_remark {
    padding: 6px 10px;
    margin: 6px 0 12px;
    font-size: 10pt;
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 0;
}

.invoice.template-1 .tax-breakdown-table,
.invoice.template-1 .summary-table {
    border: none;
}

.invoice.template-1 .tax-breakdown-title {
    color: #000;
}

.invoice.template-1 .tax-breakdown-table th,
.invoice.template-1 .tax-breakdown-table td,
.invoice.template-1 .summary-table th,
.invoice.template-1 .summary-table td {
    color: #000;
}

.invoice.template-1 #subTotal,
.invoice.template-1 #taxTotal,
.invoice.template-1 #grandTotal,
.invoice.template-1 #displayTotal {
    color: #000;
}

/* 模板2：我方会社名大 */
.invoice.template-2 #i_myCompany,
.invoice.template-2 #d_myCompany {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    color: #000;
}

.invoice.template-2 .client-name-line {
    font-size: 18px;
    font-weight: 700;
}

.invoice.template-2 #i_logo {
    width: 30mm !important;
    max-height: 20mm !important;
    height: auto !important;
    object-fit: contain;
}

.invoice.template-2 .company-details {
    line-height: 1.4;
}

.invoice.template-2 .client-name-line .client-suffix {
    font-size: inherit;
    font-weight: 900;   /* <strong>のbolderで実効900のため合わせる（.client-kameiと同じ理由） */
    color: inherit;
}

.invoice.template-2 {
    --invoice-reg-number-font-size: 14px;
    color: #000;
}
.invoice.template-2 .company-info {
    transform: translateX(25mm);
    /* テンプレート1と同じ理屈（詳細はテンプレート1側の.company-infoのコメント参照）。
       対方会社名から対方住所行までの実測ギャップは33px（テンプレート1の32pxとほぼ同じ。
       共有markupだが .client-name-line の font-weight がテンプレート2だけ700のため1px差）。 */
    padding-top: 33px;
}
.invoice.template-2 .company-info.has-logo {
    padding-top: 0;
}

.invoice.template-2 h1.title {
    font-size: 28px;
    margin-bottom: 10px;
    color: #000;
}

/* 請求書番号・発行日（#t2-meta-topright）が通常フローでタイトル直下に入り、
   その分ヘッダーは自然に押し下げられるため、ここでの追加マージンは不要。 */
.invoice.template-2 > .header {
    margin-top: 0;
}

/* ロゴを会社名の左側に表示する。position:absoluteで通常のフローから外すため、
   会社名・登録番号・住所など請求元情報側の位置・幅には一切影響しない。 */
/* ロゴは会社名の上（通常フロー）に表示する。請求元情報が下がる分は
   syncLogoOffset() が取引先情報側に padding-top を付けて上端を揃える。 */
.invoice.template-2 #i_logoBox {
    margin-bottom: -2px !important;
}

/* 請求書番号・発行日：タイトル「請求書」の直下・右寄せ（applyTemplate2DOMがJSで移動）。
   絶対配置にすると (1) right:0 がパディングボックス基準になりページ余白を無視して最端に貼り付く、
   (2) 印刷時は padding-top が 8mm→0 に変わって本文だけ上へずれるため固定topのこの欄と重なり、
   白背景の .company-info に発行日が塗り潰される、という2つの不具合が起きる。
   通常フローに置けば余白も自動で効き、本文との重なりも構造的に発生しない。 */
.invoice.template-2 #t2-meta-topright {
    text-align: right;
    font-size: 12px;
    line-height: 1.6;
    color: #000;
    /* タイトル「請求書」とほぼ同じ高さ（気持ち下）に引き上げる。通常フローのままなので
       印刷時に padding-top が変わっても本文と一緒にずれ、位置関係は崩れない。 */
    margin-top: -33px;
    margin-bottom: 0px;
}

/* お支払期限：ご請求金額ボックスの直下に移動（applyTemplate2DOMがJSで移動） */
.invoice.template-2 .t2-due-line {
    font-size: 13px;
    color: #000;
    margin: -6px 0 10px;
    /* ご請求金額（.amount-box）はborder-left 6px + padding-left 20pxで
       文字の開始位置が左端から26px内側にある。ここも同じ26pxを付けて起始位置を揃える。 */
    padding-left: 26px;
}

.invoice.template-2 .amount-box {
    font-size: 20px;
    margin: 8px 0 10px;
    color: #000;
}

/* 振込先：取引先情報の直下・ご請求金額の直上へ移動（applyTemplate2DOMがJSで移動）。
   通常の文書フローに乗せているため、取引先情報が長くても重なりは発生しない。 */
.invoice.template-2 #bankSection {
    margin-top: 4px;
}

.invoice.template-2 hr {
    margin: 10px 0;
}

.invoice.template-2 .summary-wrapper {
    margin-top: 8px;
}

.invoice.template-2 .invoice-item {
    font-size: 9.5pt;
}

.invoice.template-2 .invoice-items-table tbody td {
    padding-top: 3px;
    padding-bottom: 3px;
}

.invoice.template-2 .invoice-item.invoice-line-header,
.invoice.template-2 .invoice-items-table thead th {
    padding: 5px 0;
}

.invoice.template-2 .invoice-items-table thead th {
    padding-top: 5px;
    padding-bottom: 5px;
}

.invoice.template-1 .invoice-items-table tbody tr:nth-child(odd) td,
.invoice.template-2 .invoice-items-table tbody tr:nth-child(odd) td {
    background: #fbfcfd;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* グローバルな th,td{border:1px solid} が商品テーブルに縦線として出てしまうのを打ち消す（横線のみ残す） */
.invoice.template-1 .invoice-items-table th,
.invoice.template-1 .invoice-items-table td,
.invoice.template-2 .invoice-items-table th,
.invoice.template-2 .invoice-items-table td {
    border-left: none;
    border-right: none;
    border-top: none;
}

.invoice.template-2 .tax-breakdown-title {
    color: #000;
}

.invoice.template-2 .tax-breakdown-table th,
.invoice.template-2 .tax-breakdown-table td,
.invoice.template-2 .summary-table th,
.invoice.template-2 .summary-table td {
    padding: 4px;
    color: #000;
}

.invoice.template-2 #subTotal,
.invoice.template-2 #taxTotal,
.invoice.template-2 #grandTotal,
.invoice.template-2 #displayTotal {
    color: #000;
}

.invoice.template-2 .stamp {
    width: 1.5cm;
    height: 1.5cm;
    opacity: 1;
    /* 左右位置（旧-40mm・6px基準＋ユーザー調整分）はJS側のalignStampEl()が行内styleで一元設定する。 */
}

/* 承認欄（社長・部長・担当）：請求元情報の下に、印影と同じ大きさの正方形の枠を3つ表示する。
   表形式にはせず、ラベルは枠の上に直接表示するだけ（入力欄はなく表示のみ、applyTemplate2DOMがJSで生成）。 */
.invoice.template-2 .t2-approval-row {
    display: flex;
    margin-top: 8px;
}
.invoice.template-2 .t2-approval-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
}
/* 隣の枠と接する側は、線が2本重なって太く見えないよう1本分だけ重ねる */
.invoice.template-2 .t2-approval-cell + .t2-approval-cell .t2-approval-box {
    margin-left: -1px;
}
.invoice.template-2 .t2-approval-label {
    font-size: 10px;
    color: #333;
    margin-bottom: 2px;
}
.invoice.template-2 .t2-approval-box {
    width: 2.2cm;
    height: 2.2cm;
    border: 1px solid #333;
    box-sizing: border-box;
}

.invoice.template-2 #i_bank,
.invoice.template-2 #i_remark,
.invoice.template-2 #d_remark {
    border: 1px solid #cbd5e1;
    border-radius: 0;
    background: none;
}

/* ===== テンプレート2：納品書（三和商事株式会社の実際の納品書フォーマットに合わせる）専用の追加分。
   上のブロックは請求書と共有（#i_myCompany/#d_myCompanyのように元々両対応の指定も多い）が、
   ここから下は「元原稿の見た目」を再現するための納品書だけの構造なので、コンテナのグリッド化などは
   IDで #deliveryPreview に限定し、請求書・見積書のtemplate-2には一切影響しないようにする。 ===== */

/* 対方情報：取引先住所は原本に存在しないため非表示（御中の一行のみ）。 */
.invoice.template-2 #d_clientAddress {
    display: none;
}

/* 原本の見出し・枠に使われている塗り色（xlsxのfill定義 FF227EA8 を採用）。
   #deliveryPreview.template-2 スコープの中だけで使うカスタムプロパティ。 */
#deliveryPreview.template-2 {
    --t2-accent: #227ea8;
}

/* コンテナ全体を2カラムグリッド化し、原本の「左＝取引先・合計金額／右＝自社情報・番号・内訳」という
   配置をそのまま再現する。.header/.box はdisplay:contentsで中身をグリッドへ昇格させ、
   要素を複製せず実在のノードをそのままグリッドセルに配置する（DOM移動はJS側で既存のものを流用）。 */
#deliveryPreview.template-2 {
    display: grid;
    grid-template-columns: 57% 1fr;
    column-gap: 14px;
    grid-template-areas:
        "title   title"
        "client  meta"
        "intro   company"
        "terms   company"
        "amount  company"
        "table   table"
        "remark  remark";
}
/* .header と .box はどちらも display:contents で中身をグリッドへ昇格させる。
   これで.client-name-line/#d_introLine/.company-infoが「実在のノードのまま」直接グリッドセルに
   置ける（複製せず、既存のDOM移動の仕組みとも両立する）。 */
#deliveryPreview.template-2 > .header,
#deliveryPreview.template-2 > .header > .box { display: contents; }
#deliveryPreview.template-2 hr { display: none; }

#deliveryPreview.template-2 > h1.title { grid-area: title; }
#deliveryPreview.template-2 .client-name-line { grid-area: client; }
#deliveryPreview.template-2 > #d_metaTopRight { grid-area: meta; }
#deliveryPreview.template-2 #d_introLine { grid-area: intro; }
#deliveryPreview.template-2 > .header > .company-info { grid-area: company; }
#deliveryPreview.template-2 > #d_termsBox { grid-area: terms; }
#deliveryPreview.template-2 > .amount-box { grid-area: amount; }
#deliveryPreview.template-2 > #deliveryPreviewTable { grid-area: table; }
#deliveryPreview.template-2 > #deliveryRemarkSection { grid-area: remark; }
/* テンプレート1用の税率別内訳・小計テーブルは使わない（合計はappendDeliveryTemplate2TotalsRows()が
   明細テーブル自身に行として追加するため、単価・数量・金額の列と自動で位置が揃う） */
#deliveryPreview.template-2 > .summary-wrapper { display: none; }

/* company-info：共有ルール（transform/max-width/padding-right）はテンプレート1の横並びヘッダー用に
   調整された値のため、グリッドセルに収まる納品書テンプレート2ではリセットする。 */
#deliveryPreview.template-2 .company-info {
    transform: none;
    max-width: 100%;
    padding-right: 0;
}

/* 「下記のとおり納品いたします。」固定文言。取引先名の直下に表示。 */
.invoice.template-2 #d_introLine {
    margin-top: 6px;
    font-size: 12px;
    color: #000;
}

/* 納品書番号・納品日：タイトル「納品書」の右側セルに（applyDeliveryTemplate2DOMがJSで移動）。
   グリッド配置なのでタイトルとの重なりは発生しない（請求書側の旧来のmargin-top:-33pxハックは不要）。 */
.invoice.template-2 #d_metaTopRight {
    text-align: right;
    font-size: 12px;
    line-height: 1.6;
    color: #000;
    align-self: end;
}

.invoice.template-2 #d_logoBox {
    margin-bottom: -2px !important;
}
/* 印影の位置調整は既存のalignStampEl()（stampOffsetX/Y）に任せる（他テンプレートと同じ仕組み）。
   ここでは特別な位置指定はしない。 */

.invoice.template-2 #d_logo {
    width: 30mm !important;
    max-height: 20mm !important;
    height: auto !important;
    object-fit: contain;
}

/* タイトル：中央寄せ・字間を空けた「納　品　書」のみ（原本に下線は無いので付けない）。 */
#deliveryPreview.template-2 > h1.title {
    text-align: center;
    font-size: 26px;
    letter-spacing: 0.5em;
    margin: 0 0 10px;
    color: #000;
}

/* 納期・支払条件：ラベルセルを塗り色にした2行の枠。原本の左カラムのボックスを再現する。 */
#deliveryPreview.template-2 .d-terms-row {
    display: flex;
    border: 1px solid #000;
    border-bottom: none;
}
#deliveryPreview.template-2 .d-terms-row:last-child {
    border-bottom: 1px solid #000;
}
#deliveryPreview.template-2 .d-terms-label {
    /* 合計金額（税込）ボックスのラベル幅（.amount-box-label）と揃える。幅が違うと2つの枠を
       縦に並べたときラベルと値の境界線がズレて見えるため、値は必ず同じ幅にすること。 */
    flex: 0 0 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--t2-accent);
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6px 10px;
    font-weight: 700;
    font-size: 13px;
    border-right: 1px solid #000;
}
#deliveryPreview.template-2 .d-terms-row > span:last-child {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-size: 13px;
    color: #000;
    text-align: center;
}

/* 合計金額（税込）：ラベルセル（塗り色・2行表示）＋値セル（白地・右寄せ）の2セル構成。
   共有の.amount-box（padding/border-radius/font-sizeなど）を明示的にリセットしてから組み立てる
   （備考ボックスと同じく、リセットし忘れで基底ルールが漏れて枠が崩れる不具合があったため）。 */
#deliveryPreview.template-2 > .amount-box {
    display: flex;
    align-items: stretch;
    box-sizing: border-box;
    border: 1px solid #000;
    border-radius: 0;
    margin: 6px 0 0;
    padding: 0;
    background: none;
    color: #000;
    font-size: 13px;
    font-weight: 400;
    align-self: start;
}
#deliveryPreview.template-2 .amount-box-label {
    flex: 0 0 120px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--t2-accent);
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 10px 8px;
    font-weight: 700;
    line-height: 1.4;
    border-right: 1px solid #000;
    /* 元のテキスト「合計金額：」は隠し、原本と同じ「合計金額／（税込）」の2行を生成して表示する
       （テンプレート1側のHTMLはそのまま共有し、ここは見た目だけをCSSで差し替える）。 */
    font-size: 0;
}
#deliveryPreview.template-2 .amount-box-label::before {
    content: "合計金額\A（税込）";
    white-space: pre-line;
    font-size: 13px;
}
#deliveryPreview.template-2 .amount-box #d_displayTotal {
    flex: 1;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px 14px;
    background: #fff;
    font-size: 18px;
    font-weight: 700;
}

/* 商品明細テーブル：共有ルールで消された縦線を復活させ、原本どおりの全罫線グリッドにする
   （#deliveryPreviewTableだけに限定、請求書側の.invoice-items-tableは変更しない）。
   見出しは塗り色・白文字、単価/数量/金額は右寄せ（col-price/col-qty/col-amountは
   task L で追加済みの共通の役割クラスをそのまま使う）。 */
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table th,
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td {
    border: 1px solid #333 !important;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table thead th {
    background: var(--t2-accent) !important;
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    text-align: center;
    font-weight: 700;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-price {
    text-align: center;
}
/* 数量・金額は下の合計欄（t2-totals-value、右寄せ）と縦の桁位置を揃えるため右寄せにする。 */
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-qty,
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-amount {
    text-align: right;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-orderno,
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-code,
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.col-name {
    text-align: left;
}

/* 合計数量・税率別対象金額・消費税額・合計金額（税込）：明細テーブル自身の追加行として、
   単価・数量・金額の列にぴったり位置を揃えて表示する（appendDeliveryTemplate2TotalsRows()が
   同じ<table>内にtrを追加するので、table-layout:fixedの列幅計算に自動で追従し列がズレない）。
   左側（注文No./商品コード/商品名ぶん）は罫線なしの空セルでスキップし、右下だけに枠を出す。 */
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.t2-totals-blank {
    border: none !important;
    background: none;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.t2-totals-label {
    background: var(--t2-accent) !important;
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-size: 13px;
    text-align: left;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table td.t2-totals-value {
    text-align: right;
    font-size: 13px;
    color: #000;
}
#deliveryPreview.template-2 #deliveryPreviewTable.invoice-items-table tr.t2-totals-grand td {
    font-weight: 700;
    font-size: 15px;
}

/* 備考：見出し行を塗り色の帯にし、その下に大きな罫線枠を再現する。 */
#deliveryPreview.template-2 > #deliveryRemarkSection {
    margin-top: 10px;
}
#deliveryPreview.template-2 #deliveryRemarkSection strong {
    display: block;
    box-sizing: border-box;
    background: var(--t2-accent);
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6px 10px;
    font-size: 13px;
    text-align: center;
    border: 1px solid #000;
    border-bottom: none;
}
/* strongを帯化したことで直後の改行は不要な余白になるため消す */
#deliveryPreview.template-2 #deliveryRemarkSection > br {
    display: none;
}
.invoice.template-2 #d_remark {
    display: block;
    box-sizing: border-box;
    min-height: 70px;
    border: 1px solid #000;
    border-top: none;
    padding: 8px;
    margin: 0;
    background: none;
    border-radius: 0;
}


/* ===== 納品書テンプレート3（三和商事株式会社／JAN・型番あり）=====
   クラス名が dl-template-3 なのは、請求書の .invoice.template-3（全く別デザインの請求書
   スタイル）と衝突させないため。ここの指定はすべて #deliveryPreview.dl-template-3 配下に
   限定してあり、請求書・見積書には一切影響しない。
   原本は「左＝取引先＋合計金額／右＝自社情報」の2カラム。テンプレート2と同じくグリッドで組む。 */
#deliveryPreview.dl-template-3 {
    --t3-rule: #000;
    color: #000;
    display: grid;
    grid-template-columns: 58% 1fr;
    column-gap: 16px;
    grid-template-areas:
        "title   title"
        "client  meta"
        "client  company"
        "intro   company"
        "amount  company"
        "table   table"
        "remark  remark";
}
/* .header と .box は display:contents で中身を直接グリッドセルへ昇格させる
   （要素を複製せず、実在のノードのまま配置する）。 */
#deliveryPreview.dl-template-3 > .header,
#deliveryPreview.dl-template-3 > .header > .box { display: contents; }
#deliveryPreview.dl-template-3 hr { display: none; }

#deliveryPreview.dl-template-3 > h1.title           { grid-area: title; }
#deliveryPreview.dl-template-3 .client-name-line     { grid-area: client; }
#deliveryPreview.dl-template-3 > #d_metaTopRight     { grid-area: meta; }
#deliveryPreview.dl-template-3 #d_introLine          { grid-area: intro; }
#deliveryPreview.dl-template-3 > .header > .company-info { grid-area: company; }
#deliveryPreview.dl-template-3 > .amount-box         { grid-area: amount; }
#deliveryPreview.dl-template-3 > #deliveryPreviewTable { grid-area: table; }
#deliveryPreview.dl-template-3 > #deliveryRemarkSection { grid-area: remark; }
/* テンプレート3は合計を明細テーブルの追加行として出すため、テンプレート1用の内訳表は使わない */
#deliveryPreview.dl-template-3 > .summary-wrapper    { display: none; }
#deliveryPreview.dl-template-3 > #d_termsBox         { display: none; }
/* 取引先住所は原本に無い（会社名＋御中の一行のみ） */
#deliveryPreview.dl-template-3 #d_clientAddress      { display: none; }

/* タイトル：中央寄せ・字間を空けた「納　品　書」 */
#deliveryPreview.dl-template-3 > h1.title {
    text-align: center;
    font-size: 24px;
    letter-spacing: 0.5em;
    margin: 0 0 14px;
    color: #000;
}

/* 発行日・納品番号（タイトル直下の右側） */
#deliveryPreview.dl-template-3 #d_metaTopRight {
    text-align: left;
    font-size: 12px;
    line-height: 1.9;
    color: #000;
    align-self: start;
}
#deliveryPreview.dl-template-3 #d_metaTopRight > div {
    display: flex;
    justify-content: flex-start;
    gap: 6px;
}
/* ラベル幅を揃える（「発行日：」「納品番号：」で文字数が違うため、幅を固定しないと
   2行の下線（#d_no/#d_date）の開始位置がずれてしまう）。 */
#deliveryPreview.dl-template-3 #d_noLabel,
#deliveryPreview.dl-template-3 #d_dateLabel {
    display: inline-block;
    width: 62px;
}
/* 値は下線を引いて記入欄らしく見せる（原本の体裁） */
#deliveryPreview.dl-template-3 #d_no,
#deliveryPreview.dl-template-3 #d_date {
    min-width: 34mm;
    text-align: left;
    border-bottom: 1px solid var(--t3-rule);
}

/* 取引先名：大きめ＋下線（原本どおり） */
#deliveryPreview.dl-template-3 .client-name-line {
    font-size: 20px;
    font-weight: 700;
    align-self: start;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--t3-rule);
}
#deliveryPreview.dl-template-3 .client-name-line strong,
#deliveryPreview.dl-template-3 .client-name-line .client-suffix {
    font-size: inherit;
    font-weight: 700;
    color: #000;
}

#deliveryPreview.dl-template-3 #d_introLine {
    margin-top: 10px;
    font-size: 13px;
    color: #000;
    align-self: start;
}

/* 自社情報：テンプレート1の横並びヘッダー用に調整された共有指定をリセットしてグリッドに収める */
#deliveryPreview.dl-template-3 .company-info {
    transform: none;
    max-width: 100%;
    padding-right: 0;
    font-size: 12px;
    line-height: 1.9;
    /* ロゴが無いと会社名が上の納品番号行に密着してしまう（実測で隙間 -2px）ため、
       ロゴぶんの余白の代わりに1行ぶんの間隔を空ける。ロゴがある場合はロゴ自身が
       その空間を占めるので0に戻す（テンプレート1・2と同じ has-logo 方式）。 */
    padding-top: 22px;
}
#deliveryPreview.dl-template-3 .company-info.has-logo {
    padding-top: 0;
}
#deliveryPreview.dl-template-3 #d_myCompany {
    font-size: 15px;
    font-weight: 700;
    color: #000;
}
/* 担当者の下に出す特記事項。備考と同じく枠なしのシンプルな1行（大きくしない）。 */
#deliveryPreview.dl-template-3 #d_tokkiJikoLine {
    margin-top: 2px;
    font-size: 11px;
    color: #000;
}
/* 登録番号行と住所行の間の空行（<br id="d_companyGapBr">）。line-height:1.9のテンプレート3では
   間延びして見えるため詰める（テンプレート1・2はこのidを使わないので影響しない）。 */
#deliveryPreview.dl-template-3 #d_companyGapBr {
    display: none;
}
#deliveryPreview.dl-template-3 #d_logo {
    width: 30mm !important;
    max-height: 18mm !important;
    height: auto !important;
    object-fit: contain;
}

/* 合計金額の欄：テンプレート3は金額を取引先へ出さない運用のため、ブロックごと非表示にする
   （明細の単価・金額列、小計・消費税・合計金額の値も同じ理由でJS側が空にしている）。 */
#deliveryPreview.dl-template-3 > .amount-box {
    display: none;
}

/* 明細テーブル：原本どおり全罫線のグリッド。見出しは細い罫線＋中央寄せ（塗りは無し）。 */
#deliveryPreview.dl-template-3 #deliveryPreviewTable.invoice-items-table th,
#deliveryPreview.dl-template-3 #deliveryPreviewTable.invoice-items-table td {
    border: 1px solid var(--t3-rule) !important;
    font-size: 11px;
    padding: 6px 5px;
}
#deliveryPreview.dl-template-3 #deliveryPreviewTable.invoice-items-table thead th {
    background: #fff !important;
    color: #000;
    font-weight: 700;
    text-align: center;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
/* 文字列の列は左寄せ、数量・金額は右寄せ（原本と同じ） */
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-orderno,
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-code,
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-name,
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-modelno { text-align: left; }
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-qty,
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-price,
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.col-amount { text-align: right; }

/* テンプレート3の明細列幅（dq3-cols）。テンプレート1/2の dq-cols とは別系統。
   商品名は幅未指定にして残り幅を自動で吸収させる。
   数量は「12,345本」が1行に収まる幅を確保し、増やした分は商品コード側から回す。 */
.invoice-items-table.dq3-cols th.col-orderno,
.invoice-items-table.dq3-cols td.col-orderno { width: 13%; }
.invoice-items-table.dq3-cols th.col-code,
.invoice-items-table.dq3-cols td.col-code    { width: 13%; }
.invoice-items-table.dq3-cols th.col-modelno,
.invoice-items-table.dq3-cols td.col-modelno { width: 15%; }
.invoice-items-table.dq3-cols th.col-qty,
.invoice-items-table.dq3-cols td.col-qty     { width: 12%; }
.invoice-items-table.dq3-cols th.col-price,
.invoice-items-table.dq3-cols td.col-price   { width: 14%; }
.invoice-items-table.dq3-cols th.col-amount,
.invoice-items-table.dq3-cols td.col-amount  { width: 15%; }

/* 小計・消費税・合計金額（appendDeliveryTemplate3TotalsRowsが明細テーブルへ追加する行）。
   左側は罫線なしの空セルで飛ばし、右下にだけ枠を出す。 */
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.t3-totals-blank {
    border: none !important;
    background: none;
}
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.t3-totals-label {
    text-align: center;
    font-weight: 700;
}
#deliveryPreview.dl-template-3 #deliveryPreviewTable td.t3-totals-value {
    text-align: right;
}
#deliveryPreview.dl-template-3 #deliveryPreviewTable tr.t3-totals-grand td {
    font-weight: 700;
    font-size: 13px;
}

/* 備考：見出し＋大きな枠（原本のB22〜B23）。見出しと本文の間に区切り線を入れる。 */
#deliveryPreview.dl-template-3 > #deliveryRemarkSection { margin-top: 14px; }
#deliveryPreview.dl-template-3 #deliveryRemarkSection strong {
    display: block;
    box-sizing: border-box;
    text-align: center;
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--t3-rule);
}
#deliveryPreview.dl-template-3 #deliveryRemarkSection > br { display: none; }
#deliveryPreview.dl-template-3 #d_remark {
    display: block;
    box-sizing: border-box;
    min-height: 130px;
    border: 1px solid var(--t3-rule);
    border-top: none;
    border-radius: 0;
    background: none;
    padding: 10px;
    margin: 0;
    font-size: 12px;
    line-height: 1.8;
}

/* ===== テンプレート3：専用スタイル ===== */
.invoice.template-3 {
    color: #000;
    --invoice-reg-number-font-size: 12px;
}

.invoice.template-3 h1.title {
    text-align: center;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 5px;
    margin-bottom: 20px;
    color: #000;
}

.invoice.template-3 > .header {
    gap: 18px;
    margin-bottom: 0;
    align-items: stretch;
}

.invoice.template-3 .box {
    /* 左カラム（取引先情報＋請求金額枠）の右端をコンテンツ幅のちょうど50%で止める
       （タイトルの中央に合わせた値。2026-09-17にタイトルを「御請求書」→「請求書」に
       変更したが、50%という値はそのままで見た目は変わらない） */
    flex: 0 0 50%;
    max-width: 50%;
    display: flex;
    flex-direction: column;
}

.invoice.template-3 .client-name-line {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid #6b7280;
}

.invoice.template-3 .client-name-line strong,
.invoice.template-3 .client-name-line .client-suffix {
    font-size: 15px;
    font-weight: 700;
    color: #000;
}

.invoice.template-3 #i_clientAddress {
    font-size: 13px;
    line-height: 1.8;
    margin-top: 4px;
}

.invoice.template-3 .amount-box {
    /* 動的JS位置合わせ（印影表示と干渉するバグがあったため廃止）に代えて固定値を使用。
       テンプレート3の実際の固定会社情報（環球支付・3行住所）＋担当者行まで表示した場合の
       下端よりも少し低い位置になるよう実測して調整済み。 */
    margin-top: 98px;
    margin-bottom: 0;
    border: 1px solid #6b7280;
    border-left: 1px solid #6b7280;
    border-radius: 0;
    background: #fff;
    padding: 10px 16px;
    font-size: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #000;
}

/* テンプレート3: 請求金額枠の直下に表示するお支払期限行（JSで生成） */
.invoice.template-3 .t3-due-line {
    margin-top: 6px;
    font-size: 13px;
    color: #000;
    display: flex;
    gap: 28px;
    padding-left: 16px;
    align-items: baseline;
}
.invoice.template-3 .t3-due-line .t3-due-label {
    color: #333;
    white-space: nowrap;
}
.invoice.template-3 .amount-box::before {
    content: "請求金額";
    font-size: 14px;
    font-weight: 500;
    color: #000;
}
.invoice.template-3 .amount-box #i_displayTotal {
    font-size: 17px;
    font-weight: 700;
    color: #000;
}
.invoice.template-3 .box > br {
    display: none;
}

.invoice.template-3 .company-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 0;
    margin-left: 0;
    max-width: 50%;
    transform: none;
    /* 目標PDF準拠：右カラム（メタ＋会社情報）全体を右上へ引き上げ、
       「請求書番号」の行がタイトルの下半分と水平に並ぶようにする */
    margin-top: -48px;
    margin-right: -25mm;
}

.invoice.template-3 #i_logoBox,
.invoice.template-3 .hp-logo-box {
    margin-bottom: -17px !important;
}

.invoice.template-3 #i_metaBox {
    order: -1;
    display: table;
    border-collapse: collapse;
    width: 100%;
}

.invoice.template-3 #i_metaBox br { display: none; }
.invoice.template-3 .company-info > br { display: none; }
.invoice.template-3 #i_tantouLine {
    font-size: 13px;
    line-height: 1.8;
    margin-top: -8px;   
}

/* 我方会社名：五号（10.5pt）・Meiryo
   （#i_myCompanyは編集プレビュー、.company-details strongは履歴フォールバック描画用） */
.invoice.template-3 #i_myCompany,
.invoice.template-3 #d_myCompany,
.invoice.template-3 .company-info .company-details strong {
    font-family: "Meiryo", "メイリオ", sans-serif;
    font-size: 10.5pt;
    font-weight: 700;
    color: #000;
}

/* 我方会社情報（住所・TEL・登録番号・担当者を含む）：小五（9pt）・Meiryo */
.invoice.template-3 .company-info .company-details,
.invoice.template-3 .company-info .company-reg-number,
.invoice.template-3 #i_tantouLine {
    font-family: "Meiryo", "メイリオ", sans-serif;
    font-size: 9pt;
    line-height: 1.8;
}

/* 登録番号→住所の行間を他の行（住所→担当者＝gap10px−8px）と同じ詰め幅に揃える。
   間に非表示の<br>が挟まるため隣接（+）ではなく間接（~）セレクタを使う */
.invoice.template-3 .company-info .company-details ~ .company-details {
    margin-top: -8px;
}

.invoice.template-3 hr {
    margin: 4px 0 14px;
    border-top: 1px solid #6b7280;
}

.invoice.template-3 .invoice-items-table thead th {
    background: #f1f5f9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding-top: 9px;
    padding-bottom: 9px;
    border-bottom: 1px solid #6b7280;
}

.invoice.template-3 .invoice-item {
    font-size: 11pt;
}

.invoice.template-3 .invoice-items-table tbody td {
    padding-top: 6px;
    padding-bottom: 6px;
}

/* 商品行の色分け（グレーの縞模様） */
.invoice.template-3 .invoice-items-table tbody tr:nth-child(odd) td {
    background: #f1f5f9;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.invoice.template-3 .invoice-items-table tbody tr:nth-child(even) td {
    background: #fff;
}

.invoice.template-3 .summary-wrapper {
    margin-top: 8px;
}

.invoice.template-3 .tax-breakdown-title { color: #000; }

/* テンプレート3: 税率別内訳・小計/消費税/合計欄の実線を振込先枠と同じ太さ・色で揃える */
.invoice.template-3 .tax-breakdown-table th {
    border-bottom: 1px solid #6b7280;
}
.invoice.template-3 .tax-breakdown-table td {
    border-bottom: 1px solid #6b7280;
}
.invoice.template-3 .tax-breakdown-table tbody tr:last-child td {
    border-bottom: 1px solid #6b7280;
}
.invoice.template-3 .summary-table th {
    border-bottom: 1px solid #6b7280;
}
.invoice.template-3 .summary-table td {
    border-bottom: 1px solid #6b7280;
}
.invoice.template-3 .summary-table tr:last-child td {
    border-bottom: 1px solid #6b7280;
}

.invoice.template-3 .tax-breakdown-table th,
.invoice.template-3 .tax-breakdown-table td,
.invoice.template-3 .summary-table th,
.invoice.template-3 .summary-table td {
    color: #000;
    padding: 6px 8px;
    font-size: 13px;
}

.invoice.template-3 #subTotal,
.invoice.template-3 #taxTotal,
.invoice.template-3 #grandTotal,
.invoice.template-3 #displayTotal { color: #000; }

.invoice.template-3 .stamp {
    width: 1.5cm;
    height: 1.5cm;
    right: 39mm;
    opacity: 1;
}

.invoice.template-3 #i_bank,
.invoice.template-3 #i_remark,
.invoice.template-3 #d_remark {
    border: 1px solid #6b7280;
    border-radius: 0;
    background: none;
    padding: 6px 10px;
}
/* #i_remark は共通の min-height:4.5em（このファイル上部）を使うため、ここでは #i_bank のみ個別指定する */
.invoice.template-3 #i_bank {
    min-height: 1.6em;
}

/* テンプレート3: 請求書メタ情報（JSで生成・表形式）。
   目標PDFに合わせて枠線なしのlabel-value行にする */
.t3-meta-list {
    width: calc(100% - 4mm);
    font-size: 13px;
    border-collapse: collapse;
    table-layout: fixed;
    border: none;
    /* company-info の gap:10px を一部打ち消し、次の要素（ロゴ or 会社名）との間隔を詰める */
    margin-bottom: -6px;
}
.t3-meta-list td {
    padding: 3px 0;
    border: none;
    vertical-align: baseline;
    text-align: left;
}
.t3-meta-label {
    width: 38%;
    color: #333;
    font-size: 13px;
    white-space: nowrap;
    background: none;
}
.t3-meta-value {
    color: #000;
    font-weight: 500;
    text-align: left;
    word-break: break-all;
}

/* ===== テンプレート4（シンプル・汎用デザイン）=====
   特定の取引先に固定されない汎用テンプレート。会社情報・登録番号・ロゴ等は
   ユーザーが入力したものをそのまま表示する（テンプレート1と同じ、自動入力なし）。
   参考PDF（請求書番号・発行日を右上に、明細は税区分込みの4列固定、合計欄の下に
   前金入金済額を控除して「今回ご請求額」を出す構成）に合わせたレイアウト。 */

.invoice.template-4 h1.title {
    font-size: 28px;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: 1px;
    margin-bottom: 14px;
}
.invoice.template-4 > .header {
    margin-bottom: 4px;
}
.invoice.template-4 #invoiceItems {
    margin: 12px 0;
}

/* 取引先側：宛名の下に住所も表示する（他テンプレートと同じ） */
.invoice.template-4 .client-name-line {
    font-size: 19px;
}

/* テンプレート4専用の一文（ご請求金額ボックスの直前） */
.invoice.template-4 .box {
    position: relative;
}
.invoice.template-4 #i_greeting {
    /* 担当者の行と高さを揃えるため、position:absoluteにしてJS側（createInvoice()）で
       #i_tantouLine の位置を測って top を毎回セットする（.box は右カラムより短いため、
       通常のフローに置くと高くなりすぎる）。 */
    position: absolute;
    left: 0;
    right: 0;
    font-size: 13px;
    color: #334155;
    margin: 0;
}

/* 会社情報側：請求書番号・発行日を右上に固定表示し、その下にロゴ→会社名・登録番号→
   住所・電話→担当者の順で並べる（左寄せ、他テンプレートと同じ）。#i_metaBox は絶対配置で
   切り離し、残りは通常のフロー（DOM順そのまま）で上から積む。印影は alignStampEl() が
   会社名の位置を基準に自動追従する。 */
.invoice.template-4 .company-info {
    position: relative;
    display: block;
    padding-top: 12mm;
    text-align: left;
    /* 右端は margin-left:auto でヘッダー右端に張り付いているため、
       右余白（元は印影用に確保していた2.8cm）を詰めるとブロック全体が右へ寄る。
       印影は alignStampEl() の transform で位置決めしており、この余白には依存しない。 */
    padding-right: 1.2cm;
}
/* 会社名・登録番号のブロックと住所・TELのブロックの間にある共通マークアップの<br>を消し、
   詰めて表示する（登録番号と住所の間の余分な空白を削除）。 */
.invoice.template-4 .company-info > br {
    display: none;
}
.invoice.template-4 #i_metaBox {
    position: absolute;
    /* 「請求書」タイトルの下端と揃える（タイトルの margin-bottom 14px 分だけ引き上げる）。 */
    top: -14px;
    right: 0;
    left: auto;
    text-align: right;
    font-size: 13px;
    color: #1e293b;
    line-height: 1.6;
}
/* 「御中」は他テンプレートと共有のクラスなので、色だけテンプレート4に限定して
   会社情報側（登録番号・TEL等）と同じ濃さに揃える（グローバルな.client-suffixは変更しない）。 */
.invoice.template-4 .client-suffix {
    color: #1e293b;
    font-size: 19px;
    font-weight: 900;   /* テンプレート4の会社名（<strong>、実効900）と字号・字重を揃える */
}
.invoice.template-4 #i_metaBox br {
    display: none;
}
/* お支払い期限は原稿PDFに項目が無いため出さない */
.invoice.template-4 #i_dueLine {
    display: none;
}
.invoice.template-4 #i_logoBox {
    text-align: left;
    /* #i_logoBox はHTML側に style="margin-bottom:3px" が直接書かれており、
       インラインstyleはクラスのCSSより優先されるため !important で上書きする。
       画像ファイル自体に含まれる余白の分もここで一緒に詰めている。 */
    margin: 0 0 -5px !important;
}
.invoice.template-4 #i_logoBox img {
    width: auto;
    max-width: 55%;
}
.invoice.template-4 .stamp {
    width: 1.7cm;
    height: 1.7cm;
}

/* ご請求金額ボックス：淡い塗り + 太枠なしのカード形。ラベルは小さく、金額は大きく強調。 */
.invoice.template-4 .amount-box {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    background: #eef2f6;
    border: 1.5px solid #1e3a8a;
    border-radius: 4px;
    padding: 9px 22px;
    margin: 4px 0 14px;
}
.invoice.template-4 #i_amountLabel {
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
}
.invoice.template-4 #i_displayTotal {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    margin-left: 16px;
    font-variant-numeric: tabular-nums;
}
/* 合計欄の各行：既定の padding だと文字が下の罫線に詰まって見えるため、上下に少し余裕を持たせる。 */
.invoice.template-4 .summary-table td {
    padding: 4px 4px;
    line-height: 1.4;
}

/* 明細表（品名・内容／税区分／数量／金額（円）の固定4列。単価列は持たない）。
   ヘッダーは濃紺塗り＋白文字、行は縞模様（zebra）にして原稿PDFの見た目に合わせる。 */
   数量（3列目）は「12,345本」（5桁＋3桁区切り＋単位）が1行に収まる幅を確保し、
   増やした分は品名・内容（1列目）から回す。 */
.invoice-items-table.template4-cols th:nth-child(1),
.invoice-items-table.template4-cols td:nth-child(1) { width: 35%; text-align: left; }
.invoice-items-table.template4-cols th:nth-child(2),
.invoice-items-table.template4-cols td:nth-child(2) { width: 12%; text-align: center; }
.invoice-items-table.template4-cols th:nth-child(3),
.invoice-items-table.template4-cols td:nth-child(3) { width: 13%; text-align: center; }
.invoice-items-table.template4-cols th:nth-child(4),
.invoice-items-table.template4-cols td:nth-child(4) {
    width: 20%;
    text-align: end;
    font-variant-numeric: tabular-nums;
}
.invoice-items-table.template4-cols th:nth-child(5),
.invoice-items-table.template4-cols td:nth-child(5) {
    width: 20%;
    text-align: end;
    font-variant-numeric: tabular-nums;
}
.invoice-items-table.template4-cols thead th {
    background: #1e293b;
    color: #fff;
    border: none;
    font-weight: 600;
    font-size: 13px;
}
/* border-collapse の縦線（列と列の境目）が環境によって見えてしまうことがあるため、
   明細セルの左右・上の枠を明示的に消しておく（下線だけ .invoice-items-table tbody td の
   border-bottom を引き継ぐ）。 */
.invoice-items-table.template4-cols tbody td {
    border-left: none;
    border-right: none;
    border-top: none;
}
.invoice-items-table.template4-cols tbody tr:nth-child(even) {
    background: #f8fafc;
}

/* 合計欄：左の税率別内訳表は使わず、右側1本の縦積みに一本化する
   （小計行は非表示・税率別内訳と前金控除は createInvoice() が動的に挿入し、
   最終行を「今回ご請求額」として強調表示する）。原稿PDFと同じくページ右側へ寄せる。 */
.invoice.template-4 .tax-breakdown-container {
    display: none;
}
.invoice.template-4 .right-summary-container {
    width: 58%;
    min-width: 260px;
    margin-left: auto;
    /* 右端は明細テーブルの右端（金額列）にきっちり揃える（食い込ませると列がずれるため）。 */
}
.invoice.template-4 .summary-table tr:last-child td {
    border-top: 1px solid #94a3b8;
    padding-top: 12px;
}

/* 振込先・備考：原稿PDFに合わせて左右2カラムにする。
   備考側は見出し（「備考」の文字・枠）を出さず、本文だけを右カラムに流し込む。 */
/* セクション間の余白を詰めて全体をコンパクトにする（既定の24pxだと間延びして見えるため）。 */
.invoice.template-4 hr {
    margin: 12px 0;
}
/* ヘッダー（会社情報等）と「下記のとおり～」の間、および合計欄と振込先の間の区切り線は
   原稿PDFに無いので消す（余白は詰めるだけにする）。 */
.invoice.template-4 > .header + hr,
.invoice.template-4 .summary-wrapper + hr {
    display: none;
}
.invoice.template-4 .summary-wrapper {
    margin-top: 8px;
}
.invoice.template-4 #bankSection {
    display: inline-block;
    vertical-align: top;
    width: 38%;
    box-sizing: border-box;
    margin-right: 4%;
}
.invoice.template-4 #remarkSection {
    display: inline-block;
    vertical-align: top;
    width: 58%;
    box-sizing: border-box;
}
.invoice.template-4 #remarkSection br:first-child {
    display: none;
}
.invoice.template-4 #remarkSection strong {
    display: none;
}
.invoice.template-4 #i_remark {
    border: none;
    background: transparent;
    padding: 0;
    margin: 10px 0 20px;
    min-height: 0;
    font-size: 12px;
}

/* 振込先ボックス：破線ではなく実線にして「枠付きボックス」に近づける */
.invoice.template-4 #i_bank {
    border-style: solid;
    background: #f8fafc;
    /* 「今回ご請求額」ボックスと角の丸みを揃える（外形を一致させる） */
    border-radius: 4px;
}

/* ===== 印刷：隐藏 UI。主体继承画面上的类（template-1 の .invoice.template-1 在印刷时同样生效）===== */
@media print {
    body {
        background: white;
    }
    .sidebar {
        display: none;
    }
    .history-panel {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
        padding: 0;
        min-height: 0;
        overflow: visible;
        background: white;
    }
    /* カードや入力UI・ボタンをすべて非表示 */
    .card {
        display: none;
    }
    button {
        display: none;
    }
    #invoice-section > div:not(.invoice),
    #delivery-section > div:not(.invoice) {
        display: none;
    }
    /* 印刷対象でないプレビューを非表示 */
    .invoice:not(.print-active) {
        display: none;
    }
    /* 印刷対象プレビューのみ表示 */
    .invoice.print-active {
        position: static;
        width: 100%;
        padding: 0;
        overflow: visible;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .invoice.print-active .invoice-item {
        page-break-inside: avoid;
    }
    .invoice-items-table thead {
        display: table-header-group;
    }
    .page-break-before {
        display: block;
        height: 0;
        margin: 0;
    }

    /* ===== 履歴PDF印刷：全要素を visibility:hidden で完全隔離 → 請求書のみ visible に ===== */
    body.printing-history * {
        visibility: hidden !important;
    }
    body.printing-history #hp-invoice.print-active {
        visibility: visible !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        box-shadow: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body.printing-history #hp-invoice.print-active * {
        visibility: visible !important;
    }
}

#i_myCompany,
#d_myCompany {
    font-size: 18px;
    font-weight: 600;
}

#subTotal,
#taxTotal,
#grandTotal,
#displayTotal {
    font-weight: 700;
    color: #0f172a;
}

#toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    background: #2563eb;
    color: #fff;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 9999;
}

#toast.show {
    opacity: 1;
}

/* ===== 個別保存ボタン ===== */
/* 入力＋保存ボタンを縦に並べるグループ（振込先・備考） */
.field-group {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
/* 保存済み一覧のドロップダウンをテキストエリア直下に出すための位置合わせ用ラッパー。
   .form-row（行全体、保存ボタンまで含む）を基準にすると、ドロップダウンが保存ボタンの
   さらに下まで押し下げられてしまう。テキストエリアだけを囲んで基準にすることで、
   入力欄のすぐ下から出て（保存ボタンにかぶさって）表示されるようにする。 */
.field-input-wrap {
    position: relative;
}
.field-group textarea {
    display: block;   /* 既定はinline-block相当のため、.field-input-wrapの下に
                          ベースライン分の余白（数px）ができ、ドロップダウンの開始位置が
                          テキストエリアの下端とわずかにズレる。block化して余白を無くす。 */
    width: 100%;
    min-height: 120px;   /* 既定でやや高め。内容に応じてJSで自動拡張 */
    overflow: hidden;
    resize: none;
    /* 共通の「input,select,textarea { flex:1 }」がここにも効くと flex:1 1 0% となり、
       親(.field-group)が縦方向flexのため高さがflex側で決定され、
       autoGrowTextarea() が設定する height が無視されてしまう
       （overflow:hidden・resize:none と相まって、長文が一切見えなくなる）。
       flexから外して height 指定を有効にする。 */
    flex: none;
}
.field-actions {
    display: flex;
    justify-content: flex-end;
}

/* 振込先カード：外側ラベルを詰めて、入力グループを左に寄せ幅を広げる */
.bank-card .form-row > label {
    width: 56px;
}

/* 振込先の4項目（銀行名・支店名・口座番号・口座名義） */
.bank-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    padding-top: 22px;   /* ラベルより下げて「グループ内容」感を出す */
}
.bank-field-line {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}
.bank-field-line > span {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    text-align: right;
}
.bank-field-line > input {
    width: 100%;
}

button.field-save-btn {
    background: #217346;
    border-radius: 6px;
    width: 52px;
    height: 52px;
    min-width: 52px;
    padding: 0;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    align-self: flex-start;
    box-shadow: 0 2px 6px rgba(33,115,70,0.25);
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    text-align: center;
}
.bank-card button.field-save-btn svg {
    width: 30px;
    height: 30px;
}
button.field-save-btn:hover {
    background: #185c38;
    box-shadow: 0 3px 10px rgba(33,115,70,0.35);
}
button.item-save-icon-btn {
    width: 30px;
    height: 30px;
}
button.field-save-btn.item-save-icon-btn {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
button.item-save-icon-btn svg {
    width: 19px;
    height: 19px;
}

/* ===== 履歴モーダル ===== */
.reki-modal {
    width: min(480px, 92vw);
}
.reki-steps {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.reki-step {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: #e2e8f0;
    color: #94a3b8;
    transition: background 0.2s, color 0.2s;
}
.reki-step.active {
    background: #2563eb;
    color: #fff;
}
.reki-step.done {
    background: #10b981;
    color: #fff;
}
.reki-step-arrow {
    color: #cbd5e1;
    font-size: 18px;
    line-height: 1;
}
.reki-step-content {
    max-height: 280px;
    overflow-y: auto;
    margin-bottom: 8px;
}
.reki-item {
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 8px;
    transition: background 0.15s, border-color 0.15s;
}
.reki-item:hover {
    background: #eff6ff;
    border-color: #2563eb;
}
.reki-item-title {
    font-weight: 600;
    color: #0f172a;
    font-size: 14px;
}
.reki-item-detail {
    font-size: 12px;
    color: #64748b;
    margin-top: 3px;
}
.reki-empty {
    color: #94a3b8;
    font-size: 14px;
    padding: 24px;
    text-align: center;
}
button.reki-delete-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    padding: 2px 7px;
    border-radius: 4px;
    flex-shrink: 0;
    margin: 0;
    box-shadow: none;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
button.reki-delete-btn:hover {
    color: #ef4444;
    background: #fee2e2;
    box-shadow: none;
}

/* ===== 第二サイドバー（履歴） ===== */
.history-panel {
    position: fixed;
    left: 0;
    top: 56px;
    width: 190px;
    height: calc(100vh - 56px);
    background: #162233;
    border-left: 1px solid #1e2f42;
    border-right: 1px solid #1e2f42;
    display: none;
    flex-direction: column;
    z-index: 998;
    overflow: hidden;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    transition: transform 0.22s ease;
}
.history-panel.open {
    display: flex;
}
.history-panel-header {
    padding: 20px 14px 12px;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    border-bottom: 1px solid #1e2f42;
    flex-shrink: 0;
}
.history-panel-search {
    padding: 8px 10px;
    border-bottom: 1px solid #1e2f42;
    flex-shrink: 0;
}
.history-panel-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 9px;
    font-size: 12px;
    color: #e2e8f0;
    background: #0f1a29;
    border: 1px solid #29405c;
    border-radius: 5px;
    outline: none;
}
.history-panel-search input::placeholder { color: #475569; }
.history-panel-search input:focus { border-color: #10b981; }
.history-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}
.sidebar-hist-item {
    display: flex;
    align-items: flex-start;
    padding: 9px 10px 9px 14px;
    cursor: pointer;
    color: #94a3b8;
    border-left: 3px solid transparent;
    transition: background 0.13s, color 0.13s;
    gap: 7px;
}
.sidebar-hist-item:hover {
    background: #1e3050;
    color: #e2e8f0;
}
.sidebar-hist-item.active {
    background: #1a3a5c;
    color: #fff;
    border-left-color: #10b981;
}
.sidebar-hist-num {
    font-size: 10px;
    color: #334155;
    min-width: 14px;
    margin-top: 2px;
    flex-shrink: 0;
    text-align: right;
}
.sidebar-hist-item.active .sidebar-hist-num { color: #475569; }
.sidebar-hist-body { overflow: hidden; min-width: 0; flex: 1; }
.sidebar-hist-name {
    font-size: 12px;
    font-weight: 500;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
}
.sidebar-hist-sub {
    font-size: 10px;
    color: #475569;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-hist-item.active .sidebar-hist-sub { color: #64748b; }
.sidebar-hist-badge {
    flex-shrink: 0;
    margin-top: 1px;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    white-space: nowrap;
}
.sidebar-hist-badge.unpaid { background: #4c1d24; color: #fca5a5; }
.sidebar-hist-badge.paid { background: #14532d; color: #86efac; }
.sidebar-hist-payment-info {
    font-size: 9px;
    color: #64748b;
    margin-top: 2px;
    white-space: nowrap;
}
.sidebar-hist-empty {
    padding: 16px 14px;
    font-size: 11px;
    color: #334155;
    font-style: italic;
}

.main-content.history-panel-open,
.main-content.fk-history-panel-open,
.main-content.dl-history-panel-open,
.main-content.es-history-panel-open,
.main-content.rb-history-panel-open,
.main-content.si-history-panel-open {
    margin-left: 190px;   /* 履歴パネル（左端に表示）の幅ぶん */
}

#invoice-history-section,
#fk-history-section,
#dl-history-section,
#es-history-section,
#rb-history-section,
#si-history-section,
#recurring-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 40px;
}
.hp-action-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    padding: 14px 20px;
    margin-bottom: 16px;
    width: 210mm;
    max-width: 100%;
    box-sizing: border-box;
}
.hp-action-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.hp-action-info { min-width: 0; }
.hp-action-title { font-weight: 700; font-size: 15px; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp-action-meta {
    font-size: 11px;
    color: #64748b;
    margin-top: 3px;
    display: grid;
    grid-template-columns: max-content max-content max-content max-content;
    column-gap: 6px;
    row-gap: 2px;
}
.hp-meta-label { text-align: right; }
.hp-meta-value { text-align: left; }
.hp-payment-select {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 2px 3px 6px;
    width: 64px;
    flex: none;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
}
.hp-payment-select.unpaid { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.hp-payment-select.paid { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
#hp-empty {
    width: 210mm;
    max-width: 100%;
}
/* 影と縮小表示は「凍結スナップショットが無い古い記録」を #hp-invoice へ直接描画する
   フォールバック経路（class="invoice template-N"）専用。
   スナップショットがある通常の記録は class="hp-snapshot" のiframe表示になり、
   納品書・見積書の履歴（#dl-hist-preview / #es-hist-preview）と同じ等倍表示にする。
   ID だけで指定していた頃はiframe表示まで0.75倍になり、上のアクションバー（210mm）と
   プレビューの横幅が揃わなかった。 */
#hp-invoice.invoice {
    box-shadow: 0 6px 32px rgba(0,0,0,0.14);
}
/* 画面上のみ縮小表示（印刷には影響しない） */
@media screen {
    #hp-invoice.invoice {
        transform: scale(0.75);
        transform-origin: top center;
        margin-bottom: calc(210mm * 0.75 - 210mm);
    }
	    .page-break-before {
	        display: none;
	    }
}

.hp-snapshot {
    width: 210mm;
    background: #fff;
}
.hp-snapshot-iframe {
    width: 210mm;
    height: 297mm;     
    border: 0;
    display: block;
    background: #fff;
}

/* 明細行の削除ボタン。.delete-btn のままだと padding: 6px 14px / border-radius: 30px
   （CSS上この規則より後にある）が勝って横長のピル型になるため、30pxの正方形に上書きする。
   角丸は上の .icon-btn 側（8px）に任せる。
   月次請求書（#siRowTable）も同じ見た目に揃えるので、まとめてここで指定する。 */
.item-edit-table .delete-btn.trash-icon-only,
#siRowTable .delete-btn.trash-icon-only {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    height: 30px;
    padding: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

.item-edit-table .delete-btn.trash-icon-only .trash-icon-svg,
#siRowTable .delete-btn.trash-icon-only .trash-icon-svg {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

/* td自体にdisplay:flexを指定すると、そのセルがtable-cellとして扱われなくなり
   行の高さ同期（他の<td>と同じ65px高になる仕組み）が壊れてしまう。
   そのためtdは通常のtable-cellのままにし、中に敷いたこの内側コンテナだけをflexにする。 */
.item-edit-table td.col-ops {
    padding: 4px 2px;
}
.item-edit-table td.col-ops .col-ops-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
}

.item-edit-table td.col-ops .col-ops-inner > .item-save-icon-btn,
.item-edit-table td.col-ops .col-ops-inner > .trash-icon-only {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    height: 30px;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#furikomi-section div:has(> #fk_logoCanvas) {
    max-width: calc(100% - 152px);
    flex-wrap: nowrap;
    overflow: hidden;
}

#fk_logoCanvas {
    flex: 1 1 auto;
    min-width: 0;
    max-width: min(200px, calc(100% - 72px)) !important;
    height: auto;
}

#fk_logoDeleteBtn {
    flex: 0 0 auto;
    white-space: nowrap;
}


/* ===== 伝票建請求書（slipinvoice）専用 =====
   納品書を1枚1行に集約した月次請求書。実際の三和商事の請求書（PDF/Excel）に版式を合わせてある。
   他の単据タイプとはDOM構造を共有しないため、ここのルールは .si-doc 配下に閉じており、
   既存の帳票には一切影響しない。実物にならい、印字本体では金額に「円」を付けず桁区切りのみで表示する
   （js側のsiNum()参照）。 */
.si-doc {
    position: relative;
    background: #fff;
    width: 210mm;
    min-height: 297mm;
    box-sizing: border-box;
    padding: 10mm 12mm 14mm;
    margin: 0 auto;
    color: #000;
    font-size: 12px;
    line-height: 1.5;
}
.si-doc .si-title-band {
    background: #d9d9d9;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.3em;
    padding: 10px 0;
    margin-bottom: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
/* 請求日：灰色の見出し帯（.si-title-band）のすぐ下に右寄せで表示する（帯の外）。 */
.si-doc .si-issuedate { text-align: right; font-size: 12px; margin-bottom: 8px; }
.si-doc .si-head {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 14px;
}
.si-doc .si-head-left  { flex: 1 1 52%; min-width: 0; }
/* 我方会社名（.si-my-wrap）を取引先側の締め期間（.si-period）の行と揃えるため、
   会社名（16px＋margin-bottom2px）ぶんだけ上を空ける（宛名が空欄の一般的なケースを想定した近似値）。
   position:relativeはロゴ（.si-logo-inline、絶対配置）の基準にするため。 */
.si-doc .si-head-right { position: relative; flex: 0 0 40%; text-align: left; font-size: 11px; line-height: 1.7; padding-top: 26px; }
.si-doc .si-client {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
}
.si-doc .si-client-suffix { font-size: 16px; font-weight: 700; margin-left: 4px; }
.si-doc .si-atena  { font-size: 12px; margin-bottom: 4px; }
.si-doc .si-period { font-size: 12px; margin-bottom: 8px; }
.si-doc .si-client-addr    { font-size: 11px; color: #000; margin-bottom: 4px; }
.si-doc .si-client-tantou  { font-size: 11px; margin-bottom: 10px; }
.si-doc .si-amount-box {
    border: 1px solid #000;
    margin-top: 8px;
    width: 90%;
    /* 影は付けない。box-shadowは枠線の外側に描かれるものなので、必ず枠からはみ出して
       周囲の余白へにじむ（2026-09-04 指示により削除）。合計欄（.si-table tfoot）でも
       同じ理由で影を諦めた経緯があるので、そちらのコメントも参照のこと。
       強調を足したい場合は、はみ出しの起きない枠線の太さ（border-width）で行う。 */
    /* 中の見出し（.si-amount-label）の灰色背景は印刷時に既定で落とされるため、
       ここで継承させて印刷に残す。 */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.si-doc .si-amount-label {
    background: #d9d9d9;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    padding: 5px 0;
    border-bottom: 1px solid #000;
}
.si-doc .si-amount-value {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    padding: 8px 0;
    font-variant-numeric: tabular-nums;
}
.si-doc .si-my { position: relative; }
/* ロゴは自社情報ブロックの左側の余白に絶対配置する（.si-head-right基準）。
   .si-my-wrapは常に一定量だけ右へ寄せておき、ロゴの有無に関わらず自社情報の位置がぶれないようにする。 */
/* 26mm から1文字ぶん（1em＝この欄の文字サイズ11px）だけ左へ寄せている。
   こうしないと「東京都港区西新橋3丁目24番10号４階」が1文字ぶん幅が足りず、
   「階」だけ次の行に折り返してしまう（2026-09-04 指示により調整）。
   右端は動かないので、左へ寄せたぶんだけ文字を置ける幅が広がる。 */
.si-doc .si-my-wrap { margin-left: calc(26mm - 1em); }
.si-doc .si-logo-inline {
    position: absolute;
    left: 0;
    top: 26px;   /* .si-head-rightのpadding-topと合わせ、会社名の行に揃える */
    max-width: 22mm;
    max-height: 14mm;
    object-fit: contain;
}
.si-doc .si-my-company { position: relative; font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.si-doc .si-stamp {
    position: absolute;
    right: 2mm;
    top: -4mm;
    width: 16mm;
    height: 16mm;
    object-fit: contain;
}
.si-doc .si-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.si-doc .si-table th,
.si-doc .si-table td {
    border: 1px solid #000;
    padding: 5px 7px;
}
.si-doc .si-table thead th {
    background: #d9d9d9;
    font-weight: 700;
    text-align: center;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
/* 列幅：摘要（残り幅を自動で取る可変列、元は約308px）から
   半分を伝票No.へ、残り半分のさらに1/3を数量へ譲る（摘要は最終的に元の1/3＝約103pxになる）。 */
.si-doc .si-c-date   { width: 85px;  text-align: center; }
.si-doc .si-c-no     { width: 304px; text-align: left; }
.si-doc .si-c-desc   { text-align: left; }
.si-doc .si-c-qty    { width: 111px; text-align: right; font-variant-numeric: tabular-nums; }
.si-doc .si-c-amount { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
/* 返品・マイナス行は実物どおり赤字にする（対象外チェックとは無関係、金額の符号だけで判定） */
.si-doc .si-table tbody tr.si-row-negative td { color: #c00000; }

/* 合計欄（tfoot）：明細と同じ<table>の続きの行なので、数量・金額（税抜）の列幅を
   そのまま共有する＝上の明細と桁位置がぴったり揃う（実物のExcelと同じ構造）。
   左側（伝票日付・伝票No.・摘要）は罫線なしの空セルで飛ばし、ラベル＋値のところだけ枠を出す。 */
/* 合計欄のセル指定は行グループ（tfoot/tbody）ではなく行のクラス（.si-total-tr）で行う。
   影を付けない合計数量の行だけ別の行グループ（tbody.si-qty-total-body）へ移したため、
   tfoot に紐付けたままだと合計数量の行の枠線・ラベル背景が外れてしまう。 */
.si-doc .si-table tr.si-total-tr .si-t-blank {
    border: none;
    background: none;
}
/* 合計行のラベルの字面（太字・中央寄せ）。網掛けの有無は下の<tfoot>側の指定で決める。 */
.si-doc .si-table tr.si-total-tr .si-t-label,
.si-doc .si-table tr.si-total-tr .si-t-label-inline {
    font-weight: 700;
    text-align: center;
}
/* 合計欄（<tfoot>＝御取引額計～最終合計金額）は、ラベル側だけでなく金額側のセルも網掛けにして
   影を掛けるブロック全体をひとまとまりに見せる。合計数量の行はこの<tfoot>の外（別tbody）に
   あって網掛けしないので、ブロックの境目がはっきりする（2026-09-04 実機の見た目に合わせて調整）。

   網掛けの灰色は帳票全体で #d9d9d9 に統一している（見出し帯 .si-title-band、金額枠の見出し
   .si-amount-label、明細の見出し行 thead th と同じ色）。以前は #f2f2f2 と #eee が混在していて
   濃さが揃わず不揃いに見えていた（特に #eee は白に近く網掛けが無いように見えていた）。

   :not(.si-t-blank) は必須。左側の空セルまで塗ると、そこも影の外形に含まれてしまい
   合計欄の左側に余計な影が伸びる（2026-09-04 実機で確認）。 */
.si-doc .si-table tfoot tr.si-total-tr td:not(.si-t-blank) {
    background: #d9d9d9;
    /* 背景色は印刷時に既定で落とされるので明示する（<tfoot>のprint-color-adjustと同じ理由）。 */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.si-doc .si-table tr.si-f-grand td {
    font-weight: 700;
    font-size: 13px;
}
.si-doc .si-table tr.si-total-tr .si-negative { color: #c00000; }
/* 【合計欄に影は付けない】2026-09-04、一連の試行のすえ「影なし」に落ち着いた経緯を残す。
   影を付けると必ずブロックの外へにじみ出てしまい、要望（表からはみ出させない）と両立しない。

   試したものと、それぞれ駄目だった理由：
   1) td に box-shadow … border-collapse: collapse では枠線に潰されてほとんど見えない。
   2) td を position:relative にして ::after で影を重ねる … display:table-cell 上の
      position:relative が絶対配置の包含ブロックとして確実には機能せず、印刷時に
      とんでもない位置へ大きな灰色の影が出た。
   3) <tr> ごとに filter: drop-shadow() … 各行が下の行に影を落とし、金額欄の中に
      灰色の横縞が何本も入って濁って見えた。
   4) <tfoot> にまとめて filter: drop-shadow() … 6行が1枚の絵として扱われ外周だけに
      影が付くので見た目は良かったが、合計欄の右端・下端は表そのものの右端・下端と
      一致するため、影が必ず表の外へ8px はみ出す。
   5) 4) を clip-path: inset() で表の端に合わせて切る … 右下は収まるが、今度は
      上と左（表の内側の空白部分）へ影がはみ出しているのが目立つ。四辺すべて切ると
      影は全く見えなくなる＝影なしと同じ。
   6) <tfoot> に box-shadow: inset … <tfoot>の箱は空セルを含む表の全幅なので、
      内側の影が左端の空白部分に灰色の帯として出てしまい使えない
      （filter:drop-shadow が塗られたセルの外形だけを拾うのとは挙動が違う）。

   結論：この合計欄は「灰色の網掛け＋黒枠」だけで十分に目立つので影は使わない。
   強調を足したい場合は、はみ出しの起きない外枠の太線（border-width）で行うこと。 */
.si-doc .si-table tfoot {
    /* 背景色は印刷時に既定で落とされるため、ここで継承させて中のセルの網掛けを印刷に残す。 */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.si-doc .si-bank {
    margin-top: 14px;
    font-size: 11px;
}
.si-doc .si-remark {
    margin-top: 10px;
    font-size: 11px;
    border: 1px solid #333;
    padding: 8px 10px;
}
.si-doc .si-remark-title { font-weight: 700; margin-bottom: 4px; }

/* 実物の帳票にある「切り取り線」を模した装飾用の破線（本文の区切りとして下端に入れる） */
.si-doc .si-cutline {
    border-top: 1px dashed #999;
    margin-top: 18px;
}
.si-doc table.si-totals .si-negative { color: #c00000; }

/* ===== 請求書設定：テンプレートのサムネイル選択 =====
   上のセレクトと並存させる（どちらから選んでも同じ）。
   画像は images/tpl/ の静止画なので、帳票のレイアウトCSSを変えたら撮り直すこと
   （_tplshot/shot.html をヘッドレスブラウザで撮ると再生成できる）。 */
.tpl-picker-row { align-items: flex-start; }
.tpl-picker {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.tpl-card {
    /* 汎用buttonの見た目（青背景・影）を打ち消して、カードとして組み直す。
       幅は固定。親が広くても伸びないようにする（伸ばすと画像だけ巨大になる）。 */
    width: 150px;
    flex: none;
    margin: 0;
    padding: 6px;
    background: #fff;
    color: #0f172a;
    box-shadow: none;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.tpl-card:hover {
    background: #fff;
    border-color: #93c5fd;
    box-shadow: 0 2px 10px rgba(37,99,235,0.12);
}
.tpl-card img {
    width: 100%;
    aspect-ratio: 210 / 297;
    /* 画像はA4縦(794x1123)で撮ってあるので枠と同じ比率。containにしておけば、
       撮り直しで比率が変わっても切り取られず全体が見える（以前coverで左右が切れていた）。 */
    object-fit: contain;
    object-position: center;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    background: #fff;
    display: block;
}
.tpl-card-name {
    font-size: 11px;
    font-weight: 600;
    line-height: 1.35;
    color: #334155;
    word-break: break-all;
}
/* 選択中 */
.tpl-card.selected {
    border-color: #2563eb;
    background: #eff6ff;
}
.tpl-card.selected .tpl-card-name::after {
    content: '　✓';
    color: #2563eb;
}
