/**
 * Card styles - Cards grid, card stacks, crop cards, carousel
 */

/* --------------------------------------------------------------------------
   Cards Grid
   -------------------------------------------------------------------------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

/* --------------------------------------------------------------------------
   Card Stack (grouped cycles)
   -------------------------------------------------------------------------- */

/* Card stack container - holds scroll area + dots */
.card-stack-container {
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Direct crop-card child stretches to fill container height */
.card-stack-container > .crop-card {
  flex: 1;
}

/* Card stacks - horizontal carousel */
.card-stack {
  position: relative;
  display: flex;
  flex-direction: row;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
}

.card-stack::-webkit-scrollbar {
  display: none;
}

.stack-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--primary-600);
  color: white;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  z-index: 10;
  box-shadow: var(--shadow-md);
  display: none; /* Hidden - using dots instead */
}

.crop-card.stacked {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Carousel pagination dots */
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 0.75rem 0;
}

.carousel-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-dot::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-300);
  transition: background 0.2s ease;
}

.carousel-dot.active::after {
  background: var(--primary-500);
}

/* Placeholder dots for single cards - invisible but takes space for consistent height */
.carousel-dots-placeholder {
  visibility: hidden;
}

/* --------------------------------------------------------------------------
   Crop Card
   -------------------------------------------------------------------------- */
.crop-card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: visible;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}

.crop-card:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.crop-card-header {
  padding: 1.25rem 1.25rem 0;
}

.crop-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.crop-info {
  flex: 1;
}

.crop-name {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--gray-900);
  margin-bottom: 0.125rem;
}

.crop-farm {
  color: var(--primary-600);
  font-size: 0.875rem;
  font-weight: 500;
}

.crop-card-cycle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.8125rem;
  color: var(--gray-600);
}

.crop-card-body {
  padding: 0 1.25rem;
  flex: 1;
}

.crop-details {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.crop-detail {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.8125rem;
  color: var(--gray-600);
}

.crop-detail-icon {
  width: 16px;
  height: 16px;
  color: var(--primary-500);
  flex-shrink: 0;
}

.crop-detail-label {
  color: var(--gray-500);
  flex-shrink: 0;
}

.crop-detail-value {
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  text-align: right;
}

.crop-detail-previous {
  font-size: 0.75rem;
  color: var(--gray-400);
  text-align: right;
  margin-left: auto;
  margin-top: 0.125rem;
}

.crop-metric-row .crop-detail-value {
  font-weight: 700;
  color: var(--gray-900);
}

.crop-metrics {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--gray-100);
  position: relative;
  min-height: 8.5rem;
}

.crop-metric-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.8125rem;
}

.crop-metric-row .crop-detail-icon {
  color: var(--amber-500);
}

.btn-unit-toggle-card {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-600);
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-unit-toggle-card:hover {
  background: var(--primary-100);
  border-color: var(--primary-400);
  color: var(--primary-700);
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.15);
}

.btn-unit-toggle-card:active {
  transform: scale(0.97);
}

/* Price stats - two-line layout */
.metric-price-stats {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8125rem;
}

.price-main-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.metric-price-stats .crop-detail-icon {
  width: 16px;
  height: 16px;
  color: var(--amber-500);
}

.metric-price-stats .crop-detail-label {
  color: var(--gray-500);
}

.metric-price-stats .crop-detail-value {
  margin-left: auto;
  font-weight: 700;
  color: var(--gray-900);
}

.price-comparison-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: 24px;  /* align with text after icon */
}

.price-comparison {
  font-size: 0.75rem;
  font-weight: 600;
}

.price-comparison.positive {
  color: var(--primary-600);
}

.price-comparison.negative {
  color: var(--red-600);
}

.price-comparison.neutral {
  color: var(--gray-500);
}

.price-previous {
  font-size: 0.6875rem;
  color: var(--gray-400);
}

/* Preview values on hover - smooth transition */
.crop-metric-row .crop-detail-value {
  transition: color 0.2s ease, transform 0.2s ease;
}

.crop-metric-row .crop-detail-value.preview-active {
  color: var(--primary-600);
  transform: scale(1.05);
}

/* Clickable production row with breakdown */
.crop-metric-row.has-breakdown {
  cursor: pointer;
  border-radius: var(--radius);
  margin: -0.25rem;
  padding: 0.25rem;
  transition: background 0.15s ease;
}

.crop-metric-row.has-breakdown:hover {
  background: var(--gray-100);
}

/* Production breakdown panel */
.production-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding-left: calc(16px + 0.625rem);
  margin-top: -0.25rem;
  margin-bottom: 0.25rem;
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--gray-500);
}

.breakdown-label {
  color: var(--gray-400);
}

.breakdown-pct {
  margin-left: auto;
  width: 3rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gray-400);
  font-size: 0.6875rem;
}

.breakdown-value {
  width: 4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gray-600);
}

.breakdown-total-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--gray-200);
}

.breakdown-total-row .breakdown-label {
  color: var(--gray-500);
  font-weight: 500;
}

.breakdown-total-row .breakdown-value {
  margin-left: auto;
  color: var(--gray-700);
  font-weight: 600;
}

