/**
 * Part Browser Styles
 * Enhanced hierarchical part browser with modern UI
 */

.part-browser {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #1e1e1e;
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Header */
.part-browser-header {
    padding: 12px;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
}

.part-browser-header h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.search-box {
    position: relative;
    margin-bottom: 8px;
}

.part-search-input {
    width: 100%;
    padding: 8px 28px 8px 10px;
    border: 1px solid #3c3c3c;
    border-radius: 4px;
    background: #3c3c3c;
    color: #e0e0e0;
    font-size: 13px;
    box-sizing: border-box;
}

.part-search-input:focus {
    outline: none;
    border-color: #0078d4;
}

.part-search-input::placeholder {
    color: #808080;
}

.search-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #808080;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    display: none;
}

.search-btn:hover {
    color: #e0e0e0;
}

.view-modes {
    display: flex;
    gap: 4px;
}

.view-btn {
    flex: 1;
    padding: 6px;
    background: #3c3c3c;
    border: none;
    border-radius: 4px;
    color: #808080;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.view-btn:hover {
    background: #4c4c4c;
    color: #e0e0e0;
}

.view-btn.active {
    background: #0078d4;
    color: #fff;
}

/* Toolbar */
.part-browser-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
    font-size: 12px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.bc-item {
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    color: #e0e0e0;
    transition: background 0.2s;
}

.bc-item:hover {
    background: #3c3c3c;
}

.bc-item.active {
    color: #0078d4;
    font-weight: 500;
}

.bc-separator {
    color: #808080;
}

.part-count {
    color: #808080;
    font-size: 11px;
}

/* Content Area */
.part-browser-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #808080;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid #3c3c3c;
    border-top-color: #0078d4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    color: #e0e0e0;
    gap: 12px;
}

.error-state button {
    padding: 6px 16px;
    background: #0078d4;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    color: #808080;
    gap: 12px;
}

.empty-state button {
    padding: 6px 16px;
    background: #3c3c3c;
    border: none;
    border-radius: 4px;
    color: #e0e0e0;
    cursor: pointer;
}

/* Groups */
.group {
    margin-bottom: 4px;
}

.group-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background: #2d2d30;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.group-header:hover {
    background: #3c3c3c;
}

.group-header.expanded {
    background: #0078d415;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.group-header.sub {
    background: #252526;
    margin-left: 16px;
    margin-top: 2px;
}

.group-header.sub:hover {
    background: #2d2d30;
}

.group-toggle {
    width: 16px;
    color: #808080;
    font-size: 10px;
}

.group-icon {
    margin-right: 8px;
    font-size: 16px;
}

.group-name {
    flex: 1;
    font-weight: 500;
    font-size: 13px;
}

.group-count {
    padding: 2px 6px;
    background: #3c3c3c;
    border-radius: 10px;
    font-size: 11px;
    color: #808080;
    margin-right: 8px;
}

.group-desc {
    color: #808080;
    font-size: 11px;
    display: none;
}

@media (min-width: 300px) {
    .group-desc {
        display: block;
    }
}

/* Subgroups */
.subgroups {
    padding: 4px 0 4px 8px;
    background: #252526;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.subgroup {
    margin-bottom: 2px;
}

/* Type Grid */
.type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    padding: 4px;
}

.type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    background: #2d2d30;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.type-card:hover {
    background: #3c3c3c;
    transform: translateY(-2px);
}

.type-card:active {
    transform: translateY(0);
}

.type-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.type-name {
    font-size: 12px;
    font-weight: 500;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.type-count {
    font-size: 11px;
    color: #808080;
}

.type-desc {
    font-size: 10px;
    color: #606060;
    margin-top: 4px;
    display: none;
}

@media (min-width: 250px) {
    .type-desc {
        display: block;
    }
}

/* Part Grid - 单列布局确保按钮可见 */
.part-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: #252526;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.part-item {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    background: #2d2d30;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    gap: 8px;
    min-width: 0;
}

.part-item:hover {
    background: #3c3c3c;
}

