/**
 * Migrant Ticket Design System - Main Entry
 * CSS 主入口文件
 *
 * 注意：由於 JSP 靜態資源引入限制，此文件使用 @import 合併所有樣式。
 * 生產環境建議使用建構工具（如 Webpack/Gulp）合併壓縮 CSS。
 */

/* ========== 基礎樣式 ========== */
@import url('./base/_variables.css');
@import url('./base/_reset.css');
@import url('./base/_typography.css');

/* ========== 元件樣式 ========== */
@import url('./components/_buttons.css');
@import url('./components/_cards.css');
@import url('./components/_forms.css');
@import url('./components/_badges.css');
@import url('./components/_alerts.css');
@import url('./components/_loaders.css');

/* ========== 佈局樣式 ========== */
@import url('./layouts/_header.css');
@import url('./layouts/_footer.css');

/* ========== 頁面樣式 ========== */
@import url('./pages/_search.css');
@import url('./pages/_results.css');
@import url('./pages/_booking.css');
@import url('./pages/_complete.css');
@import url('./pages/_error.css');

/* ========== 工具類 ========== */

/* 顯示/隱藏 */
.mt-hidden { display: none !important; }
.mt-visible { visibility: visible !important; }
.mt-invisible { visibility: hidden !important; }

/* Flexbox */
.mt-flex { display: flex; }
.mt-inline-flex { display: inline-flex; }
.mt-flex-col { flex-direction: column; }
.mt-flex-wrap { flex-wrap: wrap; }
.mt-items-center { align-items: center; }
.mt-items-start { align-items: flex-start; }
.mt-items-end { align-items: flex-end; }
.mt-justify-center { justify-content: center; }
.mt-justify-between { justify-content: space-between; }
.mt-justify-end { justify-content: flex-end; }
.mt-flex-1 { flex: 1; }
.mt-flex-shrink-0 { flex-shrink: 0; }

/* 間距 */
.mt-gap-1 { gap: var(--mt-space-1); }
.mt-gap-2 { gap: var(--mt-space-2); }
.mt-gap-3 { gap: var(--mt-space-3); }
.mt-gap-4 { gap: var(--mt-space-4); }
.mt-gap-5 { gap: var(--mt-space-5); }
.mt-gap-6 { gap: var(--mt-space-6); }

/* Margin */
.mt-m-0 { margin: 0; }
.mt-m-auto { margin: auto; }
.mt-mt-0 { margin-top: 0; }
.mt-mt-2 { margin-top: var(--mt-space-2); }
.mt-mt-4 { margin-top: var(--mt-space-4); }
.mt-mt-6 { margin-top: var(--mt-space-6); }
.mt-mt-8 { margin-top: var(--mt-space-8); }
.mt-mb-0 { margin-bottom: 0; }
.mt-mb-2 { margin-bottom: var(--mt-space-2); }
.mt-mb-4 { margin-bottom: var(--mt-space-4); }
.mt-mb-6 { margin-bottom: var(--mt-space-6); }
.mt-mb-8 { margin-bottom: var(--mt-space-8); }

/* Padding */
.mt-p-0 { padding: 0; }
.mt-p-2 { padding: var(--mt-space-2); }
.mt-p-4 { padding: var(--mt-space-4); }
.mt-p-6 { padding: var(--mt-space-6); }
.mt-py-4 { padding-top: var(--mt-space-4); padding-bottom: var(--mt-space-4); }
.mt-py-6 { padding-top: var(--mt-space-6); padding-bottom: var(--mt-space-6); }
.mt-px-4 { padding-left: var(--mt-space-4); padding-right: var(--mt-space-4); }
.mt-px-6 { padding-left: var(--mt-space-6); padding-right: var(--mt-space-6); }

/* 寬度 */
.mt-w-full { width: 100%; }
.mt-w-auto { width: auto; }
.mt-max-w-sm { max-width: 384px; }
.mt-max-w-md { max-width: 448px; }
.mt-max-w-lg { max-width: 512px; }
.mt-max-w-xl { max-width: 576px; }

/* 背景 */
.mt-bg-white { background-color: var(--mt-white); }
.mt-bg-gray-50 { background-color: var(--mt-gray-50); }
.mt-bg-gray-100 { background-color: var(--mt-gray-100); }
.mt-bg-primary { background: var(--mt-gradient-primary); }

