/* SDLP 響應式設計 CSS */

/* 基本響應式設置 */
* {
    box-sizing: border-box;
}

/* 表格響應式 */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 600px;
}

/* 圖片響應式基本設定 */
.menu-frame img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
}

/* 進度百分比樣式 */
.progress-menu {
    position: relative;
}

.progress-badge {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background-color: #cfd0d0;
    border-radius: 4px;
    padding: 2px 6px;
    opacity: 0.9;
}

.progress-text {
    font-size: 14px;
    color: #d96652;
    font-family: fantasy;
    font-weight: bold;
}

/* 階段圖片響應式 */
.stage-container {
    text-align: center;
    margin-top: 20px;
}

.stage-image {
    max-width: 100%;
    height: auto;
    max-height: 200px;
}

/* 觸控設備改善 */
.touch-device .menu-frame {
    -webkit-tap-highlight-color: rgba(255, 0, 5, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.touch-device .menu-frame a {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
    transition: all 0.2s ease;
}

/* 觸控活躍狀態 */
.touch-active {
    background-color: rgba(255, 0, 5, 0.05) !important;
    transform: scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* 觸控回饋動畫 */
.touch-feedback {
    background-color: rgba(255, 0, 5, 0.1) !important;
    transform: scale(0.95);
    box-shadow: 0 0 10px rgba(255, 0, 5, 0.3);
}

/* 載入指示器 */
.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 1000;
    pointer-events: none;
}

/* 改善觸控目標大小 */
.touch-device .menu-frame {
    min-width: 44px;
}

/* 平板尺寸 (768px - 991px) */
@media (min-width: 768px) and (max-width: 991px) {
    /* 主要標題區域響應式 */
    #title-bar {
        width: 100% !important;
        max-width: 1200px;
        padding: 10px 15px;
        position: relative !important;
        height: auto !important;
        min-height: 80px;
    }

    #title-left {
        font-size: 3rem !important;
        text-align: center !important;
        margin-bottom: 10px;
    }
    
    #title-mid {
        font-size: 2rem !important;
        text-align: center !important;
        padding: 10px !important;
        line-height: 1.2 !important;
    }
    
    /* 主框架響應式 */
    .main-frame {
        width: 100% !important;
        max-width: 1000px;
        position: relative !important;
        top: 20px !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 auto !important;
        padding: 0 15px;
    }
    
    .menu-frame {
        width: 32% !important;
        max-width: 250px !important;
        height: auto !important;
        display: inline-block !important;
        margin: 0.5% !important;
        padding: 8px !important;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    /* 登入頁面響應式 */
    .main {
        width: 90% !important;
        max-width: 700px;
        height: auto !important;
        position: relative !important;
        top: 20px !important;
        left: 0 !important;
        right: 0 !important;
        margin: 20px auto !important;
        padding: 20px;
    }

    .main-left1, .main-left2 {
        width: 100% !important;
        text-align: center !important;
        float: none !important;
    }

    .main-right {
        width: 100% !important;
        float: none !important;
        margin: 0 !important;
    }
}

/* 桌機尺寸 (992px 以上) - 恢復原始設計 */
@media (min-width: 992px) {
    /* 恢復圖片原始尺寸 */
    .menu-frame img {
        width: auto !important;
        height: auto !important;
        max-width: none !important;
        display: inline-block;
    }
    
    /* 恢復桌機版選單框架原始設定 */
    .menu-frame {
        width: auto !important;
        height: auto !important;
        max-width: none !important;
        min-height: auto !important;
        padding: 0 !important;
        margin: auto !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }
    
    /* 按鈕在桌機版使用預設寬度 */
    .btn-responsive {
        width: auto;
    }
}

