.bucket-insights {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 0;
  padding: 6px 8px 8px;
  height: 100%;
  min-height: 0;
}

.bucket-visual-toggle {
  width: 38px;
  height: 38px;
  padding: 8px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  flex: 0 0 auto;
}

.bucket-visual-toggle > span {
  display: inline-grid;
  place-items: center;
}

.bucket-visual-toggle svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.bucket-visual-toggle-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
}

.bucket-visual-toggle[aria-pressed="true"] {
  color: var(--accent);
}

.bucket-visual-panel {
  display: grid;
  flex: 1 1 auto;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.bucket-visual-panel.is-entering .bucket-chart-gridlines {
  animation: bucket-chart-gridlines-in 420ms ease-out both;
}

.bucket-visual-panel.is-entering .bucket-chart-bucket {
  animation: bucket-chart-bucket-in 680ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--enter-index, 0) * 42ms);
}

.bucket-visual-panel.is-entering .bucket-chart-stack {
  transform-origin: center bottom;
  animation: bucket-chart-stack-in 820ms cubic-bezier(0.2, 0.9, 0.22, 1.08) both;
  animation-delay: calc(var(--enter-index, 0) * 42ms + 36ms);
}

.bucket-visual-panel.is-entering .bucket-chart-label {
  animation: bucket-chart-label-in 460ms ease-out both;
  animation-delay: calc(var(--enter-index, 0) * 42ms + 170ms);
}

.bucket-visual-panel.is-entering .bucket-filter-chip {
  animation: bucket-filter-chip-in 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--enter-index, 0) * 48ms + 220ms);
}

.bucket-visual-panel.is-bars-entering .bucket-chart-bar {
  animation: bucket-chart-bucket-in 680ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--enter-index, 0) * 42ms);
}

.bucket-visual-panel.is-bars-entering .bucket-chart-stack {
  transform-origin: center bottom;
  animation: bucket-chart-stack-in 820ms cubic-bezier(0.2, 0.9, 0.22, 1.08) both;
  animation-delay: calc(var(--enter-index, 0) * 42ms + 36ms);
}

.buckets.is-visual-mode > .grid {
  display: none;
}

.main > section.buckets.is-visual-mode.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

.buckets.is-visual-mode .bucket-insights {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bucket-chart {
  flex: 1 1 auto;
  display: flex;
  height: 100%;
  min-height: 0;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--border) 26%, transparent) transparent;
}

.bucket-chart::-webkit-scrollbar {
  height: 4px;
}

.bucket-chart::-webkit-scrollbar-track {
  background: transparent;
}

.bucket-chart::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--border) 26%, transparent);
  border-radius: 999px;
}

.bucket-chart::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--border) 40%, transparent);
}

.bucket-chart-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

.bucket-chart-plot {
  --bucket-chart-columns: 1;
  position: relative;
  flex: 1 1 auto;
  display: block;
  min-height: 0;
  height: 100%;
  padding-bottom: 20px;
  min-width: max(100%, calc(var(--bucket-chart-columns) * 82px));
}

.bucket-chart-gridlines {
  position: absolute;
  inset: 0 0 20px;
  pointer-events: none;
}

.bucket-chart-gridlines {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  height: 100%;
}

.bucket-chart-gridlines > span {
  border-top: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
}

.bucket-chart-average-layer {
  position: absolute;
  inset: 0 0 20px;
  z-index: 2;
  pointer-events: none;
}

.bucket-chart-average {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 4px dotted color-mix(in srgb, var(--accent) 62%, var(--panel) 38%);
  opacity: 0.85;
}

.bucket-chart-average-label {
  position: absolute;
  bottom: 6px;
  font-size: 0.66rem;
  line-height: 1;
  color: color-mix(in srgb, var(--text) 88%, var(--muted) 12%);
  white-space: nowrap;
}

.bucket-chart-average-label-start {
  left: 0;
}

.bucket-chart-average-label-end {
  right: 0;
}

.bucket-chart-bars {
  --bucket-chart-columns: 1;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--bucket-chart-columns), minmax(64px, 1fr));
  gap: 12px;
  align-items: end;
  min-width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

.bucket-chart-bucket {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  align-items: end;
  height: 100%;
  min-width: 0;
}

