/* ===== KPI Performance Page ===== */

.kpi-page {
  width: 100%;
}

/* Tab bar */
.kpi-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 2px solid #f0f0f0;
  padding-bottom: 0;
}
.kpi-tab {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.kpi-tab:hover {
  color: var(--primary);
}
.kpi-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Toolbar */
.kpi-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: #fafbfc;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0,0,0,0.04);
}
.kpi-toolbar input[type="month"] {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  transition: var(--transition);
}
.kpi-toolbar input[type="month"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24,144,255,0.1);
}
.kpi-toolbar .toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Summary cards */
.kpi-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-summary-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0,0,0,0.04);
  padding: 20px 24px;
  transition: var(--transition);
}
.kpi-summary-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.kpi-summary-card .card-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.kpi-summary-card .card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.kpi-summary-card .card-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* KPI Table */
.kpi-table {
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.kpi-table th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;

  padding: 8px 6px;
  text-align: center;
  border-bottom: 2px solid #f0f0f0;
  white-space: nowrap;
}
.kpi-table td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

/* KPI 操作列 */
.kpi-table td:last-child { text-align: center; }
.kpi-table .actions { display: flex; justify-content: center; gap: 6px; width: 100%; }
/* 操作列固定右侧 */
.kpi-table th:last-child,
.kpi-table td:last-child {
  position: sticky;
  right: 0;
  background: #fff;
  z-index: 2;
  box-shadow: -2px 0 4px rgba(0,0,0,0.06);
}
.kpi-table thead th:last-child {
  background: #fafbfc;
  z-index: 3;
}
.kpi-table td.editable-cell {
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}
.kpi-table td.editable-cell:hover {
  background: #e8f0fe;
  outline: 2px dashed #4285f4;
  outline-offset: -2px;
}
.kpi-table td.editable-cell.editing {
  padding: 0;
  background: #fff;
  outline: 2px solid #4285f4;
  outline-offset: -2px;
}
.inline-edit-input {
  width: 100%;
  border: none;
  outline: none;
  padding: 8px 6px;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  background: transparent;
  box-sizing: border-box;
}
.inline-edit-input.error {
  border: 2px solid #f44336;
  background: #fff0f0;
}
.kpi-table tbody tr:nth-child(even) {
  background: #fafbfc;
}
.kpi-table tbody tr:hover {
  background: #e8f4ff;
}
.kpi-table .editor-name {
  font-weight: 600;
  color: var(--text);
}

/* Rate coloring */
.rate-good { color: var(--success); font-weight: 600; }
.rate-warn { color: var(--warning); font-weight: 600; }
.rate-bad { color: var(--danger); font-weight: 600; }

/* Rate bar */
.kpi-rate-bar {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  width: 60px;
  height: 6px;
  background: #f0f0f0;
  border-radius: 3px;
  overflow: hidden;
}
.kpi-rate-bar .bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.kpi-rate-bar .bar-fill.fill-good { background: linear-gradient(90deg, #52c41a, #73d13d); }
.kpi-rate-bar .bar-fill.fill-warn { background: linear-gradient(90deg, #faad14, #ffc53d); }
.kpi-rate-bar .bar-fill.fill-bad { background: linear-gradient(90deg, #ff4d4f, #ff7875); }

/* Status badges */
.kpi-status-draft {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: #f5f5f5;
  color: #999;
}
.kpi-status-confirmed {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--success-light);
  color: var(--success);
}

/* Detail page */
.kpi-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}
.kpi-detail-section {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0,0,0,0.04);
  overflow: hidden;
}
.kpi-detail-section.full-width {
  grid-column: 1 / -1;
}
.kpi-detail-section .section-title {
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-detail-section .section-body {
  padding: 20px;
}

/* Score table */
.kpi-score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.kpi-score-table th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 2px solid #f0f0f0;
}
.kpi-score-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
}
.kpi-score-table tr:last-child td {
  border-bottom: none;
  font-weight: 700;
  background: var(--primary-light);
}
.kpi-score-table .dim-label {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-score-table .dim-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.kpi-score-table .dim-dot.dim-output { background: var(--primary); }
.kpi-score-table .dim-dot.dim-ontime { background: var(--success); }
.kpi-score-table .dim-dot.dim-quality { background: var(--warning); }
.kpi-score-table .dim-dot.dim-total { background: #722ed1; }

/* Final calculation card */
.kpi-final-calc {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
}
.kpi-final-calc .calc-label {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 8px;
}
.kpi-final-calc .calc-amount {
  font-size: 36px;
  font-weight: 800;
}
.kpi-final-calc .calc-breakdown {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 8px;
  line-height: 1.8;
}

/* Tier editor */
.kpi-tiers-editor {
  margin-bottom: 24px;
}
.kpi-tiers-editor h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-tier-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding: 10px 14px;
  background: #fafbfc;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.04);
}
.kpi-tier-row label {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 70px;
  flex-shrink: 0;
}
.kpi-tier-row input {
  width: 80px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
}
.kpi-tier-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24,144,255,0.1);
}
.kpi-tier-row .tier-range {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Config section */
.kpi-config-section {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0,0,0,0.04);
  padding: 24px;
  margin-bottom: 20px;
}
.kpi-config-section h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.kpi-config-grid .config-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-config-grid .config-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.kpi-config-grid .config-field input {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.kpi-config-grid .config-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24,144,255,0.1);
}