/* 手機尺寸 (767px 以下) */
@media (max-width: 767px) {
    /* 主要標題區域響應式 */
    #title-bar {
        width: 100% !important;
        max-width: 1200px;
        padding: 8px 10px;
        position: relative !important;
        height: auto !important;
        min-height: auto;
    }

    #title-left {
        font-size: 1.5rem !important;
        text-align: center !important;
        margin-bottom: 0;
        float: none !important;
        display: block !important;
        width: 100% !important;
        height: auto !important;
        line-height: 1.3 !important;
    }

    #title-left font,
    #title-left * {
        font-size: 1.5rem !important;
    }

    #title-mid {
        font-size: 1.1rem !important;
        text-align: center !important;
        padding: 0 !important;
        line-height: 1.3 !important;
        float: none !important;
        display: block !important;
        width: 100% !important;
        height: auto !important;
        margin-top: 2px;
    }

    /* plan.php 內容區域手機版字體調整 */
    .content {
        height: auto !important;
        padding: 10px !important;
    }

    .content font,
    .content font[size],
    .content font[size="3"],
    .content font[size="6"],
    .content font[size="7"] {
        font-size: 1rem !important;
    }

    .content p {
        font-size: 1rem !important;
        line-height: 1.5 !important;
        margin: 5px 0 !important;
    }

    .content table {
        width: 100% !important;
    }

    .content td {
        display: block !important;
        width: 100% !important;
        text-align: center !important;
        padding: 5px 0 !important;
    }

    .content div[style*="margin:150px"] {
        margin: 10px !important;
    }

    /* 主框架響應式 */
    .main-frame {
        width: 100% !important;
        max-width: 1000px;
        position: relative !important;
        top: 20px !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 auto !important;
        padding: 0 10px !important;
        text-align: center !important;
        font-size: 0 !important; /* 消除 inline-block 間隙 */
        box-sizing: border-box !important;
    }

    /* 登入頁面響應式 */
    .main {
        width: 95% !important;
        max-width: 600px;
        height: auto !important;
        position: relative !important;
        top: 10px !important;
        left: 0 !important;
        right: 0 !important;
        margin: 10px auto !important;
        padding: 15px 10px !important;
        min-height: auto !important;
    }

    .main-left1, .main-left2 {
        width: 100% !important;
        text-align: center !important;
        float: none !important;
        margin-bottom: 5px !important;
        font-size: 1.2rem !important;
        line-height: 1.3 !important;
        padding: 5px 0 !important;
    }
    
    .main-left1 {
        font-size: 1.5rem !important;
    }

    .main-right {
        width: 100% !important;
        float: none !important;
        margin: 10px 0 0 0 !important;
        padding: 0 !important;
    }
    
    /* 主框架內文字手機版調整 */
    .main-frame font,
    .main-frame font[size],
    .main-frame font[size="5"],
    .main-frame font[size="6"],
    .main-frame font[size="7"],
    .main-frame p {
        font-size: 1rem !important;
        line-height: 1.5 !important;
    }

    .main-frame a {
        font-size: 1rem !important;
    }

    /* 選單框架手機版觸控改善 */
    .main-frame .menu-frame,
    .menu-frame {
        width: 46% !important;
        max-width: 180px !important;
        height: auto !important;
        min-height: auto !important;
        margin: 2% !important;
        padding: 5px !important;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        display: inline-block !important;
        vertical-align: top;
        border: solid 1px #CDCDCD !important;
        border-bottom: solid 1px #CDCDCD !important;
        box-sizing: border-box !important;
        font-size: 16px !important; /* 恢復字體大小 */
    }

    /* 選單框架內的圖片手機版 */
    .main-frame .menu-frame img,
    .menu-frame img {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
        display: block !important;
        border-radius: 4px;
    }

    /* 隱藏手機版的 br 標籤，讓按鈕自然排列 */
    .main-frame > br {
        display: none !important;
    }

    /* 流程圖圖片手機版 */
    .main-frame > img,
    .main-frame img[src*="stage"],
    .main-frame img[width],
    .main-frame img[width="600"],
    .stage-container,
    .stage-container img,
    .stage-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        margin: 10px auto !important;
        font-size: 16px !important;
    }

    .menu-frame a {
        display: block;
        width: 100%;
        text-decoration: none;
        padding: 5px;
        border-radius: 6px;
        transition: all 0.2s ease;
    }
    
    .menu-frame:active {
        transform: scale(0.95);
        box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    }
    
    /* 進度百分比手機版調整 */
    .progress-badge {
        right: 5px !important;
        bottom: 5px !important;
        padding: 4px 8px !important;
        border-radius: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    }
    
    .progress-text {
        font-size: 12px !important;
    }
    
    /* 階段圖片手機版調整 */
    .stage-container {
        margin-top: 30px;
        padding: 0 15px;
    }
    
    .stage-image {
        max-height: 150px !important;
        width: 100%;
        object-fit: contain;
    }
    
    /* 按鈕響應式 */
    .btn-responsive {
        width: 100%;
        margin-bottom: 10px;
        min-height: 44px; /* iOS 建議最小觸控目標 */
    }
    
    /* 表單響應式 */
    .form-responsive .container {
        padding: 2px;
    }

    .form-responsive .row {
        margin: 3px 0;
    }

    .form-responsive .col, .form-responsive [class*="col-"] {
        padding: 3px;
    }
    
    .form-responsive .form-control {
        font-size: 16px; /* 防止iOS縮放 */
        height: 38px;
        padding: 8px 12px;
    }
    
    .form-responsive .form-title {
        font-size: 18px !important;
        margin: 5px 0 10px 0 !important;
        padding: 5px !important;
    }
    
    /* 隱藏不必要的文字在小螢幕上 */
    .hide-on-mobile {
        display: none;
    }
    
    /* 觸控反饋改善 */
    .touch-device .menu-frame:hover {
        background-color: rgba(255, 0, 5, 0.05);
    }
    
    .touched {
        background-color: rgba(255, 0, 5, 0.1) !important;
        transform: scale(0.98);
    }

    /* ========================================
       checkSelf.php 自我檢核頁面手機版優化
       ======================================== */
    .content {
        height: auto !important;
    }

    /* 縮小內容區域的邊距 */
    .content > div[style*="margin:150px"],
    .content > div[style*="margin: 150px"] {
        margin: 10px !important;
        padding: 10px;
    }

    /* 進度表格手機版 - 改為卡片式排版 */
    .table-hover.AutoNewline {
        display: block;
        width: 100%;
    }

    .table-hover.AutoNewline tr {
        display: block;
        margin-bottom: 15px;
        border-bottom: 1px solid #ddd;
        padding-bottom: 10px;
    }

    .table-hover.AutoNewline td {
        display: block;
        width: 100% !important;
        text-align: left !important;
        padding: 5px 10px;
    }

    .table-hover.AutoNewline td.tdTitle {
        width: 100% !important;
        font-weight: bold;
        background-color: #f5f5f5;
        padding: 8px 10px;
        margin-bottom: 5px;
        text-align: left !important;
    }

    /* 週次標題區塊 */
    .table-hover.AutoNewline tr[bgcolor='#ffffee'] td.tdTitle {
        background-color: #fffacd;
        text-align: center !important;
    }

    /* 隱藏空白的第三欄 */
    .table-hover.AutoNewline td:last-child:empty,
    .table-hover.AutoNewline td[style*="font-size:13px"]:empty {
        display: none;
    }

    /* 執行進度文字框手機版 */
    .progress-textarea {
        width: 100% !important;
        max-width: none !important;
        min-height: 100px;
        font-size: 16px; /* 防止 iOS 自動縮放 */
    }

    /* 儲存按鈕手機版 */
    .save-button {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        margin: 10px 0 !important;
    }

    /* 浮動提示在手機版的位置調整 */
    .toast-notification {
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 20px;
        text-align: center;
    }

    /* ========================================
       progress.php 進度檢核頁面手機版優化
       ======================================== */

    /* 主框架響應式 */
    .main-frame {
        width: 100% !important;
        position: relative !important;
        top: auto !important;
        padding: 10px;
    }

    /* 進度表格手機版 - 與 checkSelf.php 一致的卡片式排版 */
    .main-frame .table-hover,
    .main-frame table.AutoNewline {
        display: block;
        width: 100%;
    }

    .main-frame .table-hover tr,
    .main-frame table.AutoNewline tr {
        display: block;
        margin-bottom: 15px;
        border-bottom: 1px solid #ddd;
        padding-bottom: 10px;
    }

    .main-frame .table-hover td,
    .main-frame table.AutoNewline td {
        display: block;
        width: 100% !important;
        text-align: left !important;
        padding: 5px 10px;
    }

    .main-frame .table-hover td.tdTitle,
    .main-frame table.AutoNewline td.tdTitle {
        width: 100% !important;
        font-weight: bold;
        background-color: #f5f5f5;
        padding: 8px 10px;
        margin-bottom: 5px;
    }

    /* 週次標題區塊 - 黃色背景 */
    .main-frame tr[bgcolor='#ffffee'] td,
    .main-frame tr[bgcolor='#ffffee'] td.tdTitle {
        background-color: #fffacd !important;
        text-align: center !important;
    }

    /* 週進度對齊 */
    .week-progress-cell {
        text-align: left !important;
        padding: 8px 10px !important;
    }

    /* 隱藏空白欄位 */
    .main-frame td:empty {
        display: none;
    }

    /* 表單輸入框手機版 */
    .main-frame textarea,
    .main-frame input[type="text"] {
        width: 100% !important;
        max-width: none !important;
        font-size: 16px; /* 防止 iOS 自動縮放 */
    }

    /* 按鈕手機版 */
    .main-frame input[type="button"],
    .main-frame input[type="submit"],
    .main-frame button {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        margin: 10px 0 !important;
    }

    /* ========================================
       DataTables 表格手機版 - 排除卡片式排版
       讓 DataTables 保持水平表格樣式，使用水平捲動
       ======================================== */

    /* DataTables 表格恢復正常表格行為 */
    .main-frame table.dataTable,
    .main-frame table.display,
    #pshareTable {
        display: table !important;
        width: 100% !important;
    }

    .main-frame table.dataTable thead,
    .main-frame table.display thead,
    #pshareTable thead {
        display: table-header-group !important;
    }

    .main-frame table.dataTable tbody,
    .main-frame table.display tbody,
    #pshareTable tbody {
        display: table-row-group !important;
    }

    .main-frame table.dataTable tr,
    .main-frame table.display tr,
    #pshareTable tr {
        display: table-row !important;
        margin-bottom: 0 !important;
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    .main-frame table.dataTable td,
    .main-frame table.dataTable th,
    .main-frame table.display td,
    .main-frame table.display th,
    #pshareTable td,
    #pshareTable th {
        display: table-cell !important;
        width: auto !important;
    }
}