.bucket-chart-bar {
  display: grid;
  align-items: stretch;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.bucket-chart-label {
  min-height: 32px;
  padding: 6px 4px 2px;
  background: transparent;
  border: 0;
  box-shadow: none;
  font-size: 0.78rem;
  text-align: center;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bucket-chart-label:hover,
.bucket-chart-label:focus-visible {
  color: var(--accent);
  transform: none;
}

.bucket-chart-column {
  --bucket-chart-amount-space: 28px;
  position: relative;
  display: flex;
  align-items: end;
  height: 100%;
  min-height: 0;
  padding-top: var(--bucket-chart-amount-space);
  box-sizing: border-box;
  overflow: hidden;
}

.bucket-chart-bar-amount {
  position: absolute;
  left: 0;
  right: 0;
  top: clamp(0%, calc(var(--bar-amount-offset, 15%) - 14px), calc(100% - 34px));
  display: grid;
  place-items: center;
  min-height: 28px;
  gap: 2px;
  padding: 4px 6px;
  color: color-mix(in srgb, var(--text) 94%, black 6%);
  font-size: 0.72rem;
  line-height: 1;
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  pointer-events: none;
  text-align: center;
}

.bucket-chart-bar-amount-row {
  display: block;
}

.bucket-chart-bar-amount-delta {
  color: color-mix(in srgb, var(--muted) 78%, var(--text) 22%);
  font-size: 0.66rem;
}

.bucket-chart-stack {
  align-self: end;
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 3px;
  overflow: hidden;
  clip-path: inset(0 round 10px 10px 0 0);
}

.bucket-chart-segment {
  position: relative;
  width: 100%;
  flex: 0 0 auto;
  background: var(--segment-color, var(--accent));
  cursor: pointer;
  overflow: hidden;
}

.bucket-chart-segment.is-expanded {
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  min-height: 0;
  background: transparent;
}

.bucket-chart-segment-amount {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  color: var(--segment-text-color, color-mix(in srgb, var(--text) 92%, black 8%));
  font-size: 0.72rem;
  line-height: 1;
  background: color-mix(in srgb, var(--panel) 22%, transparent);
  pointer-events: none;
}

.bucket-chart-segment-detail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bucket-chart-segment-icon {
  display: inline-grid;
  place-items: center;
}

.bucket-chart-segment-value {
  display: inline-block;
}

.bucket-chart-subsegment {
  flex: 1 1 0;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  min-height: 0;
  padding: 2px 6px;
  color: var(--subsegment-text-color, var(--text));
  background: var(--subsegment-color, var(--segment-color, var(--accent)));
  font-size: 0.68rem;
  line-height: 1;
  overflow: hidden;
}

.bucket-chart-subsegment + .bucket-chart-subsegment {
  border-top: 1px solid color-mix(in srgb, var(--panel) 22%, transparent);
}

.bucket-chart-subsegment-icon {
  display: inline-grid;
  place-items: center;
}

.bucket-chart-subsegment-amount {
  justify-self: end;
}

.bucket-chart-segment.is-empty {
  height: 3px;
  min-height: 3px;
  background: color-mix(in srgb, var(--border) 76%, transparent);
}

.bucket-filter-group {
  --bucket-filter-count: 1;
  display: grid;
  grid-template-columns: repeat(var(--bucket-filter-count), minmax(0, 1fr));
  gap: clamp(4px, 1.8vw, 10px);
  flex: 0 0 auto;
  align-content: flex-start;
  width: 100%;
}

.bucket-filter-chip {
  width: 100%;
  min-width: 0;
  height: auto;
  aspect-ratio: 1 / 1;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  font-size: 1.1rem;
  border: 1px solid color-mix(in srgb, var(--bucket-filter-color, var(--border)) 55%, var(--border) 45%);
  transform: translateY(0) scale(1);
  transition:
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease;
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, #ffffff 28%, transparent),
    0 8px 18px color-mix(in srgb, var(--shadow) 22%, transparent);
}

.bucket-filter-chip:hover,
.bucket-filter-chip:focus-visible {
  transform: translateY(-1px) scale(1.02);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, #ffffff 32%, transparent),
    0 12px 24px color-mix(in srgb, var(--shadow) 26%, transparent);
}

.bucket-filter-chip:active,
.bucket-filter-chip.is-pressed {
  transform: translateY(1px) scale(0.94);
  box-shadow:
    inset 0 2px 5px color-mix(in srgb, var(--shadow) 18%, transparent),
    0 3px 8px color-mix(in srgb, var(--shadow) 18%, transparent);
}

.bucket-filter-chip.active {
  color: var(--bucket-filter-text-color, var(--text));
  background: var(--bucket-filter-color, var(--accent));
  border-color: var(--bucket-filter-color, var(--accent));
}

.bucket-filter-chip:not(.active) {
  color: color-mix(in srgb, var(--bucket-filter-color, var(--muted)) 22%, var(--muted) 78%);
  background: color-mix(in srgb, var(--panel) 82%, #9ca3af 18%);
  border-color: color-mix(in srgb, var(--bucket-filter-color, var(--border)) 35%, var(--border) 65%);
}

@keyframes bucket-chart-gridlines-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes bucket-chart-bucket-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bucket-chart-stack-in {
  from {
    transform: scaleY(0.08);
    filter: saturate(0.82) brightness(1.05);
  }
  70% {
    transform: scaleY(1.03);
  }
  to {
    transform: scaleY(1);
    filter: saturate(1) brightness(1);
  }
}

@keyframes bucket-chart-label-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bucket-filter-chip-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 640px) {
  .bucket-chart-bars {
    grid-template-columns: repeat(var(--bucket-chart-columns), minmax(56px, 1fr));
  }
}
