/* ---------------------------------------------------
   CHART CONTAINER
--------------------------------------------------- */
.chart-container {
  position: relative;
  height: clamp(420px, 60vh, 600px);
  min-height: 420px;
  width: 100%;
  margin: 0 auto 20px auto;
  display: flex;
  flex-direction: column;
  background: var(--theme-chart-container-bg);
  border: 1px solid var(--theme-chart-container-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--theme-chart-container-shadow);
  box-sizing: border-box;
}

@media (max-height: 600px) {
  .chart-container {
    min-height: 380px;
    height: max(380px, 55vh);
  }
}

canvas {
  width: 100%;
  flex: 1;
  height: auto !important; /* Let canvas fill the container's content box */
  min-height: 0;
}

/* ---------------------------------------------------
   TREND FILTERS
--------------------------------------------------- */
#trendsBrandFilters {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 8px 4px;
  margin-top: 12px;
  margin-bottom: 20px;
  justify-content: center;
}

.brand-filters .filter-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

/* ---------------------------------------------------
   COMPARE CONTROLS
--------------------------------------------------- */
.compare-main-btn {
  padding: 6px 12px;
  background-color: var(--theme-bg-compare-btn);
  color: var(--theme-text-on-filled-primary);
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.compare-dropdown {
  position: absolute;
  top: 40px;
  right: 0;
  background: var(--theme-bg-compare-menu);
  border: 1px solid var(--theme-border-compare);
  z-index: 20;
  min-width: 150px;
  box-shadow: var(--theme-shadow-dropdown);
}

.compare-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--theme-text-compare-item);
}

.compare-dropdown-item:hover {
  background-color: var(--theme-bg-compare-item-hover);
}

/* ---------------------------------------------------
   FILTER GROUPS
--------------------------------------------------- */
/* Moved to components.css */

/* ---------------------------------------------------
   TREND CONTROLS
--------------------------------------------------- */
.chart-header-controls {
    display: none; /* Deprecated in favor of .trend-controls */
}

.trend-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 10px; /* Space between chart and controls */
  margin-bottom: 10px;
  width: 100%;
}

.trend-controls-spacer {
    display: block; /* Acts as left spacer */
}

.trend-controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

.chart-footer-controls {
    display: flex;
    justify-content: flex-end; /* Align to right */
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: auto; /* Push to bottom if container has extra height */
    padding-top: 10px;
}

.time-range-selector {
    justify-self: center;
    align-self: center; /* Center in flex column */
}

/* Make dropdowns compact */
.compare-main-btn {
  height: 32px;
  font-size: 0.85rem;
  width: 220px; /* Fixed width to match custom dropdown */
  box-sizing: border-box; /* Ensure padding doesn't affect total width */
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------
   COMPARE COLUMNS
--------------------------------------------------- */
.compare-columns {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 12px 4px 20px;
}

.compare-column {
  min-width: 220px;
  max-width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------------------------------------------------
   INTEGRATED FILTER COLUMNS (NEW)
--------------------------------------------------- */
.filter-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--theme-filter-column-bg);
  border: 1px solid var(--theme-filter-column-border);
  border-radius: 12px;
  padding: 16px;
  width: 280px; /* Reduced fixed width to fit more easily */
  flex: 0 0 280px; /* Fixed basis */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.filter-column-header {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--theme-text-tab-header);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--theme-border-metric-footer);
  padding-bottom: 8px;
  margin-bottom: 4px;
}

.metrics-container-integrated {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap; /* Allow wrapping */
  gap: 10px;
  /* Removed border/padding/margin since we are moving it to the header */
  position: relative;
}

/* Ensure metric cards inside integrated container look good */
.metrics-container-integrated .metric-card {
  margin-bottom: 0; /* Let flex gap handle spacing */
  background: var(--theme-bg-metric-card);
  border: 1px solid var(--theme-border-card);
  flex: 1 1 140px; /* Allow shrinking/growing, lower basis for 2-column fit */
  min-width: 140px; /* Allow 2 cards side-by-side in 280px column */
}

/* ---------------------------------------------------
   DETAILED METRIC CARDS
--------------------------------------------------- */
.metric-card {
  background: var(--theme-bg-metric-card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.metric-title-compact {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.metric-main-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--theme-text-metric-value);
  line-height: 1.2;
}

.metric-sub-row {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.change-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--theme-bg-change-pill);
  font-weight: 500;
}

.change-pill.up {
  color: var(--theme-success);
  background: var(--theme-success-soft);
}

.change-pill.down {
  color: var(--theme-danger);
  background: var(--theme-danger-soft);
}

.metric-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--theme-border-metric-footer);
  font-size: 0.75rem;
  color: var(--theme-text-muted);
}

.range-item {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.range-item .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  opacity: 0.6;
}

.range-bar {
  flex-grow: 1;
  height: 4px;
  background: var(--theme-bg-range-bar);
  border-radius: 2px;
  position: relative;
  margin: 0 4px;
}

.range-bar .fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--theme-bg-range-fill);
  border-radius: 2px;
}

/* Responsive: trend controls and filter column */
@media (max-width: 768px) {
  .trend-controls {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .filter-column {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
  }

  .compare-main-btn {
    width: 100%;
    max-width: 100%;
  }
}
