/* Allocation Board Layout */

.allocation-container {
    display: flex;
    gap: 16px;
    height: calc(100vh - 120px);
    overflow: hidden;
    padding: 16px;
}

.project-board {
    flex: 3;
    display: flex;
    flex-direction: column;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.standby-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
    /* Light slate */
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.board-header {
    display: flex;
    background: var(--bg-gray-100);
    border-bottom: 2px solid var(--border-color);
    padding: 8px;
    font-weight: 700;
    align-items: center;
}

.board-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.project-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background-color: white;
    /* transition: background-color 0.2s; */
    border-radius: 8px;
    margin-bottom: 4px;
    /* Space between rows to see the rounding */
    overflow: hidden;
    padding: 2px;
    /* Slight padding to frame the content */
    min-height: 60px;
    /* Space for magnets */
    user-select: none;
    /* ドラッグ時にテキストが選択されないようにする */
}

/* Columns */
.col-contractor {
    width: 15%;
    padding: 0 4px;
}

.col-site {
    width: 20%;
    padding: 0 4px;
}

.col-time {
    width: 10%;
    padding: 0 4px;
}

.col-count {
    width: 8%;
    padding: 0 4px;
}

.col-staff {
    flex: 1;
    padding: 4px;
    min-height: 50px;
    background: #fafafa;
    border: 1px dashed #e5e7eb;
    border-radius: 4px;
    margin: 0 4px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
}

.col-actions {
    width: 50px;
    display: flex;
    justify-content: center;
}

.input-cell {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px;
    user-select: auto;
    /* 入力フィールド内ではテキスト選択を可能にする */
}

/* Panel Headers */
.panel-header {
    background: var(--secondary-color);
    color: white;
    padding: 12px;
    font-weight: 700;
    text-align: center;
}

#standbyZone {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
}

/* Magnets */
.magnet {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #fcd34d;
    /* yellow default */
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #1f2937;
    cursor: grab;
    user-select: none;
    transition: transform 0.1s;
    position: relative;
}

.magnet::before {
    content: attr(data-name);
    background: white;
    color: #1f2937;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    max-width: 35px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.magnet:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.magnet-zone.drag-over {
    background: #e0f2fe;
    /* Light blue tint */
    border-color: #3b82f6;
}

.date-input {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
}

