/* ========================================
   五险一金合规分析工具 - 全局样式
   ======================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --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;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  --transition: all 0.2s ease;
}

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

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Layout ---- */
.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
  margin-right: 32px;
  white-space: nowrap;
}

.app-header .subtitle {
  font-size: 12px;
  color: var(--gray-400);
  margin-left: 8px;
}

/* ---- Tabs ---- */
.tab-bar {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.tab-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--gray-500);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: var(--transition);
  white-space: nowrap;
  font-weight: 500;
}

.tab-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.tab-btn.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.tab-content { display: none; padding: 24px; max-width: 1600px; margin: 0 auto; }
.tab-content.active { display: block; }

/* ---- Card ---- */
.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* ---- Buttons ---- */
.btn {
  padding: 8px 20px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  color: var(--gray-700);
}

.btn:hover { border-color: var(--gray-400); background: var(--gray-50); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Upload Area ---- */
.upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 16px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--gray-50);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-icon { font-size: 24px; margin-bottom: 4px; }
.upload-text { color: var(--gray-600); font-size: 14px; }
.upload-hint { color: var(--gray-400); font-size: 12px; margin-top: 4px; }

/* ---- File List ---- */
.file-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.file-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  font-size: 12px;
}

.file-tag .file-name { font-weight: 500; color: var(--gray-700); }
.file-tag .file-meta { color: var(--gray-400); }
.file-tag .file-remove { color: var(--gray-400); cursor: pointer; font-size: 14px; line-height: 1; }
.file-tag .file-remove:hover { color: var(--danger); }

/* ---- Company Config ---- */
.company-config {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px;
  background: var(--gray-50);
  border-radius: 6px;
  border: 1px solid var(--gray-200);
}

.company-config .form-group { margin-bottom: 0; }

/* ---- Form ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group select,
.form-group input,
.form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--gray-800);
  background: white;
  transition: var(--transition);
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

/* ---- Sheet Tabs ---- */
.sheet-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.sheet-tab {
  padding: 6px 14px;
  background: var(--gray-100);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-600);
  transition: var(--transition);
  border: 1px solid transparent;
}

.sheet-tab:hover { background: var(--gray-200); }
.sheet-tab.active { background: var(--primary); color: white; }

/* ---- Table ---- */
.table-wrapper {
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: white;
  position: relative;
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table-wrapper th {
  padding: 8px 10px;
  text-align: left;
  background: var(--gray-100);
  font-weight: 600;
  color: var(--gray-700);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

.table-wrapper td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  white-space: nowrap;
}

.table-wrapper tr:hover td { background: var(--gray-50); }

/* ---- Column Mapper ---- */
.mapper-container {
  display: grid;
  grid-template-columns: 1fr 60px 1fr;
  gap: 8px;
  align-items: start;
}

/* ---- Summary Config Table ---- */
.summary-config-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-config-table th {
  padding: 8px 12px;
  text-align: left;
  background: var(--gray-100);
  font-weight: 600;
  color: var(--gray-700);
  border-bottom: 2px solid var(--gray-200);
  font-size: 12px;
}

.summary-config-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.summary-config-table .sc-target-input,
.summary-config-table .sc-source-select,
.summary-config-table .sc-process-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-size: 13px;
  background: white;
  font-family: var(--font);
}

.summary-config-table .sc-target-input:focus,
.summary-config-table .sc-source-select:focus,
.summary-config-table .sc-process-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}

.mapper-field {
  padding: 10px 14px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mapper-field .required { color: var(--danger); font-weight: bold; }

.mapper-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: 18px;
  padding-top: 10px;
}

.mapper-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  background: white;
}

.mapper-select.matched { border-color: var(--success); background: var(--success-light); }

/* ---- Stats Cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 16px;
  border-radius: var(--radius);
  color: white;
  text-align: center;
}

.stat-card .stat-value { font-size: 24px; font-weight: 700; margin-bottom: 2px; }
.stat-card .stat-label { font-size: 11px; opacity: 0.9; }

.stat-card.blue { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.stat-card.green { background: linear-gradient(135deg, #22c55e, #15803d); }
.stat-card.red { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.stat-card.orange { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-card.purple { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }

/* ---- Status Messages ---- */
.status-msg {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.status-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.status-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.status-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }

.status-block { flex-direction: column; align-items: flex-start; }
.status-detail { font-size: 13px; margin-top: 6px; line-height: 1.8; }

