/* コスト入力欄のグリッドを2カラム固定・幅均一化 */
.cost-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
/* 共通右寄せクラス */
.text-right {
    text-align: right !important;
}

/* 共通セル幅クラス */
.cell-input {
    width: 100%;
    box-sizing: border-box;
}
/* ベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Hiragino Sans', 'Meiryo', sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

h2 {
    font-size: 1.2rem;
    color: #444;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

h2 .hint {
    font-size: 0.8rem;
    color: #888;
    font-weight: normal;
}

section {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

/* project-info header: align title and actions on one line */
.project-info > h2 {
    display: flex;
    align-items: center;
    /* タイトルの直横にアクションを配置する */
    gap: 8px;
}
.project-info .section-title {
    margin-right: 8px;
    flex: 0 0 auto;
}
.project-info .section-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}
.project-info .section-header-actions .btn {
    height: 36px;
    padding: 6px 12px;
    font-size: 0.9rem;
}

/* 折りたたみトグルをヘッダーの最右へ配置 */
.project-info .section-toggle {
    margin-left: auto;
}

/* フォーム */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* 契約形態（4番目）を単独行にして、商談コードを次の行に移動する */
.project-info .form-grid > .form-group:nth-child(4) {
    grid-column: 1 / -1;
}

/* プロジェクト名（2番目）の入力欄を広げる：グリッドで2列分を占有 */
.project-info .form-grid > .form-group:nth-child(2) {
    grid-column: span 2;
}

/* 追加保険：プロジェクト名入力自体の最小幅を確保 */
.project-info input#projectName {
    min-width: 320px;
    max-width: none;
}

.project-info .milestone-table {
    display: grid;
    gap: 6px;
    padding: 6px 8px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: #fff;
}

.project-info .milestone-table .milestone-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 4px;
    padding: 0;
    border: none;
    background: transparent;
}

.project-info .milestone-table .milestone-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
}

