/* style.css */
:root {
    --bg-color: #f0f2f5;
    --sidebar-width: 320px;
    --control-width: 280px;
    --primary: #4361ee;
    --warning: #f39c12; 
    --danger: #e74c3c;
    --success: #2ecc71;
    
    /* 課程類別顏色 */
    --c-required: #ef476f;
    --c-elective: #06d6a0;
    --c-general: #ffd166;
    --c-common: #9b59b6;
    --c-pe: #e67e22;
    --c-default: #118ab2;
    
    --border-color: #dee2e6;
    
    /* [v32.4] 加高底部導航欄位高度以容納文字 */
    --mobile-nav-height: 75px; 
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    margin: 0; padding: 0;
    background-color: var(--bg-color);
    height: 100vh; display: flex; overflow: hidden;
}

/* --- 左側：課程清單 --- */
#left-sidebar {
    width: var(--sidebar-width);
    background: white; border-right: 1px solid #ddd;
    display: flex; flex-direction: column; z-index: 10;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
    transition: transform 0.3s;
}

#left-sidebar.delete-zone-active {
    background-color: #ffeef0; border-right: 2px dashed #ff4d4d;
}
#left-sidebar.delete-zone-active::after {
    content: "放開以移除課程"; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); font-size: 1.5rem; color: #ff4d4d; font-weight: bold; pointer-events: none;
    text-align: center; width: 100%;
}

