/* Exception compact badges */
.ex-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.4;
    margin-left: 6px;
    vertical-align: middle;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.35);
    color: #ddd;
}
.ex-badge.rst {
    border-color: #ff6b6b;
    color: #ff6b6b;
}
.ex-badge.gap {
    border-color: #4dabf7;
    color: #4dabf7;
}
.ex-badge.inact {
    border-color: #ffa94d;
    color: #ffa94d;
}
/* WISE6610 Data Analyzer - Optimized CSS */
/* Remove duplicate styles for better maintainability */

/* CSS Variables Definition */
:root {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #333;
    --border-color: #444;
    --border-light: #555;
    --text-primary: #fff;
    --text-secondary: #eee;
    --text-muted: #aaa;
    --text-disabled: #888;
    --accent-primary: #0d6efd;
    --accent-secondary: #0b5ed7;
    --success-color: #51cf66;
    --warning-color: #ffd43b;
    --danger-color: #ff6b6b;
    --info-color: #ff922b;
}

/* Base Styles */
body {
    font-family: Arial, sans-serif;
    margin: 20px auto;
    max-width: 1500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    line-height: 1.6;
}

h1 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 15px;
}

/* Header Styles */
header {
    font-size: 18px; /* 調整字體大小 */
    word-wrap: break-word; /* 強制文字換行 */
    word-break: break-word; /* 強制文字換行 */
    max-width: 300px; /* 調整寬度 */
    line-height: 1.5; /* 調整行高 */
}

/* File Upload Area Styles */
.file-upload-area {
    width: 100%;
    margin: 5px 0;
    padding-top: 0px;
    padding-bottom: 5px;
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 12px 20px;
    text-align: left;
    background: var(--bg-primary);
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 45px;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
}

.upload-zone:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.1);
}

.upload-zone.drag-over {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    border-style: solid;
    box-shadow: 0 0 20px rgba(13, 110, 253, 0.2);
    transform: scale(1.02);
}

.upload-icon {
    font-size: 24px;
    margin: 0;
    opacity: 0.7;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.upload-zone:hover .upload-icon {
    opacity: 1;
    transform: scale(1.1);
}

.upload-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.upload-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.upload-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0;
}

.upload-formats {
    font-size: 11px;
    color: var(--text-disabled);
    background: var(--bg-secondary);
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    white-space: nowrap;
}

.upload-help {
    flex-shrink: 0;
    margin-left: auto;
}

/* File Info Display */
.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 8px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.file-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 10px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 10px;
}

.remove-file-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.remove-file-btn:hover {
    background: #e74c3c;
    transform: scale(1.1);
}

/* Success state for upload zone */
.upload-zone.file-selected {
    border-color: var(--success-color);
    background: rgba(81, 207, 102, 0.1);
}

.upload-zone.file-selected .upload-icon {
    color: var(--success-color);
}

.upload-zone.file-selected .upload-title {
    color: var(--success-color);
}

/* Error state for upload zone */
.upload-zone.upload-error {
    border-color: var(--danger-color);
    background: rgba(255, 107, 107, 0.1);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Responsive adjustments for file upload */
@media (max-width: 768px) {
    .upload-zone {
        padding: 12px 15px;
        min-height: 45px;
        gap: 10px;
    }
    
    .upload-icon {
        font-size: 22px;
    }
    
    .upload-title {
        font-size: 12px;
    }
    
    .upload-subtitle {
        font-size: 11px;
    }
    
    .upload-formats {
        font-size: 10px;
        padding: 3px 8px;
    }
}

/* Section Block Styles */
section {
    flex: none;
    width: 100%;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    margin: 16px auto;
    border-radius: 8px;
    box-sizing: border-box;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: box-shadow 0.3s ease;
}

section:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Sector 1 - Chart Area */
#sector1 {
    height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    overflow: hidden;
    padding: 10px;
}

#sector1 .controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 20px;
    flex-shrink: 0;
    height: 60px; /* Fixed control height */
    padding: 10px 0;
}

#sector1 label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    flex-shrink: 0;
    white-space: nowrap;
}

#sector1 input[type="number"] {
    padding: 8px 10px;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 90px;
    font-size: 14px;
}

#sector1 input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 5px rgba(13, 110, 253, 0.3);
}

#sector1 input[type="file"] {
    padding: 8px 12px;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 14px;
}

#sector1 input[type="file"]:hover {
    border-color: var(--border-light);
    background-color: var(--bg-hover);
}

