/* Timesheet Month Styles */

/* ============================================
   ユーティリティクラス
   ============================================ */

.w-50 {
    width: 50px;
}

.w-90 {
    width: 90px;
}

.w-100 {
    width: 100%;
}

.w-150 {
    width: 150px;
}

/* ============================================
   勤務表レイアウト - 固定ヘッダー + スクロール
   ============================================ */

/* 高さの定義 */
:root {
    --month-selector-height: 50px;
    --table-header-height: 38px;
}

/* 月選択ボタン - サイトヘッダーの直下に固定 */
.timesheet-month-selector-fixed {
    position: fixed;
    top: var(--header-height, 60px);
    left: 0;
    right: 0;
    height: var(--month-selector-height);
    background: #fff;
    z-index: 1040;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 月選択ボタン分の余白を確保 */
.timesheet-scroll-area {
    padding-top: var(--month-selector-height);
}

/* テーブルヘッダー - 通常時 */
#workTable thead.sticky-header th {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

/* テーブルヘッダー - 固定時（JSで.is-fixedクラスを付与） */
#workTable thead.sticky-header.is-fixed {
    position: fixed;
    top: calc(var(--header-height, 60px) + var(--month-selector-height));
    left: 0;
    right: 0;
    z-index: 1030;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    display: table;
    width: 100%;
    table-layout: auto;
}

/* テーブルヘッダー固定時のスペーサー */
.thead-spacer {
    height: var(--table-header-height);
    display: none;
}

.thead-spacer.is-active {
    display: table-row;
}

/* テーブルコンテナ */
.timesheet-table-container {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* テーブル基本スタイル */
#workTable,
#fullscreenWorkTable {
    margin-bottom: 0;
    white-space: nowrap;
    border-collapse: collapse;
    table-layout: auto;
    width: auto;
}

#workTable th,
#workTable td,
#fullscreenWorkTable th,
#fullscreenWorkTable td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 4px 2px;
}

/* ヘッダー固定 - Sticky配置 (Fullscreenのみ) */
#fullscreenWorkTable thead.sticky-header th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    background: #f8f9fa;
    z-index: 120;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-bottom: 2px solid #dee2e6;
}

/* Fullscreen Modal Override - stickyで固定 (JSのfixed制御は無効化) */
#fullscreenModal .timesheet-table-container {
    overflow: auto;
    max-height: none;
}

#fullscreenModal #workTable thead.sticky-header th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    background: #f8f9fa;
    z-index: 120;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-bottom: 2px solid #dee2e6;
}

/* フルスクリーン時はJSのis-fixedによるposition:fixedを無効化 */
#fullscreenModal #workTable thead.sticky-header.is-fixed {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    left: unset;
    right: unset;
    transform: none;
    clip-path: none;
}

/* フルスクリーンモーダル */
#fullscreenModal {
    z-index: 1050;
}

#fullscreenModal .modal-body {
    background: #fff;
}

#fullscreenTableContainer {
    overflow: auto;
    max-height: calc(100vh - 70px);
}

/* サブモーダル（変則勤務/遅刻/早退）をフルスクリーンモーダルより前面に表示 */
/* フルスクリーン(1050)より大きい値にする */
#irregularWorkModal,
#lateModal,
#earlyModal,
#defaultSettingsModal,
#conflictModal {
    z-index: 1060 !important;
}

#irregularWorkModal .modal-backdrop,
#lateModal .modal-backdrop,
#earlyModal .modal-backdrop,
#defaultSettingsModal .modal-backdrop,
#conflictModal .modal-backdrop {
    z-index: 1055 !important;
}

#fullscreenWorkTable {
    font-size: 14px;
}

#fullscreenWorkTable th,
#fullscreenWorkTable td {
    padding: 8px 12px;
    vertical-align: middle;
}

/* テーブル列の幅定義 */
.col-date {
    width: 80px;
    min-width: 60px;
}

.col-weekday {
    width: 50px;
    min-width: 40px;
    text-align: center;
}

.col-workday {
    width: 70px;
    min-width: 60px;
    text-align: center;
}

