html, body {
  margin: 0;
  padding: 0;
  height: auto;
  overflow: visible;
}

h1 {
  text-align: center;
}

.page-container,
.schedule-main,
#schedule,
.schedule-table {
  height: auto !important;
  overflow: visible !important;
}

body { font-family: sans-serif; }

.page-header {
  text-align: center;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 1.5em;
  margin-bottom: 15px;
  color: #333;
}

.grade-filter {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.grade-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  background-color: #e0e0e0;
  color: #333;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
  min-width: 60px;
}

.grade-btn:hover {
  background-color: #d0d0d0;
  transform: translateY(-1px);
}

.grade-btn.active {
  background-color: #4a90e2;
  color: white;
}

.instruction-text {
  font-size: 12px;
  color: #666;
  margin-top: 10px;
  line-height: 1.4;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

#legend {
  margin: 2em auto 0.5em auto;
  text-align: center;
  width: fit-content;
}

.legend {
  display: inline-block;
  padding: 0.05em 0.7em;
  margin-right: 0.5em;
  border-radius: 4px;
  color: #333;
  font-weight: bold;
  font-size: 0.8em;
  line-height: 1.05;
  vertical-align: middle;
}

.cell-must { background-color: #D0E0F0; }      /* 校必修 - 淺灰藍色 */
.cell-college { background-color: #FFDAB9; }   /* 院必修 - 淺橘色 */
.cell-dept { background-color: #EAD1DC; }     /* 系必修 - 淺粉米色 */
.cell-tech { background-color: #B2C9EF; }     /* 技術次領域 - 淺藍色 */
.cell-mgmt { background-color: #DFF0D8; }     /* 管理次領域 - 淺綠色 */
.cell-elective { background-color: #FFF8DC; }  /* 專業選修 - 淺米色 */

.table-outer-border {
  border: 2px solid #bcbcbc;
  border-radius: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  background: #fff;
  overflow-x: auto;
}

.schedule-table {
  border: none;
  border-collapse: collapse;
  width: 100%;
  min-width: 900px;
  position: relative;
}

/* 移除偽元素補線，僅用 border 呈現外框 */

.schedule-table th, .schedule-table td {
  border: 2px solid #bcbcbc;
  vertical-align: top;
}

/* 確保最後一行和最後一列的邊框 */
.schedule-table tr:last-child td,
.schedule-table tr:last-child th {
  border-bottom: 2px solid #bcbcbc !important;
}

.schedule-table td:last-child, 
.schedule-table th:last-child {
  border-right: 2px solid #bcbcbc !important;
}

/* 確保有 rowspan 的單元格在最後一列時也有右邊框 */
.schedule-table td[rowspan]:last-child,
.schedule-table th[rowspan]:last-child {
  border-right: 2px solid #bcbcbc !important;
}

/* 確保有 rowspan 的單元格在最後一行時也有下邊框 */
.schedule-table tr:last-child td[rowspan],
.schedule-table tr:last-child th[rowspan] {
  border-bottom: 2px solid #bcbcbc !important;
}

/* 確保右下角單元格有完整的邊框 */
.schedule-table tr:last-child td:last-child,
.schedule-table tr:last-child th:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

/* 特別處理右下角邊框缺失問題 */
.schedule-table tr:last-child td:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

.schedule-table tr:last-child th:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

/* 強制處理右下角邊框 - 使用更高優先級 */
.schedule-table tbody tr:last-child td:last-child,
.schedule-table tbody tr:last-child th:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

/* 處理可能的 rowspan 情況 */
.schedule-table tbody tr:last-child td[rowspan]:last-child,
.schedule-table tbody tr:last-child th[rowspan]:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

/* 使用 CSS 選擇器確保右下角邊框 */
.schedule-table tbody tr:last-child > td:last-child,
.schedule-table tbody tr:last-child > th:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
}

/* 終極強制處理右下角邊框 */
.schedule-table tbody tr:last-child td:last-child,
.schedule-table tbody tr:last-child th:last-child {
  border-right: 2px solid #bcbcbc !important;
  border-bottom: 2px solid #bcbcbc !important;
  border-right-width: 2px !important;
  border-bottom-width: 2px !important;
  border-right-style: solid !important;
  border-bottom-style: solid !important;
  border-right-color: #bcbcbc !important;
  border-bottom-color: #bcbcbc !important;
}

/* 處理可能的偽元素干擾 */
.schedule-table tbody tr:last-child td:last-child::after,
.schedule-table tbody tr:last-child th:last-child::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  background-color: #bcbcbc;
  z-index: 1000;
}

.schedule-table th {
  background: #e9ecef;
  text-align: center;
  font-weight: bold;
  padding: 4px;
}

.schedule-table td {
  padding: 0;
  vertical-align: top;
}

.has-course {
  position: relative;
}

.cell-content-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
}

.course-block {
  flex: 1 1 0;
  border-left: 1px solid #ddd;
  padding: 4px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.course-block:first-child {
    border-left: none;
}

/* 巢狀表格樣式 - 確保填滿整個父元素高度並與主表格行對齊 */
.nested-course-table {
  width: 100% !important;
  height: 100% !important;
  border-collapse: collapse !important;
  table-layout: fixed;
}

.nested-course-table td {
  vertical-align: top !important;
  border: 1px solid #ddd !important;
  padding: 2px !important;
}

/* 每個巢狀表格行應該有固定高度以與主表格對齊 */
.nested-course-table tr {
  /* 計算每個時段的高度 - 基於主表格的行高 */
  height: calc(100% / var(--periods-count));
}

/* 確保有 rowspan 的 td 元素填滿整個高度 */
.has-course {
  height: 100%;
  position: relative;
}

.has-course .nested-course-table {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* 為不同 rowspan 的巢狀表格設定 CSS 變數 */
.has-course[data-periods="1"] .nested-course-table {
  --periods-count: 1;
}

.has-course[data-periods="2"] .nested-course-table {
  --periods-count: 2;
}

.has-course[data-periods="3"] .nested-course-table {
  --periods-count: 3;
}

.has-course[data-periods="4"] .nested-course-table {
  --periods-count: 4;
}

.has-course[data-periods="5"] .nested-course-table {
  --periods-count: 5;
}

.has-course[data-periods="6"] .nested-course-table {
  --periods-count: 6;
}

.has-course[data-periods="7"] .nested-course-table {
  --periods-count: 7;
}

.course-title {
  display: inline;
  max-width: 100%;
  word-break: break-all;
  vertical-align: top;
  white-space: normal;
}

.period-header {
  font-weight: bold;
  text-align: center;
  vertical-align: middle;
  min-width: 48px;
  width: 48px;
  padding: 2px 0;
}

.period-time {
    display: block;
    font-size: 10px;
    font-weight: normal;
    margin-top: 2px;
    line-height: 1.1;
}

.cell-bottom-border {
  border-bottom: 2px solid #bcbcbc !important;
}

.lunch-break {
  text-align: center;
  font-size: 0.95em;
  color: #888;
  background: #fff;
  font-weight: bold;
  letter-spacing: 0.1em;
  height: 100%;
  vertical-align: middle;
  padding: 0;
}

.view-link {
  color: #0066cc;
  text-decoration: none;
  font-size: 0.9em;
}

.view-link:hover {
  text-decoration: underline;
}

/* 檔案上傳區域樣式 */
.file-upload {
  margin: 20px 0;
  padding: 20px;
  border: 2px dashed #ccc;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.upload-section {
  margin-bottom: 20px;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background-color: white;
}

.upload-section:last-child {
  margin-bottom: 0;
}

.upload-section h3 {
  margin: 0 0 10px 0;
  color: #333;
  font-size: 16px;
}

.upload-section p {
  margin: 5px 0;
  color: #666;
  font-size: 14px;
}

.upload-section .note {
  color: #e74c3c;
  font-size: 12px;
  font-style: italic;
}

.upload-section input[type="file"] {
  margin: 10px 0;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: white;
} 

.lunch-break {
  background-color: #e9ecef;
  line-height: 80px;
  text-align: center;
  vertical-align: middle;
  font-size: 1.1rem;        
  color: #5a4d2c;           
  padding: 12px 0;          
}

tr .lunch-break {
  border-top: 2px solid #e6d79f; /* 上下邊框讓午休段落更明顯 */
  border-bottom: 2px solid #e6d79f;
}
