/* ═══════════════════════════════════════════
   KPI DASHBOARD — kpi.css
   Follows dispatcher.css conventions (.kpi- prefix, same color palette)
   ═══════════════════════════════════════════ */

/* ── Layout ── */
.kpi-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 110px);
  background: #f5f5f5;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ── Top Header ── */
.kpi-top-header {
  padding: 16px 24px 4px;
}

.kpi-main-heading {
  font-size: 22px;
  font-weight: 800;
  color: #034381;
  letter-spacing: -0.5px;
  margin: 0;
}

/* ── AI Impact Banner ── */
.kpi-impact-banner {
  background: #034381;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.kpi-impact-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #11afbf;
  white-space: nowrap;
}

.kpi-impact-stats {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  flex: 1;
}

.kpi-impact-stat {
  display: flex;
  flex-direction: column;
  padding: 0 20px;
  border-right: 1px solid rgba(255,255,255,0.15);
}

.kpi-impact-stat:first-child { padding-left: 0; }
.kpi-impact-stat:last-child { border-right: none; }

.kpi-impact-stat-label {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 2px;
}

.kpi-impact-stat-values {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.kpi-impact-before {
  color: rgba(255,255,255,0.55);
  text-decoration: line-through;
}

.kpi-impact-arrow { color: #11afbf; font-size: 12px; }

.kpi-impact-after { color: #fff; }

.kpi-impact-delta {
  font-size: 10px;
  font-weight: 700;
  background: rgba(17,175,191,0.25);
  color: #11afbf;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ── Section Nav ── */
.kpi-section-nav {
  display: flex;
  gap: 0;
  background: #fff;
  border-bottom: 2px solid #e0e0e0;
  padding: 0 24px;
}

.kpi-tab-btn {
  background: none;
  border: none;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.kpi-tab-btn:hover { color: #034381; }

.kpi-tab-btn.active {
  color: #034381;
}

.kpi-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: #11afbf;
  border-radius: 3px 3px 0 0;
}

/* ── Section Body ── */
.kpi-section { display: none; padding: 20px 24px 24px; }
.kpi-section.active { display: block; }

/* ── Grid ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.kpi-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ── Cards ── */
.kpi-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 18px 20px;
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.kpi-card-title {
  font-size: 12px;
  font-weight: 700;
  color: #034381;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-card-meta {
  font-size: 10px;
  color: #999;
}

/* ── Chart Containers ── */
.kpi-chart-wrap {
  position: relative;
  height: 200px;
}

.kpi-chart-wrap-sm {
  position: relative;
  height: 160px;
}

.kpi-chart-wrap-donut {
  position: relative;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.kpi-donut-value {
  font-size: 26px;
  font-weight: 700;
  color: #27ae60;
  line-height: 1;
}

.kpi-donut-label {
  font-size: 10px;
  color: #999;
  margin-top: 2px;
}

/* ── Period Toggle ── */
.kpi-period-toggle {
  display: flex;
  gap: 2px;
  background: #f5f5f5;
  border-radius: 6px;
  padding: 2px;
}

.kpi-period-btn {
  border: none;
  background: none;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.kpi-period-btn.active {
  background: #fff;
  color: #034381;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── Stat Values ── */
.kpi-big-stat {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.kpi-stat-sub {
  font-size: 11px;
  color: #999;
}

.kpi-green { color: #27ae60; }
.kpi-amber { color: #e67e22; }
.kpi-red   { color: #e74c3c; }
.kpi-navy  { color: #034381; }
.kpi-teal  { color: #11afbf; }

/* ── Comparison Row (AI vs Manual) ── */
.kpi-compare-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.kpi-compare-label {
  font-size: 11px;
  font-weight: 600;
  width: 60px;
  flex-shrink: 0;
}

.kpi-compare-bar-wrap {
  flex: 1;
  height: 20px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}

.kpi-compare-bar {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  transition: width 0.6s ease;
}

.kpi-compare-bar.ai   { background: #11afbf; }
.kpi-compare-bar.manual { background: #034381; }

/* ── Legend Pills ── */
.kpi-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.kpi-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #666;
}

.kpi-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Aging Table ── */
.kpi-aging-legend {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.kpi-aging-bucket {
  text-align: center;
  padding: 8px;
  border-radius: 6px;
  font-size: 11px;
}

.kpi-aging-bucket .amount {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.kpi-aging-bucket.fresh  { background: #e8f5e9; color: #27ae60; }
.kpi-aging-bucket.warn   { background: #fff8e1; color: #e67e22; }
.kpi-aging-bucket.urgent { background: #fff3e0; color: #e65100; }
.kpi-aging-bucket.overdue{ background: #ffebee; color: #e74c3c; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .kpi-impact-stats { gap: 0; }
  .kpi-impact-stat { padding: 4px 12px; border-right: none; border-bottom: 1px solid rgba(255,255,255,0.1); }
  .kpi-section-nav { padding: 0 12px; overflow-x: auto; }
  .kpi-section { padding: 14px 12px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-grid-2 { grid-template-columns: 1fr; }
  .kpi-aging-legend { grid-template-columns: repeat(2, 1fr); }
}