/* 邊框 */
.mt-border { border: 1px solid var(--mt-border-color); }
.mt-border-t { border-top: 1px solid var(--mt-border-color); }
.mt-border-b { border-bottom: 1px solid var(--mt-border-color); }
.mt-rounded { border-radius: var(--mt-radius-md); }
.mt-rounded-lg { border-radius: var(--mt-radius-lg); }
.mt-rounded-xl { border-radius: var(--mt-radius-xl); }
.mt-rounded-full { border-radius: var(--mt-radius-full); }

/* 陰影 */
.mt-shadow { box-shadow: var(--mt-shadow-md); }
.mt-shadow-lg { box-shadow: var(--mt-shadow-lg); }
.mt-shadow-xl { box-shadow: var(--mt-shadow-xl); }

/* 定位 */
.mt-relative { position: relative; }
.mt-absolute { position: absolute; }
.mt-fixed { position: fixed; }
.mt-sticky { position: sticky; }

/* 溢出 */
.mt-overflow-hidden { overflow: hidden; }
.mt-overflow-auto { overflow: auto; }
.mt-overflow-x-auto { overflow-x: auto; }

/* 游標 */
.mt-cursor-pointer { cursor: pointer; }
.mt-cursor-not-allowed { cursor: not-allowed; }

/* 選擇 */
.mt-select-none { user-select: none; }

/* ========== 動畫 ========== */
.mt-animate-fade-in {
    animation: mt-fade-in 0.3s ease-out;
}

.mt-animate-fade-in-up {
    animation: mt-fade-in-up 0.4s ease-out;
}

.mt-animate-slide-in-right {
    animation: mt-slide-in-right 0.3s ease-out;
}

@keyframes mt-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes mt-fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mt-slide-in-right {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========== 響應式工具類 ========== */
@media (max-width: 768px) {
    .mt-hidden-mobile { display: none !important; }
    .mt-flex-col-mobile { flex-direction: column; }
    .mt-text-center-mobile { text-align: center; }
}

@media (min-width: 769px) {
    .mt-hidden-desktop { display: none !important; }
}

/* ========== 頁面過渡 ========== */
body.mt-page-transition {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

body.mt-page-loaded {
    opacity: 1;
}

/* ========== 無障礙 ========== */
.mt-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;
}

/* Focus visible for keyboard navigation */
.mt-focus-visible:focus-visible {
    outline: 2px solid var(--mt-brand-primary);
    outline-offset: 2px;
}

/* ========== Bootstrap 品牌色覆寫 ========== */
/* 表單焦點狀態統一為品牌紫色 */
.form-control:focus,
.form-select:focus {
    border-color: #0066cc;
    box-shadow: 0 0 0 0.2rem rgba(0, 102, 204, 0.25);
}

/* 主要按鈕統一為品牌漸層 */
.btn-primary {
    background: linear-gradient(135deg, #0066cc 0%, #004a99 100%);
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0052a3 0%, #003d82 100%);
    border: none;
}

.btn-primary:focus,
.btn-primary:active {
    background: linear-gradient(135deg, #0052a3 0%, #003d82 100%);
    border: none;
    box-shadow: 0 0 0 0.2rem rgba(0, 102, 204, 0.25);
}

/* ========== 表單驗證動畫 ========== */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

.shake-animation {
    animation: shake 0.5s ease-in-out;
}

/* 驗證錯誤欄位增強樣式 */
.is-invalid {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.is-invalid:focus {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.5);
}

.invalid-feedback {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #dc3545;
}

.invalid-feedback i {
    font-size: 0.875rem;
}

/* ========== 響應式表格（手機版卡片佈局）========== */
/* 使用方法：在 <table> 添加 class="mt-responsive-table"，在 <td> 添加 data-label="欄位名稱" */

/* 桌面版：正常表格顯示 */
.mt-responsive-table {
    width: 100%;
}

/* 手機版：卡片式佈局 */
@media (max-width: 768px) {
    .mt-responsive-table {
        border: 0;
    }

    /* 隱藏表格 header */
    .mt-responsive-table thead {
        display: none;
    }

    /* 每一行變成一張卡片 */
    .mt-responsive-table tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--mt-border-color);
        border-radius: var(--mt-radius-md);
        background: var(--mt-white);
        box-shadow: var(--mt-shadow-sm);
    }

    /* 每個儲存格變成一行 */
    .mt-responsive-table tbody td {
        display: block;
        text-align: right;
        padding: 0.75rem 1rem;
        border: none;
        border-bottom: 1px solid var(--mt-gray-100);
    }

    .mt-responsive-table tbody td:last-child {
        border-bottom: none;
    }

    /* 使用 data-label 顯示欄位名稱 */
    .mt-responsive-table tbody td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: var(--mt-gray-700);
    }

    /* 沒有 data-label 的儲存格（如操作按鈕）居中顯示 */
    .mt-responsive-table tbody td:not([data-label]) {
        text-align: center;
    }

    /* 操作按鈕垂直排列 */
    .mt-responsive-table tbody td .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .mt-responsive-table tbody td .btn-group .btn {
        width: 100%;
    }

    /* Badge 和狀態標籤 */
    .mt-responsive-table tbody td .badge {
        display: inline-block;
        margin-left: 0.5rem;
    }

    /* 隱藏不重要的欄位（添加 .mt-hide-mobile 類別）*/
    .mt-responsive-table tbody td.mt-hide-mobile {
        display: none;
    }

    /* 增大觸控目標（按鈕、連結）*/
    .mt-responsive-table tbody td .btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }

    .mt-responsive-table tbody td a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.25rem 0;
    }
}