.col-holiday {
    width: 90px;
    min-width: 70px;
}

.col-note {
    min-width: 90px;
}

.col-freeNote {
    width: 120px;
    min-width: 100px;
}

.col-start, .col-end {
    width: 80px;
    min-width: 70px;
}

.col-break {
    width: 60px;
    min-width: 50px;
}

.col-duration, .col-working {
    width: 80px;
    min-width: 70px;
}

.col-action {
    width: 60px;
    min-width: 50px;
}

.date-cell {
    padding-left: 12px !important;
}

.time-cell {
    cursor: pointer;
    background: #fafafa;
    text-align: center;
}

.time-cell.active {
    box-shadow: inset 0 0 0 2px rgba(0, 120, 212, 0.4);
    background: #e3f2fd;
}

/* リアルタイム保存のフィードバック */
.time-cell.saving {
    background: #fff3cd;
    position: relative;
}

.time-cell.saving::after {
    content: '保存中...';
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 9px;
    color: #856404;
    font-weight: 600;
}

.time-cell.saved {
    background: #d4edda;
    transition: background 0.3s ease-out;
}

.time-cell.saved::after {
    content: '✓';
    position: absolute;
    bottom: 2px;
    right: 6px;
    font-size: 12px;
    color: #155724;
    font-weight: bold;
}

.time-cell.save-error {
    background: #f8d7da;
    transition: background 0.3s ease-out;
}

.time-cell.save-error::after {
    content: '✗';
    position: absolute;
    bottom: 2px;
    right: 6px;
    font-size: 12px;
    color: #721c24;
    font-weight: bold;
}

.holiday {
    color: #c00;
    font-size: 12px;
    margin-left: 10px;
    font-weight: 600;
}

.weekday-sun {
    color: #c33;
    font-weight: 600;
}

.weekday-sat {
    color: #116;
    font-weight: 600;
}

/* Time Picker UI */
.time-picker {
    position: fixed;
    width: 280px;
    padding: 12px;
    background: white;
    border: 1px solid #aaa;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    touch-action: none;
}

.picker-buttons {
    margin-top: 12px;
}

.picker-buttons .btn {
    min-width: 80px;
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 8px;
}

.selected-date {
    font-size: 13px;
    color: #333;
    font-weight: 600;
}

.selected-holiday {
    font-size: 12px;
    color: #c00;
    margin-left: 8px;
    font-weight: 600;
}

.display {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
    color: #0066cc;
    font-family: 'Courier New', monospace;
}

