/**
 * 商品对比表格样式
 * 包含 11 类动画效果，提升用户体验
 */

/* ==================== 基础布局 ==================== */

.product-compare-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0;
}

.compare-upload-section {
    background: var(--surface, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow, 0 1px 3px rgba(0, 0, 0, 0.1));
    min-height: 280px;
    max-height: 280px;
    overflow-y: auto;
}

.compare-upload-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

.upload-card {
    background: transparent;
    border: none;
    padding: 0;
}

.upload-card h4 {
    margin: 0 0 12px;
    font-size: 1.1rem;
    color: #0f172a;
}

/* ==================== 上传区域 ==================== */

.upload-box {
    display: block;
    border: 1px dashed rgba(148,163,184,0.6);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    position: relative;
}

.upload-box:hover {
    border-color: #2563eb;
    background: #eff6ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.upload-box.selected {
    border-color: #2563eb;
    background: #dbeafe;
    border-style: solid;
}

.upload-box input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    color: #64748b;
    margin-bottom: 4px;
    transition: color 0.3s;
    width: 32px;
    height: 32px;
}

.upload-box:hover .upload-icon {
    color: #2563eb;
}

.upload-text {
    margin: 4px 0;
    color: #475569;
    font-size: 0.85rem;
}

.upload-filename {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 2px;
}

.upload-filename.has-file {
    color: #2563eb;
    font-weight: 600;
}

.upload-meta {
    margin-top: 12px;
}

.upload-meta label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #475569;
}

.upload-meta input[type="number"] {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* ==================== 配置面板 ==================== */

.config-panel {
    background: transparent;
    border: none;
    padding: 0;
    margin-top: 12px;
}

.config-panel h4 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    color: #0f172a;
    font-weight: 600;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

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

.config-item span {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

.config-item input,
.config-item select {
    padding: 6px 10px;
    border: 1px solid rgba(148,163,184,0.35);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.config-item input:focus,
.config-item select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ==================== 筛选栏 ==================== */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--surface, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    flex-wrap: wrap;
    position: relative;
}

/* 3. 筛选按钮动画 */
.filter-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #475569;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.filter-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #2563eb;
}

.filter-btn.active {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
}

.filter-btn .badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    font-size: 0.85rem;
    transition: transform 0.2s;
}

.filter-btn.active .badge {
    background: rgba(255, 255, 255, 0.25);
}

.filter-btn:hover .badge {
    transform: scale(1.15) rotate(5deg);
}

.filter-spacer {
    flex: 1;
}

/* ==================== 对比表格 ==================== */

.compare-table-section {
    background: var(--surface, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow, 0 1px 3px rgba(0, 0, 0, 0.1));
    min-height: 500px;
    max-height: 500px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.compare-table-wrapper {
    overflow: auto;
    flex: 1;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    background: var(--surface, #ffffff);
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

/* 表头样式 */
.compare-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.compare-table th {
    padding: 12px;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    text-align: left;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
}

.compare-table th.group-header {
    background: linear-gradient(135deg, #c7d2fe, #bfdbfe);
    text-align: center;
    font-size: 1rem;
    border-bottom: 2px solid #2563eb;
}

.compare-table th.product-a-header {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
}

.compare-table th.product-b-header {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
}

.compare-table th.delta-header {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
}

/* 1. 表格行交互动画 */
.compare-table tbody tr {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
}

.compare-table tbody tr:hover {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.05) 0%, rgba(37, 99, 235, 0.02) 100%);
    transform: translateX(2px);
    box-shadow: -3px 0 0 0 #2563eb;
}

.compare-table tbody tr.selected {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.1) 0%, rgba(37, 99, 235, 0.05) 100%);
    box-shadow: -4px 0 0 0 #2563eb, 0 2px 8px rgba(37, 99, 235, 0.15);
    transform: scale(1.005);
}

/* 行点击波纹效果 */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

.compare-table tbody tr::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.3) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.6s;
}

.compare-table tbody tr:active::after {
    animation: ripple 0.6s ease-out;
}

/* 表格单元格 */
.compare-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #0f172a;
}

/* 2. 单元格编辑动画 */
td.editable,
td[contenteditable="true"] {
    position: relative;
    transition: all 0.25s ease;
}

td[contenteditable="true"]:focus {
    background: #fffbeb;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 1px #fbbf24, 0 0 0 3px rgba(245, 158, 11, 0.1);
    transform: scale(1.02);
    z-index: 10;
}

/* 编辑状态指示器 */
td[contenteditable="true"]::before {
    content: '✏️';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}

td[contenteditable="true"]:focus::before {
    opacity: 0.6;
}

/* 值变化闪烁提示 */
@keyframes valueChange {
    0%, 100% { background: transparent; }
    50% { background: rgba(34, 197, 94, 0.2); }
}

td.value-changed {
    animation: valueChange 0.8s ease-in-out;
}

/* 状态徽章 */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.status-badge.status-matched {
    background: #d1fae5;
    color: #059669;
}