.chart-container {
    width: 100%;
    height: calc(100% - 75px); /* Adjust for more accurate height calculation */
    display: flex;
    flex: 1;
    min-height: 250px; /* Ensure minimum height */
    position: relative;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Sector 2 - Table Area */
#sector2 {
    min-height: 400px;
    /* Allow the table area to grow when the page is zoomed — don't artificially cap height */
    max-height: none;
    display: flex;
    flex-direction: column;
    /* Allow native scrolling if content exceeds the container */
    overflow: auto;
    position: relative;
    overflow-x: auto; /* Enable horizontal scrolling for small screens */
    padding: 10px;
    box-sizing: border-box;
}

/* Table Controls Styles */
.table-controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin: 8px 0 7px 0;
    gap: 10px;
    position: absolute;
    top: 22px;
    left: 20px;
    z-index: 10;
}

/* Adjust section positioning for button overlay */
#sector2 {
    position: relative;
}

#sector2 h2 {
    margin-bottom: 15px;
    position: relative;
    z-index: 1;
    height: auto;
    line-height: 1.4;
}

.control-button {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
    line-height: 1.3;
}

.control-button:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.control-button:active {
    transform: translateY(1px);
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.control-button:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-disabled);
    border-color: var(--border-color);
    cursor: not-allowed;
    box-shadow: none;
}

.control-button:disabled:hover {
    transform: none;
    background-color: var(--bg-tertiary);
    color: var(--text-disabled);
    border-color: var(--border-color);
}

/* Layout adjustments for new settings section */
.main-layout {
    display: flex;
    flex-direction: row;
    width: 100%;
    /* Use min-height so the layout can grow beyond the viewport when content is larger (zooming) */
    min-height: 100vh; /* Ensure it fills viewport at minimum but can grow */
}

.left-panel {
    width: 28%;
    background-color: var(--bg-primary);
    box-sizing: border-box;
    margin-right: 20px;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allow the panel to grow and fill the height */
}

.right-panel {
    width: 72%;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    gap: 15px; /* Reduced from 20px to 15px */
    margin-left: 20px;
    flex-grow: 1; /* Allow the panel to grow and fill the height */
}

#settings {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

#file-upload h2 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
}

#settings h2 {
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}

#settings h3 {
    color: var(--text-primary);
    margin: 4px 0 4px 0;
    font-size: 15px;
    font-weight: 600;
}

#settings h3:first-of-type {
    margin-top: 0;
}

.settings-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Divider style between groups */
.settings-divider {
    height: 1px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.4), rgba(255,255,255,0.05));
    margin: 8px 0 4px 0;
    border: none;
}

/* Extra spacing rule in case older cached gap not applied */

/* Settings rows & help tooltips */
.setting-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    flex-wrap: wrap;
    font-size: 13px;
    width: 100%;
    margin-bottom: 8px;
}
.setting-row label.setting-label {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    margin: 0;
    font-size: 13px;
}
.setting-row input[type="number"],
.setting-row input[type="date"],
.setting-row input[type="file"],
.setting-row input[type="datetime-local"] {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
    max-width: 220px;
    color-scheme: dark;
    height: 32px;
    box-sizing: border-box;
}
/* Time zone select & generic select styling */
.setting-row select,
#timezoneSelect {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 34px 6px 10px; /* 預留右側空間給箭頭 */
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
    max-width: 260px;
    height: 34px;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    line-height: 1.3;
    cursor: pointer;
    position: relative;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6.75 9L12 15L17.25 9' stroke='%2388a2c4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px 16px;
    transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.setting-row select:focus,
#timezoneSelect:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 4px rgba(13,110,253,0.4);
}
.setting-row select:hover,
#timezoneSelect:hover {
    border-color: var(--border-light);
    background-color: var(--bg-hover);
}
.setting-row select:disabled,
#timezoneSelect:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
/* 時區下拉展開樣式限制：使用 datalist 類似感或原生 select 展開時 (瀏覽器控制)，此處只能調整 option 與滾動條 */
#timezoneSelect {
  max-width: 260px;
}
/* Safari/Chrome 無法直接控制下拉面板高度；此為備註：若需完全自訂可改用自製彈層組件 (未實作) */