.sidebar-header { padding: 15px; background: #2b2d42; color: white; text-align: center; }

.filter-section { padding: 10px 15px; background: #f8f9fa; border-bottom: 1px solid #eee; }
.filter-label { font-size: 0.8rem; color: #666; font-weight: bold; margin-bottom: 5px; display: flex; justify-content: space-between; align-items: center; }
.filter-row { display: flex; gap: 8px; margin-bottom: 8px; }
.filter-row:last-child { margin-bottom: 0; }
.filter-select { width: 100%; padding: 6px; border: 1px solid #ced4da; border-radius: 4px; font-size: 0.85rem; background: white; }
.filter-select:focus { outline: 2px solid var(--primary); border-color: transparent; }

#course-stats-bar {
    padding: 8px 15px; background: #e8f4fd; color: #2c3e50; font-size: 0.85rem; 
    border-bottom: 1px solid #d6eaf8; display: flex; align-items: center; justify-content: space-between;
}

.list-container { flex: 1; overflow-y: auto; padding: 10px; }

.course-card {
    background: white; border: 1px solid #eee; border-left: 4px solid var(--primary);
    padding: 10px; margin-bottom: 8px; border-radius: 6px;
    cursor: grab; transition: transform 0.2s, box-shadow 0.2s; user-select: none;
    touch-action: none;
}
.course-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.course-card.is-scheduled { opacity: 0.5; background: #f8f9fa; border-left-color: #ccc; cursor: default; filter: grayscale(100%); }
.card-info-row { font-size: 0.8rem; color: #666; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 5px; }

/* --- 中間：課表 --- */
#main-area { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow: hidden; position: relative; }

#legend-bar {
    display: flex;
    justify-content: center; /* 改為置中，讓左右兩邊靠在一起 */
    gap: 25px; /* 設定模式名稱與圖例之間的距離 */
    align-items: center;
    margin-bottom: 15px;
    background: white;
    padding: 8px 25px; /* 調整內距 */
    border-radius: 50px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    opacity: 0; 
    transition: opacity 0.3s; 
    pointer-events: none; 
    flex-shrink: 0;
    flex-wrap: wrap; 
    width: fit-content; /* 寬度隨內容自適應，不要撐滿整行 */
    max-width: 95%; /* 手機版不超過螢幕寬度 */
    margin-left: auto;
    margin-right: auto;
}

#legend-bar.show { opacity: 1; }

/* 左側模式名稱樣式 */
.legend-label {
    font-weight: bold;
    color: #333;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* 右側圖例容器樣式 */
.legend-content {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center; /* 改為置中 */
}

.legend-item { 
    display: flex; 
    align-items: center; 
    gap: 4px; 
    font-size: 0.8rem; 
    font-weight: bold; 
    white-space: nowrap; 
}

.dot { 
    width: 10px; 
    height: 10px; 
    border-radius: 50%; 
    display: inline-block; 
}

#timetable-wrapper {
    background: white; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    padding: 20px; flex: 1; display: flex; flex-direction: column; overflow: auto; position: relative;
    -webkit-overflow-scrolling: touch;
}

table.timetable { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; background-color: white; min-height: 100%; min-width: 600px; }
.timetable th { padding: 12px; background: #f8f9fa; color: #495057; border: 1px solid var(--border-color); font-weight: bold; position: sticky; top: 0; z-index: 10; }
.timetable td { border: 1px solid var(--border-color); height: 65px; vertical-align: top; padding: 2px; position: relative; transition: all 0.2s; background-color: white; }
.timetable td, .timetable th { border-top: none; border-left: none; }
.timetable th:first-child, .timetable td:first-child { border-left: 1px solid var(--border-color); width: 40px; }
.timetable tr:first-child th { border-top: 1px solid var(--border-color); }
.timetable th:first-child { border-top-left-radius: 8px; }
.timetable th:last-child { border-top-right-radius: 8px; }
.timetable tr:last-child td:first-child { border-bottom-left-radius: 8px; border-bottom: 1px solid var(--border-color); }
.timetable tr:last-child td:last-child { border-bottom-right-radius: 8px; border-bottom: 1px solid var(--border-color); }
.timetable tr:last-child td { border-bottom: 1px solid var(--border-color); }
.timetable td.period-col { background-color: #f8f9fa; text-align: center; font-weight: bold; color: #6c757d; vertical-align: middle; }

.timetable td.cell-droppable:hover { background-color: #f1f3f5; cursor: pointer; }
.timetable td.hint-valid { background-color: rgba(46, 204, 113, 0.15) !important; box-shadow: inset 0 0 0 2px #2ecc71; cursor: copy; }
.timetable td.hint-invalid { background-color: rgba(0, 0, 0, 0.03) !important; cursor: no-drop; opacity: 0.5; }
.timetable td.drag-hover-target { background-color: rgba(46, 204, 113, 0.3) !important; transform: scale(0.98); transition: transform 0.1s; }

@keyframes shake { 0% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-5px); } 100% { transform: translateX(0); } }
.shake-animation { animation: shake 0.4s ease-in-out; background-color: rgba(231, 76, 60, 0.2) !important; }

.schedule-item {
    width: 95%; height: 95%; margin: 0 auto;
    border-radius: 6px; padding: 2px 4px; font-size: 0.75rem; 
    cursor: grab; position: relative; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; justify-content: space-between;
    z-index: 5; transition: all 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.15); border: 1px solid rgba(0,0,0,0.05);
    touch-action: none;
    user-select: none;
}
.schedule-item:active { cursor: grabbing; }
.schedule-item.is-dragging { opacity: 0.5; transform: translateY(-50%) scale(0.9); }

.location-badge {
    background: rgba(255, 255, 255, 0.4); color: inherit; border-radius: 4px; padding: 1px 3px;
    font-size: 0.65rem; text-align: right; margin-top: auto; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; align-items: center; justify-content: flex-end; gap: 2px;
}
.location-badge i { font-size: 0.6rem; opacity: 0.8; }

/* 衝突特效 */
.conflict-old-item { opacity: 0.2 !important; filter: grayscale(100%) !important; transition: opacity 0.3s ease; pointer-events: none; }
.conflict-preview-item {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.95);
    width: 85%; height: 80%; border-radius: 8px; padding: 3px 5px; font-size: 0.75rem; 
    z-index: 15; display: flex; flex-direction: column; justify-content: space-between;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); opacity: 0; pointer-events: none; border: 2px solid #fff;
    animation: fadeInCourse 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes fadeInCourse { from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); } to { opacity: 0.95; transform: translate(-50%, -50%) scale(1); } }

@keyframes popInSuccess { 0% { opacity: 0; transform: translateY(-50%) scale(0.5); } 60% { opacity: 1; transform: translateY(-50%) scale(1.05); } 100% { opacity: 1; transform: translateY(-50%) scale(1); } }
.pop-in-effect { animation: popInSuccess 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }

.conflict-pending-zone {
    background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8) 10px, rgba(255, 235, 238, 0.8) 10px, rgba(255, 235, 238, 0.8) 20px) !important;
    border: 2px dashed var(--danger) !important;
}
.conflict-old-item-dimmed { opacity: 0.3 !important; filter: grayscale(100%); }

