/* ===================================================================
   nagare.css — ご契約の流れ（Flow）ページ専用スタイル（完全版）
   Rewritten (complete): 2025-08-18 06:07:10 UTC (15:07:10 JST)
   変更方針：
     - 外見が変わらない範囲で重複・順序を整理（機能同等）
     - PC幅で #contract-flow 上部の余白が消える不具合を修正
       （768px以上でも padding-top を維持）
     - scroll に関する指定は追加しない（common.css 管理方針を尊重）
     - text-wrap は pretty を使用（balance は不使用）
   役割：
     - 手順カード（イラスト＋テキスト）のレイアウトと装飾
     - ステップ間の連結ライン（縦/横）
     - ジグザグ（上3つ→下段に残り）レイアウト
     - モバイル最適化、A11y 配慮、印刷
   依存：
     - common.css のトークン（--content-max-width, --brand, --danger など）
   =================================================================== */


/* ----------------------------------------------------------- */
/* 0. Page Tokens                                              */
/* ----------------------------------------------------------- */
:root {
  --flow-bg: #fff;
  --flow-odd: #f5fff6;
  --flow-even: #e9f4ff;
  --flow-arrow: var(--danger, #c50f0f);
  --flow-border: #e6e6e6;
  --flow-radius: 12px;
  --flow-gap: 4rem;
  --flow-img-w: 150px;
  --flow-text-max: 36ch;

  /* フォント（common 未定義時は流体で保険） */
  --flow-fs-base: var(--fs-base, clamp(1.6rem, 1.5rem + 0.3vw, 1.8rem));
  --flow-fs-title: var(--fs-title, clamp(2rem, 1.6rem + 1.2vw, 2.6rem));

  /* フォーカス（common 優先） */
  --flow-focus-ring: var(--focus-ring, 3px solid rgba(0, 117, 201, 0.6));
}


/* ----------------------------------------------------------- */
/* 1. Section Wrapper                                          */
/* ----------------------------------------------------------- */
.contract-flow {
  /* 上側に十分な余白を常時確保（マージンの相殺を避けるため padding を採用） */
  padding-block: 2rem 0;
  margin-block-start: 0;
  background: var(--clr-bg-section, var(--flow-bg));
}
.contract-flow .container {
  margin-inline: auto;       /* 中央寄せ */
  margin-block-end: 1rem;    /* 下だけ余白 */
}


/* PC 幅でも上余白を維持（従来の padding:0 上書きを廃止） */
@media (min-width: 768px) {
  .contract-flow {
    /* 見た目維持のため margin は 0 を踏襲。padding-top は残す（バグ修正） */
    padding-block: 2rem 0;
    margin: 0;
  }
}


/* ----------------------------------------------------------- */
/* 2. Flow Grid（デフォルト：自動段組）                       */
/* ----------------------------------------------------------- */
.flow-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr; /* SPは縦並び */
  gap: var(--flow-gap);
}


/* ----------------------------------------------------------- */
/* 3. Flow Item + 既定コネクタ                                 */
/* ----------------------------------------------------------- */
.flow-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;

  padding: 1.2rem;
  border-radius: var(--flow-radius);
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  outline: none;
}
.flow-item:nth-child(odd) {  background: var(--flow-odd);  }
.flow-item:nth-child(even) { background: var(--flow-even); }

.flow-item:focus-within {
  outline: var(--flow-focus-ring);
  outline-offset: 2px;
}

/* 既定の縦/横コネクタ（zigzag では無効化し、後段で描き直す） */
.flow-item::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(-1 * var(--flow-gap) / 2);
  transform: translateX(-50%);
  width: 2px;
  height: var(--flow-gap);
  background: var(--flow-arrow);
}
@media (min-width: 768px) {
  .flow-item::after {
    top: 50%;
    bottom: auto;
    left: auto;
    right: calc(-1 * var(--flow-gap) / 2);
    transform: translateY(-50%);
    width: var(--flow-gap);
    height: 2px;
  }
}
.flow-item:last-child::after { display: none; }

