/* ========================================
   響應式設計 CSS - 適用於所有裝置
   ======================================== */

/* 基礎響應式設定 */
* {
    box-sizing: border-box;
}

img {
    max-width: 100%;
    height: auto;
}

/* 容器響應式 */
.container-fluid {
    padding-left: 15px;
    padding-right: 15px;
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* 導航欄響應式優化 */
@media (max-width: 991.98px) {
    .navbar-brand-custom {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .navbar-collapse {
        margin-top: 10px;
    }
    
    .navbar-nav {
        margin-top: 10px;
    }
    
    .nav-item {
        padding: 5px 0;
    }
    
    .dropdown-menu {
        position: relative !important;
        float: none;
        width: 100%;
        margin: 0;
        border: none;
        box-shadow: none;
    }
}

/* 標題響應式 */
.page-caption {
    font-size: clamp(0.9rem, 2.5vw, 1.25rem);
    padding: 0.25em clamp(1rem, 3vw, 3rem);
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .page-caption {
        font-size: 0.9rem;
        padding: 0.25em 1rem;
        letter-spacing: 1px;
    }
}

/* 表格響應式 */
.table-responsive-custom {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.table-responsive-custom table {
    width: 100%;
    min-width: 650px;
    margin-bottom: 0;
}

@media (max-width: 991.98px) {
    table {
        font-size: 0.9rem;
    }
    
    table th,
    table td {
        padding: 0.5rem !important;
        white-space: nowrap;
    }
}

@media (max-width: 767.98px) {
    table {
        font-size: 0.85rem;
    }
    
    table th,
    table td {
        padding: 0.4rem !important;
    }
}

/* 卡片響應式 */
.card-custom {
    min-height: 50px;
    max-height: none;
    padding: 10px 5px;
}

@media (max-width: 991.98px) {
    .card_padding {
        margin-bottom: 10px;
    }
}

@media (max-width: 575.98px) {
    .card-custom {
        font-size: 0.9rem;
    }
    
    .card-custom .card-child {
        line-height: 1.5;
        padding: 5px;
    }
}

/* 圖片卡片響應式 */
.img-card {
    padding: 0 0.5rem;
    padding-bottom: 1.5rem;
    width: 100%;
    max-width: 100%;
}

@media (min-width: 992px) {
    .img-card {
        width: 50%;
    }
}

@media (max-width: 991.98px) {
    .img-card {
        width: 100%;
        padding: 0 0.5rem 1rem;
    }
}

/* 學程內容頁響應式 */
.plan-content {
    padding: 15px;
}

.plan-content-inner {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.plan-content-inner > div {
    padding: 0 15px;
    width: 100%;
}

@media (min-width: 992px) {
    .plan-content-inner > div {
        width: 50%;
    }
}

@media (max-width: 767.98px) {
    .plan-content {
        padding: 10px;
    }
    
    .plan-content-padding {
        padding: 10px 5px;
    }
}

/* 浮動按鈕響應式 */
.join-plan-div {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

@media (max-width: 575.98px) {
    .join-plan-div {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: 10px;
    }
    
    .join-plan-btn {
        font-size: 0.9rem;
        padding: 8px 15px !important;
    }
}

/* 表單元素響應式 */
.form-control {
    font-size: 1rem;
}

@media (max-width: 575.98px) {
    .form-control {
        font-size: 0.9rem;
        padding: 0.375rem 0.5rem;
    }
    
    .form-inline {
        flex-direction: column;
        align-items: flex-start !important;
    }
    
    .form-inline > * {
        margin-bottom: 10px;
        width: 100%;
    }
    
    .form-inline select.form-control {
        width: 100% !important;
    }
}

/* 產業證照地圖表格響應式 */
.certificate-table {
    width: 100%;
    margin-bottom: 1rem;
}

@media (max-width: 1199.98px) {
    .plan-content .certificate-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.85rem;
    }
    
    .plan-content .certificate-table thead th,
    .plan-content .certificate-table tbody td {
        padding: 10px 8px;
        white-space: nowrap;
    }
}

@media (max-width: 767.98px) {
    .plan-content .certificate-table {
        font-size: 0.75rem;
    }
    
    .plan-content .certificate-table thead th,
    .plan-content .certificate-table tbody td {
        padding: 8px 5px;
        font-size: 0.75rem;
    }
    
    .plan-content .certificate-table .level-badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
    
    .plan-content .certificate-table .department-tag,
    .plan-content .certificate-table .type-tag {
        font-size: 0.7rem;
        padding: 2px 6px;
    }
}

/* 列表響應式 */
.ttul {
    width: 100%;
    padding-left: 40px;
}

@media (max-width: 575.98px) {
    .ttul {
        padding-left: 25px;
        font-size: 0.9rem;
    }
    
    .ttul > li:after {
        left: -25px;
        width: 25px;
    }
}

/* 按鈕響應式 */
.btn-custom {
    padding: 10px 20px;
    font-size: 1rem;
}

@media (max-width: 575.98px) {
    .btn-custom {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
}

/* 相關數據區塊響應式 */
.related-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.related-col-3 {
    padding: 0 15px;
    width: 25%;
    margin-bottom: 20px;
}

@media (max-width: 991.98px) {
    .related-col-3 {
        width: 50%;
    }
}

@media (max-width: 575.98px) {
    .related-col-3 {
        width: 100%;
    }
    
    .related-column-num {
        font-size: 2rem !important;
    }
    
    .related-column-title {
        font-size: 0.9rem !important;
    }
}

/* 封面圖片響應式 */
.cover img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

@media (max-width: 767.98px) {
    .cover img {
        max-height: 300px;
    }
}

/* 間距調整 */
.custom-margin {
    margin-left: -15px;
    margin-right: -15px;
}

@media (max-width: 575.98px) {
    .custom-margin {
        margin-left: -10px;
        margin-right: -10px;
    }
    
    .unit-margin-bottom {
        margin-bottom: 15px !important;
    }
    
    .unit2-margin-bottom {
        margin-bottom: 10px !important;
    }
}

/* 文字大小響應式 */
@media (max-width: 575.98px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
    
    body {
        font-size: 0.9rem;
    }
}

/* 管理後台響應式 */
@media (max-width: 991.98px) {
    .manager-view {
        padding: 10px;
    }
    
    .manager-view table {
        font-size: 0.85rem;
    }
}

/* 對話框響應式 */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 10px;
    }
    
    .modal-content {
        border-radius: 5px;
    }
}

/* 下載區域響應式 */
.downloadList > div {
    position: relative;
    padding-left: 2rem;
}

@media (max-width: 575.98px) {
    .downloadList > div {
        font-size: 0.9rem;
        padding-left: 1.5rem;
    }
    
    .downloadList > div > img {
        height: 1rem;
        transform: translate(-120%, -50%);
    }
}

/* 影音專區響應式 */
@media (max-width: 767.98px) {
    .video-container {
        width: 100%;
        padding: 0;
    }
    
    .video-item {
        width: 100%;
        margin-bottom: 15px;
    }
}

/* 頁碼按鈕響應式 */
.page-array {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    margin: 20px 0;
}

@media (max-width: 575.98px) {
    .page-array button {
        padding: 5px 10px;
        font-size: 0.85rem;
        margin: 2px;
    }
}

/* 工具提示響應式 */
@media (max-width: 575.98px) {
    .tooltip-inner {
        font-size: 0.85rem;
    }
}

/* 確保內容不超出螢幕 */
body {
    overflow-x: hidden;
    width: 100%;
}

.row {
    margin-left: -15px;
    margin-right: -15px;
}

@media (max-width: 575.98px) {
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }
    
    [class*="col-"] {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* 印刷樣式優化 */
@media print {
    .navbar,
    .join-plan-div,
    .page-array,
    .btn {
        display: none !important;
    }
    
    body {
        padding-top: 0;
    }
    
    .plan-content {
        padding: 0;
    }
}

/* 橫向模式優化 */
@media (max-width: 767.98px) and (orientation: landscape) {
    .navbar-collapse {
        max-height: 200px;
        overflow-y: auto;
    }
}

/* 觸控優化 */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .card-custom,
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    .form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 1rem !important; /* 防止 iOS 縮放 */
    }
}

/* ==========================================
   進階響應式優化 - 2025年11月6日擴充
   ========================================== */

/* 更細緻的斷點設定 */

/* 極小手機 (iPhone SE) */
@media (max-width: 374px) {
    body {
        font-size: 0.85rem;
    }
    
    .navbar-brand-custom {
        padding: 8px 0;
    }
    
    .website-title {
        font-size: 0.75rem !important;
        max-width: 150px;
    }
    
    .page-caption {
        font-size: 0.85rem !important;
        padding: 0.2em 0.8rem !important;
    }
    
    .btn {
        font-size: 0.8rem;
        padding: 6px 12px;
    }
}

/* 小手機 (iPhone 12 mini, iPhone SE) */
@media (min-width: 375px) and (max-width: 413px) {
    .website-title {
        font-size: 0.8125rem;
        max-width: 160px;
    }
}

/* 標準手機 (iPhone 12, 13, 14) */
@media (min-width: 414px) and (max-width: 767px) {
    .website-title {
        font-size: 0.875rem;
        max-width: 180px;
    }
}

/* 大手機/小平板 (iPhone Pro Max, iPad mini portrait) */
@media (min-width: 768px) and (max-width: 820px) {
    .container-fluid {
        max-width: 95%;
    }
}

/* iPad/平板電腦 (橫向) */
@media (min-width: 821px) and (max-width: 1024px) {
    body {
        font-size: 0.95rem;
    }
    
    .plan-content {
        padding: 1.5rem 2.5rem;
    }
}

/* 小筆電 (1366x768) */
@media (min-width: 1025px) and (max-width: 1440px) {
    .container-fluid {
        max-width: 90%;
    }
}

/* 全局工具類別 */
.d-mobile-none {
    display: block;
}

.d-mobile-block {
    display: none;
}

@media (max-width: 767.98px) {
    .d-mobile-none {
        display: none !important;
    }
    
    .d-mobile-block {
        display: block !important;
    }
}

.d-tablet-none {
    display: block;
}

.d-tablet-block {
    display: none;
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .d-tablet-none {
        display: none !important;
    }
    
    .d-tablet-block {
        display: block !important;
    }
}

/* 彈性容器工具 */
.flex-mobile-column {
    display: flex;
}

@media (max-width: 767.98px) {
    .flex-mobile-column {
        flex-direction: column;
    }
    
    .flex-mobile-column > * {
        width: 100% !important;
        margin-bottom: 10px;
    }
}

/* 文字工具類別 */
.text-mobile-center {
    text-align: left;
}

@media (max-width: 767.98px) {
    .text-mobile-center {
        text-align: center !important;
    }
}

.text-truncate-mobile {
    white-space: normal;
}

@media (max-width: 575.98px) {
    .text-truncate-mobile {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* 間距工具 */
@media (max-width: 575.98px) {
    .p-mobile-1 { padding: 0.5rem !important; }
    .p-mobile-2 { padding: 1rem !important; }
    .p-mobile-3 { padding: 1.5rem !important; }
    
    .m-mobile-1 { margin: 0.5rem !important; }
    .m-mobile-2 { margin: 1rem !important; }
    .m-mobile-3 { margin: 1.5rem !important; }
    
    .px-mobile-0 { padding-left: 0 !important; padding-right: 0 !important; }
    .py-mobile-0 { padding-top: 0 !important; padding-bottom: 0 !important; }
}

/* 圖片優化 */
img {
    -webkit-user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.img-fluid-mobile {
    max-width: 100%;
    height: auto;
}

@media (max-width: 767.98px) {
    .img-fluid-mobile {
        width: 100%;
    }
}

/* 滾動優化 */
.scroll-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.scroll-container::-webkit-scrollbar {
    height: 6px;
}

.scroll-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.scroll-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.scroll-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 卡片優化 */
@media (max-width: 767.98px) {
    .card-custom {
        min-height: 48px !important;
        max-height: none;
        padding: 12px 8px;
    }
    
    .card-custom .card-child {
        line-height: 1.4;
        font-size: 0.9rem;
    }
}

@media (max-width: 575.98px) {
    .card-custom {
        min-height: 44px !important;
        padding: 10px 6px;
    }
    
    .card-custom .card-child {
        font-size: 0.85rem;
    }
}

/* 導航優化 */
@media (max-width: 991.98px) {
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
        border-radius: 0.25rem;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    .navbar-nav .nav-item:last-child .nav-link {
        border-bottom: none;
    }
}

/* 表單優化增強 */
@media (max-width: 767.98px) {
    .form-group {
        margin-bottom: 1rem;
    }
    
    label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
    }
    
    .form-control,
    .form-control-custom {
        width: 100% !important;
        max-width: 100%;
    }
    
    .form-inline {
        display: block;
    }
    
    .form-inline .form-control,
    .form-inline .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* 按鈕組優化 */
.btn-group-mobile {
    display: flex;
    gap: 10px;
}

@media (max-width: 575.98px) {
    .btn-group-mobile {
        flex-direction: column;
    }
    
    .btn-group-mobile .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .btn-group-mobile .btn:last-child {
        margin-bottom: 0;
    }
}

/* 固定定位元素優化 */
@media (max-width: 767.98px) {
    .fixed-bottom-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1030;
        background: white;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        padding: 10px;
    }
}

/* 模態框優化 */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 0.75rem;
    }
    
    .modal-title {
        font-size: 1.1rem;
    }
}

/* 表格堆疊模式 (行動裝置) */
@media (max-width: 575.98px) {
    .table-stack-mobile thead {
        display: none;
    }
    
    .table-stack-mobile tbody,
    .table-stack-mobile tr,
    .table-stack-mobile td {
        display: block;
        width: 100%;
    }
    
    .table-stack-mobile tr {
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 5px;
        padding: 10px;
    }
    
    .table-stack-mobile td {
        text-align: right;
        padding: 10px;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 50%;
    }
    
    .table-stack-mobile td:last-child {
        border-bottom: none;
    }
    
    .table-stack-mobile td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        font-weight: bold;
        text-align: left;
    }
}

/* 加載動畫優化 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 深色模式支援 (預備) */
@media (prefers-color-scheme: dark) {
    /* 保留供未來深色模式實作 */
}

/* 高對比模式支援 */
@media (prefers-contrast: high) {
    .btn,
    .card-custom,
    .form-control {
        border-width: 2px;
    }
}

/* 觸控裝置手勢提示 */
@media (hover: none) {
    .hover-hint::after {
        content: '👆';
        margin-left: 5px;
    }
}

/* 安全區域支援 (iPhone X 系列) */
@supports (padding: env(safe-area-inset-left)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* 效能優化 */
@media (max-width: 767.98px) {
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    img,
    video {
        will-change: transform;
    }
}
