* {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    -webkit-overflow-scrolling: touch;
}

:root {
    --border-color: #d1d8e0; /* 加深邊框顏色 */
    --text-main: #2d3436;
    --text-muted: #b2bec3;
    
    /* 顏色定義：淡色 (沒點亮時) */
    --color-1-pale: #f0f7ff; /* 對調後：萍(現為臻)的淡色 */
    --color-2-pale: #fff5f5; /* 文改為淡紅 */
    --color-3-pale: #f0fff4; /* 萍改為淡綠 */
    --color-4-pale: #f6ffed;
}

body {
    background-image: url('Images/16pic_745596_b.jpg'); /* 確保路徑與資料夾完全一致 */
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-color: #f0f2f5; /* 加入底色，避免圖片載入前全白 */
    margin: 0;
    padding: 20px;
    font-family: 'Outfit', -apple-system, sans-serif;
    color: var(--text-main);
    min-height: 100vh;
}

.calendar-app {
    max-width: 1100px;
    margin: 10px auto; /* 減少頂部邊距 */
    background: rgba(255, 255, 255, 0.75);
    padding: 15px 25px; /* 減少上下內距 */
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: visible; /* 確保內容不會被裁切，讓頁面可以捲動 */
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px; /* 從 25px 壓縮 */
    width: 100%;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.5rem; /* 字體縮小一點點 */
    font-weight: 800;
    color: var(--text-main);
}

.logo-cat {
    width: 80px; /* 從 100px 縮小一點點 */
    height: auto;
    border-radius: 8px;
}

.top-actions {
    display: flex;
    gap: 10px;
}

.action-btn {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.action-btn:hover {
    background: #f8f8f8;
    border-color: #ccc;
    transform: translateY(-2px);
}

.action-btn.danger:hover {
    background: #fff5f5;
    border-color: #ff5252;
    color: #ff5252;
}

/* 導覽列五格矩形設計 */
.nav-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    max-width: 600px;
    margin: 0 auto 10px auto;
    background: rgba(255, 255, 255, 0.55); /* 再次少一些 */
    border: 1.5px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.year-selector .nav-cell {
    padding: 10px 5px;
    font-size: 1rem;
}

.month-selector {
    margin-bottom: 5px; /* 大幅壓縮與下方的間距 */
}

.month-selector .nav-cell {
    padding: 18px 5px; /* 增加高度讓月份更醒目 */
    font-size: 1.4rem; /* 增大月份字體 */
}

.nav-cell {
    background: transparent;
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    border-right: 1px solid #eee;
    color: var(--text-main);
}

.nav-cell.main {
    background: #f8f9fa;
    cursor: default;
}

.year-selector .nav-cell.main {
    font-size: 1.25rem;
    color: #2d3436;
}

.nav-cell.side {
    opacity: 0.35;
}

.nav-cell.arrow {
    color: #95a5a6;
    background: #fcfcfc;
}

.nav-cell:not(.main):hover {
    background: #f0f0f0;
}

/* 統計面板樣式 (調小一點且加入透明感) */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 改為 4 欄 */
    gap: 10px;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.45);
    padding: 8px;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid transparent;
}

