/**
 * RWD 響應式網頁設計樣式
 * 專為邦捷人資管理系統設計的響應式增強樣式
 *
 * 斷點設計：
 * - xs: < 576px (手機直向)
 * - sm: 576px - 767px (手機橫向)
 * - md: 768px - 991px (平板)
 * - lg: 992px - 1199px (桌面)
 * - xl: >= 1200px (大螢幕)
 *
 * 注意：此檔案僅包含樣式，不修改任何 UI 邏輯
 */

/* ========================================
   基礎響應式設定
   ======================================== */

/* 確保所有元素使用 border-box */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* 基礎字體響應式 */
html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

@media (min-width: 576px) {
    html {
        font-size: 14px;
    }
}

@media (min-width: 768px) {
    html {
        font-size: 15px;
    }
}

@media (min-width: 992px) {
    html {
        font-size: 16px;
    }
}

/* ========================================
   表格響應式設計
   ======================================== */

/* 表格容器增強 */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
}

/* 手機螢幕 - 表格卡片化顯示 */
@media (max-width: 767.98px) {
    /* 表格標頭隱藏 */
    .table-card-mobile thead {
        display: none;
    }

    /* 表格行轉為區塊 */
    .table-card-mobile tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        padding: 0.75rem;
        background: #fff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    /* 表格儲存格轉為行內區塊 */
    .table-card-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid #f1f3f4;
    }

    .table-card-mobile tbody td:last-child {
        border-bottom: none;
    }

    /* 使用 data-label 顯示欄位名稱 */
    .table-card-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        flex-basis: 40%;
        text-align: left;
    }

    /* 標準表格 - 縮小字體和間距 */
    .table:not(.table-card-mobile) {
        font-size: 0.85rem;
    }

    .table:not(.table-card-mobile) th,
    .table:not(.table-card-mobile) td {
        padding: 0.5rem 0.35rem;
        white-space: nowrap;
    }

    /* 操作欄位 - 垂直排列按鈕 */
    .table td .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .table td .btn-group .btn {
        width: 100%;
        justify-content: center;
    }
}

/* 極小螢幕 - 進一步精簡 */
@media (max-width: 575.98px) {
    .table:not(.table-card-mobile) {
        font-size: 0.8rem;
    }

    .table:not(.table-card-mobile) th,
    .table:not(.table-card-mobile) td {
        padding: 0.4rem 0.25rem;
    }

    /* 隱藏次要欄位 */
    .table .d-none-xs {
        display: none !important;
    }
}

/* ========================================
   表單響應式設計
   ======================================== */

/* 表單群組基礎 */
.form-group {
    margin-bottom: 1rem;
}

/* 搜尋表單 - 響應式配置 */
.search-form .row {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
}

.search-form .row > [class*="col-"] {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* 平板以下 - 調整欄位寬度 */
@media (max-width: 991.98px) {
    .search-form .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.75rem;
    }

    .search-form .col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.75rem;
    }

    .search-form .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* 手機 - 全寬欄位 */
@media (max-width: 767.98px) {
    .search-form .col-md-3,
    .search-form .col-md-4,
    .search-form .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* 輸入框 - 避免 iOS 縮放 */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    textarea {
        font-size: 16px !important;
    }
}

/* 表單標籤響應式 */
@media (max-width: 575.98px) {
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.35rem;
    }

    .form-control,
    .form-select {
        padding: 0.5rem 0.75rem;
    }
}

/* ========================================
   按鈕響應式設計
   ======================================== */