.mode {
    text-align: center;
    margin-bottom: 10px;
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.clock {
    width: 200px;
    height: 200px;
    border: 2px solid #0066cc;
    border-radius: 50%;
    margin: auto;
    position: relative;
    background: #f8f9fa;
}

.hand {
    width: 3px;
    height: 85px;
    background: #0066cc;
    position: absolute;
    top: 15px;
    left: 98.5px;
    transform-origin: bottom;
    pointer-events: none;
    transition: transform 0.08s ease-out;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(0, 102, 204, 0.4);
}

.center-dot {
    width: 14px;
    height: 14px;
    background: #0066cc;
    border-radius: 50%;
    position: absolute;
    top: 93px;
    left: 93px;
    border: 3px solid white;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
}

.drag-area {
    width: 200px;
    height: 200px;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
}

.label-small {
    font-size: 13px;
    color: #444;
}

/* Tools List Hover Effect */
.hover-shadow {
    transition: box-shadow 0.2s ease-in-out;
}

.hover-shadow:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

/* ============================================
   モバイル対応 - レスポンシブスタイル
   ============================================ */

/* タブレット以下 (767.98px以下) */
@media (max-width: 767.98px) {
    :root {
        --month-selector-height: 45px;
        --table-header-height: 35px;
    }

    /* 月選択ボタン - 画面上部に固定 */
    .timesheet-month-selector-fixed {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--month-selector-height);
        background: #fff;
        z-index: 1040;
        padding: 0.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 月選択ボタン分の余白 */
    .timesheet-scroll-area {
        padding-top: var(--month-selector-height);
    }

    /* テーブルヘッダー - 固定時 */
    #workTable thead.sticky-header.is-fixed {
        position: fixed;
        top: var(--month-selector-height);
        left: 0;
        right: 0;
        z-index: 1030;
    }

    /* テーブルコンテナ */
    .timesheet-table-container {
        border-radius: 0;
        border-left: none;
        border-right: none;
        overflow-x: auto;
    }

    /* テーブルのフォントサイズ縮小 */
    #workTable {
        font-size: 13px;
        white-space: nowrap;
        min-width: 850px;
    }

    #workTable th,
    #workTable td {
        padding: 6px 4px;
    }

    /* 日付列のコンパクト化 */
    .date-cell {
        padding-left: 6px !important;
        min-width: 60px;
    }

    /* 曜日列の幅調整 */
    .weekday-cell {
        min-width: 35px;
        text-align: center;
    }

    /* 時刻セルのタッチ対応 */
    .time-cell {
        min-width: 70px;
        min-height: 44px;
        vertical-align: middle;
    }

    /* 休憩セルのタッチ対応 */
    .break-cell {
        min-width: 50px;
        min-height: 44px;
    }

    /* クリア/リセットボタンを小さく */
    .clear-row-btn,
    .reset-row-btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    /* 備考プルダウンの調整 */
    .note-select {
        font-size: 12px;
        padding: 4px 6px;
        min-width: 80px;
        white-space: nowrap;
    }

    /* 自由備考ボタンと入力後のテキスト表示 */
    .free-note-cell {
        min-width: 100px;
        white-space: normal;
    }

    .free-note-btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    .free-note-text {
        display: none;
        font-size: 0.75rem;
        word-break: break-word;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 稼働・実働列の幅調整 */
    .duration-cell,
    .working-cell {
        min-width: 70px;
        font-size: 12px;
    }

    /* 休日出勤スイッチの調整 */
    .holiday-cell .form-check-input {
        width: 2.5em;
        height: 1.25em;
    }

    /* Time Picker モバイル - PC用ピッカーは非表示 */
    .time-picker {
        display: none !important;
    }

    /* モバイル用オーバーレイは不要 */
    #timePickerOverlay {
        display: none !important;
    }

    /* モバイルモーダル内の時計スタイル */
    #timePickerModal .clock {
        width: 200px;
        height: 200px;
    }

    #timePickerModal .hand {
        height: 85px;
        left: 98.5px;
    }

    #timePickerModal .center-dot {
        top: 93px;
        left: 93px;
    }

    #timePickerModal .drag-area {
        width: 200px;
        height: 200px;
    }

    #timePickerModal .display {
        font-size: 32px;
        font-weight: bold;
        color: #0066cc;
        font-family: 'Courier New', monospace;
    }

    #timePickerModal .mode {
        font-size: 14px;
        color: #555;
    }

    /* アコーディオンのコンパクト化 */
    .accordion-button {
        padding: 10px 12px;
        font-size: 14px;
    }

    .accordion-body {
        padding: 12px;
    }

    /* デフォルト設定のフォーム調整 */
    #collapseDefaults .d-flex {
        flex-wrap: wrap;
    }

    #collapseDefaults .form-floating {
        width: 100px !important;
    }

    /* 月選択コントロールの調整 */
    #monthInput {
        width: 140px !important;
    }
}

/* スマートフォン (480px以下) */
@media (max-width: 480px) {
    :root {
        --month-selector-height: 40px;
        --table-header-height: 32px;
    }

    /* 月選択ボタン - コンパクト */
    .timesheet-month-selector-fixed {
        padding: 0.25rem 0.5rem;
        height: var(--month-selector-height);
    }

    .timesheet-month-selector-fixed .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }

    /* 月選択ボタン分の余白 */
    .timesheet-scroll-area {
        padding-top: var(--month-selector-height);
    }

    /* テーブルヘッダー - 固定時 */
    #workTable thead.sticky-header.is-fixed {
        top: var(--month-selector-height);
    }

    /* テーブル */
    #workTable {
        font-size: 12px;
        min-width: 900px;
    }
}

