/* ==========================================================================
   1. 全域鎖定與遮罩設定 (Page Overlay)
   ========================================================================== */
body.screen-locked {
    overflow: hidden !important;
    height: 100vh;
    padding-right: 15px;
}

.page-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2147483647;
    background: transparent;
    display: none;
    cursor: wait;
    pointer-events: auto;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    filter: none !important;
    will-change: auto !important;
    transform: none !important;
}

.page-overlay.active {
    display: block !important;
}

/* ==========================================================================
   2. 廣告設定區 (Ad Section)
   ========================================================================== */
.adContainer {
    display: flex;
    gap: 60px;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 30px;
    margin-top: 2px;
}

.adImageTitle,
.adTextTitle {
    font-size: 25px;
    font-weight: 600;
    margin-bottom: 8px;
    margin-left: 20px;
}

.uploadLabel {
    position: relative;
    display: inline-block;
    margin-left: 20px;
    width: 180px;
    height: 220px;
    border-radius: 8px;
    border: 2px dashed #ccc;
    background-color: #f9f9f9;
    text-align: center;
    line-height: 220px;
    font-size: 48px;
    color: #888;
    cursor: pointer;
    overflow: hidden;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.uploadLabel:hover {
    background-color: #e6f7ff;
    border-color: #66afe9;
}

.uploadLabel .uploadInput {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.uploadLabel .plusSign {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.uploadLabel:hover .plusSign {
    transform: translate(-50%, -50%) scale(1.6);
}

.uploadLabel .previewImg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.uploadLabel .removeBtn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    color: white;
    background-color: #888;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    z-index: 10;
}

.adTextArea {
    width: 500px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.adTextTitle {
    margin-left: 0;
}

.textareaWrapper {
    display: flex;
    align-items: flex-start;
    width: 100%;
    margin: 0;
}

textarea[name="adText"] {
    flex: 1;
    height: 220px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    resize: none;
    box-sizing: border-box;
}

.buttonGroup {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-left: 12px;
}

#editAdBtn,
#saveAdBtn {
    position: relative;
    height: 36px;
    min-width: 80px;
    padding: 4px 12px;
    font-size: 14px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background-color: #f8f8f8;
    cursor: pointer;
    box-sizing: border-box;
    transition: all 0.1s ease;
    box-shadow: 0 3px 0 #bbb;
    display: flex;
    align-items: center;
    justify-content: center;
}

#editAdBtn:hover:not(:disabled),
#saveAdBtn:hover:not(:disabled) {
    background-color: #ffffff;
    border-color: #aaa;
    color: #000;
}

#editAdBtn:active:not(:disabled),
#saveAdBtn:active:not(:disabled) {
    top: 2px;
    box-shadow: 0 1px 0 #999;
}

.btn-active {
    background-color: #e0e0e0 !important;
    top: 2px !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    border-color: #999 !important;
}

#editAdBtn:disabled,
#saveAdBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    top: 0;
    background-color: #eee;
}

#saveAdBtn:not(:disabled) {
    background-color: #4A90E2;
    color: white;
    border-color: #357ABD;
    box-shadow: 0 3px 0 #2D65A4;
}

/* ==========================================================================
   3. 受試者區 (Buttons & Grouping)
   ========================================================================== */
.subject-card {
    display: inline-flex;
    align-items: flex-start;
    gap: 3px;
    margin-right: 25px;
    margin-bottom: 10px;
    vertical-align: top;
    width: 120px;
    height: 150px;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
}

/* --- Checkbox 核心樣式修正 --- */
.subject-item-check,
#selectAllSubjectsCheck {
    appearance: none;
    -webkit-appearance: none;
    /* 移除原生樣式以防強制變灰 */
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
    border: 2px solid #ccc;
    border-radius: 3px;
    background-color: #fff;
    position: relative;
    transition: all 0.2s ease;
    z-index: 10;
}

/* 勾選時的藍色背景 */
.subject-item-check:checked,
#selectAllSubjectsCheck:checked {
    background-color: #4A90E2;
    border-color: #4A90E2;
}

/* 勾選時的白色勾勾符號 */
.subject-item-check:checked::after,
#selectAllSubjectsCheck:checked::after {
    content: "✓";
    position: absolute;
    color: white;
    font-size: 14px;
    font-weight: bold;
    left: 50%;
    top: 45%;
    transform: translate(-50%, -50%);
}

/* --- 重點：鎖定且勾選時的顏色 (強制深灰色) --- */
.subject-item-check:disabled:checked,
#selectAllSubjectsCheck:disabled:checked {
    background-color: #555 !important;
    /* 改為深灰色底 */
    border-color: #555 !important;
    /* 改為深灰色邊框 */
    opacity: 0.5 !important;
    /* 移除透明度，確保顏色深 */
    cursor: not-allowed !important;
}

/* 鎖定但未勾選的樣子 */
.subject-item-check:disabled:not(:checked),
#selectAllSubjectsCheck:disabled:not(:checked) {
    background-color: #f0f0f0 !important;
    border-color: #ddd !important;
    opacity: 0.8 !important;
    cursor: not-allowed !important;
}