/* 按鈕群組基礎 */
.btn-group-responsive {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* 平板以下 - 按鈕自適應 */
@media (max-width: 991.98px) {
    .btn-group-responsive .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* 手機 - 按鈕全寬 */
@media (max-width: 767.98px) {
    .btn-group-responsive {
        flex-direction: column;
    }

    .btn-group-responsive .btn {
        width: 100%;
    }

    /* 功能區按鈕調整 */
    .function-area .btn-group,
    .card-body > .row > .col-md-8 .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .function-area .btn-group .btn,
    .card-body > .row > .col-md-8 .btn-group .btn {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
}

/* 極小螢幕 - 按鈕完全堆疊 */
@media (max-width: 575.98px) {
    .function-area .btn-group .btn,
    .card-body > .row > .col-md-8 .btn-group .btn {
        flex: 1 1 100%;
    }

    .btn-sm {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* ========================================
   卡片響應式設計
   ======================================== */

/* 卡片基礎響應式 */
.card {
    margin-bottom: 1rem;
}

/* 卡片標頭響應式 */
@media (max-width: 767.98px) {
    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-header h5,
    .card-header .card-title {
        font-size: 1rem;
    }

    .card-body {
        padding: 1rem;
    }
}

@media (max-width: 575.98px) {
    .card-header {
        padding: 0.625rem 0.75rem;
    }

    .card-body {
        padding: 0.75rem;
    }
}

/* 統計卡片響應式 */
@media (max-width: 767.98px) {
    .stats-card .stats-number {
        font-size: 1.5rem;
    }

    .stats-card .stats-label {
        font-size: 0.8rem;
    }

    .stats-card .card-body .row > div {
        margin-bottom: 1rem;
    }
}

/* ========================================
   Modal 響應式設計
   ======================================== */

/* Modal 基礎響應式 */
.modal-dialog {
    margin: 0.5rem auto;
    max-height: calc(100vh - 1rem);
}

/* 平板 */
@media (max-width: 991.98px) {
    .modal-lg,
    .modal-xl {
        max-width: calc(100% - 1rem);
        margin-left: 0.5rem;
        margin-right: 0.5rem;
    }
}

/* 手機 */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
        max-height: calc(100vh - 0.5rem);
    }

    .modal-header {
        padding: 0.75rem 1rem;
    }

    .modal-header .modal-title {
        font-size: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 180px);
        overflow-y: auto;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
    }
}

/* 極小螢幕 */
@media (max-width: 575.98px) {
    .modal-header {
        padding: 0.625rem 0.75rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-footer {
        padding: 0.625rem 0.75rem;
    }

    .modal-footer .btn {
        flex: 1 1 100%;
    }
}

/* ========================================
   導航與選單響應式
   ======================================== */

/* 側邊選單響應式 */
@media (max-width: 991.98px) {
    .side-area {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1050;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding-top: 60px;
    }

    .side-area.show {
        left: 0;
    }

    /* 遮罩層 */
    .side-area-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
    }

    .side-area-backdrop.show {
        display: block;
    }
}

/* 手機選單項目 */
@media (max-width: 767.98px) {
    .mobile-menu-area {
        padding: 1rem;
    }

    .mobile-menu-area .nav-link {
        padding: 0.625rem 1rem;
        font-size: 0.9rem;
        border-radius: 0.375rem;
    }

    .mobile-controller-title {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

/* ========================================
   標題與文字響應式
   ======================================== */

/* 頁面標題 */
h1, .h1 {
    font-size: 1.75rem;
}

h2, .h2 {
    font-size: 1.5rem;
}

h3, .h3 {
    font-size: 1.25rem;
}

@media (max-width: 767.98px) {
    h1, .h1 {
        font-size: 1.5rem;
    }

    h2, .h2 {
        font-size: 1.25rem;
    }

    h3, .h3 {
        font-size: 1.1rem;
    }
}

@media (max-width: 575.98px) {
    h1, .h1 {
        font-size: 1.35rem;
    }

    h2, .h2 {
        font-size: 1.15rem;
    }

    h3, .h3 {
        font-size: 1rem;
    }
}

/* 頁面標題區塊 */
#title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    #title {
        flex-direction: column;
        align-items: flex-start;
    }

    #title .badge {
        margin-left: 0;
    }
}

/* ========================================
   Badge 響應式設計
   ======================================== */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

@media (max-width: 767.98px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.3em 0.6em;
    }
}

/* ========================================
   警告訊息響應式
   ======================================== */

.alert {
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .alert.position-fixed {
        left: 0.5rem !important;
        right: 0.5rem !important;
        top: 0.5rem !important;
        max-width: none;
        min-width: auto;
    }
}