.flow-item.is-current {
  box-shadow:
    0 0 0 3px var(--accent-blue, #0075c9) inset,
    0 2px 10px rgba(0, 0, 0, 0.06);
}


/* ----------------------------------------------------------- */
/* 4. Illustration & Text                                      */
/* ----------------------------------------------------------- */
.flow-illust {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--flow-img-w) * 0.9);
}
.flow-illust img {
  width: clamp(120px, 18vw, var(--flow-img-w));
  height: auto;
}
.flow-text {
  margin-top: 1rem;
  font-size: var(--flow-fs-base);
  line-height: 1.7;
  max-width: var(--flow-text-max);
  white-space: normal;
}
.flow-note {
  display: block;
  margin-top: 0.5rem;
  font-weight: 700;
  color: var(--danger, #c50f0f);
}


/* ----------------------------------------------------------- */
/* 5. Accessibility / Preferences                              */
/* ----------------------------------------------------------- */
@media (prefers-contrast: more) {
  .flow-item {
    box-shadow: none;
    border: 2px solid #000;
    background: #fff !important;
  }
  .flow-item::after { background: #000; }
  .flow-note { color: #000; }
}
@media (forced-colors: active) {
  .flow-item { border: 1px solid CanvasText; }
  .flow-item::after { background: CanvasText; }
}
@media (prefers-reduced-motion: reduce) {
  .flow-item,
  .flow-item::after {
    transition: none !important;
  }
}


/* ----------------------------------------------------------- */
/* 6. Print                                                    */
/* ----------------------------------------------------------- */
@media print {
  .contract-flow { padding: 0; }
  .flow-list { gap: 1.2rem; }
  .flow-item {
    box-shadow: none;
    background: #fff !important;
    border: 1px solid #ccc;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .flow-item::after { display: none; }
  .flow-illust img { max-width: 100%; }
}


/* ----------------------------------------------------------- */
/* 7. 2-row Zigzag（上3つ → 下段に残り：矢印描き直し）        */
/* ----------------------------------------------------------- */
.flow-list--zigzag {
  --arrow-color: var(--flow-arrow, #d50000);
  --arrow-thickness: 2px;
  --arrow-head: 8px; /* 三角の片辺 長さ */

  display: grid;
  gap: var(--flow-gap);
  grid-template-columns: repeat(3, minmax(0, 1fr)); /* 上段3カラム固定 */
}

/* 既定のコネクタはこの中では消す（描き直すため） */
.flow-list--zigzag .flow-item::after,
.flow-list--zigzag .flow-item::before {
  content: none;
}

/* PC/タブレット：3×2 の見た目配置 + 矢印 */
@media (min-width: 768px) {
  /* 配置（DOM順そのまま、見た目だけ整列） */
  .flow-list--zigzag .flow-item:nth-child(1) { grid-column: 1; grid-row: 1; }
  .flow-list--zigzag .flow-item:nth-child(2) { grid-column: 2; grid-row: 1; }
  .flow-list--zigzag .flow-item:nth-child(3) { grid-column: 3; grid-row: 1; }
  .flow-list--zigzag .flow-item:nth-child(4) { grid-column: 3; grid-row: 2; } /* ③の真下 */
  .flow-list--zigzag .flow-item:nth-child(5) { grid-column: 2; grid-row: 2; } /* 左へ */
  .flow-list--zigzag .flow-item:nth-child(6) { grid-column: 1; grid-row: 2; }

  /* 1→2（右矢印） */
  .flow-list--zigzag .flow-item:nth-child(1)::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: calc(var(--flow-gap) - var(--arrow-head));
    height: var(--arrow-thickness);
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:nth-child(1)::before {
    content: "";
    position: absolute;
    top: 50%;
    left: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateY(-50%);
    width: 0; height: 0;
    border-left: var(--arrow-head) solid var(--arrow-color); /* ▶ */
    border-top: var(--arrow-head) solid transparent;
    border-bottom: var(--arrow-head) solid transparent;
  }

  /* 2→3（右矢印） */
  .flow-list--zigzag .flow-item:nth-child(2)::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: calc(var(--flow-gap) - var(--arrow-head));
    height: var(--arrow-thickness);
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:nth-child(2)::before {
    content: "";
    position: absolute;
    top: 50%;
    left: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateY(-50%);
    width: 0; height: 0;
    border-left: var(--arrow-head) solid var(--arrow-color); /* ▶ */
    border-top: var(--arrow-head) solid transparent;
    border-bottom: var(--arrow-head) solid transparent;
  }

  /* 3↓4（下矢印） */
  .flow-list--zigzag .flow-item:nth-child(3)::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    width: var(--arrow-thickness);
    height: calc(var(--flow-gap) - var(--arrow-head));
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:nth-child(3)::before {
    content: "";
    position: absolute;
    left: 50%;
    top: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateX(-50%);
    width: 0; height: 0;
    border-top: var(--arrow-head) solid var(--arrow-color); /* ▼ */
    border-left: var(--arrow-head) solid transparent;
    border-right: var(--arrow-head) solid transparent;
  }

  /* 4→5（左矢印） */
  .flow-list--zigzag .flow-item:nth-child(4)::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 100%;
    transform: translateY(-50%);
    width: calc(var(--flow-gap) - var(--arrow-head));
    height: var(--arrow-thickness);
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:nth-child(4)::before {
    content: "";
    position: absolute;
    top: 50%;
    right: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateY(-50%);
    width: 0; height: 0;
    border-right: var(--arrow-head) solid var(--arrow-color); /* ◀ */
    border-top: var(--arrow-head) solid transparent;
    border-bottom: var(--arrow-head) solid transparent;
  }

  /* 5→6（左矢印） */
  .flow-list--zigzag .flow-item:nth-child(5)::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 100%;
    transform: translateY(-50%);
    width: calc(var(--flow-gap) - var(--arrow-head));
    height: var(--arrow-thickness);
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:nth-child(5)::before {
    content: "";
    position: absolute;
    top: 50%;
    right: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateY(-50%);
    width: 0; height: 0;
    border-right: var(--arrow-head) solid var(--arrow-color); /* ◀ */
    border-top: var(--arrow-head) solid transparent;
    border-bottom: var(--arrow-head) solid transparent;
  }
}

/* スマホ：縦並びで下向き矢印に統一 */
@media (max-width: 767px) {
  .flow-list--zigzag { grid-template-columns: 1fr; }
  .flow-list--zigzag .flow-item { position: relative; }

  .flow-list--zigzag .flow-item:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    width: var(--arrow-thickness);
    height: calc(var(--flow-gap) - var(--arrow-head));
    background: var(--arrow-color);
  }
  .flow-list--zigzag .flow-item:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 50%;
    top: calc(100% + (var(--flow-gap) - var(--arrow-head)));
    transform: translateX(-50%);
    width: 0; height: 0;
    border-top: var(--arrow-head) solid var(--arrow-color);
    border-left: var(--arrow-head) solid transparent;
    border-right: var(--arrow-head) solid transparent;
  }
}

/* PC：最終ステップの矢印（頭・線）を抑止（5ステップ想定） */
@media (min-width: 768px) {
  .flow-list--zigzag .flow-item:last-child::before,
  .flow-list--zigzag .flow-item:last-child::after {
    content: none !important;
    display: none !important;
  }
}


/* -----------------------------------------------------------
   8. SP最適化：イラスト周りの余白と回り込み（1〜5共通）
   - figure の UA 既定 margin と min-height を抑止
   - 1〜5番カードのみイラストを左フロートし、テキストを回り込ませる
   - 段落の右側の狭さを解消（--flow-text-max を 100% に）
----------------------------------------------------------- */
@media (max-width: 767px) {
  /* figure の上下余白を圧縮 */
  .flow-illust {
    margin-block: 0;
    min-height: 0; /* 既定: calc(var(--flow-img-w) * 0.9) を打ち消し */
  }

  /* 1〜5番のカードのみ回り込み適用（将来増加にも安全） */
  .flow-list .flow-item:nth-of-type(-n+5) {
    display: flow-root;  /* flex 解除 + BFC化で高さ抜け防止 */
    text-align: left;
    --flow-text-max: 100%; /* 36ch 制限を当該カード内だけ解除 */
  }
  .flow-list .flow-item:nth-of-type(-n+5) .flow-illust {
    float: left;
    display: block;      /* flex指定を打ち消し */
    margin: 0 0.8rem 0.4rem 0;
  }
  .flow-list .flow-item:nth-of-type(-n+5) .flow-illust img {
    /* 320px幅→約92px, 375px→約105px, 428px→上限118px */
    width: clamp(92px, 28vw, 118px);
  }

  /* 画像下の説明文との距離を詰める */
  .flow-list .flow-item:nth-of-type(-n+5) .flow-text {
    margin-top: 0;                 /* 画像直後は 0 に */
    max-width: var(--flow-text-max);
    white-space: normal;             /* balance は未使用 */
  }

  /* 回り込みを使わないカード（6番以降）では従来どおり少し余白 */
  .flow-list .flow-item:nth-of-type(n+6) .flow-text {
    margin-top: 0.6rem;
    white-space: normal;
  }
}