.stat-item .label {
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.stat-item .value {
    font-size: 1.1rem;
    font-weight: 800;
}

.stat-item.s1 { border-color: #3498db; color: #3498db; background: #ebf5fb; } /* 臻：明亮藍 */
.stat-item.s2 { border-color: #e74c3c; color: #e74c3c; background: #fdedec; } /* 文：明亮紅 */
.stat-item.s3 { border-color: #2ecc71; color: #2ecc71; background: #eafaf1; } /* 萍：明亮綠 */
.stat-item.s4 { border-color: #f39c12; color: #f39c12; background: #fef5e7; } /* 新：明亮橘 */ /* 惠的橘色 */

/* 日曆結構 */
.weekday-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr) !important;
    width: 100%;
    text-align: center;
    font-weight: 700;
    color: var(--text-muted);
    padding-bottom: 10px;
    border-left: 1.5px solid transparent; /* 關鍵：與下方的 grid 左邊框對齊位移 */
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr) !important; /* 強制 7 欄 */
    width: 100%;
    border-top: 1.5px solid var(--border-color);
    border-left: 1.5px solid var(--border-color);
}

.date-cell {
    min-height: 120px; /* 稍微縮小最小高度，讓比例更協調 */
    border-right: 1.5px solid var(--border-color);
    border-bottom: 1.5px solid var(--border-color);
    padding: 10px 6px; /* 調整內距 */
    display: flex;
    flex-direction: column;
}

.date-num {
    font-size: 0.85rem;
    font-weight: 700; /* 加粗 */
    color: #2d3436; /* 加深顏色 */
    margin-bottom: 10px;
    text-align: right;
}

/* 非本月日期的內容透明度調整，但不影響格子邊框 */
.other-month .date-num,
.other-month .shift-row {
    opacity: 0.4;
}

/* 班次行結構 (早/中/晚) */
.shift-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex: 1;
}

.shift-label {
    font-size: 0.75rem;
    color: #95a5a6;
    width: 18px;
    text-align: center;
    font-weight: 700;
}

/* 班次空缺警示樣式 */
.empty-warning {
    background: rgba(255, 82, 82, 0.08); /* 極淡紅底 */
    border-radius: 4px;
    position: relative;
}

.empty-warning .shift-label {
    color: #ff5252; /* 標籤變紅 */
}

.empty-warning .staff-row-btns {
    outline: 1.5px dashed rgba(255, 82, 82, 0.4); /* 虛線框警示 */
    border-radius: 4px;
}

.staff-row-btns {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 改為 4 欄 */
    gap: 4px;
    flex: 1;
    height: 100%;
}

.staff-btn {
    border: 1px solid #f8f8f8;
    border-radius: 4px;
    cursor: pointer;
    min-height: 28px;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: transparent; /* 沒點亮時文字透明 */
}

/* 顯示姓名首字 */
.btn-1::after { content: '臻'; }
.btn-2::after { content: '文'; }
.btn-3::after { content: '萍'; }
.btn-4::after { content: '新'; }

.staff-btn.active { color: white; } /* 點亮後顯示白色文字 */

/* 預設淡色背景 */
.btn-1 { background-color: var(--color-1-pale); }
.btn-2 { background-color: var(--color-2-pale); }
.btn-3 { background-color: var(--color-3-pale); }
.btn-4 { background-color: var(--color-4-pale); }

/* 點亮後的顏色 (提升亮度與鮮艷度) */
.btn-1.active { background-color: #3498db !important; border-color: #3498db; box-shadow: 0 2px 5px rgba(52,152,219,0.3); } /* 臻：明亮藍 */
.btn-2.active { background-color: #e74c3c !important; border-color: #e74c3c; box-shadow: 0 2px 5px rgba(231,76,60,0.3); } /* 文：明亮紅 */
.btn-3.active { background-color: #2ecc71 !important; border-color: #2ecc71; box-shadow: 0 2px 5px rgba(46,204,113,0.3); } /* 萍：明亮綠 */
.btn-4.active { background-color: #f39c12 !important; border-color: #f39c12; box-shadow: 0 2px 5px rgba(243,156,18,0.3); } /* 新：明亮橘 */

/* 灰色不排班樣式 (每週日晚班) */
.staff-btn.disabled-shift {
    background-color: #f2f2f2 !important;
    border: 1px dashed #cccccc !important;
    cursor: not-allowed !important;
    opacity: 0.5;
    pointer-events: none; /* 完全禁止點擊事件 */
}

/* 停用時隱藏姓名首字 */
.disabled-shift::after {
    content: "" !important;
}

/* 圖例 */
/* 最下方圖例美化 */
.legend {
    display: flex;
    justify-content: center;
    gap: 25px;
    padding: 12px 25px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50px; /* 膠囊形狀 */
    backdrop-filter: blur(5px);
    width: fit-content;
    margin: 10px auto 0 auto;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.blue { background-color: #3498db; box-shadow: 0 0 8px rgba(52,152,219,0.4); } /* 臻 */
.dot.green { background-color: #2ecc71; box-shadow: 0 0 8px rgba(46,204,113,0.4); } /* 萍 */
.dot.red { background-color: #e74c3c; box-shadow: 0 0 8px rgba(231,76,60,0.4); } /* 文 */
.dot.orange { background-color: #f39c12; box-shadow: 0 0 8px rgba(243,156,18,0.4); } /* 新 */

/* 響應式調整 (針對寬度小於 1366px 的裝置，包含平板與手機) */
@media (max-width: 1366px) {
    body {
        padding: 5px;
        background-attachment: scroll !important;
        background-image: none; /* 手機端移除背景圖以解決效能卡頓 */
        background-color: #f0f2f5;
    }

    .calendar-app {
        padding: 10px;
        margin: 0;
        max-width: 100% !important;
        width: 100%;
        background: #ffffff;
        backdrop-filter: none !important; /* 移除毛玻璃，這是手機卡頓主因 */
        border-radius: 0;
        box-shadow: none;
        overflow: visible !important;
    }

    .app-header {
        margin-bottom: 5px;
        padding-top: 5px;
    }

    .logo-cat {
        width: 40px;
    }

    .app-logo {
        font-size: 1.1rem;
    }

    .nav-bar {
        max-width: 100%;
        margin-bottom: 8px;
    }

    .year-selector .nav-cell {
        padding: 6px 2px;
        font-size: 0.8rem;
    }

    .month-selector .nav-cell {
        padding: 8px 2px;
        font-size: 1.1rem;
    }

    .stats-panel {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
        padding: 5px;
        margin-bottom: 10px;
    }

    .stat-item {
        padding: 4px;
    }

    .stat-item .label { font-size: 0.6rem; }
    .stat-item .value { font-size: 0.9rem; }

    .calendar-container {
        display: block;
        width: 100%;
        padding: 5px;
        background: #fff;
        border-radius: 8px;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: inset 0 0 5px rgba(0,0,0,0.05);
    }

    .weekday-header, .calendar-grid {
        min-width: 700px; /* 確保直式時可以滑動顯示 */
        grid-template-columns: repeat(7, 1fr) !important;
    }

    .date-cell {
        min-height: 80px;
        padding: 4px 2px;
    }

    .date-num {
        font-size: 0.65rem;
        margin-bottom: 4px;
    }

    .staff-btn {
        min-height: 24px;
    }

    .legend {
        padding: 8px 10px;
        gap: 10px;
        font-size: 0.65rem;
        margin-top: 10px;
        width: 100%;
        border-radius: 8px;
    }

    /* 橫放手機模式特別優化 */
    @media (orientation: landscape) and (max-height: 500px) {
        body {
            padding: 2px;
        }
        .calendar-app {
            padding: 5px;
        }
        .app-header {
            flex-direction: row; /* 標頭維持並排 */
            margin-bottom: 2px;
            gap: 10px;
        }
        .app-logo {
            font-size: 0.9rem;
        }
        .logo-cat {
            width: 30px;
        }
        .top-actions {
            gap: 4px;
        }
        .action-btn {
            padding: 3px 6px;
            font-size: 0.7rem;
        }
        
        /* 核心關鍵：將年份與月份選取器改為「左右並排」 */
        .year-selector, .month-selector {
            display: inline-grid;
            width: 48%; /* 各佔一半 */
            margin-bottom: 2px;
            vertical-align: top;
        }
        .nav-bar {
            margin: 0 1% 2px 1%;
        }
        .nav-cell {
            padding: 4px 2px !important;
            font-size: 0.8rem !important;
        }
        .nav-cell.main {
            font-size: 0.9rem !important;
        }

        .stats-panel {
            display: none; /* 橫放時隱藏統計以增加可見面積 */
        }
        .calendar-container {
            padding: 2px;
            margin-top: 0;
        }
        .date-cell {
            min-height: 55px; /* 再次縮小格子高度 */
            padding: 2px;
        }
        .date-num {
            font-size: 0.6rem;
            margin-bottom: 2px;
        }
        .shift-row {
            margin-bottom: 1px;
        }
        .staff-btn {
            min-height: 18px;
        }
        .legend {
            display: none; /* 橫放時隱藏圖例，節省高度 */
        }
    }

    /* 手機版額外微調 (寬度小於 600px) */
    @media (max-width: 600px) {
        .staff-btn::after {
            content: "" !important;
        }
        .shift-label {
            display: none;
        }
        .app-header {
            flex-direction: column;
            gap: 5px;
        }
    }
}
