/* Box Helper - 主樣式表 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

/* 應用容器 */
.box-helper-app {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 標題區 */
.app-header {
    /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; */
    padding: 20px;
    text-align: center;
    /* box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); */
}

.app-header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 5px;
}

.app-subtitle {
    font-size: 14px;
    opacity: 0.9;
}
.app-subtitle h1 {
    color: white;
}

/* 內容區 */
.app-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* 左側面板 - 輸入表單 */
.left-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 20px;
}

/* 中間面板 - 3D 視圖 */
.middle-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    height: 400px;
    overflow: hidden;
}

/* 右側面板 - 結果列表 */
.right-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 20px;
}

/* 表單區段 */
.form-section {
    margin-bottom: 5px;
    padding-bottom: 10px;
}

.form-section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 15px;
}

/* 模式選擇器 */
.mode-selector {
    display: flex;
    gap: 10px;
}

.mode-btn {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #dee2e6;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.mode-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.mode-btn.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

/* 尺寸輸入 */
.dimension-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.input-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.input-group label {
    font-size: 12px;
    color: #6c757d;
    font-weight: 500;
    min-width: 60px;
}

.input-group input {
    width: 100px;
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 選項區 */
.dimension-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 尺寸表格 */
.dimension-table {
    width: 100%;
    margin-bottom: 15px;
    /* overflow-x: auto; */
    -webkit-overflow-scrolling: touch;
    padding-bottom: 5px;
}

.dimension-table-header {
    display: grid;
    grid-template-columns: 100px repeat(3, 70px) 100px 100px;
    gap: 8px;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 11px;
    color: #495057;
    min-width: 550px;
}

.dimension-table-row {
    display: grid;
    grid-template-columns: 100px repeat(3, 70px) 100px 100px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
    min-width: 550px;
}

@media (max-width: 640px) {
    .dimension-table-header,
    .dimension-table-row {
        grid-template-columns: 80px 1fr 1fr 1fr;
        row-gap: 8px;
        min-width: 0; /* Allow shrinking */
    }

    /* Hide Unit/Measure headers on mobile */
    .dimension-table-header > :nth-child(5),
    .dimension-table-header > :nth-child(6) {
        display: none;
    }

    /* Move Unit/Measure cells to next row */
    .dimension-table-row > :nth-child(5) {
        grid-row: 2;
        grid-column: 1 / 3; /* Span Label + L */
        justify-content: flex-start;
        padding-left: 5px;
    }

    .dimension-table-row > :nth-child(6) {
        grid-row: 2;
        grid-column: 3 / 5; /* Span W + H */
        justify-content: flex-start;
    }

    .dimension-label-col {
        min-width: 80px;
        width: 80px;
    }
    
    .dimension-col input {
        max-width: 100%;
    }
    
    /* Adjust orientation row */
    .dimension-table-row.orientation-row {
        grid-template-columns: 80px 1fr;
    }
}

@media (max-width: 768px) {
    /* Removed grid-template-columns overrides to allow horizontal scrolling instead of squashing */
    
    .dimension-col input,
    .dimension-col select {
        padding: 4px 2px;
        font-size: 12px;
    }
}

/* 佈置方向行特殊布局 */
.dimension-table-row.orientation-row {
    grid-template-columns: 100px 1fr;
}

@media (max-width: 500px) {
    /* Removed grid-template-columns overrides */
}

.dimension-col-wide {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.dimension-label-col {
    font-size: 12px;
    color: #495057;
    font-weight: 500;
    text-align: left;
    padding-left: 5px;
    /* 保持和 grid-template-columns 中第一列一致的寬度，防止 header 項目位移 */
    min-width: 100px;
    width: 100px;
    box-sizing: border-box;
}

.dimension-col {
    display: flex;
    align-items: center;
    justify-content: center;
}
.dimension-col:empty::before {
  content: '\00a0';
  white-space: pre;
  display: inline-block;
  width: 1em;
  height: 1em;
}

.dimension-table-header .dimension-label-col {
    text-align: left;
}

.dimension-table-header .dimension-col {
    text-align: center;
    font-size: 11px;
}

.dimension-col input,
.dimension-col select {
    width: 100%;
    max-width: 70px;
    padding: 6px 4px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.3s;
    text-align: center;
}

.dimension-col input:focus,
.dimension-col select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 內聯切換按鈕 */
.inline-toggle {
    display: flex;
    gap: 2px;
}

.toggle-btn-sm {
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.3s;
    white-space: nowrap;
}

.toggle-btn-sm:hover {
    border-color: #667eea;
    color: #667eea;
}

.toggle-btn-sm.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.total-count-display {
    font-size: 12px;
    color: #495057;
    font-weight: 500;
}

.unit-display {
    font-size: 12px;
    color: #6c757d;
    font-weight: 500;
}

.dimension-summary {
    margin-top: 15px;
    padding: 0;
    background: #f8f9fa;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    font-size: 13px;
    color: #495057;
    line-height: 1.6;
}

.dimension-summary summary {
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 500;
    list-style: none;
    display: flex;
    align-items: center;
}

.dimension-summary summary::after {
    content: '▼';
    font-size: 10px;
    margin-left: auto;
    transition: transform 0.2s;
}

.dimension-summary[open] summary::after {
    transform: rotate(180deg);
}

.dimension-summary .summary-content {
    padding: 0 12px 12px 12px;
    border-top: 1px solid #e9ecef;
    margin-top: 4px;
    padding-top: 8px;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-group label {
    font-size: 13px;
    color: #6c757d;
    min-width: 50px;
}

.toggle-btn {
    padding: 6px 15px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.toggle-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.toggle-btn.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

/* 總數量顯示 */
.total-count {
    text-align: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 4px;
    font-weight: 500;
    color: #495057;
}

/* 物件方向控制 */
.orientation-controls {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;  /* 強制在同一行 */
    align-items: center;
    width: 100%; /* Ensure it takes full width */
}

.orientation-btn {
    padding: 8px 16px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
    white-space: nowrap;
    color: #495057;
    flex-shrink: 0;  /* 防止按鈕縮小 */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

@media (max-width: 640px) {
    .orientation-controls {
        gap: 4px;
    }
    
    .orientation-btn {
        padding: 6px 8px;
        font-size: 12px;
        flex: 1; /* Allow buttons to grow/shrink equally */
        min-width: 0; /* Allow shrinking below content size */
    }
    
    .orientation-btn.reset-btn {
        flex: 0 0 auto; /* Reset button takes only needed space */
        padding: 6px 10px;
    }
    
    .orientation-btn.reset-btn .btn-text {
        display: none; /* Hide text on mobile */
    }
    
    .orientation-btn.reset-btn .btn-icon {
        font-size: 14px;
        font-weight: bold;
    }
}

.orientation-btn:hover {
    background: #f8f9fa;
    border-color: #667eea;
    color: #667eea;
}

.orientation-btn:active {
    background: #e9ecef;
    transform: scale(0.98);
}

.orientation-btn.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.orientation-btn.reset-btn {
    color: #dc3545;
}

.orientation-btn.reset-btn:hover {
    border-color: #dc3545;
    color: #dc3545;
    background: #fff5f5;
}

/* 寬容度限制 */
.tolerance-constraints {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.constraint-group {
    display: flex;
    flex-direction: column;
}

.constraint-group label {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 5px;
}

.constraint-group select {
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}

/* 系列篩選 */
.series-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.checkbox-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    padding: 10px;
    border-radius: 6px;
    border: 3px solid transparent;
    transition: all 0.3s;
    min-width: 100px;
    text-align: center;
    opacity: 0.75;
}

.checkbox-label.selected {
    border-color: #667eea;
    opacity: 1;
    background: rgba(102, 126, 234, 0.05);
}

.checkbox-label:hover {
    opacity: 1;
    background: #f8f9fa;
    border-color: #adb5bd;
}

.checkbox-label.selected:hover {
    border-color: #5568d3;
    background: rgba(102, 126, 234, 0.1);
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkbox-label .series-icon {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 4px;
}

.checkbox-label .series-icon-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    font-size: 54px;
    line-height: 1;
}

/* 3D 視圖 */
.box-viewer-3d {
    width: 100%;
    height: calc(100vh - 180px);
    min-height: 320px;
    position: relative;
}

.viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 300px;
    border-radius: 4px;
    overflow: hidden;
}

.interaction-zone {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    z-index: 5;
    touch-action: none; /* Disable browser scrolling in this zone to allow 3D manipulation */
    pointer-events: none; /* Allow pointer events to reach the canvas underneath */
}

.viewer-info {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.no-results-info {
    background: rgba(255, 243, 205, 0.95);
    border: 2px solid #ff9800;
}

.no-results-message {
    font-size: 14px;
    color: #d84315;
    font-weight: 500;
    text-align: center;
}

.dimension-label {
    font-size: 13px;
    line-height: 1.8;
    color: #495057;
}

.box-label {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    color: #667eea;
    font-weight: 600;
    z-index: 5;
    display: flex;
    align-items: center;
}

.box-product-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    width: 20px;
    height: 20px;
    background-color: #667eea;
    color: white;
    border-radius: 50%;
    text-decoration: none;
    font-size: 12px;
    transition: all 0.2s;
}

.box-product-link:hover {
    background-color: #5a67d8;
    transform: scale(1.1);
}

/* Viewer Controls */
.object-position-controls {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 13px;
    z-index: 10;
}

.view-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 13px;
    z-index: 10;
}

.viewer-btn {
    padding: 4px 10px;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    margin-bottom: 4px;
    background: #fff;
    color: #333;
    transition: all 0.2s;
}

.viewer-btn:hover {
    background: #f0f0f0;
}

.viewer-btn.active {
    background: #4a90e2;
    color: #fff;
    border-color: #4a90e2;
}

.control-group {
    margin-bottom: 8px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
}

/* Mobile adjustments for viewer controls */
@media (max-width: 640px) {
    .viewer-info {
        padding: 8px;
        font-size: 11px;
        max-width: 140px;
        background: rgba(255, 255, 255, 0.85); /* More transparent */
    }
    
    .dimension-label {
        font-size: 11px;
        line-height: 1.4;
    }
    
    .box-label {
        font-size: 11px;
        padding: 5px 8px;
        bottom: 5px;
        right: 5px;
    }

    .box-product-link {
        width: 16px;
        height: 16px;
        font-size: 10px;
        margin-left: 6px;
    }

    .object-position-controls {
        padding: 6px;
        font-size: 11px;
        bottom: 5px;
        left: 5px;
        background: rgba(255, 255, 255, 0.85);
    }

    .view-controls {
        padding: 6px;
        font-size: 11px;
        top: 5px;
        right: 5px;
        background: rgba(255, 255, 255, 0.85);
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .viewer-btn {
        padding: 2px 6px;
        font-size: 10px;
        margin-right: 2px;
        margin-bottom: 2px;
    }
    
    .control-label {
        margin-bottom: 2px;
        font-size: 11px;
    }
    
    /* Compact view for view controls on mobile */
    .view-controls .control-label {
        display: none; /* Hide label to save space */
    }
}

/* 結果列表 */
.results-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e9ecef;
}

.results-header h3 {
    font-size: 18px;
    color: #495057;
}

.results-count {
    font-size: 13px;
    color: #6c757d;
    margin-bottom: 0;
}

.results-count strong {
    color: #667eea;
    font-size: 16px;
}

.filtered-count {
    color: #999;
    font-size: 11px;
    margin-left: 5px;
}

.accuracy-control {
    margin-left: auto;
}

.accuracy-control label {
    display: block;
    font-size: 13px;
    color: #495057;
    margin-bottom: 8px;
    font-weight: 500;
}

.accuracy-control label strong {
    color: #667eea;
    font-size: 14px;
}

.accuracy-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #dee2e6;
    outline: none;
    -webkit-appearance: none;
    margin-bottom: 5px;
}

.accuracy-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: all 0.3s;
}

.accuracy-slider::-webkit-slider-thumb:hover {
    background: #5568d3;
    transform: scale(1.1);
}

.accuracy-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    transition: all 0.3s;
}

.accuracy-slider::-moz-range-thumb:hover {
    background: #5568d3;
    transform: scale(1.1);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #999;
}

.custom-links {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.custom-link {
    font-size: 12px;
    color: #007bff;
    text-decoration: none;
    transition: color 0.3s;
}

.custom-link:hover {
    color: #0056b3;
    text-decoration: underline;
}

.link-separator {
    color: #dee2e6;
    font-size: 12px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.no-results p {
    margin-bottom: 10px;
}

.hint {
    font-size: 12px;
    color: #adb5bd;
}

/* 結果項目 */
.results-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-item {
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
}

.result-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.item-title {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* item code link */
.item-code-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.item-code-link:hover {
    text-decoration: underline;
}

.item-code-icon {
    width: 14px;
    height: 14px;
    display: inline-block;
    color: #667eea;
    transition: transform 0.12s ease, color 0.12s ease;
}

.item-code-link:hover .item-code-icon {
    transform: translateX(3px);
    color: #5b6fe0;
}

.item-code-link:focus {
    outline: 2px solid rgba(102,126,234,0.18);
    outline-offset: 2px;
}

.result-series-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}

.result-series-icon-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    font-size: 36px;
    line-height: 1;
    flex-shrink: 0;
}

.item-material {
    font-size: 11px;
    color: #6c757d;
}

.material-label {
    font-weight: 500;
}

.series-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #667eea;
    color: white;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.item-code {
    font-weight: 600;
    color: #495057;
}

.item-price {
    font-size: 16px;
    font-weight: 600;
    color: #28a745;
}

/* 尺寸顯示 */
.item-dimensions {
    margin-bottom: 6px;
}

.dimension-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    margin-bottom: 3px;
}

.dimension-label {
    font-weight: 500;
    color: #6c757d;
    min-width: 28px;
}

.dimension-value {
    color: #495057;
    font-family: 'Courier New', monospace;
}

/* 匹配信息 */
.item-match-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.match-badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

.match-badge.excellent {
    background: #d4edda;
    color: #155724;
}

.match-badge.good {
    background: #d1ecf1;
    color: #0c5460;
}

.match-badge.fair {
    background: #fff3cd;
    color: #856404;
}

.match-badge.poor {
    background: #f8d7da;
    color: #721c24;
}

.dimension-diffs {
    display: flex;
    gap: 6px;
    font-size: 10px;
}

.diff-item {
    padding: 2px 5px;
    background: #f8f9fa;
    border-radius: 3px;
    color: #6c757d;
}

.diff-item.negative {
    background: #fee;
    color: #dc3545;
    font-weight: 500;
}

.item-actions {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #e9ecef;
    text-align: right;
}

.product-link {
    display: inline-block;
    padding: 6px 16px;
    background: #007bff;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s;
}

.product-link:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.item-remark {
    font-size: 12px;
    color: #6c757d;
    font-style: italic;
}

/* 響應式設計 */
@media (max-width: 1400px) {
    .app-content {
        /* grid-template-columns: 300px 1fr 350px; */ /* Removed grid layout */
    }
}

@media (max-width: 1200px) {
    .app-content {
        /* grid-template-columns: 1fr; */
        /* grid-template-rows: auto auto auto; */
    }
    
    .left-panel,
    .right-panel {
        max-height: none;
    }
    
    .middle-panel {
        height: 500px;
    }
    
    .box-viewer-3d {
        height: 500px;
    }
}

@media (max-width: 768px) {
    .app-content {
        padding: 5px;
        gap: 10px;
    }
    
    .dimension-inputs {
        grid-template-columns: 1fr;
    }
    
    .tolerance-constraints {
        grid-template-columns: 1fr;
    }
    
    .viewer-col,
    .settings-col {
        flex: 1 1 auto; /* Allow height to adjust to content */
        width: 100%; /* Ensure full width */
        padding: 10px;
    }
}

/* Viewer + Settings side-by-side */
.viewer-settings {
    display: flex;
    gap: 20px;
    /* align-items: flex-start; */ /* Removed to allow stretch */
    flex-wrap: wrap;
}

.viewer-col,
.settings-col {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    padding: 12px;
    flex: 1 1 300px;
    min-width: 0;
}

.viewer-col .box-viewer-3d {
    height: 440px;
}

.settings-col .form-section {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e9ecef;
}

@media (max-width: 900px) {
    .viewer-settings { flex-direction: column; }
    .viewer-col .box-viewer-3d { height: 320px; }
}

/* Details styling for series and results */
.series-details summary,
.results-details summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

.series-details[open] summary,
.results-details[open] summary {
    background: #eef2ff;
    border-left: 4px solid #667eea;
}

.results-details .results-controls { padding: 12px 0 8px 0; }

/* Compact result item style (tighter) */
.result-item {
    padding: 6px 8px; /* reduced padding */
    border: 1px solid #e9ecef;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
}

.result-item:hover {
    border-color: #667eea;
    box-shadow: 0 6px 10px rgba(102, 126, 234, 0.06);
    transform: translateY(-1px);
}

.result-item.selected-item {
    border-color: #667eea;
    background-color: #f8fbff;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.12);
}

.item-header { margin-bottom: 4px; }
.dimension-row { margin-bottom: 0; gap: 6px; font-size: 12px; }
.dimension-label { min-width: 34px; font-size: 12px; }
.match-badge { padding: 2px 6px; font-size: 11px; }
.dimension-diffs { gap: 6px; font-size: 11px; }
.item-actions { margin-top: 4px; padding-top: 4px; border-top: 1px solid #f1f1f1; text-align: right; }
.lbl-external-dim {
    font-weight: 600;
}

/* Result series icon compact */
.result-series-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}

.result-series-icon-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

/* Selected series (inline text) */
.selected-series-text {
    margin-left: 8px;
    color: #666;
    font-size: 13px;
    margin-top: 6px;
}
.selected-series-text strong {
    color: #333;
    font-weight: 600;
    margin-left: 6px;
}

/* Custom Links & Buttons */
.results-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.custom-links-container {
    text-align: right;
    width: 100%;
    margin-bottom: 10px;
}

.custom-link-btn {
    display: inline-block;
    padding: 4px 12px;
    background-color: #6c757d;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 5px;
    transition: background-color 0.2s;
}

.custom-link-btn:hover {
    background-color: #5a6268;
    text-decoration: none;
    color: white;
}

.custom-links-sm {
    display: inline-flex;
    margin-left: auto;
    gap: 2px;
    padding:5px;
}
.custom-links-sm a {
    float:right;
}

.custom-link-btn.sm {
    padding: 2px 8px;
    font-size: 11px;
    margin-left: 5px;
}

/* InputForm Summary Header */
.dimension-summary summary.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Details summary arrow (general) */
details summary {
    cursor: pointer;
    font-size: 13px;
    color: #495057;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    width: 100%;
}

details summary .details-arrow {
    margin-left: auto;
    display: flex;
    align-items: center;
    color: #667eea;
}

details summary .details-arrow svg,
.accuracy-control .details-arrow svg {
    transition: transform 0.18s ease;
    display: block;
}

/* rotate when details open */
details[open] summary .details-arrow svg {
    transform: rotate(180deg);
}

.accuracy-control.open .details-arrow svg {
    transform: rotate(180deg);
}

.accuracy-control.open .details-arrow {
    transform: rotate(180deg);
}

/* Right controls wrapper: place trigger and accuracy together on right */
.right-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative; /* anchor for absolute overlays */
}