/* 下拉選單捲軸 (WebKit) */
select::-webkit-scrollbar {
    width: 10px;
}
select::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
select::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 2px solid var(--bg-secondary);
}
select::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}
/* 專為時區選單的長文字優化 */
#timezoneSelect option {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 13px;
    padding: 4px 6px;
    line-height: 1.3;
    white-space: nowrap;
}
#timezoneSelect option:checked,
#timezoneSelect option:hover {
    background: var(--accent-primary);
    color: var(--text-primary);
}
/* 限制時區選單可見高度 (size=5) 並確保滾動美觀 */
#timezoneSelect {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) var(--bg-secondary);
}
#timezoneSelect::-webkit-scrollbar { width: 10px; }
#timezoneSelect::-webkit-scrollbar-track { background: var(--bg-secondary); }
#timezoneSelect::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 6px; border: 2px solid var(--bg-secondary); }
#timezoneSelect::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }
/* 限制展開時最多可見 ~6 筆 (以 option 高度估算) */
#timezoneSelect[size] {
    /* option 高度約 26-28px，6 * 28 + padding/邊框 ≈ 180px */
    max-height: 180px;
    overflow-y: auto;
}

/* Custom Timezone Dropdown */
.tz-select-wrapper { position: relative; width: 100%; max-width: 260px; }
.tz-select-btn {
    width: 100%; text-align: left; background: var(--bg-tertiary); color: var(--text-secondary);
    border: 1px solid var(--border-color); border-radius: 4px; padding: 6px 34px 6px 10px; font-size:13px; cursor:pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6.75 9L12 15L17.25 9' stroke='%2388a2c4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size:16px 16px;
    transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.tz-select-btn:focus, .tz-select-btn[aria-expanded="true"] { outline:none; border-color: var(--accent-primary); box-shadow:0 0 4px rgba(13,110,253,0.4); }
.tz-select-btn:hover { border-color: var(--border-light); background: var(--bg-hover); }
.tz-options { position:absolute; top: calc(100% + 4px); left:0; width:100%; background: var(--bg-secondary); border:1px solid var(--border-color); border-radius:6px; box-shadow:0 6px 18px rgba(0,0,0,0.35); padding:4px 0; z-index:200; display:none; max-height:180px; overflow-y:auto; scrollbar-width: thin; scrollbar-color: var(--bg-tertiary) var(--bg-secondary); }
.tz-options.open { display:block; animation: fadeSlide .12s ease; }
@keyframes fadeSlide { from { opacity:0; transform:translateY(-4px);} to { opacity:1; transform:translateY(0);} }
.tz-option { padding:6px 10px; font-size:13px; color: var(--text-secondary); cursor:pointer; line-height:1.3; white-space:nowrap; }
.tz-option:hover, .tz-option[aria-selected="true"], .tz-option.active { background: var(--accent-primary); color: var(--text-primary); }
.tz-options::-webkit-scrollbar { width:10px; }
.tz-options::-webkit-scrollbar-track { background: var(--bg-secondary); }
.tz-options::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius:6px; border:2px solid var(--bg-secondary); }
.tz-options::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }
.visually-hidden { position:absolute !important; left:-9999px !important; width:1px; height:1px; overflow:hidden; }
.setting-row input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(0.85) brightness(1.2);
    opacity: 0.85;
    cursor: pointer;
}
.setting-row input[type="datetime-local"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 4px rgba(13,110,253,0.4);
}
/* Checkbox inside label alignment */
.setting-row label.setting-label input[type="checkbox"] {
    margin-right: 5px;
}
.help-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    position: relative;
    line-height: 1;
    user-select: none;
}
.help-icon::after {
    content: attr(data-tip);
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translate(8px, -50%);
    background: rgba(20,20,20,0.95);
    color: #fff;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.3;
    min-width: 160px;
    max-width: 240px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
    z-index: 50;
    white-space: normal;
}
.help-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translate(0, -50%);
    border: 6px solid transparent;
    border-left-color: rgba(20,20,20,0.95);
    opacity: 0;
    transition: opacity .15s ease;
    z-index: 51;
}
.help-icon:hover::after,
.help-icon:focus::after,
.help-icon:hover::before,
.help-icon:focus::before {
    opacity: 1;
}
/* Responsive tweak: stack rows if narrow */
@media (max-width: 1100px) {
    .setting-row { flex-direction: row; }
    .help-icon::after { left: 50%; top: 100%; transform: translate(-50%, 8px); }
    .help-icon::before { left: 50%; top: 100%; transform: translate(-50%, 0); border-left-color: transparent; border-top-color: rgba(20,20,20,0.95); }
}