/* ---- Table Row Utilities ---- */
.row-custom { background: var(--primary-light); }
.row-adjust { background: #fffbeb; font-weight: 500; }
.row-muted { color: var(--gray-500); }
.col-highlight-blue { background: #e8f4fd; }
.col-highlight-green { background: #e8fdf0; }

/* ---- Info Panel (inline info boxes) ---- */
.info-panel {
  margin: 0;
  padding: 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

.info-panel-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
}

.info-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--gray-500);
}

.source-link {
  color: var(--primary);
  font-size: 11px;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

/* ---- Summary Bar ---- */
.summary-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  margin-bottom: 12px;
}

.summary-bar .text-primary { color: var(--primary); }
.summary-bar .text-warning { color: var(--warning); }
.summary-bar .text-muted { color: var(--gray-500); }

/* ---- Inline Filters ---- */
.inline-filters {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.inline-filters .form-group { margin: 0; }
.inline-filters .form-group label { font-size: 12px; }

/* ---- Employee Group (Base Calc) ---- */
.emp-group { margin-bottom: 24px; }

.emp-header {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: var(--gray-50);
  border-left: 4px solid var(--primary);
  border-radius: 0 4px 4px 0;
}

.emp-header .emp-meta {
  font-weight: normal;
  font-size: 12px;
  color: var(--gray-500);
}

/* ---- Filter Bar ---- */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--gray-50);
  border-radius: 6px;
  border: 1px solid var(--gray-200);
}

.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }

/* ---- Progress ---- */
.progress-bar {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  margin: 12px 0;
}

.progress-bar .progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ---- History ---- */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  margin-bottom: 8px;
  background: white;
  transition: var(--transition);
}

.history-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.history-item .history-info { flex: 1; }
.history-item .history-title { font-weight: 600; font-size: 14px; color: var(--gray-800); }
.history-item .history-meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* ---- Diff Colors ---- */
.diff-positive { color: var(--danger); font-weight: 600; }
.diff-negative { color: var(--success); font-weight: 600; }
.diff-zero { color: var(--gray-400); }

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 800px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; font-size: 24px; color: var(--gray-400); background: none; border: none; }
.modal-close:hover { color: var(--gray-700); }

/* ---- Virtual Scroll ---- */
.virtual-table-container {
  position: relative;
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: white;
}

.virtual-table-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--gray-100);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .app-header { flex-direction: column; height: auto; padding: 12px; }
  .tab-bar { overflow-x: auto; }
  .tab-content { padding: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .mapper-container { grid-template-columns: 1fr; }
  .mapper-arrow { transform: rotate(90deg); padding: 0; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ---- Animations ---- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease; }

/* ---- Header Detection Highlight ---- */
.header-row-highlight { background: #fef9c3 !important; }

/* ---- Loading Overlay ---- */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.88);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  /* 使用 visibility + opacity 替代 display:none，可 GPU 加速，不需要重排 */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  will-change: opacity;
}
.loading-overlay.show {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.loading-content { text-align: center; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; color: var(--gray-700); font-weight: 500; line-height: 1.8; }

/* ---- Diff Analysis Config ---- */
.diff-config-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  position: relative;
}

.diff-config-row .diff-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-config-row .diff-side-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.diff-config-row .diff-side-label.left { color: var(--primary); }
.diff-config-row .diff-side-label.right { color: var(--success); }

.diff-config-row .diff-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-400);
  padding-bottom: 8px;
}

.diff-config-row .diff-method {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.diff-config-row .diff-method label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
}

.diff-config-row select {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  background: white;
  color: var(--gray-800);
  transition: var(--transition);
}

.diff-config-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.diff-config-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: var(--transition);
}

.diff-config-delete:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* ---- Diff Result Styles ---- */
.diff-result-positive { color: var(--danger); font-weight: 600; }
.diff-result-negative { color: var(--success); font-weight: 600; }
.diff-result-zero { color: var(--gray-400); }
.diff-result-highlight { background: #fffbeb; }

/* ---- Sheet Merge ---- */
.sheet-merge-file-group {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 12px;
}
.sheet-merge-file-group legend {
  font-weight: 600;
  padding: 0 6px;
  overflow-wrap: anywhere;
}
.sheet-merge-select-all,
.sheet-merge-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 6px 14px 6px 0;
  min-height: 28px;
  overflow-wrap: anywhere;
}
.sheet-merge-select-all { font-weight: 600; }
.sheet-merge-file-group input { accent-color: var(--primary); }
.summary-sheet-inclusion {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 8px 0 12px;
  padding: 10px 12px;
  background: var(--gray-50);
  border-radius: 6px;
  font-size: 13px;
}
.summary-sheet-inclusion label { display: inline-flex; align-items: center; gap: 6px; }
.summary-sheet-inclusion input { accent-color: var(--primary); }
.summary-sheet-inclusion .sheet-inclusion-count { color: var(--gray-500); }

@media (max-width: 640px) {
  .sheet-merge-option { display: flex; margin-right: 0; }
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 14px; }
