:root {
    --md-sys-color-primary: #00639B;
    --md-sys-color-surface: #FFFFFF;
    --md-sys-color-background: #F6F8FC;
    --md-sys-color-on-surface: #1F1F1F;
    --md-sys-color-nav-bg: #F6F8FC;
    --md-sys-color-nav-active: #D3E3FD;
    --md-sys-color-nav-active-text: #041E49;
    --md-radius-xl: 24px;
}

body,
html {
    height: 100%;
    margin: 0;
    background-color: var(--md-sys-color-background);
    font-family: 'Google Sans', 'Roboto', 'Segoe UI', sans-serif;
    color: var(--md-sys-color-on-surface);
    overflow-x: hidden;
}

.bg-primary-custom {
    background-color: var(--md-sys-color-primary) !important;
    color: #fff;
}

/* 登入頁樣式 */
.login-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--md-sys-color-background);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: var(--md-radius-xl);
    background: var(--md-sys-color-surface);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.login-input {
    border-radius: 8px;
    border: 1px solid #73777F;
    padding: 12px;
    margin-bottom: 16px;
    width: 100%;
    transition: border-color 0.2s;
}

.login-input:focus {
    border-color: var(--md-sys-color-primary);
    outline: none;
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

/* Sidebar */
.sidebar {
    width: 280px;
    min-height: 100vh;
    background-color: var(--md-sys-color-nav-bg);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    transition: width 0.3s ease, transform 0.3s ease;
    padding-top: 20px;
    overflow-x: hidden;
}

.sidebar .nav-link {
    border-radius: 0 50px 50px 0;
    margin-right: 16px;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    color: #444746;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.sidebar .nav-link:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.sidebar .nav-link.active {
    background-color: var(--md-sys-color-nav-active);
    color: var(--md-sys-color-nav-active-text);
    font-weight: 600;
}

.sidebar .nav-link .material-symbols-rounded {
    margin-right: 16px;
    font-size: 20px;
}

/* Sidebar Collapsed State (Desktop) */
.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .system-title {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px 0;
    border-radius: 50%;
    width: 48px;
    margin: 0 auto 8px auto;
}

.sidebar.collapsed .nav-link .nav-text {
    display: none;
}

.sidebar.collapsed .nav-link .material-symbols-rounded {
    margin-right: 0;
}

.sidebar.collapsed .auth-info {
    display: none;
}

/* Main Wrapper */
.main-wrapper {
    margin-left: 280px;
    min-height: 100vh;
    padding: 24px 32px;
    transition: margin-left 0.3s ease;
}

.main-wrapper.expanded {
    margin-left: 80px;
}

.top-header {
    display: flex;
    align-items: center;
    margin-bottom: 24px;
}

.menu-toggle {
    background: none;
    border: none;
    padding: 8px;
    margin-right: 16px;
    border-radius: 50%;
    cursor: pointer;
    color: #444746;
    transition: background 0.2s;
}

.menu-toggle:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

/* Cards & Buttons */
.m3-card {
    border: none;
    border-radius: var(--md-radius-xl);
    background-color: var(--md-sys-color-surface);
    box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3);
    margin-bottom: 24px;
    padding: 24px;
}

.m3-btn {
    border-radius: 24px;
    padding: 10px 24px;
    font-weight: 500;
    border: none;
    background-color: var(--md-sys-color-primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3);
}

.m3-btn:hover {
    box-shadow: 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    opacity: 0.95;
    transform: translateY(-1px);
}

/* --- DataTables Material 3 與排版修復覆寫 --- */

/* 1. 修正外層 Wrapper 跑版 (顯示筆數、搜尋、分頁、資訊) */
.dataTables_wrapper {
    width: 100%;
    margin-top: 16px;
}

.dataTables_wrapper .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

.dataTables_wrapper .row>[class*="col-"] {
    padding-left: 0;
    padding-right: 0;
}

/* 頂部：顯示筆數與搜尋框 */
div.dataTables_length select {
    border-radius: 8px;
    border: 1px solid #73777F;
    padding: 6px 12px;
    margin: 0 8px;
    outline: none;
}