/* DataTables Base Styles - Using scrollX for horizontal overflow */
table.dataTable {
    width: 100% !important;
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border-collapse: separate;
    margin: 0;
}

/* DataTables scrollX container optimization */
.dataTables_wrapper .dataTables_scrollBody {
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
    overflow-x: auto !important;
}

/* Prevent text wrapping for cleaner layout */
table.dataTable,
table.dataTable.nowrap th,
table.dataTable.nowrap td {
    white-space: nowrap;
    border: 1px solid #afafafa9;
}

/* Allow proper line breaks for specific columns (like MAC field) */
.wrap-data-column {
    white-space: pre-line !important; /* Preserve line breaks from \n characters */
    word-wrap: break-word !important;
    max-width: 200px; /* Limit width if needed */
    line-height: 1.4; /* Better line spacing for multi-line content */
    padding: 8px 4px !important; /* Extra padding for readability */
}

/* Wider style for Data column */
.wrap-data-column-wide {
    white-space: pre-line !important; /* Preserve line breaks from \n characters */
    word-wrap: break-word !important;
    max-width: 300px; /* Wider than regular wrap-data-column */
    min-width: 150px; /* Minimum width for Data column */
    line-height: 1.4; /* Better line spacing for multi-line content */
    padding: 8px 4px !important; /* Extra padding for readability */
}

/* DataTables wrapper styling */
.dataTables_wrapper {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 8px;
}

/* Overlay DataTable Styles - 使用通用樣式 */

/* Overlay DataTable wrapper optimization - 確保水平滑動正常運作 */
.overlay-content .dataTables_wrapper {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    width: 100%;
    box-sizing: border-box; /* 確保 padding 包含在寬度內 */
    margin: 0; /* 移除可能的外邊距 */
}

/* 通用 DataTables 控制項樣式 */
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px 8px;
}

.dataTables_wrapper .dataTables_info {
    color: var(--text-muted);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    margin: 0 2px;
    border-radius: 4px;
    cursor: pointer;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-light);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--accent-primary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.overlay-content .dataTables_wrapper .dataTables_scrollBody {
    -webkit-overflow-scrolling: touch; /* iOS 順滑滑動 */
    overflow-x: auto !important;
}

.overlay-content .dataTables_wrapper .dataTables_length select,
.overlay-content .dataTables_wrapper .dataTables_filter input {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px 8px;
}

.overlay-content .dataTables_wrapper .dataTables_info {
    color: var(--text-muted);
}

.overlay-content .dataTables_wrapper .dataTables_paginate .paginate_button {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    margin: 0 2px;
    border-radius: 4px;
    cursor: pointer;
}

.overlay-content .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-light);
}

.overlay-content .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--accent-primary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

/* 確保 overlay 中的 tab content 也支援滑動 */
.overlay-content #nodeData {
    overflow-x: auto;
    width: 100%;
}

/* Ensure proper line breaks work in overlay tables */
.overlay-content .wrap-data-column {
    white-space: pre-line !important; /* Preserve line breaks from \n characters */
    word-wrap: break-word !important;
    max-width: 200px; /* Limit width if needed */
    min-width: 100px; /* Minimum width for readability */
    vertical-align: top; /* Align to top for multi-line content */
    line-height: 1.4; /* Better line spacing for multi-line content */
    padding: 8px 4px !important; /* Extra padding for readability */
}

/* Wider style for Data column in overlay */
.overlay-content .wrap-data-column-wide {
    white-space: pre-line !important; /* Preserve line breaks from \n characters */
    word-wrap: break-word !important;
    max-width: 300px; /* Wider than regular wrap-data-column */
    min-width: 150px; /* Minimum width for Data column */
    vertical-align: top; /* Align to top for multi-line content */
    line-height: 1.4; /* Better line spacing for multi-line content */
    padding: 8px 4px !important; /* Extra padding for readability */
}

/* Basic Info Tab Styles */
.basic-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 2fr; /* 20% 20% 20% 40% */
    gap: 20px;
    max-width: 100%;
}

/* 響應式設計：在較小螢幕上改為兩列佈局 */
@media (max-width: 1200px) {
    .basic-info-grid {
        grid-template-columns: 1fr 1fr; /* 兩列佈局 */
    }
}

/* 響應式設計：在手機螢幕上改為單列佈局 */
@media (max-width: 768px) {
    .basic-info-grid {
        grid-template-columns: 1fr; /* 單列佈局 */
    }
}

