/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 8px;
  --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.07), 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);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header h1 { 
  font-size: 18px; 
  font-weight: 700; 
  line-height: 1.4;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-sub { font-size: 12px; color: var(--text-muted); line-height: 1.4; letter-spacing: 0.5px; }
.header-nav-link {
  margin-left: auto; font-size: 13px; color: var(--text-secondary);
  text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 6px;
  transition: var(--transition);
  white-space: nowrap;
  font-weight: 500;
}
.header-nav-link:hover { 
  background: var(--primary-light); 
  color: var(--primary);
  text-decoration: none; 
  transform: translateY(-1px);
}
.header-nav-link[style*="font-weight:700"] {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600 !important;
}

/* Main */
.main-content { max-width: 1600px; margin: 0 auto; padding: 20px 24px; }

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.filter-bar:hover {
  box-shadow: var(--shadow);
}
.filter-item { display: flex; flex-direction: column; gap: 6px; }
.filter-item label { 
  font-size: 12px; 
  color: var(--text-muted); 
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-item select,
.filter-item input[type="date"],
.filter-item input[type="text"] {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  min-width: 140px;
  transition: var(--transition);
  font-family: inherit;
}
.filter-item select:focus,
.filter-item input[type="date"]:focus,
.filter-item input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.filter-search input { min-width: 200px; }
.filter-actions { 
  display: flex; 
  gap: 8px; 
  align-items: flex-end;
}

.btn {
  height: 36px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { 
  background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%); 
  color: #fff; 
  box-shadow: 0 2px 4px rgba(37,99,235,0.3);
}
.btn-primary:hover { 
  background: linear-gradient(135deg, var(--primary-hover) 0%, #2563eb 100%); 
  box-shadow: 0 4px 8px rgba(37,99,235,0.4);
  transform: translateY(-1px);
}
.btn-danger { 
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%); 
  color: #fff;
  box-shadow: 0 2px 4px rgba(220,38,38,0.3);
}
.btn-danger:hover { 
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%); 
  box-shadow: 0 4px 8px rgba(220,38,38,0.4);
  transform: translateY(-1px);
}
.btn-warning { 
  background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%); 
  color: #fff;
  box-shadow: 0 2px 4px rgba(245,158,11,0.3);
}
.btn-warning:hover { 
  background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%); 
  transform: translateY(-1px);
}
.btn-success { 
  background: linear-gradient(135deg, var(--success) 0%, #10b981 100%); 
  color: #fff;
  box-shadow: 0 2px 4px rgba(5,150,105,0.3);
}
.btn-success:hover { 
  background: linear-gradient(135deg, #047857 0%, #059669 100%); 
  transform: translateY(-1px);
}
.btn-secondary { 
  background: var(--surface); 
  color: var(--text); 
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { 
  background: #f9fafb; 
  border-color: #d1d5db;
  box-shadow: var(--shadow);
}

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  min-width: 0;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary) 0%, #7c3aed 100%);
  opacity: 0;
  transition: var(--transition);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: transparent;
}
.card:hover::before {
  opacity: 1;
}
.card-label { 
  font-size: 12px; 
  color: var(--text-muted); 
  margin-bottom: 8px; 
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.card-value { 
  font-size: 26px; 
  font-weight: 700; 
  white-space: nowrap;
  letter-spacing: -0.5px;
}
.card-value.amount { color: var(--primary); }
.card-value.cost { color: var(--warning); }
.card-value.profit { color: var(--success); }

/* Table Section */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);
}
.table-header h2 { 
  font-size: 16px; 
  font-weight: 700;
  color: var(--text);
}
.table-count { 
  font-size: 12px; 
  color: var(--text-muted);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}