/* タッチデバイス用の改善 */
@media (hover: none) and (pointer: coarse) {
    /* タップ領域を大きく */
    .time-cell,
    .break-cell {
        min-height: 48px;
    }

    /* ホバー効果を無効化（タッチでは不要） */
    .time-cell:hover {
        background: #fafafa;
    }

    /* スイッチを大きく */
    .holiday-cell .form-check-input {
        width: 3em;
        height: 1.5em;
    }

    /* ネイティブ time input のスタイル */
    .native-time-input {
        font-size: 16px !important; /* iOSでズームを防ぐ */
        padding: 12px;
        border-radius: 8px;
        border: 2px solid #0066cc;
    }
}

/* 横向きスマートフォン */
@media (max-height: 500px) and (orientation: landscape) {
    .timesheet-table-container {
        max-height: calc(100vh - 120px);
    }

    .time-picker {
        max-height: 90vh;
        overflow-y: auto;
    }

    .clock {
        width: 140px;
        height: 140px;
    }

    .hand {
        height: 55px;
        left: 68.5px;
    }

    .center-dot {
        top: 63px;
        left: 63px;
    }

    .drag-area {
        width: 140px;
        height: 140px;
    }
}

/* 勤務時間が空欄の場合の備考点滅アニメーション */
@keyframes blink-warning {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: #fff3cd;
    }
}

.note-cell.blink-warning .note-select {
    animation: blink-warning 1s ease-in-out infinite;
    border-color: #ffc107;
}

/* 出勤・退勤・休憩のいずれかが未入力の場合の警告枠線 */
.time-cell.incomplete-warning,
.break-cell.incomplete-warning {
    outline: 2px solid #dc3545;
    outline-offset: -2px;
    background-color: #fff5f5;
}

/* 行全体の警告表示 */
tr.row-incomplete .time-cell,
tr.row-incomplete .break-cell {
    background-color: #fff8f8;
}

/* 出社区分ボタンの追加スタイル */
.col-location {
    width: 70px;
    min-width: 60px;
    text-align: center;
}

.work-location-btn {
    font-size: 12px;
    padding: 2px 8px;
    min-width: 50px;
}

.workday-cell {
    text-align: center;
}

.workday-btn {
    font-size: 12px;
    padding: 2px 8px;
    min-width: 50px;
}

/* 変則勤務列 */
.col-irregular {
    width: 130px;
    min-width: 120px;
    text-align: center;
}

.irregular-cell {
    white-space: nowrap;
}

.irregular-btn {
    font-size: 11px;
    padding: 2px 6px;
}

.irregular-type-label {
    font-size: 11px;
    color: #666;
    font-weight: 500;
}

/* 変則勤務モーダルの一覧 */
#irregularWorkModal .list-group-item {
    padding: 8px 12px;
}

#irregularWorkModal .list-group-item .badge {
    font-size: 11px;
}

#irregularWorkModal .list-group-item small {
    font-size: 11px;
    line-height: 1.3;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#irregularWorkModal .irregular-item-remove {
    padding: 2px 6px;
    font-size: 12px;
}

/* 遅刻・早退列 */
.col-lateearly {
    width: 100px;
    min-width: 90px;
    text-align: center;
}

.late-btn, .early-btn {
    font-size: 10px;
    padding: 2px 4px;
    margin: 1px;
}

.late-btn.has-data {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #000;
}

.early-btn.has-data {
    background-color: #0dcaf0;
    border-color: #0dcaf0;
    color: #000;
}

/* 印刷用スタイル */
@media print {
    .timesheet-table-container {
        max-height: none;
        overflow: visible;
    }

    #workTable thead.sticky-header th {
        position: static;
    }

    .time-picker,
    .accordion,
    .clear-row-btn,
    #prevMonth,
    #nextMonth {
        display: none !important;
    }
}

.timesheet-total-card {
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #dee2e6;
    background: #f8f9fa;
    min-width: 150px;
}

.timesheet-total-card .small {
    letter-spacing: 0.02em;
}

#workTable thead.sticky-header.is-fixed {
    right: auto !important;
    width: max-content !important;
    will-change: transform;
}