.info-section {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
}

.info-section h3 {
    margin: 0 0 12px 0;
    color: var(--accent-primary);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px 0;
}

.info-item:last-child {
    margin-bottom: 0;
}

.info-item .label {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    min-width: 120px;
    text-align: left;
}

.info-item span:last-child {
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
    word-break: break-all;
    max-width: 150px;
}

/* 時間範圍區塊的特殊樣式 */
.time-range-section h3 {
    color: var(--accent-secondary, var(--accent-primary));
}

.time-range-section .info-item span:last-child {
    max-width: 200px; /* 時間範圍區塊有更多空間，可以顯示更長的文字 */
}

/* Ensure table cells can expand to accommodate wrapped content */
.overlay-content table.dataTable td.wrap-data-column,
.overlay-content table.dataTable td.wrap-data-column-wide {
    height: auto !important;
    min-height: 30px;
}

/* Overlay Styles */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    height: 80%;
    max-width: 1400px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    overflow: hidden; /* 👈 隱藏 overlay-content 的滾動條 */
    display: flex;
    flex-direction: column;
    margin: 0 auto; /* 確保水平置中 */
    box-sizing: border-box; /* 確保 padding 包含在寬度內 */
}

/* Tabs Styles */
.tabs {
    display: flex;
    margin-bottom: 10px;
}

.tab-button {
    flex: 1;
    padding: 10px 8px;
    cursor: pointer;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    text-align: center;
    border-radius: 4px 4px 0 0;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-button.active {
    background: var(--accent-primary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.tab-content {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 15px;
    border-radius: 0 0 4px 4px;
    border: 1px solid var(--border-color);
    flex: 1;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box; /* 確保 padding 包含在寬度內 */
    overflow: hidden; /* 防止內容溢出 */
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.tab-content.hidden {
    display: none !important; /* 使用 !important 確保隱藏優先級最高 */
}

/* 特別針對 nodeData tab 的樣式 - 只在這裡處理滾動 */
#nodeData {
    overflow: auto; /* 👈 只在最內層容器處理滾動 */
    width: 100%;
    height: 100%;
    flex: 1;
    box-sizing: border-box;
    padding: 0; /* 移除額外的內邊距，由 tab-content 提供 */
}

/* Node Charts Styles */
/* Charts tab content (previously #nodeCharts) - renamed to be more generic for future chart tabs */
#nodeSignalChart,
#nodeUpFreqChart,
#nodeGwChart {
    overflow: auto;
    width: 100%;
    height: 100%;
    flex: 1;
    padding: 0; /* remove extra padding; provided by .tab-content */
    box-sizing: border-box;
}

/* Gaps tab：需要可垂直捲動並堆疊多個圖表（避免被 flex:1 平均壓縮） */
#nodeGapChart {
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    height: 100%;
    flex: 1;
    padding: 0;
    box-sizing: border-box;
}
#nodeGapChart .node-charts-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px; /* 圖表間距 */
    height: auto; /* 讓內容根據實際高度延伸 */
}
#nodeGapChart .node-chart-wrapper {
    flex: 0 0 auto; /* 不要被壓縮，也不要強制撐滿剩餘空間 */
    min-height: 380px; /* 與原先接近，稍微降低確保可視範圍 */
    height: 380px; /* 固定高度，避免在多圖時撐爆第一屏 */
}
#nodeGapChart .node-chart-wrapper canvas {
    height: 100% !important;
}

.node-charts-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chart-header {
    margin-bottom: 15px;
    text-align: center;
}

.chart-header h3 {
    color: var(--text-primary);
    margin: 0 0 5px 0;
    font-size: 18px;
}

.chart-description {
    color: var(--text-muted);
    margin: 0;
    font-size: 14px;
}

.node-chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 400px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
}