.project-info .milestone-table .milestone-field {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.project-info .milestone-table .milestone-range {
    align-items: center;
    gap: 6px;
}

.project-info .milestone-table .range-separator {
    color: #6b7280;
    font-size: 0.95rem;
}

.cost-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.cost-block {
    background: #fefefe;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* cost-block 内の入力を列幅いっぱいに揃える（見た目を均一化） */
.cost-block .form-grid .form-group input {
    width: 100%;
    box-sizing: border-box;
}

.cost-block-title {
    font-weight: 700;
    color: #374151;
}

.project-info .milestone-table .milestone-field input[type="date"],
.project-info .milestone-table .milestone-field input[type="text"] {
    width: 220px;
    max-width: 220px;
}

@media (max-width: 720px) {
    .project-info .milestone-table .milestone-row {
        grid-template-columns: 1fr;
        align-items: flex-start;
    }
    .project-info .milestone-table .milestone-field {
        width: 100%;
    }
    .project-info .milestone-table .milestone-field input[type="date"],
    .project-info .milestone-table .milestone-field input[type="text"] {
        width: 100%;
        max-width: none;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
    font-weight: 600;
}

/* 日付入力の幅を統一 */
.project-info input[type="date"],
.milestone-field input[type="date"],
.milestone-sub input[type="date"] {
    width: 220px;
    max-width: 220px;
}

.form-group-btn {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
}

.form-group-btn .btn {
    height: 42px;
    white-space: nowrap;
    font-weight: bold;
}

.form-divider {
    grid-column: 1 / -1;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 4px;
    margin: 4px 0 2px;
    font-weight: 600;
    color: #374151;
}

/* ロック状態のスタイル */
.project-info.locked .project-info-grid {
    opacity: 0.6;
    pointer-events: none;
}

.project-info.locked .project-info-grid input {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

.locked-overlay {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #666;
    pointer-events: none;
}

.project-info.locked .locked-overlay {
    display: block;
}

.project-info {
    position: relative;
}

input[type="text"],
input[type="number"],
input[type="date"] {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #6b7280 50%),
        linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position:
        calc(100% - 18px) calc(50% + 1px),
        calc(100% - 12px) calc(50% + 1px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.project-info select,
.milestone-field select {
    width: 220px;
    max-width: 220px;
}

select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* ボタン */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd6;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
    color: white;
    padding: 5px 10px;
    font-size: 0.8rem;
}

.btn-danger:hover {
    background: #c82333;
}

.shortcut-toggle {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.6);
    color: #fff;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    backdrop-filter: blur(4px);
}


.shortcut-toggle:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-1px);
}

.shortcut-toggle span {
    font-size: 0.9rem;
}

/* 設定セクション */
.settings-section h2 {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 汎用セクション折りたたみ */
.collapsible > h2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.collapsible.collapsed > *:not(h2) {
    display: none;
}

.btn-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: #666;
    padding: 5px;
}

.settings-content {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.settings-content.collapsed {
    display: none;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.setting-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.setting-group input[type="number"] {
    width: 100px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.holidays-section {
    border-top: 1px solid #ddd;
    padding-top: 15px;
}

.holidays-section h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: #555;
}

.holiday-add {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.holiday-add input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.holiday-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.holiday-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #fff3cd;
    color: #856404;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
}

.holiday-tag .remove {
    cursor: pointer;
    font-weight: bold;
    color: #dc3545;
}

.holiday-tag .remove:hover {
    color: #a71d2a;
}

/* 作業者フォーム */
.worker-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.worker-form input {
    flex: 1;
    min-width: 120px;
}

/* テーブル */
.worker-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    table-layout: fixed; /* 固定レイアウトで colgroup の幅を尊重 */
}

/* テーブルを収めるラッパー（横スクロールを許可） */
.table-container {
    width: 100%;
    overflow-x: auto;
}

/* テーブル自体に最小幅を与えて列崩れを防止 */
.worker-table {
        min-width: 1100px;
        /* テーブルを inline-table にして内容幅に合わせ横スクロールで表示させる
            （固定レイアウトだと列幅割当が厳格になるため、ここでは自動レイアウトにする） */
        display: inline-table;
        table-layout: auto;
        width: max-content;
}

.worker-table th,
.worker-table td {
    padding: 12px;
    text-align: left;
    /* remove cell borders (罫線を削除) */
    border-bottom: none;
    border-right: none;
}

/* 中央寄せ: 操作列のヘッダ */
.worker-table th:last-child {
    text-align: center;
}

/* remove right border on the last column to avoid double border on table edge */
.worker-table th:last-child,
.worker-table td:last-child {
    border-right: none;
}

.worker-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
}

.worker-table tbody tr:hover {
    background: #f8f9fa;
}

/* インライン編集 */
.inline-edit {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.inline-edit:hover {
    border-color: #ddd;
    background: #fff;
}

.inline-edit:focus {
    outline: none;
    border-color: #667eea;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.inline-edit-sm {
    width: 120px;
    min-width: 80px;
}

/* planned-display: look similar to inline-edit but read-only */
.planned-display {
    /* remove internal padding so the text aligns with other numeric cells
       which use the td padding; make it a block to fill the cell. */
    /* ...existing code... */
    /* 共通化: .cell-input, .text-right を利用 */
    border-radius: 4px;
    font-size: 0.9rem;
    display: block;
    /* 削除: width, box-sizing, text-align */
}

/* right-align numeric/progress columns: planned(4), actual(5), progress-auto(6), progress-manual(7), cost(8) */
.worker-table th:nth-child(4),
.worker-table td:nth-child(4),
.worker-table th:nth-child(5),
.worker-table td:nth-child(5),
.worker-table th:nth-child(6),
.worker-table td:nth-child(6),
.worker-table th:nth-child(7),
.worker-table td:nth-child(7),
.worker-table th:nth-child(8),
.worker-table td:nth-child(8) {
    text-align: right;
}

/* ヘッダーの数値列も右寄せにして見た目を揃える */
.worker-table thead th:nth-child(4),
.worker-table thead th:nth-child(5),
.worker-table thead th:nth-child(6),
.worker-table thead th:nth-child(7),
.worker-table thead th:nth-child(8) {
    text-align: right;
}

/* フッターも確実に右寄せ */
.worker-table tfoot td:nth-child(4),
.worker-table tfoot td:nth-child(5),
.worker-table tfoot td:nth-child(6),
.worker-table tfoot td:nth-child(7),
.worker-table tfoot td:nth-child(8) {
    text-align: right;
}

/* numeric columns are right-aligned via text-align rules above; removed flex layout
   to avoid interfering with the action buttons column layout. */

/* small floating button: scroll to top */
.scroll-top {
    position: fixed;
    right: 18px;
    bottom: 74px;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    background: #667eea;
    color: #fff;
    border: 0;
    cursor: pointer;
    font-weight: 700;
}
.scroll-top.visible {
    display: flex;
}
.scroll-top:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 26px rgba(0,0,0,0.22);
    background: #5a6fd6;
}

.scroll-bottom {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    background: #6c757d;
    color: #fff;
    border: 0;
    cursor: pointer;
    font-weight: 700;
}
.scroll-bottom.visible {
    display: flex;
}
.scroll-bottom:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 26px rgba(0,0,0,0.22);
    background: #5a6268;
}

/* Ensure inline-display variants used for planned hours also inherit right alignment
   (covers elements with classes: inline-display inline-edit-sm planned-display) */
/* 右寄せは .text-right で統一 */

.inline-edit[type="date"] {
    width: 130px;
}

/* テーブル内の入力をセル幅いっぱいに広げる */
/* セル幅は .cell-input で統一 */

/* テーブル内のボタンサイズを統一 */
.worker-table tbody td button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    height: 40px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.95rem;
}

