/* --- [1. グラフ表示エリアの土台] --- */

/* グラフを囲む外枠：中央寄せとサイズ固定 */
.chart-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px #9E9E9E;
    
    /* 上の余白を 60px に増やし、下は 30px、左右は auto（中央寄せ）に設定 */
    margin: 20px auto 30px auto; 
    
    width: 1000px;
    height: 700px;
    position: relative;
    
    /* はみ出し防止 */
    display: flex;
    flex-direction: column;
    
    /* 前の要素（フォーム）との間に明確な区切りを入れたい場合は追加 */
    border: 1px solid #9e9e9e;
}

/* ラッパー：PCでは単なる透明な箱として振る舞う */
.chart-split-row {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 軸エリア：PCでは「存在しない」ものとして消す */
.chart-axis-col-left,
.chart-axis-col-right {
    display: none !important; 
}

/* 右側のメインエリア：PCでは親要素いっぱいに広げるだけ */
.chart-main-col {
    width: 100%;
    height: 100%;
    overflow: visible; /* スクロールさせない */
}

/* --- スマホ版（768px以下）の設定 --- */
@media (max-width: 768px) {
    /* グラフ全体をスクロールに追従させる */
    .sim_wrap {
        position: relative;
        z-index: 50;      /* 他のコンテンツより前面、ツールチップ(100)より背面 */
        background: #fff; /* 背景を白にして下の文字が透けないようにする */
    }
    .graph_wrap {
      position: relative;
      /* border-bottom: 1px solid #ddd; 境界線を分かりやすく */
    }
    .graph_wrap::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 3%;
      right: 3%;
      height: 1.5px;
      background: #ddd;
    }
    
    .chart-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 5px 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    /* 3番目：グラフ本体 */
    .chart-split-row {
        order: 2;
        display: flex;
        align-items: flex-start;
        width: 100%;
        height: 250px;
        position: relative;
    }

    /* 左右の軸エリア共通設定 */
    .chart-axis-col-left,
    .chart-axis-col-right {
        display: block !important;
        width: 35px;
        height: 100%;
        flex-shrink: 0;
        background: #fff;
        z-index: 10;
    }
    .chart-axis-col-left { border-right: 1px solid #eee; }
    .chart-axis-col-right { border-left: 1px solid #eee; }

    /* 中央のスクロールエリア */
    .chart-main-col {
        flex-grow: 1;
        width: calc(100% - 70px);
        height: 100%;
        overflow-x: auto;  /* 横スクロールを許可 */
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* メイングラフのCanvasを強制的に横長にする */
    .chart-main-col canvas#mixedChart {
        min-width: 800px !important;
        width: 800px !important;
        height: 250px !important;
        display: block;
    }

    /* 4. ツールチップを最前面へ（Stickyやヘッダーより上に） */
    #chartjs-tooltip {
        z-index: 100 !important;
    }

    /* 2番目：詳細数値（凡例エリア）★グラフの上に配置 */
    .custom-legend {
        order: 1;
        margin: 5px 5px 10px 5px !important;
        background: #f8f9fa;
        border-radius: 4px;
        padding: 3px !important;
        min-height: 80px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-content: flex-start;
        flex: 0 0 auto;
    }

    /* 「◯年目」というタイトル部分 */
    .legend-title {
        width: 100%;
        text-align: center;
        font-weight: bold;
        color: #11365A;
        margin-bottom: 3px;
    }

    /* 個別の項目（実質年間収入、支出など） */
    .legend-item {
      font-size: 12px;
      margin: 2px 8px;
      display: inline-flex;
      align-items: center;
      white-space: nowrap;
      /* 折り返し防止 */
    }
    
    /* 各項目の色付きアイコン(iタグ) */
    .legend-item i {
      display: inline-block;
      width: 10px;
      height: 10px;
      margin-right: 5px;
      border-radius: 2px;
    }
    
    /* 金額などの数値部分 */
    .legend-value {
      font-weight: bold;
      margin-left: 3px;
    }

    .legend-color {
        width: 12px;
        height: 12px;
        margin-right: 5px;
        border-radius: 2px;
    }
}

/* チャートのタイトル */
.chart-title {
    text-align: center;
    margin: 15px 0;
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
}

/* --- [2. グラフ操作・トグル部品] --- */

/* グラフの表示条件を切り替えるスイッチのコンテナ */
.toggle-wrapper {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
}

.toggle-container {
    background-color: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 5px;
    display: flex;
    align-items: center;
    padding: 8px 15px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
}

.toggle-container input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

/* --- [3. 数値の状態による色分け（グラフ補助）] --- */

/* キャッシュフローの正負：ラベルや凡例で使用 */
.cf-positive-green {
    color: #28a745 !important;
    font-weight: bold;
}
.cf-negative-red {
    color: #dc3545 !important;
    font-weight: bold;
}

/* 非表示制御用（グラフのみモードの切り替え等） */
.hidden-column {
    display: none !important;
}

/* --- [4. グラフ用キャンバスのレスポンシブ対応] --- */
canvas {
    max-width: 100%;
}

#chartjs-tooltip {
    z-index: 2000 !important; /* script.jsの指定と合わせる */
    pointer-events: none;
    transition: opacity 0.2s ease; 
}

#chartjs-tooltip table {
  background: #fff;
  border: 1px solid #11365A;
}
#chartjs-tooltip table thead th {
  padding: 0.4em 0 0.2em;
  font-size: 15px;
  font-weight: 400;
  background: #11365A;
  border: 1px solid #11365A;
  color: #fff;
  text-align: center;
}
#chartjs-tooltip table thead th b {
  display: inline-block;
  margin-right: 0.2em;
  font-size: 17px;
}
#chartjs-tooltip table tbody tr {
  position: relative;
}
#chartjs-tooltip table tbody tr:not(:last-child):after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 2.8%;
  right: 2.8%;
  height: 1px;
  background: #bbb;
}
#chartjs-tooltip table tbody th {
  padding: 0.4em 1.1em;
  font-size: 13px;
  color: #000;
  text-align: left;
  background: none;
  border: none;
}
#chartjs-tooltip table tbody th i {
  display: inline-block;
  margin-right: 0.3em;
}
#chartjs-tooltip table tbody th i.line {
  position: relative;
  top: -0.25em;
  width: 1em;
  height: 3px;
}
#chartjs-tooltip table tbody th i.rect,
#chartjs-tooltip table tbody th i.bar {
  width: 0.8em;
  height: 0.8em;
}
#chartjs-tooltip table tbody td {
  padding: 0.4em 1.1em;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  border: none;
}
@media screen and (max-width: 767px) {
  #chartjs-tooltip table {
    min-width: 60vw;
  }
  #chartjs-tooltip table thead th {
    font-size: 0.765rem;
  }
  #chartjs-tooltip table thead th b {
    font-size: 0.882rem;
  }
  #chartjs-tooltip table tbody th,
  #chartjs-tooltip table tbody td {
    font-size: 0.765rem;
  }
}
@media print, screen and (min-width: 768px) {
  #chartjs-tooltip table {
    min-width: 270px;
  }
}