/* 大きく目立つ日付セレクター */
.date-selector-large {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.date-nav-btn {
    background: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
    border: 2px solid white !important;
    font-weight: 700;
    padding: 10px 16px;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.3s ease;
}

.date-nav-btn:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.date-display-wrapper {
    position: relative;
}

.date-display {
    background: white;
    color: #1f2937;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 20px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    min-width: 250px;
    text-align: center;
}

.date-display:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.date-display.saturday {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    color: white;
}

.date-display.sunday {
    background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    color: white;
}

.date-display.holiday {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 8px 24px;
}

.date-main {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.date-holiday {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.95;
}



.date-label {
    font-size: 16px;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.5px;
}

.date-input-large {
    border: 3px solid white;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 20px;
    font-weight: 700;
    background: white;
    color: #1f2937;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
}

.date-input-large:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.date-input-large:focus {
    outline: none;
    border-color: #fbbf24;
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.3);
}

/* 土曜日・日曜日・祝日のスタイル */
.date-input-large.saturday {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    color: white;
}

.date-input-large.sunday {
    background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    color: white;
}

.date-input-large.holiday {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    color: white;
}

.date-info-label {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.date-info-label.holiday-info {
    background: #dc2626;
    color: white;
}

.date-info-label.weekday-info {
    background: rgba(255, 255, 255, 0.95);
    color: #1f2937;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.date-selector-large {
    position: relative;
}



/* カスタムコンテキストメニュー */
.magnet-context-menu {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 8px;
    z-index: 10000;
    min-width: 150px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: white;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.menu-item:last-child {
    margin-bottom: 0;
}

.menu-item:hover {
    background: #f3f4f6;
    transform: translateX(2px);
}

.menu-item.delete {
    color: #dc2626;
}

.menu-item.delete:hover {
    background: #fee2e2;
}

.menu-item.color {
    color: #7c3aed;
}

.menu-item.color:hover {
    background: #ede9fe;
}

.menu-item.cancel {
    color: #6b7280;
}

.menu-item.cancel:hover {
    background: #f3f4f6;
}

/* 色パレットポップアップ */
.color-palette-popup {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 12px;
    z-index: 10000;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.color-box {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.color-box:hover {
    transform: scale(1.1);
    border-color: #374151;
}

.color-box.selected {
    border-color: #1f2937;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #1f2937;
}

/* =========================================
   タッチデバイス対応
   ========================================= */

/* タッチデバイスでのホバー効果を無効化 */
@media (hover: none) and (pointer: coarse) {
    .magnet:active {
        transform: scale(1.15);
    }

    .date-nav-btn:hover,
    .date-display:hover {
        transform: none;
    }

    .color-box:hover {
        transform: none;
    }

    .menu-item:hover {
        transform: none;
    }
}

/* =========================================
   タブレット向け (768px - 1024px)
   ========================================= */

@media screen and (max-width: 1024px) {
    .allocation-container {
        padding: 12px;
        height: calc(100vh - 100px);
    }

    /* 日付セレクター */
    .date-selector-large {
        padding: 12px 16px;
    }

    .date-display {
        font-size: 18px;
        min-width: 200px;
        padding: 10px 20px;
    }

    .date-nav-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* プロジェクトボード */
    .col-contractor {
        width: 18%;
    }

    .col-site {
        width: 22%;
    }

    .col-time {
        width: 12%;
    }

    .col-count {
        width: 10%;
    }

    .input-cell {
        font-size: 13px;
    }

    /* 磁石のサイズ調整 */
    .magnet {
        width: 50px;
        height: 50px;
        font-size: 11px;
    }

    .magnet::before {
        font-size: 12px;
        max-width: 40px;
    }
}

/* =========================================
   スマートフォン向け (〜767px)
   ========================================= */

@media screen and (max-width: 767px) {
    .allocation-container {
        flex-direction: column;
        padding: 8px;
        height: auto;
        min-height: calc(100vh - 80px);
        gap: 12px;
        overflow: visible;
        /* Ensure content isn't clipped */
    }

    /* ツールバー */
    .toolbar {
        flex-direction: column;
        gap: 8px;
    }

    .toolbar-divider {
        display: none;
    }

    /* 日付セレクター */
    .date-selector-large {
        flex-direction: column;
        padding: 12px;
        gap: 8px;
    }

    .date-display {
        font-size: 16px;
        min-width: 100%;
        padding: 10px 16px;
    }

    .date-nav-btn {
        width: 100%;
        padding: 6px 10px;
        font-size: 12px;
        min-height: 36px;
    }

    /* プロジェクトボード */
    .project-board {
        flex: 1;
        min-height: 400px;
    }

    .board-header {
        display: none;
        /* スマホでは非表示 */
    }

    .board-body {
        padding: 6px;
    }

    .project-row {
        flex-wrap: wrap;
        min-height: auto;
        padding: 6px 0;
    }

    /* 列の調整 */
    .col-contractor,
    .col-site {
        width: 48%;
        padding: 2px;
        font-size: 12px;
    }

    .col-time,
    .col-count {
        width: 24%;
        padding: 2px;
        font-size: 11px;
    }

    .col-staff {
        width: calc(100% - 24px);
        /* Leave space for actions */
        margin: 4px 0;
        min-height: 44px;
        order: 10;
        /* 最後に配置 */
    }

    .col-actions {
        width: 24px;
        order: 11;
        /* col-staffの後に配置 */
        flex-direction: column;
        justify-content: center;
        gap: 8px;
        padding-left: 2px;
    }

    .col-actions .btn-icon {
        width: 20px;
        height: 10px !important;
        min-height: 0 !important;
        font-size: 8px;
        padding: 0;
        border-radius: 2px;
        line-height: 1;
    }

    .input-cell {
        font-size: 12px;
        padding: 6px;
    }

    /* 待機パネル */
    .standby-panel {
        flex: none;
        min-height: 200px;
    }

    .panel-header {
        padding: 10px;
        font-size: 14px;
    }

    #standbyZone {
        padding: 12px;
        gap: 10px;
    }

    /* 磁石のサイズ拡大（タッチしやすく）-> サイズ調整（小さく） */
    .magnet {
        width: 28px;
        height: 28px;
        font-size: 9px;
    }

    .magnet::before {
        content: attr(data-mobile-name);
        font-size: 8px;
        max-width: none;
        width: fit-content;
        padding: 0 1px;
        margin: 0 auto;
        /* Ensure it centers if block behavior occurs, though flex handles it */
        min-width: auto;
        overflow: visible;
        text-overflow: clip;
    }

    .magnet.len-3::before {
        font-size: 7px;
        /* 3文字の場合は少し小さく */
        letter-spacing: -0.5px;
        /* 詰め気味に */
    }

    /* コンテキストメニュー */
    .magnet-context-menu {
        min-width: 140px;
    }

    .menu-item {
        padding: 12px 16px;
        font-size: 15px;
    }

    /* カラーパレット */
    .color-palette-popup {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding: 10px;
        width: auto;
        max-width: 90vw;
        /* Prevent screen overflow */
    }

    .color-box {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* =========================================
   極小スマートフォン向け (〜375px)
   ========================================= */

@media screen and (max-width: 375px) {
    .allocation-container {
        padding: 6px;
    }

    /* 日付セレクター */
    .date-display {
        font-size: 14px;
        padding: 8px 12px;
    }

    .date-nav-btn {
        font-size: 12px;
        padding: 8px;
    }

    /* プロジェクトボード */
    .board-header {
        font-size: 10px;
        padding: 4px;
    }

    .project-row {
        padding: 4px 0;
    }

    .col-contractor,
    .col-site,
    .col-time,
    .col-count {
        width: 48%;
    }

    .col-staff {
        width: calc(100% - 24px);
        min-height: 50px;
    }

    .input-cell {
        font-size: 11px;
        padding: 4px;
    }

    /* 磁石 */
    .magnet {
        width: 25px;
        height: 25px;
        font-size: 8px;
    }

    .magnet::before {
        content: attr(data-mobile-name);
        font-size: 8px;
        max-width: none;
        width: fit-content;
        padding: 0 1px;
        min-width: auto;
        overflow: visible;
        text-overflow: clip;
    }

    .magnet.len-3::before {
        font-size: 6px;
        letter-spacing: -0.5px;
    }

    /* パネルヘッダー */
    .panel-header {
        font-size: 13px;
        padding: 8px;
    }
}

/* =========================================
   スマホ専用の日付ナビゲーション
   ========================================= */

/* モバイル日付ヘッダー（デフォルトは非表示） */
.mobile-date-header {
    display: none;
}

.mobile-date-nav-btn {
    display: none;
}

.mobile-date-text {
    display: none;
}


/* スマホ画面でのみ表示 */
@media screen and (max-width: 767px) {

    /* モバイル日付ヘッダーを表示 */
    .mobile-date-header {
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.15);
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
        touch-action: pan-y;
    }

    .date-arrow {
        color: rgba(255, 255, 255, 0.5);
        font-size: 18px;
        font-weight: bold;
        pointer-events: none;
    }

    .mobile-date-nav-btn {
        display: none !important;
    }

    .mobile-date-text {
        display: block !important;
        color: white;
        font-size: 16px;
        font-weight: 700;
        text-align: center;
        white-space: nowrap;
        transition: opacity 0.1s;
    }

    .mobile-date-text.swiping {
        opacity: 0.7;
    }

    .mobile-date-text.saturday {
        color: #93c5fd;
    }

    .mobile-date-text.sunday,
    .mobile-date-text.holiday {
        color: #fca5a5;
    }

    /* PC版を非表示 */
    .date-selector-desktop {
        display: none !important;
    }

    /* ツールバー全体を非表示 */
    .toolbar {
        display: none !important;
    }
}