.status-badge.status-onlyA {
    background: #dbeafe;
    color: #2563eb;
}

.status-badge.status-onlyB {
    background: #fef3c7;
    color: #d97706;
}

.status-badge.status-conflict {
    background: #fecaca;
    color: #dc2626;
}

/* 6. 差异高亮动画 */
.delta-positive {
    position: relative;
    color: #059669;
    font-weight: 600;
    transition: all 0.3s;
}

.delta-positive::before {
    content: '↑';
    margin-right: 4px;
    font-size: 12px;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.delta-negative {
    position: relative;
    color: #dc2626;
    font-weight: 600;
    transition: all 0.3s;
}

.delta-negative::before {
    content: '↓';
    margin-right: 4px;
    font-size: 12px;
    animation: bounce-down 1s ease-in-out infinite;
}

@keyframes bounce-down {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

.delta-neutral {
    color: #64748b;
}

/* 5. 数据加载与刷新动画 */
.table-loading {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
}

/* 骨架屏加载 */
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-row {
    background: linear-gradient(
        90deg,
        #f3f4f6 0%,
        #e5e7eb 50%,
        #f3f4f6 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    height: 40px;
}

/* 表格数据淡入 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.compare-table tbody tr {
    animation: fadeInUp 0.4s ease-out;
    animation-fill-mode: both;
}

/* 行错开淡入（瀑布流效果） */
.compare-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.compare-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.compare-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.compare-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.compare-table tbody tr:nth-child(5) { animation-delay: 0.25s; }

/* ==================== 手动匹配区域 ==================== */

.manual-match-section {
    background: var(--surface, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 20px;
}

.manual-match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.manual-match-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: #0f172a;
}

.manual-match-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
}

.only-a-list h5,
.only-b-list h5 {
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e2e8f0;
    font-size: 1rem;
    color: #0f172a;
}

.match-list {
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}

/* 4. 拖拽匹配动画 */
.row-item {
    padding: 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.row-item:hover {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

/* 拖拽中状态 */
.row-item.dragging {
    opacity: 0.5;
    transform: rotate(3deg) scale(0.95);
    cursor: grabbing;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* 拖拽目标区域高亮 */
.only-b-list.drag-over {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(34, 197, 94, 0.05) 100%);
    border: 2px dashed #22c55e;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 匹配成功动画 */
@keyframes matchSuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); background: #22c55e; }
    100% { transform: scale(1); background: #10b981; }
}

.row-item.matched {
    animation: matchSuccess 0.6s ease-out;
    background: #d1fae5;
    border-left: 4px solid #10b981;
}

.row-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.row-item-id {
    font-size: 0.8rem;
    color: #94a3b8;
    font-family: monospace;
}

.row-item-badge {
    padding: 2px 6px;
    background: #2563eb;
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.row-item-name {
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 4px;
}

.row-item-sales {
    font-size: 0.85rem;
    color: #64748b;
}

.manual-match-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ==================== 按钮样式 ==================== */

.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-size: 0.9rem;
}

/* 7. 按钮交互动画 */
.btn-primary {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

/* 按钮涟漪效果 */
.btn-primary::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:active:not(:disabled)::before {
    width: 300px;
    height: 300px;
}

.btn-secondary {
    background: #f8fafc;
    color: #475569;
    border: 1px solid #cbd5e1;
}

.btn-secondary:hover:not(:disabled) {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.btn-ghost {
    background: transparent;
    color: #475569;
    border: none;
}

.btn-ghost:hover {
    background: #f1f5f9;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== 操作栏 ==================== */

.compare-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.status {
    margin-left: 8px;
    font-size: 0.85rem;
}

.status-success {
    color: #059669;
}

.status-error {
    color: #dc2626;
}

.status-info {
    color: #2563eb;
}

/* ==================== 8. 工具提示（Tooltip）动画 ==================== */

.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.tooltip::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
}

.has-tooltip:hover .tooltip {
    opacity: 1;
    transform: translateY(0);
}

/* ==================== 11. 性能优化技巧 ==================== */

/* 使用 GPU 加速 */
.compare-table tbody tr,
.filter-btn,
.row-item {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 减少重排 - 使用 transform 而非 top/left */
.animated-element {
    transform: translate3d(0, 0, 0);
}

/* 延迟非关键动画 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== 9. 响应式过渡 ==================== */

@media (max-width: 768px) {
    .compare-upload-grid,
    .manual-match-grid {
        grid-template-columns: 1fr;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .compare-table-wrapper {
        transition: transform 0.3s;
    }

    /* 横向滚动指示器 */
    .compare-table-wrapper::after {
        content: '← 滑动查看更多 →';
        position: sticky;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 8px;
        background: linear-gradient(0deg, rgba(0,0,0,0.05) 0%, transparent 100%);
        text-align: center;
        font-size: 12px;
        color: #64748b;
        animation: fadeInOut 2s ease-in-out infinite;
    }

    @keyframes fadeInOut {
        0%, 100% { opacity: 0.5; }
        50% { opacity: 1; }
    }
}
