.dashboard {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 16px;
  padding-bottom: 10px;
  animation: fadeUp 260ms var(--ease) both;
}

.dashboard-loading-state {
  min-height: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  position: relative;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  border-left: 3px solid var(--accent);
  animation: dashboardItemIn 520ms var(--ease) both;
  animation-delay: var(--delay, 0ms);
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.kpi-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.kpi-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.kpi-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 10%, white);
  color: var(--accent);
  font-size: 14px;
  flex: 0 0 auto;
  animation: iconPop 560ms var(--ease) both;
  animation-delay: calc(var(--delay, 0ms) + 100ms);
}

.kpi-label {
  color: #64748b;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  display: block;
  min-height: 22px;
  color: #0f172a;
  font-size: clamp(16px, 1.2vw, 20px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-bottom: 6px;
  letter-spacing: 0;
}

.kpi-trend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
}

.kpi-badge.up {
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
}

.kpi-badge.down {
  background: rgba(var(--success-rgb), 0.08);
  color: var(--success);
}

.kpi-badge .mdi {
  font-size: 11px;
}

.kpi-delta {
  color: #94a3b8;
  font-size: 10px;
  white-space: nowrap;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 24px;
}

.dashboard-card {
  padding: 20px;
  transition: box-shadow 200ms ease, transform 200ms ease;
  animation: dashboardItemIn 560ms var(--ease) both;
}

.top-grid .dashboard-card:nth-child(1) { animation-delay: 80ms; }
.top-grid .dashboard-card:nth-child(2) { animation-delay: 150ms; }
.top-grid .dashboard-card:nth-child(3) { animation-delay: 220ms; }
.bottom-grid .dashboard-card:nth-child(1) { animation-delay: 290ms; }
.bottom-grid .dashboard-card:nth-child(2) { animation-delay: 360ms; }
.bottom-grid .dashboard-card:nth-child(3) { animation-delay: 430ms; }
.bottom-grid .dashboard-card:nth-child(4) { animation-delay: 500ms; }

.dashboard-card:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.trend-panel {
  grid-column: span 6;
}

.trend-count-panel,
.donut-panel,
.model-panel,
.feedback-panel {
  grid-column: span 3;
}

.rank-panel,
.employee-rank-panel,
.top-claim-panel,
.bottleneck-panel {
  grid-column: span 6;
}

.budget-metrics-panel {
  grid-column: span 6;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.card-head h3 {
  color: #1e293b;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.card-head .mdi {
  color: #94a3b8;
  font-size: 12px;
  vertical-align: 1px;
}

.card-select {
  width: 110px;
}

.card-range-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(var(--theme-primary-rgb, 58, 124, 165), .18);
  border-radius: 4px;
  background: rgba(var(--theme-primary-rgb, 58, 124, 165), .07);
  color: var(--theme-primary-active);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.panel-note {
  margin-top: 8px;
  color: #64748b;
  font-size: 12px;
  text-align: center;
}

.card-subtitle {
  margin: -8px 0 12px;
  color: #64748b;
  font-size: 12px;
  font-weight: 550;
  line-height: 1.55;
}

.system-observability-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(320px, .9fr) minmax(320px, .9fr);
  grid-template-areas:
    "agent agent agent"
    "token token token"
    "accuracy accuracy side"
    "tools tools side";
  gap: 18px;
}

.system-agent-ratio-panel {
  grid-area: agent;
}

.system-token-pie-panel {
  grid-area: token;
}

.system-token-panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, .95fr);
  gap: 18px;
  align-items: stretch;
}

.system-accuracy-panel {
  grid-area: accuracy;
}

.system-tool-detail-panel {
  grid-area: tools;
}

.system-side-stack {
  grid-area: side;
  display: grid;
  gap: 18px;
  align-content: start;
}

.system-side-stack .dashboard-card {
  grid-column: auto;
}

.system-side-card {
  padding: 16px;
}

.system-side-card .card-head {
  margin-bottom: 12px;
}

.system-side-card .card-subtitle {
  margin: -6px 0 8px;
  font-size: 11px;
}

.duration-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.duration-summary strong {
  display: block;
  color: #0f172a;
  font-size: 26px;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
}

.duration-summary span {
  display: block;
  margin-top: 5px;
  color: #64748b;
  font-size: 11px;
  font-weight: 650;
}