.node-chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* GAP Summary badges */
.gap-summary { display:flex; flex-wrap:wrap; gap:8px; font-size:12px; }
.gap-badge { background:#1d2733; border:1px solid #344455; padding:4px 8px; border-radius:4px; line-height:1.2; }
.gap-badge.critical { border-color:#d9534f; color:#ffb4b0; }
.gap-badge.warn { border-color:#f0ad4e; color:#ffd596; }
.gap-badge.ok { border-color:#5cb85c; color:#b5f3b5; }

/* Close Overlay Button */
#closeOverlay {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 4px;
    margin-top: 10px;
    transition: background-color 0.3s ease;
}

#closeOverlay:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

/* Devname Link Styles */
.devname-link {
    color: var(--accent-primary);
    text-decoration: none;
    cursor: pointer;
}

.devname-link:hover {
    color: var(--accent-secondary);
    text-decoration: underline;
}

/* 自訂時區下拉選單 */
.tz-select { position: relative; width: 100%; max-width: 260px; }
.tz-selected { width:100%; background: var(--bg-tertiary); border:1px solid var(--border-color); color:var(--text-secondary); padding:6px 34px 6px 10px; border-radius:4px; font-size:13px; text-align:left; cursor:pointer; position:relative; line-height:1.3; }
.tz-selected:after { content:''; position:absolute; right:10px; top:50%; width: 0; height: 0; border-left:6px solid transparent; border-right:6px solid transparent; border-top:7px solid #88a2c4; transform:translateY(-30%); transition: transform .2s ease; }
.tz-selected[aria-expanded='true']:after { transform: translateY(-70%) rotate(180deg); }
.tz-selected:hover { border-color: var(--border-light); background: var(--bg-hover); }
.tz-selected:focus { outline:none; border-color: var(--accent-primary); box-shadow:0 0 4px rgba(13,110,253,0.4); }
.tz-dropdown { position:absolute; left:0; top: calc(100% + 4px); width:100%; background: var(--bg-secondary); border:1px solid var(--border-color); border-radius:6px; box-shadow:0 8px 18px rgba(0,0,0,0.4); max-height:185px; overflow-y:auto; padding:4px 0; z-index:150; scrollbar-width: thin; scrollbar-color: var(--bg-tertiary) var(--bg-secondary); }
.tz-dropdown::-webkit-scrollbar { width:10px; }
.tz-dropdown::-webkit-scrollbar-track { background: var(--bg-secondary); }
.tz-dropdown::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius:6px; border:2px solid var(--bg-secondary); }
.tz-dropdown::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }
.tz-option { padding:6px 10px; font-size:13px; line-height:1.2; cursor:pointer; display:flex; align-items:center; gap:6px; color: var(--text-secondary); }
.tz-option:hover, .tz-option[data-active='true'] { background: var(--accent-primary); color: var(--text-primary); }
.tz-option .tz-offset { font-weight:600; min-width:72px; color: var(--info-color); }
.tz-option.active .tz-offset, .tz-option:hover .tz-offset { color: #fff; }
.tz-option .tz-name { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tz-dropdown.hidden { display:none; }
.tz-no-match { padding:8px 10px; font-size:12px; color: var(--text-disabled); }
/* 可選搜尋列（預留） */
.tz-search { padding:4px 8px 8px 8px; }
.tz-search input { width:100%; background: var(--bg-tertiary); border:1px solid var(--border-color); color:var(--text-secondary); padding:6px 8px; font-size:13px; border-radius:4px; }
.tz-search input:focus { outline:none; border-color: var(--accent-primary); box-shadow: 0 0 4px rgba(13,110,253,0.4); }

/* Responsive Adjustments */
@media (max-width: 768px) {
    body {
        margin: 10px;
        max-width: none;
    }
    
    #sector1 {
        height: auto;
        min-height: 350px;
        padding: 15px;
    }
    
    #sector1 .controls-container {
        flex-direction: column;
        gap: 15px;
        height: auto;
        padding: 15px 0;
    }
    
    #sector1 label {
        width: 100%;
        justify-content: space-between;
    }
    
    #sector1 input[type="number"],
    #sector1 input[type="file"] {
        width: 150px;
    }
    
    .chart-container {
        height: 280px;
        min-height: 280px;
    }
    
    #sector2 {
        padding: 15px;
    }

    /* Adjustments for new layout */
    .main-layout {
        flex-direction: column;
    }

    .left-panel,
    .right-panel {
        width: 100%;
        height: auto;
        margin: 0;
    }

    .left-panel {
        padding: 0 15px;
    }

    .right-panel {
        padding: 0 15px;
    }

    /* Overlay adjustments for mobile */
    .overlay-content {
        width: 95%;
        height: 90%;
        padding: 15px;
    }
}

@media (max-width: 900px) {
    .left-panel { 
        width: 100%; 
        margin-right: 0;
    }
    .right-panel { 
        width: 100%; 
        margin-left: 0;
    }
}