.worker-table tbody td button.btn + button.btn {
    margin-left: 8px;
}

/* 小さめの数値入力は幅を制限 */
/* 必要なら .inline-edit-sm で幅制限 */

/* ブラウザ幅が小さい場合はテーブル全体を縮めつつ、重要列を優先表示 */
@media (max-width: 1100px) {
    .worker-table {
        min-width: 900px; /* 多少縮める */
    }
}

@media (max-width: 760px) {
    /* スマホでは操作列を小さく、テーブルは横スクロールに任せる */
    .worker-table tbody td button.btn {
        min-width: 64px;
        height: 36px;
        padding: 6px 10px;
        font-size: 0.9rem;
    }
    .worker-table th:nth-child(3), /* 単価 */
    .worker-table td:nth-child(3),
    .worker-table th:nth-child(7), /* 実績工数 */
    .worker-table td:nth-child(7) {
        display: none; /* 重要度が低い列を非表示にして幅を稼ぐ */
    }
}

/* 列ごとの最小幅調整: 作業者(1列目) と コード(2列目) を広めに確保 */
.worker-table th:nth-child(1),
.worker-table td:nth-child(1) {
    min-width: 180px;
}
.worker-table th:nth-child(2),
.worker-table td:nth-child(2) {
    min-width: 160px;
}

/* colgroup を使った固定幅指定（フッターと揃えるため） */
.worker-table col.col-name { width: 180px; }
.worker-table col.col-code { width: 160px; }
.worker-table col.col-rate { width: 120px; }
.worker-table col.col-planned { width: 140px; }
.worker-table col.col-actual { width: 140px; }
.worker-table col.col-progress-auto { width: 120px; }
.worker-table col.col-progress-manual { width: 120px; }
.worker-table col.col-cost { width: 140px; }
.worker-table col.col-action { width: 240px; }

/* cost 列と action 列の最小幅を保証して、ボタン群と金額が重ならないようにする */
.worker-table th:nth-child(6),
.worker-table td:nth-child(6) {
    min-width: 180px;
}
.worker-table th:nth-child(7),
.worker-table td:nth-child(7) {
    min-width: 240px;
}

/* 小さい画面では少し小さくするが、極端に潰れないようにする */
@media (max-width: 900px) {
    .worker-table th:nth-child(1),
    .worker-table td:nth-child(1) {
        min-width: 140px;
    }
    .worker-table th:nth-child(2),
    .worker-table td:nth-child(2) {
        min-width: 120px;
    }
}

.total-row {
    background: #e8f4fd !important;
    font-weight: 600;
}