/* ========================================
   搜尋結果統計響應式
   ======================================== */

@media (max-width: 767.98px) {
    .search-result-stats {
        flex-direction: column;
        gap: 0.5rem;
    }

    .search-result-stats small {
        display: block;
    }
}

/* ========================================
   功能區域響應式
   ======================================== */

@media (max-width: 767.98px) {
    .function-area .row {
        flex-direction: column;
    }

    .function-area .col-md-8,
    .function-area .col-md-4 {
        width: 100%;
        max-width: 100%;
    }

    .function-area .text-end {
        text-align: left !important;
        margin-top: 0.75rem;
    }
}

/* ========================================
   空資料狀態響應式
   ======================================== */

.no-data,
.empty-state {
    padding: 2rem 1rem;
}

@media (max-width: 767.98px) {
    .no-data i,
    .empty-state i {
        font-size: 2.5rem;
    }

    .no-data h4,
    .empty-state h4 {
        font-size: 1.1rem;
    }

    .no-data p,
    .empty-state p {
        font-size: 0.9rem;
    }
}

/* ========================================
   Checkbox 響應式
   ======================================== */

@media (max-width: 767.98px) {
    .form-check-input {
        width: 1.25em;
        height: 1.25em;
    }

    .table .form-check-input {
        margin-top: 0;
    }
}

/* ========================================
   日期時間選擇器響應式
   ======================================== */

@media (max-width: 767.98px) {
    #ui-datepicker-div,
    .ui-datepicker {
        width: calc(100vw - 1rem) !important;
        max-width: 320px;
        font-size: 0.85rem !important;
    }

    .ui-datepicker-calendar td a {
        padding: 0.35rem !important;
    }
}

@media (max-width: 575.98px) {
    #ui-datepicker-div,
    .ui-datepicker {
        max-width: 280px;
        font-size: 0.8rem !important;
    }
}

/* ========================================
   時間軸響應式 (審核歷程)
   ======================================== */

@media (max-width: 767.98px) {
    .timeline {
        padding-left: 1.5rem;
    }

    .timeline-marker {
        left: -1.25rem;
        width: 10px;
        height: 10px;
    }

    .timeline-content {
        margin-left: 0.5rem;
    }
}

/* ========================================
   附件列表響應式
   ======================================== */

@media (max-width: 767.98px) {
    .attachment-item {
        flex-direction: column;
        align-items: stretch;
    }

    .attachment-item > div:first-child {
        margin-bottom: 0.5rem;
    }

    .attachment-item .btn-group {
        justify-content: flex-end;
    }
}

/* ========================================
   Grid 響應式補強
   ======================================== */

/* 確保 row 在小螢幕正確換行 */
@media (max-width: 767.98px) {
    .row > .col-md-3,
    .row > .col-md-4,
    .row > .col-md-6,
    .row > .col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* 雙欄配置用於中等螢幕 */
@media (min-width: 576px) and (max-width: 767.98px) {
    .row > .col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ========================================
   列印樣式
   ======================================== */

@media print {
    .side-area,
    .mobile-menu-area,
    .menu-toggle-btn,
    .btn-group,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .table {
        font-size: 10pt;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ========================================
   無障礙支援
   ======================================== */

/* 焦點可見性 */
:focus-visible {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* 減少動態偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高對比模式 */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }

    .form-control,
    .form-select {
        border-width: 2px;
    }

    .card {
        border-width: 2px;
    }
}

/* ========================================
   觸控設備優化
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* 增大觸控目標 */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
    }

    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* 移除 hover 效果 */
    .btn:hover {
        transform: none;
    }

    .card:hover {
        transform: none;
    }
}

/* ========================================
   Safari iOS 修復
   ======================================== */

/* 修復 iOS Safari 縮放問題 */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px;
    }
}

/* 修復 iOS Safari 滾動彈性 */
.modal-body,
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   橫向模式特殊處理
   ======================================== */

@media (orientation: landscape) and (max-height: 500px) {
    .modal-body {
        max-height: calc(100vh - 120px);
    }

    .mobile-menu-area {
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
}