.duration-summary em {
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(var(--success-rgb), 0.10);
  color: var(--success);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.duration-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.duration-meta span {
  padding: 7px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fbfdff;
  color: #475569;
  font-size: 11px;
  font-weight: 750;
}

.duration-bars {
  display: grid;
  gap: 9px;
}

.duration-bar-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
}

.duration-bar-row span,
.duration-bar-row strong {
  color: #475569;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.duration-bar-row strong {
  color: #0f172a;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.duration-bar-row i {
  height: 7px;
  overflow: hidden;
  border-radius: 4px;
  background: #eef2f7;
}

.duration-bar-row b {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.system-tool-table {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.system-tool-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fbfdff;
}

.system-tool-row-head,
.system-tool-row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.system-tool-row-head strong {
  min-width: 0;
  color: #1e293b;
  font-size: 13px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-tool-row-head span {
  color: #0f172a;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.system-tool-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: #eef2f7;
}

.system-tool-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.system-tool-row-meta {
  color: #64748b;
  font-size: 11px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.bottleneck-panel,
.budget-metrics-panel,
.top-claim-panel,
.model-panel,
.feedback-panel {
  display: flex;
  flex-direction: column;
}

.bottleneck-panel .text-link {
  margin-top: auto;
}

.feedback-list {
  flex: 1;
  display: grid;
  gap: 12px;
  align-content: center;
}

.feedback-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.feedback-row:last-child {
  border-bottom: 0;
}

.feedback-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: #eef2f7;
  color: #64748b;
  font-size: 16px;
  flex: 0 0 auto;
}

.feedback-row.success .feedback-icon {
  background: rgba(var(--success-rgb), .10);
  color: var(--success);
}

.feedback-row.danger .feedback-icon {
  background: rgba(239, 68, 68, .10);
  color: #dc2626;
}

.feedback-row.info .feedback-icon {
  background: rgba(var(--theme-primary-rgb, 58, 124, 165), .10);
  color: var(--theme-primary-active);
}

.feedback-row strong {
  display: block;
  color: #1e293b;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.feedback-row span:not(.feedback-icon) {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-size: 12px;
}

.budget-metrics-content {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(190px, .86fr) minmax(0, 1.14fr);
  gap: 16px;
  align-items: stretch;
  min-height: 0;
}

.budget-gauge-block {
  min-width: 0;
  display: grid;
  place-items: center;
  padding-right: 16px;
  border-right: 1px solid #f1f5f9;
}

.budget-gauge-block :deep(.gauge-chart) {
  width: 100%;
  min-height: 210px;
}

.budget-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-content: stretch;
}

.budget-metric-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  min-height: 68px;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #f8fafc;
  animation: listRowIn 460ms var(--ease) both;
  animation-delay: var(--delay, 0ms);
}

.budget-metric-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: rgba(var(--theme-primary-rgb, 58, 124, 165), .10);
  color: var(--theme-primary-active);
  flex: 0 0 auto;
}

.budget-metric-item div {
  min-width: 0;
}

.budget-metric-item span:not(.budget-metric-icon),
.budget-metric-item strong,
.budget-metric-item em {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: normal;
}

.budget-metric-item span:not(.budget-metric-icon) {
  color: #64748b;
  font-size: 11px;
  font-weight: 650;
}

.budget-metric-item strong {
  margin-top: 5px;
  color: #0f172a;
  font-size: 15px;
  font-weight: 850;
}

.budget-metric-item em {
  margin-top: 5px;
  color: #94a3b8;
  font-size: 11px;
}

.budget-metric-item.warning {
  border-color: rgba(245, 158, 11, .26);
  background: rgba(245, 158, 11, .06);
}

.budget-metric-item.warning .budget-metric-icon {
  background: rgba(245, 158, 11, .12);
  color: #b45309;
}

.budget-metric-item.danger {
  border-color: rgba(239, 68, 68, .26);
  background: rgba(239, 68, 68, .06);
}

.budget-metric-item.danger .budget-metric-icon {
  background: rgba(239, 68, 68, .12);
  color: #dc2626;
}

.budget-metric-item.success .budget-metric-icon {
  background: rgba(var(--success-rgb), .10);
  color: var(--success);
}

.top-claim-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.top-claim-split {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, .92fr) minmax(0, 1.08fr);
  gap: 18px;
  align-items: stretch;
  min-height: 0;
}

.department-employee-mix {
  min-width: 0;
  padding-right: 18px;
  border-right: 1px solid #f1f5f9;
}

.department-employee-mix :deep(.donut-chart) {
  min-height: 100%;
}

.department-employee-mix :deep(.donut-body) {
  height: 150px;
}

