
:root {
    --primary-color: #6495ED;
    --secondary-color: #4169E1;
    --text-color: #333;
    --border-color: #ddd;
    --bg-light: #f8f9fa;
    --success-color: #28a745;
    --info-color: #17a2b8;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft JhengHei', 'Segoe UI', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: #fff;
}

/* 初始載入全螢幕遮罩 */
#init-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    /* JS 控制顯示 */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    text-align: center;
}

#init-loading .spinner {
    margin-bottom: 1rem;
}

/* 跳到主要內容連結 - 無障礙 */
.skip-link {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
}

.skip-link:focus {
    left: 10px;
    top: 10px;
}

/* 導航列 */
.navbar {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1rem 0;
}

.navbar-brand {
    color: white !important;
    font-weight: bold;
    font-size: 1.25rem;
}

.navbar-brand:hover {
    color: #f0f0f0 !important;
}

/* 查詢表單區域 */
.search-section {
    background: var(--bg-light);
    padding: 2rem 0;
    margin-top: 70px;
}

.form-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.form-header {
    background: var(--info-color);
    color: white;
    padding: 1rem;
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    border-radius: 8px 8px 0 0;
    font-weight: bold;
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.form-control,
.form-select {
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(100, 149, 237, 0.25);
}

/* 按鈕樣式 */
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    padding: 0.75rem 2rem;
    font-weight: 600;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
    transform: translateY(-1px);
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    border-radius: 4px;
}

/* 結果表格 - 改進部分 */
.results-section {
    padding: 2rem 0;
    scroll-margin-top: 80px;
}

/* 表格工具列 */
.table-toolbar {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.85rem;
}

.table-toolbar .toolbar-section {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.table-toolbar .form-control,
.table-toolbar .form-select {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    min-width: 100px;
}

.table-toolbar .form-label {
    font-size: 0.8rem;
    margin: 0;
    white-space: nowrap;
}

.table-toolbar .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* 表格容器 - 支援橫向滑動 */
.table-container {
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    background: white;
}

.table-responsive {
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f1f1;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.table {
    margin-bottom: 0;
    font-size: 0.85rem;
    min-width: 1400px;
    /* 確保最小寬度支援所有欄位 */
}

.table thead th {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.75rem 0.5rem;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.table thead th:hover {
    background: #5a6268;
}

.table thead th.sortable::after {
    content: ' ⇅';
    opacity: 0.5;
}

.table thead th.sort-asc::after {
    content: ' ↑';
    opacity: 1;
}

.table thead th.sort-desc::after {
    content: ' ↓';
    opacity: 1;
}

.table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: rgba(100, 149, 237, 0.05);
}

.table tbody tr.filtered-out {
    display: none;
}

.table tbody td {
    padding: 0.5rem;
    vertical-align: middle;
    border: none;
    /* white-space: nowrap; */
    white-space: normal;
    text-align: center;
}

/* 特殊欄位樣式 */
.course-code {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
}

.course-name {
    max-width: 200px;
    white-space: normal;
}

.course-name strong {
    display: block;
    margin-bottom: 0.25rem;
}

.course-name em {
    font-size: 0.8rem;
    color: #666;
    display: none;
    /* 預設隱藏英文 */
}

.show-english .course-name em {
    display: block;
}

.teacher-links {
    max-width: 150px;
}

.teacher-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.85rem;
}

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

.schedule-cell {
    max-width: 120px;
    font-size: 0.8rem;
}

.syllabus-link {
    color: var(--success-color);
    text-decoration: none;
    font-size: 0.8rem;
}

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

/* 手機版卡片樣式 原768px 修正版型 */
@media (max-width: 1000px) {
    .navbar .container {
        display: flex;
        justify-content: center;
    }
    
    .form-header{
        display: none;
    }

    .table-responsive {
        display: none;
    }

    .table-toolbar {
        display: none;
    }

    .mobile-cards {
        display: block;
    }

    .course-card {
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        margin-bottom: 1rem;
        padding: 1rem;
        border-left: 4px solid var(--primary-color);
    }

    .course-header {
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .course-title {
        font-size: 1.1rem;
        font-weight: bold;
        color: var(--primary-color);
        margin-bottom: 0.25rem;
    }

    .course-code {
        font-size: 0.9rem;
        color: #666;
        background: var(--bg-light);
        padding: 0 !important;
        border-radius: 4px;
        display: inline-block;
    }

    .course-info {
        display: grid;
        gap: 0.5rem;
    }

    .info-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .info-item {
        flex: 1;
        min-width: 120px;
    }

    .info-label {
        font-weight: 600;
        color: var(--text-color);
        font-size: 0.85rem;
        margin-bottom: 0.25rem;
        display: block;
    }

    .info-value {
        font-size: 0.9rem;
        color: #555;
    }

    .search-section {
        padding: 1rem 0;
        margin-top: 60px;
    }

    .form-card {
        padding: 1rem;
    }

    .form-header {
        margin: -1rem -1rem 1rem -1rem;
        padding: 0.75rem;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .navbar-brand {
        font-size: 1rem;
    }
}

@media (min-width: 1001px) {
    .mobile-cards {
        display: none;
    }
}

@media (min-width: 1600px) {
    .container {
        max-width: 1520px !important;
    }
}

@media (max-width: 1000px) {
    .container {
        max-width: 540px !important;
    }
}

/* 無障礙焦點樣式 */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 說明文字 */
.info-text {
    background: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 4px;
    padding: 1rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.info-text h6 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-weight: bold;
}

/* 載入動畫 - 改進為全螢幕居中 */
.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading p {
    font-size: 1.1rem;
    color: var(--text-color);
    margin: 0;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 輔助工具 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 表格欄位隱藏功能 */
.table .hideable-column {
    display: none;
}

.table.show-all-columns .hideable-column {
    display: table-cell;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-available {
    background-color: #d4edda;
    color: #155724;
}

.status-full {
    background-color: #f8d7da;
    color: #721c24;
}

.status-limited {
    background-color: #fff3cd;
    color: #856404;
}

/* 新增：統計資訊 */
.results-stats {
    background: linear-gradient(135deg, #e3f2fd, #f3e5f5);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border-left: 4px solid var(--primary-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-item {
    text-align: center;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.9rem;
    color: #666;
}

#error-screen {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: #fff;
    color: #333;
    font-size: 1.5rem;
    font-weight: bold;
    z-index: 3000;
    /* display: flex; */
    justify-content: center;
    align-items: center;
    text-align: center;
}