.breakdown-total-row.clickable {
  cursor: pointer;
  border-radius: 0.25rem;
  margin-left: -0.25rem;
  margin-right: -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  transition: background-color 0.15s ease;
}

.breakdown-total-row.clickable .breakdown-label {
  font-weight: 600;
  color: var(--gray-700);
}

.breakdown-total-row.clickable .breakdown-value {
  color: var(--primary-600, #2563eb);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.breakdown-total-row.clickable:hover {
  background-color: var(--gray-100);
}

.breakdown-total-row.clickable:hover .breakdown-value {
  text-decoration-style: solid;
}

.breakdown-revenue {
  font-size: 0.6875rem;
  color: var(--gray-400);
  padding-left: 0.75rem;
  margin-top: -0.125rem;
  margin-bottom: 0.125rem;
}

.breakdown-revenue::before {
  content: "└─";
  margin-right: 0.25rem;
  color: var(--gray-300);
}

.breakdown-rejection,
.metric-rejection {
  font-size: 0.6875rem;
  color: var(--amber-600);
  padding-left: 0.75rem;
  margin-top: -0.125rem;
  margin-bottom: 0.25rem;
}

/* Top clients chart panel */
.crop-metric-row.has-top-clients {
  cursor: pointer;
  transition: background 0.15s ease;
}

.crop-metric-row.has-top-clients:hover {
  background: var(--gray-100);
}

.top-clients-chart {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: calc(16px + 0.625rem);
  margin-top: -0.25rem;
  margin-bottom: 0.5rem;
}

.client-bar {
  display: flex;
  width: 100%;
  height: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--gray-100);
}

.client-bar-segment {
  height: 100%;
  min-width: 2px;
  transition: opacity 0.15s ease;
}

.client-bar-segment-clickable {
  cursor: pointer;
}

.client-bar-segment:hover {
  opacity: 0.8;
}

.top-clients-legend {
  display: flex;
  margin-top: 0.5rem;
  flex-direction: column;
  gap: 0.25rem;
}

.top-clients-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--gray-500);
}

.top-clients-row-clickable {
  cursor: pointer;
  padding: 0.25rem 0.375rem;
  margin: -0.25rem -0.375rem;
  border-radius: 0.25rem;
  transition: background-color 0.15s ease;
}

.top-clients-row-clickable:hover {
  background-color: var(--gray-100);
}

.top-clients-row-clickable:hover .client-name {
  color: var(--primary-600);
}

.client-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.client-name {
  color: var(--gray-600);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-pct {
  width: 3rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gray-400);
  font-size: 0.6875rem;
}

.client-value {
  width: 4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gray-600);
}

.top-clients-total-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  margin-top: 0.25rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--gray-200);
}

.top-clients-total-row .client-name {
  color: var(--gray-500);
  font-weight: 500;
}

.top-clients-total-row .client-value {
  margin-left: auto;
  color: var(--gray-700);
  font-weight: 600;
}

.top-clients-total-row .client-count {
  color: var(--gray-400);
  font-size: 0.6875rem;
}

.metric-rejection-rate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--gray-700);
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  background: var(--amber-50);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--amber-500);
}

.metric-rejection-rate .rejection-icon {
  width: 14px;
  height: 14px;
  color: var(--amber-600);
}

.metric-rejection-rate .crop-detail-label {
  font-weight: 500;
  color: var(--gray-600);
}

.metric-rejection-rate .crop-detail-value {
  font-weight: 600;
  color: var(--amber-700);
}

.metric-rejection-rate .rejection-detail {
  color: var(--gray-500);
  font-size: 0.6875rem;
}

.metric-rejection-rate .rejection-comparison {
  flex-basis: 100%;
  font-size: 0.6875rem;
  color: var(--gray-500);
  margin-top: 0.125rem;
  padding-left: 1.125rem;
}

.metric-rejection-rate .rejection-comparison.positive {
  color: var(--green-600);
}

.metric-rejection-rate .rejection-comparison.negative {
  color: var(--red-600);
}

/* Usable production KPI - complements rejection rate */
.metric-usable-production {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--gray-700);
  padding: 0.5rem 0.75rem;
  margin-top: 0.25rem;
  background: var(--primary-50);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--primary-500);
}

.metric-usable-production .usable-icon {
  width: 14px;
  height: 14px;
  color: var(--primary-600);
}

.metric-usable-production .crop-detail-label {
  font-weight: 500;
  color: var(--gray-600);
}

.metric-usable-production .crop-detail-value {
  font-weight: 600;
  color: var(--primary-700);
}

.metric-usable-production .usable-detail {
  color: var(--gray-500);
  font-size: 0.6875rem;
}

.metric-usable-production .usable-comparison {
  flex-basis: 100%;
  font-size: 0.6875rem;
  color: var(--gray-500);
  margin-top: 0.125rem;
  padding-left: 1.125rem;
}

.metric-usable-production .usable-comparison.positive {
  color: var(--primary-600);
}

.metric-usable-production .usable-comparison.negative {
  color: var(--red-600);
}

.crop-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  margin-top: 1.5rem; /* Extra space for tooltip clearance */
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.crop-card-footer .footer-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 1.75rem; /* Match toggle button height for consistent card heights */
}

.crop-card-footer .footer-right {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-left: auto;
}

.crop-card-footer .btn {
  flex: none;
}