/* ========== Loading 狀態統一 ========== */

/* 1. 按鈕 Loading 狀態 */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    left: 50%;
    margin-left: -0.5rem;
    margin-top: -0.5rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
    to { transform: rotate(360deg); }
}

/* 2. 頁面級 Loading（全螢幕遮罩）*/
.mt-page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mt-page-loader.show {
    opacity: 1;
    visibility: visible;
}

.mt-page-loader .spinner {
    width: 3rem;
    height: 3rem;
    border: 4px solid rgba(0, 102, 204, 0.2);
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.mt-page-loader .loading-text {
    margin-top: 1rem;
    color: var(--mt-gray-700);
    font-size: 0.9rem;
    font-weight: 500;
}

/* 3. 區塊級 Loading（局部載入）*/
.mt-block-loader {
    position: relative;
    min-height: 100px;
}

.mt-block-loader::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    z-index: 10;
}

.mt-block-loader::after {
    content: "";
    position: absolute;
    width: 2rem;
    height: 2rem;
    top: 50%;
    left: 50%;
    margin-left: -1rem;
    margin-top: -1rem;
    border: 3px solid rgba(0, 102, 204, 0.2);
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
    z-index: 11;
}

/* 4. 內聯 Spinner（小型）*/
.mt-spinner-sm {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(0, 102, 204, 0.2);
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
    vertical-align: middle;
}

.mt-spinner-md {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid rgba(0, 102, 204, 0.2);
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

/* 5. 骨架屏（Skeleton Screen）*/
.mt-skeleton {
    background: linear-gradient(
        90deg,
        var(--mt-gray-200) 0%,
        var(--mt-gray-100) 50%,
        var(--mt-gray-200) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--mt-radius-sm);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.mt-skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

.mt-skeleton-text:last-child {
    width: 80%;
}

.mt-skeleton-card {
    height: 200px;
    border-radius: var(--mt-radius-md);
}

.mt-skeleton-circle {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
}

/* 6. 表單提交 Loading 狀態 */
form.submitting {
    pointer-events: none;
    opacity: 0.6;
}

form.submitting button[type="submit"] {
    position: relative;
}

form.submitting button[type="submit"]::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    right: 1rem;
    margin-top: -0.5rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

/* ========== Bootstrap 原生元件字級覆寫 ==========
 * Bootstrap .badge/.small/.form-text 等元件預設用相對 em 單位（如 .75em），
 * 在一般文字大小下會低於規格要求的14px，此處統一覆寫為最小14px下限。
 */
.badge {
    font-size: max(14px, 0.75em);
}

small,
.small,
.form-text {
    font-size: max(14px, 0.875em);
}

/* ========== 列印樣式 ========== */
@media print {
    .mt-no-print {
        display: none !important;
    }

    .mt-page-loader,
    .mt-back-to-top,
    .mt-navbar-toggler {
        display: none !important;
    }

    body {
        background: white;
    }
}
