/* 基本設定 */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #f0f0f0;
    font-family: 'Meiryo', 'Hiragino Kaku Gothic ProN', sans-serif;
}

/* ホワイトボード全体を囲むコンテナ */
.whiteboard-container {
    position: relative;
    width: 100vw;
    height: 56.25vw; /* 16:9 のアスペクト比を維持 */
    max-height: 100vh;
    max-width: 177.78vh; /* 16:9 */
    margin: auto;
    top: 50%;
    transform: translateY(-50%);
}

/* 背景画像レイヤー */
.background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    z-index: 1;
}

.bg-image-left { flex: 0 0 8.5%; }
.bg-image-main { flex: 0 0 76.5%; }
.bg-image-right { flex: 0 0 15.0%; }

.background-layer img {
    width: 100%;
    height: 100%;
    display: block;
}

/* UI操作レイヤー */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    z-index: 2;
    /* 背景画像とUI要素のズレ防止 */
    padding-left: 8.5%;
    padding-right: 15.0%;
    box-sizing: border-box;
}

/* 中央のメイングリッドエリア */
.main-grid-area {
    flex-grow: 1;
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* v6: ヘッダーエリア */
.header-area {
    flex-shrink: 0; /* 高さが縮まないようにする */
    height: 15.0%; /* 背景画像に合わせた比率 */
    background-image: url('assets/whiteboard_bg_r1_c2_r1_c1.png');
    background-size: 100% 100%;
    position: relative; /* calendar-headerの基準点 */
}

/* v6: チャートエリア */
.chart-area {
    flex-grow: 1; /* 残りの高さいっぱいに広がる */
    background-image: url('assets/whiteboard_bg_r1_c2_r2_c1.png');
    background-size: 100% 100%;
    position: relative; /* today-marker-lineの基準点 */
    overflow: hidden; /* ★★★ コイツがキモ！はみ出た部分を隠す魔法！ ★★★ */
    display: flex; /* 中のgantt-chartをflexで制御するため */
    padding-bottom: 8.0%; /* ★★★ 下フチとの間に最強の余白を作る！ ★★★ */
    box-sizing: border-box; /* paddingを含めて高さを計算する魔法！ */
}

/* v6: 背景画像が変更されたので、元のimgタグは非表示に */
.bg-image-main img {
    display: none;
}

/* v6: 背景画像が変更されたので、元のdivには背景色を設定して見た目を維持 */
.bg-image-main {
    flex: 0 0 76.5%;
    background-color: #f0f0f0; /* ホワイトボードっぽさを出すための背景色 */
}

/* カレンダーヘッダー（曜日） */
.calendar-header {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    align-items: center;
    text-align: center;
    font-size: clamp(10px, 1.5vw, 18px);
    box-sizing: border-box;
    position: absolute; /* header-area内で絶対配置 */
    z-index: 5;         /* 重なりの順番を指定。数字が大きいほど手前に来る！ */
    width: 100%;
    /* 高さを固定せず、bottomで位置だけ決めるのがイケてる！ */
    height: auto; /* 高さは中身に合わせる */
    /*
     * ★★★ レスポンシブ対応の最強アンサー！ ★★★
     * 画面幅(vw)を基準にすることで、画面サイズが変わってもズレなくなる魔法！
     */
    bottom: 0.5vw;
}

.day-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    font-weight: bold;
}

/* 日付（1, 2, 3...）のスタイル */
.day-number {
    display: none; /* 日付を非表示にする */
}