.part-item.selected {
    background: #0078d430;
    border: 1px solid #0078d4;
}

.part-preview {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    min-width: 64px;
    background: #252526;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.part-thumbnail {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    padding: 4px;
    box-sizing: border-box;
    transition: opacity 0.2s;
    display: block;
}

.part-icon-placeholder {
    font-size: 28px;
    transition: opacity 0.2s;
}

.part-dims {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 9px;
    font-weight: 600;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 5px;
    border-radius: 3px;
    backdrop-filter: blur(2px);
}

/* Base/Variant Part Badges */
.variant-count {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    background: #0078d4;
    padding: 2px 6px;
    border-radius: 10px;
    backdrop-filter: blur(2px);
}

.variant-type-label {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 9px;
    font-weight: 600;
    color: #ff9800;
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 4px;
    border-radius: 3px;
    backdrop-filter: blur(2px);
}

/* Base part styling */
.part-item.base-part {
    border-left: 3px solid #0078d4;
}

.part-item.base-part.has-variants {
    background: #2d3035;
}

/* Variant part styling */
.part-item.variant-part {
    border-left: 3px solid #ff9800;
    background: #2a2a2a;
    margin-left: 20px;
    width: calc(100% - 20px);
}

/* Variant list container */
.variant-list {
    width: 100%;
}

/* Expand button */
.action-btn.expand {
    background: #5a5a5a;
    font-size: 10px;
    width: 22px;
    height: 22px;
}

.action-btn.expand.expanded {
    background: #0078d4;
}

.part-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 64px;
    min-width: 0;
    overflow: hidden;
}

.part-name {
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 6px;
    line-height: 1.4;
    word-break: break-word;
}

.part-desc {
    font-size: 12px;
    color: #a0a0a0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.part-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.part-item:hover .part-actions {
    opacity: 1;
}

/* 有派生件的基础零件，按钮始终可见 */
.part-item.has-variants .part-actions {
    opacity: 1;
}

/* 展开按钮在右下角 */
.expand-btn {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    padding: 0;
    background: #5a5a5a;
    border: none;
    border-radius: 3px;
    color: #fff;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
}

.expand-btn:hover {
    background: #0078d4;
}

.expand-btn.expanded {
    background: #0078d4;
}

.action-btn {
    width: 20px;
    height: 20px;
    padding: 0;
    background: #0078d4;
    border: none;
    border-radius: 3px;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.action-btn:hover {
    background: #106ebe;
}

/* Footer */
.part-browser-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #252526;
    border-top: 1px solid #3c3c3c;
    font-size: 11px;
}

.stats {
    display: flex;
    gap: 12px;
    color: #808080;
}

.actions {
    display: flex;
    gap: 4px;
}

.actions button {
    padding: 4px 8px;
    background: #3c3c3c;
    border: none;
    border-radius: 3px;
    color: #e0e0e0;
    font-size: 12px;
    cursor: pointer;
}

.actions button:hover {
    background: #4c4c4c;
}

/* Scrollbar */
.part-browser-content::-webkit-scrollbar {
    width: 8px;
}

.part-browser-content::-webkit-scrollbar-track {
    background: #1e1e1e;
}

.part-browser-content::-webkit-scrollbar-thumb {
    background: #3c3c3c;
    border-radius: 4px;
}

.part-browser-content::-webkit-scrollbar-thumb:hover {
    background: #4c4c4c;
}

/* Part Preview Popup - Hidden by default (using global popup instead) */
.part-preview-popup {
    display: none;
}

/* Global Preview Popup - Fixed position, outside part browser */
.part-preview-global {
    position: fixed;
    width: 160px;
    height: 160px;
    background: #2d2d30;
    border: 2px solid #0078d4;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
    overflow: hidden;
}

.part-preview-global.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.part-preview-global .preview-gif {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #252526;
    border-radius: 6px;
}

/* Loading state for preview */
.part-preview-global .preview-gif[src=""] {
    background: linear-gradient(90deg, #252526 25%, #2d2d30 50%, #252526 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