/* ガントチャート */
.gantt-controls {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.zoom-mode-label {
    padding: 6px 12px;
    background: #667eea;
    color: white;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
}

.gantt-container {
    overflow-x: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
}

.gantt-header {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 10;
}

.gantt-header-cell {
    min-width: 40px;
    padding: 8px 4px;
    text-align: center;
    font-size: 0.75rem;
    border-right: 1px solid #eee;
}

.gantt-header-cell.weekend {
    background: #fff0f0;
}

.gantt-header-cell.holiday {
    background: #fff3cd;
}

.gantt-header-cell.today {
    background: #e8f4fd;
    font-weight: bold;
    color: #667eea;
}

.gantt-body {
    min-height: 200px;
}

.gantt-row {
    display: flex;
    align-items: flex-start;
    height: 96px;
    padding: 4px 0;
    border-bottom: 1px solid #eee;
    position: relative;
}

.gantt-row-label {
    min-width: 150px;
    padding: 10px 15px;
    font-weight: 600;
    background: #fafafa;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    border-right: 2px solid #ddd;
    position: sticky;
    left: 0;
    z-index: 10;
}

.milestone-row {
    height: 88px;
    background: #f7f9fc;
}

.milestone-row .gantt-row-label {
    justify-content: flex-start;
    padding-top: 16px;
}

.milestone-cells {
    position: relative;
    min-height: 88px;
    overflow: visible;
}

.milestone-cells .gantt-cell {
    pointer-events: none;
}

.milestone-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.milestone-link {
    position: absolute;
    height: 2px;
    background: var(--ms-color, #2563eb);
    border-radius: 999px;
    transform: translateY(-50%);
    z-index: 1;
    pointer-events: none;
}

.milestone-marker {
    position: absolute;
    top: 12px;
    width: 0;
    height: 0;
    background: transparent;
    transform: translateX(-50%);
    z-index: 2;
    /* allow pointer events on the marker itself (parent layer is non-interactive) */
    pointer-events: auto;
    cursor: grab;
}

.milestone-dot {
    display: none;
}

.milestone-tag {
    --ms-tag-height: 22px;
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid var(--ms-color, #2563eb);
    color: #111827;
    border-radius: 999px;
    height: var(--ms-tag-height);
    line-height: var(--ms-tag-height);
    padding: 0 10px;
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    z-index: 3;
    line-height: 1.6;
    pointer-events: auto;
}

.gantt-row-cells {
    display: flex;
    flex: 1;
    position: relative;
    height: 100%;
}

.worker-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.lane-legend {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.lane-pill {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e9efff;
    color: #2b7be4;
    border: 1px solid #d2defa;
}

.lane-pill.actual {
    background: #ffe9d7;
    color: #d66a1e;
    border-color: #ffd2ac;
}

.gantt-cell {
    min-width: 40px;
    height: 100%;
    border-right: 1px solid #f0f0f0;
}

.gantt-cell.weekend {
    background: #fff8f8;
}

.gantt-cell.holiday {
    background: #fff3cd;
}

.gantt-cell.today {
    background: #e8f4fd;
}

/* 選択範囲ハイライト（ガント行内） */
.gantt-selection {
    position: absolute;
    top: 8px;
    height: 34px;
    background: rgba(102, 126, 234, 0.14);
    border: 1px solid rgba(102,126,234,0.35);
    border-radius: 4px;
    pointer-events: none; /* 選択中のイベントはコンテナが受け取る */
    z-index: 1;
}

/* セグメント削除ボタン */
.gantt-bar,
.gantt-bar-actual {
    overflow: visible; /* allow delete button to be visible when positioned near edges */
}

.gantt-bar .seg-delete,
.gantt-bar-actual .seg-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 50%;
    background: rgba(255,255,255,0.95);
    color: #b91c1c;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    cursor: pointer;
    z-index: 3;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.gantt-bar:hover .seg-delete,
.gantt-bar-actual:hover .seg-delete {
    opacity: 1;
    transform: translateY(0);
}

/* small bars hide the delete control (handled by JS when rendering) */
.gantt-bar .seg-delete.hidden,
.gantt-bar-actual .seg-delete.hidden {
    display: none !important;
}

/* ガントバー */
.gantt-bar {
    position: absolute;
    /* make planned bar more prominent */
    height: 28px;
    top: 8px;
    background: linear-gradient(135deg, #2b7be4 0%, #5a4fe1 100%);
    border-radius: 6px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 6px 14px rgba(43, 123, 228, 0.28);
    transition: box-shadow 0.18s;
    user-select: none;
    z-index: 4;
    touch-action: none;
}

/* 実績バー（予定の直下に表示） */
.gantt-bar-actual {
    position: absolute;
    /* place in a separate lane below planned bar */
    height: 28px;
    top: 52px;
    background: linear-gradient(180deg, #f18b2e 0%, #e36b2a 100%);
    border-radius: 6px;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-bar-actual .actual-label {
    display: inline-block;
    line-height: 1;
    font-size: 12px;
    color: #fff;
}

.gantt-actual-placeholder {
    position: absolute;
    left: 10px;
    right: 10px;
    top: 52px;
    height: 28px;
    border-radius: 6px;
    border: 1px dashed #f1b375;
    background: #fff7ec;
    color: #c97e2b;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.gantt-bar:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
}

.gantt-bar.dragging {
    opacity: 0.8;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.gantt-bar-resize {
    position: absolute;
    height: 100%;
    cursor: ew-resize;
    top: 0;
    background: rgba(255, 255, 255, 0.3);
    opacity: 0;
    transition: opacity 0.2s;
}

.gantt-bar-resize {
    z-index: 2;
}

.gantt-bar:hover .gantt-bar-resize {
    opacity: 1;
}

/* Ensure delete button sits above resize handles */
.gantt-bar .seg-delete,
.gantt-bar-actual .seg-delete {
    z-index: 6;
}

.gantt-bar-resize:hover {
    background: rgba(255, 255, 255, 0.6);
}

.gantt-bar-resize.left {
    border-radius: 4px 0 0 4px;
}

.gantt-bar-resize.right {
    border-radius: 0 4px 4px 0;
}

/* アクション */
.actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* 集計 */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    border-radius: 10px;
    overflow: hidden;
}

.summary-table th,
.summary-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #e5e7eb;
    text-align: right;
}

.summary-table th:first-child,
.summary-table td:first-child {
    text-align: left;
}

.summary-table thead {
    background: #f3f4f6;
    color: #374151;
}

.summary-subtotal td {
    font-weight: 600;
    background: #fdf6e3;
}

.summary-highlight td {
    font-weight: 700;
    background: #fff7ed;
    color: #b45309;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .worker-form {
        flex-direction: column;
    }
    
    .gantt-row-label {
        min-width: 100px;
        font-size: 0.8rem;
    }
}

/* 通知 */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.notification.fade-out {
    animation: fadeOut 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* 選択状態のガントバー */
.gantt-bar.selected {
    box-shadow: 0 0 0 3px #ffc107, 0 4px 12px rgba(102, 126, 234, 0.6);
}

/* ショートカットヘルプ */
.shortcuts-help {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 15px;
    border-radius: 8px;
    font-size: 0.8rem;
    z-index: 100;
}

.shortcuts-help kbd {
    background: #555;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 5px;
}

/* ショートカットヘルプの閉じるボタン */
.shortcuts-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    z-index: 110; /* ensure it's above the help box content */
    pointer-events: auto;
}

/* モーダル */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    padding: 10px;
}

.modal-content {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    max-height: 80vh;
    overflow: auto;
    min-width: 320px;
    max-width: 800px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}

.daily-modal {
    width: min(920px, 95%);
}

/* 今日行のハイライト */
.daily-row.today-highlight {
    box-shadow: 0 8px 28px rgba(102, 126, 234, 0.18);
    border-color: #667eea;
    background: linear-gradient(90deg, #ffffff, #f3f6ff);
    transform: translateX(0);
}

.daily-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eceef5;
}

.daily-modal-heading {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* 見出し領域は横方向で縮められるようにし、長いタイトルは省略表示する */
.daily-modal-heading {
    flex: 1 1 auto;
    min-width: 0; /* flex item の省略を有効にするため */
}

.daily-modal-title {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
    /* allow up to two lines, then ellipsis */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 日付レンジ（タイトルの下段） */
.daily-modal-range {
    display: block;
    font-size: 0.95rem;
    color: #444;
    margin-top: 2px;
}

/* ガントのコンテキストメニュー */
.gantt-context-menu {
    position: absolute;
    background: #ffffff;
    border: 1px solid #d9dce6;
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    border-radius: 6px;
    padding: 6px 8px;
    z-index: 1200;
    min-width: 140px;
}
.gantt-context-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 8px 10px;
    font-size: 0.95rem;
    color: #333;
    cursor: pointer;
}
.gantt-context-menu button:hover {
    background: #f4f6fb;
}

.daily-modal-subtitle {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: #7a7f99;
    text-transform: uppercase;
}

.daily-modal-title {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
}

.daily-modal-actions {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
}

/* daily-modal の幅制限を緩和し、アクションのボタンが折返さないようにする */
.modal-content.daily-modal {
    /* 幅を狭めてモーダルをコンパクトに表示 */
    max-width: 720px;
    width: min(720px, 92%);
    padding: 14px 18px;
}

.daily-modal-actions .btn {
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 0.95rem;
}

/* 小さい画面ではボタンを縦並びに戻す（はみ出し回避） */
@media (max-width: 640px) {
    .daily-modal-header {
        align-items: flex-start;
    }
    .daily-modal-actions {
        flex-wrap: wrap;
        width: 100%;
        margin-top: 8px;
    }
    .daily-modal-actions .btn {
        flex: 1 1 auto;
    }
    .modal-content.daily-modal {
        width: calc(100% - 20px);
        max-width: none;
    }
}

.daily-modal-body {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 4px;
}

.daily-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.daily-row {
    display: grid;
    /* 日付 / メタ(曜日・祝日) / 予定 / 実績 の4列構成 */
    grid-template-columns: 140px 150px 110px 110px;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    border: 1px solid #e6e9f2;
    border-radius: 8px;
    background: #fdfefe;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.daily-row:hover {
    transform: translateX(2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.daily-row.weekend {
    background: #fff7f7;
    border-color: #f5d0d0;
}

.daily-row.holiday {
    background: #fff6e6;
    border-color: #f3ca8c;
}

.daily-date {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 曜日・祝日表示用のメタ列 */
.daily-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
    font-size: 0.95rem;
    color: #5b5b5b;
}

.daily-day-chip {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef1fb;
    color: #5a61c6;
}

.daily-row.weekend .daily-day-chip {
    background: #ffe1e1;
    color: #c15555;
}

.daily-row.holiday .daily-day-chip {
    background: #ffeccc;
    color: #b07017;
}

.daily-holiday-chip {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 999px;
    background: #ffd18d;
    color: #8a5500;
}

.daily-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d2d7eb;
    border-radius: 6px;
    text-align: right;
    font-weight: 600;
}

.daily-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102,126,234,0.2);
    outline: none;
}

.daily-input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: #666;
}

.daily-input-group label {
    font-size: 0.75rem;
}

/* 期間グループモーダルのカスタムスタイル (main UI に合わせる) */
/* 期間グループモーダルのカスタムスタイル (main UI に合わせる) */
#periodModal .modal-content {
    /* compact dialog: target ~340px wide for tight layout */
    width: min(340px, 92%);
    max-width: 340px;
    padding: 14px 16px 14px 16px;
    border-radius: 10px;
}

#periodModal .modal-content h3 {
    margin: 0 0 12px 0;
    font-size: 1.25rem;
    color: #222;
    font-weight: 700;
}

#periodModal .modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 6px;
}