div.dataTables_filter input {
    border-radius: 20px;
    border: 1px solid #73777F;
    padding: 6px 16px;
    margin-left: 8px;
    outline: none;
    transition: border-color 0.2s;
}

div.dataTables_filter input:focus {
    border-color: var(--md-sys-color-primary);
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

/* 底部：資料筆數資訊與分頁器 */
div.dataTables_info {
    color: #73777F;
    font-size: 14px;
    padding-top: 0 !important;
}

div.dataTables_paginate {
    display: flex;
    justify-content: flex-end;
    margin-top: 0 !important;
}

div.dataTables_paginate ul.pagination {
    margin: 0;
}

/* 2. 表格主體與欄位配色 (斑馬紋與首欄視覺) */
table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
    margin-top: 0 !important;
    margin-bottom: 16px !important;
    border-radius: 12px;
    overflow: hidden;
}

/* 表頭配色 */
table.dataTable thead th {
    background-color: #EBF1F8 !important;
    /* 淺藍色表頭 */
    color: #001D35;
    font-weight: 600;
    padding: 14px 16px !important;
    font-size: 14px;
    border-bottom: 1px solid #D3E3FD !important;
}

/* 資料列配色 (斑馬紋) */
table.dataTable tbody tr:nth-child(odd) td {
    background-color: #FFFFFF !important;
}

table.dataTable tbody tr:nth-child(even) td {
    background-color: #F8FAFD !important;
    /* 極淺藍灰，區隔欄位 */
}

/* 欄位微調與邊框 */
table.dataTable tbody td {
    border-bottom: 1px solid #E0E2E0 !important;
    padding: 14px 16px !important;
    font-size: 14px;
    vertical-align: middle;
    color: #1F1F1F;
}

/* 首欄加粗高亮 (通常是 ID 或名稱) */
table.dataTable tbody td:first-child {
    font-weight: 500;
    color: var(--md-sys-color-primary);
}

/* 懸停效果 */
table.dataTable.table-hover tbody tr:hover td {
    background-color: #E8F0FE !important;
    /* Gmail 懸停淺藍 */
    cursor: default;
}

/* 3. 分頁按鈕樣式 (Google Style 正圓形) */
.page-item .page-link {
    border: none;
    color: #444746;
    background: transparent;
    border-radius: 50% !important;
    margin: 0 4px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    box-shadow: none !important;
}

.page-item.active .page-link {
    background-color: var(--md-sys-color-primary);
    color: #fff;
    font-weight: bold;
}

.page-item .page-link:hover:not(.active) {
    background-color: rgba(0, 0, 0, 0.08);
}

.page-item.disabled .page-link {
    color: #C4C7C5;
    background: transparent;
}

/* 4. RWD 響應式介面 (行動裝置自動折疊排列) */
@media (max-width: 991px) {
    .dataTables_wrapper .row {
        flex-direction: column;
        align-items: stretch;
    }

    div.dataTables_length,
    div.dataTables_filter {
        text-align: left !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 12px;
    }

    div.dataTables_filter input {
        width: 100%;
        margin-left: 12px;
    }

    div.dataTables_info {
        text-align: center !important;
        margin-bottom: 12px;
    }

    div.dataTables_paginate {
        justify-content: center !important;
    }
}
/* --- DataTables 匯出按鈕 (Buttons) 樣式修復 --- */

/* 1. 移除 DataTables 強制的灰色漸層與底色 */
div.dt-buttons .btn {
    background-image: none !important; 
    background-color: transparent !important; 
    box-shadow: none !important;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

/* 2. 匯出 Excel 按鈕 (Success 綠色) */
div.dt-buttons .btn-outline-success {
    color: #146C2E !important;
    border: 1px solid #146C2E !important;
}

div.dt-buttons .btn-outline-success:hover {
    background-color: #146C2E !important;
    color: #FFFFFF !important;
}

/* 3. 列印報表按鈕 (Secondary 灰色) */
div.dt-buttons .btn-outline-secondary {
    color: #444746 !important;
    border: 1px solid #73777F !important;
}

div.dt-buttons .btn-outline-secondary:hover {
    background-color: #E0E2E0 !important;
    color: #1F1F1F !important;
}
/* --- FullCalendar Material 3 & Gmail 風格深度美化 --- */

/* 1. 日曆外層容器與字體優化 */
#calendar {
    background-color: var(--md-sys-color-surface) !important;
    padding: 24px !important;
    border-radius: 24px !important; /* M3 XL 圓角 */
    border: 1px solid #E0E2E0 !important;
    box-shadow: 0 1px 3px 0 rgba(60,64,67,0.15) !important;
    font-family: 'Google Sans', 'Roboto', sans-serif !important;
}