.department-employee-mix :deep(.donut-legend) {
  grid-template-columns: 1fr;
  gap: 7px;
}

.department-employee-mix :deep(.legend-name) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-claim-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.top-claim-row:last-child {
  border-bottom: 0;
}

.top-claim-row div {
  min-width: 0;
}

.top-claim-row div:last-child {
  text-align: right;
}

.top-claim-row strong,
.top-claim-row span {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-claim-row strong {
  color: #1e293b;
  font-size: 13px;
  font-weight: 800;
}

.top-claim-row span {
  margin-top: 4px;
  color: #64748b;
  font-size: 11px;
}

.bottleneck-list {
  flex: 1;
  display: grid;
  gap: 16px;
  align-content: center;
}

.bottleneck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: listRowIn 460ms var(--ease) both;
  animation-delay: var(--delay, 0ms);
}

.reviewer {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.reviewer-avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--theme-primary-light-9);
  color: var(--theme-primary-active);
  font-size: 13px;
  font-weight: 700;
  flex: 0 0 auto;
}

.reviewer strong,
.reviewer-stats strong {
  display: block;
  color: #1e293b;
  font-size: 14px;
  font-weight: 500;
}

.reviewer span,
.reviewer-stats span {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-size: 12px;
}

.reviewer-stats {
  text-align: right;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status-tag.danger {
  background: rgba(239,68,68,.10);
  color: #ef4444;
}

.status-tag.warning {
  background: rgba(245,158,11,.10);
  color: #f59e0b;
}

.status-tag.success {
  background: rgba(var(--success-rgb), .10);
  color: var(--success);
}

.text-link {
  width: 100%;
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 0;
  border: 0;
  border-top: 1px solid #f1f5f9;
  background: transparent;
  color: var(--theme-primary);
  font-size: 14px;
}

@keyframes dashboardItemIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes listRowIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes iconPop {
  0% {
    opacity: 0;
    transform: scale(.82);
  }
  70% {
    opacity: 1;
    transform: scale(1.04);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kpi-card,
  .dashboard-card,
  .budget-metric-item,
  .bottleneck-row {
    animation: none;
  }
}

@media (max-width: 1320px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .system-observability-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "agent agent"
      "token token"
      "accuracy side"
      "tools side";
  }

  .trend-panel,
  .trend-count-panel,
  .rank-panel,
  .employee-rank-panel,
  .top-claim-panel {
    grid-column: span 12;
  }

  .donut-panel,
  .bottleneck-panel,
  .model-panel,
  .feedback-panel {
    grid-column: span 6;
  }

  .budget-metrics-panel {
    grid-column: span 12;
  }
}

@media (max-width: 1440px) {
  .dashboard {
    gap: 14px;
  }

  .kpi-grid {
    gap: 10px;
  }

  .content-grid {
    gap: 18px;
  }

  .dashboard-card {
    padding: 18px;
  }

  .card-head {
    margin-bottom: 14px;
  }

  .card-head h3 {
    font-size: 15px;
  }
}

@media (max-width: 860px) {
  .kpi-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .system-observability-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "agent"
      "token"
      "accuracy"
      "tools"
      "side";
  }

  .system-tool-table {
    grid-template-columns: 1fr;
  }

  .system-token-panel-grid {
    grid-template-columns: 1fr;
  }

  .trend-panel,
  .trend-count-panel,
  .rank-panel,
  .employee-rank-panel,
  .top-claim-panel,
  .donut-panel,
  .budget-metrics-panel,
  .bottleneck-panel,
  .model-panel,
  .feedback-panel {
    grid-column: span 1;
  }

  .card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .donut-wrap {
    grid-template-columns: 1fr;
  }

  .rank-row {
    grid-template-columns: 24px 64px minmax(0, 1fr);
  }

  .top-claim-split {
    grid-template-columns: 1fr;
  }

  .department-employee-mix {
    padding-right: 0;
    padding-bottom: 14px;
    border-right: 0;
    border-bottom: 1px solid #f1f5f9;
  }

  .budget-metric-grid {
    grid-template-columns: 1fr;
  }

  .budget-metrics-content {
    grid-template-columns: 1fr;
  }

  .budget-gauge-block {
    padding-right: 0;
    padding-bottom: 14px;
    border-right: 0;
    border-bottom: 1px solid #f1f5f9;
  }

  .rank-value {
    grid-column: 2 / -1;
  }

  .budget-summary {
    grid-template-columns: 1fr;
  }
}
