:root {
    --sidebar-width: 220px;
}

html,
body {
    height: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
}

#content {
    flex: 1;
}

body {
    overflow-x: hidden;
    /* 防止水平滾動 */
}

footer {
    background-color: #343a40;
    color: white;
    padding: 10px 0;
    text-align: center;
    width: 100%;
    position: fixed;
    bottom: 0;
    z-index: 1080;
}

/* ============================================
   Dashboard 美化樣式
   ============================================ */

/* Dashboard 背景漸層 */
.dashboard-bg {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    min-height: 100vh;
    padding-bottom: 60px;
}

/* 統計卡片基礎樣式 */
.stat-card {
    border: 1px solid #e5e7eb;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: relative;
    height: 100%;
    background: white;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--card-gradient-start), var(--card-gradient-end));
}

.stat-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.stat-card.primary {
    --card-gradient-start: #667eea;
    --card-gradient-end: #764ba2;
}

.stat-card.success {
    --card-gradient-start: #10b981;
    --card-gradient-end: #059669;
}

.stat-card.warning {
    --card-gradient-start: #f59e0b;
    --card-gradient-end: #d97706;
}

.stat-card.info {
    --card-gradient-start: #3b82f6;
    --card-gradient-end: #2563eb;
}

/* 統計卡片內容 */
.stat-card .card-body {
    padding: 2rem;
}

.stat-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--card-gradient-start), var(--card-gradient-end));
    color: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    }

    50% {
        box-shadow: 0 4px 25px rgba(0, 0, 0, 0.25);
    }

    100% {
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    }
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--card-gradient-start), var(--card-gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.95rem;
    color: #6b7280;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 資訊卡片 */
.info-card {
    border: 1px solid #e5e7eb;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    overflow: hidden;
    background: white;
}

.info-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.info-card .card-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.info-card .card-header h5 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.info-card .card-body {
    padding: 1.5rem;
    background: white;
}

/* 活動列表樣式 */
.event-list {
    max-height: 300px;
    overflow-y: auto;
}

.event-list::-webkit-scrollbar {
    width: 6px;
}

.event-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.event-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.event-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid #e5e7eb;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.event-item:hover {
    background-color: #f9fafb;
    padding-left: 0.5rem;
    border-radius: 8px;
}

.event-date {
    font-weight: 600;
    color: #667eea;
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 100px;
}

.event-name {
    color: #374151;
    font-size: 0.9rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 統計數字樣式 */
.display-number {
    font-size: 2rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 0.5rem;
}

/* Badge 美化 */
.custom-badge {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.custom-badge.secondary {
    background: linear-gradient(135deg, #6b7280, #4b5563);
}

/* List Group 美化 */
.modern-list-group .list-group-item {
    border: none;
    border-bottom: 1px solid #e5e7eb;
    padding: 1rem 1.25rem;
    transition: all 0.2s ease;
}

.modern-list-group .list-group-item:hover {
    background-color: #f9fafb;
    transform: translateX(5px);
}

.navbar {
    z-index: 1080;
}

/* form p {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}*/

/* form label {
    font-weight: bold;
} */

/*form input,
form select,
form textarea {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    min-width: 50px;
} */

#sidebar {
    width: var(--sidebar-width);
    background: #343a40;
    color: white;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding-top: 56px;
    /* Navbar 高度 */
    transition: margin-left 0.3s;
    z-index: 1040;
    /* Above footer and content */
}

#sidebar.collapsed {
    margin-left: calc(var(--sidebar-width) * -1);
}

#sidebar a {
    color: white;
    display: block;
    padding: 10px 15px;
    text-decoration: none;
}

#sidebar a:hover {
    background: #495057;
    text-decoration: none;
}

#content {
    margin-left: var(--sidebar-width);
    padding: 20px;
    padding-bottom: 100px;
    transition: margin-left 0.3s;
}

#content.expanded {
    margin-left: 0;
}