/* 2. 控制列與按鈕美化 (Gmail 膠囊按鈕風格) */
.fc .fc-toolbar {
    margin-bottom: 20px !important;
}

.fc .fc-toolbar-title {
    font-size: 1.4rem !important;
    font-weight: 600 !important;
    color: #1F1F1F !important;
    letter-spacing: -0.5px;
}

/* 按鈕樣式修復 */
.fc .fc-button-primary {
    background-color: #FFFFFF !important;
    border: 1px solid #73777F !important;
    color: #00639B !important;
    font-weight: 500 !important;
    padding: 8px 16px !important;
    border-radius: 100px !important; /* M3 膠囊按鈕 */
    transition: all 0.2s ease !important;
    box-shadow: none !important;
}

/* 滑鼠懸停懸浮 (Hover) */
.fc .fc-button-primary:hover {
    background-color: #F0F4F9 !important;
    border-color: #00639B !important;
    color: #041E49 !important;
}

/* 作用中/被選取的按鈕狀態 (Active) */
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
    background-color: #D3E3FD !important; /* M3 Active Container */
    color: #041E49 !important;
    border-color: #A8C7FA !important;
    font-weight: 600 !important;
}

/* 今日按鈕獨立微調 */
.fc .fc-today-button {
    border-radius: 100px !important;
    margin-right: 12px !important;
}

/* 3. 網格與線條美化 (極淡柔和灰藍線) */
.fc th, .fc td, .fc .fc-timegrid-slot {
    border-color: #E8F0FE !important; /* 改為極淡的藍灰格線，不吃視覺干擾 */
}

.fc .fc-col-header-cell {
    background-color: #F8FAFD !important; /* 表頭維持淺色區隔 */
    padding: 10px 0 !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #444746 !important;
}

/* 「今天」那一欄的底色美化 */
.fc .fc-day-today {
    background-color: rgba(211, 227, 253, 0.2) !important; /* 極透明的 Gmail 今日高亮底色 */
}

/* 4. 時間線指標美化 (現在時間的紅色/藍色橫線) */
.fc .fc-timegrid-now-indicator-line {
    border-color: #00639B !important; /* 改為企業主色線 */
    border-width: 2px !important;
}

.fc .fc-timegrid-now-indicator-arrow {
    border-left-color: #00639B !important; /* 箭頭同步變色 */
}

/* 5. 行程活動卡片 (Events) 深度精緻化 */
.fc-v-event, .fc-h-event {
    border: none !important;
    border-radius: 8px !important; /* 柔軟圓角 */
    padding: 4px 8px !important;
    box-shadow: 0 1px 2px 0 rgba(60,64,67,0.2) !important;
    transition: transform 0.15s ease, box-shadow 0.15s ease !important;
}

/* 卡片滑鼠懸停放大特效 */
.fc-v-event:hover, .fc-h-event:hover {
    transform: translateY(-1px) scale(1.01);
    box-shadow: 0 4px 8px 0 rgba(60,64,67,0.25) !important;
    filter: brightness(0.95);
}

/* 活動內文字體調整 */
.fc-event-main {
    font-size: 12px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    padding: 2px 0 !important;
}

.fc-event-time {
    font-size: 11px !important;
    font-weight: bold !important;
    opacity: 0.85;
}

/* 6. 滾動條 Gmail 扁平化修飾 */
#calendar .fc-scroller::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
#calendar .fc-scroller::-webkit-scrollbar-track {
    background: transparent;
}
#calendar .fc-scroller::-webkit-scrollbar-thumb {
    background: #C4C7C5;
    border-radius: 100px;
}
#calendar .fc-scroller::-webkit-scrollbar-thumb:hover {
    background: #A8C7FA;
}