/* css/staff_shift_settings.css */

/* --- Safari Viewport Height Fix --- */
#root-container {
    /* style.css の min-height: 100% を上書きし、JSで設定した実際のビューポート高を使用 */
    height: var(--app-height);
    min-height: auto; /* min-heightをリセット */
}

/* --- 新しい2カラムレイアウト --- */
.shift-calendar-main {
    padding: 1.5rem;
    /* 親の main-content が row 方向なので、このページ用に column に上書き */
    flex-direction: column;
    /* この要素自体もFlexアイテムであるため、高さ計算のバグを回避 */
    min-height: 0;
}

.shift-layout-container {
    display: flex;
    gap: 1.5rem;
    flex-grow: 1; /* 親フレックスコンテナ内で利用可能なスペースをすべて使用する */
    min-height: 0; /* flexアイテムがコンテンツによって不必要に拡大するのを防ぐ (Safari対策) */
}

/* 左側: スタッフリスト */
.staff-list-panel {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    /* Safariでの高さ計算のバグを回避 */
    min-height: 0;
    padding: 1.5rem;
}

.staff-list-panel .card-title {
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.staff-list-scroll-container {
    overflow-y: auto;
    flex-grow: 1;
}

.staff-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.staff-list-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    /* ★変更: Flexboxを使用して、スタッフ名とステータスを両端に配置 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.staff-list-item .staff-name {
    font-weight: 500;
    flex-grow: 1; /* 名前が長い場合に省略されるように */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.staff-list-item:last-child {
    border-bottom: none;
}

.staff-list-item.selected {
    background-color: #dbeafe; /* blue-100 */
    color: #1e40af; /* blue-800 */
    font-weight: 600;
}

/* ★追加: 曜日別シフト設定状態のバッジ */
.weekly-shift-status {
    font-size: 0.7rem; /* 11.2px */
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px; /* rounded-full */
    flex-shrink: 0; /* 縮まないようにする */
}
.weekly-shift-status.is-set {
    background-color: #dbeafe; /* blue-100 */
    color: #1e40af; /* blue-800 */
}
.weekly-shift-status.is-unset {
    background-color: #f3f4f6; /* gray-100 */
    color: #6b7280; /* gray-500 */
}

/* 右側: カレンダー */
.calendar-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    /* Safariでの高さ計算のバグを回避 */
    min-height: 0;
}

/* --- Tab Styles --- */
.tab-buttons {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: -1px; /* To overlap with card border */
    z-index: 1;
    position: relative;
    background-color: #f9fafb;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}
.tab-button {
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #6b7280;
    border: none;
    background-color: transparent;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: -1px;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}
.tab-button:hover {
    color: #374151;
    background-color: #f3f4f6;
}
.tab-button.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
    background-color: white;
}
.tab-panel {
    display: none; /* Hide by default */
    flex-grow: 1;
    flex-direction: column;
    /* Safariでの高さ計算のバグを回避 */
    min-height: 0;
}
.tab-panel.active {
    display: flex; /* Show active tab */
    flex-direction: column;
}

.shift-calendar-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    /* Safariでの高さ計算のバグを回避 */
    min-height: 0;
}

.shift-calendar-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.shift-calendar-header .calendar-actions {
    display: flex;
    gap: 0.75rem;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.calendar-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
    min-width: 180px;
    text-align: center;
}

.shift-calendar-body {
    flex-grow: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: auto; /* 曜日ヘッダー行の高さはコンテンツに合わせる */
    grid-auto-rows: minmax(100px, 1fr); /* 日付セルの最小高さを確保しつつ、残りの高さを均等に分割 */
    overflow-y: auto; /* ★変更: カレンダー本体が縦に長くなった場合にスクロールできるように */
    min-height: 0; /* ★追加: SafariのFlexbox高さ計算バグ対策の決定版 */
}

/* ★追加: カレンダーのプレースホルダー（スタッフ未選択時など） */
.calendar-placeholder {
    grid-column: 1 / -1; /* グリッド全体に広がるように */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem; /* text-lg */
    color: #6b7280; /* text-gray-500 */
    min-height: 400px;
}

.loading-spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    grid-column: 1 / -1; /* グリッド全体に広がるように */
}

/* --- カレンダーグリッドのスタイル --- */
.calendar-weekday-header {
    display: contents; /* グリッドレイアウトに影響を与えないように */
}