/* Mobile Overlay Styles */
@media (max-width: 1023.98px) {
    #sidebar {
        margin-left: calc(var(--sidebar-width) * -1);
        /* Hidden by default on mobile */
    }

    #sidebar.show-sidebar {
        margin-left: 0;
    }

    #content {
        margin-left: 0 !important;
        /* Content always full width on mobile */
    }

    /* Backdrop for mobile */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1035;
        /* Below sidebar, above everything else */
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

.sidebar-active {
    background-color: #198754;
    color: #fff;
    font-weight: bold;
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
}

.nav-link:hover {
    background-color: #5a189a;
}

.datatable {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #ccc;
}

.datatable thead {
    background-color: teal;
    color: white;
}

.datatable th,
.datatable td {
    border-top: 1px solid #ccc;
    padding: 8px;
}

/* DataTables Row Grouping Header */
.datatable tbody tr.dtrg-group {
    background-color: #b4fcff !important;
    color: #9e05f7 !important;
    font-weight: bold;
    text-align: left;
}

.datatable tbody tr.dtrg-group:hover {
    background-color: #b4fcff !important;
}

.datatable tbody tr.dtrg-group.collapsed i {
    transform: rotate(-90deg);
    transition: transform 0.2s;
}

.datatable tbody tr.dtrg-group i {
    transition: transform 0.2s;
}

/* Zebra stripe：隔行淺灰底色 */
.datatable tbody tr:nth-child(even) {
    background-color: #f2f2f2;
}

/* Hover effect：滑鼠經過時改背景色 */
.datatable tbody tr:hover {
    background-color: #e0f7fa !important;
    cursor: pointer;
}

.datatable th.sorting_asc,
.datatable th.sorting_desc {
    font-weight: bold;
    background-color: #fa7e18;
}

#active-filters {
    margin-top: 10px;
}

.tag {
    display: inline-block;
    background: indianred;
    color: white;
    padding: 4px 8px;
    margin: 4px;
    border-radius: 4px;
    border-radius: 50rem !important;
    font-weight: 500;
    font-size: 0.85rem;
}

.remove-btn {
    background: none;
    border: none;
    color: white;
    margin-left: 5px;
    cursor: pointer;
}

.custom-filter-bg {
    background-color: #ffdd9e;
    padding: 10px;
    border-radius: 6px;
}

/* ========================================================= */
/* 出席率側邊欄 (固定在右上角) 樣式 */
/* ========================================================= */

#attendance-sidebar {
    /* 1. 定位：固定在視窗，並移到右上角 */
    position: fixed;
    top: 60px;
    /* 距離視窗頂部 20px */
    right: 20px;
    /* 距離視窗右側 20px */

    /* 2. 尺寸：限制最大寬度，使其緊湊 */
    max-width: 220px;
    width: 100%;
    /* 確保在小螢幕上仍響應 */

    /* 3. 層級：確保它在所有其他內容之上 */
    z-index: 1050;
    /* 高於 Bootstrap modal 的預設 z-index */

    /* 4. 樣式美化 */
    background-color: #b6f8fa !important;
    /* 輕微的背景色 */
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    /* 輕微陰影 */
    padding: 15px;

    /* 5. 確保內容文字不會太寬 */
    font-size: 0.9rem;
}

.attendance-card-compact {
    /* 設置相對定位，以便進度條作為絕對定位背景 */
    position: relative;
    overflow: hidden;
    /* 隱藏超出卡片邊界的進度條部分 */
    border: 1px solid #ccc;
}

.attendance-card-content {
    /* 確保內容在進度條之上 */
    position: relative;
    z-index: 2;
    padding: 10px !important;
    /* 確保內容緊湊 */
    color: #333;
    /* 確保文字顏色清晰 */
    /* 覆寫 .card-body 的 padding，使其更窄 */
    padding: 0.75rem 1rem !important;
}

.attendance-stat-line {
    font-weight: bold;
    font-size: 1.5rem;
}

/* --------------------------------------------------------- */
/* 實現進度條背景：關鍵 CSS 技巧 */
/* --------------------------------------------------------- */

