/* 产品成本查询系统 - 样式 */

:root {
    --primary: #4f6ef7;
    --primary-light: #6b83f9;
    --primary-dark: #3b57d9;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* Header */
.header {
    background: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 100%);
    color: white;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 { font-size: 20px; font-weight: 600; }
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
    padding: 8px 16px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.nav-tab:hover { background: rgba(255,255,255,0.25); }
.nav-tab.active { background: rgba(255,255,255,0.95); color: var(--primary); }

/* Container */
.container { max-width: 1600px; margin: 16px auto; padding: 0 16px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Search Box */
.search-box {
    background: white;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.search-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; color: var(--gray-500); font-weight: 500; }
.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,110,247,0.1);
}
.form-group.search-input { flex: 1; min-width: 200px; }

/* Autocomplete */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0 0 6px 6px;
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
    z-index: 50;
    display: none;
}
.autocomplete-list.show { display: block; }
.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}
.autocomplete-item:hover, .autocomplete-item.active {
    background: var(--gray-50);
}
.autocomplete-item .main-text { font-weight: 500; color: var(--gray-800); }
.autocomplete-item .sub-text { font-size: 12px; color: var(--gray-500); }
.autocomplete-item .cost-text {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
    white-space: nowrap;
}
.autocomplete-highlight { background: #fef3c7; padding: 0 2px; border-radius: 2px; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* Cards */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}
.stat-card .label { font-size: 12px; color: var(--gray-500); margin-bottom: 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; color: var(--gray-800); }
.stat-card .sub { font-size: 11px; color: var(--gray-400); margin-top: 4px; }
.stat-card .copy-hint {
    font-size: 10px;
    color: var(--gray-400);
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.stat-card:hover .copy-hint { opacity: 1; }
.stat-card.copied { border-color: var(--success); }
.stat-card.copied .copy-hint { color: var(--success); }

/* Result Info Bar */
.result-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.result-bar .info { font-size: 13px; color: var(--gray-500); }
.result-bar .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Table */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}
.table-scroll {
    overflow: auto;
    max-height: calc(100vh - 350px);
    min-height: 300px;
}
.table-scroll::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.table-scroll::-webkit-scrollbar-track {
    background: var(--gray-100);
}
.table-scroll::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}
.table-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
    text-align: left;
}
th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    position: sticky;
    top: 0;
    z-index: 10;
    user-select: none;
    cursor: pointer;
    border-bottom: 2px solid var(--gray-200);
}
th:hover { background: var(--gray-100); }
th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 10px;
}
th.sorted .sort-icon { opacity: 1; color: var(--primary); }

/* Column resize handle */
th .resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
}
th .resize-handle:hover,
th .resize-handle.active {
    background: var(--primary);
}

/* Frozen columns */
.frozen-col {
    position: sticky;
    background: white;
    z-index: 5;
}
.frozen-col-0 { left: 0; }
.frozen-col-1 { left: 80px; }
.frozen-col-2 { left: 250px; }

/* Highlight column */
.highlight-col {
    background: #f0f4ff;
    font-weight: 600;
}

/* Row styles */
tr:hover { background: var(--gray-50); }
tr.row-negative { background: #fef2f2; }
tr.row-negative:hover { background: #fee2e2; }
tr.row-high-cost { background: #fffbeb; }
tr.row-high-cost:hover { background: #fef3c7; }
tr.row-high-revenue { background: #f0fdf4; }
tr.row-high-revenue:hover { background: #dcfce7; }

.num-cell { text-align: right; font-variant-numeric: tabular-nums; }
.negative { color: var(--danger); }
.positive { color: var(--success); }

/* Sticky horizontal scrollbar */
.sticky-scrollbar {
    position: sticky;
    bottom: 0;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    overflow-x: auto;
    overflow-y: hidden;
    height: 12px;
}
.sticky-scrollbar::-webkit-scrollbar { height: 8px; }
.sticky-scrollbar::-webkit-scrollbar-track { background: var(--gray-100); }
.sticky-scrollbar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
.sticky-scrollbar-content { height: 1px; }

/* Column settings dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px 0;
    min-width: 220px;
    z-index: 50;
    display: none;
    max-height: 400px;
    overflow-y: auto;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.1s;
}
.dropdown-item:hover { background: var(--gray-50); }
.dropdown-item input[type="checkbox"] { margin: 0; }
.dropdown-item label { cursor: pointer; flex: 1; font-size: 13px; }
.dropdown-divider { height: 1px; background: var(--gray-200); margin: 4px 0; }
.dropdown-header {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
}

/* Advanced filter panel */
.filter-panel {
    background: white;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    display: none;
}
.filter-panel.show { display: block; }
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 12px; color: var(--gray-500); }
.filter-group input, .filter-group select {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 12px;
}
.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

/* Analysis Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-500);
    padding: 4px;
}
.modal-close:hover { color: var(--gray-800); }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Analysis stats */
.analysis-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.analysis-stat {
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 12px;
}
.analysis-stat .label { font-size: 11px; color: var(--gray-500); }
.analysis-stat .value { font-size: 18px; font-weight: 700; color: var(--gray-800); margin-top: 4px; }
.analysis-stat .change { font-size: 11px; margin-top: 4px; }
.analysis-stat .change.up { color: var(--danger); }
.analysis-stat .change.down { color: var(--success); }

/* Chart container */
.chart-container {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.chart-header h3 { font-size: 15px; }
.chart-checkboxes {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.chart-checkboxes label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}
.chart-canvas { width: 100%; height: 400px; }

/* Compare section */
.compare-section { margin-top: 24px; }
.compare-selectors {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.compare-selectors select {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
}

/* Import section */
.import-box {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    max-width: 700px;
    margin: 0 auto;
}
.import-box h2 { font-size: 18px; margin-bottom: 20px; }
.file-drop {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}
.file-drop:hover, .file-drop.dragover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f0f4ff;
}
.file-drop input[type="file"] { display: none; }

/* Validation results */
.validation-results {
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    display: none;
}
.validation-results.show { display: block; }
.validation-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-200);
    font-size: 13px;
}
.validation-item:last-child { border-bottom: none; }
.validation-item .count { font-weight: 600; }
.validation-item.valid .count { color: var(--success); }
.validation-item.duplicate .count { color: var(--warning); }
.validation-item.error .count { color: var(--danger); }

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
    display: none;
}
.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    width: 0%;
    transition: width 0.3s;
}

.log-area {
    background: var(--gray-900);
    color: var(--gray-300);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'Consolas', monospace;
    font-size: 12px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}
.log-area.show { display: block; }
.log-area .info { color: #60a5fa; }
.log-area .success { color: #4ade80; }
.log-area .error { color: #f87171; }
.log-area .warn { color: #fbbf24; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    padding: 12px;
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}
.pagination button:hover { border-color: var(--primary); }
.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.pagination .page-info { font-size: 12px; color: var(--gray-500); margin: 0 8px; }

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-500);
}
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state .message { font-size: 15px; }
.empty-state .hint { font-size: 13px; color: var(--gray-400); margin-top: 8px; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--gray-800);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    font-size: 13px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Responsive */
@media (max-width: 768px) {
    .header { flex-direction: column; gap: 12px; padding: 12px 16px; }
    .search-row { flex-direction: column; }
    .form-group.search-input { min-width: 100%; }
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
    .modal { width: 95%; }
    .analysis-stats { grid-template-columns: repeat(2, 1fr); }
}