/* Editor selector for personal view */
.kpi-editor-select {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  min-width: 180px;
  background: #fff;
}
.kpi-editor-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24,144,255,0.1);
}

/* Orders list in detail */
.kpi-orders-list {
  max-height: 400px;
  overflow-y: auto;
}
.kpi-orders-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.kpi-orders-list th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
  position: sticky;
  top: 0;
}
.kpi-orders-list td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}

/* Overdue row hover */
.overdue-row:hover { background: #f5f8ff; }
.overdue-row { transition: background 0.15s; }

/* Overdue detail panel */
.overdue-detail-panel {
  background: #f7f8fa;
  border: 1px solid #e8eaed;
  border-radius: 6px;
  padding: 16px 20px;
  margin: 8px 12px;
}
.overdue-detail-panel .detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px 24px;
}
.overdue-detail-panel .detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.overdue-detail-panel .detail-label {
  font-size: 11px;
  color: #999;
  font-weight: 500;
}
.overdue-detail-panel .detail-value {
  font-size: 13px;
  color: #333;
  word-break: break-all;
}
.overdue-detail-panel .detail-full {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #e0e0e0;
}
.overdue-detail-panel .detail-full .detail-label {
  font-size: 11px;
  color: #999;
  font-weight: 500;
  margin-bottom: 4px;
  display: block;
}
.overdue-detail-panel .detail-full .detail-value {
  font-size: 13px;
  color: #333;
  white-space: pre-wrap;
  word-break: break-all;
}
.overdue-detail-panel .detail-full a {
  color: #1890ff;
  text-decoration: none;
}
.overdue-detail-panel .detail-full a:hover {
  text-decoration: underline;
}

/* Formula trigger (？ icon) */
.kpi-formula-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e6f0ff;
  color: #1890ff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 4px;
  vertical-align: middle;
  user-select: none;
  transition: background 0.15s;
}
.kpi-formula-trigger:hover {
  background: #bae0ff;
}

/* Formula tooltip (hover) */
.kpi-formula-tip {
  display: none;
  position: fixed;
  z-index: 9999;
  background: #333;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 320px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Formula expand row */
.formula-expand {
  padding: 0 !important;
  border: none !important;
}
.formula-box {
  background: #fafbfc;
  border: 1px solid #e8eaed;
  border-radius: 6px;
  padding: 14px 18px;
  margin: 6px 0;
}
.formula-title {
  font-size: 13px;
  font-weight: 600;
  color: #1890ff;
  margin-bottom: 8px;
}
.formula-line {
  font-size: 13px;
  color: #333;
  font-weight: 500;
  margin-bottom: 4px;
}
.formula-detail {
  font-size: 12px;
  color: #666;
  margin-left: 16px;
  line-height: 1.6;
}

/* Empty state */
.kpi-empty {
  text-align: center;
  padding: 60px 20px;
  color: #bbb;
}
.kpi-empty .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.kpi-empty .empty-text {
  font-size: 14px;
  margin-bottom: 8px;
}
.kpi-empty .empty-hint {
  font-size: 12px;
  color: #ccc;
}

/* Back button */
.kpi-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 16px;
}
.kpi-back-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* Responsive */
@media (max-width: 768px) {
  .kpi-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .kpi-toolbar .toolbar-right {
    margin-left: 0;
    justify-content: flex-start;
  }
  .kpi-summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .kpi-detail-grid {
    grid-template-columns: 1fr;
  }
  .kpi-config-grid {
    grid-template-columns: 1fr;
  }
  .kpi-table {
    font-size: 11px;
  }
  .kpi-table th, .kpi-table td {
    padding: 8px 6px;
  }
  .kpi-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* === KPI Edit Modal === */
.kpi-modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  animation: kpiFadeIn .2s ease;
}
@keyframes kpiFadeIn { from { opacity: 0; } to { opacity: 1; } }

.kpi-modal-card {
  background: var(--card-bg, #fff); border-radius: 12px;
  width: 560px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18); padding: 0;
  animation: kpiSlideUp .25s ease;
}
@keyframes kpiSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.kpi-modal-header {
  padding: 20px 24px 12px; border-bottom: 1px solid var(--border-color, #f0f0f0);
}
.kpi-modal-header h4 { margin: 0; font-size: 17px; font-weight: 600; color: var(--text, #1a1a1a); }
.kpi-modal-sub { font-size: 12px; color: var(--text-secondary, #999); }

.kpi-modal-body {
  padding: 16px 24px; display: flex; flex-direction: column; gap: 12px;
}

.kpi-edit-row {
  display: flex; gap: 14px;
}
.kpi-edit-field {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
}
.kpi-edit-field label {
  font-size: 12px; font-weight: 500; color: var(--text-secondary, #888);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.kpi-edit-field .kpi-edit-input,
.kpi-edit-field input[type="number"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-color, #d9d9d9);
  border-radius: 6px; font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
  background: var(--input-bg, #fff); color: var(--text, #1a1a1a);
}
.kpi-edit-field .kpi-edit-input:focus,
.kpi-edit-field input[type="number"]:focus {
  border-color: #4f8cff; box-shadow: 0 0 0 2px rgba(79,140,255,0.15);
}

.kpi-modal-footer {
  padding: 12px 24px 16px; display: flex; gap: 10px; justify-content: flex-end;
  border-top: 1px solid var(--border-color, #f0f0f0);
}