.attendance-card-compact::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    /* 高度與卡片一致 */
    width: 0%;
    /* 初始寬度為 0 */
    background-color: var(--bs-primary);
    /* 使用 Bootstrap 主色 */
    opacity: 0.3;
    /* 設置透明度，讓背景不影響閱讀 */
    transition: width 0.8s ease-out;
    /* 設置動畫過渡效果 */
    z-index: 1;
    /* 位於內容之下，背景之上 */
}

/* 透過 CSS 變量獲取 data-percentage 屬性並應用寬度 */
.attendance-card-compact[data-percentage]::before {
    /* 讀取 data-percentage 屬性並將其應用為寬度 */
    width: var(--percentage, 0%);
}

/* --------------------------------------------------------- */
/* 設置不同百分比區間的顏色（可選） */
/* --------------------------------------------------------- */

/* 低出席率： < 50% */
.attendance-card-compact[data-percentage^="0"]::before,
.attendance-card-compact[data-percentage^="1"]::before,
.attendance-card-compact[data-percentage^="2"]::before,
.attendance-card-compact[data-percentage^="3"]::before,
.attendance-card-compact[data-percentage^="4"]::before {
    background-color: var(--bs-danger);
    /* 紅色 */
}

/* 中等出席率： 50% - 79% */
.attendance-card-compact[data-percentage^="5"]::before,
.attendance-card-compact[data-percentage^="6"]::before,
.attendance-card-compact[data-percentage^="7"]::before {
    background-color: var(--bs-warning);
    /* 黃色/橙色 */
}

/* 高出席率： >= 80% */
.attendance-card-compact[data-percentage^="8"]::before,
.attendance-card-compact[data-percentage^="9"]::before,
.attendance-card-compact[data-percentage="100"]::before {
    background-color: var(--bs-success);
    /* 綠色 */
}

/* 預設文字顏色 (中性) */
.attendance-stat-line {
    color: #333;
    /* 確保在白色背景上清晰可讀 */
}

/* 1. 低出席率： < 50% (紅色文字) */
.attendance-card-compact[data-percentage^="0"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="1"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="2"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="3"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="4"] .attendance-stat-line {
    color: var(--bs-danger) !important;
}

/* 2. 中等出席率： 50% - 79% (橙色文字) */
.attendance-card-compact[data-percentage^="5"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="6"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="7"] .attendance-stat-line {
    color: #fa7e18 !important;
}

/* 3. 高出席率： 80% - 100% (綠色文字) */
.attendance-card-compact[data-percentage^="8"] .attendance-stat-line,
.attendance-card-compact[data-percentage^="9"] .attendance-stat-line,
.attendance-card-compact[data-percentage="100"] .attendance-stat-line {
    color: var(--bs-success) !important;
}


/* 調整卡片樣式，使其更緊湊
#attendance-sidebar .card-body {
    padding: 10px;
}

#attendance-sidebar .card-title {
    font-size: 0.7rem;
    margin-bottom: 5px;
}

#attendance-sidebar .display-4 {
    font-size: 1.5rem; /* 縮小主要百分比數字 
    margin-top: 5px;
}

/* 調整週期自定表單，使其更窄 
#attendance-sidebar form.form-inline {
    flex-wrap: wrap; /* 允許換行 
}

#attendance-sidebar form.form-inline .form-control {
    width: 100%;
    margin-bottom: 5px;
}

#attendance-sidebar form.form-inline button {
    width: 100%;
    margin-top: 5px;
} */

/* 針對小螢幕（可選）：在手機上取消固定，改為正常顯示 */
@media (max-width: 768px) {
    #attendance-sidebar {
        position: static;
        /* 不再固定 */
        max-width: 100%;
        margin-top: 20px;
        /* 在手機上增加間距 */
        box-shadow: none;
        /* 移除陰影 */
    }
}

/* 專門針對出席率側邊欄中的切換按鈕圖標 */
#attendance-sidebar #toggle-more-btn i {
    /* 1. 確保 transform 屬性可以生效 */
    display: inline-block;

    /* 2. 設置過渡效果：讓旋轉在 0.3 秒內平滑完成 */
    transition: transform 0.3s ease;

    /* 3. 確保初始狀態是向下 (0 度) */
    transform: rotate(0deg);
}