/* 中央確認視窗 */
.central-modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000; justify-content: center; align-items: center; backdrop-filter: blur(2px); }
.central-modal { background: white; width: 320px; border-radius: 12px; padding: 25px; display: flex; flex-direction: column; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.3); animation: popIn 0.3s; }
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 驚喜 GIF 視窗 */
#surprise-modal .central-modal { width: auto; max-width: 90%; padding: 10px; background: transparent; box-shadow: none; }
#surprise-modal img { max-width: 100%; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }

/* --- [v32.3 Compact + Stats] 右側佈局 --- */
#right-sidebar { 
    width: var(--control-width); background: white; border-left: 1px solid #ddd; 
    padding: 15px; 
    display: flex; flex-direction: column; 
    box-shadow: -2px 0 5px rgba(0,0,0,0.05); 
    height: 100vh;
}

.sidebar-title-area { text-align: center; margin-bottom: 10px; flex-shrink: 0; }
.control-group { margin-bottom: 12px; }
.control-group h3 { font-size: 0.9rem; color: #2b2d42; margin-bottom: 5px; border-bottom: 2px solid #eee; padding-bottom: 3px; }

.scrollable-content {
    flex: 1; overflow-y: auto; padding-right: 5px; display: flex; flex-direction: column; gap: 5px; 
}

.btn-action { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 8px; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; transition: all 0.2s; font-size: 0.85rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #3f37c9; }
.btn-outline { background: white; border: 1px solid #ccc; color: #555; }
.btn-outline:hover { background: #f8f9fa; border-color: #aaa; }

#mode-btn { background: #f8f9fa; border: 2px solid #ddd; color: #333; justify-content: space-between; padding: 6px 12px; font-size: 0.8rem; }
#mode-btn:hover { background: #e9ecef; border-color: #ccc; }

/* Stats - 緊湊3欄佈局 */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; margin-bottom: 5px; }
.stat-item { background: white; border: 1px solid #eee; border-radius: 6px; padding: 4px; text-align: center; }

.clickable-stat { cursor: pointer; transition: background-color 0.2s, transform 0.1s; position: relative; }
.clickable-stat:hover { background-color: #f1f3f5; border-color: #d0d0d0; }
.clickable-stat:active { transform: scale(0.98); }

.stat-val { font-weight: bold; font-size: 0.9rem; color: #333; display: block; }
.stat-label { font-size: 0.65rem; color: #888; }
.total-stat { background: var(--primary); color: white; border-radius: 6px; padding: 6px; text-align: center; box-shadow: 0 4px 6px rgba(67, 97, 238, 0.2); }
.total-val { font-size: 1.4rem; font-weight: bold; line-height: 1; }
.total-label { font-size: 0.75rem; opacity: 0.9; }

.btn-row { display: flex; gap: 8px; width: 100%; }
.btn-row .btn-action { flex: 1; padding: 8px 5px; white-space: nowrap; font-size: 0.8rem; }

/* Author Link Style */
.author-link {
    font-size: 0.8rem; color: var(--primary); text-decoration: none; 
    display: inline-flex; align-items: center; gap: 5px;
    margin-top: 5px; padding: 4px 10px; border-radius: 20px;
    background: rgba(67, 97, 238, 0.1); transition: background 0.2s;
}
.author-link:hover { background: rgba(67, 97, 238, 0.2); }

/* Surprise Button */
.surprise-btn {
    font-size: 0.7rem; color: #ccc; text-decoration: none; cursor: pointer;
    margin-top: 10px; display: inline-block; transition: color 0.2s;
}
.surprise-btn:hover { color: var(--primary); }

/* Modal */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
.modal { background: white; width: 400px; max-width: 90%; max-height: 80vh; border-radius: 12px; padding: 20px; display: flex; flex-direction: column; animation: popIn 0.3s; }

#fill-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; }
#fill-list .course-card { cursor: pointer; margin-bottom: 8px; transition: transform 0.2s, box-shadow 0.2s; }
#fill-list .course-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); background: #f8f9fa; }

.file-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; max-height: 300px; }
.file-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; font-size: 0.9rem; }
.file-item:last-child { border-bottom: none; }
.btn-delete-file { color: #e74c3c; cursor: pointer; padding: 5px; border-radius: 4px; transition: background 0.2s; }
.btn-delete-file:hover { background: #fadbd8; }

.import-option { display: flex; flex-direction: column; gap: 10px; }
.import-btn { padding: 15px; border: 1px solid #ddd; border-radius: 8px; text-align: left; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 15px; }
.import-btn:hover { background: #f8f9fa; border-color: var(--primary); }
.import-icon { font-size: 1.5rem; color: var(--primary); }

/* 統計列表樣式 */
.stats-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; max-height: 400px; }
.stats-row { display: flex; justify-content: space-between; padding: 10px; border-bottom: 1px solid #f0f0f0; }
.stats-row:last-child { border-bottom: none; }
.stats-dept { font-weight: bold; color: #555; }
.stats-credit { background: #e8f4fd; color: var(--primary); padding: 2px 8px; border-radius: 12px; font-size: 0.85rem; font-weight: bold; }

.footer-credits {
    position: fixed; bottom: 15px; right: 20px; text-align: right;
    font-size: 0.85rem; color: #555; z-index: 100; pointer-events: none;
    line-height: 1.5; font-family: 'Segoe UI', sans-serif; opacity: 0.8;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9);
}
.footer-credits a { pointer-events: auto; color: var(--primary); text-decoration: none; font-weight: bold; }
.footer-credits a:hover { text-decoration: underline; }

/* --- Mobile Responsive & Navigation --- */
#mobile-nav { display: none; } /* 預設隱藏 */

@media screen and (max-width: 900px) {
    body { padding-bottom: var(--mobile-nav-height); }
    
    /* 分頁切換邏輯 */
    .view-section {
        display: none !important;
        width: 100% !important;
        height: 100% !important;
        border: none !important;
        box-shadow: none !important;
    }
    .view-section.active { display: flex !important; }

    /* 調整各區塊樣式以適應手機 */
    #left-sidebar, #right-sidebar { 
        position: static; 
        width: 100%; 
        height: 100%; 
        overflow-y: auto;
    }
    
    #main-area {
        padding: 10px;
        overflow: hidden;
    }
    
    #timetable-wrapper {
        padding: 10px;
        border-radius: 8px;
    }
    
    /* [v32.4] 手機版導航列 */
    #mobile-nav {
        display: flex;
        flex-direction: column; /* 垂直排列：上按鈕，下文字 */
        position: fixed;
        bottom: 0; left: 0; width: 100%;
        height: var(--mobile-nav-height);
        background: white;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 999;
        border-top: 1px solid #eee;
        justify-content: center;
    }
    
    .nav-row {
        display: flex;
        width: 100%;
        flex: 1; /* 佔據主要空間 */
        justify-content: space-around;
        align-items: center;
    }
    
    .nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        color: #888;
        font-size: 0.75rem;
        cursor: pointer;
    }
    .nav-item i { font-size: 1.2rem; margin-bottom: 3px; }
    .nav-item.active { color: var(--primary); }
    
    .mobile-copyright {
        text-align: center;
        font-size: 0.65rem;
        color: #aaa;
        padding-bottom: 4px;
        width: 100%;
    }
    .mobile-copyright a { color: #888; text-decoration: none; }
    
    .footer-credits { display: none; } /* 手機版隱藏桌面版 footer */
    
    /* 修正手機版彈窗寬度 */
    .central-modal { width: 85%; }

    /* 手機版取消拖曳效果，允許正常捲動 */
    .course-card, .schedule-item {
        touch-action: pan-y !important; /* 允許垂直捲動 */
        -webkit-user-select: none;
        user-select: none;
        cursor: default !important;
    }
}