.weekday {
    text-align: center;
    padding: 0.75rem 0.5rem;
    font-weight: 600;
    background-color: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
}
.weekday:last-child { border-right: none; }
.weekday.sunday { color: #b91c1c; }
.weekday.saturday { color: #1d4ed8; }

.calendar-day {
    border-right: 1px solid #e5e7eb;
    border-top: 1px solid #e5e7eb;
    padding: 0.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* セル内のスクロールを有効にするため */
    cursor: pointer;
}
.calendar-day:hover {
    background-color: #f0f9ff;
}
.calendar-day.is-selected {
    background-color: #93c5fd !important; /* bg-blue-300, important to override sunday/saturday styles */
    box-shadow: inset 0 0 0 2px #3b82f6; /* focus ring effect */
}
.calendar-day.is-selected:hover {
    background-color: #60a5fa !important; /* a bit darker on hover */
}

.calendar-day:nth-child(7n) { border-right: none; }
.calendar-day.other-month { background-color: #f9fafb; color: #d1d5db; cursor: default; } /* ★修正: holidayクラスをsundayの定義に移動 */
.calendar-day.other-month:hover { background-color: #f9fafb; }
.calendar-day.sunday, .calendar-day.holiday { background-color: #fef2f2; }
.calendar-day.saturday { background-color: #eff6ff; }
.calendar-day.today .day-number {
    background-color: #3b82f6;
    color: white;
    border-radius: 50%;
    font-weight: bold;
}

/* ★追加: 日付番号と祝日名をまとめるコンテナ */
.day-number-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0.25rem;
}

.day-number {
    font-size: 0.875rem;
    font-weight: 500;
    width: 1.75rem;
    height: 1.75rem;
    line-height: 1.75rem;
    text-align: center;
}
.other-month .day-number { color: #d1d5db; }

/* ★追加: 祝日名のスタイル */
.holiday-name {
    font-size: 0.7rem; /* 11.2px */
    color: #b91c1c; /* red-700 */
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.other-month .holiday-name { display: none; } /* 他の月では祝日名を表示しない */

.shifts-in-day {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0; /* ★追加: Safariで日付セル内のシフトリストが親を突き抜けるのを防ぐ */
    padding-right: 4px; /* スクロールバーのスペース */
}

.shift-entry {
    background-color: white;
    border-radius: 4px;
    padding: 4px 6px;
    margin-bottom: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    border-left: 4px solid #60a5fa; /* デフォルトの色 */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: transform 0.1s, box-shadow 0.1s;
}
.shift-entry:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.shift-entry.day-off {
    border-left-color: #f87171; /* 休日 */
    background-color: #fef2f2;
}
.shift-entry-staff { font-weight: 600; }
.shift-entry-details { color: #4b5563; }

/* --- ★追加: ドラッグ＆ドロップのスタイル --- */
/* ドロップ先のプレースホルダー */
.sortable-ghost {
    background-color: #dbeafe; /* blue-100 */
    opacity: 0.6;
    border-radius: 4px;
}
/* ドラッグ中の要素 */
.sortable-drag {
    opacity: 0.8;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transform: scale(1.05);
}

/* --- シフト編集モーダル内のトグルボタン --- */
.status-toggle-group {
    display: flex;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    overflow: hidden;
}
.status-toggle-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    background-color: #f9fafb;
    color: #6b7280;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-weight: 500;
    text-align: center;
}
.status-toggle-btn:not(:last-child) {
    border-right: 1px solid #d1d5db;
}
.status-toggle-btn.active.btn-status-valid {
    background-color: #3b82f6;
    color: white;
}
.status-toggle-btn.active.btn-status-invalid {
    background-color: #ef4444;
    color: white;
}

/* --- Weekly Shift Settings Form --- */
.weekly-shift-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
    min-height: 0; /* ★追加: SafariのFlexbox高さ計算バグ対策の決定版 */
}

/* 曜日別シフトフォームのスタイル (HTMLのインラインスタイルから移動) */
#weeklyShiftForm {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0; /* Safariでの高さ計算のバグを回避 */
}
.form-description {
    font-size: 0.875rem;
    color: #4b5563;
    margin-bottom: 1.5rem;
    line-height: 1.5;
    background-color: #f9fafb;
    padding: 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid #e5e7eb;
}
.weekly-hours-grid {
  display: grid;
  /* ★修正: コピー/ペーストボタン用の列を追加 */
  grid-template-columns: auto 1fr auto;
  gap: 1rem 1.5rem;
  align-items: center;
  max-width: 500px;
  margin: 0 auto;
}
.weekly-day-label {
  font-weight: 500;
  padding-right: 1rem;
  text-align: right;
}
.weekly-time-inputs {
  display: flex;
  align-items: center;
  gap: 1rem; /* トグルと時間入力の間のスペース */
}
.weekly-time-inputs .form-input-add-customer {
    width: 110px;
}
/* トグルボタンのコンテナ */
.weekly-shift-toggle {
    flex-shrink: 0; /* 縮まないようにする */
}
/* 時間入力のラッパー */
.time-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ★追加: 曜日別設定のコピー/ペーストボタン */
.weekly-day-actions {
    display: flex;
    gap: 0.5rem;
}
.icon-btn {
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 0.375rem; /* 6px */
    padding: 0.3rem;
    cursor: pointer;
    color: #6b7280; /* gray-500 */
    transition: all 0.2s ease;
}
.icon-btn:hover:not(:disabled) {
    background-color: #f3f4f6; /* gray-100 */
    color: #1f2937; /* gray-800 */
}
.icon-btn:disabled {
    color: #d1d5db; /* gray-300 */
    cursor: not-allowed;
}
.icon-btn svg {
    width: 1.25rem; /* 20px */
    height: 1.25rem; /* 20px */
}

/* --- ★追加: 汎用モーダルコンポーネントのスタイル --- */
.modal-content {
    background-color: white;
    border-radius: 0.5rem; /* 8px */
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); /* shadow-lg */
    display: flex;
    flex-direction: column;
    width: 90%; /* for small screens */
    max-height: 90vh;
    overflow: hidden; /* to make sure children with sharp corners respect the border-radius */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #6b7280;
    transition: color 0.2s ease;
}
.close-btn:hover {
    color: #111827;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
}

/* モーダルのフッター (form-actions-panelを流用) */
.modal-content .form-actions-panel {
    /* ★修正: ボタンを右寄せで横並びにするスタイルを追加 */
    margin-top: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e5e7eb;
    background-color: #f9fafb;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* --- ★追加: モーダルアニメーション --- */
/* モーダル表示/非表示を display:none から opacity/visibility に変更し、
   滑らかなアニメーション（フェードイン/アウト）を可能にします。 */
.modal-overlay {
    /* ★修正: モーダルを画面全体に広げ、中央に配置するためのスタイルを追加 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.6); /* 半透明の黒い背景 (bg-gray-900/60) */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50; /* 他の要素より手前に表示 */
    /* is-visible クラスがないときは非表示 */
    opacity: 0;
    visibility: hidden;
    /* アニメーションの設定: visibilityは遅延させて非表示にする */
    transition: opacity 0.3s ease, visibility 0s 0.3s;
}

.modal-overlay.is-visible {
    /* is-visible クラスが付与されたら表示 */
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease;
}

.modal-overlay .modal-content {
    /* is-visible クラスがないときは少し上にずらして縮小し、透明にする */
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal-overlay.is-visible .modal-content {
    /* is-visible クラスが付与されたら元の位置・サイズに戻し、不透明にする */
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* --- ★追加: ボタン内のローディングスピナー制御 --- */
/* 通常時はスピナーを非表示 */
.btn .spinner {
    display: none;
    width: 1.25rem; /* 20px */
    height: 1.25rem; /* 20px */
    border-width: 3px; /* スピナーの線の太さ */
}

/* is-loadingクラスが付与されたボタンのスタイル */
.btn.is-loading {
    cursor: not-allowed;
}
.btn.is-loading .spinner {
    display: inline-block;
}
.btn.is-loading .btn-text {
    display: none;
}

/* --- ★追加: 曜日別シフトのコピー＆ペーストボタン --- */
#weeklyShiftActionsPanel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

#weeklyShiftActionsPanel .btn-primary {
    padding: 0.75rem 2rem; /* 保存ボタンのサイズを維持 */
}

.copy-paste-actions {
    display: flex;
    gap: 0.75rem;
}

#pasteWeeklyShiftBtn:disabled {
    background-color: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
}

/* --- ★追加: 一括編集ドロップダウンメニュー --- */
.dropdown-container {
    position: relative;
    display: inline-block;
}

/* ★修正: IDセレクタを使い、意図しないスタイルの上書きを防ぐ */
#bulkEditDropdown {
    display: none; /* デフォルトは非表示 */
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.25rem; /* 4px */
    background-color: white;
    min-width: 180px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1); /* shadow-md */
    border-radius: 0.375rem; /* 6px */
    z-index: 10;
    padding: 0.5rem 0; /* 8px */
    border: 1px solid #e5e7eb; /* gray-200 */
}

#bulkEditDropdown.show {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem; /* 8px 16px */
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.875rem; /* 14px */
    color: #374151; /* gray-700 */
    transition: background-color 0.15s ease-in-out;
}

.dropdown-item:hover { background-color: #f3f4f6; /* gray-100 */ }
.dropdown-item.danger { color: #dc2626; /* red-600 */ }
.dropdown-item.danger:hover { background-color: #fef2f2; /* red-50 */ color: #b91c1c; /* red-700 */ }
