app/template/default/Product/detail.twig line 1

Open in your IDE?
  1. {#
  2. This file is part of EC-CUBE
  3. Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  4. http://www.ec-cube.co.jp/
  5. For the full copyright and license information, please view the LICENSE
  6. file that was distributed with this source code.
  7. #}
  8. {% extends 'default_frame.twig' %}
  9. {% set body_class = 'product_page' %}
  10. {% block stylesheet %}
  11.     <style>
  12.         .slick-slider {
  13.             margin-bottom: 10px;
  14.             margin-top: -20px;
  15.         }
  16.         .slick-dots {
  17.             position: absolute;
  18.             bottom: -45px;
  19.             display: block;
  20.             width: 100%;
  21.             padding: 0;
  22.             list-style: none;
  23.             text-align: center;
  24.         }
  25.         .slick-dots li {
  26.             position: relative;
  27.             display: inline-block;
  28.             width: 20px;
  29.             height: 20px;
  30.             margin: 0 5px;
  31.             padding: 0;
  32.             cursor: pointer;
  33.         }
  34.         .slick-dots li button {
  35.             font-size: 0;
  36.             line-height: 0;
  37.             display: block;
  38.             width: 20px;
  39.             height: 20px;
  40.             padding: 5px;
  41.             cursor: pointer;
  42.             color: transparent;
  43.             border: 0;
  44.             outline: none;
  45.             background: transparent;
  46.         }
  47.         .slick-dots li button:hover,
  48.         .slick-dots li button:focus {
  49.             outline: none;
  50.         }
  51.         .slick-dots li button:hover:before,
  52.         .slick-dots li button:focus:before {
  53.             opacity: 1;
  54.         }
  55.         .slick-dots li button:before {
  56.             content: " ";
  57.             line-height: 20px;
  58.             position: absolute;
  59.             top: 0;
  60.             left: 0;
  61.             width: 12px;
  62.             height: 12px;
  63.             text-align: center;
  64.             opacity: .25;
  65.             background-color: black;
  66.             border-radius: 50%;
  67.         }
  68.         .slick-dots li.slick-active button:before {
  69.             opacity: .75;
  70.             background-color: black;
  71.         }
  72.         .slick-dots li button.thumbnail img {
  73.             width: 0;
  74.             height: 0;
  75.         }
  76.     </style>
  77.     <link rel="stylesheet" href="/html/user_data/js/style.css">
  78.     <link rel="stylesheet" href="/html/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  79.     <style>
  80.         /* Show zoom cursor on product images to hint click-to-expand */
  81.         .item_visual .slide-item a { display: block; cursor: zoom-in; }
  82.     </style>
  83.     <style>
  84.         /* ============================================
  85.            商品詳細グリッド: 画像50% / 内容50%(均等)
  86.         ============================================ */
  87.         @media (min-width: 768px) {
  88.             body.product_page .ec-grid2 {
  89.                 display: flex;
  90.                 align-items: flex-start;
  91.             }
  92.             body.product_page .ec-grid2 .ec-grid2__cell {
  93.                 width: 50%;
  94.                 flex: 0 0 50%;
  95.                 min-width: 0;
  96.             }
  97.             body.product_page .ec-grid2 .ec-grid2__cell2 {
  98.                 width: 50%;
  99.                 flex: 0 0 50%;
  100.                 min-width: 0;
  101.             }
  102.         }
  103.         /* ============================================
  104.            商品説明欄内のHTMLが画面幅を突き抜けないように
  105.         ============================================ */
  106.         body.product_page .ec-productRole__description {
  107.             min-width: 0;
  108.             overflow-wrap: break-word;
  109.             word-break: break-word;
  110.         }
  111.         body.product_page .ec-productRole__description img,
  112.         body.product_page .ec-productRole__description table,
  113.         body.product_page .ec-productRole__description iframe,
  114.         body.product_page .ec-productRole__description video {
  115.             max-width: 100% !important;
  116.             height: auto;
  117.         }
  118.         body.product_page .ec-productRole__description table {
  119.             display: block;
  120.             overflow-x: auto;
  121.             -webkit-overflow-scrolling: touch;
  122.         }
  123.         /* ============================================
  124.            スマホ用 見積金額 下部固定バー
  125.         ============================================ */
  126.         #sp-mitsumori-bar {
  127.             display: none;
  128.         }
  129.         /* ============================================
  130.            スマホ用 お見積りの詳細 ボトムシート
  131.         ============================================ */
  132.         .sp-detail-sheet { display: none; }
  133.         .sp-detail-sheet.is-open {
  134.             display: block;
  135.             position: fixed;
  136.             top: 0; left: 0; right: 0; bottom: 0;
  137.             z-index: 2000;
  138.         }
  139.         .sp-detail-sheet__overlay {
  140.             position: absolute;
  141.             top: 0; left: 0; right: 0; bottom: 0;
  142.             background: rgba(0,0,0,0.45);
  143.         }
  144.         .sp-detail-sheet__panel {
  145.             position: absolute;
  146.             left: 0; right: 0; bottom: 0;
  147.             background: #fff;
  148.             border-radius: 14px 14px 0 0;
  149.             max-height: 82vh;
  150.             display: flex;
  151.             flex-direction: column;
  152.             box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  153.             padding-bottom: env(safe-area-inset-bottom);
  154.             animation: spSheetUp 0.22s ease-out;
  155.         }
  156.         @keyframes spSheetUp {
  157.             from { transform: translateY(100%); }
  158.             to   { transform: translateY(0); }
  159.         }
  160.         .sp-detail-sheet__header {
  161.             display: flex;
  162.             align-items: center;
  163.             justify-content: space-between;
  164.             padding: 14px 16px;
  165.             border-bottom: 1px solid #eee;
  166.             flex: 0 0 auto;
  167.         }
  168.         .sp-detail-sheet__title { font-size: 16px; font-weight: bold; color: #333; }
  169.         .sp-detail-sheet__close {
  170.             background: none;
  171.             border: none;
  172.             font-size: 26px;
  173.             line-height: 1;
  174.             color: #888;
  175.             cursor: pointer;
  176.             padding: 0 4px;
  177.         }
  178.         .sp-detail-sheet__body {
  179.             overflow-y: auto;
  180.             -webkit-overflow-scrolling: touch;
  181.             padding: 4px 0;
  182.             flex: 1 1 auto;
  183.         }
  184.         .sp-detail-sheet__body ul { list-style: none; margin: 0; padding: 0; }
  185.         .sp-detail-sheet__body li { border-bottom: 1px solid #f2f2f2; }
  186.         .sp-detail-sheet__body .nav-link {
  187.             display: flex;
  188.             align-items: center;
  189.             justify-content: space-between;
  190.             padding: 12px 16px;
  191.             color: #333;
  192.             font-size: 14px;
  193.         }
  194.         .sp-detail-sheet__body .nav-link .float-right {
  195.             float: none !important;
  196.             font-weight: bold;
  197.             white-space: nowrap;
  198.             margin-left: auto;
  199.         }
  200.         .sp-detail-sheet__footer {
  201.             display: flex;
  202.             gap: 8px;
  203.             padding: 12px 16px 16px;
  204.             border-top: 1px solid #eee;
  205.             flex: 0 0 auto;
  206.         }
  207.         .sp-detail-sheet__footer button {
  208.             flex: 1 1 auto;
  209.             padding: 12px;
  210.             border-radius: 8px;
  211.             font-size: 14px;
  212.             font-weight: bold;
  213.             cursor: pointer;
  214.         }
  215.         .sp-detail-sheet__invoice {
  216.             background: #fff;
  217.             border: 1px solid #17a2b8;
  218.             color: #17a2b8;
  219.         }
  220.         .sp-detail-sheet__cart {
  221.             background: #c00;
  222.             border: 1px solid #c00;
  223.             color: #fff;
  224.         }
  225.         /* ============================================
  226.            商品タイプ選択 共通スタイル
  227.         ============================================ */
  228.         /* セクションラベル */
  229.         .rp-section-label {
  230.             font-size: 14px;
  231.             font-weight: bold;
  232.             color: #333;
  233.             margin-bottom: 10px;
  234.         }
  235.         .rp-section-label span {
  236.             font-weight: normal;
  237.             color: #c00;
  238.         }
  239.         /* ---- 1. 画像付きカード ---- */
  240.         .rp-card-group {
  241.             display: flex;
  242.             flex-wrap: wrap;
  243.             gap: 8px;
  244.             margin-bottom: 4px;
  245.         }
  246.         .rp-card {
  247.             position: relative;
  248.             cursor: pointer;
  249.             touch-action: manipulation; /* drop iOS 300ms tap delay (#15) */
  250.             -webkit-tap-highlight-color: rgba(0,0,0,0);
  251.             /* iOS Safari: prevent the first tap from being consumed as a text
  252.                selection ("字だけ青くなる" = selection highlight) which forced a
  253.                2nd tap to actually switch the option (#15). */
  254.             -webkit-user-select: none; -moz-user-select: none; user-select: none;
  255.             -webkit-touch-callout: none;
  256.             width: 110px;
  257.             border: 2px solid #ddd;
  258.             border-radius: 10px;
  259.             overflow: hidden;
  260.             transition: border-color 0.2s, box-shadow 0.2s;
  261.             background: #fff;
  262.             text-decoration: none;
  263.             color: #333;
  264.             display: block;
  265.         }
  266.         /* Gate :hover behind real hover-capable pointers. On iOS Safari a
  267.            :hover rule that changes appearance makes the first tap apply the
  268.            hover state and suppresses the click, so the option chip needed a
  269.            second tap to fire its onclick (is-selected + price update). */
  270.         @media (hover: hover) and (pointer: fine) {
  271.             .rp-card:hover {
  272.                 border-color: #999;
  273.                 box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  274.             }
  275.         }
  276.         .rp-card.is-selected {
  277.             border-color: #1a6fcf;
  278.             box-shadow: 0 2px 10px rgba(26,111,207,0.25);
  279.         }
  280.         /* visually-hidden instead of display:none. A label wrapping a
  281.            display:none radio fires its tap unreliably on iOS Safari (first tap
  282.            often ignored -> "2回タッチ"). Keeping the input in the layout but
  283.            invisible makes the first tap register. */
  284.         .rp-card input[type="radio"] {
  285.             position: absolute; opacity: 0; width: 1px; height: 1px;
  286.             margin: 0; pointer-events: none;
  287.         }
  288.         .rp-card__image {
  289.             width: 100%;
  290.             aspect-ratio: 1 / 1;
  291.             object-fit: cover;
  292.             display: block;
  293.             background: #f5f5f5;
  294.         }
  295.         .rp-card__placeholder {
  296.             width: 100%;
  297.             aspect-ratio: 1 / 1;
  298.             background: #f0f0f0;
  299.             display: flex;
  300.             align-items: center;
  301.             justify-content: center;
  302.             color: #bbb;
  303.             font-size: 24px;
  304.         }
  305.         .rp-card__name {
  306.             display: block;
  307.             padding: 5px 5px;
  308.             font-size: 11px;
  309.             color: #333;
  310.             text-align: center;
  311.             line-height: 1.4;
  312.             word-break: break-all;
  313.         }
  314.         .rp-card.is-selected .rp-card__name { color: #1a6fcf; font-weight: bold; }
  315.         .rp-card.is-selected::after {
  316.             content: "✓";
  317.             position: absolute;
  318.             top: 3px; right: 6px;
  319.             color: #1a6fcf;
  320.             font-size: 13px;
  321.             font-weight: bold;
  322.         }
  323.         /* ---- 2. ボタン式ラジオ(画像なし・8個以内)---- */
  324.         .rp-btn-group {
  325.             display: flex;
  326.             flex-wrap: wrap;
  327.             gap: 8px;
  328.             margin-bottom: 4px;
  329.             max-width: 100%;
  330.             min-width: 0;
  331.         }
  332.         .rp-btn {
  333.             cursor: pointer;
  334.             touch-action: manipulation; /* drop iOS 300ms tap delay (#15) */
  335.             -webkit-tap-highlight-color: rgba(0,0,0,0);
  336.             /* iOS Safari: block first-tap text selection so 1 tap switches (#15) */
  337.             -webkit-user-select: none; -moz-user-select: none; user-select: none;
  338.             -webkit-touch-callout: none;
  339.             padding: 8px 14px;
  340.             border: 2px solid #ddd;
  341.             border-radius: 10px;
  342.             font-size: 13px;
  343.             color: #333;
  344.             background: #fff;
  345.             transition: border-color 0.2s, background 0.2s;
  346.             white-space: normal;
  347.             max-width: 100%;
  348.             overflow-wrap: anywhere;
  349.             text-decoration: none;
  350.         }
  351.         @media (hover: hover) and (pointer: fine) {
  352.             .rp-btn:hover { border-color: #999; }
  353.         }
  354.         .rp-btn.is-selected {
  355.             border-color: #1a6fcf;
  356.             color: #1a6fcf;
  357.             font-weight: bold;
  358.             background: #f0f6ff;
  359.         }
  360.         .rp-btn input[type="radio"] {
  361.             position: absolute; opacity: 0; width: 1px; height: 1px;
  362.             margin: 0; pointer-events: none;
  363.         }
  364.         /* iOS Safari "2回タッチ" fix for the type-selection link chips.
  365.            The global theme stylesheet ships an ungated `a:hover{color:#296292}`
  366.            (paired with `a{color:#337ab7;text-decoration:underline}`). Because
  367.            .rp-btn / .rp-card are real <a> links, iOS Safari applies that hover
  368.            colour on the FIRST tap — the chip text turns blue (#296292, the
  369.            reported "字だけ青くなる") — and treats the tap as a hover, swallowing
  370.            the navigation so a 2nd tap was needed. The local .rp-*:hover rules
  371.            are already gated behind (hover:hover), but this inherited global
  372.            rule was not. Pin the hover/active colour to the base/selected colour
  373.            so tapping produces no visual change and the first tap navigates
  374.            immediately. Higher specificity (0,2,0 / 0,3,0) overrides a:hover. */
  375.         .rp-btn:hover,
  376.         .rp-btn:active { color: #333; text-decoration: none; }
  377.         .rp-btn.is-selected:hover,
  378.         .rp-btn.is-selected:active { color: #1a6fcf; text-decoration: none; }
  379.         .rp-card:hover,
  380.         .rp-card:active { color: #333; text-decoration: none; }
  381.         .rp-card:hover .rp-card__name,
  382.         .rp-card:active .rp-card__name { color: #333; }
  383.         .rp-card.is-selected:hover .rp-card__name,
  384.         .rp-card.is-selected:active .rp-card__name { color: #1a6fcf; }
  385.         /* ---- 選択肢が多い場合: 縦3段に収めて横スクロール(顧客要望「3列くらいで横スクロール」)---- */
  386.         /* grid-auto-flow:column + 3行固定 → 選択肢が縦に最大3段、超過分は右へ伸び横スクロールで閲覧 */
  387.         .rp-btn-group.is-scroll,
  388.         .opt-btn-group.is-scroll {
  389.             display: grid;
  390.             grid-auto-flow: column;
  391.             grid-template-rows: repeat(3, auto);
  392.             grid-auto-columns: max-content;
  393.             justify-content: start;
  394.             align-items: start;
  395.             gap: 8px;
  396.             overflow-x: auto;
  397.             overflow-y: hidden;
  398.             -webkit-overflow-scrolling: touch;
  399.             scrollbar-width: thin;
  400.             /* 上下に余白を確保して、行の枠線が overflow クリップ/スクロールバーに
  401.                切り取られないようにする(「文字列が長いと下枠が消える」対策)。 */
  402.             padding: 2px 0 12px;
  403.         }
  404.         /* is-scroll(横スクロール)内では選択肢を折り返さず単一行に固定する。
  405.            折り返すと行高が不揃いになり overflow-y:hidden で下枠が切れるため、
  406.            長い選択肢は折り返さず横スクロールで見せる(本来の設計意図)。 */
  407.         .rp-btn-group.is-scroll .rp-btn,
  408.         .rp-btn-group.is-scroll .opt-btn,
  409.         .opt-btn-group.is-scroll .rp-btn,
  410.         .opt-btn-group.is-scroll .opt-btn {
  411.             white-space: nowrap;
  412.             word-break: normal;
  413.             overflow-wrap: normal;
  414.         }
  415.         .rp-btn-group.is-scroll::-webkit-scrollbar,
  416.         .opt-btn-group.is-scroll::-webkit-scrollbar {
  417.             height: 6px;
  418.         }
  419.         .rp-btn-group.is-scroll::-webkit-scrollbar-thumb,
  420.         .opt-btn-group.is-scroll::-webkit-scrollbar-thumb {
  421.             background: #c0c0c0;
  422.             border-radius: 3px;
  423.         }
  424.         /* ---- 3. プルダウン(画像なし・9個以上)---- */
  425.         .rp-select-wrap {
  426.             margin-bottom: 4px;
  427.         }
  428.         .rp-select {
  429.             width: 100%;
  430.             max-width: 420px;
  431.             padding: 8px 12px;
  432.             border: 2px solid #ddd;
  433.             border-radius: 10px;
  434.             font-size: 13px;
  435.             color: #333;
  436.             background: #fff;
  437.             appearance: none;
  438.             background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  439.             background-repeat: no-repeat;
  440.             background-position: right 12px center;
  441.             cursor: pointer;
  442.         }
  443.         .rp-select:focus {
  444.             outline: none;
  445.             border-color: #1a6fcf;
  446.         }
  447.         /* ---- オプション選択ボタン(枠線ラジオ)---- */
  448.         .opt-btn-group {
  449.             display: flex;
  450.             flex-wrap: wrap;
  451.             gap: 8px;
  452.             padding: 6px 0;
  453.             max-width: 100%;
  454.             min-width: 0;
  455.         }
  456.         .opt-btn {
  457.             cursor: pointer;
  458.             touch-action: manipulation; /* drop iOS 300ms tap delay (#15) */
  459.             -webkit-tap-highlight-color: rgba(0,0,0,0);
  460.             /* iOS Safari: block first-tap text selection so 1 tap switches (#15) */
  461.             -webkit-user-select: none; -moz-user-select: none; user-select: none;
  462.             -webkit-touch-callout: none;
  463.             padding: 7px 14px;
  464.             border: 2px solid #ddd;
  465.             border-radius: 10px;
  466.             font-size: 13px;
  467.             color: #333;
  468.             background: #fff;
  469.             transition: border-color 0.2s, background 0.2s;
  470.             white-space: normal;
  471.             max-width: 100%;
  472.             overflow-wrap: anywhere;
  473.             text-decoration: none;
  474.         }
  475.         @media (hover: hover) and (pointer: fine) {
  476.             .opt-btn:hover { border-color: #999; }
  477.         }
  478.         .opt-btn.is-selected {
  479.             border-color: #1a6fcf;
  480.             color: #1a6fcf;
  481.             font-weight: bold;
  482.             background: #f0f6ff;
  483.         }
  484.         .opt-btn input[type="radio"] {
  485.             position: absolute; opacity: 0; width: 1px; height: 1px;
  486.             margin: 0; pointer-events: none;
  487.         }
  488.         /* opt-btn with color swatch image. The label still works as a
  489.            radio target — clicking the image checks the input. The text
  490.            label stays under the image so users can still read the name. */
  491.         .opt-btn--with-image {
  492.             padding: 4px 6px 6px;
  493.             white-space: normal;
  494.             text-align: center;
  495.             display: inline-flex;
  496.             flex-direction: column;
  497.             align-items: center;
  498.             min-width: 96px;
  499.             max-width: 140px;
  500.         }
  501.         .opt-btn--with-image .opt-btn__img {
  502.             display: block;
  503.             width: 88px;
  504.             height: 66px;
  505.             object-fit: cover;
  506.             border-radius: 6px;
  507.             margin-bottom: 4px;
  508.             background: #f5f5f5;
  509.         }
  510.         .opt-btn--with-image .opt-btn__name {
  511.             display: block;
  512.             font-size: 11px;
  513.             line-height: 1.3;
  514.             color: inherit;
  515.         }
  516.         .opt-btn--with-image.is-selected .opt-btn__img {
  517.             outline: 2px solid #1a6fcf;
  518.             outline-offset: 1px;
  519.         }
  520.         /* sale_type=2 (内窓) 補助金対象ガラスの強調表示.
  521.            補助金が出る性能区分 (真空断熱 / Low-E複層 等) のガラス選択肢に
  522.            緑枠 + 「補助金対象」バッジを付け、選択前から判別できるようにする。 */
  523.         .opt-btn--subsidy {
  524.             border-color: #2e7d32;
  525.         }
  526.         .opt-btn--subsidy.is-selected {
  527.             border-color: #1a6fcf;
  528.         }
  529.         .opt-btn__subsidy-badge {
  530.             display: inline-block;
  531.             margin-left: 6px;
  532.             padding: 1px 6px;
  533.             border-radius: 6px;
  534.             background: #2e7d32;
  535.             color: #fff;
  536.             font-size: 11px;
  537.             font-weight: bold;
  538.             white-space: nowrap;
  539.         }
  540.         /* ============================================
  541.            施工エリア案内
  542.         ============================================ */
  543.         .ec-areaNotice {
  544.             margin: 16px 0;
  545.             padding: 16px 20px;
  546.             background: #f8f9fa;
  547.             border-left: 4px solid #1a6fcf;
  548.             border-radius: 0 8px 8px 0;
  549.         }
  550.         .ec-areaNotice__inner {
  551.             display: flex;
  552.             align-items: flex-start;
  553.             gap: 12px;
  554.         }
  555.         .ec-areaNotice__icon {
  556.             font-size: 22px;
  557.             line-height: 1;
  558.             flex-shrink: 0;
  559.             margin-top: 2px;
  560.         }
  561.         .ec-areaNotice__body {
  562.             flex: 1;
  563.         }
  564.         .ec-areaNotice__title {
  565.             font-size: 13px;
  566.             font-weight: bold;
  567.             color: #1a6fcf;
  568.             margin: 0 0 6px;
  569.         }
  570.         .ec-areaNotice__text {
  571.             font-size: 13px;
  572.             color: #444;
  573.             line-height: 1.7;
  574.             margin: 0;
  575.         }
  576.         .ec-areaNotice__text strong {
  577.             color: #222;
  578.         }
  579.         .ec-areaNotice__link {
  580.             display: inline-block;
  581.             margin-top: 8px;
  582.             font-size: 12px;
  583.             color: #1a6fcf;
  584.             text-decoration: underline;
  585.         }
  586.         .ec-areaNotice__link:hover {
  587.             color: #0d4fa0;
  588.         }
  589.         /* ============================================
  590.            SNSシェア + ブランド名 タイトル行
  591.         ============================================ */
  592.         .ec-productRole__titleRow {
  593.             display: flex;
  594.             align-items: center;
  595.             justify-content: space-between;
  596.             gap: 8px;
  597.             margin-bottom: 4px;
  598.         }
  599.         .ec-productRole__titleRow .ec-headingTitle {
  600.             margin: 0;
  601.             flex: 1;
  602.             font-size: 18px;
  603.         }
  604.         .ec-share-inline {
  605.             display: flex;
  606.             align-items: center;
  607.             gap: 8px;
  608.             flex-shrink: 0;
  609.         }
  610.         @media (max-width: 767px) {
  611.             /* maker_area の float を解除して独立表示 */
  612.             #maker_area {
  613.                 float: none !important;
  614.                 width: auto !important;
  615.                 height: auto !important;
  616.                 display: block;
  617.                 margin-bottom: 4px;
  618.             }
  619.             /* タイトル行: 商品名が全幅を占有しSNSは右寄せ下段 */
  620.             .ec-productRole__titleRow {
  621.                 flex-wrap: wrap;
  622.                 clear: both;
  623.             }
  624.             .ec-productRole__titleRow .ec-headingTitle {
  625.                 flex: 1 1 100%;
  626.                 font-size: 16px;
  627.             }
  628.             .ec-share-inline {
  629.                 flex: 0 0 auto;
  630.                 margin-left: auto;
  631.             }
  632.         }
  633.         .ec-share-inline a {
  634.             display: flex;
  635.             align-items: center;
  636.             justify-content: center;
  637.             width: 32px;
  638.             height: 32px;
  639.             border-radius: 50%;
  640.             font-size: 15px;
  641.             color: #fff;
  642.             text-decoration: none;
  643.             transition: opacity 0.2s;
  644.         }
  645.         .ec-share-inline a:hover { opacity: 0.8; }
  646.         .ec-share-inline .share-twitter  { background: #000; }
  647.         .ec-share-inline .share-facebook { background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888); }
  648.         .ec-share-inline .share-line     { background: #06c755; }
  649.         /* description_detail下のシェアブロックはPC/スマホ共通で非表示(タイトル行に移動) */
  650.         .ec-productRole__share { display: none; }
  651.         /* ============================================
  652.            PC用: 現在のお見積り額カード強調
  653.         ============================================ */
  654.         @media (min-width: 768px) {
  655.             .mitsumori-card-pc {
  656.                 border: 2px solid #1a6fcf !important;
  657.                 border-radius: 10px !important;
  658.                 box-shadow: 0 4px 16px rgba(26,111,207,0.18) !important;
  659.                 margin-top: 20px;
  660.                 overflow: hidden;
  661.                 background: linear-gradient(135deg, #1a6fcf, #0d4fa0) !important;
  662.             }
  663.             .mitsumori-card-pc .card-header {
  664.                 background: linear-gradient(135deg, #1a6fcf, #0d4fa0) !important;
  665.                 color: #fff !important;
  666.                 padding: 14px 16px !important;
  667.                 border-bottom: none !important;
  668.             }
  669.             .mitsumori-card-pc .card-title {
  670.                 color: #fff !important;
  671.                 font-size: 15px !important;
  672.                 font-weight: bold !important;
  673.                 margin: 0 !important;
  674.             }
  675.             .mitsumori-card-pc #mitsumori_message {
  676.                 font-size: 22px !important;
  677.                 font-weight: bold !important;
  678.                 color: #fff !important;
  679.             }
  680.             .mitsumori-card-pc .btn-tool {
  681.                 color: #fff !important;
  682.             }
  683.             /* 合計行を大きく強調 */
  684.             .mitsumori-card-pc .nav-item:first-child .nav-link {
  685.                 font-size: 16px !important;
  686.                 font-weight: bold !important;
  687.                 color: #c00 !important;
  688.                 background: #fff8f8 !important;
  689.                 padding: 12px 16px !important;
  690.             }
  691.             .mitsumori-card-pc .nav-item:first-child #mitsumori_goukei {
  692.                 font-size: 20px !important;
  693.                 font-weight: bold !important;
  694.                 color: #c00 !important;
  695.             }
  696.             /* card-body(明細リスト)を白背景に */
  697.             .mitsumori-card-pc .card-body {
  698.                 background: #fff !important;
  699.             }
  700.             .mitsumori-card-pc .card-footer {
  701.                 background: #f8faff !important;
  702.                 border-top: 1px solid #dce8fb !important;
  703.                 padding: 12px 16px !important;
  704.             }
  705.         }
  706.         @media (max-width: 767px) {
  707.             /* スマホでは現在のお見積り額カードの強調スタイルをすべてリセット */
  708.             .mitsumori-card-pc {
  709.                 border: none !important;
  710.                 border-radius: 0 !important;
  711.                 box-shadow: none !important;
  712.                 margin-top: 0 !important;
  713.                 overflow: visible !important;
  714.                 background: none !important;
  715.                 /* sticky-top(position:sticky / z-index:1020) を解除。
  716.                    そのままだと最下部で #sp-mitsumori-bar(z-index:1000) の上に
  717.                    重なり、合計バーと文字が被るため通常フローへ戻す。 */
  718.                 position: static !important;
  719.                 z-index: auto !important;
  720.             }
  721.             .mitsumori-card-pc .card-header {
  722.                 background: none !important;
  723.                 color: inherit !important;
  724.                 padding: inherit !important;
  725.                 border-bottom: inherit !important;
  726.             }
  727.             .mitsumori-card-pc .card-title { color: inherit !important; }
  728.             .mitsumori-card-pc #mitsumori_message { font-size: inherit !important; color: inherit !important; }
  729.             .mitsumori-card-pc .btn-tool { color: inherit !important; }
  730.             /* 折りたたみトグルボタン */
  731.             .btn-mitsumori-toggle {
  732.                 background: none !important;
  733.                 border: 1px solid #aaa !important;
  734.                 border-radius: 4px !important;
  735.                 padding: 2px 8px !important;
  736.                 font-size: 12px !important;
  737.                 color: #333 !important;
  738.                 line-height: 1.4 !important;
  739.             }
  740.             .btn-mitsumori-toggle .toggle-icon {
  741.                 display: inline-block;
  742.                 transition: transform 0.2s;
  743.             }
  744.             /* 展開状態: ▼→▲ */
  745.             .card:not(.collapsed-card) .btn-mitsumori-toggle .toggle-icon::before {
  746.                 content: "▲ 閉じる";
  747.             }
  748.             .card:not(.collapsed-card) .btn-mitsumori-toggle .toggle-icon {
  749.                 display: none;
  750.             }
  751.             .card:not(.collapsed-card) .btn-mitsumori-toggle::after {
  752.                 content: "▲ 閉じる";
  753.                 font-size: 12px;
  754.             }
  755.             .mitsumori-card-pc .nav-item:first-child .nav-link {
  756.                 font-size: inherit !important;
  757.                 color: inherit !important;
  758.                 background: none !important;
  759.                 padding: inherit !important;
  760.             }
  761.             .mitsumori-card-pc .nav-item:first-child #mitsumori_goukei {
  762.                 font-size: inherit !important;
  763.                 color: inherit !important;
  764.             }
  765.             .mitsumori-card-pc .card-footer {
  766.                 background: none !important;
  767.                 border-top: inherit !important;
  768.                 padding: inherit !important;
  769.             }
  770.             /* 横スクロール禁止 */
  771.             body, html {
  772.                 overflow-x: hidden;
  773.                 max-width: 100vw;
  774.             }
  775.             /* ボタンの折り返しを許可(nowrapが原因で横スクロール発生するため) */
  776.             .opt-btn,
  777.             .rp-btn {
  778.                 white-space: normal;
  779.                 word-break: break-all;
  780.             }
  781.             /* エリア案内: スマホでコンパクト */
  782.             .ec-areaNotice {
  783.                 margin: 8px 0;
  784.                 padding: 8px 10px;
  785.                 border-left-width: 3px;
  786.                 cursor: pointer;
  787.             }
  788.             .ec-areaNotice__inner {
  789.                 flex-direction: row;
  790.                 gap: 8px;
  791.                 align-items: flex-start;
  792.             }
  793.             .ec-areaNotice__icon { font-size: 15px; }
  794.             /* タイトル行: 展開トグル */
  795.             .ec-areaNotice__title {
  796.                 font-size: 11px;
  797.                 margin-bottom: 3px;
  798.                 display: flex;
  799.                 justify-content: space-between;
  800.                 align-items: center;
  801.             }
  802.             .ec-areaNotice__title::after {
  803.                 content: "▼";
  804.                 font-size: 9px;
  805.                 color: #888;
  806.                 margin-left: 6px;
  807.                 transition: transform 0.2s;
  808.             }
  809.             .ec-areaNotice.is-open .ec-areaNotice__title::after {
  810.                 transform: rotate(180deg);
  811.             }
  812.             /* 折りたたみ対象: 閉じた状態では非表示 */
  813.             .ec-areaNotice__detail {
  814.                 display: none;
  815.             }
  816.             .ec-areaNotice.is-open .ec-areaNotice__detail {
  817.                 display: block;
  818.             }
  819.             .ec-areaNotice__text { font-size: 11px; line-height: 1.5; }
  820.             .ec-areaNotice__text br { display: none; }
  821.             .ec-areaNotice__link { font-size: 11px; margin-top: 3px; }
  822.             .rp-card { width: calc(33.333% - 6px); min-width: 80px; }
  823.             
  824.             #sp-mitsumori-bar {
  825.                 display: flex;
  826.                 position: fixed;
  827.                 bottom: 0;
  828.                 left: 0;
  829.                 right: 0;
  830.                 z-index: 1000;
  831.                 background: #fff;
  832.                 border-top: 2px solid #e0e0e0;
  833.                 box-shadow: 0 -2px 8px rgba(0,0,0,0.12);
  834.                 align-items: center;
  835.                 padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) 10px;
  836.                 gap: 8px;
  837.             }
  838.             #sp-mitsumori-bar .sp-bar__label {
  839.                 font-size: 11px;
  840.                 color: #666;
  841.                 white-space: nowrap;
  842.             }
  843.             /* 価格ラッパ: 合計金額は最重要のため常に全桁表示する(縮小・省略しない)。
  844.                幅が足りない場合は下のボタン側を縮める(flex 配分でボタンが先に縮む)。 */
  845.             #sp-mitsumori-bar .sp-bar__pricewrap {
  846.                 flex: 0 0 auto;
  847.                 min-width: 0;
  848.             }
  849.             #sp-mitsumori-bar .sp-bar__price {
  850.                 font-size: 18px;
  851.                 font-weight: bold;
  852.                 color: #c00;
  853.                 white-space: nowrap;
  854.             }
  855.             #sp-mitsumori-bar .sp-bar__btn {
  856.                 font-size: 12px;
  857.                 padding: 8px 12px;
  858.                 background: #333;
  859.                 color: #fff;
  860.                 border: none;
  861.                 border-radius: 6px;
  862.                 white-space: nowrap;
  863.                 cursor: pointer;
  864.                 position: relative;
  865.                 display: inline-flex;
  866.                 align-items: center;
  867.                 gap: 6px;
  868.                 flex: 1 1 auto;
  869.                 min-width: 0;
  870.                 justify-content: center;
  871.             }
  872.             #sp-mitsumori-bar .sp-bar__btn i {
  873.                 font-size: 14px;
  874.                 flex: 0 0 auto;
  875.             }
  876.             /* お見積りの詳細(内訳)を開くボタン。価格・カートボタンを圧迫しないよう
  877.                最小幅のアイコン+短ラベルにし、幅不足時も縮まない固定幅で維持する。 */
  878.             #sp-mitsumori-bar .sp-bar__detail-btn {
  879.                 display: inline-flex;
  880.                 flex-direction: column;
  881.                 align-items: center;
  882.                 justify-content: center;
  883.                 gap: 2px;
  884.                 flex: 0 0 auto;
  885.                 padding: 4px 8px;
  886.                 background: #fff;
  887.                 color: #c00;
  888.                 border: 1px solid #c00;
  889.                 border-radius: 6px;
  890.                 font-size: 10px;
  891.                 font-weight: bold;
  892.                 line-height: 1.1;
  893.                 white-space: nowrap;
  894.                 cursor: pointer;
  895.             }
  896.             #sp-mitsumori-bar .sp-bar__detail-btn i { font-size: 15px; }
  897.             /* 幅が足りないときはボタンの文字を省略し、価格と数字を守る。 */
  898.             #sp-mitsumori-bar .sp-bar__btn-label {
  899.                 overflow: hidden;
  900.                 text-overflow: ellipsis;
  901.                 white-space: nowrap;
  902.             }
  903.             #sp-mitsumori-bar .sp-bar__cart-badge {
  904.                 position: absolute;
  905.                 top: -6px;
  906.                 right: -6px;
  907.                 background: #c00;
  908.                 color: #fff;
  909.                 border-radius: 50%;
  910.                 min-width: 16px;
  911.                 height: 16px;
  912.                 font-size: 10px;
  913.                 line-height: 16px;
  914.                 padding: 0 4px;
  915.                 font-weight: bold;
  916.             }
  917.             #sp-mitsumori-bar .sp-bar__home-btn {
  918.                 display: inline-flex;
  919.                 align-items: center;
  920.                 justify-content: center;
  921.                 width: 36px;
  922.                 height: 36px;
  923.                 flex: 0 0 auto;
  924.                 border: 1px solid #ccc;
  925.                 border-radius: 6px;
  926.                 background: #fff;
  927.                 color: #333;
  928.                 text-decoration: none;
  929.                 cursor: pointer;
  930.             }
  931.             #sp-mitsumori-bar .sp-bar__home-btn i {
  932.                 font-size: 16px;
  933.             }
  934.             #sp-mitsumori-bar .sp-bar__home-btn:hover {
  935.                 background: #f0f0f0;
  936.             }
  937.             /* 下部バーの高さ分ページ下部にpaddingを追加 (iOS safe-area 込み) */
  938.             body {
  939.                 padding-bottom: calc(80px + env(safe-area-inset-bottom));
  940.             }
  941.         }
  942.         /* ============================================
  943.            カート追加モーダル: 縦並び中央配置
  944.         ============================================ */
  945.         .add-cart-modal__wrap {
  946.             text-align: center;
  947.         }
  948.         .add-cart-modal__header {
  949.             font-size: 16px;
  950.             margin: 20px 0 24px;
  951.             text-align: center;
  952.         }
  953.         .add-cart-modal__actions {
  954.             display: flex;
  955.             flex-direction: column;
  956.             align-items: center;
  957.             gap: 16px;
  958.             padding: 0 20px 20px;
  959.         }
  960.         .add-cart-modal__primary {
  961.             display: inline-block;
  962.             width: 80%;
  963.             max-width: 320px;
  964.             padding: 14px 20px;
  965.             font-size: 15px;
  966.             font-weight: bold;
  967.             text-align: center;
  968.             background: #d9534f;
  969.             color: #fff !important;
  970.             border-radius: 6px;
  971.             text-decoration: none;
  972.             cursor: pointer;
  973.         }
  974.         .add-cart-modal__primary:hover {
  975.             background: #c9302c;
  976.             color: #fff !important;
  977.             text-decoration: none;
  978.         }
  979.         .add-cart-modal__secondary {
  980.             display: inline-block;
  981.             padding: 6px 14px;
  982.             font-size: 12px;
  983.             color: #666;
  984.             border: 1px solid #ccc;
  985.             border-radius: 4px;
  986.             background: #fff;
  987.             cursor: pointer;
  988.         }
  989.         .add-cart-modal__secondary:hover {
  990.             background: #f0f0f0;
  991.             color: #333;
  992.         }
  993.         @media (max-width: 767px) {
  994.             .add-cart-modal__actions {
  995.                 gap: 20px;
  996.             }
  997.         }
  998.     </style>
  999. {% endblock %}
  1000. {% block javascript %}
  1001.     <script>
  1002.         eccube.classCategories = {{ class_categories_as_json(Product)|raw }};
  1003.         // 規格2に選択肢を割り当てる。
  1004.         function fnSetClassCategories(form, classcat_id2_selected) {
  1005.             var $form = $(form);
  1006.             var product_id = $form.find('input[name=product_id]').val();
  1007.             var $sele1 = $form.find('select[name=classcategory_id1]');
  1008.             var $sele2 = $form.find('select[name=classcategory_id2]');
  1009.             eccube.setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
  1010.         }
  1011.         {% if form.classcategory_id2 is defined %}
  1012.         fnSetClassCategories(
  1013.             $('#form1'), {{ form.classcategory_id2.vars.value|json_encode|raw }}
  1014.         );
  1015.         {% elseif form.classcategory_id1 is defined %}
  1016.         eccube.checkStock($('#form1'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  1017.         {% endif %}
  1018.     </script>
  1019.     <script>
  1020.         $(function() {
  1021.             // bfcache無効化
  1022.             $(window).bind('pageshow', function(event) {
  1023.                 if (event.originalEvent.persisted) {
  1024.                     location.reload(true);
  1025.                 }
  1026.             });
  1027.             // Core Web Vital の Cumulative Layout Shift(CLS)対策のため
  1028.             // img タグに width, height が付与されている.
  1029.             // 630px 未満の画面サイズでは縦横比が壊れるための対策
  1030.             // see https://github.com/EC-CUBE/ec-cube/pull/5023
  1031.             $('.ec-grid2__cell').hide();
  1032.             var removeSize = function () {
  1033.                 $('.slide-item').height('');
  1034.                 $('.slide-item img')
  1035.                     .removeAttr('width')
  1036.                     .removeAttr('height')
  1037.                     .removeAttr('style');
  1038.             };
  1039.             var slickInitial = function(slick) {
  1040.                 $('.ec-grid2__cell').fadeIn(1500);
  1041.                 var baseHeight = $(slick.target).height();
  1042.                 var baseWidth = $(slick.target).width();
  1043.                 var rate = baseWidth / baseHeight;
  1044.                 if(baseHeight * rate < 400){
  1045.                     $('.slide-item').height(baseHeight * rate); // 余白を削除する
  1046.                 }else{
  1047.                     $('.slide-item').height(400); // 余白を削除する
  1048.                 }
  1049.                 // transform を使用することでCLSの影響を受けないようにする
  1050.                 $('.slide-item img')
  1051.                     .css(
  1052.                         {
  1053.                             'transform-origin': 'top left',
  1054.                             'transform': 'scaleY(' + rate + ')',
  1055.                             'transition': 'transform .1s'
  1056.                         }
  1057.                     );
  1058.                 // 正しいサイズに近くなったら属性を解除する
  1059.                 setTimeout(removeSize, 500);
  1060.             };
  1061.             $('.item_visual').on('init', slickInitial);
  1062.             // リサイズ時は CLS の影響を受けないため属性を解除する
  1063.             $(window).resize(removeSize);
  1064.             $('.item_visual').slick({
  1065.                 dots: false,
  1066.                 arrows: true,
  1067.                 responsive: [{
  1068.                     breakpoint: 768,
  1069.                     settings: {
  1070.                         dots: true,
  1071.                         arrows: false
  1072.                     }
  1073.                 }]
  1074.             });
  1075.             $('.slideThumb').on('click', function() {
  1076.                 var index = $(this).attr('data-index');
  1077.                 $('.item_visual').slick('slickGoTo', index, false);
  1078.             })
  1079.         });
  1080.     </script>
  1081.     <script>
  1082.         $(function() {
  1083.             $('.add-cart').on('click', function(event) {
  1084.                 {% if form.classcategory_id1 is defined %}
  1085.                 // 規格1フォームの必須チェック
  1086.                 if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  1087.                     $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  1088.                     return true;
  1089.                 } else {
  1090.                     $('#classcategory_id1')[0].setCustomValidity('');
  1091.                 }
  1092.                 {% endif %}
  1093.                 {% if form.classcategory_id2 is defined %}
  1094.                 // 規格2フォームの必須チェック
  1095.                 if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  1096.                     $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  1097.                     return true;
  1098.                 } else {
  1099.                     $('#classcategory_id2')[0].setCustomValidity('');
  1100.                 }
  1101.                 {% endif %}
  1102.                 // タイプ2: カート送信直前に set_count を quantity に同期
  1103.                 if($('#set_count').length){
  1104.                     var _sc = parseInt($('#set_count').val()) || 1;
  1105.                     $('#quantity').val(_sc);
  1106.                     $('input[name="quantity"]').val(_sc);
  1107.                 }
  1108.                 // 個数フォームのチェック
  1109.                 if ($('#quantity').val() < 1) {
  1110.                     $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  1111.                     return true;
  1112.                 } else {
  1113.                     $('#quantity')[0].setCustomValidity('');
  1114.                 }
  1115.                 event.preventDefault();
  1116.                 $form = $('#form1');
  1117.                 $.ajax({
  1118.                     url: $form.attr('action'),
  1119.                     type: $form.attr('method'),
  1120.                     data: $form.serialize(),
  1121.                     dataType: 'json',
  1122.                     beforeSend: function(xhr, settings) {
  1123.                         // Buttonを無効にする
  1124.                         $('.add-cart').prop('disabled', true);
  1125.                     }
  1126.                 }).done(function(data) {
  1127.                     // レスポンス内のメッセージをalertで表示
  1128.                     $.each(data.messages, function() {
  1129.                         $('#ec-modal-header').text(this);
  1130.                     });
  1131.                     $('.ec-modal').show()
  1132.                     // カートブロックを更新する
  1133.                     $.ajax({
  1134.                         url: "{{ url('block_cart') }}",
  1135.                         type: 'GET',
  1136.                         dataType: 'html'
  1137.                     }).done(function(html) {
  1138.                         $('.ec-headerRole__cart').html(html);
  1139.                     });
  1140.                 }).fail(function(data) {
  1141.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  1142.                 }).always(function(data) {
  1143.                     // Buttonを有効にする
  1144.                     $('.add-cart').prop('disabled', false);
  1145.                 });
  1146.             });
  1147.         });
  1148.         $('.ec-modal-wrap').on('click', function(e) {
  1149.             // モーダル内の処理は外側にバブリングさせない
  1150.             e.stopPropagation();
  1151.         });
  1152.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  1153.             $('.ec-modal').hide()
  1154.         });
  1155.         var pw = "{% if mitsumori_json %}{{ mitsumori_json.pw }}{% endif %}";
  1156.         var pd = "{% if mitsumori_json %}{{ mitsumori_json.pd }}{% endif %}";
  1157.         var ph = "{% if mitsumori_json %}{{ mitsumori_json.ph }}{% endif %}";
  1158.         var pm = "{% if mitsumori_json %}{{ mitsumori_json.pm }}{% endif %}";
  1159.         var pc = "{% if mitsumori_json %}{{ mitsumori_json.pc }}{% endif %}";
  1160.         // option1 / option2: カテゴリ別 option 軸 (um: タイプ=subtype, fe: ct_up 等)
  1161.         var option1 = "{% if mitsumori_json and mitsumori_json.option1 is defined %}{{ mitsumori_json.option1 }}{% endif %}";
  1162.         var option2 = "{% if mitsumori_json and mitsumori_json.option2 is defined %}{{ mitsumori_json.option2 }}{% endif %}";
  1163.         var op0 = "{% if mitsumori_json %}{{ mitsumori_json.op[0] }}{% endif %}";
  1164.         var op1 = "{% if mitsumori_json %}{{ mitsumori_json.op[1] }}{% endif %}";
  1165.         var op2 = "{% if mitsumori_json %}{{ mitsumori_json.op[2] }}{% endif %}";
  1166.         var op3 = "{% if mitsumori_json %}{{ mitsumori_json.op[3] }}{% endif %}";
  1167.         var op4 = "{% if mitsumori_json %}{{ mitsumori_json.op[4] }}{% endif %}";
  1168.         var op5 = "{% if mitsumori_json %}{{ mitsumori_json.op[5] }}{% endif %}";
  1169.         var op6 = "{% if mitsumori_json %}{{ mitsumori_json.op[6] }}{% endif %}";
  1170.         var op7 = "{% if mitsumori_json %}{{ mitsumori_json.op[7] }}{% endif %}";
  1171.         var op8 = "{% if mitsumori_json %}{{ mitsumori_json.op[8] }}{% endif %}";
  1172.         var op9 = "{% if mitsumori_json %}{{ mitsumori_json.op[9] }}{% endif %}";
  1173.         var op10 = "{% if mitsumori_json %}{{ mitsumori_json.op[10] }}{% endif %}";
  1174.         const formatter = new Intl.NumberFormat('ja-JP');
  1175.         // ============================================================
  1176.         //  free_area 1 エントリのスキーマ(11 キー固定)
  1177.         // ============================================================
  1178.         //   w           : 幅 (string, 例 "239.9cm" / tf は "1m")
  1179.         //   d           : 奥行
  1180.         //   h           : 高さ (tf はロール長 "10m")
  1181.         //   m           : 素材
  1182.         //   c           : カラー
  1183.         //   price       : 販売価格 (税抜、amount=1 ベース)
  1184.         //   unit_price  : 商品 per-unit 増分 (税抜、AMOUNT_CATEGORIES のみ)
  1185.         //   maker_price : メーカー価格 (税抜)
  1186.         //   ct          : 基本工事費 (税抜、amount=1 ベース)
  1187.         //   option1     : fe → ct_up / その他カテゴリ → category-specific
  1188.         //   option2     : um → ct_up / その他カテゴリ → category-specific
  1189.         //
  1190.         //  ct4 (設置場所) / ct5 (撤去) / ct6 (残土) は option_area 側で扱う.
  1191.         // ============================================================
  1192.         // 施工オプション定義(option_area)— 各エントリ {name, comment, on, off, price}
  1193.         var op_data = {{ op_json|default('[]')|raw }};
  1194.         // option_item_area:
  1195.         //   tg 用 — block 別オプション差額表
  1196.         //     { axis_labels: {F:'床材',front:'前面型',side1:'右側面型',side2:'左側面型'},
  1197.         //       blocks: { 'W_label|D_label': { F:[{idx,label,diff},...], front:[...], side1:[...], side2:[...] }, ... } }
  1198.         //   fe (sale_type=4) 用 — ブロックの種類×段数の差額表 (fe_block キー)
  1199.         //     { fe_block: { depends_on_name: '...', depends_on_value: '...',
  1200.         //                   title: '...', default_key: '...',
  1201.         //                   choices: [{key,label,price}, ...] } }
  1202.         // 該当しないカテゴリでは fe_block は null. axis_labels/blocks は空.
  1203.         var oi_data = {{ oi_json|default('{"axis_labels":{},"blocks":{},"fe_block":null}')|raw }};
  1204.         // 選択中の tg オプション差額 (axis -> selected choice_idx). ラジオ click で更新される.
  1205.         var oi_selected = { F: 1, front: 1, side1: 1, side2: 1 };
  1206.         // 選択中の fe ブロック種類×段数 (key 文字列). 既定は oi_data.fe_block.default_key.
  1207.         var fe_block_selected = (oi_data && oi_data.fe_block && oi_data.fe_block.default_key) || '';
  1208.         // sale_type ID(mtb_sale_type の id。本サイトでの意味は次の通り):
  1209.         //   1 通常 / 2 補助金窓 / 3 物置 / 4 フェンス / 5 デッキ / 6 芝生 / 9 商品のみ
  1210.         var SALE_TYPE_ID = {{ ProductClass.SaleType.id }};
  1211.         {# option1 / option2 ラベルをカテゴリ別に決定 (sh=31, rd=43, mo=15) — 以降の UI / JS 両方で使用 #}
  1212.         {% set option1_label = 'オプション1' %}
  1213.         {% set option2_label = 'オプション2' %}
  1214.         {% if Product.ProductCategories is not empty %}
  1215.             {% for pcat in Product.ProductCategories %}
  1216.                 {% if pcat.category_id == 31 %}{% set option1_label = 'サイズプリセット' %}{% set option2_label = '駆動方式' %}{% endif %}
  1217.                 {% if pcat.category_id == 43 %}{% set option1_label = 'ランマ' %}{% set option2_label = 'タイプ' %}{% endif %}
  1218.                 {% if pcat.category_id == 15 %}{% set option1_label = '棚タイプ' %}{% endif %}
  1219.                 {% if pcat.category_id == 17 %}{% set option1_label = '窓タイプ' %}{% endif %}
  1220.             {% endfor %}
  1221.         {% endif %}
  1222.         // 消費税率(pp.price/pp.ct/op_data.price は scraper が税抜で保存しているため、
  1223.         // calcGoukei 出口で 1+TAX_RATE を掛けて税込 mitsumori_goukei にする)
  1224.         var TAX_RATE = 0.10;
  1225.         function toIncTax(v) { return Math.round(v * (1 + TAX_RATE)); }
  1226.         /**
  1227.          * tg 用 block 別オプション差額の集計.
  1228.          *   現選択 (W, D) から block key を作り、oi_data.blocks[blockKey] を取得.
  1229.          *   各 axis (F/front/side1/side2) で oi_selected[axis] の choice の diff を合計.
  1230.          * 戻り値: { total: 差額合計(税抜), items: [{name, label, diff}, ...] }
  1231.          *   block が無い (tg 以外 / 該当 (W,D) が未取得) なら total=0.
  1232.          */
  1233.         function collectOptionItems(curW, curD) {
  1234.             var result = { total: 0, items: [] };
  1235.             if (!oi_data || !oi_data.blocks) return result;
  1236.             var blockKey = (curW || '') + '|' + (curD || '');
  1237.             var block = oi_data.blocks[blockKey];
  1238.             if (!block) return result;
  1239.             var axes = ['F', 'front', 'side1', 'side2'];
  1240.             for (var i = 0; i < axes.length; i++) {
  1241.                 var axis = axes[i];
  1242.                 var choices = block[axis];
  1243.                 if (!choices || !choices.length) continue;
  1244.                 var idx = oi_selected[axis] || 1;
  1245.                 var pick = null;
  1246.                 for (var j = 0; j < choices.length; j++) {
  1247.                     if (parseInt(choices[j].idx) === parseInt(idx)) { pick = choices[j]; break; }
  1248.                 }
  1249.                 if (!pick) pick = choices[0];
  1250.                 var diff = parseInt(pick.diff) || 0;
  1251.                 result.total += diff;
  1252.                 result.items.push({
  1253.                     name:  oi_data.axis_labels[axis] || axis,
  1254.                     label: pick.label,
  1255.                     diff:  diff,
  1256.                 });
  1257.             }
  1258.             return result;
  1259.         }
  1260.         /**
  1261.          * tg ラジオ群を block 別に DOM へ描画する.
  1262.          *   W/D が確定したら現 block の 4 軸 (F/front/side1/side2) ラジオを #tg-options 要素に出す.
  1263.          *   block が空なら #tg-options を空にする.
  1264.          */
  1265.         function renderOptionItemRadios(curW, curD) {
  1266.             var $box = $('#tg-options');
  1267.             if (!$box.length) return;
  1268.             $box.empty();
  1269.             if (!oi_data || !oi_data.blocks) return;
  1270.             var blockKey = (curW || '') + '|' + (curD || '');
  1271.             var block = oi_data.blocks[blockKey];
  1272.             if (!block) return;
  1273.             var axes = ['F', 'front', 'side1', 'side2'];
  1274.             axes.forEach(function(axis) {
  1275.                 var choices = block[axis];
  1276.                 if (!choices || !choices.length) return;
  1277.                 var axisLabel = (oi_data.axis_labels && oi_data.axis_labels[axis]) || axis;
  1278.                 var $section = $('<div class="form-group tg-axis"></div>');
  1279.                 $section.append('<p class="rp-section-label"><strong>' + axisLabel + '</strong>: <span class="tg-axis-selected"></span></p>');
  1280.                 var $list = $('<div class="tg-choice-list"></div>');
  1281.                 choices.forEach(function(ch, i) {
  1282.                     var inputId = 'tg_' + axis + '_' + ch.idx;
  1283.                     var name = 'tg_' + axis;
  1284.                     var checked = (parseInt(ch.idx) === parseInt(oi_selected[axis] || 1)) ? ' checked' : '';
  1285.                     var diffTxt = ch.diff > 0 ? '+' + formatter.format(ch.diff) + '円' : (ch.diff < 0 ? formatter.format(ch.diff) + '円' : '±0');
  1286.                     $list.append(
  1287.                         '<label class="tg-choice"><input type="radio" name="' + name + '" id="' + inputId + '" value="' + ch.idx + '" data-axis="' + axis + '"' + checked + '> ' +
  1288.                         ch.label + '<span class="tg-diff">(' + diffTxt + ')</span></label>'
  1289.                     );
  1290.                 });
  1291.                 $section.append($list);
  1292.                 $box.append($section);
  1293.             });
  1294.             // ラジオ click で oi_selected を更新 → 再計算
  1295.             $box.off('change.tg').on('change.tg', 'input[type="radio"][data-axis]', function() {
  1296.                 var axis = $(this).data('axis');
  1297.                 oi_selected[axis] = parseInt($(this).val()) || 1;
  1298.                 mitsumori_simulation('refresh', '');
  1299.             });
  1300.             updateOptionItemSelectedLabels();
  1301.         }
  1302.         function updateOptionItemSelectedLabels() {
  1303.             $('#tg-options .tg-axis').each(function() {
  1304.                 var $sel = $(this).find('input[type="radio"]:checked');
  1305.                 if (!$sel.length) return;
  1306.                 var label = $sel.parent().contents().filter(function() { return this.nodeType === 3; }).text().trim();
  1307.                 $(this).find('.tg-axis-selected').text(label);
  1308.             });
  1309.         }
  1310.         // =========================================================
  1311.         // fe (sale_type=4) ブロック種類×段数 サブ UI
  1312.         // =========================================================
  1313.         /**
  1314.          * fe_block の親オプション (= op_data 内の「ご希望のフェンス設置方法」 entry)
  1315.          * を name でルックアップし、その index を返す. 見つからなければ -1.
  1316.          *   fe_block.depends_on_name が設定されていればそれで照合.
  1317.          *   未設定なら 'ご希望のフェンス設置方法' を含む name にフォールバック.
  1318.          */
  1319.         function findFeBlockParentOpIndex() {
  1320.             if (!oi_data || !oi_data.fe_block) return -1;
  1321.             var needle = oi_data.fe_block.depends_on_name || 'ご希望のフェンス設置方法';
  1322.             for (var i = 0; i < op_data.length; i++) {
  1323.                 if (!op_data[i] || !op_data[i].name) continue;
  1324.                 if (op_data[i].name.indexOf(needle) >= 0) return i;
  1325.             }
  1326.             return -1;
  1327.         }
  1328.         /**
  1329.          * fe_block の現在の選択値の price (税抜) と choice 内容を集計.
  1330.          *   親オプション (= 'ご希望のフェンス設置方法') が depends_on_value を選んでいる
  1331.          *   ときだけ加算する. それ以外 (既存ブロック側 / 親未選択) は price=0.
  1332.          * 戻り値: { price: 0|N, choice: {key,label,price}|null, active: bool }
  1333.          */
  1334.         function collectFeBlock() {
  1335.             var result = { price: 0, choice: null, active: false };
  1336.             if (SALE_TYPE_ID !== 4) return result;
  1337.             if (!oi_data || !oi_data.fe_block) return result;
  1338.             if (!oi_data.fe_block.choices || !oi_data.fe_block.choices.length) return result;
  1339.             var parentIdx = findFeBlockParentOpIndex();
  1340.             if (parentIdx < 0) return result;
  1341.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1342.             var parentSel = ops[parentIdx];
  1343.             var triggerValue = oi_data.fe_block.depends_on_value || '新規にブロック積みを行う';
  1344.             if (parentSel !== triggerValue) return result;  // 親が新規ブロック積み以外なら無加算
  1345.             result.active = true;
  1346.             var choices = oi_data.fe_block.choices;
  1347.             var pick = null;
  1348.             for (var j = 0; j < choices.length; j++) {
  1349.                 if (choices[j].key === fe_block_selected) { pick = choices[j]; break; }
  1350.             }
  1351.             if (!pick) pick = choices[0];
  1352.             result.choice = pick;
  1353.             result.price  = parseInt(pick.price) || 0;
  1354.             return result;
  1355.         }
  1356.         /**
  1357.          * fe_block ラジオ群を #fe-block-options 要素に描画する.
  1358.          *   active=false (親が「新規にブロック積み」以外) のときは非表示.
  1359.          */
  1360.         function renderFeBlockRadios() {
  1361.             var $box = $('#fe-block-options');
  1362.             if (!$box.length) return;
  1363.             if (!oi_data || !oi_data.fe_block || !oi_data.fe_block.choices) {
  1364.                 $box.empty().hide();
  1365.                 return;
  1366.             }
  1367.             var parentIdx = findFeBlockParentOpIndex();
  1368.             if (parentIdx < 0) {
  1369.                 $box.empty().hide();
  1370.                 return;
  1371.             }
  1372.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1373.             var triggerValue = oi_data.fe_block.depends_on_value || '新規にブロック積みを行う';
  1374.             var visible = (ops[parentIdx] === triggerValue);
  1375.             if (!visible) {
  1376.                 $box.hide();
  1377.                 return;
  1378.             }
  1379.             var fb = oi_data.fe_block;
  1380.             $box.empty();
  1381.             var $title = $('<p class="rp-section-label"><strong>' + (fb.title || 'ブロックの種類と段数') + '</strong></p>');
  1382.             $box.append($title);
  1383.             // 他オプション群と同じ .opt-btn-group / .opt-btn 形式で描画.
  1384.             //   生の <label><input type=radio> ... 形式だと CSS 定義が無く
  1385.             //   ラベル折り返し・縦ズレ・隣接 opt-btn との間隔不揃いが発生する.
  1386.             var $list = $('<div class="opt-btn-group" style="flex-direction:column;align-items:stretch;"></div>');
  1387.             fb.choices.forEach(function(ch) {
  1388.                 var inputId = 'fe_block_' + ch.key;
  1389.                 var isSel   = (ch.key === fe_block_selected);
  1390.                 var checked = isSel ? ' checked' : '';
  1391.                 var selCls  = isSel ? ' is-selected' : '';
  1392.                 var priceTxt = (parseInt(ch.price) || 0) > 0
  1393.                     ? ' <span class="fe-block-price" style="margin-left:6px;color:#666;font-size:12px;white-space:nowrap;">(+' + formatter.format(toIncTax(parseInt(ch.price))) + '円 税込)</span>'
  1394.                     : '';
  1395.                 $list.append(
  1396.                     '<label class="opt-btn' + selCls + '" style="text-align:left;display:flex;align-items:center;flex-wrap:wrap;">' +
  1397.                     '<input type="radio" name="fe_block" id="' + inputId + '" value="' + ch.key + '"' + checked + '>' +
  1398.                     '<span class="fe-block-label">' + ch.label + '</span>' +
  1399.                     priceTxt +
  1400.                     '</label>'
  1401.                 );
  1402.             });
  1403.             $box.append($list);
  1404.             $box.show();
  1405.             $box.off('change.fe_block').on('change.fe_block', 'input[type="radio"][name="fe_block"]', function() {
  1406.                 fe_block_selected = $(this).val();
  1407.                 // is-selected 切替 (opt-btn 形式共通)
  1408.                 $box.find('label.opt-btn').removeClass('is-selected');
  1409.                 $(this).closest('label.opt-btn').addClass('is-selected');
  1410.                 mitsumori_simulation('refresh', '');
  1411.             });
  1412.         }
  1413.         /**
  1414.          * fe (sale_type=4) で op_data エントリの連動表示制御.
  1415.          *   親「ご希望のフェンス設置方法」の選択値に応じて、
  1416.          *     - 「既存ブロックに穴空け工事が必要ですか?」 entry を表示/非表示
  1417.          *   切替の trigger は親選択値の文字列で判定 (entry index にハードコードしない).
  1418.          */
  1419.         function updateFeOpConditionalVisibility() {
  1420.             if (SALE_TYPE_ID !== 4) return;
  1421.             var parentIdx = findFeBlockParentOpIndex();
  1422.             if (parentIdx < 0) return;
  1423.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1424.             var parentSel = ops[parentIdx];
  1425.             // 親が「既存ブロックに設置する」 (= off 側) のとき穴空け entry を表示
  1426.             var triggerOffValue = (op_data[parentIdx] && op_data[parentIdx].off) || '既存ブロックに設置する';
  1427.             $('div[data-op-name]').each(function() {
  1428.                 var n = $(this).attr('data-op-name') || '';
  1429.                 if (n.indexOf('穴空け') >= 0) {
  1430.                     if (parentSel === triggerOffValue) {
  1431.                         $(this).show();
  1432.                     } else {
  1433.                         $(this).hide();
  1434.                     }
  1435.                 }
  1436.             });
  1437.         }
  1438.         /**
  1439.          * 選択中の施工オプションを集計し、ON選択分の price を合計する.
  1440.          * 戻り値: { total: 合計金額, items: [{name, value, price}, ...] }
  1441.          */
  1442.         function collectOptions() {
  1443.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1444.             var total = 0;
  1445.             var items = [];
  1446.             for (var i = 0; i < ops.length; i++) {
  1447.                 if (!op_data[i] || !op_data[i].name) continue;
  1448.                 var sel = ops[i];
  1449.                 if (!sel) continue;
  1450.                 var price = parseInt(op_data[i].price) || 0;
  1451.                 // 「ON」選択時のみ加算(OFF や「不要」「商品購入のみ」は加算しない)
  1452.                 var isOn = (sel === op_data[i].on);
  1453.                 items.push({
  1454.                     name:  op_data[i].name,
  1455.                     value: sel,
  1456.                     price: isOn ? price : 0,
  1457.                     on:    op_data[i].on,
  1458.                     off:   op_data[i].off,
  1459.                 });
  1460.                 if (isOn) total += price;
  1461.             }
  1462.             // fe (sale_type=4) のブロック種類×段数 分を items / total に統合.
  1463.             // 親オプション「ご希望のフェンス設置方法」 が 「新規にブロック積みを行う」 のとき
  1464.             // だけ加算される (collectFeBlock 内で判定済み).
  1465.             var fb = collectFeBlock();
  1466.             if (fb.active && fb.choice) {
  1467.                 items.push({
  1468.                     name:  (oi_data.fe_block && oi_data.fe_block.title) || 'ブロックの種類と段数',
  1469.                     value: fb.choice.label,
  1470.                     price: fb.price,
  1471.                     on:    fb.choice.label,
  1472.                     off:   '',
  1473.                 });
  1474.                 total += fb.price;
  1475.             }
  1476.             return { total: total, items: items };
  1477.         }
  1478.         /**
  1479.          * free_area 1 エントリ ({w,d,h,m,c,price,unit_price,maker_price,ct,option1,option2})
  1480.          * から sale_type 別に最終金額を算出する.
  1481.          *
  1482.          * 計算式(amount=1 ベース、出口で × 1.10 税込化):
  1483.          *   1 通常        : price + ct + option_sum
  1484.          *   2 補助金窓    : price × set_count + (ct + (set_count-1) × option2) + option_sum
  1485.          *   3 物置        : (price + ct) × daisu + option_sum
  1486.          *   4 フェンス    : price + (maisu-1) × unit_price
  1487.          *                  + ct + max(0, maisu-3) × option1
  1488.          *                  + option_sum   (maisu >= 3)
  1489.          *   5 デッキ      : price + ct + option_sum   (area は表示用、計算非関与)
  1490.          *   6 芝生        : price × ceil(area / (w_m × h_m)) + ct + option_sum
  1491.          *   9 商品のみ    : price のみ(カート quantity 倍で総額)
  1492.          *
  1493.          * fe では option1 を ct_up、um では option2 を ct_up として転用.
  1494.          * tf では w / h にロール幅・長さが格納されており parseLen で数値抽出.
  1495.          *
  1496.          * @param {Object} pp  free_area の 1 行(matrix エントリ)
  1497.          * @param {number} optionTotal  collectOptions().total
  1498.          * @param {Object} ctx  UI 入力 {set_count, daisu, maisu, area, quantityOnly, ...}
  1499.          * @returns {Object} {goukei, price, ct, opt, qty}  すべて税込整数
  1500.          */
  1501.         function calcGoukei(pp, optionTotal, ctx) {
  1502.             var basePrice  = parseInt(pp.price)       || 0;
  1503.             var baseCt     = parseInt(pp.ct)          || 0;
  1504.             var unitPrice  = parseInt(pp.unit_price)  || 0;
  1505.             var optSum     = optionTotal;
  1506.             var price      = basePrice;
  1507.             var ct         = baseCt;
  1508.             var qty        = 1;
  1509.             var goukei     = 0;
  1510.             // 「商品購入のみ」選択時は工事費・オプションをゼロにする(任意 sale_type で適用)
  1511.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1512.             var purchaseOnly = ops.some(function(v){ return v === '商品購入のみ'; });
  1513.             if (purchaseOnly) {
  1514.                 baseCt = 0;
  1515.                 ct     = 0;
  1516.                 optSum = 0;
  1517.             }
  1518.             switch (SALE_TYPE_ID) {
  1519.                 case 2: {  // 補助金・窓 (シンプル表引き方式 2026-05-)
  1520.                     // 2026-05 仕様簡素化: 枚数軸を廃止し、subtype に枚数を内包.
  1521.                     // pp.price / pp.ct は (W, H, ガラス, subtype) の単一価格.
  1522.                     // 複数枚をまとめて買う場合はカート quantity で表現.
  1523.                     qty    = 1;
  1524.                     price  = basePrice;
  1525.                     ct     = baseCt;
  1526.                     goukei = price + ct + optSum;
  1527.                     break;
  1528.                 }
  1529.                 case 3: {  // 物置・ゴミステーション
  1530.                     qty   = Math.max(1, parseInt(ctx.daisu) || 1);
  1531.                     price = basePrice * qty;
  1532.                     ct    = baseCt * qty;
  1533.                     goukei = price + ct + optSum;
  1534.                     break;
  1535.                 }
  1536.                 case 4: {  // フェンス・組み立て式(maisu ≥ 3、base_amount = 3)
  1537.                     // scraper は amount=3 を base にしているので pp.price = price(3),
  1538.                     // pp.unit_price = price(4) - price(3).
  1539.                     qty   = Math.max(3, parseInt(ctx.maisu) || 3);
  1540.                     price = basePrice + (qty - 3) * unitPrice;
  1541.                     // option1 が ct_up (4枚目以降の増分). 未設定なら ct 固定動作
  1542.                     var ctUp1 = parseInt(pp.option1) || 0;
  1543.                     ct = baseCt + Math.max(0, qty - 3) * ctUp1;
  1544.                     // fe_block(ブロック積み段数): collectOptions が base(3枚分)を optSum に
  1545.                     // 算入済み. ブロック費も本体同様に枚数連動するため、4枚目以降は 1枚毎に
  1546.                     // choice.unit_price(= block(4)-block(3)) を加算する.
  1547.                     // (顧客指摘「何枚施工でも増える金額が同じ」の是正。unit_price 未設定の
  1548.                     //  旧データでは +0 で従来動作。)
  1549.                     if (!purchaseOnly) {
  1550.                         var fbC = collectFeBlock();
  1551.                         if (fbC.active && fbC.choice) {
  1552.                             optSum += Math.max(0, qty - 3) * (parseInt(fbC.choice.unit_price) || 0);
  1553.                         }
  1554.                     }
  1555.                     goukei = price + ct + optSum;
  1556.                     break;
  1557.                 }
  1558.                 case 5: {  // ウッドデッキ・タイルデッキ
  1559.                     // area は担当者向けの参考値として保持(計算には使わない)
  1560.                     qty    = 1;
  1561.                     goukei = basePrice + baseCt + optSum;
  1562.                     price  = basePrice;
  1563.                     ct     = baseCt;
  1564.                     break;
  1565.                 }
  1566.                 case 6: {  // 芝生・人工芝(ロール単位)
  1567.                     // pp.w "1m", pp.h "10m" から数値抽出
  1568.                     var w_m = parseLen(pp.w);
  1569.                     var h_m = parseLen(pp.h);
  1570.                     var rollSize = w_m * h_m;
  1571.                     if (!rollSize || rollSize <= 0) rollSize = 1;
  1572.                     // 施工サイズ(面積)があれば必要枚数を自動算出。無ければ直接指定の枚数を使う。
  1573.                     var area  = parseFloat(ctx.area) || 0;
  1574.                     if (area > 0) {
  1575.                         qty = Math.max(1, Math.ceil(area / rollSize));
  1576.                     } else {
  1577.                         qty = Math.max(1, parseInt(ctx.tf_qty) || 1);
  1578.                     }
  1579.                     price  = basePrice * qty;
  1580.                     ct     = baseCt;
  1581.                     goukei = price + ct + optSum;
  1582.                     break;
  1583.                 }
  1584.                 case 7: {  // 数量買い・基本工事費固定(gf ガーデンファニチャー / st 石材)
  1585.                     qty    = Math.max(1, parseInt(ctx.suuryou) || 1);
  1586.                     price  = basePrice * qty;
  1587.                     ct     = baseCt;                 // ct は固定(数量に依らない)
  1588.                     goukei = price + ct + optSum;
  1589.                     break;
  1590.                 }
  1591.                 case 9: {  // 商品のみ購入
  1592.                     // カート側で quantity × unit price するため goukei は単品価格
  1593.                     qty    = parseInt(ctx.quantityOnly) || 1;
  1594.                     price  = basePrice;
  1595.                     ct     = 0;
  1596.                     optSum = 0;
  1597.                     goukei = price;
  1598.                     break;
  1599.                 }
  1600.                 default: {  // 1: 通常(カーポート等、matrix 選択のみ)
  1601.                     qty    = 1;
  1602.                     goukei = basePrice + baseCt + optSum;
  1603.                     break;
  1604.                 }
  1605.             }
  1606.             // 出口で税込化(pp.price/pp.ct/op_data.price はすべて税抜で保存されている前提)
  1607.             return {
  1608.                 goukei: toIncTax(goukei),
  1609.                 price:  toIncTax(price),
  1610.                 ct:     toIncTax(ct),
  1611.                 opt:    toIncTax(optSum),
  1612.                 qty:    qty,
  1613.             };
  1614.         }
  1615.         /**
  1616.          * 寸法文字列から「メートル単位の数値」を抽出する.
  1617.          *
  1618.          * 単位は m / cm / mm を認識し、いずれも m 単位に正規化して返す.
  1619.          * 単位が無い場合は m 単位とみなす(旧 tf データ "1m" "10m" との互換).
  1620.          * 数値が見つからない場合は 0 を返す(呼び出し側で fallback).
  1621.          *
  1622.          * 例:
  1623.          *   "1m"     → 1
  1624.          *   "100cm"  → 1   (2026-06 以降の m → cm 正規化に対応)
  1625.          *   "200cm"  → 2
  1626.          *   "5.5m"   → 5.5
  1627.          *   "1000mm" → 1
  1628.          *   ""       → 0
  1629.          */
  1630.         function parseLen(s) {
  1631.             if (!s) return 0;
  1632.             var str = String(s);
  1633.             var m = str.match(/(\d+(?:\.\d+)?)\s*(mm|cm|m)?/i);
  1634.             if (!m) return 0;
  1635.             var n = parseFloat(m[1]);
  1636.             if (isNaN(n)) return 0;
  1637.             var unit = (m[2] || 'm').toLowerCase();
  1638.             if (unit === 'cm') return n / 100;
  1639.             if (unit === 'mm') return n / 1000;
  1640.             return n;  // 'm' or no unit
  1641.         }
  1642.         // pp は autoSelectFirstColor 等からも参照するので global にする
  1643.         var pp = {{ pp|raw }};
  1644.         // sale_type=2 の幅 / 高さ ladder (Twig p_w / p_h を JS で参照するため).
  1645.         // 入力 mm 値を pp の幅・高さバケット文字列にマッピングする際の元データ.
  1646.         // p_w / p_h は連想配列で来ることがあるため Object.values で配列化する.
  1647.         var PP_W_LADDER = Object.values({{ p_w|default({})|json_encode|raw }} || {});
  1648.         var PP_H_LADDER = Object.values({{ p_h|default({})|json_encode|raw }} || {});
  1649.         /* ============================================================
  1650.            sale_type=2 (補助金窓) 専用: 複数タイプ集計 & 補助金計算
  1651.            ============================================================
  1652.            - 入力 UI: #window-types-container 配下の .window-type-block
  1653.            - 補助金根拠: 先進的窓リノベ2026事業
  1654.              https://window-renovation2026.env.go.jp/construction/inner-window.html
  1655.            - 価格軸: (subtype, w, h, glass, color) で pp を lookup
  1656.            - 1 商品 = 1 明細 にまとめ、内訳 JSON を別途保存予定 (cart 連携は後続タスク)
  1657.            ============================================================ */
  1658.         // 補助金マトリクス: [住宅区分][性能][サイズ区分] → 1 箇所あたり金額 (税抜・端数なし)
  1659.         var WINDOW_SUBSIDY_MATRIX = {
  1660.             detached:  { // 戸建住宅・延床240㎡以下の非住宅
  1661.                 P: { G: 140000, L: 89000, M: 58000, S: 36000 },
  1662.                 S: { G: 76000,  L: 52000, M: 34000, S: 22000 }
  1663.             },
  1664.             apartment: { // 低層・中高層集合住宅・240㎡超の非住宅
  1665.                 P: { G: 152000, L: 98000, M: 64000, S: 40000 },
  1666.                 S: { G: 83000,  L: 57000, M: 37000, S: 24000 }
  1667.             }
  1668.         };
  1669.         // 住宅区分: 画面 UI (input[name="window_housing_type"]) から取得する.
  1670.         // 既定値は PFC meta_key="住宅区分" を fallback (未設定なら '戸建').
  1671.         var HOUSING_TYPE_DEFAULT = {{ getProduct_field(Product.id, '住宅区分')|default('戸建')|json_encode|raw }};
  1672.         function getCurrentHousingKey() {
  1673.             var el = document.querySelector('input[name="window_housing_type"]:checked');
  1674.             var v  = el ? el.value : HOUSING_TYPE_DEFAULT;
  1675.             return (v === '集合住宅') ? 'apartment' : 'detached';
  1676.         }
  1677.         // 商品シリーズ自動判定 (Product.name から)
  1678.         // 根拠カタログ: YKK AP「ウチリモ」XAAAA-H26-067-1 (2026.04), 同「LiteU」XAAAA-H16-088-2,
  1679.         //              三協アルミ「プラメイクEII」0142_STJ1931L, LIXIL「インプラス」(既知)
  1680.         var PRODUCT_NAME_RAW = {{ Product.name|default('')|json_encode|raw }};
  1681.         function detectProductSeries(name) {
  1682.             if (!name) return null;
  1683.             if (/ウチリモ/.test(name)) return 'uchirimo';
  1684.             if (/プラマード\s*U/i.test(name)) return 'pramado_u';
  1685.             if (/インプラス/.test(name)) return 'inplus';
  1686.             if (/プラメイク\s*EII|プラメイクEII/i.test(name)) return 'plamake_eii';
  1687.             if (/LiteU/i.test(name)) return 'lite_u';
  1688.             return null;
  1689.         }
  1690.         // シリーズ上限グレード:
  1691.         //   'P'  = SS/P まで到達可能 (真空断熱ガラス採用シリーズ)
  1692.         //   'S'  = Low-E 複層止まり (真空断熱ガラスのラインなし)
  1693.         //   null = 単板のみ → 補助金対象外
  1694.         var SERIES_GRADE_CAP = {
  1695.             uchirimo:    'P',
  1696.             pramado_u:   'P',
  1697.             inplus:      'S',
  1698.             plamake_eii: 'S',
  1699.             lite_u:      null
  1700.         };
  1701.         var DETECTED_SERIES = detectProductSeries(PRODUCT_NAME_RAW);
  1702.         var SERIES_GRADE_CAP_VAL = (DETECTED_SERIES !== null && Object.prototype.hasOwnProperty.call(SERIES_GRADE_CAP, DETECTED_SERIES))
  1703.             ? SERIES_GRADE_CAP[DETECTED_SERIES]
  1704.             : undefined;
  1705.         // 商品単位グレード上限 (PFC `meta_key=補助金グレード上限` で個別上書き)
  1706.         // 値: 'P' / 'SS' / 'S' / '対象外' / '無' / 'NONE' / 空文字 (未指定)
  1707.         var PRODUCT_GRADE_CAP_RAW = {{ getProduct_field(Product.id, '補助金グレード上限')|default('')|json_encode|raw }};
  1708.         function normalizeGradeCap(v) {
  1709.             if (v === null || v === undefined || v === '') return undefined;
  1710.             var s = String(v).trim().toUpperCase();
  1711.             if (s === 'NONE' || s === '対象外' || s === '無') return null;
  1712.             if (s === 'P' || s === 'SS') return 'P';
  1713.             if (s === 'S') return 'S';
  1714.             return undefined;
  1715.         }
  1716.         var PRODUCT_GRADE_CAP = normalizeGradeCap(PRODUCT_GRADE_CAP_RAW);
  1717.         // 窓種 (subtype = option1) ごとのグレード上限.
  1718.         // 根拠: YKK AP「ウチリモ」業務用 (XAAAA-H26-067-1) の窓種別ラインナップで
  1719.         //      真空ガラス (Glavenir) の設定有無を確認:
  1720.         //        引違い窓 (2/3/4枚建) / 浴室仕様 引違い窓 / FIX窓        → P 到達可能
  1721.         //        内開き窓 (居室/浴室) / 開き窓テラス / テラスドア類       → 真空ガラスなし → S 止まり
  1722.         function detectSubtypeGradeCap(subtype) {
  1723.             if (!subtype) return undefined;
  1724.             var s = String(subtype);
  1725.             if (/内開|開き窓テラス|テラスドア|開き戸/.test(s)) return 'S';
  1726.             return undefined;
  1727.         }
  1728.         // クリップ: 強さは 'P' > 'S' > null (対象外). cap=null は強制対象外, cap=undefined は無効化なし.
  1729.         function clipGradeBy(grade, cap) {
  1730.             if (cap === undefined) return grade;
  1731.             if (cap === null)      return null;
  1732.             if (grade === null)    return null;
  1733.             if (cap === 'S' && grade === 'P') return 'S';
  1734.             return grade;
  1735.         }
  1736.         function finalizeGlassGrade(raw, subtype) {
  1737.             var g = clipGradeBy(raw, SERIES_GRADE_CAP_VAL);
  1738.             g     = clipGradeBy(g,   detectSubtypeGradeCap(subtype));
  1739.             g     = clipGradeBy(g,   PRODUCT_GRADE_CAP);
  1740.             return g;
  1741.         }
  1742.         /**
  1743.          * ガラスタイプ名から性能区分 'P' (SS, Uw≤1.1) / 'S' (Uw≤1.5) / null を判別.
  1744.          * null = 補助対象外.
  1745.          *
  1746.          * 根拠: YKK AP「ウチリモ 内窓」業務用カタログ (XAAAA-H26-069-1) で
  1747.          *       P (SS) は真空断熱ガラスのみ、Low-E はアルゴン入りでも S 止まり、
  1748.          *       Low-E ガス無 + 型ガラス / フロストは 2026年4月で対象外、
  1749.          *       が確認できた。アルゴン入り Low-E を P 判定する旧ルールは誤りだった。
  1750.          *
  1751.          * シリーズによっては P がそもそも存在しない (LIXIL インプラスは S 一律)
  1752.          * ため、最終的には PFC で商品単位の上限を上書きできる仕組みが必要。
  1753.          */
  1754.         function detectGlassPerformance(glassName) {
  1755.             if (!glassName) return null;
  1756.             var n = String(glassName);
  1757.             // 補助対象外: 単板 / 和紙調 / 防音 / 防犯 / 型ガラス・フロスト (Low-E ガス無の型は 2026/4 で対象外)
  1758.             if (/単ガラス|単板|和紙調|防音|防犯|複層\/型|型ガラス|フロスト/.test(n)) return null;
  1759.             // P (SS): 真空断熱ガラスのみ
  1760.             if (/真空断熱/.test(n)) return 'P';
  1761.             // S: Low-E 系のみ (アルゴン入りでも S 止まり)
  1762.             if (/Low-?E/i.test(n)) return 'S';
  1763.             // 一般複層 / ブラインドイン複層 / 複層強化 など Low-E 無しの複層は補助対象外
  1764.             return null;
  1765.         }
  1766.         /**
  1767.          * 幅 mm × 高さ mm からサイズ区分 'G' (≥4.0㎡) / 'L' (2.8-3.9) / 'M' (1.6-2.7) / 'S' (0.2-1.5) / null.
  1768.          * null = 補助対象外 (0.2㎡ 未満).
  1769.          */
  1770.         function detectSizeClass(w_mm, h_mm) {
  1771.             var w = parseFloat(w_mm) || 0;
  1772.             var h = parseFloat(h_mm) || 0;
  1773.             if (w <= 0 || h <= 0) return null;
  1774.             var area = (w * h) / 1000000.0;
  1775.             if (area < 0.2) return null;
  1776.             if (area < 1.6) return 'S';
  1777.             if (area < 2.8) return 'M';
  1778.             if (area < 4.0) return 'L';
  1779.             return 'G';
  1780.         }
  1781.         function lookupSubsidyAmount(performance, sizeClass) {
  1782.             if (!performance || !sizeClass) return 0;
  1783.             var t = WINDOW_SUBSIDY_MATRIX[getCurrentHousingKey()];
  1784.             if (!t || !t[performance]) return 0;
  1785.             return t[performance][sizeClass] || 0;
  1786.         }
  1787.         /**
  1788.          * mm 入力値を ladder バケット文字列に変換する.
  1789.          *   bucketizeMm(1750, ["100cm まで","150cm まで","200cm まで","300cm まで"]) → "200cm まで"
  1790.          * - 入力が空 or 0 のときはそのまま返す (未入力扱い)
  1791.          * - 入力がラダー最大を超えるときは最大バケットを返す (= 価格上限の保護)
  1792.          * - 入力文字列が既にラダーラベルそのものなら無変換 (互換のため)
  1793.          */
  1794.         function bucketizeMm(input, ladder) {
  1795.             if (!input && input !== 0) return '';
  1796.             if (!ladder || ladder.length === 0) return input;
  1797.             var s = String(input).trim();
  1798.             if (s === '') return '';
  1799.             if (ladder.indexOf(s) >= 0) return s;
  1800.             var mm = parseMm(s);
  1801.             if (mm <= 0) return s;
  1802.             var withMax = ladder.map(function(b) { return { label: b, max: parseMm(b) }; });
  1803.             withMax.sort(function(a, b) { return a.max - b.max; });
  1804.             for (var i = 0; i < withMax.length; i++) {
  1805.                 if (mm <= withMax[i].max) return withMax[i].label;
  1806.             }
  1807.             return withMax[withMax.length - 1].label;
  1808.         }
  1809.         /**
  1810.          * pp 配列から該当 1 行を返す. 完全一致優先、見つからなければ最初の候補.
  1811.          * 軸: subtype (option1) / w / h / m / c. axisMatch は既存ロジックと同じ.
  1812.          * sale_type=2 では pw_val / ph_val に mm 数値が来るため、内部で bucketizeMm
  1813.          * を通してから既存マッチングに渡す.
  1814.          */
  1815.         function lookupPpRow(subtype, pw_val, ph_val, pm_val, pc_val) {
  1816.             if (!pp || pp.length === 0) return null;
  1817.             var pw_bucket = bucketizeMm(pw_val, PP_W_LADDER);
  1818.             var ph_bucket = bucketizeMm(ph_val, PP_H_LADDER);
  1819.             var axMatch = function(input, value) {
  1820.                 return input == value || input === '指定なし' || value === '' || value == null;
  1821.             };
  1822.             var colMatch = function(input, value) {
  1823.                 if (axMatch(input, value)) return true;
  1824.                 if (typeof value === 'string' && value.indexOf('/') !== -1 && input) {
  1825.                     return value.split('/').some(function(s) { return s.trim() === input; });
  1826.                 }
  1827.                 return false;
  1828.             };
  1829.             var candidates = pp.filter(function(el) {
  1830.                 return axMatch(pw_bucket, el.w)
  1831.                     && axMatch(ph_bucket, el.h)
  1832.                     && axMatch(pm_val, el.m)
  1833.                     && axMatch(subtype, el.option1);
  1834.             });
  1835.             for (var i = 0; i < candidates.length; i++) {
  1836.                 if (colMatch(pc_val, candidates[i].c)) return candidates[i];
  1837.             }
  1838.             return candidates[0] || null;
  1839.         }
  1840.         /**
  1841.          * "1000mm" / "200cm" / "1.0m" / 単位なし → mm に正規化して返す.
  1842.          * UI 上の「200cm まで」等の文字列をそのまま渡せるようにする.
  1843.          */
  1844.         function parseMm(s) {
  1845.             if (!s) return 0;
  1846.             var str = String(s);
  1847.             var m = str.match(/(\d+(?:\.\d+)?)/);
  1848.             if (!m) return 0;
  1849.             var num = parseFloat(m[1]);
  1850.             if (/mm/i.test(str)) return num;
  1851.             if (/cm/i.test(str)) return num * 10;
  1852.             if (/(^|\d)\s*m($|\W)/i.test(str)) return num * 1000;
  1853.             return num;
  1854.         }
  1855.         /**
  1856.          * 1 タイプブロックから入力を読み、pp lookup → 単価・補助金額を計算して返す.
  1857.          * incomplete=true: 軸のどれかが未選択 → 計算しない (UI で「未選択」を示すため).
  1858.          */
  1859.         function collectWindowTypeRow(block) {
  1860.             var get = function(axis) {
  1861.                 // radio / checkbox は :checked、それ以外 (number/text) は値そのまま.
  1862.                 var radio = block.querySelector('input[data-axis="' + axis + '"]:checked');
  1863.                 if (radio) return radio.value;
  1864.                 var any = block.querySelector('input[data-axis="' + axis + '"]');
  1865.                 if (!any) return '';
  1866.                 if (any.type === 'radio' || any.type === 'checkbox') return '';
  1867.                 return (any.value || '').trim();
  1868.             };
  1869.             var setqtyEl = block.querySelector('input[data-axis="setqty"]');
  1870.             var subtype = get('subtype');
  1871.             var pw_val  = get('pw');
  1872.             var ph_val  = get('ph');
  1873.             var pm_val  = get('pm');
  1874.             var pc_val  = get('pc');
  1875.             var setqty  = setqtyEl ? Math.max(1, parseInt(setqtyEl.value) || 1) : 1;
  1876.             var row = {
  1877.                 subtype: subtype, pw: pw_val, ph: ph_val, pm: pm_val, pc: pc_val, setqty: setqty,
  1878.                 unit_price_exc: 0, unit_ct_exc: 0, subsidy: 0,
  1879.                 size_class: null, glass_perf: null,
  1880.                 incomplete: false
  1881.             };
  1882.             // p_option1 / p_w / p_h / p_m / color のいずれかが商品データに無いときは未選択でも完了扱いにする.
  1883.             // (例: 商品によっては subtype が無い場合がある)
  1884.             var hasSubtype = !!block.querySelector('input[data-axis="subtype"]');
  1885.             var hasPw      = !!block.querySelector('input[data-axis="pw"]');
  1886.             var hasPh      = !!block.querySelector('input[data-axis="ph"]');
  1887.             var hasPm      = !!block.querySelector('input[data-axis="pm"]');
  1888.             var hasPc      = !!block.querySelector('input[data-axis="pc"]');
  1889.             if ((hasSubtype && !subtype) || (hasPw && !pw_val) || (hasPh && !ph_val)
  1890.                 || (hasPm && !pm_val)  || (hasPc && !pc_val)) {
  1891.                 row.incomplete = true;
  1892.                 return row;
  1893.             }
  1894.             var ppRow = lookupPpRow(subtype, pw_val, ph_val, pm_val, pc_val);
  1895.             if (ppRow) {
  1896.                 row.unit_price_exc = parseInt(ppRow.price) || 0;
  1897.                 row.unit_ct_exc    = parseInt(ppRow.ct)    || 0;
  1898.             }
  1899.             // ガラス名検出 → シリーズ上限 → subtype 上限 → 商品上限 の順で min クリップ.
  1900.             // 例: LiteU (SERIES_GRADE_CAP_VAL=null) は Low-E でも null に落ちて補助対象外.
  1901.             // 例: ウチリモの「内開き窓」subtype は真空ガラスでも S に落ちる.
  1902.             row.glass_perf = finalizeGlassGrade(detectGlassPerformance(pm_val), subtype);
  1903.             row.size_class = detectSizeClass(parseMm(pw_val), parseMm(ph_val));
  1904.             row.subsidy    = lookupSubsidyAmount(row.glass_perf, row.size_class);
  1905.             return row;
  1906.         }
  1907.         /**
  1908.          * sale_type=2 用集計: 全タイプから合計を出し DOM 更新.
  1909.          * 計算式 (税抜→税込で出口で 1.10 倍):
  1910.          *   商品金額 = Σ(各タイプ単価 × set_qty)
  1911.          *   基本工事費 = 1 回分 (各タイプ pp.ct のうち最初に得た非ゼロ値)
  1912.          *   補助金合計 = Σ(各タイプ補助金 × set_qty)
  1913.          *   実質支払額 = (商品+ct+option) 税込 - 補助金合計
  1914.          */
  1915.         function recalcAllForSaleType2() {
  1916.             if (typeof SALE_TYPE_ID === 'undefined' || SALE_TYPE_ID != 2) return;
  1917.             if (!pp || pp.length === 0) {
  1918.                 $('#mitsumori_message').text('価格データ準備中');
  1919.                 $('#mitsumori_btn').hide();
  1920.                 ['#mitsumori_goukei','#mitsumori_off','#mitsumori_price','#maker_price',
  1921.                  '#mitsumori_ct','#mitsumori_option','#mitsumori_kei','#mitsumori_shoukei','#mitsumori_tax']
  1922.                  .forEach(function(s){ $(s).text('---円'); });
  1923.                 return;
  1924.             }
  1925.             var blocks = document.querySelectorAll('#window-types-container .window-type-block');
  1926.             if (blocks.length === 0) return;
  1927.             var rows = [];
  1928.             var hasIncomplete = false;
  1929.             var baseCt = 0;
  1930.             var hasAnyPriced = false;
  1931.             blocks.forEach(function(b) {
  1932.                 var r = collectWindowTypeRow(b);
  1933.                 rows.push({ block: b, row: r });
  1934.                 if (r.incomplete) hasIncomplete = true;
  1935.                 if (r.unit_ct_exc > 0 && baseCt === 0) baseCt = r.unit_ct_exc;
  1936.                 if (r.unit_price_exc > 0) hasAnyPriced = true;
  1937.                 var subSpan = b.querySelector('.wt-subsidy-amount');
  1938.                 if (subSpan) subSpan.textContent = r.incomplete ? '―' : Math.round(r.subsidy * r.setqty).toLocaleString();
  1939.             });
  1940.             if (hasIncomplete || !hasAnyPriced) {
  1941.                 $('#mitsumori_message').text('窓タイプを選択してください');
  1942.                 $('#mitsumori_btn').hide();
  1943.                 return;
  1944.             }
  1945.             var ops = [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10];
  1946.             var purchaseOnly = ops.some(function(v){ return v === '商品購入のみ'; });
  1947.             var sumPriceExc = 0, sumSubsidy = 0, totalPanes = 0;
  1948.             rows.forEach(function(item) {
  1949.                 var r = item.row;
  1950.                 sumPriceExc += r.unit_price_exc * r.setqty;
  1951.                 sumSubsidy  += r.subsidy * r.setqty;
  1952.                 if (r.unit_price_exc > 0) totalPanes += r.setqty;
  1953.             });
  1954.             // 内窓 工事費(顧客最終回答): 1枚目 22,000円 + 2枚目以降 1枚あたり +5,000円(税込表示額)。
  1955.             // 既存パイプライン整合のため税抜(ctExc)も用意(税行 taxAmt 用)。商品購入のみは 0。
  1956.             var WINDOW_CT_BASE = 22000, WINDOW_CT_ADD = 5000;
  1957.             var ctIncTarget = purchaseOnly ? 0 : (WINDOW_CT_BASE + Math.max(0, totalPanes - 1) * WINDOW_CT_ADD);
  1958.             var ctExc  = purchaseOnly ? 0 : Math.round(ctIncTarget / (1 + TAX_RATE));
  1959.             var optExc = purchaseOnly ? 0 : (collectOptions().total || 0);
  1960.             var sumPriceInc = Math.round(sumPriceExc * (1 + TAX_RATE));
  1961.             var ctInc       = ctIncTarget;
  1962.             var optInc      = Math.round(optExc * (1 + TAX_RATE));
  1963.             var goukeiInc   = sumPriceInc + ctInc + optInc;
  1964.             // 窓リノベ2026 申請条件:
  1965.             //   - 補助金合計 ≥ 50,000 円 (5 万円未満は申請不可 → 還元 0 円扱い)
  1966.             //   - 1 戸あたり上限 1,000,000 円 (住宅・非住宅240㎡以下)
  1967.             //     ※ 非住宅 240㎡超の 10,000,000 円上限は対象外 (商品設計時に別扱い想定)
  1968.             var SUBSIDY_MIN_AMOUNT = 50000;
  1969.             var SUBSIDY_MAX_PER_UNIT = 1000000;
  1970.             var subsidyRawSum = sumSubsidy;
  1971.             var subsidyEligible = subsidyRawSum >= SUBSIDY_MIN_AMOUNT;
  1972.             var subsidyAmt = 0;
  1973.             var subsidyNote = '';
  1974.             if (subsidyEligible) {
  1975.                 if (subsidyRawSum > SUBSIDY_MAX_PER_UNIT) {
  1976.                     subsidyAmt = SUBSIDY_MAX_PER_UNIT;
  1977.                     subsidyNote = '※補助上限 ' + SUBSIDY_MAX_PER_UNIT.toLocaleString()
  1978.                         + '円 超過分は控除対象外(補助金合計 ' + subsidyRawSum.toLocaleString() + '円)';
  1979.                 } else {
  1980.                     subsidyAmt = subsidyRawSum;
  1981.                 }
  1982.             } else if (subsidyRawSum > 0) {
  1983.                 subsidyNote = '※補助金合計が 5 万円未満のため申請対象外です('
  1984.                     + subsidyRawSum.toLocaleString() + '円)';
  1985.             } else if (SERIES_GRADE_CAP_VAL === null) {
  1986.                 // LiteU 等の単板構成シリーズ: グレード判定で必ず null になる
  1987.                 subsidyNote = '※本商品は補助金(先進的窓リノベ2026事業)対象外です';
  1988.             } else if (PRODUCT_GRADE_CAP === null) {
  1989.                 subsidyNote = '※本商品は補助金対象外として登録されています';
  1990.             }
  1991.             var implementedInc = Math.max(0, goukeiInc - subsidyAmt);
  1992.             var taxAmt      = Math.round((sumPriceExc + ctExc + optExc) * TAX_RATE);
  1993.             $('#mitsumori_message').text(subsidyNote);
  1994.             $('#mitsumori_btn').show();
  1995.             $('#mitsumori_goukei').text(goukeiInc.toLocaleString() + '円');
  1996.             $('#mitsumori_price').text(sumPriceInc.toLocaleString() + '円');
  1997.             $('#mitsumori_ct').text(ctInc.toLocaleString() + '円');
  1998.             $('#mitsumori_option').text(optInc.toLocaleString() + '円');
  1999.             $('#mitsumori_off').text((subsidyAmt > 0 ? '-' : '') + subsidyAmt.toLocaleString() + '円');
  2000.             $('#maker_price').text('---円'); // 補助金窓では未使用
  2001.             $('#mitsumori_kei').text(goukeiInc.toLocaleString() + '円');
  2002.             $('#mitsumori_shoukei').text(implementedInc.toLocaleString() + '円');
  2003.             $('#mitsumori_tax').text(taxAmt.toLocaleString() + '円');
  2004.             // 内訳を mitsumori_json に詰めて hidden input にセット (PDF / カート連携用)
  2005.             var window_types = rows.map(function(item) {
  2006.                 var r = item.row;
  2007.                 // 幅 / 高さは数値入力 (mm) が来るので "1750mm" 形式で保存する.
  2008.                 // 古い radio 由来の "200cm まで" 形式が来た場合はそのまま保存して互換.
  2009.                 var w_mm = parseMm(r.pw);
  2010.                 var h_mm = parseMm(r.ph);
  2011.                 var w_save = (w_mm > 0 && /^\s*\d+(?:\.\d+)?\s*$/.test(String(r.pw))) ? (w_mm + 'mm') : r.pw;
  2012.                 var h_save = (h_mm > 0 && /^\s*\d+(?:\.\d+)?\s*$/.test(String(r.ph))) ? (h_mm + 'mm') : r.ph;
  2013.                 return {
  2014.                     subtype:        r.subtype,
  2015.                     w:              w_save,
  2016.                     h:              h_save,
  2017.                     glass:          r.pm,
  2018.                     color:          r.pc,
  2019.                     setqty:         r.setqty,
  2020.                     unit_price_inc: Math.round(r.unit_price_exc * (1 + TAX_RATE)),
  2021.                     line_total_inc: Math.round(r.unit_price_exc * r.setqty * (1 + TAX_RATE)),
  2022.                     size_class:     r.size_class,
  2023.                     glass_perf:     r.glass_perf,
  2024.                     subsidy_unit:   r.subsidy,
  2025.                     subsidy_total:  r.subsidy * r.setqty
  2026.                 };
  2027.             });
  2028.             var opCalc2 = collectOptions();
  2029.             var mitsumori_json = {
  2030.                 "mitsumori_goukei": goukeiInc.toLocaleString() + '円',
  2031.                 "mitsumori_price":  sumPriceInc.toLocaleString() + '円',
  2032.                 "mitsumori_ct":     ctInc.toLocaleString() + '円',
  2033.                 "mitsumori_option": optInc.toLocaleString() + '円',
  2034.                 "mitsumori_off":    (subsidyAmt > 0 ? '-' : '') + subsidyAmt.toLocaleString() + '円',
  2035.                 "maker_price":      '---円',
  2036.                 "product_id":       {{ Product.id }},
  2037.                 "sale_type":        SALE_TYPE_ID,
  2038.                 "housing_key":      getCurrentHousingKey(),
  2039.                 "series_key":       DETECTED_SERIES,
  2040.                 "series_grade_cap": (SERIES_GRADE_CAP_VAL === undefined) ? null : SERIES_GRADE_CAP_VAL,
  2041.                 "product_grade_cap":(PRODUCT_GRADE_CAP    === undefined) ? null : PRODUCT_GRADE_CAP,
  2042.                 "window_types":     window_types,
  2043.                 "subsidy_total":    subsidyAmt,
  2044.                 "subsidy_raw":      subsidyRawSum,
  2045.                 "subsidy_eligible": subsidyEligible,
  2046.                 "subsidy_note":     subsidyNote,
  2047.                 "op_items":         opCalc2.items
  2048.             };
  2049.             $('#mitsumori_json').val(JSON.stringify(mitsumori_json));
  2050.             renderWindowTypesModalRows(window_types, subsidyAmt);
  2051.         }
  2052.         /**
  2053.          * sale_type=2 用: 見積モーダル明細テーブルを window_types で動的展開.
  2054.          * - 既存の商品名行 (1 行目) は hide() し、各タイプ行を上に挿入
  2055.          * - 基本工事費行はそのまま (#mitsumori_ct_01 / _02 が更新されている)
  2056.          * - 補助金 (割引額) 行を末尾に追加
  2057.          * - 既存の renderOptionDetailRows と共存できるよう class で区別
  2058.          */
  2059.         function renderWindowTypesModalRows(window_types, subsidyAmt) {
  2060.             var $tbody = $('.modal-mitsumori table tbody');
  2061.             if (!$tbody.length) return;
  2062.             // 既存の動的行を全削除 (opt-row は既存実装、wt-row / wt-subsidy-row は今回追加)
  2063.             $tbody.find('tr.wt-row, tr.wt-subsidy-row').remove();
  2064.             var $itemRow = $tbody.find('tr').first();
  2065.             var fmt = new Intl.NumberFormat('ja-JP');
  2066.             if (!window_types || window_types.length === 0) {
  2067.                 // 集計対象なし → 商品名行を表示に戻す
  2068.                 $itemRow.show();
  2069.                 return;
  2070.             }
  2071.             window_types.forEach(function(wt, i) {
  2072.                 var label = '窓タイプ' + (i + 1) + ':'
  2073.                     + (wt.subtype || '') + ' / '
  2074.                     + (wt.w || '') + '×' + (wt.h || '') + ' / '
  2075.                     + (wt.glass || '') + ' / '
  2076.                     + (wt.color || '');
  2077.                 var $tr = $('<tr class="wt-row"></tr>')
  2078.                     .append('<td>' + label + '</td>')
  2079.                     .append('<td>' + wt.setqty + '</td>')
  2080.                     .append('<td>セット</td>')
  2081.                     .append('<td>' + fmt.format(wt.unit_price_inc) + '円</td>')
  2082.                     .append('<td>' + fmt.format(wt.line_total_inc) + '円</td>');
  2083.                 $itemRow.before($tr);
  2084.             });
  2085.             // 元の商品名行は複数タイプに置換されたので非表示
  2086.             $itemRow.hide();
  2087.             // 補助金(割引額)行を末尾に追加
  2088.             if (subsidyAmt > 0) {
  2089.                 var $subRow = $('<tr class="wt-subsidy-row"></tr>')
  2090.                     .append('<td>補助金(割引額)</td>')
  2091.                     .append('<td>1</td>')
  2092.                     .append('<td>式</td>')
  2093.                     .append('<td>-' + fmt.format(subsidyAmt) + '円</td>')
  2094.                     .append('<td>-' + fmt.format(subsidyAmt) + '円</td>');
  2095.                 $tbody.append($subRow);
  2096.             }
  2097.         }
  2098.         // 公開: onWindowTypeAxisChange (UI 骨格 task 1) からも呼ばれる
  2099.         window.recalcAll = recalcAllForSaleType2;
  2100.         // 公開: ガラス選択肢が補助金対象か (窓タイプブロック生成時のバッジ判定に使う).
  2101.         // subtype は P→S に落とすことはあっても null にはしないため、性能区分の
  2102.         // 対象/対象外は subtype に依存しない。ここでは series/product 上限のみ適用し、
  2103.         // finalizeGlassGrade が null でなければ「補助金対象ガラス」と判定する。
  2104.         window.glassYieldsSubsidy = function(glassName) {
  2105.             if (!glassName) return false;
  2106.             return finalizeGlassGrade(detectGlassPerformance(glassName), '') !== null;
  2107.         };
  2108.         function mitsumori_simulation(type , value_id){
  2109.             // sale_type=2 (補助金窓) は複数タイプ集計 UI に統合済み. 既存 mitsumori_simulation は使わない.
  2110.             if (typeof SALE_TYPE_ID !== 'undefined' && SALE_TYPE_ID == 2) {
  2111.                 // type/value_id が op\d+ (施工オプション) の場合はグローバル変数を先に更新
  2112.                 if (type && /^op\d+$/.test(type) && value_id) {
  2113.                     var v = $('#'+value_id).val();
  2114.                     if (type === 'op0')  op0  = v;
  2115.                     if (type === 'op1')  op1  = v;
  2116.                     if (type === 'op2')  op2  = v;
  2117.                     if (type === 'op3')  op3  = v;
  2118.                     if (type === 'op4')  op4  = v;
  2119.                     if (type === 'op5')  op5  = v;
  2120.                     if (type === 'op6')  op6  = v;
  2121.                     if (type === 'op7')  op7  = v;
  2122.                     if (type === 'op8')  op8  = v;
  2123.                     if (type === 'op9')  op9  = v;
  2124.                     if (type === 'op10') op10 = v;
  2125.                 }
  2126.                 recalcAllForSaleType2();
  2127.                 return;
  2128.             }
  2129.             // 価格データ未登録 (pp 行 0 件) の商品は axis 入力に依存せず
  2130.             // 「価格データ準備中」を表示して終了する.
  2131.             // (例: scrape 未対象の新規商品 — um のウチリモ 7487/7488 等)
  2132.             if (!pp || pp.length === 0) {
  2133.                 $('#mitsumori_message').text("価格データ準備中");
  2134.                 $('#mitsumori_btn').hide();
  2135.                 $('#mitsumori_goukei').text("---円");
  2136.                 $('#mitsumori_off').text("---円");
  2137.                 $('#mitsumori_price').text("---円");
  2138.                 $('#maker_price').text("---円");
  2139.                 $('#mitsumori_ct').text("---円");
  2140.                 $('#mitsumori_option').text("---円");
  2141.                 $('#mitsumori_kei').text("---円");
  2142.                 $('#mitsumori_shoukei').text("---円");
  2143.                 $('#mitsumori_tax').text("---円");
  2144.                 return;
  2145.             }
  2146.             if(type == "pw"){
  2147.                 pw = $('#'+value_id).val();
  2148.             }
  2149.             if(type == "pd"){
  2150.                 pd = $('#'+value_id).val();
  2151.             }
  2152.             if(type == "ph"){
  2153.                 ph = $('#'+value_id).val();
  2154.             }
  2155.             if(type == "pm"){
  2156.                 pm = $('#'+value_id).val();
  2157.             }
  2158.             if(type == "pc"){
  2159.                 pc = $('#'+value_id).val();
  2160.             }
  2161.             if(type == "option1"){
  2162.                 option1 = $('#'+value_id).val();
  2163.             }
  2164.             if(type == "option2"){
  2165.                 option2 = $('#'+value_id).val();
  2166.             }
  2167.             if(type == "op0"){ op0 = $('#'+value_id).val(); }
  2168.             if(type == "op1"){ op1 = $('#'+value_id).val(); }
  2169.             if(type == "op2"){ op2 = $('#'+value_id).val(); }
  2170.             if(type == "op3"){ op3 = $('#'+value_id).val(); }
  2171.             if(type == "op4"){ op4 = $('#'+value_id).val(); }
  2172.             if(type == "op5"){ op5 = $('#'+value_id).val(); }
  2173.             if(type == "op6"){ op6 = $('#'+value_id).val(); }
  2174.             if(type == "op7"){ op7 = $('#'+value_id).val(); }
  2175.             if(type == "op8"){ op8 = $('#'+value_id).val(); }
  2176.             if(type == "op9"){ op9 = $('#'+value_id).val(); }
  2177.             if(type == "op10"){ op10 = $('#'+value_id).val(); }
  2178.             // op0 が「商品購入のみ」のとき、他のオプション (op1..op10) を disable 化.
  2179.             // 価格計算側 (calcGoukei の purchaseOnly 分岐) は既にゼロ化しているが、
  2180.             // UI で選択可能に見えるとユーザーが混乱するため radio を完全に無効化する.
  2181.             (function applyPurchaseOnlyUI() {
  2182.                 var isPurchaseOnly = (op0 === '商品購入のみ');
  2183.                 for (var k = 1; k <= 10; k++) {
  2184.                     var $inputs = $('input[name="op' + k + '"]');
  2185.                     if ($inputs.length === 0) continue;
  2186.                     $inputs.prop('disabled', isPurchaseOnly);
  2187.                     var $group = $inputs.first().closest('.form-group');
  2188.                     $group.css({
  2189.                         'opacity':        isPurchaseOnly ? '0.4'  : '1',
  2190.                         'pointer-events': isPurchaseOnly ? 'none' : 'auto'
  2191.                     });
  2192.                 }
  2193.             })();
  2194.             // 全 type 共通: 該当 radio を checked にし、ボタンの is-selected を付け替え + ラベル更新.
  2195.             //   value_id が指定されていて、対応する DOM 要素が opt-btn 配下にあれば適用する.
  2196.             //   (icheck-danger 形式から opt-btn 形式に統一した際、option1/option2/pw/pd/ph/pm/pc 等の
  2197.             //    クリックで is-selected が更新されない不具合があったため、op\d+ 限定の処理を一般化)
  2198.             if (value_id) {
  2199.                 var $clicked = $('#' + value_id);
  2200.                 if ($clicked.length && $clicked.closest('.opt-btn').length) {
  2201.                     $clicked.prop('checked', true);
  2202.                     var groupName = $clicked.attr('name');
  2203.                     $('input[name="' + groupName + '"]').closest('.opt-btn').removeClass('is-selected');
  2204.                     $clicked.closest('.opt-btn').addClass('is-selected');
  2205.                     var $group = $clicked.closest('.form-group');
  2206.                     var $label = $group.find('.rp-section-label');
  2207.                     if ($label.length) {
  2208.                         var labelText = $label.text().split(':')[0].trim();
  2209.                         $label.html(labelText + ': <span>' + $clicked.val() + '</span>');
  2210.                     }
  2211.                     // op_data の price=0 & 解体/撤去/設置場所 オプションの場合、ON 選択時に「現場調査後に正式お見積もり」文言を表示.
  2212.                     //   (twig 側で is_removal_unknown ブロックを描画済み。display 切替のみ JS で行う)
  2213.                     if (/^op\d+$/.test(type)) {
  2214.                         var opIdx = type.replace('op', '');
  2215.                         var opEntry = op_data[parseInt(opIdx)];
  2216.                         if (opEntry) {
  2217.                             var $note = $group.find('.opt-survey-note[data-op-idx="' + opIdx + '"]');
  2218.                             if ($note.length) {
  2219.                                 var isOn = ($clicked.val() === opEntry.on);
  2220.                                 $note.toggle(isOn);
  2221.                             }
  2222.                         }
  2223.                         // wd (sale_type=5) のステップ / デッキフェンス用の注記もここで切替.
  2224.                         //   ステップ → deck_step (op0 だが op_data 範囲外), 必要 選択時に表示.
  2225.                         var radioName = $clicked.attr('name');
  2226.                         if (radioName === 'deck_step') {
  2227.                             $group.find('.opt-survey-note-wd-step').toggle($clicked.val() === '必要');
  2228.                         } else if (radioName === 'deck_fence') {
  2229.                             $group.find('.opt-survey-note-wd-fence').toggle($clicked.val() === '必要');
  2230.                         }
  2231.                     }
  2232.                 }
  2233.             }
  2234.             // 必須項目チェックは sale_type 1 系(カーポート/物置/フェンスなど価格マトリクス必要)に限定
  2235.             var requireMatrix = (SALE_TYPE_ID == 1 || SALE_TYPE_ID == 2 || SALE_TYPE_ID == 3 || SALE_TYPE_ID == 4 || SALE_TYPE_ID == 5 || SALE_TYPE_ID == 6 || SALE_TYPE_ID == 7 || SALE_TYPE_ID == 9);
  2236.             // sale_type=3 (物置・ゴミステーション・照明 等) では「素材」を選択肢として扱わない.
  2237.             //   - mo/gs/sy は m が "指定なし" など名目的にしか入っていない
  2238.             //   - sl は m が空のままで matrix に行が来る
  2239.             //   そのため pm の必須チェックを sale_type=3 でスキップする。
  2240.             var pmRequired = (SALE_TYPE_ID != 3);
  2241.             if (requireMatrix) {
  2242.                 if(pmRequired && pm == ""){
  2243.                     $('#mitsumori_message').text("素材を選択してください");
  2244.                 }
  2245.                 if(ph == ""){
  2246.                     $('#mitsumori_message').text("高さを選択してください");
  2247.                 }
  2248.                 if(pd == ""){
  2249.                     $('#mitsumori_message').text("奥行きを選択してください");
  2250.                 }
  2251.                 if(pw == ""){
  2252.                     $('#mitsumori_message').text("幅を選択してください");
  2253.                 }
  2254.                 if(pc == ""){
  2255.                     $('#mitsumori_message').text("カラーを選択してください");
  2256.                     $('#mitsumori_btn').hide();
  2257.                     $('#mitsumori_goukei').text("---円");
  2258.                     $('#mitsumori_off').text("---円");
  2259.                     $('#mitsumori_price').text("---円");
  2260.                     $('#maker_price').text("---円");
  2261.                     $('#mitsumori_ct').text("---円");
  2262.                     $('#mitsumori_option').text("---円");
  2263.                 }
  2264.             }
  2265.             if(pw != "" && pd != "" && ph != "" && (!pmRequired || pm != "") && pc != ""){
  2266.                 $('#mitsumori_btn').show();
  2267.                 // 入力コンテキスト(sale_type 別パラメータ)
  2268.                 var ctx = {
  2269.                     set_count:    parseInt($('#set_count').val())    || 1,
  2270.                     daisu:        parseInt($('#daisu').val())        || 1,
  2271.                     maisu:        parseInt($('#maisu').val())        || 3,
  2272.                     suuryou:      parseInt($('#suuryou').val())      || 1,
  2273.                     area:         (function(){
  2274.                         // tf(人工芝): 施工サイズ 縦(m)×横(m) から面積を算出し #area に反映.
  2275.                         var L = parseFloat($('#tf_len').val()) || 0;
  2276.                         var W = parseFloat($('#tf_wid').val()) || 0;
  2277.                         if (L > 0 && W > 0) { var a = L * W; $('#area').val(a); return a; }
  2278.                         return parseFloat($('#area').val()) || 0;
  2279.                     })(),
  2280.                     tf_len:       parseFloat($('#tf_len').val())     || 0,
  2281.                     tf_wid:       parseFloat($('#tf_wid').val())     || 0,
  2282.                     tf_qty:       parseInt($('#tf_qty').val())       || 1,
  2283.                     quantityOnly: parseInt($('#quantity_only').val())|| 1,
  2284.                     mado_w:       $('#mado_w').val() || '',
  2285.                     mado_h:       $('#mado_h').val() || '',
  2286.                     mado_type:    $('input[name=mado_type]:checked').val()  || '',
  2287.                     glass_type:   $('input[name=glass_type]:checked').val() || '',
  2288.                     deck_step:    $('input[name=deck_step]:checked').val()  || '',
  2289.                     deck_fence:   $('input[name=deck_fence]:checked').val() || '',
  2290.                 };
  2291.                 // 施工オプション集計(残土処理を含む)
  2292.                 var opCalc = collectOptions();
  2293.                 var pp_matched = false;
  2294.                 // 各軸の汎用 axisMatch:
  2295.                 //   user 選択 == matrix 値 / user "指定なし" / matrix 値が空
  2296.                 var axisMatch = function(input, value){
  2297.                     return input == value || input == "指定なし" || value === "" || value == null;
  2298.                 };
  2299.                 // 色専用マッチャー: scraper のデータ形式に合わせて拡張する
  2300.                 //   1. 完全一致 / "指定なし" / 値が空 → 真 (axisMatch と同じ)
  2301.                 //   2. matrix 値が "色1/色2/色3" の形 (同価格グループ) → split して user 選択が含まれれば真
  2302.                 // scraper のロジック (scraper_price.py L765-779):
  2303.                 //   全色同価格 → c=""、価格違いグループあり → 各 group を "/" 結合した色名で 1 行
  2304.                 var colorMatch = function(input, value){
  2305.                     if (axisMatch(input, value)) return true;
  2306.                     if (typeof value === 'string' && value.indexOf('/') !== -1 && input) {
  2307.                         var parts = value.split('/');
  2308.                         for (var idx = 0; idx < parts.length; idx++) {
  2309.                             if (parts[idx].trim() === input) return true;
  2310.                         }
  2311.                     }
  2312.                     return false;
  2313.                 };
  2314.                 // 他軸 (w/d/h/m + option1/option2) でマッチする pp 行を抽出.
  2315.                 // option1/option2 は um の subtype 等で使われる. axisMatch は free_area 側が
  2316.                 // 空のとき真を返すので、um 以外のカテゴリ (option 軸を使わない) でも影響なし.
  2317.                 var candidates = pp.filter(function(el){
  2318.                     return axisMatch(pw, el.w) && axisMatch(pd, el.d) && axisMatch(ph, el.h) && axisMatch(pm, el.m)
  2319.                         && axisMatch(option1, el.option1) && axisMatch(option2, el.option2);
  2320.                 });
  2321.                 // フォールバック: 全軸一致が 0 件のときに限り option1/option2 を無視して再マッチ。
  2322.                 // 玄関ドア等で option1(なし/ランマ付き)・option2(◯◯タイプ) が pm(開き方) から
  2323.                 // 導出可能な冗長軸で、未選択だと全軸 AND 一致を満たせず価格が出ない事象の救済。
  2324.                 // pm/幅/奥行/高さ は従来どおり一致を要求するため通常商品の価格選択に影響しない。
  2325.                 if (candidates.length === 0) {
  2326.                     candidates = pp.filter(function(el){
  2327.                         return axisMatch(pw, el.w) && axisMatch(pd, el.d) && axisMatch(ph, el.h) && axisMatch(pm, el.m);
  2328.                     });
  2329.                 }
  2330.                 var picked = null;
  2331.                 // 優先 1: 色も含めて完全一致 ("色1/色2" 形式の split match を含む)
  2332.                 for (var ii = 0; ii < candidates.length; ii++) {
  2333.                     if (colorMatch(pc, candidates[ii].c)) { picked = candidates[ii]; break; }
  2334.                 }
  2335.                 // 優先 2: 完全一致なし & user の pc が候補のどの c 値にも該当しない (= 命名違い等)
  2336.                 //   かつ候補全行で price が一致する場合は、色軸を実質無視して先頭行を採用.
  2337.                 //   例 id=3353: pp.c は "ステンカラー+..." 6種だが price は全て同じなので
  2338.                 //     SM(スミ) を選んでも安全に最初の行の価格を返せる.
  2339.                 if (!picked && candidates.length > 0) {
  2340.                     var ppCsInCand = candidates.map(function(r){ return r.c || ''; });
  2341.                     var pcAbsent = (pc !== '' && pc !== '指定なし' && ppCsInCand.indexOf(pc) === -1
  2342.                                     && ppCsInCand.every(function(v){ return v.indexOf('/') === -1 || v.split('/').map(function(s){return s.trim();}).indexOf(pc) === -1; }));
  2343.                     if (pcAbsent) {
  2344.                         var uniqPrices = new Set();
  2345.                         candidates.forEach(function(r){ uniqPrices.add(String(r.price)); });
  2346.                         if (uniqPrices.size === 1) {
  2347.                             // 全候補同価格 → 色軸を wildcard 扱いで OK
  2348.                             picked = candidates[0];
  2349.                         }
  2350.                         // 価格が異なる場合は意図的に picked=null のまま「対応しておりません」.
  2351.                     }
  2352.                 }
  2353.                 pp.forEach((el) => {
  2354.                   if (el === picked) {
  2355.                     pp_matched = true;
  2356.                     // tg block-keyed オプション差額を集計 (tg 以外は total=0)
  2357.                     var oiCalc = collectOptionItems(el.w || '', el.d || '');
  2358.                     // tg ブロックに合わせてラジオを再描画 (tg 以外は no-op)
  2359.                     renderOptionItemRadios(el.w || '', el.d || '');
  2360.                     // fe ブロックの種類×段数 サブ radio (fe 以外/未設定は no-op)
  2361.                     renderFeBlockRadios();
  2362.                     // fe ご希望のフェンス設置方法 — 「既存ブロックに穴空け」 entry の連動表示
  2363.                     updateFeOpConditionalVisibility();
  2364.                     var calc       = calcGoukei(el, opCalc.total, ctx);
  2365.                     var goukei     = calc.goukei;
  2366.                     var price      = calc.price;
  2367.                     var ct         = calc.ct;
  2368.                     var optionSum  = calc.opt;
  2369.                     // tf(人工芝): 必要枚数入力へ算出結果を反映(施工サイズ入力時は上書き、
  2370.                     // 直接指定時は同値なので実質変化なし。要素が無い sale_type では no-op)
  2371.                     var $tfQty = $('#tf_qty');
  2372.                     if ($tfQty.length) $tfQty.val(calc.qty || 1);
  2373.                     // オプション差額は税抜 → 税込に変換して合計に加算
  2374.                     var oiIncTax   = toIncTax(oiCalc.total);
  2375.                     goukei += oiIncTax;
  2376.                     price  += oiIncTax;  // 差額は本体価格扱いとして mitsumori_price にも加算
  2377.                     // maker_price も scraper が税抜で保存しているため税込に変換
  2378.                 var makerPrice = toIncTax(parseInt(el.maker_price) || 0);
  2379.                     $('#mitsumori_message').text(formatter.format(goukei) + "円");
  2380.                     $('#mitsumori_goukei').text(formatter.format(goukei) + "円");
  2381.                     $('#mitsumori_off').text(formatter.format(price - makerPrice) + "円");
  2382.                     $('#mitsumori_price').text(formatter.format(price) + "円");
  2383.                     $('#maker_price').text(formatter.format(makerPrice) + "円");
  2384.                     $('#mitsumori_ct').text(formatter.format(ct) + "円");
  2385.                     $('#mitsumori_option').text(formatter.format(optionSum) + "円");
  2386.                     $('#mitsumori_kei').text(formatter.format(goukei) + "円");
  2387.                     $('#mitsumori_price_01').text(formatter.format(price) + "円");
  2388.                     $('#mitsumori_price_02').text(formatter.format(price) + "円");
  2389.                     $('#mitsumori_ct_01').text(formatter.format(ct) + "円");
  2390.                     $('#mitsumori_ct_02').text(formatter.format(ct) + "円");
  2391.                     $('#mitsumori_goukei_02').text(formatter.format(goukei) + "円");
  2392.                     var shoukei = goukei / 1.1;
  2393.                     var tax     = parseInt(goukei - shoukei);
  2394.                     $('#mitsumori_shoukei').text(formatter.format(parseInt(shoukei)) + "円");
  2395.                     $('#mitsumori_tax').text(formatter.format(tax) + "円");
  2396.                     // PDF 明細用:オプション内訳テーブルを差し込む (施工オプション + tg block オプション)
  2397.                     renderOptionDetailRows(opCalc.items.concat(oiCalc.items.map(function(it){
  2398.                         return { name: it.name, value: it.label, price: it.diff };
  2399.                     })));
  2400.                   }
  2401.                 });
  2402.                 if (!pp_matched) {
  2403.                     $('#mitsumori_message').text("この組み合わせは対応しておりません");
  2404.                     $('#mitsumori_btn').hide();
  2405.                     $('#mitsumori_goukei').text("---円");
  2406.                     $('#mitsumori_off').text("---円");
  2407.                     $('#mitsumori_price').text("---円");
  2408.                     $('#maker_price').text("---円");
  2409.                     $('#mitsumori_ct').text("---円");
  2410.                     $('#mitsumori_option').text("---円");
  2411.                     $('#mitsumori_kei').text("---円");
  2412.                     $('#mitsumori_shoukei').text("---円");
  2413.                     $('#mitsumori_tax').text("---円");
  2414.                 }
  2415.                 // mitsumori_json: バック側に送信する見積データ
  2416.                 var mitsumori_json = { "mitsumori_goukei": $('#mitsumori_goukei').text(),
  2417.                                         "mitsumori_goukei_02": $('#mitsumori_goukei_02').text(),
  2418.                                         "mitsumori_price": $('#mitsumori_price').text(),
  2419.                                         "maker_price": $('#maker_price').text(),
  2420.                                         "mitsumori_off": $('#mitsumori_off').text(),
  2421.                                         "mitsumori_ct": $('#mitsumori_ct').text(),
  2422.                                         "mitsumori_option": $('#mitsumori_option').text(),
  2423.                                         "product_id": {{ Product.id }},
  2424.                                         "sale_type": SALE_TYPE_ID,
  2425.                                         "pw": pw,
  2426.                                         "pd": pd,
  2427.                                         "ph": ph,
  2428.                                         "pm": pm,
  2429.                                         "pc": pc,
  2430.                                         "op": [op0,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10],
  2431.                                         "op_items": opCalc.items,
  2432.                                         "mado_w":     ctx.mado_w,
  2433.                                         "mado_h":     ctx.mado_h,
  2434.                                         "mado_type":  ctx.mado_type,
  2435.                                         "glass_type": ctx.glass_type,
  2436.                                         "set_count":  ctx.set_count,
  2437.                                         "daisu":      ctx.daisu,
  2438.                                         "maisu":      ctx.maisu,
  2439.                                         "suuryou":    ctx.suuryou,
  2440.                                         "area":       ctx.area,
  2441.                                         "tf_len":     ctx.tf_len,
  2442.                                         "tf_wid":     ctx.tf_wid,
  2443.                                         "tf_qty":     $('#tf_qty').val(),
  2444.                                         "deck_step":  ctx.deck_step,
  2445.                                         "deck_fence": ctx.deck_fence };
  2446.                 $('#mitsumori_json').val(JSON.stringify(mitsumori_json));
  2447.             }
  2448.         }
  2449.         // PDF/モーダル明細の動的差し替え(基本工事費の次にオプション行を追加)
  2450.         function renderOptionDetailRows(items) {
  2451.             var $tbody = $('.modal-mitsumori table tbody');
  2452.             if (!$tbody.length) return;
  2453.             $tbody.find('tr.opt-row').remove();
  2454.             var anchorRow = $tbody.find('tr').filter(function(){
  2455.                 return $(this).find('td:first').text().indexOf('残土') !== -1
  2456.                     || $(this).find('td:first').text().indexOf('基本工事費') !== -1;
  2457.             }).last();
  2458.             items.forEach(function(it){
  2459.                 if (!it.name || !it.value) return;
  2460.                 var priceTxt = it.price > 0
  2461.                     ? formatter.format(it.price) + '円'
  2462.                     : '0円';
  2463.                 var $tr = $('<tr class="opt-row"></tr>')
  2464.                     .append('<td>' + it.name + ':' + it.value + '</td>')
  2465.                     .append('<td>1</td>')
  2466.                     .append('<td>式</td>')
  2467.                     .append('<td>' + priceTxt + '</td>')
  2468.                     .append('<td>' + (it.price > 0 ? formatter.format(it.price) + '円' : '') + '</td>');
  2469.                 if (anchorRow.length) {
  2470.                     anchorRow.after($tr);
  2471.                     anchorRow = $tr;
  2472.                 } else {
  2473.                     $tbody.append($tr);
  2474.                 }
  2475.             });
  2476.         }
  2477.         // 見積書モーダルを開く直前に、右側「現在のお見積り額」パネルの表示値を
  2478.         // モーダル内の対応 ID にコピーして金額の食い違いを防ぐ。
  2479.         // pw/pd/ph/pm が未選択で mitsumori_simulation の full update に到達しない場合でも、
  2480.         // パネル側の値(HTML 静的初期値 or 直近の simulation 結果)が modal にも反映される。
  2481.         function syncMitsumoriModalFromPanel() {
  2482.             var goukeiText = $('#mitsumori_goukei').text();
  2483.             var priceText  = $('#mitsumori_price').text();
  2484.             var ctText     = $('#mitsumori_ct').text();
  2485.             $('#mitsumori_kei').text(goukeiText);
  2486.             $('#mitsumori_price_01').text(priceText);
  2487.             $('#mitsumori_price_02').text(priceText);
  2488.             $('#mitsumori_ct_01').text(ctText);
  2489.             $('#mitsumori_ct_02').text(ctText);
  2490.             $('#mitsumori_goukei_02').text(goukeiText);
  2491.             // 小計 / 消費税 は税込 goukei から逆算
  2492.             var num = parseInt(goukeiText.replace(/[^\d-]/g, ''), 10);
  2493.             if (!isNaN(num) && num > 0) {
  2494.                 var shoukei = Math.round(num / 1.1);
  2495.                 var tax     = num - shoukei;
  2496.                 $('#mitsumori_shoukei').text(formatter.format(shoukei) + '円');
  2497.                 $('#mitsumori_tax').text(formatter.format(tax) + '円');
  2498.             } else {
  2499.                 $('#mitsumori_shoukei').text('---円');
  2500.                 $('#mitsumori_tax').text('---円');
  2501.             }
  2502.         }
  2503.         $(document).on('show.bs.modal', '#modal-mitsumori', function () {
  2504.             syncMitsumoriModalFromPanel();
  2505.         });
  2506.         {# pc の auto-init: pw/pd/ph/pm と同じく p_c(matrix 派生)の length==1 or 全空で「指定なし」化.
  2507.            search_word(color) が空の「複合色」型商品で pc が空のまま放置されて
  2508.            「カラーを選択してください」固定になるバグの修正.
  2509.            search_word に登録された name があれば優先採用. #}
  2510.         {% if p_c and (p_c|length == 1 or p_c|join == "") %}
  2511.             pc = "指定なし";
  2512.             {% for pc_val in p_c %}{% if pc_val %} pc = "{{ pc_val }}"; {% endif %}{% endfor %}
  2513.             {% if color and color|length == 1 %}
  2514.                 {% for cc in color %}{% if cc and cc['name'] %} pc = "{{ cc['name'] }}"; {% endif %}{% endfor %}
  2515.             {% endif %}
  2516.         {% elseif color and color|length == 1 %}
  2517.             pc = "指定なし";
  2518.             {% for cc in color %}{% if cc and cc['name'] %} pc = "{{ cc['name'] }}"; {% endif %}{% endfor %}
  2519.         {% endif %}
  2520.         {% if p_w and (p_w|length == 1 or p_w|join == "") %}
  2521.             pw = "指定なし";
  2522.             {% for pw in p_w %}{% if pw %} pw = "{{ pw }}"; {% endif %}{% endfor %}
  2523.         {% endif %}
  2524.         {% if p_d and (p_d|length == 1 or p_d|join == "") %}
  2525.             pd = "指定なし";
  2526.             {% for pd in p_d %}{% if pd %} pd = "{{ pd }}"; {% endif %}{% endfor %}
  2527.         {% endif %}
  2528.         {% if p_h and (p_h|length == 1 or p_h|join == "") %}
  2529.             ph = "指定なし";
  2530.             {% for ph in p_h %}{% if ph %} ph = "{{ ph }}"; {% endif %}{% endfor %}
  2531.         {% endif %}
  2532.         {% if p_m and (p_m|length == 1 or p_m|join == "") %}
  2533.             pm = "指定なし";
  2534.             {% for pm in p_m %}{% if pm %} pm = "{{ pm }}"; {% endif %}{% endfor %}
  2535.         {% endif %}
  2536.         {# p_option1 / p_option2 の auto-init: length==1 or 全空で JS 変数を埋める #}
  2537.         {% if p_option1 and (p_option1|length == 1 or p_option1|join == "") %}
  2538.             option1 = "";
  2539.             {% for opt1 in p_option1 %}{% if opt1 %} option1 = "{{ opt1|e('js') }}"; {% endif %}{% endfor %}
  2540.         {% endif %}
  2541.         {% if p_option2 and (p_option2|length == 1 or p_option2|join == "") %}
  2542.             option2 = "";
  2543.             {% for opt2 in p_option2 %}{% if opt2 %} option2 = "{{ opt2|e('js') }}"; {% endif %}{% endfor %}
  2544.         {% endif %}
  2545.         // カラー radio が複数あるとき初期チェックが無いと「カラーを選択してください」固定になるので、
  2546.         // 何もチェックされていなければ「最初の radio」を選択する。
  2547.         // sale_type≠3 は name="color", sale_type=3 は name="color3".
  2548.         //
  2549.         // 注意:
  2550.         //   ・search_word(= radio の値)と pp.c(= matrix の色軸)は別の命名体系のケースがある
  2551.         //     (例 id=3353: radio="SM(スミ)" / pp.c="ステンカラー+セピアブラウン")
  2552.         //   ・pp.c に合わせて radio を選ぼうとしても文字列一致しないので無意味。
  2553.         //   ・単純に「先頭の radio」を選ぶ実装に戻し、マッチング側で命名体系違いを吸収する
  2554.         //     (pc が pp.c のどの値にもマッチしないときは色軸を wildcard 扱いにする)。
  2555.         //   ・.rp-section-label のテキストも忘れずに同期する(古い session 値が残ると
  2556.         //     "ステンカラー+セピアブラウン" のような表示と実際の radio が食い違う)。
  2557.         (function autoSelectFirstColor(){
  2558.             var groups = ['color', 'color3'];
  2559.             for (var gi = 0; gi < groups.length; gi++) {
  2560.                 var name = groups[gi];
  2561.                 var nodes = document.querySelectorAll('input[type="radio"][name="' + name + '"]');
  2562.                 if (nodes.length === 0) continue;
  2563.                 var anyChecked = false;
  2564.                 for (var i = 0; i < nodes.length; i++) {
  2565.                     if (nodes[i].checked) { anyChecked = true; break; }
  2566.                 }
  2567.                 if (anyChecked) continue;
  2568.                 var target = nodes[0];
  2569.                 target.checked = true;
  2570.                 pc = target.value;
  2571.                 // opt-btn の is-selected を付け替え
  2572.                 var lbl = target.closest('.opt-btn');
  2573.                 if (lbl) {
  2574.                     var sib = lbl.parentNode ? lbl.parentNode.querySelectorAll('.opt-btn') : [];
  2575.                     for (var k = 0; k < sib.length; k++) sib[k].classList.remove('is-selected');
  2576.                     lbl.classList.add('is-selected');
  2577.                 }
  2578.                 // 「カラー: <name>」表示の同期(古い mitsumori_json.pc が残らないように)
  2579.                 var grp = (lbl && lbl.closest('.form-group')) || (target.closest('.form-group'));
  2580.                 if (grp) {
  2581.                     var section = grp.querySelector('.rp-section-label');
  2582.                     if (section) {
  2583.                         var labelHead = section.textContent.split(':')[0].trim();
  2584.                         section.innerHTML = labelHead + ': <span>' + target.value + '</span>';
  2585.                     }
  2586.                 }
  2587.             }
  2588.         })();
  2589.         // option1 / option2 / pw / pd / ph / pm (matrix 軸の radio 群) も同様に
  2590.         // 「どれもチェックされていなければ先頭を選ぶ」を適用する.
  2591.         //   sale_type=2 の窓タイプ等で「初期表示時に一番初めの選択肢が選択されていない」事象を解消.
  2592.         (function autoSelectFirstMatrixAxis(){
  2593.             var axes = [
  2594.                 { name: 'pw',      jsVar: 'pw' },
  2595.                 { name: 'pd',      jsVar: 'pd' },
  2596.                 { name: 'ph',      jsVar: 'ph' },
  2597.                 { name: 'pm',      jsVar: 'pm' },
  2598.                 { name: 'glass_type', jsVar: 'pm' },
  2599.                 { name: 'option1', jsVar: 'option1' },
  2600.                 { name: 'option2', jsVar: 'option2' }
  2601.             ];
  2602.             for (var ai = 0; ai < axes.length; ai++) {
  2603.                 var ax = axes[ai];
  2604.                 var nodes = document.querySelectorAll('input[type="radio"][name="' + ax.name + '"]');
  2605.                 if (nodes.length === 0) continue;
  2606.                 var anyChecked = false;
  2607.                 for (var i = 0; i < nodes.length; i++) {
  2608.                     if (nodes[i].checked) { anyChecked = true; break; }
  2609.                 }
  2610.                 if (anyChecked) continue;
  2611.                 var target = nodes[0];
  2612.                 target.checked = true;
  2613.                 // グローバル JS 変数も埋める
  2614.                 if (ax.jsVar === 'pw') pw = target.value;
  2615.                 else if (ax.jsVar === 'pd') pd = target.value;
  2616.                 else if (ax.jsVar === 'ph') ph = target.value;
  2617.                 else if (ax.jsVar === 'pm') pm = target.value;
  2618.                 else if (ax.jsVar === 'option1') option1 = target.value;
  2619.                 else if (ax.jsVar === 'option2') option2 = target.value;
  2620.                 var lbl = target.closest('.opt-btn');
  2621.                 if (lbl) {
  2622.                     var sib = lbl.parentNode ? lbl.parentNode.querySelectorAll('.opt-btn') : [];
  2623.                     for (var k = 0; k < sib.length; k++) sib[k].classList.remove('is-selected');
  2624.                     lbl.classList.add('is-selected');
  2625.                 }
  2626.                 var grp = (lbl && lbl.closest('.form-group')) || (target.closest('.form-group'));
  2627.                 if (grp) {
  2628.                     var section = grp.querySelector('.rp-section-label');
  2629.                     if (section) {
  2630.                         var labelHead = section.textContent.split(':')[0].trim();
  2631.                         section.innerHTML = labelHead + ': <span>' + target.value + '</span>';
  2632.                     }
  2633.                 }
  2634.             }
  2635.         })();
  2636.         // 取付/設置工事トグル(off 値が「商品購入のみ」のオプション)は、新規アクセス時に
  2637.         // どちらの radio も未チェックのため初期価格が「商品購入のみ」= 基本工事費抜きになる。
  2638.         // 顧客要望(#10)に合わせ、未選択時は「工事も希望する」(on 側) を初期選択し、
  2639.         // 初期表示を基本工事費込みの最安値に統一する(色・寸法軸の先頭自動選択と同型)。
  2640.         //   ・判定キーは calcGoukei / applyPurchaseOnlyUI と同じ定数「商品購入のみ」。
  2641.         //   ・別用途で op{n} を流用する商品(ウッドデッキ deck_step 等)は radio 値に
  2642.         //     「商品購入のみ」を含まないため対象外(既存挙動を壊さない)。
  2643.         //   ・mitsumori_json 復元やユーザー操作で既に選択済みなら尊重する。
  2644.         (function autoSelectFirstInstall(){
  2645.             for (var i = 0; i <= 10; i++) {
  2646.                 var nodes = document.querySelectorAll('input[type="radio"][name="op' + i + '"]');
  2647.                 if (nodes.length === 0) continue;
  2648.                 // このグループが「商品購入のみ」を off に持つ工事トグルか判定し、
  2649.                 // 「商品購入のみ」でない側 (= 工事希望 on) を取得する。
  2650.                 var hasPurchaseOnly = false;
  2651.                 var onNode = null;
  2652.                 for (var j = 0; j < nodes.length; j++) {
  2653.                     if (nodes[j].value === '商品購入のみ') hasPurchaseOnly = true;
  2654.                     else if (!onNode) onNode = nodes[j];
  2655.                 }
  2656.                 if (!hasPurchaseOnly || !onNode) continue;
  2657.                 var anyChecked = false;
  2658.                 for (var k = 0; k < nodes.length; k++) {
  2659.                     if (nodes[k].checked) { anyChecked = true; break; }
  2660.                 }
  2661.                 if (anyChecked) continue;
  2662.                 onNode.checked = true;
  2663.                 // グローバル op 変数を on 値で埋める(calcGoukei の purchaseOnly 判定が参照)
  2664.                 switch (i) {
  2665.                     case 0:  op0  = onNode.value; break;
  2666.                     case 1:  op1  = onNode.value; break;
  2667.                     case 2:  op2  = onNode.value; break;
  2668.                     case 3:  op3  = onNode.value; break;
  2669.                     case 4:  op4  = onNode.value; break;
  2670.                     case 5:  op5  = onNode.value; break;
  2671.                     case 6:  op6  = onNode.value; break;
  2672.                     case 7:  op7  = onNode.value; break;
  2673.                     case 8:  op8  = onNode.value; break;
  2674.                     case 9:  op9  = onNode.value; break;
  2675.                     case 10: op10 = onNode.value; break;
  2676.                 }
  2677.                 // opt-btn の is-selected を付け替え
  2678.                 var lbl = onNode.closest('.opt-btn');
  2679.                 if (lbl) {
  2680.                     var sib = lbl.parentNode ? lbl.parentNode.querySelectorAll('.opt-btn') : [];
  2681.                     for (var s = 0; s < sib.length; s++) sib[s].classList.remove('is-selected');
  2682.                     lbl.classList.add('is-selected');
  2683.                 }
  2684.                 // rp-section-label 表示同期 + 現地調査文言(is_removal_unknown / is_tf_kouji)を on 表示に
  2685.                 var grp = (lbl && lbl.closest('.form-group')) || onNode.closest('.form-group');
  2686.                 if (grp) {
  2687.                     var section = grp.querySelector('.rp-section-label');
  2688.                     if (section) {
  2689.                         var labelHead = section.textContent.split(':')[0].trim();
  2690.                         section.innerHTML = labelHead + ': <span>' + onNode.value + '</span>';
  2691.                     }
  2692.                     var note = grp.querySelector('.opt-survey-note[data-op-idx="' + i + '"]');
  2693.                     if (note) note.style.display = '';
  2694.                 }
  2695.             }
  2696.         })();
  2697.         // ページ読み込み時: 見積金額が「合計」になっているため、カート数量は基本1
  2698.         // sale_type=9(商品のみ購入)だけ通常 EC として数量を引き継ぐ
  2699.         (function initQuantityByType(){
  2700.             var saleType = {{ ProductClass.SaleType.id }};
  2701.             if (saleType == 9 && $('#quantity_only').length) {
  2702.                 $('#quantity').val(parseInt($('#quantity_only').val()) || 1);
  2703.             } else {
  2704.                 $('#quantity').val(1);
  2705.                 $('input[name="quantity"]').val(1);
  2706.             }
  2707.         })();
  2708.         // type → ラベルのプレフィックス文字列
  2709.         // option1/option2 のラベルは category 依存 (rd: ランマ/タイプ, sh: サイズプリセット/駆動方式 等).
  2710.         // PHP から渡された option1_label / option2_label を埋め込み、JS 側でラベル更新に使う.
  2711.         var optLabelMap = {pc:'カラー', pw:'幅', pd:'奥行き', ph:'高さ', pm:'素材',
  2712.                            option1: '{{ option1_label|default('オプション1')|e('js') }}',
  2713.                            option2: '{{ option2_label|default('オプション2')|e('js') }}'};
  2714.         // type → input[name]
  2715.         var optNameMap  = {pc:'color', pw:'pw', pd:'pd', ph:'ph', pm:'pm',
  2716.                            option1: 'option1', option2: 'option2'};
  2717.         // opt-btn用: 値を直接受け取るラッパー
  2718.         function mitsumori_simulation_val(type, value) {
  2719.             if (type === 'pc') pc = value;
  2720.             if (type === 'pw') pw = value;
  2721.             if (type === 'pd') pd = value;
  2722.             if (type === 'ph') ph = value;
  2723.             if (type === 'pm') pm = value;
  2724.             if (type === 'option1') option1 = value;
  2725.             if (type === 'option2') option2 = value;
  2726.             // is-selected クラスを同グループ内で付け替え
  2727.             var inputName = optNameMap[type];
  2728.             if (inputName) {
  2729.                 var $btns = $('input[name="' + inputName + '"]').closest('.opt-btn');
  2730.                 $btns.removeClass('is-selected');
  2731.                 $btns.filter(function(){
  2732.                     return $(this).find('input').val() === value;
  2733.                 }).addClass('is-selected');
  2734.             }
  2735.             // ラベル行の選択値テキストを更新(例: 「カラー: ブラック」)
  2736.             var labelPrefix = optLabelMap[type];
  2737.             if (labelPrefix) {
  2738.                 // 対象のrp-section-labelを特定(input[name]を含む親を遡る)
  2739.                 var $group = $('input[name="' + inputName + '"]').first().closest('.form-group');
  2740.                 var $label = $group.find('.rp-section-label');
  2741.                 $label.html(labelPrefix + ': <span>' + value + '</span>');
  2742.             }
  2743.             // simulation本体を呼ぶ(value_idは空でOK、グローバル変数を使う)
  2744.             mitsumori_simulation('', '');
  2745.         }
  2746.         mitsumori_simulation("","");
  2747.         // ボタン群: 親幅を超える、または3行以上になる場合は is-scroll を付与し
  2748.         // 縦3段グリッド+横スクロール表示にする(顧客要望「3列くらいで横スクロール」)
  2749.         function applyBtnGroupScroll() {
  2750.             $('.rp-btn-group, .opt-btn-group').each(function() {
  2751.                 var $group = $(this);
  2752.                 $group.removeClass('is-scroll');
  2753.                 var $items = $group.children();
  2754.                 if ($items.length === 0) return;
  2755.                 var parentWidth = $group.parent().width() || $group.width();
  2756.                 var totalWidth = 0;
  2757.                 var gap = parseInt($group.css('gap'), 10) || 8;
  2758.                 $items.each(function() {
  2759.                     totalWidth += this.offsetWidth + gap;
  2760.                 });
  2761.                 // 単一ボタンが親幅を超える、もしくは合計幅が親幅を超える → 横スクロール化
  2762.                 var anyTooWide = false;
  2763.                 $items.each(function() {
  2764.                     if (this.offsetWidth > parentWidth) { anyTooWide = true; return false; }
  2765.                 });
  2766.                 // 折り返し時の行数も計測
  2767.                 var tops = {};
  2768.                 $items.each(function() { tops[this.offsetTop] = true; });
  2769.                 var rowCount = Object.keys(tops).length;
  2770.                 if (anyTooWide || totalWidth > parentWidth * 2 || rowCount >= 3) {
  2771.                     $group.addClass('is-scroll');
  2772.                 }
  2773.             });
  2774.         }
  2775.         applyBtnGroupScroll();
  2776.         $(window).on('resize', function() {
  2777.             clearTimeout(window._btnScrollTimer);
  2778.             window._btnScrollTimer = setTimeout(applyBtnGroupScroll, 150);
  2779.         });
  2780.         // onload: 見積金額が確定している場合は「工事費込み価格」表示を一致させる
  2781.         (function syncPrice02Display() {
  2782.             var goukeiEl = document.getElementById('mitsumori_goukei');
  2783.             var displayEl = document.getElementById('price02-display');
  2784.             if (!goukeiEl || !displayEl) return;
  2785.             var goukeiText = goukeiEl.textContent.trim();
  2786.             // ---円(未確定)の場合は書き換えない
  2787.             if (goukeiText && goukeiText !== '---円') {
  2788.                 displayEl.textContent = goukeiText;
  2789.             }
  2790.             // 以降の変更にも追従: mitsumori_goukei を監視
  2791.             new MutationObserver(function() {
  2792.                 var text = goukeiEl.textContent.trim();
  2793.                 if (text && text !== '---円') {
  2794.                     displayEl.textContent = text;
  2795.                 }
  2796.             }).observe(goukeiEl, { childList: true, subtree: true, characterData: true });
  2797.         })();
  2798.         function contact_form(product_id){
  2799.             $('#form1').attr('action', '{{ url('contact', {product:Product.id}) }}');
  2800.             $('#form1').submit();
  2801.         }
  2802.         // maisu / madoset は下部の新しい関数定義を使用
  2803.         function heibei(bei){
  2804.             $('#heibei').val(parseInt($('#heibei').val()) + bei);
  2805.             if(parseInt($('#heibei').val()) < 1){ $('#heibei').val(1); }
  2806.             if(parseInt($('#heibei').val()) > 100){ $('#heibei').val(100); }
  2807.             // goukei に既に枚数を含むため、カート数量は1で固定
  2808.             $('#quantity').val(1);
  2809.             mitsumori_simulation('heibei','heibei');
  2810.         }
  2811.         function daisu(dai){
  2812.             $('#daisu').val(parseInt($('#daisu').val()) + dai);
  2813.             if(parseInt($('#daisu').val()) < 1){ $('#daisu').val(1); }
  2814.             if(parseInt($('#daisu').val()) > 10){ $('#daisu').val(10); }
  2815.             $('#quantity').val(1);
  2816.             mitsumori_simulation('daisu','daisu');
  2817.         }
  2818.         // sale_type=7(数量買い・基本工事費固定)用:個数入力
  2819.         function suuryou(n){
  2820.             $('#suuryou').val(parseInt($('#suuryou').val()) + n);
  2821.             if(parseInt($('#suuryou').val()) < 1){ $('#suuryou').val(1); }
  2822.             if(parseInt($('#suuryou').val()) > 100){ $('#suuryou').val(100); }
  2823.             $('#quantity').val(1);
  2824.             mitsumori_simulation('suuryou','suuryou');
  2825.         }
  2826.         function maisu(mai){
  2827.             $('#maisu').val(parseInt($('#maisu').val()) + mai);
  2828.             // sale_type=4 (フェンス) は3枚未満不可、6 (芝生) は1枚から
  2829.             var minMai = (SALE_TYPE_ID == 4) ? 3 : 1;
  2830.             if(parseInt($('#maisu').val()) < minMai){ $('#maisu').val(minMai); }
  2831.             if(parseInt($('#maisu').val()) > 100){ $('#maisu').val(100); }
  2832.             $('#quantity').val(1);
  2833.             mitsumori_simulation('maisu','maisu');
  2834.         }
  2835.         // タイプ2: セット数プルダウン連動
  2836.         function madosetSelect(val){
  2837.             var v = parseInt(val);
  2838.             if(v < 1) v = 1;
  2839.             if(v > 20) v = 20;
  2840.             $('#set_count').val(v);
  2841.             $('#quantity').val(1);
  2842.             $('input[name="quantity"]').val(1);
  2843.             mitsumori_simulation('set','set_count');
  2844.         }
  2845.         // タイプ2: ±ボタン版(後方互換)
  2846.         function madoset(mai){
  2847.             var current = parseInt($('#set_count').val()) || 1;
  2848.             var next = current + mai;
  2849.             if(next < 1) next = 1;
  2850.             if(next > 20) next = 20;
  2851.             $('#set_count').val(next);
  2852.             madosetSelect(next);
  2853.         }
  2854.         // タイプ5: ステップ・フェンス選択値を mitsumori_json に保存するためのグローバル変数
  2855.         var deck_step = "{% if mitsumori_json and mitsumori_json.deck_step is defined %}{{ mitsumori_json.deck_step|default('不要') }}{% else %}不要{% endif %}";
  2856.         var deck_fence = "{% if mitsumori_json and mitsumori_json.deck_fence is defined %}{{ mitsumori_json.deck_fence|default('不要') }}{% else %}不要{% endif %}";
  2857.         // PDF出力: モーダルの mitsumori_json をフォームに同期してから送信
  2858.         function syncPdfJson(){
  2859.             var jsonVal = $('#mitsumori_json').val();
  2860.             $('#pdf_mitsumori_json').val(jsonVal);
  2861.         }
  2862.         // タイプ9: 商品のみ購入
  2863.         function quantityOnly(val){
  2864.             var current = parseInt($('#quantity_only').val()) || 1;
  2865.             var next = current + val;
  2866.             if(next < 1) next = 1;
  2867.             $('#quantity_only').val(next);
  2868.             $('#quantity').val(next);
  2869.         }
  2870.         // ===== スマホ用下部固定バーへの金額同期 =====
  2871.         // mitsumori_message と mitsumori_goukei を監視して下部バーを更新
  2872.         (function() {
  2873.             var msgTarget   = document.getElementById('mitsumori_message');
  2874.             var goukeiTarget = document.getElementById('mitsumori_goukei');
  2875.             var spPrice     = document.getElementById('sp-mitsumori-price');
  2876.             var spBtn       = document.querySelector('#sp-mitsumori-bar .sp-bar__btn');
  2877.             if (!spPrice || !spBtn) return;
  2878.             function syncBar() {
  2879.                 var msg    = msgTarget ? msgTarget.textContent : '';
  2880.                 var goukei = goukeiTarget ? goukeiTarget.textContent : '---円';
  2881.                 // メッセージが「〇〇を選択してください」の場合はメッセージを表示しボタンを非表示
  2882.                 if (msg.indexOf('選択してください') !== -1) {
  2883.                     spPrice.textContent = msg;
  2884.                     spPrice.style.fontSize = '13px';
  2885.                     spPrice.style.color    = '#888';
  2886.                     spBtn.style.display    = 'none';
  2887.                 } else {
  2888.                     // 価格確定時はボタンを表示
  2889.                     spPrice.textContent = goukei;
  2890.                     spPrice.style.fontSize = '18px';
  2891.                     spPrice.style.color    = '#c00';
  2892.                     spBtn.style.display    = 'block';
  2893.                 }
  2894.             }
  2895.             // 初期値を同期
  2896.             syncBar();
  2897.             // mitsumori_message の変化を監視
  2898.             if (msgTarget) {
  2899.                 new MutationObserver(syncBar).observe(
  2900.                     msgTarget, { childList: true, subtree: true, characterData: true }
  2901.                 );
  2902.             }
  2903.             // mitsumori_goukei の変化も監視
  2904.             if (goukeiTarget) {
  2905.                 new MutationObserver(syncBar).observe(
  2906.                     goukeiTarget, { childList: true, subtree: true, characterData: true }
  2907.                 );
  2908.             }
  2909.         })();
  2910.         // ===== スマホ用 お見積りの詳細 ボトムシート 開閉 =====
  2911.         // 現在の内訳カード(.mitsumori-card-pc .card-body)を複製して表示する。
  2912.         // 価格計算ロジックには触れず、その時点で表示中の内訳をそのまま見せる。
  2913.         // window に直接ぶら下げてスコープに依存せず onclick から呼べるようにする。
  2914.         window.openSpMitsumoriDetail = function () {
  2915.             var sheet = document.getElementById('sp-mitsumori-detail');
  2916.             var body  = document.getElementById('sp-detail-body');
  2917.             var src   = document.querySelector('.mitsumori-card-pc .card-body');
  2918.             if (!sheet || !body) return;
  2919.             body.innerHTML = '';
  2920.             if (src) {
  2921.                 // 複製し、重複 id を避けるため clone 側の id を除去する
  2922.                 var clone = src.cloneNode(true);
  2923.                 var ided = clone.querySelectorAll('[id]');
  2924.                 for (var i = 0; i < ided.length; i++) { ided[i].removeAttribute('id'); }
  2925.                 body.appendChild(clone);
  2926.             }
  2927.             sheet.classList.add('is-open');
  2928.             sheet.setAttribute('aria-hidden', 'false');
  2929.             document.body.style.overflow = 'hidden';
  2930.         };
  2931.         window.closeSpMitsumoriDetail = function () {
  2932.             var sheet = document.getElementById('sp-mitsumori-detail');
  2933.             if (!sheet) return;
  2934.             sheet.classList.remove('is-open');
  2935.             sheet.setAttribute('aria-hidden', 'true');
  2936.             document.body.style.overflow = '';
  2937.         };
  2938.         // ===== 現在のお見積り額: 折りたたみトグルボタンのテキスト切り替え =====
  2939.         (function() {
  2940.             var card = document.querySelector('.mitsumori-card-pc');
  2941.             var btn  = document.querySelector('.btn-mitsumori-toggle .toggle-icon');
  2942.             if (!card || !btn) return;
  2943.             // MutationObserverでcollapsed-cardクラスの変化を監視
  2944.             new MutationObserver(function() {
  2945.                 if (card.classList.contains('collapsed-card')) {
  2946.                     btn.textContent = '▼ 詳細';
  2947.                 } else {
  2948.                     btn.textContent = '▲ 閉じる';
  2949.                 }
  2950.             }).observe(card, { attributes: true, attributeFilter: ['class'] });
  2951.         })();
  2952.         // ===== エリア案内: スマホのみタップで展開 =====
  2953.         (function() {
  2954.             var notice = document.querySelector('.ec-areaNotice');
  2955.             if (!notice) return;
  2956.             notice.addEventListener('click', function(e) {
  2957.                 if (window.innerWidth > 767) return;
  2958.                 // リンククリック時は展開/折りたたみせずリンク遷移
  2959.                 if (e.target.tagName === 'A') return;
  2960.                 notice.classList.toggle('is-open');
  2961.             });
  2962.         })();
  2963.     </script>
  2964.     <script type="application/ld+json">
  2965.     {
  2966.         "@context": "https://schema.org/",
  2967.         "@type": "Product",
  2968.         "name": "{{ Product.name }}",
  2969.         "image": [
  2970.             {% for img in Product.ProductImage %}
  2971.                 "{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}"{% if not loop.last %},{% endif %}
  2972.             {% else %}
  2973.                 "{{ app.request.schemeAndHttpHost }}{{ asset(''|no_image_product, 'save_image') }}"
  2974.             {% endfor %}
  2975.         ],
  2976.         "description": "{{ Product.description_list | default(Product.description_detail) | replace({'\n': '', '\r': ''}) | slice(0,300) }}",
  2977.         {% if Product.code_min %}
  2978.         "sku": "{{ Product.code_min }}",
  2979.         {% endif %}
  2980.         "offers": {
  2981.             "@type": "Offer",
  2982.             "url": "{{ url('product_detail', {'id': Product.id}) }}",
  2983.             "priceCurrency": "{{ eccube_config.currency }}",
  2984.             "price": {{ Product.getPrice02IncTaxMin ? Product.getPrice02IncTaxMin : 0}},
  2985.             "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
  2986.         }
  2987.     }
  2988.     </script>
  2989. {% endblock %}
  2990. {% block main %}
  2991.     {# option1 / option2 ラベルをカテゴリ別に決定 (sh=31, rd=43, mo=15) - block scope のため main 側でも再定義 #}
  2992.     {% set option1_label = 'オプション1' %}
  2993.     {% set option2_label = 'オプション2' %}
  2994.     {# rd(玄関ドア, cat43) は素材(m)が開き方+ランマを内包し option1(ランマ)/option2(タイプ) が
  2995.        完全な冗長軸のため、素材のみ「開き方」として表示し option1/option2 の選択 UI は抑制する。
  2996.        価格マッチングは m + カラーで一意に決まり、未選択 option は fallback が無視するため影響なし。 #}
  2997.     {% set is_cat43 = false %}
  2998.     {% if Product.ProductCategories is not empty %}
  2999.         {% for pcat in Product.ProductCategories %}
  3000.             {% if pcat.category_id == 31 %}{% set option1_label = 'サイズプリセット' %}{% set option2_label = '駆動方式' %}{% endif %}
  3001.             {% if pcat.category_id == 43 %}{% set option1_label = 'ランマ' %}{% set option2_label = 'タイプ' %}{% set is_cat43 = true %}{% endif %}
  3002.             {% if pcat.category_id == 15 %}{% set option1_label = '棚タイプ' %}{% endif %}
  3003.             {% if pcat.category_id == 17 %}{% set option1_label = '窓タイプ' %}{% endif %}
  3004.         {% endfor %}
  3005.     {% endif %}
  3006.     <div class="ec-productRole" style="margin-top:20px;">
  3007.         <div class="ec-grid2">
  3008.             <div class="ec-grid2__cell">
  3009.                 <div class="ec-sliderItemRole">
  3010.                     {# 商品名 + ブランド名 + SNSシェア #}
  3011.                     <div class="ec-productRole__title">
  3012.                         <div class="ec-productRole__titleRow">
  3013.                             <h2 class="ec-headingTitle">{{ Product.name }}</h2>
  3014.                             <div class="ec-share-inline">
  3015.                                 <a href="https://twitter.com/share?url={{ app.request.uri|url_encode }}&text={{ Product.name|url_encode }}"
  3016.                                    class="share-twitter" target="_blank" rel="noreferrer noopener" title="Xでシェア">
  3017.                                     <svg viewBox="0 0 24 24" style="width:15px;height:15px;fill:#fff;"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.74l7.73-8.835L1.254 2.25H8.08l4.254 5.622L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
  3018.                                 </a>
  3019.                                 <a href="https://www.instagram.com/" class="share-facebook" target="_blank" rel="noreferrer noopener" title="Instagram">
  3020.                                     <svg viewBox="0 0 24 24" style="width:15px;height:15px;fill:#fff;"><path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zM12 0C8.741 0 8.333.014 7.053.072 2.695.272.273 2.69.073 7.052.014 8.333 0 8.741 0 12c0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98C8.333 23.986 8.741 24 12 24c3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98C15.668.014 15.259 0 12 0zm0 5.838a6.162 6.162 0 100 12.324 6.162 6.162 0 000-12.324zM12 16a4 4 0 110-8 4 4 0 010 8zm6.406-11.845a1.44 1.44 0 100 2.881 1.44 1.44 0 000-2.881z"/></svg>
  3021.                                 </a>
  3022.                                 <a href="https://social-plugins.line.me/lineit/share?url={{ app.request.uri|url_encode }}"
  3023.                                    class="share-line" target="_blank" rel="noreferrer noopener" title="LINEでシェア">
  3024.                                     <i class="fab fa-line"></i>
  3025.                                 </a>
  3026.                             </div>
  3027.                         </div>
  3028.                     </div>
  3029.                     {% if BaseInfo.option_favorite_product %}
  3030.                      <div style="position:relative;top: 20px;left: 10px;z-index:100;">
  3031.                         {% if is_favorite == false %}
  3032.                         <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  3033.                            <button type="submit" id="favorite" class="favorite">&#9825;</button>
  3034.                         </form>
  3035.                         {% else %}
  3036.                         <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  3037.                            <button type="submit" id="favorite" class="favorite" style="color:red;">&#9829;</button>
  3038.                         </form>
  3039.                         {% endif %}
  3040.                      </div>
  3041.                     {% endif %}
  3042.                     <div class="item_visual">
  3043.                         {% for ProductImage in Product.ProductImage %}
  3044.                             <div class="slide-item">
  3045.                                 <a class="js-zoom" href="{{ asset(ProductImage, 'save_image') }}" aria-label="{{ loop.first ? Product.name : '' }}">
  3046.                                     <img src="{{ asset(ProductImage, 'save_image') }}" alt="{{ loop.first ? Product.name : '' }}" width="550" height="550" style="max-height: 400px;"{% if loop.index > 1 %} loading="lazy"{% endif %}>
  3047.                                 </a>
  3048.                             </div>
  3049.                         {% else %}
  3050.                             <div class="slide-item"><img src="{{ asset(''|no_image_product, 'save_image') }}" alt="{{ Product.name }}" width="550" height="550" style="max-height: 400px;"></div>
  3051.                         {% endfor %}
  3052.                     </div>
  3053.                     <div class="item_nav">
  3054.                         {% for ProductImage in Product.ProductImage %}
  3055.                             <div class="slideThumb" data-index="{{ loop.index0 }}"><img src="{{ asset(ProductImage, 'save_image') }}" alt="" width="80" height="80" loading="lazy"></div>
  3056.                         {% endfor %}
  3057.                     </div>
  3058.                 </div>
  3059.                     {# ===== 施工エリア案内(見積シミュレーションの下)===== #}
  3060.                     <div class="ec-areaNotice" style="margin-top:16px;margin-right:10px;">
  3061.                         <div class="ec-areaNotice__inner">
  3062.                             <div class="ec-areaNotice__icon">📍</div>
  3063.                             <div class="ec-areaNotice__body">
  3064.                                 <p class="ec-areaNotice__title">施工対応エリアについて</p>
  3065.                                 <div class="ec-areaNotice__detail">
  3066.                                     <p class="ec-areaNotice__text">
  3067.                                         当店の施工サービスは、<strong>山梨県全域</strong>および<br>
  3068.                                         <strong>諏訪エリア(諏訪市・岡谷市・茅野市・諏訪郡)</strong>を対象としております。<br>
  3069.                                         上記エリア外のお客様には、商品のみのご購入が可能でございます。<br>
  3070.                                         ご不明な点がございましたら、お気軽にお問い合わせください。
  3071.                                     </p>
  3072.                                     <a class="ec-areaNotice__link" href="{{ url('contact') }}">エリア外のお客様・ご相談はこちら →</a>
  3073.                                 </div>
  3074.                             </div>
  3075.                         </div>
  3076.                     </div>
  3077.             </div>
  3078.             <div class="ec-grid2__cell2">
  3079.                 <div class="ec-productRole__profile" >
  3080.                     {# 関連カテゴリ (DIY=21 / 石材=28 / 照明=44 は非表示要件のため除外) #}
  3081.                     {% set hidden_cat_ids = [21, 28, 44] %}
  3082.                     {% if Product.ProductCategories is not empty %}
  3083.                         <div class="ec-productRole__category" style="padding:10px 0;">
  3084.                             {% for ProductCategory in Product.ProductCategories %}
  3085.                                 {% if ProductCategory.Category.id not in hidden_cat_ids %}
  3086.                                 <ul>
  3087.                                     <li>
  3088.                                         {% for Category in ProductCategory.Category.path %}
  3089.                                             <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
  3090.                                             <span>></span>{% endif -%}
  3091.                                         {% endfor %}
  3092.                                     </li>
  3093.                                 </ul>
  3094.                                 {% endif %}
  3095.                             {% endfor %}
  3096.                         </div>
  3097.                     {% endif %}
  3098.                     {# 販売価格 #}
  3099.                     <div class="ec-productRole__price">
  3100.                         <span style="color:black;font-size:15px;">工事費込み価格</span>
  3101.                         {% if Product.hasProductClass -%}
  3102.                             {% if Product.getPrice02IncTaxMin == Product.getPrice02IncTaxMax %}
  3103.                                 <div class="ec-price">
  3104.                                     <span id="price02-display" class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }}</span>
  3105.                                     <span class="ec-price__tax">({{ '税込'|trans }})~</span>
  3106.                                 </div>
  3107.                             {% else %}
  3108.                                 <div class="ec-price">
  3109.                                     <span id="price02-display" class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}</span>
  3110.                                     <span class="ec-price__tax">({{ '税込'|trans }})</span>
  3111.                                 </div>
  3112.                             {% endif %}
  3113.                         {% else %}
  3114.                             <div class="ec-price">
  3115.                                 <span id="price02-display" class="ec-price__price">{{ Product.getPrice02IncTaxMin|price }}</span>
  3116.                                     <span class="ec-price__tax">({{ '税込'|trans }})~</span>
  3117.                             </div>
  3118.                         {% endif %}
  3119.                     </div>
  3120.                     {# タグ #}
  3121.                     <ul class="ec-productRole__tags">
  3122.                         {% for Tag in Product.Tags %}
  3123.                             <li class="ec-productRole__tag tag_{{ Tag.id }}">{{ Tag }}</li>
  3124.                         {% endfor %}
  3125.                     </ul>
  3126.                     {# 商品コード #}
  3127.                     {% if Product.code_min is not empty %}
  3128.                         <div class="ec-productRole__code">
  3129.                             {{ '商品コード'|trans }}: <span class="product-code-default">{{ Product.code_min }}{% if Product.code_min != Product.code_max %} ~ {{ Product.code_max }}{% endif %}</span>
  3130.                         </div>
  3131.                     {% endif %}
  3132.                     <div class="ec-productRole__description">
  3133.                         <div class="ec-rectHeading">
  3134.                             <h4>製品情報</h4>
  3135.                         </div>
  3136.                         {{ Product.sales_infomation|raw|nl2br }}
  3137.                     </div>
  3138.                     <div class="card card-danger" style="clear:both;margin:1px;">
  3139.                       <div class="card-header">
  3140.                         <h3 class="card-title">見積シミュレーション</h3>
  3141.                       </div>
  3142.                       <div class="card-body p-2">
  3143.                         {% set related_image = getProduct_field(Product.id,"related_image") %}
  3144.                         {# related_image は配列: ["1段目画像あり","2段目画像あり","3段目画像あり"] のうち該当するものが格納 #}
  3145.                         {% set img1 = related_image and ("1段目画像あり" in related_image) %}
  3146.                         {% set img2 = related_image and ("2段目画像あり" in related_image) %}
  3147.                         {% set img3 = related_image and ("3段目画像あり" in related_image) %}
  3148.                         {% set img4 = related_image and ("4段目画像あり" in related_image) %}
  3149.                         {% set type1 = getProduct_field(Product.id,"related_name1") %}
  3150.                         {% set type2 = getProduct_field(Product.id,"related_name2") %}
  3151.                         {% set type3 = getProduct_field(Product.id,"related_name3") %}
  3152.                         {% set type4 = getProduct_field(Product.id,"related_name4") %}
  3153.                         {% set hasRelated = (type1 and related_product1 and related_product1|length)
  3154.                                          or (type2 and related_product2 and related_product2|length)
  3155.                                          or (type3 and related_product3 and related_product3|length)
  3156.                                          or (type4 and related_product4 and related_product4|length) %}
  3157.                         {% if hasRelated %}
  3158.                             <div class="row" style="border-bottom:1px solid rgba(0,0,0,.125)"><label class="col-12 col-form-label">この商品のタイプを選択してください。</label></div>
  3159.                         {% endif %}
  3160.                         {# ===== 1段目 ===== #}
  3161.                         {% if type1 and related_product1 and related_product1|length %}
  3162.                         <div class="form-group mt-3 pb-3" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3163.                           <div class="rp-section-label">{{ type1 }}{% if img1 and base_select1 %}: <span>{{ base_select1 }}</span>{% endif %}</div>
  3164.                           {% if img1 %}
  3165.                             {# --- 画像付きカード --- #}
  3166.                             <div class="rp-card-group">
  3167.                               {% for rp_id, rp_name in related_product1 %}
  3168.                                 <a class="rp-card{% if base_select1 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3169.                                   <img class="rp-card__image"
  3170.                                        src="{{ (related_image_obj[rp_id] is defined and related_image_obj[rp_id]) ? asset(related_image_obj[rp_id], 'save_image') : asset(''|no_image_product, 'save_image') }}"
  3171.                                        alt="{{ rp_name }}"
  3172.                                        width="120" height="120" loading="lazy"
  3173.                                        onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
  3174.                                   <div class="rp-card__placeholder" style="display:none;">📦</div>
  3175.                                   <span class="rp-card__name">{{ rp_name }}</span>
  3176.                                 </a>
  3177.                               {% endfor %}
  3178.                             </div>
  3179.                           {% else %}
  3180.                             {# --- ボタン式ラジオ --- #}
  3181.                             <div class="rp-btn-group">
  3182.                               {% for rp_id, rp_name in related_product1 %}
  3183.                                 <a class="rp-btn{% if base_select1 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3184.                                   {{ rp_name }}
  3185.                                 </a>
  3186.                               {% endfor %}
  3187.                             </div>
  3188.                           {% endif %}
  3189.                         </div>
  3190.                         {% endif %}
  3191.                         {# ===== 2段目 ===== #}
  3192.                         {% if type2 and related_product2 and related_product2|length %}
  3193.                         <div class="form-group mt-3 pb-3" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3194.                           <div class="rp-section-label">{{ type2 }}{% if img2 and base_select2 %}: <span>{{ base_select2 }}</span>{% endif %}</div>
  3195.                           {% if img2 %}
  3196.                             <div class="rp-card-group">
  3197.                               {% for rp_id, rp_name in related_product2 %}
  3198.                                 <a class="rp-card{% if base_select2 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3199.                                   <img class="rp-card__image"
  3200.                                        src="{{ (related_image_obj[rp_id] is defined and related_image_obj[rp_id]) ? asset(related_image_obj[rp_id], 'save_image') : asset(''|no_image_product, 'save_image') }}"
  3201.                                        alt="{{ rp_name }}"
  3202.                                        width="120" height="120" loading="lazy"
  3203.                                        onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
  3204.                                   <div class="rp-card__placeholder" style="display:none;">📦</div>
  3205.                                   <span class="rp-card__name">{{ rp_name }}</span>
  3206.                                 </a>
  3207.                               {% endfor %}
  3208.                             </div>
  3209.                           {% else %}
  3210.                             <div class="rp-btn-group">
  3211.                               {% for rp_id, rp_name in related_product2 %}
  3212.                                 <a class="rp-btn{% if base_select2 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3213.                                   {{ rp_name }}
  3214.                                 </a>
  3215.                               {% endfor %}
  3216.                             </div>
  3217.                           {% endif %}
  3218.                         </div>
  3219.                         {% endif %}
  3220.                         {# ===== 3段目 ===== #}
  3221.                         {% if type3 and related_product3 and related_product3|length %}
  3222.                         <div class="form-group mt-3 pb-3" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3223.                           <div class="rp-section-label">{{ type3 }}{% if img3 and base_select3 %}: <span>{{ base_select3 }}</span>{% endif %}</div>
  3224.                           {% if img3 %}
  3225.                             <div class="rp-card-group">
  3226.                               {% for rp_id, rp_name in related_product3 %}
  3227.                                 <a class="rp-card{% if base_select3 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3228.                                   <img class="rp-card__image"
  3229.                                        src="{{ (related_image_obj[rp_id] is defined and related_image_obj[rp_id]) ? asset(related_image_obj[rp_id], 'save_image') : asset(''|no_image_product, 'save_image') }}"
  3230.                                        alt="{{ rp_name }}"
  3231.                                        width="120" height="120" loading="lazy"
  3232.                                        onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
  3233.                                   <div class="rp-card__placeholder" style="display:none;">📦</div>
  3234.                                   <span class="rp-card__name">{{ rp_name }}</span>
  3235.                                 </a>
  3236.                               {% endfor %}
  3237.                             </div>
  3238.                           {% else %}
  3239.                             <div class="rp-btn-group">
  3240.                               {% for rp_id, rp_name in related_product3 %}
  3241.                                 <a class="rp-btn{% if base_select3 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3242.                                   {{ rp_name }}
  3243.                                 </a>
  3244.                               {% endfor %}
  3245.                             </div>
  3246.                           {% endif %}
  3247.                         </div>
  3248.                         {% endif %}
  3249.                         {# ===== 4段目 ===== #}
  3250.                         {% if type4 and related_product4 and related_product4|length %}
  3251.                         <div class="form-group mt-3 pb-3" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3252.                           <div class="rp-section-label">{{ type4 }}{% if img4 and base_select4 %}: <span>{{ base_select4 }}</span>{% endif %}</div>
  3253.                           {% if img4 %}
  3254.                             {# --- 画像付きカード --- #}
  3255.                             <div class="rp-card-group">
  3256.                               {% for rp_id, rp_name in related_product4 %}
  3257.                                 <a class="rp-card{% if base_select4 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3258.                                   <img class="rp-card__image"
  3259.                                        src="{{ (related_image_obj[rp_id] is defined and related_image_obj[rp_id]) ? asset(related_image_obj[rp_id], 'save_image') : asset(''|no_image_product, 'save_image') }}"
  3260.                                        alt="{{ rp_name }}" width="120" height="120" loading="lazy">
  3261.                                   <span class="rp-card__label">{{ rp_name }}</span>
  3262.                                 </a>
  3263.                               {% endfor %}
  3264.                             </div>
  3265.                           {% else %}
  3266.                             {# --- ボタン式ラジオ --- #}
  3267.                             <div class="rp-btn-group">
  3268.                               {% for rp_id, rp_name in related_product4 %}
  3269.                                 <a class="rp-btn{% if base_select4 == rp_name %} is-selected{% endif %}" href="/products/detail/{{ rp_id }}">
  3270.                                   {{ rp_name }}
  3271.                                 </a>
  3272.                               {% endfor %}
  3273.                             </div>
  3274.                           {% endif %}
  3275.                         </div>
  3276.                         {% endif %}
  3277.                         {# ガレージ等で全オプション空のときに見出しのみ表示される事象を回避.
  3278.                            色 / 寸法 / 素材 / option1/2 / op_data いずれかに「描画される」要素がある場合のみ
  3279.                            「この商品のオプションを選択してください。」見出しを表示する.
  3280.                            op_data は cg=9 で「残土」 / gs=27 で「撤去」「残土」を後段ループで
  3281.                            hide するため、単純な op|length > 0 では「見出しだけ残る」事象が
  3282.                            wh / cg の一部商品で発生していた. 描画される entry を事前カウントする. #}
  3283.                         {% set is_gs_h = false %}
  3284.                         {% set is_cg_h = false %}
  3285.                         {% if Product.ProductCategories is not empty %}
  3286.                             {% for pc_h in Product.ProductCategories %}
  3287.                                 {% if pc_h.category_id == 27 %}{% set is_gs_h = true %}{% endif %}
  3288.                                 {% if pc_h.category_id == 9  %}{% set is_cg_h = true %}{% endif %}
  3289.                             {% endfor %}
  3290.                         {% endif %}
  3291.                         {% set visible_op_count = 0 %}
  3292.                         {% if op and op|length %}
  3293.                             {% for opi in op %}
  3294.                                 {% if opi['name'] %}
  3295.                                     {% set _hide_h = false %}
  3296.                                     {% if is_gs_h and (opi['name'] matches '/撤去/' or opi['name'] matches '/残土/') %}{% set _hide_h = true %}{% endif %}
  3297.                                     {% if is_cg_h and opi['name'] matches '/残土/' %}{% set _hide_h = true %}{% endif %}
  3298.                                     {% if not _hide_h %}{% set visible_op_count = visible_op_count + 1 %}{% endif %}
  3299.                                 {% endif %}
  3300.                             {% endfor %}
  3301.                         {% endif %}
  3302.                         {% set has_any_option =
  3303.                             (color and color|length and ProductClass.SaleType.id != 3)
  3304.                             or (p_w and p_w|length and p_w|join != "")
  3305.                             or (p_d and p_d|length and p_d|join != "")
  3306.                             or (p_h and p_h|length and p_h|join != "")
  3307.                             or (p_m and p_m|length and p_m|join != "")
  3308.                             or (p_option1 and p_option1|length and p_option1|join != "")
  3309.                             or (p_option2 and p_option2|length and p_option2|join != "")
  3310.                             or ProductClass.SaleType.id in [2, 5, 6, 7, 9]
  3311.                         %}
  3312.                         {% if has_any_option %}
  3313.                         <div class="row" style="border-bottom:1px solid rgba(0,0,0,.125)"><label class="col-12 col-form-label">この商品のオプションを選択してください。</label></div>
  3314.                         {% endif %}
  3315.                         {# sale_type=2 (補助金窓) はタイプごとに個別カラー選択するため共通カラーは非表示 #}
  3316.                         {% if color and color|length and ProductClass.SaleType.id != 3 and ProductClass.SaleType.id != 2 %}
  3317.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3318.                           <div class="rp-section-label">カラー{% if mitsumori_json and mitsumori_json.pc %}: <span>{{ mitsumori_json.pc }}</span>{% endif %}</div>
  3319.                           <div class="opt-btn-group">
  3320.                             {% set idx = 0 %}
  3321.                             {% for cc in color %}{% if cc and cc['name'] %}{% set idx = idx + 1 %}
  3322.                               {% set has_img = cc['img'] is defined and cc['img'] is not empty %}
  3323.                               <label class="opt-btn{% if has_img %} opt-btn--with-image{% endif %}{% if (mitsumori_json and mitsumori_json.pc == cc['name']) or color|length == 1 %} is-selected{% endif %}"
  3324.                                      onclick="mitsumori_simulation_val('pc', '{{ cc['name']|e('js') }}');">
  3325.                                 <input type="radio" name="color" id="cc_{{ idx }}" value="{{ cc['name'] }}"
  3326.                                        {% if (mitsumori_json and mitsumori_json.pc == cc['name']) or color|length == 1 %}checked{% endif %}>
  3327.                                 {% if has_img %}
  3328.                                   <img src="{{ cc['img'] }}" alt="{{ cc['name'] }}" class="opt-btn__img"
  3329.                                        onerror="this.parentNode.classList.remove('opt-btn--with-image'); this.remove();">
  3330.                                   <span class="opt-btn__name">{{ cc['name'] }}</span>
  3331.                                 {% else %}
  3332.                                   {{ cc['name'] }}
  3333.                                 {% endif %}
  3334.                               </label>
  3335.                             {% endif %}{% endfor %}
  3336.                           </div>
  3337.                         </div>
  3338.                         {% endif %}
  3339.                         {# sale_type=2 (補助金窓) はタイプごとに個別幅選択するため共通幅は非表示.
  3340.                            tf (人工芝, sale_type=6) は専用の「芝の幅」+「施工サイズ」UI を下部に持つため、
  3341.                            汎用の 幅/奥行/高さ は描画しない (両方出すと name="pw"/"ph" が重複し、
  3342.                            片方を選ぶともう片方の選択が外れる顧客指摘あり). #}
  3343.                         {% if p_w and p_w|length and p_w|join != "" and ProductClass.SaleType.id not in [2, 3, 6] %}
  3344.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3345.                           <div class="rp-section-label">幅{% if mitsumori_json and mitsumori_json.pw %}: <span>{{ mitsumori_json.pw }}</span>{% endif %}</div>
  3346.                           <div class="opt-btn-group">
  3347.                             {% set idx = 0 %}
  3348.                             {% for pw in p_w %}{% if pw %}{% set idx = idx + 1 %}
  3349.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pw == pw) or p_w|length == 1 %} is-selected{% endif %}"
  3350.                                      onclick="mitsumori_simulation_val('pw', '{{ pw|e('js') }}');">
  3351.                                 <input type="radio" name="pw" id="pw_{{ idx }}" value="{{ pw }}"
  3352.                                        {% if (mitsumori_json and mitsumori_json.pw == pw) or p_w|length == 1 %}checked{% endif %}>
  3353.                                 {{ pw }}
  3354.                               </label>
  3355.                             {% endif %}{% endfor %}
  3356.                           </div>
  3357.                         </div>
  3358.                         {% endif %}
  3359.                         {% if p_d and p_d|length and p_d|join != "" and ProductClass.SaleType.id not in [3, 6] %}
  3360.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3361.                           <div class="rp-section-label">奥行き{% if mitsumori_json and mitsumori_json.pd %}: <span>{{ mitsumori_json.pd }}</span>{% endif %}</div>
  3362.                           <div class="opt-btn-group">
  3363.                             {% set idx = 0 %}
  3364.                             {% for pd in p_d %}{% if pd %}{% set idx = idx + 1 %}
  3365.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pd == pd) or p_d|length == 1 %} is-selected{% endif %}"
  3366.                                      onclick="mitsumori_simulation_val('pd', '{{ pd|e('js') }}');">
  3367.                                 <input type="radio" name="pd" id="pd_{{ idx }}" value="{{ pd }}"
  3368.                                        {% if (mitsumori_json and mitsumori_json.pd == pd) or p_d|length == 1 %}checked{% endif %}>
  3369.                                 {{ pd }}
  3370.                               </label>
  3371.                             {% endif %}{% endfor %}
  3372.                           </div>
  3373.                         </div>
  3374.                         {% endif %}
  3375.                         {# sale_type=2 (補助金窓) はタイプごとに個別高さ選択するため共通高さは非表示.
  3376.                            sale_type=6 (人工芝) は専用 UI なので汎用高さは描画しない. #}
  3377.                         {% if p_h and p_h|length and p_h|join != "" and ProductClass.SaleType.id not in [2, 3, 6] %}
  3378.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3379.                           <div class="rp-section-label">高さ{% if mitsumori_json and mitsumori_json.ph %}: <span>{{ mitsumori_json.ph }}</span>{% endif %}</div>
  3380.                           <div class="opt-btn-group">
  3381.                             {% set idx = 0 %}
  3382.                             {% for ph in p_h %}{% if ph %}{% set idx = idx + 1 %}
  3383.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.ph == ph) or p_h|length == 1 %} is-selected{% endif %}"
  3384.                                      onclick="mitsumori_simulation_val('ph', '{{ ph|e('js') }}');">
  3385.                                 <input type="radio" name="ph" id="ph_{{ idx }}" value="{{ ph }}"
  3386.                                        {% if (mitsumori_json and mitsumori_json.ph == ph) or p_h|length == 1 %}checked{% endif %}>
  3387.                                 {{ ph }}
  3388.                               </label>
  3389.                             {% endif %}{% endfor %}
  3390.                           </div>
  3391.                         </div>
  3392.                         {% endif %}
  3393.                         {# sale_type=2 (補助金窓) はタイプごとに個別ガラス選択するため共通素材は非表示 #}
  3394.                         {% if p_m and p_m|length and p_m|join != "" and ProductClass.SaleType.id != 3 and ProductClass.SaleType.id != 2 %}
  3395.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3396.                           <div class="rp-section-label">{% if is_cat43 %}開き方{% else %}素材{% endif %}{% if mitsumori_json and mitsumori_json.pm %}: <span>{{ mitsumori_json.pm }}</span>{% endif %}</div>
  3397.                           <div class="opt-btn-group">
  3398.                             {% set idx = 0 %}
  3399.                             {% for pm in p_m %}{% if pm %}{% set idx = idx + 1 %}
  3400.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pm == pm) or p_m|length == 1 %} is-selected{% endif %}"
  3401.                                      onclick="mitsumori_simulation_val('pm', '{{ pm|e('js') }}');">
  3402.                                 <input type="radio" name="pm" id="pm_{{ idx }}" value="{{ pm }}"
  3403.                                        {% if (mitsumori_json and mitsumori_json.pm == pm) or p_m|length == 1 %}checked{% endif %}>
  3404.                                 {{ pm }}
  3405.                               </label>
  3406.                             {% endif %}{% endfor %}
  3407.                           </div>
  3408.                         </div>
  3409.                         {% endif %}
  3410.                         {# option1 (sale_type 2 は専用 UI が下にあるため除外 / sale_type 3 は下部ブロックで描画 /
  3411.                            sale_type 4 = fe・ts は option1 が ct_unit_price (枚数増分の工事費単価) で
  3412.                            ユーザー選択肢ではなく計算用の内部値のため radio として表示しない. 値は
  3413.                            上の auto-init (p_option1|length == 1) で JS の option1 変数に埋め込み済み) #}
  3414.                         {% if p_option1 and p_option1|length and p_option1|join != "" and ProductClass.SaleType.id != 2 and ProductClass.SaleType.id != 3 and ProductClass.SaleType.id != 4 and not is_cat43 %}
  3415.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3416.                           <div class="rp-section-label">{{ option1_label }}{% if mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 %}: <span>{{ mitsumori_json.option1 }}</span>{% endif %}</div>
  3417.                           <div class="opt-btn-group">
  3418.                             {% set idx = 0 %}
  3419.                             {% for opt1 in p_option1 %}{% if opt1 %}{% set idx = idx + 1 %}
  3420.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 == opt1) or p_option1|length == 1 %} is-selected{% endif %}"
  3421.                                      onclick="mitsumori_simulation_val('option1', '{{ opt1|e('js') }}');">
  3422.                                 <input type="radio" name="option1" id="option1_{{ idx }}" value="{{ opt1 }}"
  3423.                                        {% if (mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 == opt1) or p_option1|length == 1 %}checked{% endif %}>
  3424.                                 {{ opt1 }}
  3425.                               </label>
  3426.                             {% endif %}{% endfor %}
  3427.                           </div>
  3428.                         </div>
  3429.                         {% endif %}
  3430.                         {# option2 #}
  3431.                         {% if p_option2 and p_option2|length and p_option2|join != "" and ProductClass.SaleType.id != 2 and ProductClass.SaleType.id != 3 and not is_cat43 %}
  3432.                         <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3433.                           <div class="rp-section-label">{{ option2_label }}{% if mitsumori_json and mitsumori_json.option2 is defined and mitsumori_json.option2 %}: <span>{{ mitsumori_json.option2 }}</span>{% endif %}</div>
  3434.                           <div class="opt-btn-group">
  3435.                             {% set idx = 0 %}
  3436.                             {% for opt2 in p_option2 %}{% if opt2 %}{% set idx = idx + 1 %}
  3437.                               <label class="opt-btn{% if (mitsumori_json and mitsumori_json.option2 is defined and mitsumori_json.option2 == opt2) or p_option2|length == 1 %} is-selected{% endif %}"
  3438.                                      onclick="mitsumori_simulation_val('option2', '{{ opt2|e('js') }}');">
  3439.                                 <input type="radio" name="option2" id="option2_{{ idx }}" value="{{ opt2 }}"
  3440.                                        {% if (mitsumori_json and mitsumori_json.option2 is defined and mitsumori_json.option2 == opt2) or p_option2|length == 1 %}checked{% endif %}>
  3441.                                 {{ opt2 }}
  3442.                               </label>
  3443.                             {% endif %}{% endfor %}
  3444.                           </div>
  3445.                         </div>
  3446.                         {% endif %}
  3447.                         <!-- 1: 施工見積(通常) → 幅/奥行/高さ/素材/カラーは上部の共通ブロックで表示済み -->
  3448.                         {% if ProductClass.SaleType.id == 1 %}
  3449.                         {% endif %}
  3450.                         <!-- 2: 施工見積(補助金・窓) 複数タイプ追加対応 (2026-05) -->
  3451.                         {% if ProductClass.SaleType.id == 2 %}
  3452.                             {# 2026-05 改修: ex-shop プラメイク方式に倣い、1 商品で
  3453.                                複数の「窓タイプ」(subtype × 幅 × 高さ × ガラス × カラー × セット数)
  3454.                                を追加できる UI に変更. 各タイプは内訳 JSON として 1 明細にまとめる. #}
  3455.                             {# ec-productRole__profile は標準テンプレで height:600px / overflow:auto
  3456.                                が当たっており、複数タイプ追加カードが内部スクロールに押し込まれて
  3457.                                見えない. sale_type=2 のときだけ縦方向に伸ばす. #}
  3458.                             <style>
  3459.                                 .ec-productRole__profile {
  3460.                                     overflow: visible !important;
  3461.                                     max-height: none !important;
  3462.                                     height: auto !important;
  3463.                                 }
  3464.                             </style>
  3465.                             {# 住宅区分 UI: 補助金単価が戸建 / 集合住宅で異なるためお客様に申告いただく. #}
  3466.                             {% set housing_default = getProduct_field(Product.id, '住宅区分')|default('戸建') %}
  3467.                             <div class="card mt-3 mb-3">
  3468.                               <div class="card-header" style="background:#fff3cd;color:#333;">
  3469.                                 <strong>お住まいの種別を選択</strong>
  3470.                                 <small class="ms-2 text-muted">補助金単価が変わります</small>
  3471.                               </div>
  3472.                               <div class="card-body p-2">
  3473.                                 <div class="opt-btn-group" id="window-housing-type-group">
  3474.                                   <label class="opt-btn">
  3475.                                     <input type="radio" name="window_housing_type" value="戸建"
  3476.                                            {% if housing_default != '集合住宅' %}checked{% endif %}>
  3477.                                     戸建住宅<small class="d-block text-muted">(延床240㎡以下の非住宅含む)</small>
  3478.                                   </label>
  3479.                                   <label class="opt-btn">
  3480.                                     <input type="radio" name="window_housing_type" value="集合住宅"
  3481.                                            {% if housing_default == '集合住宅' %}checked{% endif %}>
  3482.                                     集合住宅<small class="d-block text-muted">(低層・中高層/240㎡超の非住宅)</small>
  3483.                                   </label>
  3484.                                 </div>
  3485.                               </div>
  3486.                             </div>
  3487.                             <div class="card mt-3 mb-3">
  3488.                               <div class="card-header" style="background:#fff3cd;color:#333;">
  3489.                                 <strong>窓タイプを選択(複数追加可・最大 20)</strong>
  3490.                               </div>
  3491.                               <div class="card-body p-2">
  3492.                                 <div id="window-types-container"><!-- 動的に窓タイプブロックが追加される --></div>
  3493.                                 <div class="text-center mt-2">
  3494.                                   <button type="button" id="btn-add-window-type" class="btn btn-outline-primary btn-sm" onclick="addWindowType();">+ 窓タイプを追加</button>
  3495.                                   <div class="small text-muted mt-1">最大 20 タイプまで追加できます</div>
  3496.                                 </div>
  3497.                               </div>
  3498.                             </div>
  3499.                             {# 窓タイプブロックのテンプレート. __IDX__ を JS で連番に置換して clone する. #}
  3500.                             <template id="window-type-template">
  3501.                               <div class="window-type-block" data-type-idx="__IDX__" style="border:1px solid #ddd;border-radius:6px;padding:10px;margin-bottom:10px;background:#fafafa;">
  3502.                                 <div class="d-flex justify-content-between align-items-center mb-2">
  3503.                                   <strong>窓タイプ <span class="wt-num">__IDX__</span></strong>
  3504.                                   <button type="button" class="btn btn-sm btn-outline-danger btn-remove-window-type" onclick="removeWindowType(this);">× 削除</button>
  3505.                                 </div>
  3506.                                 {# 窓タイプ (subtype) #}
  3507.                                 {% if p_option1 and p_option1|length and p_option1|join != "" %}
  3508.                                 <div class="form-group mt-2 pb-2" style="border-bottom:1px dashed rgba(0,0,0,.1)">
  3509.                                   <div class="rp-section-label">窓タイプ</div>
  3510.                                   <div class="opt-btn-group">
  3511.                                     {% for v in p_option1 %}{% if v %}
  3512.                                       <label class="opt-btn">
  3513.                                         <input type="radio" name="wt_subtype___IDX__" value="{{ v }}" data-axis="subtype" onchange="onWindowTypeAxisChange(this);">
  3514.                                         {{ v }}
  3515.                                       </label>
  3516.                                     {% endif %}{% endfor %}
  3517.                                   </div>
  3518.                                 </div>
  3519.                                 {% endif %}
  3520.                                 {# 幅 (mm 直接入力) #}
  3521.                                 {% if p_w and p_w|length and p_w|join != "" %}
  3522.                                 <div class="form-group mt-2 pb-2" style="border-bottom:1px dashed rgba(0,0,0,.1)">
  3523.                                   <div class="rp-section-label">幅</div>
  3524.                                   <div class="input-group" style="max-width:240px;">
  3525.                                     <input type="number" name="wt_pw___IDX__" class="form-control" min="100" step="10"
  3526.                                            placeholder="例 1750" data-axis="pw" data-unit="mm"
  3527.                                            oninput="onWindowTypeAxisChange(this);">
  3528.                                     <span class="input-group-text">mm</span>
  3529.                                   </div>
  3530.                                   <small class="text-muted">商品の対応幅: 〜{{ (p_w|last)|default('') }}({{ p_w|length }} 段階の価格帯から自動選択)</small>
  3531.                                 </div>
  3532.                                 {% endif %}
  3533.                                 {# 高さ (mm 直接入力) #}
  3534.                                 {% if p_h and p_h|length and p_h|join != "" %}
  3535.                                 <div class="form-group mt-2 pb-2" style="border-bottom:1px dashed rgba(0,0,0,.1)">
  3536.                                   <div class="rp-section-label">高さ</div>
  3537.                                   <div class="input-group" style="max-width:240px;">
  3538.                                     <input type="number" name="wt_ph___IDX__" class="form-control" min="100" step="10"
  3539.                                            placeholder="例 1200" data-axis="ph" data-unit="mm"
  3540.                                            oninput="onWindowTypeAxisChange(this);">
  3541.                                     <span class="input-group-text">mm</span>
  3542.                                   </div>
  3543.                                   <small class="text-muted">商品の対応高さ: 〜{{ (p_h|last)|default('') }}({{ p_h|length }} 段階の価格帯から自動選択)</small>
  3544.                                 </div>
  3545.                                 {% endif %}
  3546.                                 {# ガラスタイプ #}
  3547.                                 {% if p_m and p_m|length and p_m|join != "" %}
  3548.                                 <div class="form-group mt-2 pb-2" style="border-bottom:1px dashed rgba(0,0,0,.1)">
  3549.                                   <div class="rp-section-label">ガラスタイプ</div>
  3550.                                   <div class="opt-btn-group">
  3551.                                     {% for v in p_m %}{% if v %}
  3552.                                       <label class="opt-btn">
  3553.                                         <input type="radio" name="wt_pm___IDX__" value="{{ v }}" data-axis="pm" onchange="onWindowTypeAxisChange(this);">
  3554.                                         {{ v }}
  3555.                                       </label>
  3556.                                     {% endif %}{% endfor %}
  3557.                                   </div>
  3558.                                   <small class="text-muted">「<span style="color:#2e7d32;font-weight:bold;">補助金対象</span>」が付いたガラスは、先進的窓リノベ補助金の対象です。</small>
  3559.                                 </div>
  3560.                                 {% endif %}
  3561.                                 {# 窓枠カラー #}
  3562.                                 {% if color and color|length %}
  3563.                                 <div class="form-group mt-2 pb-2" style="border-bottom:1px dashed rgba(0,0,0,.1)">
  3564.                                   <div class="rp-section-label">窓枠カラー</div>
  3565.                                   <div class="opt-btn-group">
  3566.                                     {% for cc in color %}{% if cc and cc['name'] %}
  3567.                                       {% set has_img = cc['img'] is defined and cc['img'] is not empty %}
  3568.                                       <label class="opt-btn{% if has_img %} opt-btn--with-image{% endif %}">
  3569.                                         <input type="radio" name="wt_pc___IDX__" value="{{ cc['name'] }}" data-axis="pc" onchange="onWindowTypeAxisChange(this);">
  3570.                                         {% if has_img %}
  3571.                                           <img src="{{ cc['img'] }}" alt="{{ cc['name'] }}" class="opt-btn__img"
  3572.                                                onerror="this.parentNode.classList.remove('opt-btn--with-image'); this.remove();">
  3573.                                           <span class="opt-btn__name">{{ cc['name'] }}</span>
  3574.                                         {% else %}
  3575.                                           {{ cc['name'] }}
  3576.                                         {% endif %}
  3577.                                       </label>
  3578.                                     {% endif %}{% endfor %}
  3579.                                   </div>
  3580.                                 </div>
  3581.                                 {% endif %}
  3582.                                 {# セット数 + タイプごとの補助金額表示 (補助金は task 2 で実計算) #}
  3583.                                 <div class="form-group row mt-2 align-items-center">
  3584.                                   <label class="col-4 col-form-label">セット数</label>
  3585.                                   <div class="col-4">
  3586.                                     <div class="input-group">
  3587.                                       <input type="number" name="wt_setqty___IDX__" class="form-control wt-input-setqty" value="1" min="1" max="99" data-axis="setqty" onchange="onWindowTypeAxisChange(this);">
  3588.                                       <span class="input-group-text">セット</span>
  3589.                                     </div>
  3590.                                   </div>
  3591.                                   <div class="col-4 text-end">
  3592.                                     <small class="text-muted">補助金額<br><span class="wt-subsidy-amount">―</span> 円</small>
  3593.                                   </div>
  3594.                                 </div>
  3595.                               </div>
  3596.                             </template>
  3597.                             {# 複数タイプ管理 JS. addWindowType / removeWindowType / 再番号付け. #}
  3598.                             <script>
  3599.                             (function() {
  3600.                                 var MAX_WINDOW_TYPES = 20;
  3601.                                 function addWindowType() {
  3602.                                     var container = document.getElementById('window-types-container');
  3603.                                     if (!container) return;
  3604.                                     var existing = container.querySelectorAll('.window-type-block');
  3605.                                     if (existing.length >= MAX_WINDOW_TYPES) return;
  3606.                                     var newIdx = existing.length + 1;
  3607.                                     var tpl = document.getElementById('window-type-template');
  3608.                                     if (!tpl) return;
  3609.                                     // <template> の innerHTML を取り出して __IDX__ を新規連番に置換し、要素化して append.
  3610.                                     var html = tpl.innerHTML.replace(/__IDX__/g, String(newIdx));
  3611.                                     var wrapper = document.createElement('div');
  3612.                                     wrapper.innerHTML = html.trim();
  3613.                                     var block = wrapper.firstChild;
  3614.                                     container.appendChild(block);
  3615.                                     decorateSubsidyGlass(block);
  3616.                                     updateRemoveButtonVisibility();
  3617.                                     if (typeof recalcAll === 'function') recalcAll();
  3618.                                 }
  3619.                                 // 補助金対象ガラスの選択肢に「補助金対象」バッジ + 緑枠を付与する.
  3620.                                 // 判定は calc script 側の window.glassYieldsSubsidy に委譲 (ロジック二重化を避ける)。
  3621.                                 function decorateSubsidyGlass(block) {
  3622.                                     if (!block || typeof window.glassYieldsSubsidy !== 'function') return;
  3623.                                     var radios = block.querySelectorAll('input[data-axis="pm"]');
  3624.                                     radios.forEach(function(inp) {
  3625.                                         var label = inp.closest('.opt-btn');
  3626.                                         if (!label || label.querySelector('.opt-btn__subsidy-badge')) return;
  3627.                                         if (window.glassYieldsSubsidy(inp.value)) {
  3628.                                             label.classList.add('opt-btn--subsidy');
  3629.                                             var badge = document.createElement('span');
  3630.                                             badge.className = 'opt-btn__subsidy-badge';
  3631.                                             badge.textContent = '補助金対象';
  3632.                                             label.appendChild(badge);
  3633.                                         }
  3634.                                     });
  3635.                                 }
  3636.                                 function removeWindowType(btn) {
  3637.                                     var block = btn.closest('.window-type-block');
  3638.                                     if (!block) return;
  3639.                                     block.remove();
  3640.                                     reindexBlocks();
  3641.                                     updateRemoveButtonVisibility();
  3642.                                     if (typeof recalcAll === 'function') recalcAll();
  3643.                                 }
  3644.                                 function updateRemoveButtonVisibility() {
  3645.                                     var blocks = document.querySelectorAll('#window-types-container .window-type-block');
  3646.                                     blocks.forEach(function(b) {
  3647.                                         var btn = b.querySelector('.btn-remove-window-type');
  3648.                                         if (btn) btn.style.display = blocks.length > 1 ? '' : 'none';
  3649.                                     });
  3650.                                 }
  3651.                                 function reindexBlocks() {
  3652.                                     // ブロック削除後に 1 から振り直し. input[name] の末尾 _N も書き換える.
  3653.                                     var blocks = document.querySelectorAll('#window-types-container .window-type-block');
  3654.                                     blocks.forEach(function(b, i) {
  3655.                                         var n = i + 1;
  3656.                                         b.setAttribute('data-type-idx', String(n));
  3657.                                         var numSpan = b.querySelector('.wt-num');
  3658.                                         if (numSpan) numSpan.textContent = String(n);
  3659.                                         b.querySelectorAll('input[name]').forEach(function(inp) {
  3660.                                             inp.name = inp.name.replace(/_\d+$/, '_' + n);
  3661.                                         });
  3662.                                     });
  3663.                                 }
  3664.                                 // 軸変更イベント. recalcAll が定義されていれば再計算 (task 2 で実装).
  3665.                                 window.onWindowTypeAxisChange = function() {
  3666.                                     if (typeof recalcAll === 'function') recalcAll();
  3667.                                 };
  3668.                                 window.addWindowType = addWindowType;
  3669.                                 window.removeWindowType = removeWindowType;
  3670.                                 // 隠し radio(opacity:0/pointer-events:none) を label で包む opt-btn は iOS で初回タップの
  3671.                                 // change が不発になりやすい。窓タイプ/住宅区分は label に onclick が無く change 依存だった
  3672.                                 // ため「2回タッチ/選択できない」が発生。click は確実に発火するので委譲 click で選択状態・
  3673.                                 // is-selected・再計算を行う(JSで複製される窓タイプにも委譲で対応)。
  3674.                                 document.addEventListener('click', function(ev) {
  3675.                                     if (!ev.target || !ev.target.closest) return;
  3676.                                     var label = ev.target.closest('.opt-btn');
  3677.                                     if (!label) return;
  3678.                                     if (!label.closest('#window-types-container') && !label.closest('#window-housing-type-group')) return;
  3679.                                     var input = label.querySelector('input[type="radio"]');
  3680.                                     if (!input || input.disabled) return;
  3681.                                     input.checked = true;
  3682.                                     var nm = input.getAttribute('name');
  3683.                                     if (nm) {
  3684.                                         document.querySelectorAll('input[name="' + nm + '"]').forEach(function(i) {
  3685.                                             var l = i.closest('.opt-btn');
  3686.                                             if (l) l.classList.toggle('is-selected', i.checked);
  3687.                                         });
  3688.                                     }
  3689.                                     if (typeof recalcAll === 'function') recalcAll();
  3690.                                 });
  3691.                                 // 初期表示で 1 ブロック追加 + 住宅区分ラジオの change で再計算.
  3692.                                 document.addEventListener('DOMContentLoaded', function() {
  3693.                                     if (document.querySelector('#window-types-container')) {
  3694.                                         addWindowType();
  3695.                                     }
  3696.                                     var housingInputs = document.querySelectorAll('input[name="window_housing_type"]');
  3697.                                     var syncHousingSelectedClass = function() {
  3698.                                         housingInputs.forEach(function(el) {
  3699.                                             var lbl = el.closest('.opt-btn');
  3700.                                             if (!lbl) return;
  3701.                                             if (el.checked) lbl.classList.add('is-selected');
  3702.                                             else            lbl.classList.remove('is-selected');
  3703.                                         });
  3704.                                     };
  3705.                                     syncHousingSelectedClass();
  3706.                                     housingInputs.forEach(function(el) {
  3707.                                         el.addEventListener('change', function() {
  3708.                                             syncHousingSelectedClass();
  3709.                                             if (typeof recalcAll === 'function') recalcAll();
  3710.                                         });
  3711.                                     });
  3712.                                 });
  3713.                             })();
  3714.                             </script>
  3715.                         {% endif %}
  3716.                         <!-- 3: 施工見積(物置・ゴミステーション) -->
  3717.                         {% if ProductClass.SaleType.id == 3 %}
  3718.                             {# 幅・奥行き・高さ(p_w/p_d/p_h からボタン型ラジオ生成) #}
  3719.                             {% if p_w and p_w|length and p_w|join != "" %}
  3720.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3721.                               <div class="rp-section-label">幅{% if mitsumori_json and mitsumori_json.pw %}: <span>{{ mitsumori_json.pw }}</span>{% endif %}</div>
  3722.                               <div class="opt-btn-group">
  3723.                                 {% set idx = 0 %}
  3724.                                 {% for pw_val in p_w %}{% if pw_val %}{% set idx = idx + 1 %}
  3725.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pw == pw_val) or p_w|length == 1 %} is-selected{% endif %}"
  3726.                                          onclick="mitsumori_simulation('pw','pw3_{{ idx }}');">
  3727.                                     <input type="radio" name="pw" id="pw3_{{ idx }}" value="{{ pw_val }}"
  3728.                                            {% if (mitsumori_json and mitsumori_json.pw == pw_val) or p_w|length == 1 %}checked{% endif %}>
  3729.                                     {{ pw_val }}
  3730.                                   </label>
  3731.                                 {% endif %}{% endfor %}
  3732.                               </div>
  3733.                             </div>
  3734.                             {% endif %}
  3735.                             {% if p_d and p_d|length and p_d|join != "" %}
  3736.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3737.                               <div class="rp-section-label">奥行き{% if mitsumori_json and mitsumori_json.pd %}: <span>{{ mitsumori_json.pd }}</span>{% endif %}</div>
  3738.                               <div class="opt-btn-group">
  3739.                                 {% set idx = 0 %}
  3740.                                 {% for pd_val in p_d %}{% if pd_val %}{% set idx = idx + 1 %}
  3741.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pd == pd_val) or p_d|length == 1 %} is-selected{% endif %}"
  3742.                                          onclick="mitsumori_simulation('pd','pd3_{{ idx }}');">
  3743.                                     <input type="radio" name="pd" id="pd3_{{ idx }}" value="{{ pd_val }}"
  3744.                                            {% if (mitsumori_json and mitsumori_json.pd == pd_val) or p_d|length == 1 %}checked{% endif %}>
  3745.                                     {{ pd_val }}
  3746.                                   </label>
  3747.                                 {% endif %}{% endfor %}
  3748.                               </div>
  3749.                             </div>
  3750.                             {% endif %}
  3751.                             {% if p_h and p_h|length and p_h|join != "" %}
  3752.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3753.                               <div class="rp-section-label">高さ{% if mitsumori_json and mitsumori_json.ph %}: <span>{{ mitsumori_json.ph }}</span>{% endif %}</div>
  3754.                               <div class="opt-btn-group">
  3755.                                 {% set idx = 0 %}
  3756.                                 {% for ph_val in p_h %}{% if ph_val %}{% set idx = idx + 1 %}
  3757.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.ph == ph_val) or p_h|length == 1 %} is-selected{% endif %}"
  3758.                                          onclick="mitsumori_simulation('ph','ph3_{{ idx }}');">
  3759.                                     <input type="radio" name="ph" id="ph3_{{ idx }}" value="{{ ph_val }}"
  3760.                                            {% if (mitsumori_json and mitsumori_json.ph == ph_val) or p_h|length == 1 %}checked{% endif %}>
  3761.                                     {{ ph_val }}
  3762.                                   </label>
  3763.                                 {% endif %}{% endfor %}
  3764.                               </div>
  3765.                             </div>
  3766.                             {% endif %}
  3767.                             {# 棚タイプ(p_m データから選択肢を生成) #}
  3768.                             {% if p_m and p_m|length and p_m|join != "" %}
  3769.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3770.                               <div class="rp-section-label">棚タイプ <small class="text-muted">(間仕切り仕様)</small>{% if mitsumori_json and mitsumori_json.pm %}: <span>{{ mitsumori_json.pm }}</span>{% endif %}</div>
  3771.                               <div class="opt-btn-group">
  3772.                                 {% set idx = 0 %}
  3773.                                 {% for pm_val in p_m %}{% if pm_val %}{% set idx = idx + 1 %}
  3774.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pm == pm_val) or p_m|length == 1 %} is-selected{% endif %}"
  3775.                                          onclick="mitsumori_simulation('pm','pm3_{{ idx }}');">
  3776.                                     <input type="radio" name="pm" id="pm3_{{ idx }}" value="{{ pm_val }}"
  3777.                                            {% if (mitsumori_json and mitsumori_json.pm == pm_val) or p_m|length == 1 %}checked{% endif %}>
  3778.                                     {{ pm_val }}
  3779.                                   </label>
  3780.                                 {% endif %}{% endfor %}
  3781.                               </div>
  3782.                             </div>
  3783.                             {% endif %}
  3784.                             {# option1 (mo の 棚タイプ 等、p_option1 データから選択肢を生成) #}
  3785.                             {% if p_option1 and p_option1|length and p_option1|join != "" %}
  3786.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3787.                               <div class="rp-section-label">{{ option1_label }}{% if mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 %}: <span>{{ mitsumori_json.option1 }}</span>{% endif %}</div>
  3788.                               <div class="opt-btn-group">
  3789.                                 {% set idx = 0 %}
  3790.                                 {% for opt1_val in p_option1 %}{% if opt1_val %}{% set idx = idx + 1 %}
  3791.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 == opt1_val) or p_option1|length == 1 %} is-selected{% endif %}"
  3792.                                          onclick="mitsumori_simulation('option1','option1_3_{{ idx }}');">
  3793.                                     <input type="radio" name="option1" id="option1_3_{{ idx }}" value="{{ opt1_val }}"
  3794.                                            {% if (mitsumori_json and mitsumori_json.option1 is defined and mitsumori_json.option1 == opt1_val) or p_option1|length == 1 %}checked{% endif %}>
  3795.                                     {{ opt1_val }}
  3796.                                   </label>
  3797.                                 {% endif %}{% endfor %}
  3798.                               </div>
  3799.                             </div>
  3800.                             {% endif %}
  3801.                             {# カラー(共通の color データ使用) #}
  3802.                             {% if color and color|length %}
  3803.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3804.                               <div class="rp-section-label">カラー{% if mitsumori_json and mitsumori_json.pc %}: <span>{{ mitsumori_json.pc }}</span>{% endif %}</div>
  3805.                               <div class="opt-btn-group">
  3806.                                 {% set idx = 0 %}
  3807.                                 {% for cc in color %}{% if cc and cc['name'] %}{% set idx = idx + 1 %}
  3808.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pc == cc['name']) or color|length == 1 %} is-selected{% endif %}"
  3809.                                          onclick="mitsumori_simulation('pc','cc3_{{ idx }}');">
  3810.                                     <input type="radio" name="color3" id="cc3_{{ idx }}" value="{{ cc['name'] }}"
  3811.                                            {% if (mitsumori_json and mitsumori_json.pc == cc['name']) or color|length == 1 %}checked{% endif %}>
  3812.                                     {{ cc['name'] }}
  3813.                                   </label>
  3814.                                 {% endif %}{% endfor %}
  3815.                               </div>
  3816.                             </div>
  3817.                             {% endif %}
  3818.                             {# 台数 #}
  3819.                             <div class="form-group row mt-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3820.                               <label class="col-4 col-form-label">台数</label>
  3821.                               <div class="col-4">
  3822.                                 <div class="input-group mb-3">
  3823.                                   <input type="number" name="daisu" id="daisu" class="form-control" value="{{ mitsumori_json.daisu|default('1') }}" min="1" max="10" onchange="mitsumori_simulation('daisu','daisu');">
  3824.                                   <span class="input-group-text">台</span>
  3825.                                 </div>
  3826.                               </div>
  3827.                               <div class="col-4">
  3828.                                 <button type="button" class="btn btn-info" onclick="daisu(+1);">+</button>
  3829.                                 <button type="button" class="btn btn-danger" onclick="daisu(-1);">ー</button>
  3830.                               </div>
  3831.                             </div>
  3832.                         {% endif %}
  3833.                         <!-- 4: 施工見積(フェンス・組み立て式) -->
  3834.                         {% if ProductClass.SaleType.id == 4 %}
  3835.                             {# 枚数 #}
  3836.                             <div class="form-group row mt-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3837.                               <label class="col-4 col-form-label">枚数</label>
  3838.                               <div class="col-4 mb-3">
  3839.                                 <div class="input-group">
  3840.                                   <input type="number" name="maisu" id="maisu" class="form-control" value="{{ mitsumori_json.maisu|default('3') }}" min="3" max="20" onchange="if(parseInt(this.value)<3)this.value=3; mitsumori_simulation('maisu','maisu');">
  3841.                                   <span class="input-group-text">枚</span>
  3842.                                 </div>
  3843.                               </div>
  3844.                               <div class="col-4">
  3845.                                 <button type="button" class="btn btn-info" onclick="maisu(+1);">+</button>
  3846.                                 <button type="button" class="btn btn-danger" onclick="maisu(-1);">ー</button>
  3847.                               </div>
  3848.                             </div>
  3849.                         {% endif %}
  3850.                         <!-- 5: 施工見積(ウッドデッキ・タイルデッキ) -->
  3851.                         {% if ProductClass.SaleType.id == 5 %}
  3852.                             {# ステップの有無 #}
  3853.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3854.                               <div class="rp-section-label">ステップ</div>
  3855.                               <div class="opt-btn-group">
  3856.                                 {% set step_yes_checked = (mitsumori_json and mitsumori_json.deck_step is defined and mitsumori_json.deck_step == '必要') %}
  3857.                                 {% set step_no_checked = (not mitsumori_json or mitsumori_json.deck_step is not defined or mitsumori_json.deck_step == '不要' or not mitsumori_json.deck_step) %}
  3858.                                 <label class="opt-btn{% if step_yes_checked %} is-selected{% endif %}"
  3859.                                        onclick="mitsumori_simulation('op0','deck_step_yes');">
  3860.                                   <input type="radio" name="deck_step" id="deck_step_yes" value="必要"
  3861.                                          {% if step_yes_checked %}checked{% endif %}>
  3862.                                   必要
  3863.                                 </label>
  3864.                                 <label class="opt-btn{% if step_no_checked %} is-selected{% endif %}"
  3865.                                        onclick="mitsumori_simulation('op0','deck_step_no');">
  3866.                                   <input type="radio" name="deck_step" id="deck_step_no" value="不要"
  3867.                                          {% if step_no_checked %}checked{% endif %}>
  3868.                                   不要
  3869.                                 </label>
  3870.                               </div>
  3871.                               <div class="opt-survey-note-wd-step" style="font-size:12px;color:#c00;margin-top:6px;{% if not step_yes_checked %}display:none;{% endif %}">
  3872.                                 ※ 現場調査後に正式お見積もりさせていただきます。
  3873.                               </div>
  3874.                             </div>
  3875.                             {# ウッドデッキフェンスの有無 #}
  3876.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3877.                               <div class="rp-section-label">デッキフェンス</div>
  3878.                               <div class="opt-btn-group">
  3879.                                 {% set fence_yes_checked = (mitsumori_json and mitsumori_json.deck_fence is defined and mitsumori_json.deck_fence == '必要') %}
  3880.                                 {% set fence_no_checked = (not mitsumori_json or mitsumori_json.deck_fence is not defined or mitsumori_json.deck_fence == '不要' or not mitsumori_json.deck_fence) %}
  3881.                                 <label class="opt-btn{% if fence_yes_checked %} is-selected{% endif %}"
  3882.                                        onclick="mitsumori_simulation('op1','deck_fence_yes');">
  3883.                                   <input type="radio" name="deck_fence" id="deck_fence_yes" value="必要"
  3884.                                          {% if fence_yes_checked %}checked{% endif %}>
  3885.                                   必要
  3886.                                 </label>
  3887.                                 <label class="opt-btn{% if fence_no_checked %} is-selected{% endif %}"
  3888.                                        onclick="mitsumori_simulation('op1','deck_fence_no');">
  3889.                                   <input type="radio" name="deck_fence" id="deck_fence_no" value="不要"
  3890.                                          {% if fence_no_checked %}checked{% endif %}>
  3891.                                   不要
  3892.                                 </label>
  3893.                               </div>
  3894.                               <div class="opt-survey-note-wd-fence" style="font-size:12px;color:#c00;margin-top:6px;{% if not fence_yes_checked %}display:none;{% endif %}">
  3895.                                 ※ 現場調査後に正式お見積もりさせていただきます。
  3896.                               </div>
  3897.                             </div>
  3898.                         {% endif %}
  3899.                         <!-- 6: 施工見積(芝生・枚数・数量買い) -->
  3900.                         {% if ProductClass.SaleType.id == 6 %}
  3901.                             {# 規格(p_m データ → 素材から抽出) #}
  3902.                             {% if p_m and p_m|length and p_m|join != "" %}
  3903.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3904.                               <div class="rp-section-label">規格{% if mitsumori_json and mitsumori_json.pm %}: <span>{{ mitsumori_json.pm }}</span>{% endif %}</div>
  3905.                               <div class="opt-btn-group">
  3906.                                 {% set idx = 0 %}
  3907.                                 {% for pm_val in p_m %}{% if pm_val %}{% set idx = idx + 1 %}
  3908.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pm == pm_val) or p_m|length == 1 %} is-selected{% endif %}"
  3909.                                          onclick="mitsumori_simulation('pm','pm6_{{ idx }}');">
  3910.                                     <input type="radio" name="pm" id="pm6_{{ idx }}" value="{{ pm_val }}"
  3911.                                            {% if (mitsumori_json and mitsumori_json.pm == pm_val) or p_m|length == 1 %}checked{% endif %}>
  3912.                                     {{ pm_val }}
  3913.                                   </label>
  3914.                                 {% endif %}{% endfor %}
  3915.                               </div>
  3916.                             </div>
  3917.                             {% endif %}
  3918.                             {# 芝の幅(p_w = ロール幅。free_area の w。例 100cm/200cm = 1m/2m 幅。
  3919.                                h はロール長(例 1000cm=10m)で固定のため UI には出さない)。 #}
  3920.                             {% if p_w and p_w|length and p_w|join != "" %}
  3921.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3922.                               <div class="rp-section-label">芝の幅{% if mitsumori_json and mitsumori_json.pw %}: <span>{{ mitsumori_json.pw }}</span>{% endif %}</div>
  3923.                               <div class="opt-btn-group">
  3924.                                 {% set idx = 0 %}
  3925.                                 {% for pw_val in p_w %}{% if pw_val %}{% set idx = idx + 1 %}
  3926.                                   <label class="opt-btn{% if (mitsumori_json and mitsumori_json.pw == pw_val) or p_w|length == 1 %} is-selected{% endif %}"
  3927.                                          onclick="mitsumori_simulation('pw','pw6_{{ idx }}');">
  3928.                                     <input type="radio" name="pw" id="pw6_{{ idx }}" value="{{ pw_val }}"
  3929.                                            {% if (mitsumori_json and mitsumori_json.pw == pw_val) or p_w|length == 1 %}checked{% endif %}>
  3930.                                     {{ pw_val }}
  3931.                                   </label>
  3932.                                 {% endif %}{% endfor %}
  3933.                               </div>
  3934.                             </div>
  3935.                             {% endif %}
  3936.                             {# 1ロールの長さ表記(顧客要望 #10)。h はロール長 (例 1000cm=10m) で固定のため選択ではなく表示のみ。 #}
  3937.                             {% set _roll_h = (p_h is defined and p_h|length) ? (p_h|first) : '' %}
  3938.                             {% if _roll_h %}
  3939.                             <div class="form-group mt-3 pb-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3940.                               <div class="rp-section-label">1ロールの長さ:<span style="font-weight:bold;">{% if 'cm' in _roll_h %}{{ (_roll_h|replace({'cm':'', ',':''})|trim) / 100 }}m{% else %}{{ _roll_h }}{% endif %}</span></div>
  3941.                             </div>
  3942.                             {% endif %}
  3943.                             {# 施工サイズ(縦 × 横、m 入力)→ 必要枚数を自動算出して表示.
  3944.                                面積=縦×横 を #area に流し込み、case 6 の qty=ceil(area/ロール面積) を流用. #}
  3945.                             <div class="form-group row mt-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3946.                               <label class="col-4 col-form-label">施工サイズ</label>
  3947.                               <div class="col-8">
  3948.                                 <div class="input-group">
  3949.                                   <input type="number" name="tf_len" id="tf_len"
  3950.                                     class="form-control"
  3951.                                     value="{{ mitsumori_json.tf_len|default('') }}"
  3952.                                     placeholder="縦" min="0.1" step="0.1"
  3953.                                     onchange="mitsumori_simulation('tf_len','tf_len');">
  3954.                                   <span class="input-group-text">m&nbsp;×</span>
  3955.                                   <input type="number" name="tf_wid" id="tf_wid"
  3956.                                     class="form-control"
  3957.                                     value="{{ mitsumori_json.tf_wid|default('') }}"
  3958.                                     placeholder="横" min="0.1" step="0.1"
  3959.                                     onchange="mitsumori_simulation('tf_wid','tf_wid');">
  3960.                                   <span class="input-group-text">m</span>
  3961.                                 </div>
  3962.                                 {# area は内部計算用に保持(縦×横を JS で書き込む) #}
  3963.                                 <input type="hidden" name="area" id="area" value="{{ mitsumori_json.area|default('') }}">
  3964.                                 {# 必要枚数は直接入力も可能。施工サイズ入力時は自動算出して上書きする。
  3965.                                    施工サイズ未入力でも、ここで枚数だけ指定してカートに入れられる。 #}
  3966.                                 <div style="margin-top:10px;display:inline-block;background:#fff3cd;border:1px solid #ffe69c;border-radius:6px;padding:8px 14px;font-size:16px;color:#c00;font-weight:bold;">
  3967.                                   必要枚数:<input type="number" name="tf_qty" id="tf_qty"
  3968.                                     value="{{ mitsumori_json.tf_qty|default('1') }}" min="1" step="1"
  3969.                                     style="width:80px;font-size:22px;font-weight:bold;color:#c00;text-align:right;border:1px solid #ffe69c;border-radius:4px;padding:2px 6px;"
  3970.                                     onchange="mitsumori_simulation('tf_qty','tf_qty');"> 枚
  3971.                                 </div>
  3972.                                 <div style="margin-top:6px;font-size:12px;color:#666;">※ 施工サイズを入力すると必要枚数を自動計算します。サイズが分からない場合は枚数を直接ご指定ください。</div>
  3973.                               </div>
  3974.                             </div>
  3975.                         {% endif %}
  3976.                         <!-- 7: 施工見積(数量買い・基本工事費固定) -->
  3977.                         {% if ProductClass.SaleType.id == 7 %}
  3978.                             {# 個数(物置の daisu と同形式、単位は「個」) #}
  3979.                             <div class="form-group row mt-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3980.                               <label class="col-4 col-form-label">個数</label>
  3981.                               <div class="col-4">
  3982.                                 <div class="input-group mb-3">
  3983.                                   <input type="number" name="suuryou" id="suuryou" class="form-control"
  3984.                                     value="{{ mitsumori_json.suuryou|default('1') }}" min="1" max="100"
  3985.                                     onchange="mitsumori_simulation('suuryou','suuryou');">
  3986.                                   <span class="input-group-text">個</span>
  3987.                                 </div>
  3988.                               </div>
  3989.                               <div class="col-4">
  3990.                                 <button type="button" class="btn btn-info" onclick="suuryou(+1);">+</button>
  3991.                                 <button type="button" class="btn btn-danger" onclick="suuryou(-1);">ー</button>
  3992.                               </div>
  3993.                             </div>
  3994.                         {% endif %}
  3995.                         <!-- 9: 商品のみ購入 -->
  3996.                         {% if ProductClass.SaleType.id == 9 %}
  3997.                             <div class="form-group row mt-2" style="border-bottom:1px solid rgba(0,0,0,.125)">
  3998.                               <label class="col-4 col-form-label">数量</label>
  3999.                               <div class="col-4">
  4000.                                 <div class="input-group mb-3">
  4001.                                   <input type="number" name="quantity_only" id="quantity_only" class="form-control" value="1" min="1" onchange="$('#quantity').val(this.value);">
  4002.                                   <span class="input-group-text">個</span>
  4003.                                 </div>
  4004.                               </div>
  4005.                               <div class="col-4">
  4006.                                 <button type="button" class="btn btn-info" onclick="quantityOnly(+1);">+</button>
  4007.                                 <button type="button" class="btn btn-danger" onclick="quantityOnly(-1);">ー</button>
  4008.                               </div>
  4009.                             </div>
  4010.                         {% endif %}
  4011.                         <div class="row" style="border-bottom:1px solid rgba(0,0,0,.125)"><label class="col-12 col-form-label">取り付け工事のご希望に関してお答えください。</label></div>
  4012.                         {# gs (ゴミステーション, category id=27) では「撤去対応」「残土・ガラ処理」は ex-shop に存在しないため非表示
  4013.                            cg (カーゲート, category id=9) では「残土・ガラ処理」分は撤去金額側に内包済みのため非表示
  4014.                            (撤去オプション自体は残す) #}
  4015.                         {% set is_gs = false %}
  4016.                         {% set is_cg = false %}
  4017.                         {% if Product.ProductCategories is not empty %}
  4018.                             {% for ProductCategory in Product.ProductCategories %}
  4019.                                 {% if ProductCategory.category_id == 27 %}{% set is_gs = true %}{% endif %}
  4020.                                 {% if ProductCategory.category_id == 9 %}{% set is_cg = true %}{% endif %}
  4021.                             {% endfor %}
  4022.                         {% endif %}
  4023.                         {% for i in 0..10 %}
  4024.                             {% if op and op|length >= i+1 %}
  4025.                             {% if op[i]['name'] %}
  4026.                             {% set hide_opt = false %}
  4027.                             {% if is_gs and (op[i]['name'] matches '/撤去/' or op[i]['name'] matches '/残土/') %}
  4028.                                 {% set hide_opt = true %}
  4029.                             {% endif %}
  4030.                             {% if is_cg and op[i]['name'] matches '/残土/' %}
  4031.                                 {% set hide_opt = true %}
  4032.                             {% endif %}
  4033.                             {% if not hide_opt %}
  4034.                             {# price=0 で「解体」「撤去」「設置場所」(wd 等で API 差額未提供) を含むオプションは
  4035.                                選択時に「現場調査後に正式お見積もり」文言を出す. #}
  4036.                             {% set is_removal_unknown = (op[i]['price']|default(0) == 0 or op[i]['price']|default('0') == '0')
  4037.                                                           and (op[i]['name'] matches '/解体/' or op[i]['name'] matches '/撤去/' or op[i]['name'] matches '/設置場所/') %}
  4038.                             {# tf (人工芝, sale_type=6): ex-shop に施工価格がないため「取り付け工事も希望する」選択時に現地調査文言を表示 #}
  4039.                             {% set is_tf_kouji = (ProductClass.SaleType.id == 6 and op[i]['name'] matches '/取り付け工事/') %}
  4040.                             <div class="form-group mt-3 pb-3" data-op-idx="{{ i }}" data-op-name="{{ op[i]['name']|e('html_attr') }}" style="border-bottom:1px solid rgba(0,0,0,.125)">
  4041.                               <div class="rp-section-label">{{ op[i]['name'] }}{% if mitsumori_json and mitsumori_json.op[i] %}: <span>{{ mitsumori_json.op[i] }}</span>{% endif %}</div>
  4042.                               {% if op[i]['comment'] %}<div class="opt-comment" style="font-size:12px;color:#666;margin:4px 0 6px;">{{ op[i]['comment'] }}</div>{% endif %}
  4043.                               <div class="opt-btn-group">
  4044.                                 {# off が空 (= ex-shop に選択肢が 1 つしかない基礎施工等) のときは on 側を
  4045.                                    既定選択にして 2 個目の空ラジオを描画しない. #}
  4046.                                 <label class="opt-btn{% if (mitsumori_json and mitsumori_json.op[i] == op[i]['on']) or not op[i]['off'] %} is-selected{% endif %}"
  4047.                                        onclick="mitsumori_simulation('op{{ i }}','op{{ i }}_1');">
  4048.                                   <input type="radio" name="op{{ i }}" id="op{{ i }}_1" value="{{ op[i]['on'] }}" {% if (mitsumori_json and mitsumori_json.op[i] == op[i]['on']) or not op[i]['off'] %}checked{% endif %}>
  4049.                                   {{ op[i]['on'] }}
  4050.                                 </label>
  4051.                                 {% if op[i]['off'] %}
  4052.                                 <label class="opt-btn{% if mitsumori_json and mitsumori_json.op[i] == op[i]['off'] %} is-selected{% endif %}"
  4053.                                        onclick="mitsumori_simulation('op{{ i }}','op{{ i }}_2');">
  4054.                                   <input type="radio" name="op{{ i }}" id="op{{ i }}_2" value="{{ op[i]['off'] }}" {% if mitsumori_json and mitsumori_json.op[i] == op[i]['off'] %}checked{% endif %}>
  4055.                                   {{ op[i]['off'] }}
  4056.                                 </label>
  4057.                                 {% endif %}
  4058.                               </div>
  4059.                               {% if is_removal_unknown or is_tf_kouji %}
  4060.                               <div class="opt-survey-note" data-op-idx="{{ i }}" style="font-size:12px;color:#c00;margin-top:6px;{% if not (mitsumori_json and mitsumori_json.op[i] == op[i]['on']) %}display:none;{% endif %}">
  4061.                                 ※ 現場調査後に正式お見積もりさせていただきます。
  4062.                               </div>
  4063.                               {% endif %}
  4064.                             </div>
  4065.                             {% endif %}
  4066.                             {% endif %}
  4067.                             {% endif %}
  4068.                         {% endfor %}
  4069.                         {# fe (sale_type=4) ブロックの種類×段数 サブ UI コンテナ.
  4070.                            親オプション「ご希望のフェンス設置方法」 = 「新規にブロック積みを行う」
  4071.                            を選択したときだけ JS (renderFeBlockRadios) で表示される. #}
  4072.                         {% if ProductClass.SaleType.id == 4 and oi and oi.fe_block %}
  4073.                         <div id="fe-block-options" class="form-group mt-3 pb-3" style="display:none;border-bottom:1px solid rgba(0,0,0,.125)"></div>
  4074.                         {% endif %}
  4075.                       </div>
  4076.                       <!-- /.card-body -->
  4077.                     </div>
  4078.                     <form action="{{ url('product_add_cart', {id:Product.id}) }}" method="post" id="form1" name="form1">
  4079.                         {% if Product.stock_find %}
  4080.                             <div class="ec-productRole__actions">
  4081.                                 {% if form.classcategory_id1 is defined %}
  4082.                                     <div class="ec-select">
  4083.                                         {{ form_row(form.classcategory_id1) }}
  4084.                                         {{ form_errors(form.classcategory_id1) }}
  4085.                                     </div>
  4086.                                     {% if form.classcategory_id2 is defined %}
  4087.                                         <div class="ec-select">
  4088.                                             {{ form_row(form.classcategory_id2) }}
  4089.                                             {{ form_errors(form.classcategory_id2) }}
  4090.                                         </div>
  4091.                                     {% endif %}
  4092.                                 {% endif %}
  4093.                                 <div class="ec-numberInput">
  4094.                                     {{ form_widget(form.quantity, { type: 'hidden' }) }}
  4095.                                     {{ form_errors(form.quantity) }}
  4096.                                 </div>
  4097.                             </div>
  4098.                         {% else %}
  4099.                             <div class="ec-productRole__btn">
  4100.                                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  4101.                                     {{ 'ただいま品切れ中です。'|trans }}
  4102.                                 </button>
  4103.                             </div>
  4104.                         {% endif %}
  4105.                         <div class="ec-productRole__btn mt-3">
  4106.                            <button type="submit" id="cart_btn" class="ec-blockBtn--action add-cart">カートに入れる</button>
  4107.                         </div>
  4108.                         {{ form_rest(form) }}
  4109.                     </form>
  4110.                     <div class="ec-modal add-cart-modal">
  4111.                         <div class="ec-modal-overlay">
  4112.                             <div class="ec-modal-wrap add-cart-modal__wrap">
  4113.                                 <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  4114.                                 <div id="ec-modal-header" class="text-center add-cart-modal__header">{{ 'カートに追加しました。'|trans }}</div>
  4115.                                 <div class="ec-modal-box add-cart-modal__box">
  4116.                                     <div class="ec-role add-cart-modal__actions">
  4117.                                         <a href="{{ url('cart') }}" class="ec-inlineBtn--action add-cart-modal__primary">{{ 'カートに進む'|trans }}</a>
  4118.                                         <span class="ec-inlineBtn--cancel add-cart-modal__secondary">{{ '商品検索を続ける'|trans }}</span>
  4119.                                     </div>
  4120.                                 </div>
  4121.                             </div>
  4122.                         </div>
  4123.                     </div>
  4124.                     <div class="ec-productRole__description">{{ Product.description_detail|raw|nl2br }}
  4125.                     </div>
  4126.                     {# SNSシェア #}
  4127.                     <div class="ec-productRole__share">
  4128.                         <ul class="ec-share">
  4129.                             <li class="ec-share__item">
  4130.                                 <a href="https://twitter.com/share?url={{ app.request.uri|url_encode }}&text={{ Product.name|url_encode }}" class="ec-share__link ec-share__link--twitter" target="_blank" rel="noreferrer noopener">
  4131.                                     <i class="fab fa-twitter"></i>
  4132.                                 </a>
  4133.                             </li>
  4134.                             <li class="ec-share__item">
  4135.                                 <a href="https://www.facebook.com/sharer/sharer.php?u={{ app.request.uri|url_encode }}" class="ec-share__link ec-share__link--facebook" target="_blank" rel="noreferrer noopener">
  4136.                                     <i class="fab fa-facebook-f"></i>
  4137.                                 </a>
  4138.                             </li>
  4139.                             <li class="ec-share__item">
  4140.                                 <a href="https://social-plugins.line.me/lineit/share?url={{ app.request.uri|url_encode }}" class="ec-share__link ec-share__link--line" target="_blank" rel="noreferrer noopener">
  4141.                                     <i class="fab fa-line"></i>
  4142.                                 </a>
  4143.                             </li>
  4144.                         </ul>
  4145.                     </div>
  4146.                 </div>
  4147.                 {# ===== スマホ用 見積金額 下部固定バー ===== #}
  4148.                 <div id="sp-mitsumori-bar">
  4149.                     <div class="sp-bar__pricewrap">
  4150.                         <div class="sp-bar__label">合計(工事費・税込)</div>
  4151.                         <div class="sp-bar__price" id="sp-mitsumori-price">---円</div>
  4152.                     </div>
  4153.                     <button type="button" class="sp-bar__detail-btn"
  4154.                             onclick="openSpMitsumoriDetail();" title="お見積りの詳細(内訳)を表示">
  4155.                         <i class="far fa-file-alt"></i>
  4156.                         <span>詳細</span>
  4157.                     </button>
  4158.                     <button type="button" class="sp-bar__btn"
  4159.                             onclick="document.getElementById('cart_btn2') && document.getElementById('cart_btn2').click();">
  4160.                         <i class="fas fa-shopping-cart"></i>
  4161.                         <span class="sp-bar__btn-label">カートへ</span>
  4162.                         {% set spTotalQty = get_carts_total_quantity() %}
  4163.                         {% if spTotalQty > 0 %}
  4164.                             <span class="sp-bar__cart-badge">{{ spTotalQty|number_format }}</span>
  4165.                         {% endif %}
  4166.                     </button>
  4167.                     <a href="{{ url('homepage') }}" class="sp-bar__home-btn" title="トップページへ">
  4168.                         <i class="fas fa-home"></i>
  4169.                     </a>
  4170.                 </div>
  4171.                 {# ===== スマホ用 お見積りの詳細 ボトムシート ===== #}
  4172.                 {# タップ時に現在の内訳カード(.mitsumori-card-pc)の中身を複製して表示する。
  4173.                    価格計算には触れず、ライブ同期済みの表示値をそのまま見せる方式。 #}
  4174.                 <div id="sp-mitsumori-detail" class="sp-detail-sheet" aria-hidden="true">
  4175.                     <div class="sp-detail-sheet__overlay" onclick="closeSpMitsumoriDetail();"></div>
  4176.                     <div class="sp-detail-sheet__panel" role="dialog" aria-label="お見積りの詳細">
  4177.                         <div class="sp-detail-sheet__header">
  4178.                             <span class="sp-detail-sheet__title">お見積りの詳細</span>
  4179.                             <button type="button" class="sp-detail-sheet__close" onclick="closeSpMitsumoriDetail();" aria-label="閉じる">&times;</button>
  4180.                         </div>
  4181.                         <div class="sp-detail-sheet__body" id="sp-detail-body"></div>
  4182.                         <div class="sp-detail-sheet__footer">
  4183.                             <button type="button" class="sp-detail-sheet__invoice"
  4184.                                     onclick="closeSpMitsumoriDetail(); document.getElementById('mitsumori_btn') && document.getElementById('mitsumori_btn').click();">見積書を表示</button>
  4185.                             <button type="button" class="sp-detail-sheet__cart"
  4186.                                     onclick="closeSpMitsumoriDetail(); document.getElementById('cart_btn2') && document.getElementById('cart_btn2').click();">カートに入れる</button>
  4187.                         </div>
  4188.                     </div>
  4189.                 </div>
  4190.                 {# tg カテゴリ用: block 別オプション差額ラジオ (W/D 確定後に JS が動的描画) #}
  4191.                 <div id="tg-options" class="tg-options-container col-12"></div>
  4192.                 <div class="card col-12 collapsed-card sticky-top float-right mitsumori-card-pc">
  4193.                     <div class="card-header">
  4194.                       <h3 class="card-title">現在のお見積り額</h3>
  4195.                       <div class="card-tools">
  4196.                         <span class="float-left" id="mitsumori_message">395000円</span>
  4197.                         <button type="button" class="btn btn-tool btn-mitsumori-toggle" data-card-widget="collapse" title="詳細を表示">
  4198.                           <span class="toggle-icon">▼ 詳細</span>
  4199.                         </button>
  4200.                       </div>
  4201.                     </div>
  4202.                     <div class="card-body p-0">
  4203.                       <ul class="nav nav-pills flex-column">
  4204.                         <li class="nav-item active">
  4205.                           <a class="nav-link">
  4206.                             <i class="far fa-file-alt"></i> 合計(工事費・税込)
  4207.                             <span class="float-right" id="mitsumori_goukei">395,000円</span>
  4208.                           </a>
  4209.                         </li>
  4210.                         <li class="nav-item active">
  4211.                           <a class="nav-link">
  4212.                             <i class="far fa-file-alt"></i> 商品価格
  4213.                             <span class="float-right" id="mitsumori_price">307,008円</span>
  4214.                           </a>
  4215.                         </li>
  4216.                         {# sale_type=2 (補助金窓) ではカタログ価格軸を使わないので非表示. JS 側で #maker_price には "---円" を入れる. #}
  4217.                         {% if ProductClass.SaleType.id != 2 %}
  4218.                         <li class="nav-item">
  4219.                           <a class="nav-link">
  4220.                             &nbsp;&nbsp;<i class="far fa-file-alt"></i> カタログ価格
  4221.                             <span class="float-right" id="maker_price">479,700円</span>
  4222.                           </a>
  4223.                         </li>
  4224.                         {% else %}
  4225.                         {# sale_type=2 でも JS が #maker_price を参照するので hidden で残す #}
  4226.                         <span id="maker_price" style="display:none;">---円</span>
  4227.                         {% endif %}
  4228.                         <li class="nav-item">
  4229.                           <a class="nav-link">
  4230.                             &nbsp;&nbsp;<i class="far fa-file-alt"></i>
  4231.                             {% if ProductClass.SaleType.id == 2 %}補助金(割引額){% else %}お値引き{% endif %}
  4232.                             <span class="float-right" id="mitsumori_off">-172,692円</span>
  4233.                           </a>
  4234.                         </li>
  4235.                         {# 補助金窓のみ: 当店が申請代行する旨を補助金行の直下に小さく表示 (消費者の手続き勘違い防止) #}
  4236.                         {% if ProductClass.SaleType.id == 2 %}
  4237.                         <li class="nav-item">
  4238.                           <div style="padding:4px 12px 8px;color:#6c757d;font-size:11px;line-height:1.4;">
  4239.                             ※当店が補助金事業者として申請代行し、契約代金に充当します
  4240.                           </div>
  4241.                         </li>
  4242.                         {% endif %}
  4243.                         <li class="nav-item">
  4244.                           <a class="nav-link">
  4245.                             <i class="far fa-file-alt"></i> 基本工事費
  4246.                             <span class="float-right" id="mitsumori_ct">53,250円</span>
  4247.                           </a>
  4248.                         </li>
  4249.                         <li class="nav-item">
  4250.                           <a class="nav-link">
  4251.                             <i class="far fa-file-alt"></i> 施工オプション
  4252.                             <span class="float-right"id="mitsumori_option">6,297円</span>
  4253.                           </a>
  4254.                         </li>
  4255.                       </ul>
  4256.                     </div>
  4257.                     <div class="card-footer">
  4258.                         <button type="button" id="mitsumori_btn" class="btn btn-info" data-toggle="modal" data-target="#modal-mitsumori">
  4259.                           見積書表示
  4260.                         </button>
  4261.                         <button type="submit" id="cart_btn2" class="btn btn-info add-cart">カートに入れる</button>
  4262.                     </div>
  4263.                 </div>
  4264.             </div>
  4265.         </div>
  4266.     </div>
  4267.   <div class="modal" id="modal-mitsumori">
  4268.     <div class="modal-dialog modal-mitsumori" style="max-width:1000px">
  4269.       <div class="modal-content">
  4270.         <div class="modal-header">
  4271.           <h4 class="modal-title">お見積書</h4>
  4272.           <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  4273.             <span aria-hidden="true">&times;</span>
  4274.           </button>
  4275.         </div>
  4276.         <div class="modal-body">
  4277.             <div class="invoice p-3 mb-5" style="max-width:1000px; margin:auto;">
  4278.               <!-- title row -->
  4279.               <div class="row">
  4280.                 <div class="col-12">
  4281.                   <h2>概算お見積書 
  4282.                     <small class="float-right" style="font-size:14px;">発行日: 2025/03/14</small>
  4283.                   </h2>
  4284.                 </div>
  4285.                 <!-- /.col -->
  4286.               </div>
  4287.               <!-- info row -->
  4288.               <div class="row invoice-info">
  4289.                 <div class="col-sm-8 invoice-col">
  4290.                   <h3>お客様</h3>
  4291.                   <span>下記の通り、お見積もり申し上げます。</span>
  4292.                   <br />
  4293.                   <br / >
  4294.                   <br />
  4295.                   <h2>お見積金額: <span id="mitsumori_kei">399,080円</span></h2>
  4296.                   <span>
  4297.                     <br/>
  4298.                     <br/>
  4299.                     <br/>
  4300.                     <br/>
  4301.                   </span>
  4302.                 </div>
  4303.                 <div class="col-sm-4 invoice-col">
  4304.                   <p>
  4305.                     <img alt="" src="/html/user_data/js/images/logo.png" style="width: 260px; max-width: 100%; max-height: 10mm;">
  4306.                   </p>
  4307.                   <p>有限会社プラス</p>
  4308.                   <p>〒400-0334</p>
  4309.                   <p>山梨県南アルプス市藤田1450番地2</p>
  4310.                   <p>TEL: 055-284-6480</p>
  4311.                   <img alt="" src="/html/user_data/js/images/seal.svg" style="z-index: 2; position: absolute; width: 21mm; left: 58mm; top: 36mm;">
  4312.                 </div>
  4313.                 <!-- /.col -->
  4314.                 <!-- /.col -->
  4315.               </div>
  4316.               <!-- /.row -->
  4317.               <!-- Table row -->
  4318.               <div class="row">
  4319.                 <div class="col-12 table-responsive">
  4320.                   <table class="table table-striped">
  4321.                     <thead>
  4322.                       <tr>
  4323.                         <th>項目</th>
  4324.                         <th>数量</th>
  4325.                         <th>単位</th>
  4326.                         <th>単価</th>
  4327.                         <th>小計</th>
  4328.                       </tr>
  4329.                     </thead>
  4330.                     <tbody>
  4331.                       <tr>
  4332.                         <td id="mitsumori_item_name">{{ Product.name }}</td>
  4333.                         <td>1</td>
  4334.                         <td>式</td>
  4335.                         <td id="mitsumori_price_01">352,800</td>
  4336.                         <td id="mitsumori_price_02">352,800</td>
  4337.                       </tr>
  4338.                       <tr>
  4339.                         <td>基本工事費</td>
  4340.                         <td>1</td>
  4341.                         <td>式</td>
  4342.                         <td id="mitsumori_ct_01">10,000</td>
  4343.                         <td id="mitsumori_ct_02">10,000</td>
  4344.                       </tr>
  4345.                       <tr>
  4346.                         <td>残土・ガラ処理</td>
  4347.                         <td>1</td>
  4348.                         <td>式</td>
  4349.                         <td>0円</td>
  4350.                         <td></td>
  4351.                       </tr>
  4352.                       <tr>
  4353.                         <td> </td>
  4354.                         <td></td>
  4355.                         <td></td>
  4356.                         <td></td>
  4357.                         <td></td>
  4358.                       </tr>
  4359.                     </tbody>
  4360.                   </table>
  4361.                 </div>
  4362.                 <!-- /.col -->
  4363.               </div>
  4364.               <!-- /.row -->
  4365.               <div class="row">
  4366.                 <!-- accepted payments column -->
  4367.                 <div class="col-6">
  4368.                   <p class="lead">お支払い方法</p>
  4369.                   <p class="text-muted well well-sm shadow-none" style="margin-top: 10px;">銀行振込、クレジットカード決済、PAYPAY決済
  4370.                     <br>銀行振込:山梨中央銀行 白根支店 普通口座 391402
  4371.                     <br>※商品代金と工事代金の総額が金100万円(税込)を超える場合、着手金として代金の半額をご契約後お支払いいただきます。 
  4372.                   </p>
  4373.                 </div>
  4374.                 <!-- /.col -->
  4375.                 <div class="col-6">
  4376.                   <div class="table-responsive">
  4377.                     <table class="table">
  4378.                       <tbody>
  4379.                         <tr>
  4380.                           <th style="width:50%">小計:</th>
  4381.                           <td id="mitsumori_shoukei">362,800</td>
  4382.                         </tr>
  4383.                         <tr>
  4384.                           <th>消費税 (10%)</th>
  4385.                           <td id="mitsumori_tax">36,280</td>
  4386.                         </tr>
  4387.                         <tr>
  4388.                           <th>合計:</th>
  4389.                           <td id="mitsumori_goukei_02">399,080</td>
  4390.                         </tr>
  4391.                       </tbody>
  4392.                     </table>
  4393.                   </div>
  4394.                 </div>
  4395.                 <!-- /.col -->
  4396.               </div>
  4397.               <!-- /.row -->
  4398.             </div>
  4399.         </div>
  4400.         <div class="modal-footer justify-content-between">
  4401.                   {# PDF出力: mitsumori_json を POST して PDF ダウンロード #}
  4402.                   <form method="post" action="{{ url('mitsumori_pdf') }}" target="_blank" id="pdf_download_form">
  4403.                     <input type="hidden" name="_token" value="{{ csrf_token('mitsumori_pdf') }}">
  4404.                     <input type="hidden" name="mitsumori_json" id="pdf_mitsumori_json">
  4405.                     <button type="submit" class="btn btn-primary float-right" style="margin-right: 5px;" onclick="syncPdfJson();">
  4406.                       <i class="fas fa-download"></i>PDF出力
  4407.                     </button>
  4408.                   </form>
  4409.                   <button type="submit" id="cart_btn3" class="btn btn-info add-cart">カートに入れる</button>
  4410.         </div>
  4411.       </div>
  4412.       <!-- /.modal-content -->
  4413.     </div>
  4414.     <!-- /.modal-dialog -->
  4415.   </div>
  4416.   <!-- /.modal -->
  4417.     <!-- Image zoom modal: custom lightweight lightbox (no CDN dependency) -->
  4418.     <div id="img-modal" role="dialog" aria-modal="true" aria-label="画像拡大">
  4419.         <button id="img-modal__close" aria-label="閉じる">&times;</button>
  4420.         <button id="img-modal__prev" aria-label="前の画像">&#10094;</button>
  4421.         <img id="img-modal__img" src="" alt="">
  4422.         <button id="img-modal__next" aria-label="次の画像">&#10095;</button>
  4423.     </div>
  4424.     <style>
  4425.     #img-modal {
  4426.         display: none;
  4427.         position: fixed;
  4428.         inset: 0;
  4429.         z-index: 9999;
  4430.         background: rgba(0,0,0,0.88);
  4431.         align-items: center;
  4432.         justify-content: center;
  4433.         cursor: zoom-out;
  4434.     }
  4435.     #img-modal.is-open { display: flex; }
  4436.     #img-modal__img {
  4437.         max-width: 92vw;
  4438.         max-height: 88vh;
  4439.         object-fit: contain;
  4440.         border-radius: 4px;
  4441.         cursor: default;
  4442.         user-select: none;
  4443.         touch-action: pinch-zoom;
  4444.         display: block;
  4445.     }
  4446.     #img-modal__close {
  4447.         position: absolute;
  4448.         top: 14px;
  4449.         right: 18px;
  4450.         font-size: 38px;
  4451.         color: #fff;
  4452.         cursor: pointer;
  4453.         background: none;
  4454.         border: none;
  4455.         padding: 0;
  4456.         line-height: 1;
  4457.         z-index: 1;
  4458.         opacity: 0.85;
  4459.     }
  4460.     #img-modal__close:hover { opacity: 1; }
  4461.     #img-modal__prev,
  4462.     #img-modal__next {
  4463.         position: absolute;
  4464.         top: 50%;
  4465.         transform: translateY(-50%);
  4466.         font-size: 36px;
  4467.         color: #fff;
  4468.         cursor: pointer;
  4469.         background: rgba(0,0,0,0.32);
  4470.         border: none;
  4471.         padding: 10px 16px;
  4472.         line-height: 1;
  4473.         border-radius: 6px;
  4474.         z-index: 1;
  4475.         opacity: 0.8;
  4476.         user-select: none;
  4477.     }
  4478.     #img-modal__prev:hover, #img-modal__next:hover { opacity: 1; }
  4479.     #img-modal__prev { left: 12px; }
  4480.     #img-modal__next { right: 12px; }
  4481.     @media (max-width: 767px) {
  4482.         #img-modal__prev, #img-modal__next { font-size: 28px; padding: 8px 12px; }
  4483.     }
  4484.     </style>
  4485.     <script>
  4486.     (function(){
  4487.         var images = [];
  4488.         var current = 0;
  4489.         // Collect original (non-cloned) slide images at click time.
  4490.         // After Slick init, slides are wrapped in .slick-slide; clones have .slick-cloned.
  4491.         function collectImages() {
  4492.             images = [];
  4493.             var $slides = $('.item_visual .slick-slide:not(.slick-cloned)');
  4494.             if (!$slides.length) {
  4495.                 // Slick not yet initialized (fallback)
  4496.                 $slides = $('.item_visual .slide-item');
  4497.             }
  4498.             $slides.each(function() {
  4499.                 var $a = $(this).find('a.js-zoom');
  4500.                 if ($a.length) {
  4501.                     images.push({ src: $a.attr('href'), alt: $a.find('img').attr('alt') || '' });
  4502.                 }
  4503.             });
  4504.         }
  4505.         function showImage(idx) {
  4506.             current = ((idx % images.length) + images.length) % images.length;
  4507.             $('#img-modal__img').attr({ src: images[current].src, alt: images[current].alt });
  4508.         }
  4509.         function openModal(href) {
  4510.             collectImages();
  4511.             if (!images.length) return;
  4512.             var idx = 0;
  4513.             for (var i = 0; i < images.length; i++) {
  4514.                 if (images[i].src === href) { idx = i; break; }
  4515.             }
  4516.             showImage(idx);
  4517.             $('#img-modal').addClass('is-open');
  4518.             $('body').css('overflow', 'hidden');
  4519.         }
  4520.         function closeModal() {
  4521.             $('#img-modal').removeClass('is-open');
  4522.             $('body').css('overflow', '');
  4523.         }
  4524.         // Click handler: works for both original and Slick-cloned anchors
  4525.         $(document).on('click', '.item_visual a.js-zoom', function(e) {
  4526.             e.preventDefault();
  4527.             openModal($(this).attr('href'));
  4528.         });
  4529.         // Close on backdrop click
  4530.         $('#img-modal').on('click', function(e) {
  4531.             if (e.target === this) closeModal();
  4532.         });
  4533.         $('#img-modal__close').on('click', closeModal);
  4534.         $('#img-modal__prev').on('click', function(e) { e.stopPropagation(); showImage(current - 1); });
  4535.         $('#img-modal__next').on('click', function(e) { e.stopPropagation(); showImage(current + 1); });
  4536.         // Keyboard navigation
  4537.         $(document).on('keydown', function(e) {
  4538.             if (!$('#img-modal').hasClass('is-open')) return;
  4539.             if (e.key === 'Escape') closeModal();
  4540.             if (e.key === 'ArrowLeft') showImage(current - 1);
  4541.             if (e.key === 'ArrowRight') showImage(current + 1);
  4542.         });
  4543.         // Touch swipe (horizontal only)
  4544.         var _tx = 0;
  4545.         var $modal = document.getElementById('img-modal');
  4546.         $modal.addEventListener('touchstart', function(e) {
  4547.             _tx = e.changedTouches[0].clientX;
  4548.         }, { passive: true });
  4549.         $modal.addEventListener('touchend', function(e) {
  4550.             var dx = e.changedTouches[0].clientX - _tx;
  4551.             if (Math.abs(dx) > 48) {
  4552.                 dx < 0 ? showImage(current + 1) : showImage(current - 1);
  4553.             }
  4554.         }, { passive: true });
  4555.     })();
  4556.     </script>
  4557. {% endblock %}