* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #18181b;
    color: #e4e4e7;
    padding: 8px;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 头部区域 */
.header-area {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 6px;
    padding-left: 4px;
}

h1 {
    font-size: 18px;
    color: #60a5fa;
}

.subtitle {
    color: #a1a1aa;
    font-size: 11px;
}

.rate-badge {
    background: #22c55e20;
    color: #22c55e;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    margin-left: auto;
}

/* 表单区域 */
.form-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 6px;
    background: #27272a;
    padding: 6px 10px;
    border-radius: 6px;
}

.form-group {
    flex: 1;
    min-width: 120px;
}

.form-group.category-group {
    flex: 1;
    min-width: 120px;
}

.category-select-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.category-select-row select {
    flex: 1;
    min-width: 0;
}

label {
    display: block;
    font-size: 9px;
    font-weight: 500;
    color: #a1a1aa;
    margin-bottom: 2px;
    text-transform: uppercase;
}

select,
input {
    width: 100%;
    padding: 2px 6px;
    background: #3f3f46;
    border: 1px solid #52525b;
    border-radius: 4px;
    color: #e4e4e7;
    font-size: 12px;
    cursor: pointer;
    height: 26px;
}

button {
    padding: 0 16px;
    height: 26px;
    background: #60a5fa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    line-height: 26px;
}

button:hover:not(:disabled) {
    background: #3b82f6;
}

button:disabled {
    background: #3f3f46;
    color: #a1a1aa;
    cursor: not-allowed;
}

/* 内联子分类层级容器 */
.sub-category-inline {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.sub-category-inline:empty {
    display: none;
}

.category-level-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 0 1 auto;
    min-width: 120px;
}

.category-level-group .level-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.select-wrapper {
    flex: 1;
    min-width: 0;
}

.category-level-group select {
    width: 100%;
    min-width: 0;
}

.add-level-btn {
    height: 26px;
    width: 26px;
    min-width: 26px;
    padding: 0;
    background: #60a5fa;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.add-level-btn:hover {
    background: #3b82f6;
}

.remove-level-btn {
    height: 26px;
    width: 26px;
    min-width: 26px;
    padding: 0;
    background: #3f3f46;
    color: #a1a1aa;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.remove-level-btn:hover {
    background: #ef4444;
    color: white;
}

/* 排除区域 */
.exclusions-section {
    background: #27272a;
    border-radius: 6px;
    margin-bottom: 6px;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.exclusions-label {
    font-size: 10px;
    color: #a1a1aa;
    font-weight: 500;
    white-space: nowrap;
}

.no-subcategories {
    font-size: 11px;
    color: #a1a1aa;
    padding: 2px 6px;
}

.exclusions-select {
    width: 120px;
    border-radius: 12px;
    height: 22px;
    padding: 0 8px;
    font-size: 11px;
}

.exclusion-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.exclusion-tag {
    background: #60a5fa20;
    color: #60a5fa;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.exclusion-tag button {
    background: none;
    border: none;
    color: #60a5fa;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    height: auto;
    line-height: 1;
}

.exclusion-tag button:hover {
    color: #ef4444;
}

/* 结果展示区域 */
#result {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: #1f1f23;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
}

.stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: #27272a;
    font-size: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid #3f3f46;
}

.stats-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.count {
    background: #3f3f46;
    padding: 2px 10px;
    border-radius: 10px;
}

/* 表格紧凑自适应滚动 - 开启 GPU 加速 */
.table-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    width: 100%;
    transform: translateZ(0);
    will-change: transform, scroll-position;
    -webkit-overflow-scrolling: touch;
}

/* 强制固定表格布局 */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

th {
    text-align: left;
    padding: 6px 8px;
    background: #27272a;
    color: #a1a1aa;
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 #3f3f46;
}

td {
    padding: 4px 8px;
    border-bottom: 1px solid #3f3f46;
    vertical-align: middle;
    overflow: hidden;
}

/* 独立行渲染优化 */
tr {
    contain: content;
}

tr:hover {
    background: #2a2a2e;
}

.product-image {
    width: 45px;
    height: 45px;
    object-fit: contain;
    background: #fff;
    border-radius: 4px;
    padding: 2px;
    display: block;
    cursor: zoom-in;
    transition: border 0.2s;
    border: 1px solid transparent;
    content-visibility: auto;
    -webkit-tap-highlight-color: transparent;
}

.product-image:hover {
    border: 1px solid #60a5fa;
}

/* 模态框打开时禁止底层图片 hover 蓝色边框 */
body.modal-open .product-image,
body.modal-open .product-image:hover {
    border-color: transparent !important;
}

/* 模态框打开时全局禁止文本选中，消除蓝色 ::selection 高亮 */
body.modal-open {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* 悬浮与大图 */
#hoverPreview {
    position: fixed;
    display: none;
    z-index: 9998;
    pointer-events: none;
    background: #fff;
    padding: 4px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

#hoverPreview img {
    width: 220px;
    height: 220px;
    object-fit: contain;
    display: block;
    border-radius: 4px;
}

#imageModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    -webkit-tap-highlight-color: transparent;
}

#imageModal img {
    max-width: 85vw;
    max-height: 85vh;
    object-fit: contain;
    background: #fff;
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

.modal-close {
    position: absolute;
    top: 25px;
    right: 40px;
    color: #a1a1aa;
    font-size: 45px;
    cursor: pointer;
    line-height: 1;
    user-select: none;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #ef4444;
}

.title-link {
    color: #60a5fa;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
    font-size: 13px;
}

.title-link:hover {
    text-decoration: underline;
}

.price {
    font-weight: bold;
    color: #22c55e;
    white-space: nowrap;
    font-size: 14px;
}

.cny-price {
    color: #facc15;
    font-size: 11px;
    margin-left: 4px;
    font-weight: normal;
}

/* 修复路径列不对齐的问题：将 Flex 移到内部 div */
.category-path {
    font-size: 11px;
    color: #a1a1aa;
}

.cat-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
}

.cat-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    line-height: 1.3;
}

.fetch-single-btn {
    background: #3f3f46;
    color: #60a5fa;
    border: 1px solid #52525b;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 10px;
    cursor: pointer;
    flex-shrink: 0;
    height: 20px;
    line-height: 14px;
}

.fetch-single-btn:hover {
    background: #52525b;
}

.btn-bulk-fetch {
    background: #f59e0b;
    height: 24px;
    line-height: 24px;
    padding: 0 12px;
    font-size: 11px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-bulk-fetch:hover:not(:disabled) {
    background: #d97706;
}

.btn-bulk-fetch:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-export {
    background: #22c55e;
    height: 24px;
    line-height: 24px;
    padding: 0 12px;
    font-size: 11px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    margin-left: 8px;
}

/* 其他小部件 */
.loading {
    text-align: center;
    padding: 40px;
    color: #a1a1aa;
    font-size: 14px;
    width: 100%;
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid #3f3f46;
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid #ef4444;
    color: #ef4444;
    padding: 12px;
    border-radius: 6px;
    margin: 12px;
    font-size: 13px;
}

.progress-bar-container {
    background: #3f3f46;
    height: 2px;
    width: 100%;
    flex-shrink: 0;
    display: none;
}

.progress-bar {
    background: #f59e0b;
    height: 100%;
    width: 0%;
    transition: width 0.2s;
}

@media (max-width: 800px) {
    body {
        height: auto;
        overflow: auto;
    }

    .container {
        height: auto;
    }

    #result {
        min-height: 600px;
    }
}

/* ========== 设置面板 ========== */
.settings-gear-btn {
    background: none;
    border: none;
    color: #a1a1aa;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s, transform 0.3s;
    margin-left: auto;
}

.settings-gear-btn:hover {
    color: #60a5fa;
    transform: rotate(90deg);
}

.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: settingsFadeIn 0.15s ease-out;
}

@keyframes settingsFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.settings-panel {
    background: #27272a;
    border-radius: 8px;
    border: 1px solid #3f3f46;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 420px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: settingsSlideIn 0.15s ease-out;
}

@keyframes settingsSlideIn {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #3f3f46;
}

.settings-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #e4e4e7;
}

.settings-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: #3f3f46;
    border: 1px solid #3f3f46;
    border-radius: 4px;
    color: #a1a1aa;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.settings-close-btn:hover {
    background: #52525b;
    color: #e4e4e7;
}

.settings-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.settings-form-group {
    margin-bottom: 14px;
}

.settings-form-group:last-of-type {
    margin-bottom: 0;
}

.settings-form-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #a1a1aa;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

.settings-form-group input,
.settings-form-group select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #3f3f46;
    border-radius: 4px;
    font-size: 13px;
    background: #3f3f46;
    color: #e4e4e7;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.settings-form-group input:focus,
.settings-form-group select:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.1);
}

.settings-form-group input[type="number"] {
    -moz-appearance: textfield;
}

.settings-form-group input[type="number"]::-webkit-inner-spin-button,
.settings-form-group input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.settings-hint {
    display: block;
    font-size: 10px;
    color: #71717a;
    margin-top: 3px;
}

.settings-msg {
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 12px;
    margin-top: 12px;
}

.settings-msg.success {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.settings-msg.error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.settings-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #3f3f46;
}

.settings-cancel-btn,
.settings-save-btn {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.settings-cancel-btn {
    background: #3f3f46;
    border: 1px solid #3f3f46;
    color: #e4e4e7;
}

.settings-cancel-btn:hover {
    background: #52525b;
}

.settings-save-btn {
    background: #60a5fa;
    border: 1px solid #60a5fa;
    color: white;
}

.settings-save-btn:hover {
    filter: brightness(1.1);
}
