/* ========================================
   VisualPlan - 自前実装CSS
   ======================================== */

.gantt-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 13px;
    user-select: none;
}

/* --- Time Header --- */
.gantt-header {
    display: flex;
    border-bottom: 2px solid #ccc;
    background: #f5f5f5;
    position: sticky;
    top: 0;
    z-index: 10;
}

.gantt-header-label {
    width: 420px;
    min-width: 420px;
    border-right: 1px solid #ddd;
    padding: 8px 12px;
    font-weight: 500;
    background: #f5f5f5;
}

.gantt-header-timeline {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.gantt-header-cells {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
}

.gantt-header-cell {
    border-right: 1px solid #e0e0e0;
    padding: 4px 2px;
    text-align: center;
    font-size: 11px;
    color: #666;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* 休日（土日・祝日）統一色 */
.gantt-header-cell.non-working {
    background: #ffebee;
    color: #c62828;
}

.gantt-header-cell.today {
    background: #e3f2fd;
    font-weight: 700;
    color: #23AA64;
}

/* --- Body --- */
.gantt-body {
    display: flex;
    /* デスクトップ: ヘッダー・ツールバー分を差し引いてビューポートいっぱいに */
    max-height: calc(100vh - 200px);
    overflow: hidden; /* body自体はスクロールしない */
}

.gantt-labels {
    width: 420px;
    min-width: 420px;
    border-right: 1px solid #ddd;
    flex-shrink: 0;
    overflow-y: scroll; /* 左パネル独自スクロール */
}

.gantt-timeline {
    flex: 1;
    overflow: auto; /* 縦横両方スクロール可能 */
    position: relative;
}

.gantt-timeline-inner {
    position: relative;
}

/* --- Rows --- */
.gantt-row,
.gantt-row-label {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
}

.gantt-row-label {
    padding: 4px 12px;
    overflow: hidden;
}

.gantt-row-main {
    min-height: 56px;
    background: #fafafa;
    cursor: pointer;
}

.gantt-row-main:hover {
    background: #f0f0f0;
}

.gantt-row-sub {
    min-height: 40px;
    padding-left: 44px;
    font-size: 12px;
    color: #555;
}

/* --- Sub label info (2 lines) --- */
.gantt-sub-label-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.gantt-sub-label-name {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-sub-label-period {
    font-size: 10px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-row-hidden {
    display: none;
}

/* --- Label Info (3 lines) --- */
.gantt-label-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.gantt-label-line1 {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-label-line2 {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-label-line3 {
    font-size: 10px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Overdue label background --- */
.gantt-label-overdue {
    background-color: #ffcdd2 !important;
}

.gantt-label-overdue:hover {
    background-color: #ef9a9a !important;
}

/* --- Toggle --- */
.gantt-toggle {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    margin-right: 4px;
    font-size: 16px;
    color: #888;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.gantt-toggle.collapsed {
    transform: rotate(-90deg);
}

/* --- Bars --- */
.gantt-bar {
    position: absolute;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    font-size: 11px;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 2;
    cursor: pointer;
}

.gantt-bar-main {
    background: #23AA64;
    top: 16px;
}

.gantt-bar-main:hover {
    filter: brightness(1.1);
}

.gantt-bar-sub {
    top: 8px;
    height: 22px;
    font-size: 10px;
}

.gantt-bar.overdue {
    background: #d32f2f !important;
    animation: pulse-overdue 2s infinite;
}

/* --- Deadline undetermined bar --- */
.gantt-bar.undetermined {
    background: repeating-linear-gradient(
        90deg,
        #E0C8A0 0px,
        #E0C8A0 8px,
        #EDD8B5 8px,
        #EDD8B5 16px
    ) !important;
    color: #666;
    border-right: 3px solid #C0A878;
}

/* --- Undetermined label background --- */
.gantt-label-undetermined {
    background-color: #FFF3E0 !important;
}

.gantt-label-undetermined:hover {
    background-color: #FFE0B2 !important;
}

/* --- Section separator --- */
.gantt-section-separator {
    box-sizing: border-box;
    height: 28px;
    min-height: 28px;
    background: #E0E0E0;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-bottom: 2px solid #BDBDBD;
    cursor: pointer;
    user-select: none;
}

.gantt-section-separator:hover {
    filter: brightness(0.95);
}

.gantt-section-toggle {
    display: inline-block;
    margin-right: 4px;
    font-size: 11px;
}

/* Section color variants */
.gantt-section-warning {
    background: #FFF3E0;
    border-bottom-color: #FFB74D;
    color: #E65100;
}

.gantt-section-primary {
    background: #E3F2FD;
    border-bottom-color: #64B5F6;
    color: #1565C0;
}

.gantt-section-success {
    background: #E8F5E9;
    border-bottom-color: #81C784;
    color: #23AA64;
}

@keyframes pulse-overdue {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* --- Holiday overlay on bars --- */
.gantt-bar-holiday {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(140, 70, 70, 0.7);
    z-index: 1;
    pointer-events: none;
    border-radius: 0;
}

/* --- Today Marker --- */
.gantt-today-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #d32f2f;
    z-index: 5;
    pointer-events: none;
}

.gantt-today-marker::before {
    content: '今日';
    position: absolute;
    top: -20px;
    left: -12px;
    font-size: 10px;
    color: #d32f2f;
    font-weight: 700;
}

/* --- Grid Lines --- */
.gantt-grid-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: #f0f0f0;
    z-index: 0;
}

/* 休日（土日・祝日）統一グリッド色 */
.gantt-grid-line.non-working {
    background: #ffcdd2;
    opacity: 0.3;
}

/* --- Scrollbar --- */
/* 左パネル: 縦スクロールバーを非表示（右パネルのスクロールバーで操作） */
.gantt-labels {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.gantt-labels::-webkit-scrollbar {
    width: 0;
    display: none;
}

/* 右パネル: 縦横スクロールバーを表示 */
.gantt-timeline {
    scrollbar-width: auto;
    scrollbar-color: #999 #e0e0e0;
}

.gantt-timeline::-webkit-scrollbar {
    width: 14px;
    height: 16px;
}

.gantt-timeline::-webkit-scrollbar-track {
    background: #e0e0e0;
}

.gantt-timeline::-webkit-scrollbar-thumb {
    background: #999;
    border-radius: 6px;
    border: 2px solid #e0e0e0;
}

.gantt-timeline::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* --- Label Thumbnails --- */
.gantt-label-thumbs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: 4px;
    flex-shrink: 0;
    align-items: center;
}

.gantt-label-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: transform 0.15s;
}

.gantt-label-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* --- Image Overlay (lightbox) --- */
.gantt-image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.gantt-image-overlay-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* --- New badge --- */
.gantt-new-badge {
    display: inline-block;
    background: #E53935;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    line-height: 1.2;
    vertical-align: middle;
    letter-spacing: 0.5px;
    animation: pulse-new 2s infinite;
}

@keyframes pulse-new {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* --- Completed bar check --- */
.gantt-bar-check {
    font-weight: 700;
    margin-left: 2px;
}

/* ========================================
   ツールバー
   ======================================== */
.gantt-toolbar-row1 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
}

.gantt-toolbar-row2 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
}

/* ========================================
   AppBar ロゴ
   ======================================== */
.appbar-logo {
    height: 35px;
    object-fit: contain;
    margin-left: 8px;
}

/* ========================================
   モバイル対応 (768px以下)
   ======================================== */
@media (max-width: 768px) {
    /* ページタイトルを小さく */
    .gantt-page-title {
        font-size: 1.1rem !important;
        margin-bottom: 4px !important;
    }

    /* 左パネルを狭くする */
    .gantt-header-label,
    .gantt-labels {
        width: 160px;
        min-width: 160px;
    }

    /* ラベルのパディングを詰める */
    .gantt-row-label {
        padding: 2px 6px;
    }

    /* メイン行を少しコンパクトに */
    .gantt-row-main {
        min-height: 48px;
    }

    /* サブ行もコンパクトに */
    .gantt-row-sub {
        min-height: 36px;
        padding-left: 28px;
    }

    /* フォントサイズを縮小 */
    .gantt-label-line1 {
        font-size: 11px;
    }

    .gantt-label-line2 {
        font-size: 9px;
    }

    .gantt-label-line3 {
        display: none;
    }

    .gantt-sub-label-period {
        display: none;
    }

    .gantt-sub-label-name {
        font-size: 10px;
    }

    /* トグルを小さく */
    .gantt-toggle {
        font-size: 12px;
        margin-right: 2px;
    }

    /* サムネイルを非表示 */
    .gantt-label-thumbs {
        display: none;
    }

    /* バー: 小さくなりすぎないようにする */
    .gantt-bar {
        font-size: 10px;
        height: 22px;
        padding: 0 4px;
    }

    .gantt-bar-main {
        top: 13px;
    }

    .gantt-bar-sub {
        top: 7px;
        height: 20px;
        font-size: 9px;
    }

    /* ガントチャート本体の高さをビューポートに合わせる */
    .gantt-body {
        max-height: calc(100vh - 240px);
    }

    /* モバイルではスクロールバーを非表示（タッチスワイプで操作） */
    .gantt-timeline {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .gantt-timeline::-webkit-scrollbar {
        height: 0;
        display: none;
    }

    .gantt-body::-webkit-scrollbar {
        width: 6px;
    }

    /* ヘッダーセルを小さく */
    .gantt-header-cell {
        font-size: 9px;
        padding: 2px 1px;
    }

    .gantt-header-label {
        padding: 4px 6px;
        font-size: 11px;
    }

    /* AppBarロゴを小さく */
    .appbar-logo {
        height: 29px;
    }
}

/* ========================================
   小型モバイル対応 (480px以下)
   ======================================== */
@media (max-width: 480px) {
    .gantt-page-title {
        font-size: 0.95rem !important;
    }

    .gantt-header-label,
    .gantt-labels {
        width: 110px;
        min-width: 110px;
    }

    .gantt-label-line2 {
        display: none;
    }

    .gantt-row-main {
        min-height: 40px;
    }

    .gantt-row-sub {
        min-height: 32px;
        padding-left: 20px;
    }

    /* バー: 最低でも操作可能なサイズを維持 */
    .gantt-bar {
        height: 20px;
        font-size: 9px;
    }

    .gantt-bar-main {
        top: 10px;
    }

    .gantt-bar-sub {
        top: 6px;
        height: 18px;
    }

    .gantt-body {
        max-height: calc(100vh - 260px);
    }

    /* AppBarロゴをさらに小さく */
    .appbar-logo {
        height: 24px;
    }
}