/* 初始狀態隱藏全選容器 */
.select-all-container {
    display: none;
    margin-top: 20px;
    margin-bottom: 40px;
    font-size: 20px;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    font-weight: bold;
    color: #333;
    /* 文字顏色保持不變 */
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    line-height: 1;
}

.select-all-container label {
    cursor: pointer;
    display: flex;
    align-items: center;
    user-select: none;
}

/* 圖片樣式 */
#tableImages .myButton {
    display: block;
    width: 110px;
    height: 130px;
    object-fit: contain;
    margin: 0 !important;
    box-shadow: none !important;
    filter: none !important;
    transition: transform 0.2s ease;
    border-radius: 4px;
    position: relative;
    z-index: 1;
}

#tableImages .myButton:hover {
    transform: scale(1.2);
    box-shadow: none !important;
    z-index: 99;
}

#tableImages .myButton.is-selected {
    transform: scale(1.2) !important;
    z-index: 100 !important;
}

#subjectActionGroup {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 0px 0;
    width: 100%;
}

.analysis-status-container {
    margin-bottom: 6px;
    min-height: 14px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
}

#analysisStatusText {
    font-size: 14px;
    color: #2196F3;
    font-weight: bold;
    animation: fadeInUp 0.4s ease-out, pulseText 2s infinite ease-in-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulseText {

    0%,
    100% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
    }
}

#analysisStatusText.completed {
    animation: fadeInUp 0.4s ease-out;
    color: #4CAF50 !important;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}

.export-group {
    margin-top: 5px;
    margin-bottom: 20px;
}

#SelectRetryBtn,
#analyzeBtn,
#ExportAllDataBtn,
#ExportAllResultBtn,
#ExportSelectDataBtn,
#ExportSelectResultBtn,
#ExportEDA,
#ExportResultTable {
    position: relative;
    top: 0;
    height: 36px;
    min-width: 80px;
    width: auto;
    padding: 0 15px;
    font-size: 14px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background-color: #f8f8f8;
    cursor: pointer;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 0 #bbb;
    transition: all 0.1s ease;
    white-space: nowrap;
}

#SelectRetryBtn,
#analyzeBtn {
    color: #333;
    background-color: #f8f8f8;
    z-index: 9999;
}

#ExportAllDataBtn,
#ExportAllResultBtn,
#ExportSelectDataBtn,
#ExportSelectResultBtn,
#ExportEDA,
#ExportResultTable {
    background-color: #4A90E2 !important;
    color: white !important;
    border-color: #357ABD !important;
    box-shadow: 0 3px 0 #2D65A4 !important;
}

#SelectRetryBtn:active,
#analyzeBtn:active,
#ExportAllDataBtn:active,
#ExportAllResultBtn:active,
#ExportSelectDataBtn:active,
#ExportSelectResultBtn:active,
#ExportEDA:active,
#ExportResultTable:active,
#analyzeBtn.btn-pressed {
    top: 2px !important;
    box-shadow: 0 1px 0 #999 !important;
}

#SelectRetryBtn:disabled,
#analyzeBtn:disabled,
#ExportAllDataBtn:disabled,
#ExportAllResultBtn:disabled,
#ExportSelectDataBtn:disabled,
#ExportSelectResultBtn:disabled,
#ExportEDA:disabled,
#ExportResultTable:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none !important;
    top: 0 !important;
    background-color: #eee !important;
    color: #888 !important;
    border-color: #ccc !important;
}

#analyzeBtn.btn-pressed {
    background-color: #e0e0e0 !important;
    pointer-events: none;
}

/* ==========================================================================
   4. 原始資料表區 (Data Table)
   ========================================================================== */
#tableData {
    margin-top: 0;
    width: 100%;
    max-height: 500px;
    overflow: auto !important;
    box-sizing: border-box;
    display: block;
    border: none;
    background-color: transparent;
}

#tableData:not(:empty) {
    margin-top: 20px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: #fff;
}

.data-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    table-layout: auto;
}

.data-table thead th {
    position: sticky;
    top: 0;
    background-color: #f2f2f2;
    z-index: 10;
    border-bottom: 2px solid #ccc;
    padding: 12px 15px;
    text-align: left;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
    background-color: #fff;
}

.data-table tbody tr:hover td {
    background-color: #f0f7ff;
}

#tableData::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#tableData::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.data-table tbody tr.selected-row td {
    background-color: #fff9db !important;
    border-bottom: 1px solid #f1db6d;
    transition: background-color 0.2s ease;
}

.data-table th:first-child,
.data-table td:first-child {
    position: sticky;
    left: 0;
    width: 40px;
    min-width: 40px;
    text-align: center;
    z-index: 10;
    background-color: #fff;
    border-right: 2px solid #ddd;
}

.data-table thead th:first-child {
    background-color: #f2f2f2;
    z-index: 20;
    top: 0;
}

.data-table tbody tr:hover td:first-child {
    background-color: #f0f7ff;
}