/* 曜日（月, 火, 水...）のスタイル */
.day-of-week {
    display: flex;
    justify-content: center;
    align-items: center;
    /* わずかな位置ズレを、要素自身の幅に対する割合で補正 */
    transform: translateX(-5%);
    height: 100%; /* 親要素いっぱいに広げる */
}
.day-cell.saturday { color: #007bff; }
.day-cell.sunday, .day-cell.holiday { color: #dc3545; }

/* 今日の日付マーカー（黄色い丸） */
.today-marker {
    position: absolute;
    top: 50%;
    left: 50%; 
    transform: translate(-50%, -50%);
    width: 2.0em;  /* マーカーのサイズを少し小さく調整 */
    height: 2.0em; /* マーカーのサイズを少し小さく調整 */
    background-color: rgba(255, 255, 0, 0.5);
    border-radius: 50%;
    z-index: -1;
}

/* 今日ライン */
.today-marker-line {
    position: absolute;
    top: 0; /* chart-areaの上端から */
    bottom: 4.5%; /* chart-areaの下端に合わせて調整 */
    width: 1px; /* もっと細く！シュッとスタイリッシュに！ */
    background-color: #ff8a8a; /* 主張しすぎない淡い赤色に変更！ */
    z-index: 10;
    display: none; /* JSで表示制御 */
}

/* ガントチャートエリア */
.gantt-chart {
    display: grid;
    grid-template-columns: repeat(31, 1fr); 
    grid-auto-rows: 40px; /* 1タスクあたりの高さを確保（2段分） */
    gap: 2px;
    padding: 0; /* 左上から描画するために余白をゼロに！ */
    width: 100%; /* chart-areaいっぱいに広げる */
    overflow-y: auto; /* 縦方向にはみ出たらスクロール */
    overflow-x: hidden; /* 横方向のスクロールは不要 */
}

/* スクロールバーのスタイリング */
.gantt-chart::-webkit-scrollbar {
    width: 8px;
}

.gantt-chart::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.gantt-chart::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

/* ★★★ ここからが2段表示のキモ！ ★★★ */
.project-info {
    grid-row: auto / span 1; /* JSで指定した行に配置 */
    align-self: start; /* 行の上側に配置 */
    font-size: 12px;
    padding-left: 4px;
    white-space: nowrap; /* 折り返さずに1行で表示 */
    overflow: hidden; /* はみ出た部分を隠す */
    text-overflow: ellipsis; /* はみ出たら「...」で省略！ */
    z-index: 1; /* バーより手前に表示 */
    pointer-events: none; /* テキストはクリックさせない */
}

.project-name {
    font-weight: bold;
}

.project-bar {
    grid-row: auto / span 1;
    align-self: end; /* 行の下側に配置 */
    height: 18px; /* バーの高さを指定 */
    background-color: #ddd;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    overflow: visible; /* バーからはみ出す要素（ホバー）を見せるため */
}

/* project-barから移動 */
.project-bar:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
/* ★★★ ここまで！ ★★★ */

/* ステータスごとの色分け */
.project-bar[data-status="ontrack"] { border-color: #3b82f6; } /* 施工中: 青 */
.project-bar[data-status="delayed"] { border-color: #ef4444; } /* 遅延: 赤 */
.project-bar[data-status="pending"] { border-color: #f97316; } /* 予定: オレンジ */
.project-bar[data-status="completed"] { border-color: #22c55e; } /* 完了: 緑 */

/* マウスホバーで表示される「詳細へ」バッジ */
.project-bar .detail-badge {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    opacity: 0; /* 最初は透明 */
    transition: opacity 0.2s ease-in-out;
}

.project-bar:hover .detail-badge {
    opacity: 1; /* ホバーで表示 */
}

/* ハイライトされていないタスクバーを薄暗くするスタイル */
.project-bar.dimmed {
    opacity: 0.3;
    transition: opacity 0.3s ease;
    pointer-events: none; /* 薄暗いときはクリックできなくする */
}

.project-progress-indicator {
    height: 100%;
    border-radius: 3px;
    border-left: 5px solid; /* 左の帯をここに移動 */
    border-color: inherit; /* 親のproject-barの色を引き継ぐ */
    box-sizing: border-box;
}

/* 進捗バーもステータスに連動 */
.project-bar[data-status="ontrack"] .project-progress-indicator { background-color: #3b82f6; }
.project-bar[data-status="delayed"] .project-progress-indicator { background-color: #ef4444; }
.project-bar[data-status="pending"] .project-progress-indicator { background-color: #f97316; }
.project-bar[data-status="completed"] .project-progress-indicator { background-color: #22c55e; }

/* 進捗率のテキストスタイルを追加 */
/* バーの中に表示するようにスタイルを変更 */
.project-progress-text {
    position: absolute;
    right: 6px; /* 右端に配置 */
    top: 50%;   /* 上下中央に配置 */
    transform: translateY(-45%); /* 微調整 */
    font-size: 10px;
    font-weight: bold;
    color: black; /* 文字色を黒に変更 */
    text-shadow: 1px 1px 2px rgba(255,255,255,0.7); /* 白い影をつけて視認性アップ */
}

.project-overflow-label {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.9em;
    display: none; /* JSで表示制御 */
}

/* 右側のコントロールパネル */
.control-panel {
    /* flexboxで子要素を縦に並べる最強の司令塔！ */
    display: flex;
    flex-direction: column;
    align-items: center; /* 子要素を中央揃えに */
    gap: 1em; /* 各要素の間にいい感じの隙間を作る */
    width: 11%; /* 全体の幅はキープ */
    z-index: 20;
    position: absolute; /* 全体の位置決めは今まで通り */
    right: 3%;
    top: 10%; /* 上からの開始位置を下にずらす！ */
}

.month-navigator {
    display: flex;
    flex-direction: column; /* 縦並びにする */
    align-items: center;
    gap: 4px; /* ボタン間の垂直マージン */
}

.month-navigator button {
    font-size: clamp(6px, 0.8vw, 10px); /* フォントをさらに小さく調整 */
    padding: 0.2em 0.6em; /* 文字サイズに合わせてパディングも可変に */
    cursor: pointer;
}

.month-steppers button {
    margin: 0 2px; /* 左右ボタン間のマージン */
}

/* --- ここから追加 --- */

/* 年表示のスタイル */
#year-display {
    font-size: clamp(12px, 2.2vw, 22px);
    color: #333;
    font-weight: bold;
    width: 100%;
    text-align: center;
}

/* ソートボタンと凡例エリアのマージン */
.sort-buttons {
    margin-top: 0.5em; /* 月ナビゲーターとの間を少しだけ空ける */
}
.status-legend {
    margin-top: 0; /* flexのgapで管理するので不要に */
}

/* ソートボタンのスタイル */
.sort-buttons button {
    width: 100%; /* 親要素いっぱいに広げる */
    font-size: clamp(6px, 1.0vw, 10px); /* フォントをさらに小さく！シュッとさせる！ */
    padding: 0.5em 0.8em;
    cursor: pointer;
    border: 1px solid #ccc;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sort-buttons button:hover {
    background-color: #f0f0f0;
}

/* 凡例エリアのスタイル */
.status-legend {
    display: flex;
    flex-direction: column;
    gap: 6px; /* 各凡例アイテムの間の余白 */
    width: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 10px;
    border-radius: 5px;
    box-sizing: border-box;
}

.legend-item {
    display: flex;
    align-items: center;
    cursor: pointer; /* クリックできることを示すカーソル */
    font-size: clamp(8px, 1.2vw, 12px);
    padding: 4px 6px; /* クリックしやすくするために少し余白を */
    border-radius: 4px;
    transition: background-color 0.2s ease; /* ホバーやアクティブ時のアニメーション */
}

/* 「全部表示」ボタン用の特別スタイル */
.legend-item[data-status="all"] .legend-text {
    margin: auto; /* テキストを中央揃えにする */
}


/* 色見本の丸いチップ */
.legend-color-chip {
    display: inline-block;
    width: 1em;
    height: 1em;
    border-radius: 50%;
    margin-right: 8px;
    border: 2px solid; /* 枠線として色をつける */
}

/* 「全部表示」ボタンの色チップは非表示に */
.legend-item[data-status="all"] .legend-color-chip {
    display: none;
}

/* ホバーしたときの色 */
.legend-item:not(.active):hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* 選択されている凡例（アクティブ状態）のスタイル */
.legend-item.active {
    background-color: rgba(0, 0, 0, 0.1);
}
/* data-status属性に応じて色を付ける（project-barと同じ色！） */
.legend-item[data-status="ontrack"] .legend-color-chip { border-color: #3b82f6; }
.legend-item[data-status="delayed"] .legend-color-chip { border-color: #ef4444; }
.legend-item[data-status="pending"] .legend-color-chip { border-color: #f97316; }
.legend-item[data-status="completed"] .legend-color-chip { border-color: #22c55e; }

/* ★★★ ここから追加！ ★★★ */
/* アクティブな凡例のチップを塗りつぶす */
.legend-item.active[data-status="ontrack"] .legend-color-chip { background-color: #3b82f6; }
.legend-item.active[data-status="delayed"] .legend-color-chip { background-color: #ef4444; }
.legend-item.active[data-status="pending"] .legend-color-chip { background-color: #f97316; }
.legend-item.active[data-status="completed"] .legend-color-chip { background-color: #22c55e; }

/* ★★★ ここから追加！ ★★★ */
/* 画面遷移ボタンのスタイル */
.nav-button {
    display: inline-block; /* ★ インラインブロック要素に変更 */
    width: auto; /* ★ 幅を自動調整（中身に合わせる） */
    padding: 0.5em; /* ★ 凡例ボタンと高さを合わせる */
    font-size: clamp(8px, 1.2vw, 12px);
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    color: #fff;
    background-color: #2563eb; /* 目立つ青色 */
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.nav-button:hover {
    background-color: #1d4ed8; /* ホバーで少し濃い青に */
}
/* ★★★ ここまで追加！ ★★★ */

/* --- ここまで追加 --- */

/* 左上の縦書き月表示 */
#month-display {
    position: absolute;
    top: 20%; /* 上下中央に配置 */
    left: 4.0%; /* 左側エリア(8.5%)のちょうど真ん中に配置 */
    transform: translate(-50%, -50%); /* 要素自身のサイズを考慮して中央揃え */
    width: 8.5%; /* 親要素である左側エリアと同じ幅を持つ */
    z-index: 20;
    display: flex;
    /* 月だけになったので、flexで中央揃えにする */
    justify-content: center;
    align-items: center;
    font-weight: bold;
}

/* 月のスタイル（こっちをデカくする！） */
#month-display span {
    font-size: clamp(20px, 5vw, 40px);
    color: #000;
}