.series-trigger {
    margin-left: 0;
}

.series-modal-trigger {
    background: #fff;
    border: 1px solid #e1e5ea;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.series-modal-trigger svg {
    width: 14px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
    color: #667eea;
    transition: color 0.12s ease, transform 0.12s ease;
}

.series-modal-trigger:hover svg {
    color: #5b6fe0;
    transform: translateY(-1px);
}

/* Accuracy button */
.accuracy-button {
    background: #f8f9fa;
    border: 1px solid #e7eaf0;
    padding: 6px 10px;
    border-radius: 6px;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
}

/* Overlay (absolute, does not push layout) */
.accuracy-overlay {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 10000;
}

.accuracy-overlay-panel {
    width: 360px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    padding: 12px;
}

.accuracy-presets {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.slider-value {
    margin-top: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.accuracy-presets .preset {
    background: #fff;
    border: 1px solid #e7eaf0;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
}

/* Modal footer stats */
.series-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid #f1f1f1;
}

.series-modal-stats {
    font-size: 13px;
    color: #666;
}

/* Ensure the accuracy slider still styles correctly inside overlay */
.accuracy-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #dee2e6;
    outline: none;
    -webkit-appearance: none;
    margin-bottom: 5px;
}

/* Modal overlay */
.series-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.series-modal-dialog {
    background: #fff;
    width: 720px; /* increase default width so it can show up to 4 items per row */
    max-width: 95%;
    border-radius: 8px;
    box-shadow: 0 6px 30px rgba(0,0,0,0.2);
    overflow: hidden;
}

.series-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f1f1;
}

.series-modal-body {
    padding: 14px 16px;
    max-height: 60vh;
    overflow: auto;
}

/* Grid layout: at least 2 per row, up to 4 depending on available width */
.series-list {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.series-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 8px;
    border-radius: 8px;
    text-align: center;
    background: rgba(0,0,0,0.02);
    transition: background 0.15s, transform 0.12s;
}

.series-item:hover {
    background: #f3f7ff;
    transform: translateY(-3px);
}

.series-item.selected {
    background: #e8f0ff;
    outline: 2px solid rgba(102,126,234,0.15);
}

.series-item .series-icon {
    width: 96px;
    height: 96px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.series-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.series-item .series-name {
    display: inline-block;
    font-weight: 700;
    font-size: 14px;
}

.series-item .series-count {
    font-size: 13px;
    color: #666;
}

/* Modal footer button styles */
.series-modal-footer .btn {
    background: #667eea;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.series-modal-footer .btn:hover {
    background: #5b6fe0;
}

.series-modal-footer .btn:active {
    transform: translateY(1px);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
}

.series-modal-footer {
    padding: 10px 16px;
    text-align: right;
    border-top: 1px solid #f1f1f1;
}

.accuracy-slider-container {
    padding: 5px 0;
}