/* 極小螢幕 (320px 以下) */
@media (max-width: 320px) {
    #title-left {
        font-size: 1.3rem !important;
    }
    
    #title-mid {
        font-size: 1rem !important;
    }
    
    .main {
        margin: 5px !important;
        padding: 10px 5px !important;
        width: 98% !important;
    }
    
    .main-left1 {
        font-size: 1.3rem !important;
    }
    
    .main-left2 {
        font-size: 1rem !important;
    }
    
    .form-responsive .row {
        margin: 2px 0;
    }
    
    .form-responsive .form-control {
        font-size: 14px;
        height: 36px;
        padding: 6px 10px;
    }
    
    .form-responsive .form-title {
        font-size: 16px !important;
    }
    
    /* 極小螢幕選單調整 */
    .menu-frame {
        width: 100% !important;
        max-width: none !important;
        margin: 5px 0 !important;
        padding: 3px !important;
    }
}

/* 中等手機螢幕 (375px - 414px) */
@media (min-width: 375px) and (max-width: 414px) {
    .menu-frame {
        width: 48% !important;
        max-width: 180px !important;
    }
    
    .main {
        width: 90% !important;
        padding: 15px 8px !important;
    }
    
    .main-left1 {
        font-size: 1.4rem !important;
    }
    
    .main-left2 {
        font-size: 1.1rem !important;
    }
}

/* DataTables 響應式支援 */
.dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-bottom: 10px;
}

/* 手機版 DataTables 調整 */
@media (max-width: 767px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        text-align: center;
        margin-bottom: 10px;
    }
    
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        max-width: 200px;
        margin-left: 0 !important;
    }
    
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: center;
        margin-top: 10px;
    }
    
    table.dataTable {
        font-size: 12px;
    }
    
    table.dataTable th,
    table.dataTable td {
        padding: 4px !important;
        word-wrap: break-word;
    }
    
    /* 隱藏不重要的欄位在手機版 */
    .hide-mobile {
        display: none !important;
    }
}

/* 背景響應式調整 */
.html-contain {
    height: auto !important;
    min-height: 100vh;
}

/* Canvas 背景調整 */
canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

/* 打印樣式保持原樣 */
@media print {
    .btn, .noprint {
        display: none !important;
    }
    
    .main-frame, #title-bar {
        position: static !important;
        width: 100% !important;
    }
}