/* ---- DASHBOARD PAGE ---- */

/* KPI Cards Row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  padding: 24px;
}

.kpi-card {
  background: var(--color-white);
  border: 1px solid var(--color-gray-100);
  border-radius: var(--radius);
  padding: 24px;
}

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

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon svg {
  width: 20px;
  height: 20px;
}

.kpi-icon-ships {
  background: #eff6ff;
  color: #2554E8;
}

.kpi-icon-visits {
  background: #f5f3ff;
  color: #7c3aed;
}

.kpi-icon-active {
  background: #f0fdf4;
  color: #16a34a;
}

.kpi-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
}

.kpi-badge-up {
  background: #f0fdf4;
  color: #16a34a;
}

.kpi-badge-live {
  background: #f0fdf4;
  color: #16a34a;
}

.kpi-subtitle {
  font-size: 13px;
  color: var(--color-text-light);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
  margin-bottom: 4px;
}

.kpi-meta {
  font-size: 12px;
  color: var(--color-text-light);
  margin-bottom: 16px;
}

.kpi-sparkline {
  height: 32px;
  margin-bottom: 16px;
}

.kpi-sparkline svg {
  width: 100%;
  height: 100%;
}

.kpi-countries {
  display: flex;
  gap: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--color-gray-100);
}

.kpi-country-label {
  display: block;
  font-size: 12px;
  color: var(--color-text-light);
  margin-bottom: 2px;
}

.kpi-country-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

/* Charts Row */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 0 24px 24px;
}

.charts-row:has(.chart-card-wide) {
  grid-template-columns: 3fr 2fr;
}

.chart-card {
  background: var(--color-white);
  border: 1px solid var(--color-gray-100);
  border-radius: var(--radius);
  padding: 24px;
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.chart-header h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.chart-subtitle {
  font-size: 13px;
  color: var(--color-text-light);
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chart-control-label {
  font-size: 13px;
  color: var(--color-text-light);
  padding: 4px 12px;
  border: 1px solid var(--color-gray-100);
  border-radius: 4px;
  white-space: nowrap;
}

.chart-control-label strong {
  color: var(--color-text);
}

.chart-view-toggle {
  display: flex;
  border: 1px solid var(--color-gray-100);
  border-radius: 4px;
  overflow: hidden;
}

.chart-view-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-light);
}

.chart-view-btn.active {
  background: var(--color-gray-50);
  color: var(--color-accent);
}

.chart-view-btn svg {
  width: 14px;
  height: 14px;
}

/* Horizontal Bar Chart */
.bar-chart-horizontal {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.bar-label {
  width: 180px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--color-text);
  text-align: right;
}

.bar-track {
  flex: 1;
  display: flex;
  height: 24px;
  border-radius: 3px;
  overflow: hidden;
  gap: 2px;
}

.bar-segment {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.bar-0-83 { background: #06b6d4; }
.bar-84-108 { background: #22d3ee; }
.bar-109-133 { background: #7c3aed; }
.bar-133plus { background: #2554E8; }

.bar-axis {
  display: flex;
  justify-content: space-between;
  margin-left: 196px;
  font-size: 11px;
  color: var(--color-text-light);
  margin-top: 4px;
}

.bar-legend {
  display: flex;
  gap: 20px;
  margin-left: 196px;
  margin-top: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-text-light);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* Stacked Bar Chart */
.stacked-chart {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stacked-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stacked-label {
  width: 80px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--color-text);
  text-align: right;
}

.stacked-track {
  flex: 1;
  display: flex;
  height: 36px;
  border-radius: 3px;
  overflow: hidden;
}

.stacked-seg {
  height: 100%;
  transition: width 0.3s ease;
}

.seg-steel { background: #2dd4bf; }
.seg-building { background: #a78bfa; }
.seg-recyclables { background: #818cf8; }
.seg-containers { background: #60a5fa; }
.seg-other { background: #94a3b8; }

.stacked-legend {
  margin-left: 92px;
  flex-wrap: wrap;
  gap: 12px;
}

/* Time Series Charts */
.time-chart {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.time-chart-area {
  display: flex;
  gap: 12px;
  height: 200px;
}

.time-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-text-light);
  text-align: right;
  width: 30px;
  flex-shrink: 0;
  padding: 4px 0;
}

.time-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  border-bottom: 1px solid var(--color-gray-100);
  padding-bottom: 24px;
  position: relative;
}

.time-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.time-bar {
  width: 70%;
  background: #60a5fa;
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
}

.time-bar-label {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 8px;
  position: absolute;
  bottom: 0;
}

.time-bar-group:nth-child(1) .time-bar-label { left: calc((100% / 7) * 0 + (100% / 14)); }
.time-bar-group:nth-child(2) .time-bar-label { left: calc((100% / 7) * 1 + (100% / 14)); }
.time-bar-group:nth-child(3) .time-bar-label { left: calc((100% / 7) * 2 + (100% / 14)); }
.time-bar-group:nth-child(4) .time-bar-label { left: calc((100% / 7) * 3 + (100% / 14)); }
.time-bar-group:nth-child(5) .time-bar-label { left: calc((100% / 7) * 4 + (100% / 14)); }
.time-bar-group:nth-child(6) .time-bar-label { left: calc((100% / 7) * 5 + (100% / 14)); }
.time-bar-group:nth-child(7) .time-bar-label { left: calc((100% / 7) * 6 + (100% / 14)); }

/* Line Chart */
.line-chart-area {
  height: 200px;
}

.line-chart-canvas {
  flex: 1;
  position: relative;
  border-bottom: 1px solid var(--color-gray-100);
  padding-bottom: 24px;
}

.line-chart-canvas svg {
  width: 100%;
  height: calc(100% - 24px);
}

.line-chart-x-axis {
  display: flex;
  justify-content: space-between;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 12px;
  color: var(--color-text-light);
}

/* Responsive */
@media (max-width: 1024px) {
  .kpi-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 16px;
  }

  .charts-row,
  .charts-row:has(.chart-card-wide) {
    grid-template-columns: 1fr;
    padding: 0 16px 16px;
  }

  .bar-label {
    width: 140px;
  }

  .bar-axis,
  .bar-legend {
    margin-left: 156px;
  }
}

@media (max-width: 768px) {
  .kpi-row {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .kpi-value {
    font-size: 28px;
  }

  .charts-row {
    padding: 0 12px 12px;
  }

  .chart-header {
    flex-direction: column;
    gap: 12px;
  }

  .chart-controls {
    flex-wrap: wrap;
  }

  .bar-label {
    width: 100px;
    font-size: 12px;
  }

  .bar-axis,
  .bar-legend {
    margin-left: 116px;
  }

  .stacked-label {
    width: 60px;
    font-size: 12px;
  }

  .stacked-legend {
    margin-left: 72px;
  }

  .time-chart-area {
    height: 160px;
  }
}