#periodModal .modal-body .form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
}

#periodModal .modal-body label {
    width: 140px;
    font-weight: 600;
    color: #444;
}

/* allow inputs to take remaining space so labels can be wider */
#periodModal .modal-body input[type="date"],
#periodModal .modal-body input[type="number"] {
    /* default flexible inputs */
    flex: 0 1 180px;
    min-width: 90px;
    max-width: 180px;
    width: auto;
}

/* Aggressively narrow date and number fields since they only need to show YYYY/MM/DD and short numbers */
#periodModal .modal-body input[type="date"] {
    flex: 0 1 170px;
    max-width: 170px;
    min-width: 120px;
    padding: 8px 10px;
}

#periodModal .modal-body input[type="number"] {
    flex: 0 1 96px;
    max-width: 96px;
    min-width: 60px;
    padding: 8px 10px;
    text-align: right;
}

#periodModal input[type="date"],
#periodModal input[type="number"] {
    padding: 10px 12px;
    border: 1px solid #e6eaf6;
    border-radius: 8px;
    background: #fff;
    box-shadow: none;
    font-size: 0.96rem;
    min-height: 40px;
}

#periodModal .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 14px;
}

#periodModal .close {
    position: absolute;
    left: 18px;
    top: 16px;
    font-size: 1.2rem;
    color: #666;
    cursor: pointer;
}

/* ボタンの見た目調整 */
#periodModal .btn {
    min-width: 110px;
    padding: 10px 14px;
    border-radius: 10px;
}

#periodModal .btn.btn-primary {
    background: #5f7bef; /* 少し明るめ */
}

@media (max-width: 480px) {
    #periodModal .modal-content { width: calc(100% - 28px); padding: 14px; }
    #periodModal .modal-body .form-row { flex-direction: column; align-items: stretch; gap: 10px; }
    #periodModal .modal-body label { width: auto; }
    #periodModal .modal-footer { flex-direction: column-reverse; gap: 10px; }
}

/* Print styles: A4 portrait, single-page vertical table layout */
@page {
    size: A4 landscape;
    margin: 10mm;
}