.photo-box {
    width: 150px;
    height: 150px;
    border: 1px dashed #ced4da;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background-color: #fafafa;
    cursor: pointer;
}

.photo-box .add-text {
    font-size: 0.9rem;
    color: #6c757d;
    text-align: center;
    padding: 0.5rem;
}

.photo-box .icon-lg {
    font-size: 3rem;
    /* 圖示大小 */
    display: block;
    margin-bottom: 5px;
}

.photo-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.photo-box .clear-btn {
    position: absolute;
    right: 6px;
    top: 6px;
    /* background: rgba(255, 1, 1, 0.6); */
    /* color: #fff; */
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: pointer;
    z-index: 5;
}

.photo-box .clear-btn.hidden {
    display: none;
}

/* 隱藏原生 file input（仍可被 script 控制） */
.photo-widget-container input[type="file"] {
    display: none;
}

/* small helper for accessibility focus */
.photo-box:focus {
    outline: 2px solid #80bdff;
    outline-offset: 2px;
}

/* ========================================================= */
/* AutocompleteSelectMultiple Custom Styles */
/* ========================================================= */

/* 隱藏 Django Admin 預設的幫助文字 (如 "Hold down 'Control'...") */
.custom-autocomplete+.help,
.custom-autocomplete+.help-tooltip {
    display: none !important;
}

/* 調整 Select2 容器樣式以匹配 Bootstrap */
.select2-container {
    background-color: #fff !important;
    border: 1px solid #ced4da !important;
    border-radius: 0.375rem !important;
    min-height: 38px !important;
    /* Bootstrap input height */
    padding: 2px 8px !important;
}

.select2-container .select2-container--focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* 調整選項標籤樣式 */
.select2-container .select2-selection__choice {
    background-color: #652b9b !important;
    border: 1px solid #ced4da !important;
    border-radius: 0.25rem !important;
    color: #ffffff !important;
    padding: 2px 6px !important;
    margin-top: 4px !important;
}

.select2-container .select2-selection__choice__remove {
    color: #ffffff !important;
    margin-right: 5px !important;
}

.select2-container .select2-selection__choice__remove:hover {
    background-color: #bd76ff !important;
    color: #05fd2e !important;
}

/* 調整下拉選單樣式 */
.select2-dropdown {
    border: 1px solid #ced4da !important;
    border-radius: 0.375rem !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

.select2-container .select2-results__option--highlighted[aria-selected] {
    background-color: #652b9b !important;
    color: #ffffff !important;
}

.form-buttons-container {
    position: sticky;
    bottom: 60px;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

#filter-sidebar {
    /* 1. 定位：固定在視窗，並移到右上角 */
    position: fixed;
    top: 60px;
    /* 距離視窗頂部 20px */
    right: 20px;
    /* 距離視窗右側 20px */

    /* 2. 尺寸：限制最大寬度，使其緊湊 */
    max-width: 250px;
    width: 100%;
    /* 確保在小螢幕上仍響應 */

    /* 3. 高度與滾動：限制最大高度並啟用垂直滾動 */
    /* max-height: calc(100vh - 80px); */
    /* 視窗高度減去頂部偏移量和底部留白 */
    /* overflow-y: auto; */
    /* 內容過多時顯示垂直滾動條 */

    /* 4. 層級：確保它在所有其他內容之上 */
    z-index: 1050;
    /* 高於 Bootstrap modal 的預設 z-index */

    /* 5. 樣式美化 */
    /* background-color: #b6f8fa !important; */
    /* 輕微的背景色 */
    /* border: 1px solid #dee2e6; */
    /* border-radius: 8px; */
    /* box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); */
    /* 輕微陰影 */
    /* padding: 15px; */

    /* 6. 確保內容文字不會太寬 */
    font-size: 0.9rem;
}

/* Filter content 滾動區域 */
#filter-content {
    max-height: calc(100vh - 150px);
    overflow-y: auto;
}