.table-wrap { overflow-x: auto; }
.table-empty, .table-loading {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  display: none;
}
.table-loading { display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 13px;
}
td:first-child {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
thead { position: sticky; top: 0; z-index: 1; }
th {
  background: linear-gradient(180deg, #f8f9fb 0%, #f1f3f5 100%);
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f1f3;
  white-space: nowrap;
  font-size: 12px;
  transition: background 0.15s ease;
}
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { 
  background: linear-gradient(90deg, #f0f7ff 0%, #f8f9fb 100%);
}
.col-amount, .col-cost, .col-profit, .col-rate { text-align: right; }
td .profit-positive { color: var(--success); font-weight: 600; }
td .profit-negative { color: var(--danger); font-weight: 600; }
td .rate-positive { color: var(--success); }
td .rate-negative { color: var(--danger); }
.merged-tids {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
td .status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}
.author-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.author-badge.author-self {
  background: #d1fae5;
  color: #065f46;
}
.author-badge.author-daijin {
  background: #fef3c7;
  color: #92400e;
}
.author-badge.author-no-comm {
  background: #f1f5f9;
  color: #64748b;
}
.author-badge.author-alliance {
  background: #ede9fe;
  color: #6b21a8;
}
.status-交易完成, .status-已完成 { background: #ecfdf5; color: var(--success); }
.status-卖家已发货, .status-已发货 { background: #eff6ff; color: var(--primary); }
.status-已退款 { background: #fef2f2; color: var(--danger); }
.status-交易关闭, .status-交易作废 { background: #f1f5f9; color: var(--text-secondary); }
.status-待发货, .status-待打包, .status-待称重 { background: #fff7ed; color: #ea580c; }
.status-待付款 { background: #fefce8; color: #ca8a04; }
.status-待审核, .status-等待财审, .status-等待人工审核, .status-审核完成 { background: #f0f9ff; color: #0369a1; }
.status-待打印快递单, .status-待打印发货单 { background: #f5f3ff; color: #7c3aed; }
.status-UNKNOWN, .status-未知 { color: var(--text-muted); }
.status-FINISHED { background: #ecfdf5; color: var(--success); }

.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }


.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
}
.page-info, .page-info-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 8px;
  font-weight: 500;
}
.btn-page {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
}
.btn-page:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 2px 4px rgba(37,99,235,0.15);
}
.btn-page:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
  background: #f9fafb;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 90%;
  max-width: 1100px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-radius: 16px 16px 0 0;
}
.modal-header h3 { 
  font-size: 17px; 
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  width: 36px; height: 36px;
  border: none;
  background: #f1f5f9;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition);
}
.modal-close:hover { 
  background: #e2e5ea; 
  color: var(--text);
  transform: rotate(90deg);
}
.modal-body { padding: 24px; }

.detail-info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.detail-info-item {
  background: #f8f9fb;
  border-radius: 6px;
  padding: 10px 14px;
}
.detail-info-item .d-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 2px; }
.detail-info-item .d-value { font-size: 14px; font-weight: 600; }

.detail-section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 20px 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  color: var(--primary);
}

.detail-table-wrap { overflow-x: auto; margin-bottom: 16px; }
.detail-table-wrap table { min-width: 800px; }
.detail-table-wrap th { font-size: 12px; padding: 6px 8px; }
.detail-table-wrap td { font-size: 12px; padding: 5px 8px; }

.detail-cost-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.detail-cost-card {
  background: #f8f9fb;
  border-radius: 6px;
  padding: 10px 14px;
  text-align: center;
}
.detail-cost-card .cost-label { font-size: 11px; color: var(--text-secondary); }
.detail-cost-card .cost-value { font-size: 16px; font-weight: 700; margin-top: 2px; }
.detail-cost-card .cost-value.amount { color: var(--primary); }
.detail-cost-card .cost-value.cost { color: var(--warning); }
.detail-cost-card .cost-value.profit-pos { color: var(--success); }
.detail-cost-card .cost-value.profit-neg { color: var(--danger); }

.detail-summary-row {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(135deg, #eff6ff, #f0f9ff);
  border-radius: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.detail-summary-row .summary-item { font-size: 14px; }
.detail-summary-row .summary-item strong { font-size: 16px; }

/* Cost Config */
.cost-config-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 20px;
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  background: #f8f9fb;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.section-header:hover { background: #f0f2f5; }
.section-header h2 { font-size: 15px; font-weight: 600; }
.toggle-icon { font-size: 12px; color: var(--text-secondary); transition: transform .2s; }
.toggle-icon.open { transform: rotate(90deg); }

.cost-config-body { padding: 20px; }
.cost-form-panel {
  background: #f8f9fb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.cost-form-panel h4 { font-size: 14px; margin-bottom: 12px; }
.cost-form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.form-item { display: flex; flex-direction: column; gap: 4px; }
.form-item label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.form-item .input {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 8px;
  font-size: 13px;
  width: 100%;
}
.cost-form-actions { margin-top: 12px; display: flex; gap: 8px; }
.cost-list-panel h4 { font-size: 14px; margin-bottom: 8px; }
.cost-config-section .btn-sm { padding: 2px 8px; font-size: 12px; height: 26px; }

/* Responsive */
@media (max-width: 768px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-actions { align-items: stretch; flex-wrap: wrap; }
  .card-value { font-size: 20px; }
}

/* ========== 同步面板 ========== */
.btn-sync-toggle {
  background: none; border: 1px solid var(--border); cursor: pointer;
  font-size: 14px; color: var(--primary); font-family: inherit;
}
.btn-sync-toggle:hover { background: rgba(37,99,235,.08); }

.sync-panel {
  position: fixed; top: 0; right: 0; width: 440px; height: 100vh;
  background: var(--surface); box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 1000; overflow-y: auto; padding: 0;
  animation: slideInRight 0.25s ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.sync-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.sync-panel-header h3 { font-size: 16px; display: flex; align-items: center; gap: 6px; }
.sync-panel-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-muted); padding: 4px 8px; border-radius: var(--radius);
}
.sync-panel-close:hover { background: var(--bg); color: var(--text); }
.sync-panel-body { padding: 16px 24px 24px; }

.sync-info-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.sync-info-item {
  background: var(--bg); border-radius: var(--radius); padding: 12px;
  text-align: center;
}
.sync-info-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.sync-info-value { display: block; font-size: 14px; font-weight: 600; }

.sync-controls {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; background: var(--bg); border-radius: var(--radius);
  margin-bottom: 16px;
}
.sync-control-row { display: flex; align-items: center; gap: 10px; }
.sync-control-row label {
  font-size: 13px; color: var(--text-secondary); min-width: 65px; white-space: nowrap;
}
.sync-control-row select,
.sync-control-row input {
  flex: 1; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; background: var(--surface);
  font-family: inherit;
}

.sync-progress {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius); margin-bottom: 16px;
}
.sync-progress-icon { font-size: 24px; animation: spin 1.5s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.sync-progress-text { font-size: 13px; color: var(--primary); }

.sync-result { margin-bottom: 16px; }
.sync-result-box { padding: 16px; border-radius: var(--radius); }
.sync-result-success { background: #f0fdf4; border: 1px solid #bbf7d0; }
.sync-result-fail { background: #fef2f2; border: 1px solid #fecaca; }
.sync-result-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.sync-result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sync-result-item { display: flex; flex-direction: column; }
.sync-result-label { font-size: 12px; color: var(--text-muted); }
.sync-result-val { font-size: 18px; font-weight: 700; }

.sync-log-section { margin-top: 8px; }
.sync-log-section h4 { font-size: 14px; margin-bottom: 10px; color: var(--text-secondary); }
.sync-log-list { max-height: 300px; overflow-y: auto; }
.sync-log-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.sync-status-ok { color: var(--success); }
.sync-status-fail { color: var(--danger); }
.sync-status-running { color: var(--warning); }
.sync-log-time { color: var(--text-muted); min-width: 130px; }
.sync-log-detail { color: var(--text-secondary); flex: 1; }
